Files
swiss-datashare/backend/src/user/dto/user.dto.ts

38 lines
787 B
TypeScript
Raw Normal View History

import { Expose, plainToClass } from "class-transformer";
2022-12-05 15:53:24 +01:00
import { IsEmail, Length, Matches, MinLength } from "class-validator";
2022-10-10 17:58:42 +02:00
export class UserDTO {
@Expose()
id: string;
2022-12-05 10:02:19 +01:00
@Expose()
@Matches("^[a-zA-Z0-9_.]*$", undefined, {
message: "Username can only contain letters, numbers, dots and underscores",
})
@Length(3, 32)
2022-12-01 23:07:49 +01:00
username: string;
@Expose()
@IsEmail()
email: string;
2022-12-05 15:53:24 +01:00
@MinLength(8)
password: string;
2022-12-01 23:07:49 +01:00
@Expose()
isAdmin: boolean;
@Expose()
totpVerified: boolean;
2022-10-10 17:58:42 +02:00
from(partial: Partial<UserDTO>) {
return plainToClass(UserDTO, partial, { excludeExtraneousValues: true });
}
2022-12-05 10:02:19 +01:00
fromList(partial: Partial<UserDTO>[]) {
return partial.map((part) =>
plainToClass(UserDTO, part, { excludeExtraneousValues: true })
);
}
}