area-data.entity.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { Entity, PrimaryGeneratedColumn, Column, Index } from 'typeorm';
  2. import { z } from '@hono/zod-openapi';
  3. @Entity('area_data')
  4. export class AreaData {
  5. @PrimaryGeneratedColumn({ unsigned: true })
  6. id!: number;
  7. @Column({ name: 'parent_id', type: 'int', unsigned: true, nullable: true })
  8. parentId?: number;
  9. @Column({ name: 'name', type: 'varchar', length: 100 })
  10. name!: string;
  11. @Column({ name: 'created_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  12. createdAt!: Date;
  13. @Column({
  14. name: 'updated_at',
  15. type: 'timestamp',
  16. default: () => 'CURRENT_TIMESTAMP',
  17. onUpdate: 'CURRENT_TIMESTAMP'
  18. })
  19. updatedAt!: Date;
  20. }
  21. export const AreaDataSchema = z.object({
  22. id: z.number().int().positive().openapi({
  23. description: '区域ID',
  24. example: 1
  25. }),
  26. parentId: z.number().int().positive().nullable().openapi({
  27. description: '父区域ID,自引用',
  28. example: 0
  29. }),
  30. name: z.string().max(100).openapi({
  31. description: '区域名称',
  32. example: '北京市'
  33. }),
  34. createdAt: z.date().openapi({
  35. description: '创建时间',
  36. example: '2023-01-01T00:00:00Z'
  37. }),
  38. updatedAt: z.date().openapi({
  39. description: '更新时间',
  40. example: '2023-01-01T00:00:00Z'
  41. })
  42. });
  43. export const CreateAreaDataDto = z.object({
  44. parentId: z.number().int().positive().nullable().openapi({
  45. description: '父区域ID,自引用',
  46. example: 0
  47. }),
  48. name: z.string().max(100).openapi({
  49. description: '区域名称',
  50. example: '北京市'
  51. })
  52. });
  53. export const UpdateAreaDataDto = z.object({
  54. parentId: z.number().int().positive().nullable().optional().openapi({
  55. description: '父区域ID,自引用',
  56. example: 0
  57. }),
  58. name: z.string().max(100).optional().openapi({
  59. description: '区域名称',
  60. example: '北京市'
  61. })
  62. });