Files
Picsur/shared/src/dto/auth.dto.ts
2022-02-28 10:29:40 +01:00

80 lines
1.1 KiB
TypeScript

import {
IsBoolean,
IsDefined,
IsNotEmpty,
IsOptional,
IsString,
IsInt,
ValidateNested,
} from 'class-validator';
import { EUser } from '../entities/user.entity';
import { Type } from 'class-transformer';
// Api
export class AuthLoginRequest {
@IsNotEmpty()
@IsString()
username: string;
@IsNotEmpty()
@IsString()
password: string;
}
export class AuthLoginResponse {
@IsString()
@IsDefined()
access_token: string;
}
export class AuthRegisterRequest {
@IsString()
@IsNotEmpty()
username: string;
@IsString()
@IsNotEmpty()
password: string;
@IsBoolean()
@IsOptional()
isAdmin?: boolean;
}
export class AuthDeleteRequest {
@IsString()
@IsNotEmpty()
username: string;
}
export class AuthDeleteResponse extends EUser {}
export class AuthMeResponse {
@IsDefined()
@ValidateNested()
@Type(() => EUser)
user: EUser;
@IsString()
@IsDefined()
newJwtToken: string;
}
// Extra
export class JwtDataDto {
@IsDefined()
@ValidateNested()
@Type(() => EUser)
user: EUser;
@IsOptional()
@IsInt()
iat?: number;
@IsOptional()
@IsInt()
exp?: number;
}