소스 검색

fix(order-module): 修复订单资产查询API时间字段类型转换问题

- 将路由定义中的 `z.string().datetime()` 改为 `z.coerce.date()`
- 修复查询订单人员资产API返回500错误的问题
- 错误信息:期望string类型,但收到了Date类型
- 修复文件:`allin-packages/order-module/src/routes/order-custom.routes.ts`
- 更新故事文档记录修复详情

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 9 시간 전
부모
커밋
54fa890d54
2개의 변경된 파일27개의 추가작업 그리고 9개의 파일을 삭제
  1. 9 9
      allin-packages/order-module/src/routes/order-custom.routes.ts
  2. 18 0
      docs/stories/008.007.transplant-order-management-ui.story.md

+ 9 - 9
allin-packages/order-module/src/routes/order-custom.routes.ts

@@ -368,9 +368,9 @@ const createOrderPersonAssetRoute = createRoute({
           assetType: z.string().openapi({ description: '资产类型' }),
           assetFileType: z.string().openapi({ description: '资产文件类型' }),
           fileId: z.number().int().openapi({ description: '文件ID' }),
-          relatedTime: z.string().datetime().openapi({ description: '关联时间' }),
-          createTime: z.string().datetime().openapi({ description: '创建时间' }),
-          updateTime: z.string().datetime().openapi({ description: '更新时间' })
+          relatedTime: z.coerce.date().openapi({ description: '关联时间' }),
+          createTime: z.coerce.date().openapi({ description: '创建时间' }),
+          updateTime: z.coerce.date().openapi({ description: '更新时间' })
         }) }
       }
     },
@@ -414,9 +414,9 @@ const queryOrderPersonAssetRoute = createRoute({
               assetType: z.string().openapi({ description: '资产类型' }),
               assetFileType: z.string().openapi({ description: '资产文件类型' }),
               fileId: z.number().int().openapi({ description: '文件ID' }),
-              relatedTime: z.string().datetime().openapi({ description: '关联时间' }),
-              createTime: z.string().datetime().openapi({ description: '创建时间' }),
-              updateTime: z.string().datetime().openapi({ description: '更新时间' })
+              relatedTime: z.coerce.date().openapi({ description: '关联时间' }),
+              createTime: z.coerce.date().openapi({ description: '创建时间' }),
+              updateTime: z.coerce.date().openapi({ description: '更新时间' })
             })).openapi({ description: '资产列表' }),
             total: z.number().int().openapi({ description: '总记录数' })
           })
@@ -846,9 +846,9 @@ const app = new OpenAPIHono<AuthContext>()
             assetType: z.string(),
             assetFileType: z.string(),
             fileId: z.number().int(),
-            relatedTime: z.string().datetime(),
-            createTime: z.string().datetime(),
-            updateTime: z.string().datetime()
+            relatedTime: z.coerce.date(),
+            createTime: z.coerce.date(),
+            updateTime: z.coerce.date()
           })),
           total: z.number().int()
         }),

+ 18 - 0
docs/stories/008.007.transplant-order-management-ui.story.md

@@ -692,6 +692,23 @@ Ready for Review - 所有任务已完成。已完成任务状态:
      - 订单管理集成测试:31个测试中25个通过,6个跳过,测试通过率100%
      - 所有现有功能测试保持通过,没有破坏现有功能
 
+14. **API时间字段类型修复(2025-12-08)**:
+   - **问题发现**:订单资产查询API返回500错误,错误信息显示类型不匹配:期望`string`类型,但收到了`Date`类型
+   - **问题分析**:路由定义中的schema期望`z.string().datetime()`,但实际从数据库返回的是`Date`对象
+   - **解决方案**:将schema改为`z.coerce.date()`,使`parseWithAwait`函数能正确处理Date对象
+   - **修复文件**:
+     1. `allin-packages/order-module/src/routes/order-custom.routes.ts`
+        - 第417-419行:查询订单人员资产路由的响应schema
+        - 第371-373行:创建订单人员资产路由的响应schema
+        - 第849-851行:查询订单人员资产处理函数中的schema
+   - **修复内容**:
+     - 将`z.string().datetime()`改为`z.coerce.date()`
+     - 保持与实体定义一致(实体中的时间字段是`Date`类型)
+   - **测试验证**:
+     - 使用curl命令测试API:`curl -X GET '/api/v1/order/assets/query?orderId=2&personId=1&page=1&limit=100'`
+     - 结果:返回HTTP 200成功响应,包含正确的时间字段格式(ISO字符串)
+     - 错误已修复:不再返回500错误和类型不匹配错误信息
+
 ### File List
 *创建/修改的文件:*
 - `allin-packages/order-management-ui/` - 订单管理UI包
@@ -718,6 +735,7 @@ Ready for Review - 所有任务已完成。已完成任务状态:
 - `allin-packages/order-module/package.json` - **最终修复**:添加残疾人模块依赖`"@d8d/allin-disability-module": "workspace:*"`
 - `allin-packages/order-management-ui/src/components/AttendanceModal.tsx` - **任务14新增**:考勤打卡功能(出勤表导出)组件,支持月份选择和出勤天数选择,使用xlsx库生成Excel文件,实现模拟出勤算法(√标记出勤,空白标记缺勤),集成到订单管理UI中
 - `allin-packages/order-management-ui/tests/components/AttendanceModal.test.tsx` - **任务14新增**:AttendanceModal组件测试文件,包含11个测试用例,验证组件渲染、选择器显示、订单信息显示、按钮状态、取消功能、无人员警告等
+- `allin-packages/order-module/src/routes/order-custom.routes.ts` - **API时间字段类型修复**:修复订单资产查询API的时间字段类型转换问题,将`z.string().datetime()`改为`z.coerce.date()`,解决期望`string`类型但收到`Date`类型的500错误
 
 *影响的文件:*
 - `allin-packages/order-management-ui/package.json` - 依赖配置