Prechádzať zdrojové kódy

🐛 fix(user): 修复用户ID参数类型转换问题

- 将用户ID参数从字符串类型改为数字类型
- 移除多余的parseInt转换,直接使用参数值
- 更新参数验证规则,确保ID为数字类型
yourname 4 mesiacov pred
rodič
commit
51836bdfa1
1 zmenil súbory, kde vykonal 3 pridanie a 3 odobranie
  1. 3 3
      src/server/api/users/[id]/get.ts

+ 3 - 3
src/server/api/users/[id]/get.ts

@@ -10,9 +10,9 @@ import { UserSchema } from '@/server/modules/users/user.entity';
 const userService = new UserService(AppDataSource);
 
 const GetParams = z.object({
-  id: z.string().openapi({
+  id: z.coerce.number().openapi({
     param: { name: 'id', in: 'path' },
-    example: '1',
+    example: 1,
     description: '用户ID'
   })
 });
@@ -43,7 +43,7 @@ const routeDef = createRoute({
 const app = new OpenAPIHono<AuthContext>().openapi(routeDef, async (c) => {
   try {
     const { id } = c.req.valid('param');
-    const user = await userService.getUserById(parseInt(id));
+    const user = await userService.getUserById(id);
     if (!user) {
       return c.json({ code: 404, message: '用户不存在' }, 404);
     }