The DTO I have looks like this:
export class UpdateUserDto {
@IsOptional()
@IsString({ message: MESSAGES.IS_INVALID })
@Length(3, 20, { message: MESSAGES.LENGTH })
username?: string;
@IsOptional()
@IsEnum(Role, { message: MESSAGES.IS_INVALID })
role?: Role;
@IsOptional()
@IsString({ message: MESSAGES.IS_INVALID })
@Length(3, 20, { message: MESSAGES.LENGTH })
firstName?: string;
@IsOptional()
@IsString({ message: MESSAGES.IS_INVALID })
@Length(4, 40, { message: MESSAGES.LENGTH })
lastName?: string;
}
My goal is to serialize the DTO based on the role of the user.
For example:
The user logged in as an admin, can send the role parameter in the request body, otherwise he cannot.
I tried @Expose, but it didn't work. (I don't have access to the user.role in the request)
How can I do this?