import { IsEmail, IsArray, ArrayNotEmpty, ArrayUnique, IsISO8601, IsIn, IsOptional, IsString, IsNumber, Min, Max, IsEnum } from "class-validator"; import { LeaveApprovalStatus, LeaveTypes } from "@prisma/client"; import { LeaveRequestViewDto } from "./leave-request-view.dto"; import { Type } from "class-transformer"; //sets wich function to call export const UPSERT_ACTIONS = ['create', 'update', 'delete'] as const; export type UpsertAction = (typeof UPSERT_ACTIONS)[number]; //sets wich types to use export const REQUEST_TYPES = Object.values(LeaveTypes) as readonly LeaveTypes[]; export type RequestTypes = (typeof REQUEST_TYPES)[number]; //filter requests by type and action export interface UpsertResult { action: UpsertAction; leave_requests: LeaveRequestViewDto[]; } export class UpsertLeaveRequestDto { @IsEmail() email!: string; @IsArray() @ArrayNotEmpty() @ArrayUnique() @IsISO8601({}, { each: true }) dates!: string[]; @IsOptional() @IsEnum(LeaveTypes) type!: string; @IsIn(UPSERT_ACTIONS) action!: UpsertAction; @IsOptional() @IsString() comment?: string; @IsOptional() @Type(() => Number) @IsNumber({ maxDecimalPlaces: 2 }) @Min(0) @Max(24) requested_hours?: number; @IsOptional() @IsEnum(LeaveApprovalStatus) approval_status?: LeaveApprovalStatus }