| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import { z } from '@hono/zod-openapi';
- // 平台实体Schema
- export const PlatformSchema = z.object({
- id: z.number().int().positive().openapi({
- description: '平台ID',
- example: 1
- }),
- platformName: z.string().max(100).openapi({
- description: '平台名称',
- example: '微信平台'
- }),
- contactPerson: z.string().max(50).openapi({
- description: '联系人',
- example: '张三'
- }),
- contactPhone: z.string().max(20).openapi({
- description: '联系电话',
- example: '13800138000'
- }),
- contactEmail: z.string().email().max(100).nullable().optional().openapi({
- description: '联系邮箱',
- example: 'zhangsan@example.com'
- }),
- status: z.number().int().min(0).max(1).default(1).openapi({
- description: '状态:1-正常,0-禁用',
- example: 1
- }),
- createTime: z.coerce.date().openapi({
- description: '创建时间',
- example: '2024-01-01T00:00:00Z'
- }),
- updateTime: z.coerce.date().openapi({
- description: '更新时间',
- example: '2024-01-01T00:00:00Z'
- })
- });
- // 创建平台DTO
- export const CreatePlatformSchema = z.object({
- platformName: z.string({
- error: '请输入平台名称'
- }).min(1, {
- message: '平台名称不能为空'
- }).max(100, {
- message: '平台名称不能超过100个字符'
- }).openapi({
- description: '平台名称',
- example: '微信平台'
- }),
- contactPerson: z.string().max(50).optional().openapi({
- description: '联系人',
- example: '张三'
- }),
- contactPhone: z.string().max(20).optional().openapi({
- description: '联系电话',
- example: '13800138000'
- }),
- contactEmail: z.string({
- error: '请输入联系邮箱'
- }).email({
- message: '请输入有效的邮箱地址'
- }).max(100, {
- message: '邮箱地址不能超过100个字符'
- }).optional()
- .or(z.literal('')) // 允许空字符串
- .transform(val => val === '' ? undefined : val) // 将空字符串转为undefined
- .openapi({
- description: '联系邮箱',
- example: 'zhangsan@example.com'
- })
- });
- // 更新平台DTO
- export const UpdatePlatformSchema = z.object({
- id: z.number().int().positive().openapi({
- description: '平台ID',
- example: 1
- }),
- platformName: z.string().min(1).max(100).optional().openapi({
- description: '平台名称',
- example: '微信平台'
- }),
- contactPerson: z.string().max(50).optional().openapi({
- description: '联系人',
- example: '张三'
- }),
- contactPhone: z.string().max(20).optional().openapi({
- description: '联系电话',
- example: '13800138000'
- }),
- contactEmail: z.string({
- error: '请输入联系邮箱'
- }).email({
- message: '请输入有效的邮箱地址'
- }).max(100, {
- message: '邮箱地址不能超过100个字符'
- }).optional()
- .or(z.literal('')) // 允许空字符串
- .transform(val => val === '' ? undefined : val) // 将空字符串转为undefined
- .openapi({
- description: '联系邮箱',
- example: 'zhangsan@example.com'
- })
- });
- // 删除平台DTO
- export const DeletePlatformSchema = z.object({
- id: z.number().int().positive().openapi({
- description: '平台ID',
- example: 1
- })
- });
- // 分页查询参数Schema
- export const PaginationQuerySchema = z.object({
- skip: z.coerce.number().int().min(0).default(0).optional().openapi({
- description: '跳过记录数',
- example: 0
- }),
- take: z.coerce.number().int().min(1).max(100).default(10).optional().openapi({
- description: '获取记录数',
- example: 10
- })
- });
- // 搜索平台参数Schema
- export const SearchPlatformQuerySchema = PaginationQuerySchema.extend({
- name: z.string().min(1).openapi({
- description: '搜索关键词',
- example: '微信'
- })
- });
- // 类型定义
- export type Platform = z.infer<typeof PlatformSchema>;
- export type CreatePlatformDto = z.infer<typeof CreatePlatformSchema>;
- export type UpdatePlatformDto = z.infer<typeof UpdatePlatformSchema>;
- export type DeletePlatformDto = z.infer<typeof DeletePlatformSchema>;
- export type PaginationQuery = z.infer<typeof PaginationQuerySchema>;
- export type SearchPlatformQuery = z.infer<typeof SearchPlatformQuerySchema>;
|