|
|
@@ -0,0 +1,293 @@
|
|
|
+import { z } from '@hono/zod-openapi';
|
|
|
+import { UserSchema } from '@d8d/user-module';
|
|
|
+import { AreaSchema } from '@d8d/geo-areas';
|
|
|
+
|
|
|
+// 状态枚举
|
|
|
+export const DeliveryAddressStatusEnum = {
|
|
|
+ NORMAL: 1,
|
|
|
+ DISABLED: 2,
|
|
|
+ DELETED: 3
|
|
|
+} as const;
|
|
|
+
|
|
|
+export const IsDefaultEnum = {
|
|
|
+ NOT_DEFAULT: 0,
|
|
|
+ IS_DEFAULT: 1
|
|
|
+} as const;
|
|
|
+
|
|
|
+// 基础实体Schema
|
|
|
+export const DeliveryAddressSchema = z.object({
|
|
|
+ id: z.number()
|
|
|
+ .int('ID必须是整数')
|
|
|
+ .positive('ID必须是正整数')
|
|
|
+ .openapi({
|
|
|
+ description: '收货地址ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ userId: z.number()
|
|
|
+ .int('用户ID必须是整数')
|
|
|
+ .positive('用户ID必须是正整数')
|
|
|
+ .openapi({
|
|
|
+ description: '用户ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ name: z.string()
|
|
|
+ .min(1, '姓名不能为空')
|
|
|
+ .max(255, '姓名最多255个字符')
|
|
|
+ .openapi({
|
|
|
+ description: '收货人姓名',
|
|
|
+ example: '张三'
|
|
|
+ }),
|
|
|
+ phone: z.string()
|
|
|
+ .regex(/^1[3-9]\d{9}$/, '请输入正确的手机号')
|
|
|
+ .openapi({
|
|
|
+ description: '收货人手机号',
|
|
|
+ example: '13800138000'
|
|
|
+ }),
|
|
|
+ address: z.string()
|
|
|
+ .min(1, '详细地址不能为空')
|
|
|
+ .max(255, '详细地址最多255个字符')
|
|
|
+ .openapi({
|
|
|
+ description: '详细地址',
|
|
|
+ example: '北京市朝阳区建国门外大街1号'
|
|
|
+ }),
|
|
|
+ receiverProvince: z.coerce.number<number>()
|
|
|
+ .int('省份ID必须是整数')
|
|
|
+ .positive('省份ID必须是正整数')
|
|
|
+ .default(0)
|
|
|
+ .openapi({
|
|
|
+ description: '收货省份ID',
|
|
|
+ example: 110000
|
|
|
+ }),
|
|
|
+ receiverCity: z.coerce.number<number>()
|
|
|
+ .int('城市ID必须是整数')
|
|
|
+ .positive('城市ID必须是正整数')
|
|
|
+ .default(0)
|
|
|
+ .openapi({
|
|
|
+ description: '收货城市ID',
|
|
|
+ example: 110100
|
|
|
+ }),
|
|
|
+ receiverDistrict: z.coerce.number<number>()
|
|
|
+ .int('区县ID必须是整数')
|
|
|
+ .positive('区县ID必须是正整数')
|
|
|
+ .default(0)
|
|
|
+ .openapi({
|
|
|
+ description: '收货区县ID',
|
|
|
+ example: 110105
|
|
|
+ }),
|
|
|
+ receiverTown: z.coerce.number<number>()
|
|
|
+ .int('街道ID必须是整数')
|
|
|
+ .positive('街道ID必须是正整数')
|
|
|
+ .default(0)
|
|
|
+ .openapi({
|
|
|
+ description: '收货街道ID',
|
|
|
+ example: 110105001
|
|
|
+ }),
|
|
|
+ state: z.coerce.number<number>()
|
|
|
+ .int('状态必须是整数')
|
|
|
+ .min(1, '状态最小值为1')
|
|
|
+ .max(3, '状态最大值为3')
|
|
|
+ .default(1)
|
|
|
+ .openapi({
|
|
|
+ description: '状态:1正常,2禁用,3删除',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ isDefault: z.coerce.number<number>()
|
|
|
+ .int('是否默认必须是整数')
|
|
|
+ .min(0, '最小值为0')
|
|
|
+ .max(1, '最大值为1')
|
|
|
+ .default(0)
|
|
|
+ .openapi({
|
|
|
+ description: '是否默认地址:0否,1是',
|
|
|
+ example: 0
|
|
|
+ }),
|
|
|
+ createdBy: z.number()
|
|
|
+ .int('创建人ID必须是整数')
|
|
|
+ .positive('创建人ID必须是正整数')
|
|
|
+ .nullable()
|
|
|
+ .openapi({
|
|
|
+ description: '创建用户ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ updatedBy: z.number()
|
|
|
+ .int('更新人ID必须是整数')
|
|
|
+ .positive('更新人ID必须是正整数')
|
|
|
+ .nullable()
|
|
|
+ .openapi({
|
|
|
+ description: '更新用户ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ createdAt: z.coerce.date('创建时间格式不正确')
|
|
|
+ .openapi({
|
|
|
+ description: '创建时间',
|
|
|
+ example: '2024-01-01T12:00:00Z'
|
|
|
+ }),
|
|
|
+ updatedAt: z.coerce.date('更新时间格式不正确')
|
|
|
+ .openapi({
|
|
|
+ description: '更新时间',
|
|
|
+ example: '2024-01-01T12:00:00Z'
|
|
|
+ }),
|
|
|
+ user: UserSchema.optional().openapi({
|
|
|
+ description: '关联用户信息'
|
|
|
+ }),
|
|
|
+ province: AreaSchema.optional().openapi({
|
|
|
+ description: '关联省份信息'
|
|
|
+ }),
|
|
|
+ city: AreaSchema.optional().openapi({
|
|
|
+ description: '关联城市信息'
|
|
|
+ }),
|
|
|
+ district: AreaSchema.optional().openapi({
|
|
|
+ description: '关联区县信息'
|
|
|
+ }),
|
|
|
+ town: AreaSchema.optional().openapi({
|
|
|
+ description: '关联街道信息'
|
|
|
+ })
|
|
|
+});
|
|
|
+
|
|
|
+// 创建DTO
|
|
|
+export const CreateDeliveryAddressDto = z.object({
|
|
|
+ userId: z.number()
|
|
|
+ .int('用户ID必须是整数')
|
|
|
+ .positive('用户ID必须是正整数')
|
|
|
+ .openapi({
|
|
|
+ description: '用户ID',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ name: z.string()
|
|
|
+ .min(1, '收货人姓名不能为空')
|
|
|
+ .max(255, '收货人姓名最多255个字符')
|
|
|
+ .openapi({
|
|
|
+ description: '收货人姓名',
|
|
|
+ example: '张三'
|
|
|
+ }),
|
|
|
+ phone: z.string()
|
|
|
+ .regex(/^1[3-9]\d{9}$/, '请输入正确的手机号')
|
|
|
+ .openapi({
|
|
|
+ description: '收货人手机号',
|
|
|
+ example: '13800138000'
|
|
|
+ }),
|
|
|
+ address: z.string()
|
|
|
+ .min(1, '详细地址不能为空')
|
|
|
+ .max(255, '详细地址最多255个字符')
|
|
|
+ .openapi({
|
|
|
+ description: '详细地址',
|
|
|
+ example: '北京市朝阳区建国门外大街1号'
|
|
|
+ }),
|
|
|
+ receiverProvince: z.coerce.number<number>()
|
|
|
+ .int('省份ID必须是整数')
|
|
|
+ .positive('省份ID必须是正整数')
|
|
|
+ .default(0)
|
|
|
+ .openapi({
|
|
|
+ description: '收货省份ID',
|
|
|
+ example: 110000
|
|
|
+ }),
|
|
|
+ receiverCity: z.coerce.number<number>()
|
|
|
+ .int('城市ID必须是整数')
|
|
|
+ .positive('城市ID必须是正整数')
|
|
|
+ .default(0)
|
|
|
+ .openapi({
|
|
|
+ description: '收货城市ID',
|
|
|
+ example: 110100
|
|
|
+ }),
|
|
|
+ receiverDistrict: z.coerce.number<number>()
|
|
|
+ .int('区县ID必须是整数')
|
|
|
+ .positive('区县ID必须是正整数')
|
|
|
+ .default(0)
|
|
|
+ .openapi({
|
|
|
+ description: '收货区县ID',
|
|
|
+ example: 110105
|
|
|
+ }),
|
|
|
+ receiverTown: z.coerce.number<number>()
|
|
|
+ .int('街道ID必须是整数')
|
|
|
+ .positive('街道ID必须是正整数')
|
|
|
+ .default(0)
|
|
|
+ .openapi({
|
|
|
+ description: '收货街道ID',
|
|
|
+ example: 110105001
|
|
|
+ }),
|
|
|
+ isDefault: z.coerce.number<number>()
|
|
|
+ .int('是否默认必须是整数')
|
|
|
+ .min(0, '最小值为0')
|
|
|
+ .max(1, '最大值为1')
|
|
|
+ .default(0)
|
|
|
+ .openapi({
|
|
|
+ description: '是否默认地址:0否,1是',
|
|
|
+ example: 0
|
|
|
+ })
|
|
|
+});
|
|
|
+
|
|
|
+// 更新DTO
|
|
|
+export const UpdateDeliveryAddressDto = z.object({
|
|
|
+ name: z.string()
|
|
|
+ .min(1, '收货人姓名不能为空')
|
|
|
+ .max(255, '收货人姓名最多255个字符')
|
|
|
+ .optional()
|
|
|
+ .openapi({
|
|
|
+ description: '收货人姓名',
|
|
|
+ example: '张三'
|
|
|
+ }),
|
|
|
+ phone: z.string()
|
|
|
+ .regex(/^1[3-9]\d{9}$/, '请输入正确的手机号')
|
|
|
+ .optional()
|
|
|
+ .openapi({
|
|
|
+ description: '收货人手机号',
|
|
|
+ example: '13800138000'
|
|
|
+ }),
|
|
|
+ address: z.string()
|
|
|
+ .min(1, '详细地址不能为空')
|
|
|
+ .max(255, '详细地址最多255个字符')
|
|
|
+ .optional()
|
|
|
+ .openapi({
|
|
|
+ description: '详细地址',
|
|
|
+ example: '北京市朝阳区建国门外大街1号'
|
|
|
+ }),
|
|
|
+ receiverProvince: z.coerce.number<number>()
|
|
|
+ .int('省份ID必须是整数')
|
|
|
+ .positive('省份ID必须是正整数')
|
|
|
+ .optional()
|
|
|
+ .openapi({
|
|
|
+ description: '收货省份ID',
|
|
|
+ example: 110000
|
|
|
+ }),
|
|
|
+ receiverCity: z.coerce.number<number>()
|
|
|
+ .int('城市ID必须是整数')
|
|
|
+ .positive('城市ID必须是正整数')
|
|
|
+ .optional()
|
|
|
+ .openapi({
|
|
|
+ description: '收货城市ID',
|
|
|
+ example: 110100
|
|
|
+ }),
|
|
|
+ receiverDistrict: z.coerce.number<number>()
|
|
|
+ .int('区县ID必须是整数')
|
|
|
+ .positive('区县ID必须是正整数')
|
|
|
+ .optional()
|
|
|
+ .openapi({
|
|
|
+ description: '收货区县ID',
|
|
|
+ example: 110105
|
|
|
+ }),
|
|
|
+ receiverTown: z.coerce.number<number>()
|
|
|
+ .int('街道ID必须是整数')
|
|
|
+ .positive('街道ID必须是正整数')
|
|
|
+ .optional()
|
|
|
+ .openapi({
|
|
|
+ description: '收货街道ID',
|
|
|
+ example: 110105001
|
|
|
+ }),
|
|
|
+ state: z.coerce.number<number>()
|
|
|
+ .int('状态必须是整数')
|
|
|
+ .min(1, '状态最小值为1')
|
|
|
+ .max(3, '状态最大值为3')
|
|
|
+ .optional()
|
|
|
+ .openapi({
|
|
|
+ description: '状态:1正常,2禁用,3删除',
|
|
|
+ example: 1
|
|
|
+ }),
|
|
|
+ isDefault: z.coerce.number<number>()
|
|
|
+ .int('是否默认必须是整数')
|
|
|
+ .min(0, '最小值为0')
|
|
|
+ .max(1, '最大值为1')
|
|
|
+ .optional()
|
|
|
+ .openapi({
|
|
|
+ description: '是否默认地址:0否,1是',
|
|
|
+ example: 0
|
|
|
+ })
|
|
|
+});
|