2022-10-09 22:30:32 +02:00
|
|
|
import { Expose, plainToClass } from "class-transformer";
|
2022-12-05 10:02:19 +01:00
|
|
|
import {
|
|
|
|
|
IsEmail,
|
|
|
|
|
IsNotEmpty,
|
|
|
|
|
IsString,
|
|
|
|
|
Length,
|
|
|
|
|
Matches,
|
|
|
|
|
} from "class-validator";
|
2022-10-09 22:30:32 +02:00
|
|
|
|
2022-10-10 17:58:42 +02:00
|
|
|
export class UserDTO {
|
2022-10-09 22:30:32 +02:00
|
|
|
@Expose()
|
|
|
|
|
id: string;
|
|
|
|
|
|
|
|
|
|
@Expose()
|
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;
|
2022-10-09 22:30:32 +02:00
|
|
|
|
|
|
|
|
@Expose()
|
|
|
|
|
@IsEmail()
|
|
|
|
|
email: string;
|
|
|
|
|
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@IsString()
|
|
|
|
|
password: string;
|
|
|
|
|
|
2022-12-01 23:07:49 +01:00
|
|
|
@Expose()
|
|
|
|
|
isAdmin: boolean;
|
|
|
|
|
|
2022-10-10 17:58:42 +02:00
|
|
|
from(partial: Partial<UserDTO>) {
|
|
|
|
|
return plainToClass(UserDTO, partial, { excludeExtraneousValues: true });
|
2022-10-09 22:30:32 +02:00
|
|
|
}
|
2022-12-05 10:02:19 +01:00
|
|
|
|
|
|
|
|
fromList(partial: Partial<UserDTO>[]) {
|
|
|
|
|
return partial.map((part) =>
|
|
|
|
|
plainToClass(UserDTO, part, { excludeExtraneousValues: true })
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-10-09 22:30:32 +02:00
|
|
|
}
|