refactor: validate enum (#19943)
This commit is contained in:
+10
-19
@@ -1,10 +1,10 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { IsBoolean, IsEmail, IsEnum, IsNotEmpty, IsNumber, IsString, Min } from 'class-validator';
|
||||
import { IsEmail, IsNotEmpty, IsNumber, IsString, Min } from 'class-validator';
|
||||
import { User, UserAdmin } from 'src/database';
|
||||
import { UserAvatarColor, UserMetadataKey, UserStatus } from 'src/enum';
|
||||
import { UserMetadataItem } from 'src/types';
|
||||
import { Optional, PinCode, ValidateBoolean, ValidateUUID, toEmail, toSanitized } from 'src/validation';
|
||||
import { Optional, PinCode, ValidateBoolean, ValidateEnum, ValidateUUID, toEmail, toSanitized } from 'src/validation';
|
||||
|
||||
export class UserUpdateMeDto {
|
||||
@Optional()
|
||||
@@ -23,9 +23,7 @@ export class UserUpdateMeDto {
|
||||
@IsNotEmpty()
|
||||
name?: string;
|
||||
|
||||
@Optional({ nullable: true })
|
||||
@IsEnum(UserAvatarColor)
|
||||
@ApiProperty({ enumName: 'UserAvatarColor', enum: UserAvatarColor })
|
||||
@ValidateEnum({ enum: UserAvatarColor, name: 'UserAvatarColor', optional: true, nullable: true })
|
||||
avatarColor?: UserAvatarColor | null;
|
||||
}
|
||||
|
||||
@@ -34,7 +32,7 @@ export class UserResponseDto {
|
||||
name!: string;
|
||||
email!: string;
|
||||
profileImagePath!: string;
|
||||
@ApiProperty({ enumName: 'UserAvatarColor', enum: UserAvatarColor })
|
||||
@ValidateEnum({ enum: UserAvatarColor, name: 'UserAvatarColor' })
|
||||
avatarColor!: UserAvatarColor;
|
||||
profileChangedAt!: Date;
|
||||
}
|
||||
@@ -84,9 +82,7 @@ export class UserAdminCreateDto {
|
||||
@IsString()
|
||||
name!: string;
|
||||
|
||||
@Optional({ nullable: true })
|
||||
@IsEnum(UserAvatarColor)
|
||||
@ApiProperty({ enumName: 'UserAvatarColor', enum: UserAvatarColor })
|
||||
@ValidateEnum({ enum: UserAvatarColor, name: 'UserAvatarColor', optional: true, nullable: true })
|
||||
avatarColor?: UserAvatarColor | null;
|
||||
|
||||
@Optional({ nullable: true })
|
||||
@@ -103,12 +99,10 @@ export class UserAdminCreateDto {
|
||||
@ValidateBoolean({ optional: true })
|
||||
shouldChangePassword?: boolean;
|
||||
|
||||
@Optional()
|
||||
@IsBoolean()
|
||||
@ValidateBoolean({ optional: true })
|
||||
notify?: boolean;
|
||||
|
||||
@Optional()
|
||||
@IsBoolean()
|
||||
@ValidateBoolean({ optional: true })
|
||||
isAdmin?: boolean;
|
||||
}
|
||||
|
||||
@@ -131,9 +125,7 @@ export class UserAdminUpdateDto {
|
||||
@IsNotEmpty()
|
||||
name?: string;
|
||||
|
||||
@Optional({ nullable: true })
|
||||
@IsEnum(UserAvatarColor)
|
||||
@ApiProperty({ enumName: 'UserAvatarColor', enum: UserAvatarColor })
|
||||
@ValidateEnum({ enum: UserAvatarColor, name: 'UserAvatarColor', optional: true, nullable: true })
|
||||
avatarColor?: UserAvatarColor | null;
|
||||
|
||||
@Optional({ nullable: true })
|
||||
@@ -150,8 +142,7 @@ export class UserAdminUpdateDto {
|
||||
@ApiProperty({ type: 'integer', format: 'int64' })
|
||||
quotaSizeInBytes?: number | null;
|
||||
|
||||
@Optional()
|
||||
@IsBoolean()
|
||||
@ValidateBoolean({ optional: true })
|
||||
isAdmin?: boolean;
|
||||
}
|
||||
|
||||
@@ -172,7 +163,7 @@ export class UserAdminResponseDto extends UserResponseDto {
|
||||
quotaSizeInBytes!: number | null;
|
||||
@ApiProperty({ type: 'integer', format: 'int64' })
|
||||
quotaUsageInBytes!: number | null;
|
||||
@ApiProperty({ enumName: 'UserStatus', enum: UserStatus })
|
||||
@ValidateEnum({ enum: UserStatus, name: 'UserStatus' })
|
||||
status!: string;
|
||||
license!: UserLicense | null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user