fix(employees): change DTOs to accomodate lack of last_update date
This commit is contained in:
parent
6acb853c69
commit
7e9dbe5b3d
|
|
@ -323,12 +323,12 @@ model Preferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
model PaidTimeOff {
|
model PaidTimeOff {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
employee_id Int @unique
|
employee_id Int @unique
|
||||||
vacation_hours Decimal @default(0) @db.Decimal(12, 2)
|
vacation_hours Decimal @default(0) @db.Decimal(12, 2)
|
||||||
banked_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)
|
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])
|
employee Employees @relation("EmployeePaidTimeOff", fields: [employee_id], references: [id])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ export class EmployeesGetService {
|
||||||
paid_time_off: {
|
paid_time_off: {
|
||||||
vacation_hours: existing_profile.paid_time_off?.vacation_hours.toNumber() ?? 0,
|
vacation_hours: existing_profile.paid_time_off?.vacation_hours.toNumber() ?? 0,
|
||||||
banked_hours: existing_profile.paid_time_off?.banked_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,
|
is_supervisor: existing_profile.is_supervisor,
|
||||||
phone_number: existing_profile.user.phone_number,
|
phone_number: existing_profile.user.phone_number,
|
||||||
|
|
@ -212,7 +212,7 @@ export class EmployeesGetService {
|
||||||
sick_hours: employee.paid_time_off?.sick_hours.toNumber() ?? 0,
|
sick_hours: employee.paid_time_off?.sick_hours.toNumber() ?? 0,
|
||||||
vacation_hours: employee.paid_time_off?.vacation_hours.toNumber() ?? 0,
|
vacation_hours: employee.paid_time_off?.vacation_hours.toNumber() ?? 0,
|
||||||
banked_hours: employee.paid_time_off?.banked_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}`,
|
employee_full_name: `${employee.user.first_name} ${employee.user.last_name}`,
|
||||||
first_work_day: toStringFromDate(employee.first_work_day),
|
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 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({
|
await tx.paidTimeOff.upsert({
|
||||||
where: { employee_id: employee_pto.employee_id },
|
where: { employee_id: employee_pto.employee_id },
|
||||||
|
|
@ -74,14 +75,14 @@ export class EmployeesUpdateService {
|
||||||
sick_hours: employee_pto.sick_hours,
|
sick_hours: employee_pto.sick_hours,
|
||||||
vacation_hours: employee_pto.vacation_hours,
|
vacation_hours: employee_pto.vacation_hours,
|
||||||
banked_hours: employee_pto.banked_hours,
|
banked_hours: employee_pto.banked_hours,
|
||||||
last_updated: employee_pto.last_updated,
|
last_updated: last_updated,
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
employee_id: employee_pto.employee_id,
|
employee_id: employee_pto.employee_id,
|
||||||
sick_hours: employee_pto.sick_hours,
|
sick_hours: employee_pto.sick_hours,
|
||||||
vacation_hours: employee_pto.vacation_hours,
|
vacation_hours: employee_pto.vacation_hours,
|
||||||
banked_hours: employee_pto.banked_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 { 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 {
|
export class PaidTimeOffDto {
|
||||||
@IsInt() id: number;
|
@IsInt() id: number;
|
||||||
|
|
@ -7,7 +7,7 @@ export class PaidTimeOffDto {
|
||||||
@IsOptional() @Type(() => Number) vacation_hours?: number;
|
@IsOptional() @Type(() => Number) vacation_hours?: number;
|
||||||
@IsOptional() @Type(() => Number) sick_hours?: number;
|
@IsOptional() @Type(() => Number) sick_hours?: number;
|
||||||
@IsOptional() @Type(() => Number) banked_hours?: number;
|
@IsOptional() @Type(() => Number) banked_hours?: number;
|
||||||
@IsDateString() @IsOptional() last_updated: string;
|
@IsString() @IsOptional() last_updated?: string | null;
|
||||||
|
|
||||||
constructor(employee_id: number) {
|
constructor(employee_id: number) {
|
||||||
this.employee_id = employee_id;
|
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 }
|
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 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 months_since_last_update = (today.getMonth() + year_difference * 12) - (pto_details!.last_updated?.getMonth() ?? 0);
|
||||||
|
|
||||||
if (months_since_last_update > 0) {
|
if (months_since_last_update > 0) {
|
||||||
const updated_pto = await this.addHoursToPTO(months_since_last_update * 8, employee.id, today);
|
const updated_pto = await this.addHoursToPTO(months_since_last_update * 8, employee.id, today);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user