| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2024-06-17 20:12:31 |
| 4 | * @LastEditTime: 2025-05-06 15:49:03 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: 用户 |
| 7 | */ |
| 8 | import { ApiProperty } from '@nestjs/swagger'; |
| 9 | import { Expose } from 'class-transformer'; |
| 10 | import { IsEnum, IsOptional, IsPhoneNumber, IsString } from 'class-validator'; |
| 11 | import { User } from '../../db/schema/user.schema'; |
| 12 | import { GenderEnum } from '../../global/enum/all.enum'; |
| 13 | |
| 14 | export class WxLoginDto { |
| 15 | @ApiProperty({ title: '微信登录的code', required: true }) |
| 16 | @IsString({ message: 'code' }) |
| 17 | @Expose() |
| 18 | code: string; |
| 19 | } |
| 20 | |
| 21 | export class PhoneDto { |
| 22 | @ApiProperty({ title: '手机号', required: true }) |
| 23 | @IsPhoneNumber('CN', { message: '手机号' }) |
| 24 | @Expose() |
| 25 | readonly phone: string; |
| 26 | } |
| 27 | |
| 28 | export class LoginByPhoneDto { |
| 29 | @ApiProperty({ title: '手机号', required: true }) |
| 30 | @IsPhoneNumber('CN', { message: '手机号' }) |
| 31 | @Expose() |
| 32 | readonly phone: string; |
| 33 | |
| 34 | @ApiProperty({ required: true }) |
| 35 | @IsString({ message: '短信验证码' }) |
| 36 | @Expose() |
| 37 | readonly code: string; |
| 38 | } |
| 39 | |
| 40 | export class GetRegisterCodeDto { |
| 41 | @ApiProperty({ required: true }) |
| 42 | @IsPhoneNumber('CN', { message: '手机号' }) |
| 43 | @Expose() |
| 44 | readonly phone: string; |
| 45 | } |
| 46 | |
| 47 | // 手机号注册 |
| 48 | export class PhoneRegisterDto { |
| 49 | @ApiProperty({ required: true, title: '短信验证码' }) |
| 50 | @IsString({ message: '短信验证码' }) |
| 51 | @Expose() |
| 52 | readonly code: string; |
| 53 | |
| 54 | @ApiProperty({ required: true, title: '手机号' }) |
| 55 | @IsPhoneNumber('CN', { message: '手机号' }) |
| 56 | @Expose() |
| 57 | readonly phone: string; |
| 58 | |
| 59 | @ApiProperty({ required: true, title: '密码' }) |
| 60 | @IsString({ message: '密码' }) |
| 61 | @Expose() |
| 62 | readonly password: string; |
| 63 | } |
| 64 | |
| 65 | // 手机号验证码登录 |
| 66 | export class PhoneLoginByCodeDto { |
| 67 | @ApiProperty({ required: true }) |
| 68 | @IsPhoneNumber('CN', { message: '手机号' }) |
| 69 | @Expose() |
| 70 | readonly phone: string; |
| 71 | |
| 72 | @ApiProperty({ required: true }) |
| 73 | @IsString({ message: '短信验证码' }) |
| 74 | @Expose() |
| 75 | readonly code: string; |
| 76 | |
| 77 | @ApiProperty({ required: false }) |
| 78 | @IsOptional() |
| 79 | @Expose() |
| 80 | readonly inviteCode?: string; |
| 81 | } |
| 82 | |
| 83 | export class PhoneLoginByAuthDto { |
| 84 | @ApiProperty({ required: true }) |
| 85 | @IsString({ message: '授权码' }) |
| 86 | @Expose() |
| 87 | readonly accessToken: string; |
| 88 | |
| 89 | @ApiProperty({ required: false }) |
| 90 | @IsOptional() |
| 91 | @Expose() |
| 92 | readonly inviteCode?: string; |
| 93 | } |
| 94 | |
| 95 | export class LoginByPasswordDto { |
| 96 | @ApiProperty({ title: '手机号', required: true }) |
| 97 | @IsPhoneNumber('CN', { message: '手机号' }) |
| 98 | @Expose() |
| 99 | readonly phone: string; |
| 100 | |
| 101 | @ApiProperty({ required: true }) |
| 102 | @IsString({ message: '密码' }) |
| 103 | @Expose() |
| 104 | readonly password: string; |
| 105 | } |
| 106 | |
| 107 | export class ChangePasswordDto { |
| 108 | @ApiProperty({ required: true }) |
| 109 | @IsString({ message: '密码' }) |
| 110 | @Expose() |
| 111 | readonly password: string; |
| 112 | } |
| 113 | |
| 114 | export class UpdateUserInfoDto { |
| 115 | @ApiProperty({ title: '昵称' }) |
| 116 | @IsString({ message: '昵称' }) |
| 117 | @IsOptional() |
| 118 | @Expose() |
| 119 | readonly name?: string; |
| 120 | |
| 121 | @ApiProperty({ title: '头像' }) |
| 122 | @IsString({ message: '头像' }) |
| 123 | @IsOptional() |
| 124 | @Expose() |
| 125 | avatar?: string; |
| 126 | |
| 127 | @ApiProperty({ required: false, title: '性别' }) |
| 128 | @IsEnum(GenderEnum, { message: '性别' }) |
| 129 | @IsOptional() |
| 130 | @Expose() |
| 131 | readonly gender?: GenderEnum; |
| 132 | |
| 133 | @ApiProperty({ title: '简介' }) |
| 134 | @IsString({ message: '简介' }) |
| 135 | @IsOptional() |
| 136 | @Expose() |
| 137 | readonly desc?: string; |
| 138 | } |
| 139 | |
| 140 | export class UserResDto implements Partial<User> { |
| 141 | @ApiProperty({ title: '用户ID', required: true }) |
| 142 | id: string; |
| 143 | |
| 144 | @ApiProperty({ title: '用户名', required: true }) |
| 145 | name: string; |
| 146 | |
| 147 | @ApiProperty({ title: '手机号', required: true }) |
| 148 | phone: string; |
| 149 | |
| 150 | @ApiProperty({ title: '性别', enum: GenderEnum, required: false }) |
| 151 | gender?: GenderEnum; |
| 152 | |
| 153 | @ApiProperty({ title: '头像图片链接', required: false }) |
| 154 | avatar?: string; |
| 155 | |
| 156 | @ApiProperty({ title: '简介', required: false }) |
| 157 | desc?: string; |
| 158 | } |
| 159 | |
| 160 | export class PhoneRegisterResDto { |
| 161 | @ApiProperty({ title: '用户信息', required: true }) |
| 162 | userInfo: UserResDto; |
| 163 | |
| 164 | @ApiProperty({ title: '登录的Ttoken信息', required: true }) |
| 165 | token: string = 'Beare sss'; |
| 166 | } |
| 167 | |
| 168 | export class SetWxInfoDto { |
| 169 | @ApiProperty({ required: true }) |
| 170 | @IsString({ message: '微信授权码' }) |
| 171 | @Expose() |
| 172 | readonly code: string; |
| 173 | } |
| 174 | |
| 175 | // 手机号验证码登录 |
| 176 | export class PhoneLoginByGzhDto { |
| 177 | @ApiProperty({ required: true }) |
| 178 | @IsPhoneNumber('CN', { message: '手机号' }) |
| 179 | @Expose() |
| 180 | readonly phone: string; |
| 181 | |
| 182 | @ApiProperty({ required: true }) |
| 183 | @IsString({ message: '短信验证码' }) |
| 184 | @Expose() |
| 185 | readonly code: string; |
| 186 | |
| 187 | @ApiProperty({ required: true }) |
| 188 | @IsString({ message: '二维码票据' }) |
| 189 | @Expose() |
| 190 | readonly openId: string; |
| 191 | |
| 192 | @ApiProperty({ required: false }) |
| 193 | @IsOptional() |
| 194 | @Expose() |
| 195 | readonly inviteCode?: string; |
| 196 | } |
| 197 |