user.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {
  2. IsInt,
  3. Length,
  4. Matches,
  5. Allow,
  6. IsEmail,
  7. ArrayNotEmpty,
  8. ValidateIf,
  9. IsOptional,
  10. IsIn,
  11. IsNumberString,
  12. } from 'class-validator';
  13. import { Expose } from 'class-transformer';
  14. import { PageGetDto } from '../../comm';
  15. export class CreateUserDto {
  16. @IsInt()
  17. @Expose()
  18. departmentId: number;
  19. @Length(2)
  20. @Expose()
  21. name: string;
  22. @Matches(/^[a-z0-9A-Z]+$/)
  23. @Length(6, 20)
  24. @Expose()
  25. username: string;
  26. @Allow()
  27. @Expose()
  28. nickName: string;
  29. @ArrayNotEmpty()
  30. @Expose()
  31. roles: number[];
  32. @Allow()
  33. @Expose()
  34. remark: string;
  35. @ValidateIf((_o, v) => { return !(v === '' || v === undefined || v === null); })
  36. @IsEmail()
  37. @Expose()
  38. email: string;
  39. @Allow()
  40. @Expose()
  41. phone: string;
  42. @IsOptional()
  43. @IsIn([ 0, 1 ])
  44. @Expose()
  45. status: number;
  46. }
  47. export class UpdateUserDto extends CreateUserDto {
  48. @IsInt()
  49. @Expose()
  50. id: number;
  51. }
  52. export class InfoUserDto {
  53. @IsNumberString()
  54. @Expose()
  55. userId: string;
  56. }
  57. export class DeleteUserDto {
  58. @ArrayNotEmpty()
  59. @Expose()
  60. userIds: number[];
  61. }
  62. export class QueryUserDto extends PageGetDto {
  63. @IsOptional()
  64. @IsNumberString()
  65. @Expose()
  66. departmentId: string;
  67. }