Files
SerpentRace/SerpentRace_Backend/src/Database/dto/user.dto.ts
T
2025-07-18 09:20:40 +02:00

327 lines
5.3 KiB
TypeScript

import { IsEmail, IsString, IsOptional, IsEnum, IsNumber, IsDate, IsBoolean, Length, MinLength } from 'class-validator';
import { Type } from 'class-transformer';
import { UserStatus, UserAuthLevel } from '../entities/user.entity';
// JWT Token DTO
export class JwtTokenDto {
@IsNumber()
userId!: number;
@IsString()
@Length(1, 255)
username!: string;
@IsOptional()
@IsNumber()
companyId?: number;
@IsEnum(UserAuthLevel)
authLevel!: UserAuthLevel;
@IsEnum(UserStatus)
status!: UserStatus;
}
// Login Response DTO
export class LoginResponseDto {
@IsString()
@Length(1, 255)
username!: string;
@IsNumber()
id!: number;
@IsOptional()
@IsNumber()
companyId?: number;
@IsEnum(UserAuthLevel)
authLevel!: UserAuthLevel;
@IsEnum(UserStatus)
status!: UserStatus;
@IsString()
token!: string;
}
// User Creation DTO
export class CreateUserDto {
@IsString()
@Length(1, 255)
username!: string;
@IsString()
@Length(1, 255)
FirstName!: string;
@IsString()
@Length(1, 255)
LastName!: string;
@IsEmail()
@Length(1, 255)
email!: string;
@IsString()
@MinLength(8)
@Length(1, 255)
password!: string;
@IsOptional()
@IsNumber()
CompanyId?: number;
@IsOptional()
@IsEnum(UserAuthLevel)
authLevel?: UserAuthLevel;
@IsOptional()
@IsEnum(UserStatus)
status?: UserStatus;
}
// User Update DTO
export class UpdateUserDto {
@IsOptional()
@IsString()
@Length(1, 255)
username?: string;
@IsOptional()
@IsString()
@Length(1, 255)
FirstName?: string;
@IsOptional()
@IsString()
@Length(1, 255)
LastName?: string;
@IsOptional()
@IsEmail()
@Length(1, 255)
email?: string;
@IsOptional()
@IsString()
@MinLength(8)
@Length(1, 255)
password?: string;
@IsOptional()
@IsEnum(UserStatus)
status?: UserStatus;
@IsOptional()
@IsEnum(UserAuthLevel)
authLevel?: UserAuthLevel;
@IsOptional()
@IsString()
@Length(1, 32)
securityToken?: string;
@IsOptional()
@IsDate()
@Type(() => Date)
securityTokenExpiry?: Date;
@IsOptional()
@IsDate()
@Type(() => Date)
premiumExpirationDate?: Date;
@IsOptional()
@IsNumber()
CompanyId?: number;
@IsOptional()
@IsBoolean()
companyRegistered?: boolean;
@IsOptional()
@IsDate()
@Type(() => Date)
companyRegistrationDate?: Date;
}
// User Request DTO (for queries/filters)
export class UserRequestDto {
@IsOptional()
@IsString()
@Length(1, 26)
guid?: string;
@IsOptional()
@IsString()
@Length(1, 255)
username?: string;
@IsOptional()
@IsEmail()
email?: string;
@IsOptional()
@IsEnum(UserStatus)
status?: UserStatus;
@IsOptional()
@IsEnum(UserAuthLevel)
authLevel?: UserAuthLevel;
@IsOptional()
@IsNumber()
CompanyId?: number;
@IsOptional()
@IsBoolean()
companyRegistered?: boolean;
@IsOptional()
@IsNumber()
page?: number;
@IsOptional()
@IsNumber()
limit?: number;
}
// User Response DTO (for API responses)
export class UserResponseDto {
@IsNumber()
id!: number;
@IsString()
guid!: string;
@IsString()
username!: string;
@IsString()
FirstName!: string;
@IsString()
LastName!: string;
@IsEmail()
email!: string;
@IsDate()
createdAt!: Date;
@IsDate()
updatedAt!: Date;
@IsEnum(UserStatus)
status!: UserStatus;
@IsEnum(UserAuthLevel)
authLevel!: UserAuthLevel;
@IsOptional()
@IsDate()
premiumExpirationDate?: Date;
@IsOptional()
@IsNumber()
CompanyId?: number;
@IsBoolean()
companyRegistered!: boolean;
@IsOptional()
@IsDate()
companyRegistrationDate?: Date;
// Helper method flags
@IsBoolean()
isConfirmed!: boolean;
@IsBoolean()
isPremium!: boolean;
@IsBoolean()
isAdmin!: boolean;
@IsBoolean()
canLogin!: boolean;
@IsBoolean()
hasCompany!: boolean;
@IsBoolean()
needsCompanyReregistration!: boolean;
}
// User Remove DTO
export class RemoveUserDto {
@IsString()
@Length(1, 26)
guid!: string;
@IsOptional()
@IsString()
reason?: string;
@IsOptional()
@IsBoolean()
hardDelete?: boolean; // true for permanent deletion, false for soft delete
}
// Login Request DTO
export class LoginRequestDto {
@IsString()
@Length(1, 255)
username!: string;
@IsString()
@Length(1, 255)
password!: string;
}
// Password Reset Request DTO
export class PasswordResetRequestDto {
@IsEmail()
email!: string;
}
// Password Reset DTO
export class PasswordResetDto {
@IsString()
@Length(32, 32)
token!: string;
@IsString()
@MinLength(8)
@Length(1, 255)
newPassword!: string;
}
// Email Confirmation DTO
export class EmailConfirmationDto {
@IsString()
@Length(32, 32)
token!: string;
}
// Premium Subscription DTO
export class PremiumSubscriptionDto {
@IsString()
@Length(1, 26)
userGuid!: string;
@IsNumber()
months!: number;
}
// Company Registration DTO
export class CompanyRegistrationDto {
@IsString()
@Length(1, 26)
userGuid!: string;
@IsNumber()
companyId!: number;
}