|
|
@@ -6,6 +6,7 @@ import { AppDataSource } from '@/server/data-source';
|
|
|
import { SolutionDesignService } from '@/server/modules/solution-designs/solution-design.service';
|
|
|
import { AuthContext } from '@/server/types/context';
|
|
|
import { authMiddleware } from '@/server/middleware/auth.middleware';
|
|
|
+import { parseWithAwait } from '@/server/utils/parseWithAwait';
|
|
|
|
|
|
// 路由定义
|
|
|
const routeDef = createRoute({
|
|
|
@@ -44,12 +45,15 @@ const app = new OpenAPIHono<AuthContext>().openapi(routeDef, async (c) => {
|
|
|
const service = new SolutionDesignService(AppDataSource);
|
|
|
const result = await service.createSolutionDesign(data, user.id, data.originalFileId);
|
|
|
|
|
|
- return c.json(result, 200);
|
|
|
+ // 使用parseWithAwait处理Promise字段
|
|
|
+ const validatedResult = await parseWithAwait(SolutionDesignSchema, result);
|
|
|
+
|
|
|
+ return c.json(validatedResult, 200);
|
|
|
|
|
|
} catch (error) {
|
|
|
console.error('创建方案设计失败:', error);
|
|
|
const { code = 500, message = '创建方案设计失败' } = error as Error & { code?: number };
|
|
|
- return c.json({ code, message }, code);
|
|
|
+ return c.json({ code, message }, code as 400 | 500 | 200);
|
|
|
}
|
|
|
});
|
|
|
|