fix(employees): change DTOs to accomodate lack of last_update date
This commit is contained in:
parent
6acb853c69
commit
7e9dbe5b3d
|
|
@ -328,7 +328,7 @@ model PaidTimeOff {
|
|||
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
|
||||
last_updated DateTime? @db.Date
|
||||
|
||||
employee Employees @relation("EmployeePaidTimeOff", fields: [employee_id], references: [id])
|
||||
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user