|
@@ -1,6 +1,6 @@
|
|
|
import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
|
|
import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
|
|
|
import { z } from 'zod';
|
|
import { z } from 'zod';
|
|
|
-import { AppDataSource } from '@d8d/shared-utils';
|
|
|
|
|
|
|
+import { AppDataSource, parseWithAwait } from '@d8d/shared-utils';
|
|
|
import { authMiddleware } from '@d8d/auth-module-mt';
|
|
import { authMiddleware } from '@d8d/auth-module-mt';
|
|
|
import { AuthContext } from '@d8d/shared-types';
|
|
import { AuthContext } from '@d8d/shared-types';
|
|
|
import { PrintTaskService } from '../../services/print-task.service';
|
|
import { PrintTaskService } from '../../services/print-task.service';
|
|
@@ -84,8 +84,9 @@ const app = new OpenAPIHono<AuthContext>()
|
|
|
const cancelReason = reason as any as CancelReason;
|
|
const cancelReason = reason as any as CancelReason;
|
|
|
const task = await printTaskService.cancelPrintTask(tenantId, taskId, cancelReason);
|
|
const task = await printTaskService.cancelPrintTask(tenantId, taskId, cancelReason);
|
|
|
|
|
|
|
|
- return c.json({
|
|
|
|
|
- success: true,
|
|
|
|
|
|
|
+ // 验证响应格式
|
|
|
|
|
+ const response = {
|
|
|
|
|
+ success: true as const,
|
|
|
data: {
|
|
data: {
|
|
|
id: task.id,
|
|
id: task.id,
|
|
|
tenantId: task.tenantId,
|
|
tenantId: task.tenantId,
|
|
@@ -95,7 +96,10 @@ const app = new OpenAPIHono<AuthContext>()
|
|
|
cancelledAt: task.cancelledAt ? task.cancelledAt.toISOString() : null,
|
|
cancelledAt: task.cancelledAt ? task.cancelledAt.toISOString() : null,
|
|
|
updatedAt: task.updatedAt.toISOString()
|
|
updatedAt: task.updatedAt.toISOString()
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
|
|
+ };
|
|
|
|
|
+ const validatedResponse = await parseWithAwait(CancelPrintTaskResponseSchema, response);
|
|
|
|
|
+
|
|
|
|
|
+ return c.json(validatedResponse);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error(`[租户${tenantId}] 取消打印任务失败,任务ID: ${taskId}:`, error);
|
|
console.error(`[租户${tenantId}] 取消打印任务失败,任务ID: ${taskId}:`, error);
|
|
|
const errorMessage = error instanceof Error ? error.message : '取消打印任务失败';
|
|
const errorMessage = error instanceof Error ? error.message : '取消打印任务失败';
|