|
|
@@ -6,6 +6,7 @@ import { ErrorSchema } from '../../utils/errorHandler';
|
|
|
import { AppDataSource } from '../../data-source';
|
|
|
import { AuthContext } from '../../types/context';
|
|
|
import { CreateUserDto, UpdateUserDto, UserSchema } from '../../modules/users/user.schema';
|
|
|
+import { parseWithAwait } from '../../utils/parseWithAwait';
|
|
|
|
|
|
// 创建用户路由 - 自定义业务逻辑(密码加密等)
|
|
|
const createUserRoute = createRoute({
|
|
|
@@ -112,7 +113,7 @@ const app = new OpenAPIHono<AuthContext>()
|
|
|
const userService = new UserService(AppDataSource);
|
|
|
const result = await userService.createUser(data);
|
|
|
|
|
|
- return c.json(result, 201);
|
|
|
+ return c.json(await parseWithAwait(UserSchema, result), 201);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
return c.json({
|
|
|
@@ -138,7 +139,7 @@ const app = new OpenAPIHono<AuthContext>()
|
|
|
return c.json({ code: 404, message: '资源不存在' }, 404);
|
|
|
}
|
|
|
|
|
|
- return c.json(result, 200);
|
|
|
+ return c.json(await parseWithAwait(UserSchema, result), 200);
|
|
|
} catch (error) {
|
|
|
if (error instanceof z.ZodError) {
|
|
|
return c.json({
|