forked from Yara724/api
82 lines
2.0 KiB
TypeScript
82 lines
2.0 KiB
TypeScript
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
|
import { IsNotEmpty, IsOptional, IsString, MaxLength } from "class-validator";
|
|
import { RoleEnum } from "src/Types&Enums/role.enum";
|
|
|
|
export class LoginActorDto {
|
|
@ApiProperty({ example: RoleEnum, type: "array", description: "LOGIN_DTO" })
|
|
role: RoleEnum[];
|
|
|
|
@ApiPropertyOptional({
|
|
description:
|
|
"Actor email or username. For field experts you may also send nationalCode instead.",
|
|
})
|
|
@IsOptional()
|
|
@IsString()
|
|
username?: string;
|
|
|
|
@ApiPropertyOptional({
|
|
description: "Alias for username when logging in with email.",
|
|
})
|
|
@IsOptional()
|
|
@IsString()
|
|
email?: string;
|
|
|
|
@ApiPropertyOptional({
|
|
example: "4311402422",
|
|
description:
|
|
"10-digit national ID. Alternative login identifier for actors (especially field experts without email).",
|
|
})
|
|
@IsOptional()
|
|
@IsString()
|
|
nationalCode?: string;
|
|
|
|
@ApiProperty({})
|
|
password: string;
|
|
|
|
@ApiProperty({
|
|
example: "f47ac10b-58cc-4372-a567-0e02b2c3d479",
|
|
description: "Captcha id from GET /actor/captcha.",
|
|
})
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
@MaxLength(64)
|
|
captchaId: string;
|
|
|
|
@ApiProperty({
|
|
example: "a7bx2",
|
|
description: "Characters shown in the captcha image.",
|
|
})
|
|
@IsString()
|
|
@IsNotEmpty()
|
|
@MaxLength(16)
|
|
captcha: string;
|
|
}
|
|
|
|
export class LoginActorDtoRs extends LoginActorDto {
|
|
private readonly userId;
|
|
constructor(userData) {
|
|
super();
|
|
this.userId = userData._id;
|
|
this.role = userData.role;
|
|
this.username = userData.email;
|
|
this.clientKey = userData.clientKey;
|
|
this.token = userData.token;
|
|
this.refreshToken = userData.refreshToken;
|
|
}
|
|
|
|
@ApiProperty({ type: "string", description: "LOGIN_DTO_RS" })
|
|
fullName: string;
|
|
|
|
@ApiProperty({ type: "string", description: "LOGIN_DTO_RS" })
|
|
role: RoleEnum[];
|
|
|
|
@ApiProperty({ type: "string", description: "LOGIN_DTO_RS" })
|
|
token: string;
|
|
|
|
@ApiProperty({ type: "string", description: "LOGIN_DTO_RS" })
|
|
refreshToken: string;
|
|
|
|
@ApiProperty({ type: "string", description: "LOGIN_DTO_RS" })
|
|
clientKey: string;
|
|
}
|