date-notes.entity.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Entity, PrimaryGeneratedColumn, Column, Index } from 'typeorm';
  2. import { z } from '@hono/zod-openapi';
  3. @Entity('date_notes')
  4. @Index(['code', 'noteDate'], { unique: true })
  5. export class DateNotes {
  6. @PrimaryGeneratedColumn({ unsigned: true })
  7. id!: number;
  8. @Column({ name: 'code', type: 'varchar', length: 255, nullable: false, comment: '股票代码' })
  9. code!: string;
  10. @Column({ name: 'note_date', type: 'timestamp', nullable: false, comment: '备注日期' })
  11. noteDate!: Date;
  12. @Column({ name: 'note', type: 'varchar', length: 255, nullable: false, comment: '备注内容' })
  13. note!: string;
  14. @Column({ name: 'created_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  15. createdAt!: Date;
  16. @Column({ name: 'updated_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP', onUpdate: 'CURRENT_TIMESTAMP' })
  17. updatedAt!: Date;
  18. }
  19. export const DateNotesSchema = z.object({
  20. id: z.number().int().positive().openapi({ description: 'ID', example: 1 }),
  21. code: z.string().max(255).openapi({ description: '股票代码', example: '001339' }),
  22. noteDate: z.date().openapi({ description: '备注日期', example: '2024-11-07T08:00:00Z' }),
  23. note: z.string().max(255).openapi({ description: '备注内容', example: 'test01' }),
  24. createdAt: z.date().openapi({ description: '创建时间', example: '2025-05-22T16:17:13Z' }),
  25. updatedAt: z.date().openapi({ description: '更新时间', example: '2025-05-22T16:17:13Z' })
  26. });
  27. export const CreateDateNotesDto = z.object({
  28. code: z.string().max(255).openapi({ description: '股票代码', example: '001339' }),
  29. noteDate: z.coerce.date().openapi({ description: '备注日期', example: '2024-11-07T08:00:00Z' }),
  30. note: z.string().max(255).openapi({ description: '备注内容', example: 'test01' })
  31. });
  32. export const UpdateDateNotesDto = z.object({
  33. code: z.string().max(255).optional().openapi({ description: '股票代码', example: '001339' }),
  34. noteDate: z.coerce.date().optional().openapi({ description: '备注日期', example: '2024-11-07T08:00:00Z' }),
  35. note: z.string().max(255).optional().openapi({ description: '备注内容', example: 'test01' })
  36. });