config.schema.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { z } from '@hono/zod-openapi';
  2. export const ConfigSchema = z.object({
  3. id: z.number().int().positive().openapi({ description: '配置ID' }),
  4. key: z.string().min(1, '配置键名不能为空').max(255, '配置键名最多255个字符').openapi({
  5. description: '配置键名',
  6. example: 'site_name'
  7. }),
  8. value: z.string().min(1, '配置值不能为空').max(255, '配置值最多255个字符').openapi({
  9. description: '配置值',
  10. example: '站点名称'
  11. }),
  12. state: z.number().int().min(1).max(2).default(2).openapi({
  13. description: '状态 1可用 2禁用',
  14. example: 1
  15. }),
  16. createdAt: z.coerce.date().openapi({
  17. description: '创建时间',
  18. example: '2024-01-01T12:00:00Z'
  19. }),
  20. updatedAt: z.coerce.date().openapi({
  21. description: '更新时间',
  22. example: '2024-01-01T12:00:00Z'
  23. }),
  24. createdBy: z.number().int().positive().nullable().openapi({
  25. description: '创建用户ID',
  26. example: 1
  27. }),
  28. updatedBy: z.number().int().positive().nullable().openapi({
  29. description: '更新用户ID',
  30. example: 1
  31. })
  32. });
  33. export const CreateConfigDto = z.object({
  34. key: z.string().min(1, '配置键名不能为空').max(255, '配置键名最多255个字符').openapi({
  35. description: '配置键名',
  36. example: 'site_name'
  37. }),
  38. value: z.string().min(1, '配置值不能为空').max(255, '配置值最多255个字符').openapi({
  39. description: '配置值',
  40. example: '站点名称'
  41. }),
  42. state: z.number().int().min(1).max(2).default(2).openapi({
  43. description: '状态 1可用 2禁用',
  44. example: 1
  45. })
  46. });
  47. export const UpdateConfigDto = z.object({
  48. key: z.string().min(1, '配置键名不能为空').max(255, '配置键名最多255个字符').optional().openapi({
  49. description: '配置键名',
  50. example: 'site_name'
  51. }),
  52. value: z.string().min(1, '配置值不能为空').max(255, '配置值最多255个字符').optional().openapi({
  53. description: '配置值',
  54. example: '站点名称'
  55. }),
  56. state: z.number().int().min(1).max(2).optional().openapi({
  57. description: '状态 1可用 2禁用',
  58. example: 1
  59. })
  60. });