| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import { z } from 'zod';
- import { DisabledStatus } from '@/share/types';
- import { locationInfoSchema } from '@/server/modules/locations/location.schema';
- // 车型枚举
- export enum VehicleType {
- BUS = 'bus', // 大巴
- MINIBUS = 'minibus', // 中巴
- CAR = 'car' // 小车
- }
- // 活动类型枚举
- export enum ActivityType {
- DEPARTURE = 'departure', // 去程活动
- RETURN = 'return' // 返程活动
- }
- // 路线创建Schema
- export const createRouteSchema = z.object({
- name: z.string().min(1, '路线名称不能为空').max(255, '路线名称不能超过255个字符'),
- description: z.string().max(1000, '路线描述不能超过1000个字符').optional().nullable(),
- startLocationId: z.number().int().positive('出发地点ID必须为正整数'),
- endLocationId: z.number().int().positive('目的地点ID必须为正整数'),
- pickupPoint: z.string().min(1, '上车点不能为空').max(255, '上车点不能超过255个字符'),
- dropoffPoint: z.string().min(1, '下车点不能为空').max(255, '下车点不能超过255个字符'),
- departureTime: z.coerce.date(),
- vehicleType: z.enum([VehicleType.BUS, VehicleType.MINIBUS, VehicleType.CAR], {
- message: '车型必须是有效的类型(bus/minibus/car)'
- }),
- price: z.number().min(0, '价格不能为负数').max(99999999.99, '价格不能超过99999999.99'),
- seatCount: z.number().int().min(1, '座位数至少为1').max(1000, '座位数不能超过1000'),
- availableSeats: z.number().int().min(0, '可用座位数不能为负数').max(1000, '可用座位数不能超过1000'),
- activityId: z.number().int().positive('活动ID必须为正整数'),
- });
- // 路线更新Schema
- export const updateRouteSchema = z.object({
- name: z.string().min(1, '路线名称不能为空').max(255, '路线名称不能超过255个字符').optional(),
- description: z.string().max(1000, '路线描述不能超过1000个字符').optional().nullable(),
- startLocationId: z.number().int().positive('出发地点ID必须为正整数').optional(),
- endLocationId: z.number().int().positive('目的地点ID必须为正整数').optional(),
- pickupPoint: z.string().min(1, '上车点不能为空').max(255, '上车点不能超过255个字符').optional(),
- dropoffPoint: z.string().min(1, '下车点不能为空').max(255, '下车点不能超过255个字符').optional(),
- departureTime: z.coerce.date(),
- vehicleType: z.enum([VehicleType.BUS, VehicleType.MINIBUS, VehicleType.CAR], {
- message: '车型必须是有效的类型(bus/minibus/car)'
- }).optional(),
- price: z.number().min(0, '价格不能为负数').max(99999999.99, '价格不能超过99999999.99').optional(),
- seatCount: z.number().int().min(1, '座位数至少为1').max(1000, '座位数不能超过1000').optional(),
- availableSeats: z.number().int().min(0, '可用座位数不能为负数').max(1000, '可用座位数不能超过1000').optional(),
- activityId: z.number().int().positive('活动ID必须为正整数').optional(),
- isDisabled: z.nativeEnum(DisabledStatus).optional(),
- });
- // 路线获取Schema
- export const getRouteSchema = z.object({
- id: z.number().int().positive('ID必须为正整数'),
- name: z.string().min(1, '路线名称不能为空').max(255, '路线名称不能超过255个字符'),
- description: z.string().max(1000, '路线描述不能超过1000个字符').optional().nullable(),
- startLocationId: z.number().int().positive('出发地点ID必须为正整数'),
- endLocationId: z.number().int().positive('目的地点ID必须为正整数'),
- startLocation: locationInfoSchema.optional().nullable(),
- endLocation: locationInfoSchema.optional().nullable(),
- pickupPoint: z.string().min(1, '上车点不能为空').max(255, '上车点不能超过255个字符'),
- dropoffPoint: z.string().min(1, '下车点不能为空').max(255, '下车点不能超过255个字符'),
- departureTime: z.coerce.date(),
- vehicleType: z.enum([VehicleType.BUS, VehicleType.MINIBUS, VehicleType.CAR], {
- message: '车型必须是有效的类型(bus/minibus/car)'
- }),
- price: z.coerce.number().min(0, '价格不能为负数').max(99999999.99, '价格不能超过99999999.99'),
- seatCount: z.number().int().min(1, '座位数至少为1').max(1000, '座位数不能超过1000'),
- availableSeats: z.number().int().min(0, '可用座位数不能为负数').max(1000, '可用座位数不能超过1000'),
- activityId: z.number().int().positive('活动ID必须为正整数'),
- isDisabled: z.nativeEnum(DisabledStatus),
- createdAt: z.coerce.date(),
- updatedAt: z.coerce.date(),
- createdBy: z.number().int().nullable(),
- updatedBy: z.number().int().nullable(),
- });
- // 路线列表查询Schema
- export const listRoutesSchema = z.object({
- keyword: z.string().optional(),
- vehicleType: z.string().optional(),
- routeType: z.enum(['departure', 'return']).optional(),
- minPrice: z.coerce.number().min(0).optional(),
- maxPrice: z.coerce.number().min(0).optional(),
- activityId: z.coerce.number().int().positive().optional(),
- isDisabled: z.coerce.number().int().optional(),
- page: z.coerce.number().int().min(1).default(1),
- pageSize: z.coerce.number().int().min(1).max(100).default(20),
- sortBy: z.enum(['name', 'price', 'departureTime', 'createdAt']).default('createdAt'),
- sortOrder: z.enum(['ASC', 'DESC']).default('DESC'),
- });
- // 路线列表返回Schema
- export const routeListResponseSchema = z.object({
- id: z.number().int().positive('ID必须为正整数'),
- name: z.string().min(1, '路线名称不能为空').max(255, '路线名称不能超过255个字符'),
- description: z.string().max(1000, '路线描述不能超过1000个字符').optional().nullable(),
- startLocationId: z.number().int().positive('出发地点ID必须为正整数'),
- endLocationId: z.number().int().positive('目的地点ID必须为正整数'),
- startLocation: locationInfoSchema.optional().nullable(),
- endLocation: locationInfoSchema.optional().nullable(),
- pickupPoint: z.string().min(1, '上车点不能为空').max(255, '上车点不能超过255个字符'),
- dropoffPoint: z.string().min(1, '下车点不能为空').max(255, '下车点不能超过255个字符'),
- departureTime: z.coerce.date(),
- vehicleType: z.enum([VehicleType.BUS, VehicleType.MINIBUS, VehicleType.CAR], {
- message: '车型必须是有效的类型(bus/minibus/car)'
- }),
- price: z.coerce.number().min(0, '价格不能为负数').max(99999999.99, '价格不能超过99999999.99'),
- seatCount: z.number().int().min(1, '座位数至少为1').max(1000, '座位数不能超过1000'),
- availableSeats: z.number().int().min(0, '可用座位数不能为负数').max(1000, '可用座位数不能超过1000'),
- activityId: z.number().int().positive('活动ID必须为正整数'),
- routeType: z.enum(['departure', 'return']),
- isDisabled: z.nativeEnum(DisabledStatus),
- createdAt: z.coerce.date(),
- updatedAt: z.coerce.date(),
- createdBy: z.number().int().nullable(),
- updatedBy: z.number().int().nullable(),
- activity: z.object({
- id: z.number().int().positive('活动ID必须为正整数'),
- name: z.string().min(1, '活动名称不能为空').max(255, '活动名称不能超过255个字符'),
- type: z.enum([ActivityType.DEPARTURE, ActivityType.RETURN], {
- message: '活动类型必须是departure(去程)或return(返程)'
- }),
- }).optional(),
- });
- // 路线删除Schema
- export const deleteRouteSchema = z.object({
- id: z.number().int().positive('ID必须为正整数'),
- });
- // 路线启用/禁用Schema
- export const toggleRouteStatusSchema = z.object({
- id: z.number().int().positive('ID必须为正整数'),
- isDisabled: z.nativeEnum(DisabledStatus),
- });
- // 导出类型
- export type CreateRouteInput = z.infer<typeof createRouteSchema>;
- export type UpdateRouteInput = z.infer<typeof updateRouteSchema>;
- export type GetRouteInput = z.infer<typeof getRouteSchema>;
- export type ListRoutesInput = z.infer<typeof listRoutesSchema>;
- export type DeleteRouteInput = z.infer<typeof deleteRouteSchema>;
- export type ToggleRouteStatusInput = z.infer<typeof toggleRouteStatusSchema>;
|