From 02fe538af484b971376e43f13690e079269b0f43 Mon Sep 17 00:00:00 2001 From: Artem-Darius Atlas Date: Thu, 29 Jun 2023 16:09:05 +0300 Subject: [PATCH] feat: added DTO classes for the auth service --- .../device/dto/elements/user-select.dto.ts | 15 ++++++++++++++ apps/auth/src/device/dto/fingerprint.dto.ts | 11 ++++++++++ apps/auth/src/device/dto/register.dto.ts | 18 +++++++++++++++++ apps/auth/src/device/dto/user.dto.ts | 20 +++++++++++++++++++ .../src/token/dto/generate-refresh.dto.ts | 19 ++++++++++++++++++ apps/auth/src/token/dto/refresh-token.dto.ts | 10 ++++++++++ apps/auth/src/user/dto/devices.dto.ts | 17 ++++++++++++++++ .../user/dto/elements/device-select.dto.ts | 19 ++++++++++++++++++ apps/auth/src/user/dto/uuid.dto.ts | 10 ++++++++++ 9 files changed, 139 insertions(+) create mode 100644 apps/auth/src/device/dto/elements/user-select.dto.ts create mode 100644 apps/auth/src/device/dto/fingerprint.dto.ts create mode 100644 apps/auth/src/device/dto/register.dto.ts create mode 100644 apps/auth/src/device/dto/user.dto.ts create mode 100644 apps/auth/src/token/dto/generate-refresh.dto.ts create mode 100644 apps/auth/src/token/dto/refresh-token.dto.ts create mode 100644 apps/auth/src/user/dto/devices.dto.ts create mode 100644 apps/auth/src/user/dto/elements/device-select.dto.ts create mode 100644 apps/auth/src/user/dto/uuid.dto.ts diff --git a/apps/auth/src/device/dto/elements/user-select.dto.ts b/apps/auth/src/device/dto/elements/user-select.dto.ts new file mode 100644 index 0000000..47738ea --- /dev/null +++ b/apps/auth/src/device/dto/elements/user-select.dto.ts @@ -0,0 +1,15 @@ +import { IsBoolean, IsOptional } from "class-validator"; + +export class UserSelectDto { + @IsOptional() + @IsBoolean() + public uuid?: boolean | null; + @IsOptional() + @IsBoolean() + public isBlocked?: boolean | null; + + constructor(uuid: boolean, isBlocked: boolean) { + this.uuid = uuid; + this.isBlocked = isBlocked; + } +} \ No newline at end of file diff --git a/apps/auth/src/device/dto/fingerprint.dto.ts b/apps/auth/src/device/dto/fingerprint.dto.ts new file mode 100644 index 0000000..d8c7001 --- /dev/null +++ b/apps/auth/src/device/dto/fingerprint.dto.ts @@ -0,0 +1,11 @@ +import { IsHexadecimal, Length } from "class-validator"; + +export class FingerprintDto { + @IsHexadecimal() + @Length(64, 64) + public fingerprint: string; + + constructor(fingerprint: string) { + this.fingerprint = fingerprint; + } +} \ No newline at end of file diff --git a/apps/auth/src/device/dto/register.dto.ts b/apps/auth/src/device/dto/register.dto.ts new file mode 100644 index 0000000..c99e977 --- /dev/null +++ b/apps/auth/src/device/dto/register.dto.ts @@ -0,0 +1,18 @@ +import { IsHexadecimal, IsString, IsUUID, Length } from "class-validator"; + +export class RegisterDto { + @IsHexadecimal() + @Length(64, 64) + public fingerprint: string; + @IsString() + @Length(0, 100) + public name: string; + @IsUUID(4) + public userUuid: string; + + constructor(fingerprint: string, name: string, userUuid: string) { + this.fingerprint = fingerprint; + this.name = name; + this.userUuid = userUuid; + } +} \ No newline at end of file diff --git a/apps/auth/src/device/dto/user.dto.ts b/apps/auth/src/device/dto/user.dto.ts new file mode 100644 index 0000000..87e75d1 --- /dev/null +++ b/apps/auth/src/device/dto/user.dto.ts @@ -0,0 +1,20 @@ +import { IsHexadecimal, IsOptional, Length, ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +import { UserSelectDto } from "./elements/user-select.dto"; + +export class UserDto { + @IsHexadecimal() + @Length(64, 64) + public fingerprint: string; + @IsOptional() + @ValidateNested({ each: false }) + @Type(() => UserSelectDto) + public select?: UserSelectDto | null; + + constructor(fingerprint: string, select?: UserSelectDto | null) { + this.fingerprint = fingerprint; + this.select = select; + } +} diff --git a/apps/auth/src/token/dto/generate-refresh.dto.ts b/apps/auth/src/token/dto/generate-refresh.dto.ts new file mode 100644 index 0000000..ce4525b --- /dev/null +++ b/apps/auth/src/token/dto/generate-refresh.dto.ts @@ -0,0 +1,19 @@ +import { IsHexadecimal, IsOptional, IsString, IsUUID, Length } from "class-validator"; + +export class GenerateRefreshDto { + @IsUUID(4) + public user_uuid: string; + @IsHexadecimal() + @Length(64, 64) + public device_fingerprint: string; + @IsOptional() + @IsString() + @Length(0, 100) + public device_name?: string | null; + + constructor(user_uuid: string, device_fingerprint: string, device_name?: string) { + this.user_uuid = user_uuid; + this.device_fingerprint = device_fingerprint; + this.device_name = device_name; + } +} \ No newline at end of file diff --git a/apps/auth/src/token/dto/refresh-token.dto.ts b/apps/auth/src/token/dto/refresh-token.dto.ts new file mode 100644 index 0000000..c4066df --- /dev/null +++ b/apps/auth/src/token/dto/refresh-token.dto.ts @@ -0,0 +1,10 @@ +import { IsString } from "class-validator"; + +export class RefreshTokenDto { + @IsString() + public refresh_token: string; + + constructor(refresh_token: string) { + this.refresh_token = refresh_token; + } +} \ No newline at end of file diff --git a/apps/auth/src/user/dto/devices.dto.ts b/apps/auth/src/user/dto/devices.dto.ts new file mode 100644 index 0000000..7da5eef --- /dev/null +++ b/apps/auth/src/user/dto/devices.dto.ts @@ -0,0 +1,17 @@ +import { IsOptional, IsUUID, ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; +import { DeviceSelectDto } from "./elements/device-select.dto"; + +export class DevicesDto { + @IsUUID(4) + public uuid: string; + @IsOptional() + @ValidateNested({ each: false }) + @Type(() => DeviceSelectDto) + public select?: DeviceSelectDto | null; + + constructor(uuid: string, select: DeviceSelectDto) { + this.uuid = uuid; + this.select = select; + } +} \ No newline at end of file diff --git a/apps/auth/src/user/dto/elements/device-select.dto.ts b/apps/auth/src/user/dto/elements/device-select.dto.ts new file mode 100644 index 0000000..a301c28 --- /dev/null +++ b/apps/auth/src/user/dto/elements/device-select.dto.ts @@ -0,0 +1,19 @@ +import { IsBoolean, IsOptional } from "class-validator"; + +export class DeviceSelectDto { + @IsOptional() + @IsBoolean() + public name?: boolean | null; + @IsOptional() + @IsBoolean() + public fingerprint?: boolean | null; + @IsOptional() + @IsBoolean() + public isBlocked?: boolean | null; + + constructor(name: boolean, fingerprint: boolean, isBlocked: boolean) { + this.name = name; + this.fingerprint = fingerprint; + this.isBlocked = isBlocked; + } +} \ No newline at end of file diff --git a/apps/auth/src/user/dto/uuid.dto.ts b/apps/auth/src/user/dto/uuid.dto.ts new file mode 100644 index 0000000..fa6de64 --- /dev/null +++ b/apps/auth/src/user/dto/uuid.dto.ts @@ -0,0 +1,10 @@ +import { IsUUID } from "class-validator"; + +export class UuidDto { + @IsUUID(4) + public uuid: string; + + constructor(uuid: string) { + this.uuid = uuid; + } +} \ No newline at end of file