diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5a03063..05b9dfa 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -323,12 +323,12 @@ model Preferences { } model PaidTimeOff { - id Int @id @default(autoincrement()) - employee_id Int @unique - vacation_hours Decimal @default(0) @db.Decimal(12, 2) - banked_hours Decimal @default(0) @db.Decimal(12, 2) - sick_hours Decimal @default(0) @db.Decimal(12, 2) - last_updated DateTime @db.Date + id Int @id @default(autoincrement()) + employee_id Int @unique + vacation_hours Decimal @default(0) @db.Decimal(12, 2) + banked_hours Decimal @default(0) @db.Decimal(12, 2) + sick_hours Decimal @default(0) @db.Decimal(12, 2) + last_updated DateTime? @db.Date employee Employees @relation("EmployeePaidTimeOff", fields: [employee_id], references: [id]) diff --git a/src/identity-and-account/employees/services/employees-get.service.ts b/src/identity-and-account/employees/services/employees-get.service.ts index 40e24bb..426f1c2 100644 --- a/src/identity-and-account/employees/services/employees-get.service.ts +++ b/src/identity-and-account/employees/services/employees-get.service.ts @@ -120,7 +120,7 @@ export class EmployeesGetService { paid_time_off: { vacation_hours: existing_profile.paid_time_off?.vacation_hours.toNumber() ?? 0, banked_hours: existing_profile.paid_time_off?.banked_hours.toNumber() ?? 0, - last_updated: existing_profile.paid_time_off?.last_updated.toISOString().slice(0, 10) ?? '', + last_updated: existing_profile.paid_time_off?.last_updated?.toISOString() ?? null, }, is_supervisor: existing_profile.is_supervisor, phone_number: existing_profile.user.phone_number, @@ -212,7 +212,7 @@ export class EmployeesGetService { sick_hours: employee.paid_time_off?.sick_hours.toNumber() ?? 0, vacation_hours: employee.paid_time_off?.vacation_hours.toNumber() ?? 0, banked_hours: employee.paid_time_off?.banked_hours.toNumber() ?? 0, - last_updated: employee.paid_time_off?.last_updated.toISOString().slice(0, 10) ?? '', + last_updated: employee.paid_time_off?.last_updated?.toISOString() ?? null, }, employee_full_name: `${employee.user.first_name} ${employee.user.last_name}`, first_work_day: toStringFromDate(employee.first_work_day), diff --git a/src/identity-and-account/employees/services/employees-update.service.ts b/src/identity-and-account/employees/services/employees-update.service.ts index 7bb28e1..19c1504 100644 --- a/src/identity-and-account/employees/services/employees-update.service.ts +++ b/src/identity-and-account/employees/services/employees-update.service.ts @@ -67,6 +67,7 @@ export class EmployeesUpdateService { }); const employee_pto = dto.paid_time_off ?? new PaidTimeOffDto(employee.id); + const last_updated = employee_pto.last_updated ? toDateFromString(employee_pto.last_updated) : null; await tx.paidTimeOff.upsert({ where: { employee_id: employee_pto.employee_id }, @@ -74,14 +75,14 @@ export class EmployeesUpdateService { sick_hours: employee_pto.sick_hours, vacation_hours: employee_pto.vacation_hours, banked_hours: employee_pto.banked_hours, - last_updated: employee_pto.last_updated, + last_updated: last_updated, }, create: { employee_id: employee_pto.employee_id, sick_hours: employee_pto.sick_hours, vacation_hours: employee_pto.vacation_hours, banked_hours: employee_pto.banked_hours, - last_updated: employee_pto.last_updated, + last_updated: last_updated, } }) diff --git a/src/time-and-attendance/domains/paid-time-off.dto.ts b/src/time-and-attendance/domains/paid-time-off.dto.ts index 3dd12c0..a9f5476 100644 --- a/src/time-and-attendance/domains/paid-time-off.dto.ts +++ b/src/time-and-attendance/domains/paid-time-off.dto.ts @@ -1,5 +1,5 @@ import { Type } from "class-transformer"; -import { IsDateString, IsDecimal, IsInt, IsNotEmpty, IsNumber, IsOptional } from "class-validator"; +import { IsString, IsInt, IsNotEmpty, IsOptional } from "class-validator"; export class PaidTimeOffDto { @IsInt() id: number; @@ -7,7 +7,7 @@ export class PaidTimeOffDto { @IsOptional() @Type(() => Number) vacation_hours?: number; @IsOptional() @Type(() => Number) sick_hours?: number; @IsOptional() @Type(() => Number) banked_hours?: number; - @IsDateString() @IsOptional() last_updated: string; + @IsString() @IsOptional() last_updated?: string | null; constructor(employee_id: number) { this.employee_id = employee_id; diff --git a/src/time-and-attendance/domains/services/sick-leave.service.ts b/src/time-and-attendance/domains/services/sick-leave.service.ts index 30e3c6d..db74b52 100644 --- a/src/time-and-attendance/domains/services/sick-leave.service.ts +++ b/src/time-and-attendance/domains/services/sick-leave.service.ts @@ -54,8 +54,8 @@ export class SickLeaveService { if (!updated_pto.success) return { success: updated_pto.success, error: updated_pto.error } } - const year_difference = today.getFullYear() - (pto_details!.last_updated.getFullYear() ?? today.getFullYear()); - const months_since_last_update = (today.getMonth() + year_difference * 12) - pto_details!.last_updated.getMonth(); + const year_difference = today.getFullYear() - (pto_details!.last_updated?.getFullYear() ?? today.getFullYear()); + const months_since_last_update = (today.getMonth() + year_difference * 12) - (pto_details!.last_updated?.getMonth() ?? 0); if (months_since_last_update > 0) { const updated_pto = await this.addHoursToPTO(months_since_last_update * 8, employee.id, today);