|
|
@@ -5,6 +5,7 @@ import { ErrorSchema } from './errorHandler';
|
|
|
import { AuthContext } from '../types/context';
|
|
|
import { ObjectLiteral } from 'typeorm';
|
|
|
import { AppDataSource } from '../data-source';
|
|
|
+import { parseWithAwait } from './parseWithAwait';
|
|
|
|
|
|
export function createCrudRoutes<
|
|
|
T extends ObjectLiteral,
|
|
|
@@ -253,12 +254,13 @@ export function createCrudRoutes<
|
|
|
);
|
|
|
|
|
|
return c.json({
|
|
|
- data: await z.array(listSchema).parseAsync(data),
|
|
|
+ // data: z.array(listSchema).parse(data),
|
|
|
+ data: await parseWithAwait(z.array(listSchema), data),
|
|
|
pagination: { total, current: page, pageSize }
|
|
|
}, 200);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- return c.json({ code: 400, message: '参数验证失败', errors: error.message }, 400);
|
|
|
+ return c.json({ code: 400, message: '参数验证失败', errors: JSON.parse(error.message) }, 400);
|
|
|
}
|
|
|
return c.json({
|
|
|
code: 500,
|
|
|
@@ -274,7 +276,7 @@ export function createCrudRoutes<
|
|
|
return c.json(result, 201);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- return c.json({ code: 400, message: '参数验证失败', errors: error.message }, 400);
|
|
|
+ return c.json({ code: 400, message: '参数验证失败', errors: JSON.parse(error.message) }, 400);
|
|
|
}
|
|
|
return c.json({
|
|
|
code: 500,
|
|
|
@@ -291,10 +293,11 @@ export function createCrudRoutes<
|
|
|
return c.json({ code: 404, message: '资源不存在' }, 404);
|
|
|
}
|
|
|
|
|
|
- return c.json(await getSchema.parseAsync(result), 200);
|
|
|
+ // return c.json(await getSchema.parseAsync(result), 200);
|
|
|
+ return c.json(await parseWithAwait(getSchema, data), 200);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- return c.json({ code: 400, message: '参数验证失败', errors: error.message }, 400);
|
|
|
+ return c.json({ code: 400, message: '参数验证失败', errors: JSON.parse(error.message) }, 400);
|
|
|
}
|
|
|
return c.json({
|
|
|
code: 500,
|
|
|
@@ -316,7 +319,7 @@ export function createCrudRoutes<
|
|
|
return c.json(result, 200);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- return c.json({ code: 400, message: '参数验证失败', errors: error.message }, 400);
|
|
|
+ return c.json({ code: 400, message: '参数验证失败', errors: JSON.parse(error.message) }, 400);
|
|
|
}
|
|
|
return c.json({
|
|
|
code: 500,
|
|
|
@@ -336,7 +339,7 @@ export function createCrudRoutes<
|
|
|
return c.body(null, 204);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
- return c.json({ code: 400, message: '参数验证失败', errors: error.message }, 400);
|
|
|
+ return c.json({ code: 400, message: '参数验证失败', errors: JSON.parse(error.message) }, 400);
|
|
|
}
|
|
|
return c.json({
|
|
|
code: 500,
|