|
|
@@ -1,14 +1,19 @@
|
|
|
import { z } from 'zod';
|
|
|
import { DisabledStatus } from '@/share/types';
|
|
|
-import { ActivityType } from '../activities/activity.entity';
|
|
|
|
|
|
-// 车型枚举
|
|
|
+// 车型枚举
|
|
|
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个字符'),
|
|
|
@@ -17,8 +22,8 @@ export const createRouteSchema = z.object({
|
|
|
endPoint: z.string().min(1, '目的地不能为空').max(255, '目的地不能超过255个字符'),
|
|
|
pickupPoint: z.string().min(1, '上车点不能为空').max(255, '上车点不能超过255个字符'),
|
|
|
dropoffPoint: z.string().min(1, '下车点不能为空').max(255, '下车点不能超过255个字符'),
|
|
|
- departureTime: z.string().datetime('出发时间格式不正确'),
|
|
|
- vehicleType: z.nativeEnum(VehicleType, {
|
|
|
+ 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'),
|
|
|
@@ -35,8 +40,8 @@ export const updateRouteSchema = z.object({
|
|
|
endPoint: z.string().min(1, '目的地不能为空').max(255, '目的地不能超过255个字符').optional(),
|
|
|
pickupPoint: z.string().min(1, '上车点不能为空').max(255, '上车点不能超过255个字符').optional(),
|
|
|
dropoffPoint: z.string().min(1, '下车点不能为空').max(255, '下车点不能超过255个字符').optional(),
|
|
|
- departureTime: z.string().datetime('出发时间格式不正确').optional(),
|
|
|
- vehicleType: z.nativeEnum(VehicleType, {
|
|
|
+ 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(),
|
|
|
@@ -56,7 +61,7 @@ export const getRouteSchema = z.object({
|
|
|
pickupPoint: z.string().min(1, '上车点不能为空').max(255, '上车点不能超过255个字符'),
|
|
|
dropoffPoint: z.string().min(1, '下车点不能为空').max(255, '下车点不能超过255个字符'),
|
|
|
departureTime: z.coerce.date(),
|
|
|
- vehicleType: z.nativeEnum(VehicleType, {
|
|
|
+ vehicleType: z.enum([VehicleType.BUS, VehicleType.MINIBUS, VehicleType.CAR], {
|
|
|
message: '车型必须是有效的类型(bus/minibus/car)'
|
|
|
}),
|
|
|
price: z.coerce.number().min(0, '价格不能为负数').max(99999999.99, '价格不能超过99999999.99'),
|
|
|
@@ -94,7 +99,7 @@ export const routeListResponseSchema = z.object({
|
|
|
pickupPoint: z.string().min(1, '上车点不能为空').max(255, '上车点不能超过255个字符'),
|
|
|
dropoffPoint: z.string().min(1, '下车点不能为空').max(255, '下车点不能超过255个字符'),
|
|
|
departureTime: z.coerce.date(),
|
|
|
- vehicleType: z.nativeEnum(VehicleType, {
|
|
|
+ vehicleType: z.enum([VehicleType.BUS, VehicleType.MINIBUS, VehicleType.CAR], {
|
|
|
message: '车型必须是有效的类型(bus/minibus/car)'
|
|
|
}),
|
|
|
price: z.coerce.number().min(0, '价格不能为负数').max(99999999.99, '价格不能超过99999999.99'),
|
|
|
@@ -109,7 +114,7 @@ export const routeListResponseSchema = z.object({
|
|
|
activity: z.object({
|
|
|
id: z.number().int().positive('活动ID必须为正整数'),
|
|
|
name: z.string().min(1, '活动名称不能为空').max(255, '活动名称不能超过255个字符'),
|
|
|
- type: z.nativeEnum(ActivityType, {
|
|
|
+ type: z.enum([ActivityType.DEPARTURE, ActivityType.RETURN], {
|
|
|
message: '活动类型必须是departure(去程)或return(返程)'
|
|
|
}),
|
|
|
}).optional(),
|