Procházet zdrojové kódy

fix: 修复平台联系邮箱验证 - 允许空字符串、null和有效email

修复 PlatformSchema、CreatePlatformSchema 和 UpdatePlatformSchema 中的 contactEmail 字段验证,
使其接受空字符串、null 和有效的 email 格式,解决创建/更新平台时不填写 email 导致响应验证 400 错误的问题。

Co-Authored-By: Claude (d8d-model) <noreply@anthropic.com>
yourname před 1 dnem
rodič
revize
ec9907f1c2

+ 7 - 1
allin-packages/platform-module/src/schemas/platform.schema.ts

@@ -18,7 +18,11 @@ export const PlatformSchema = z.object({
     description: '联系电话',
     example: '13800138000'
   }),
-  contactEmail: z.string().email().max(100).nullable().optional().openapi({
+  contactEmail: z.union([
+    z.literal(''),
+    z.null(),
+    z.string().email().max(100)
+  ]).optional().openapi({
     description: '联系邮箱',
     example: 'zhangsan@example.com'
   }),
@@ -57,6 +61,7 @@ export const CreatePlatformSchema = z.object({
     example: '13800138000'
   }),
   contactEmail: z.union([
+    z.literal(''),
     z.literal('').optional(),  // 空字符串或undefined
     z.string().email({
       message: '请输入有效的邮箱地址'
@@ -88,6 +93,7 @@ export const UpdatePlatformSchema = z.object({
     example: '13800138000'
   }),
   contactEmail: z.union([
+    z.literal(''),
     z.literal('').optional(),  // 空字符串或undefined
     z.string().email({
       message: '请输入有效的邮箱地址'