Jelajahi Sumber

♻️ refactor(stock): 分离日期备注的实体和Schema定义

- 将DateNotesSchema、CreateDateNotesDto和UpdateDateNotesDto从date-notes.entity.ts移至新文件date-notes.schema.ts
- 为所有Schema字段添加详细的验证错误提示信息
- 优化Schema示例值,使其更符合实际业务场景
yourname 6 bulan lalu
induk
melakukan
d9d5a23d27

+ 1 - 23
src/server/modules/stock/date-notes.entity.ts

@@ -1,5 +1,4 @@
 import { Entity, PrimaryGeneratedColumn, Column, Index } from 'typeorm';
-import { z } from '@hono/zod-openapi';
 
 @Entity('date_notes')
 @Index(['code', 'noteDate'], { unique: true })
@@ -21,25 +20,4 @@ export class DateNotes {
 
   @Column({ name: 'updated_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP', onUpdate: 'CURRENT_TIMESTAMP' })
   updatedAt!: Date;
-}
-
-export const DateNotesSchema = z.object({
-  id: z.number().int().positive().openapi({ description: 'ID', example: 1 }),
-  code: z.string().max(255).openapi({ description: '股票代码', example: '001339' }),
-  noteDate: z.date().openapi({ description: '备注日期', example: '2024-11-07T08:00:00Z' }),
-  note: z.string().max(255).openapi({ description: '备注内容', example: 'test01' }),
-  createdAt: z.date().openapi({ description: '创建时间', example: '2025-05-22T16:17:13Z' }),
-  updatedAt: z.date().openapi({ description: '更新时间', example: '2025-05-22T16:17:13Z' })
-});
-
-export const CreateDateNotesDto = z.object({
-  code: z.string().max(255).openapi({ description: '股票代码', example: '001339' }),
-  noteDate: z.coerce.date().openapi({ description: '备注日期', example: '2024-11-07T08:00:00Z' }),
-  note: z.string().max(255).openapi({ description: '备注内容', example: 'test01' })
-});
-
-export const UpdateDateNotesDto = z.object({
-  code: z.string().max(255).optional().openapi({ description: '股票代码', example: '001339' }),
-  noteDate: z.coerce.date().optional().openapi({ description: '备注日期', example: '2024-11-07T08:00:00Z' }),
-  note: z.string().max(255).optional().openapi({ description: '备注内容', example: 'test01' })
-});
+}

+ 58 - 0
src/server/modules/stock/date-notes.schema.ts

@@ -0,0 +1,58 @@
+import { z } from '@hono/zod-openapi';
+
+export const DateNotesSchema = z.object({
+  id: z.number().int('ID必须是整数').positive('ID必须是正整数').openapi({
+    description: '日期备注ID',
+    example: 1
+  }),
+  code: z.string().min(1, '股票代码不能为空').max(255, '股票代码最多255个字符').openapi({
+    description: '股票代码',
+    example: '600000'
+  }),
+  noteDate: z.coerce.date('备注日期格式不正确').openapi({
+    description: '备注日期',
+    example: '2024-01-15T00:00:00Z'
+  }),
+  note: z.string().min(1, '备注内容不能为空').max(255, '备注内容最多255个字符').openapi({
+    description: '备注内容',
+    example: '重点关注该股票走势'
+  }),
+  createdAt: z.coerce.date('创建时间格式不正确').openapi({
+    description: '创建时间',
+    example: '2024-01-15T10:30:00Z'
+  }),
+  updatedAt: z.coerce.date('更新时间格式不正确').openapi({
+    description: '更新时间',
+    example: '2024-01-15T10:30:00Z'
+  })
+});
+
+export const CreateDateNotesDto = z.object({
+  code: z.string().min(1, '股票代码不能为空').max(255, '股票代码最多255个字符').openapi({
+    description: '股票代码',
+    example: '600000'
+  }),
+  noteDate: z.coerce.date('备注日期格式不正确').openapi({
+    description: '备注日期',
+    example: '2024-01-15T00:00:00Z'
+  }),
+  note: z.string().min(1, '备注内容不能为空').max(255, '备注内容最多255个字符').openapi({
+    description: '备注内容',
+    example: '重点关注该股票走势'
+  })
+});
+
+export const UpdateDateNotesDto = z.object({
+  code: z.string().min(1, '股票代码不能为空').max(255, '股票代码最多255个字符').optional().openapi({
+    description: '股票代码',
+    example: '600000'
+  }),
+  noteDate: z.coerce.date('备注日期格式不正确').optional().openapi({
+    description: '备注日期',
+    example: '2024-01-15T00:00:00Z'
+  }),
+  note: z.string().min(1, '备注内容不能为空').max(255, '备注内容最多255个字符').optional().openapi({
+    description: '备注内容',
+    example: '更新后的备注内容'
+  })
+});