| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- import { z } from '@hono/zod-openapi';
- import { UserSchema } from '@d8d/user-module/schemas';
- import { getAreaSchema } from '@d8d/geo-areas/schemas';
- // 状态枚举
- export const DeliveryAddressStatusEnum = {
- NORMAL: 1,
- DISABLED: 2,
- DELETED: 3
- } as const;
- export const IsDefaultEnum = {
- NOT_DEFAULT: 0,
- IS_DEFAULT: 1
- } as const;
- // 用户专用基础实体Schema - 移除userId字段
- export const UserDeliveryAddressSchema = 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
- }),
- // 注意:移除了userId字段,自动使用当前登录用户ID
- 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: getAreaSchema.optional().openapi({
- description: '关联省份信息'
- }),
- city: getAreaSchema.optional().openapi({
- description: '关联城市信息'
- }),
- district: getAreaSchema.optional().openapi({
- description: '关联区县信息'
- }),
- town: getAreaSchema.optional().openapi({
- description: '关联街道信息'
- })
- });
- // 用户专用创建DTO - 移除userId字段
- export const CreateUserDeliveryAddressDto = z.object({
- // 注意:移除了userId字段,自动使用当前登录用户ID
- 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 UpdateUserDeliveryAddressDto = 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
- })
- });
|