fix(pay-period): change payload to send regular hours and other hours, rather than each individual shift type as a property

This commit is contained in:
Nicolas Drolet 2025-10-09 15:17:02 -04:00
parent 7c7edea768
commit 5a1017f82b
4 changed files with 456 additions and 383 deletions

View File

@ -1134,6 +1134,45 @@
"SchedulePresets"
]
}
},
"/schedule-presets/apply-presets/{email}": {
"post": {
"operationId": "SchedulePresetsController_applyPresets",
"parameters": [
{
"name": "email",
"required": true,
"in": "path",
"schema": {
"type": "string"
}
},
{
"name": "preset",
"required": true,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "start",
"required": true,
"in": "query",
"schema": {
"type": "string"
}
}
],
"responses": {
"201": {
"description": ""
}
},
"tags": [
"SchedulePresets"
]
}
}
},
"info": {
@ -1551,20 +1590,10 @@
"example": 40,
"description": "pay-period`s regular hours"
},
"evening_hours": {
"type": "number",
"other_hours": {
"type": "object",
"example": 0,
"description": "pay-period`s evening hours"
},
"emergency_hours": {
"type": "number",
"example": 0,
"description": "pay-period`s emergency hours"
},
"overtime_hours": {
"type": "number",
"example": 2,
"description": "pay-period`s overtime hours"
"description": "pay-period`s other hours"
},
"expenses": {
"type": "number",
@ -1585,9 +1614,7 @@
"required": [
"employee_name",
"regular_hours",
"evening_hours",
"emergency_hours",
"overtime_hours",
"other_hours",
"expenses",
"mileage",
"is_approved"

View File

@ -62,17 +62,21 @@ export class LeaveRequestsUtils {
await this.shiftsCommand.upsertShiftsByDate(email, iso_date, {
old_shift: existing
? {
date: existing.date,
start_time: existing.start_time.toISOString().slice(11, 16),
end_time: existing.end_time.toISOString().slice(11, 16),
type: existing.bank_code?.type ?? type,
is_remote: existing.is_remote,
is_approved:existing.is_approved,
comment: existing.comment ?? undefined,
}
: undefined,
new_shift: {
date: existing?.date ?? '',
start_time: toHHmm(start_minutes),
end_time: toHHmm(end_minutes),
is_remote: existing?.is_remote ?? false,
is_approved:existing?.is_approved ?? false,
comment: comment ?? existing?.comment ?? "",
type: type,
},
@ -97,10 +101,12 @@ export class LeaveRequestsUtils {
await this.shiftsCommand.upsertShiftsByDate(email, iso_date, {
old_shift: {
date: existing.date,
start_time: existing.start_time.toISOString().slice(11, 16),
end_time: existing.end_time.toISOString().slice(11, 16),
type: existing.bank_code?.type ?? type,
is_remote: existing.is_remote,
is_approved:existing.is_approved,
comment: existing.comment ?? undefined,
},
});

View File

@ -21,15 +21,21 @@ export class EmployeePeriodOverviewDto {
@ApiProperty({ example: 40, description: 'pay-period`s regular hours' })
regular_hours: number;
@ApiProperty({ example: 0, description: 'pay-period`s evening hours' })
@ApiProperty({ example: 0, description: 'pay-period`s other hours' })
other_hours: {
evening_hours: number;
@ApiProperty({ example: 0, description: 'pay-period`s emergency hours' })
emergency_hours: number;
@ApiProperty({ example: 2, description: 'pay-period`s overtime hours' })
overtime_hours: number;
sick_hours: number;
holiday_hours: number;
vacation_hours: number;
};
total_hours: number;
@ApiProperty({ example: 420.69, description: 'pay-period`s total expenses ($)' })

View File

@ -101,8 +101,10 @@ export class PayPeriodsQueryService {
const seed_names = new Map<number, { name: string; email: string }>(
crew.map(crew => [
crew.id,
{ name:`${crew.first_name} ${crew.last_name}`.trim(),
email: crew.email }
{
name: `${crew.first_name} ${crew.last_name}`.trim(),
email: crew.email
}
]
)
);
@ -120,8 +122,10 @@ export class PayPeriodsQueryService {
}
private async buildOverview(
period: { period_start: string | Date; period_end: string | Date; payday: string | Date;
period_no: number; pay_year: number; label: string; }, //add is_approved
period: {
period_start: string | Date; period_end: string | Date; payday: string | Date;
period_no: number; pay_year: number; label: string;
}, //add is_approved
options?: { filtered_employee_ids?: number[]; seed_names?: Map<number, { name: string, email: string }> }
): Promise<PayPeriodOverviewDto> {
const toDateString = (d: Date) => d.toISOString().slice(0, 10);
@ -152,16 +156,21 @@ export class PayPeriodsQueryService {
start_time: true,
end_time: true,
is_remote: true,
timesheet: { select: {
timesheet: {
select: {
is_approved: true,
employee: { select: {
employee: {
select: {
id: true,
user: { select: {
user: {
select: {
first_name: true,
last_name: true,
email: true,
} },
} },
}
},
}
},
},
},
bank_code: { select: { categorie: true, type: true } },
@ -176,17 +185,23 @@ export class PayPeriodsQueryService {
},
select: {
amount: true,
timesheet: { select: {
timesheet: {
select: {
is_approved: true,
employee: { select: {
employee: {
select: {
id: true,
user: { select: {
user: {
select: {
first_name: true,
last_name: true,
email: true,
} },
} },
} },
}
},
}
},
}
},
bank_code: { select: { categorie: true, modifier: true, type: true } },
},
});
@ -200,9 +215,14 @@ export class PayPeriodsQueryService {
email,
employee_name: name,
regular_hours: 0,
other_hours: {
evening_hours: 0,
emergency_hours: 0,
overtime_hours: 0,
sick_hours: 0,
holiday_hours: 0,
vacation_hours: 0,
},
total_hours: 0,
expenses: 0,
mileage: 0,
@ -218,9 +238,14 @@ export class PayPeriodsQueryService {
email,
employee_name: name,
regular_hours: 0,
other_hours: {
evening_hours: 0,
emergency_hours: 0,
overtime_hours: 0,
sick_hours: 0,
holiday_hours: 0,
vacation_hours: 0,
},
total_hours: 0,
expenses: 0,
mileage: 0,
@ -239,13 +264,22 @@ export class PayPeriodsQueryService {
const hours = computeHours(shift.start_time, shift.end_time);
const type = (shift.bank_code?.type ?? '').toUpperCase();
switch (type) {
case "EVENING": record.evening_hours += hours;
case "EVENING": record.other_hours.evening_hours += hours;
record.total_hours += hours;
break;
case "EMERGENCY": record.emergency_hours += hours;
case "EMERGENCY": record.other_hours.emergency_hours += hours;
record.total_hours += hours;
break;
case "OVERTIME": record.overtime_hours += hours;
case "OVERTIME": record.other_hours.overtime_hours += hours;
record.total_hours += hours;
break;
case "SICK": record.other_hours.sick_hours += hours;
record.total_hours += hours;
break;
case "HOLIDAY": record.other_hours.holiday_hours += hours;
record.total_hours += hours;
break;
case "VACATION": record.other_hours.vacation_hours += hours;
record.total_hours += hours;
break;
case "REGULAR": record.regular_hours += hours;