|
@@ -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 { PrinterService } from '../../services/printer.service';
|
|
import { PrinterService } from '../../services/printer.service';
|
|
@@ -11,7 +11,7 @@ const PrinterCreateRequestSchema = z.object({
|
|
|
printerSn: z.string().min(1, '打印机SN不能为空'),
|
|
printerSn: z.string().min(1, '打印机SN不能为空'),
|
|
|
printerKey: z.string().min(1, '打印机密钥不能为空'),
|
|
printerKey: z.string().min(1, '打印机密钥不能为空'),
|
|
|
printerName: z.string().optional(),
|
|
printerName: z.string().optional(),
|
|
|
- printerType: z.enum(['RECEIPT', 'LABEL']).default('RECEIPT'),
|
|
|
|
|
|
|
+ printerType: z.enum(['58mm', '80mm']).default('58mm'),
|
|
|
isDefault: z.boolean().default(false)
|
|
isDefault: z.boolean().default(false)
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -82,10 +82,14 @@ const app = new OpenAPIHono<AuthContext>()
|
|
|
const printerService = new PrinterService(AppDataSource, feieConfig);
|
|
const printerService = new PrinterService(AppDataSource, feieConfig);
|
|
|
const printer = await printerService.addPrinter(tenantId, body);
|
|
const printer = await printerService.addPrinter(tenantId, body);
|
|
|
|
|
|
|
|
- return c.json({
|
|
|
|
|
- success: true,
|
|
|
|
|
|
|
+ // 验证响应格式
|
|
|
|
|
+ const response = {
|
|
|
|
|
+ success: true as const,
|
|
|
data: printer
|
|
data: printer
|
|
|
- });
|
|
|
|
|
|
|
+ };
|
|
|
|
|
+ const validatedResponse = await parseWithAwait(PrinterCreateResponseSchema, response);
|
|
|
|
|
+
|
|
|
|
|
+ return c.json(validatedResponse);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error(`[租户${tenantId}] 添加打印机失败:`, error);
|
|
console.error(`[租户${tenantId}] 添加打印机失败:`, error);
|
|
|
const errorMessage = error instanceof Error ? error.message : '添加打印机失败';
|
|
const errorMessage = error instanceof Error ? error.message : '添加打印机失败';
|