parent
4bd562ef17
commit
3763a85613
@ -0,0 +1,113 @@ |
||||
/* * |
||||
* * @name: register.dto.ts |
||||
* * @description: 注册接口的参数验证 |
||||
* * @author: x7129 |
||||
* * @date: 2023-03-23 15:01 |
||||
* * */ |
||||
import { |
||||
IsDate, |
||||
IsEmail, |
||||
IsEnum, |
||||
IsNotEmpty, |
||||
IsNumber, |
||||
IsOptional, |
||||
IsPhoneNumber, |
||||
IsString, |
||||
Length, |
||||
Max, |
||||
Min, |
||||
} from 'class-validator'; |
||||
import { Type } from 'class-transformer'; |
||||
|
||||
// ? ?
|
||||
// ? 函数名称: 性别枚举
|
||||
// ? 函数用法:
|
||||
// ? ?
|
||||
|
||||
export enum sex { |
||||
'男' = 1, |
||||
'女' = 2, |
||||
'其他' = 3, |
||||
} |
||||
|
||||
// 此文件为参数验证演示
|
||||
// https://github.com/typestack/class-validator#usage
|
||||
// 这里有更多的验证方法
|
||||
export class RegisterEmailCheckoutEmailDto { |
||||
// @ 邮箱
|
||||
@Length(8, 128, { message: '请将邮箱长度控制在8到128位之间!' }) |
||||
@IsEmail({}, { message: '邮箱格式错误!' }) |
||||
@IsString({ message: '邮箱应为字符串格式!' }) |
||||
email: string; |
||||
} |
||||
export class RegisterEmailSignUpDto extends RegisterEmailCheckoutEmailDto { |
||||
// @ 验证码
|
||||
@Length(6, 6, { message: '验证码是6位字符!' }) |
||||
code: string; |
||||
|
||||
// @ 密码
|
||||
@Length(8, 128, { message: '请将密码长度控制在8到128位之间!' }) |
||||
password: string; |
||||
|
||||
// @ 用户名
|
||||
@Length(8, 128, { message: '请将用户名长度控制在8到128位之间!' }) |
||||
usernmae: string; |
||||
|
||||
// @ 真实姓名
|
||||
@IsOptional() |
||||
@Length(2, 128, { message: '请将真实姓名长度控制在2到128位之间!' }) |
||||
realname: string; |
||||
|
||||
// @ 昵称
|
||||
@IsOptional() |
||||
@Length(1, 128, { message: '请将昵称长度控制在1到128位之间!' }) |
||||
nickname: string; |
||||
|
||||
// @ 生日
|
||||
@IsOptional() |
||||
@IsDate({ message: '生日是一个日期,如1999-12-24!' }) |
||||
@Type(() => Date) |
||||
birthday: number; |
||||
|
||||
// @ 性别
|
||||
@IsOptional() |
||||
@IsEnum(sex, { message: '性别必须为:' + Object.keys(sex) }) |
||||
sex: number; |
||||
|
||||
// @ 住址
|
||||
@IsOptional() |
||||
@Length(1, 128, { message: '请将住址长度控制在1到128位之间!' }) |
||||
address: string; |
||||
|
||||
// @ 国家/地区
|
||||
@IsOptional() |
||||
@Length(1, 128, { message: '请将国家/地区长度控制在1到128位之间!' }) |
||||
country: string; |
||||
|
||||
// @ 个人简介
|
||||
@IsOptional() |
||||
@Length(1, 128, { message: '请将个人简介长度控制在1到128位之间!' }) |
||||
profile: string; |
||||
|
||||
// @ github地址
|
||||
@IsOptional() |
||||
@Length(1, 128, { message: '请将github地址长度控制在1到128位之间!' }) |
||||
githubUrl: string; |
||||
|
||||
// @ 个人主页地址
|
||||
@IsOptional() |
||||
@Length(1, 128, { message: '请将个人主页地址长度控制在1到128位之间!' }) |
||||
personalUrl: string; |
||||
// @ 阿里账号
|
||||
@IsOptional() |
||||
@Length(1, 128, { message: '请将阿里账号长度控制在1到128位之间!' }) |
||||
alibabaId: string; |
||||
// @ 抖音账号
|
||||
@IsOptional() |
||||
@Length(1, 128, { message: '请将抖音账号长度控制在1到128位之间!' }) |
||||
tiktokId: string; |
||||
// @ 微博账号
|
||||
@IsOptional() |
||||
@Length(1, 128, { message: '请将微博账号长度控制在1到128位之间!' }) |
||||
weiboId: string; |
||||
} |
Loading…
Reference in new issue