2022-02-21 14:53:21 +01:00
|
|
|
import {
|
|
|
|
|
IsBoolean,
|
2022-02-24 11:22:28 +01:00
|
|
|
IsDefined,
|
2022-02-21 14:53:21 +01:00
|
|
|
IsNotEmpty,
|
|
|
|
|
IsOptional,
|
|
|
|
|
IsString,
|
2022-02-25 12:22:00 +01:00
|
|
|
IsInt,
|
2022-02-21 14:53:21 +01:00
|
|
|
ValidateNested,
|
|
|
|
|
} from 'class-validator';
|
2022-02-26 16:06:32 +01:00
|
|
|
import { EUser } from '../entities/user.entity';
|
|
|
|
|
import { Type } from 'class-transformer';
|
2022-02-21 14:53:21 +01:00
|
|
|
|
2022-02-25 12:22:00 +01:00
|
|
|
// Api
|
|
|
|
|
|
|
|
|
|
export class AuthLoginRequest {
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@IsString()
|
|
|
|
|
username: string;
|
|
|
|
|
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
@IsString()
|
|
|
|
|
password: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class AuthLoginResponse {
|
2022-02-21 14:53:21 +01:00
|
|
|
@IsString()
|
2022-02-24 11:22:28 +01:00
|
|
|
@IsDefined()
|
2022-02-21 14:53:21 +01:00
|
|
|
access_token: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-25 12:22:00 +01:00
|
|
|
export class AuthRegisterRequest {
|
2022-02-21 14:53:21 +01:00
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
username: string;
|
|
|
|
|
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
password: string;
|
|
|
|
|
|
|
|
|
|
@IsBoolean()
|
|
|
|
|
@IsOptional()
|
|
|
|
|
isAdmin?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-25 12:22:00 +01:00
|
|
|
export class AuthDeleteRequest {
|
2022-02-21 14:53:21 +01:00
|
|
|
@IsString()
|
|
|
|
|
@IsNotEmpty()
|
|
|
|
|
username: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-26 16:06:32 +01:00
|
|
|
export class AuthDeleteResponse extends EUser {}
|
2022-02-25 12:22:00 +01:00
|
|
|
|
2022-02-28 10:29:40 +01:00
|
|
|
export class AuthMeResponse {
|
|
|
|
|
@IsDefined()
|
|
|
|
|
@ValidateNested()
|
|
|
|
|
@Type(() => EUser)
|
|
|
|
|
user: EUser;
|
|
|
|
|
|
|
|
|
|
@IsString()
|
|
|
|
|
@IsDefined()
|
|
|
|
|
newJwtToken: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-25 12:22:00 +01:00
|
|
|
// Extra
|
|
|
|
|
|
2022-02-21 14:53:21 +01:00
|
|
|
export class JwtDataDto {
|
2022-02-24 11:22:28 +01:00
|
|
|
@IsDefined()
|
2022-02-26 16:06:32 +01:00
|
|
|
@ValidateNested()
|
|
|
|
|
@Type(() => EUser)
|
|
|
|
|
user: EUser;
|
2022-02-25 12:22:00 +01:00
|
|
|
|
|
|
|
|
@IsOptional()
|
|
|
|
|
@IsInt()
|
|
|
|
|
iat?: number;
|
|
|
|
|
|
|
|
|
|
@IsOptional()
|
|
|
|
|
@IsInt()
|
|
|
|
|
exp?: number;
|
2022-02-21 14:53:21 +01:00
|
|
|
}
|