dto.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { ApiProperty } from '@nestjs/swagger';
  2. import { IsBoolean, IsNotEmpty, IsOptional, IsString, Length } from 'class-validator';
  3. export class LoginDto {
  4. @ApiProperty({ required: true })
  5. @IsString()
  6. @IsNotEmpty({ message: '用户名不能为空' })
  7. username: string;
  8. @ApiProperty({ required: true })
  9. @IsString()
  10. @IsNotEmpty({ message: '密码不能为空' })
  11. password: string;
  12. }
  13. export class RegisterUserDto {
  14. @ApiProperty({ required: true })
  15. @IsString()
  16. @Length(6, 20, {
  17. message: `用户名长度必须是$constraint1到$constraint2之间,当前传递的值是$value`,
  18. })
  19. username: string;
  20. @ApiProperty({ required: true })
  21. @IsString()
  22. @Length(6, 20, { message: `密码长度必须是$constraint1到$constraint2之间` })
  23. password: string;
  24. }
  25. export class LoginUserDto {
  26. @ApiProperty({ required: true })
  27. @IsString()
  28. @Length(5, 20, {
  29. message: `用户名长度必须是$constraint1到$constraint2之间,当前传递的值是$value`,
  30. })
  31. username: string;
  32. @ApiProperty({ required: true })
  33. @IsString()
  34. @Length(6, 20, { message: `密码长度必须是$constraint1到$constraint2之间` })
  35. password: string;
  36. @ApiProperty({ required: false })
  37. @IsBoolean()
  38. @IsOptional()
  39. isQuick?: boolean;
  40. @ApiProperty({ required: false })
  41. @IsString()
  42. @IsOptional()
  43. captcha?: string;
  44. }
  45. export class ChangePasswordDto {
  46. @ApiProperty({ required: true })
  47. @IsString()
  48. @IsNotEmpty({ message: '旧密码不能为空' })
  49. oldPassword: string;
  50. @ApiProperty({ required: true })
  51. @IsString()
  52. @IsNotEmpty({ message: '新密码不能为空' })
  53. newPassword: string;
  54. }