Files
Picsur/shared/src/dto/auth.dto.ts

69 lines
978 B
TypeScript
Raw Normal View History

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';
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;
}
export class AuthDeleteResponse extends EUser {}
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()
@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
}