From d45feb1aa01eb0db04185d2fee08b4cf248746ab Mon Sep 17 00:00:00 2001 From: Nicolas Drolet Date: Tue, 9 Sep 2025 08:21:27 -0400 Subject: [PATCH 1/4] fix(payperiod): add type to payload. --- .../services/pay-periods-query.service.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/modules/pay-periods/services/pay-periods-query.service.ts b/src/modules/pay-periods/services/pay-periods-query.service.ts index f0f306a..d5ac7ad 100644 --- a/src/modules/pay-periods/services/pay-periods-query.service.ts +++ b/src/modules/pay-periods/services/pay-periods-query.service.ts @@ -161,7 +161,9 @@ export class PayPeriodsQueryService { } }, }, }, - bank_code: { select: { categorie: true } }, + bank_code: { select: { + type: true, + categorie: true } }, }, }); @@ -184,7 +186,10 @@ export class PayPeriodsQueryService { } }, } }, } }, - bank_code: { select: { categorie: true, modifier: true } }, + bank_code: { select: { + type: true, + categorie: true, + modifier: true } }, }, }); @@ -230,13 +235,14 @@ export class PayPeriodsQueryService { const record = ensure(employee.id, name, employee.user.email); const hours = computeHours(shift.start_time, shift.end_time); - const categorie = (shift.bank_code?.categorie || "REGULAR").toUpperCase(); - switch (categorie) { + const type = (shift.bank_code?.type).toUpperCase(); + switch (type) { case "EVENING": record.evening_hours += hours; break; case "EMERGENCY": record.emergency_hours += hours; break; case "OVERTIME": record.overtime_hours += hours; break; - default: record.regular_hours += hours; break; + case "REGULAR": record.regular_hours += hours; break; } + record.is_approved = record.is_approved && shift.timesheet.is_approved; } @@ -248,10 +254,10 @@ export class PayPeriodsQueryService { const amount = toMoney(expense.amount); record.expenses += amount; - const categorie = (expense.bank_code?.categorie || "").toUpperCase(); + const type = (expense.bank_code?.type || "").toUpperCase(); const rate = expense.bank_code?.modifier ?? 0; - if (categorie === "MILEAGE" && rate > 0) { - record.mileage += amount / rate; + if (type === "MILEAGE" && rate > 0) { + record.mileage += Math.round((amount / rate) * 100) / 100; } record.is_approved = record.is_approved && expense.timesheet.is_approved; } From bcf73927bd5e49d3b2ad242c07a460e6c3249b4b Mon Sep 17 00:00:00 2001 From: Nicolas Drolet Date: Tue, 16 Sep 2025 11:20:50 -0400 Subject: [PATCH 2/4] fix(payperiod): add minor fix to total hours calculated method --- .../pay-periods/services/pay-periods-query.service.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/modules/pay-periods/services/pay-periods-query.service.ts b/src/modules/pay-periods/services/pay-periods-query.service.ts index c921fd3..15932b3 100644 --- a/src/modules/pay-periods/services/pay-periods-query.service.ts +++ b/src/modules/pay-periods/services/pay-periods-query.service.ts @@ -239,14 +239,13 @@ 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; break; - case "EMERGENCY": record.emergency_hours += hours; break; - case "OVERTIME": record.overtime_hours += hours; break; - case "REGULAR" : record.regular_hours += hours; break; + case "EVENING": record.evening_hours += hours; record.total_hours += hours; break; + case "EMERGENCY": record.emergency_hours += hours; record.total_hours += hours; break; + case "OVERTIME": record.overtime_hours += hours; record.total_hours += hours; break; + case "REGULAR" : record.regular_hours += hours; record.total_hours += hours; break; } record.is_approved = record.is_approved && shift.timesheet.is_approved; - record.total_hours += hours; record.is_remote = record.is_remote || !!shift.is_remote; } From 1c797c348a5a5ae848db7e36248ac25838abb7f7 Mon Sep 17 00:00:00 2001 From: Nicolas Drolet Date: Fri, 26 Sep 2025 11:40:04 -0400 Subject: [PATCH 3/4] "refactor(timesheet): add full employee name to return data to display in timesheet approval employee details dialog header" --- .../timesheets/dtos/timesheet-period.dto.ts | 1 + .../services/timesheets-query.service.ts | 17 +++++++++++++++-- .../timesheets/utils/timesheet.helpers.ts | 6 ++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/modules/timesheets/dtos/timesheet-period.dto.ts b/src/modules/timesheets/dtos/timesheet-period.dto.ts index cfd0194..6da4551 100644 --- a/src/modules/timesheets/dtos/timesheet-period.dto.ts +++ b/src/modules/timesheets/dtos/timesheet-period.dto.ts @@ -61,4 +61,5 @@ export class WeekDto { export class TimesheetPeriodDto { week1: WeekDto; week2: WeekDto; + employee_full_name: string; } diff --git a/src/modules/timesheets/services/timesheets-query.service.ts b/src/modules/timesheets/services/timesheets-query.service.ts index f4517e2..67ed8e2 100644 --- a/src/modules/timesheets/services/timesheets-query.service.ts +++ b/src/modules/timesheets/services/timesheets-query.service.ts @@ -20,9 +20,22 @@ export class TimesheetsQueryService { //finds the employee const employee = await this.prisma.employees.findFirst({ where: { user: { is: { email } } }, - select: { id: true }, + select: { + id: true, + user_id: true, + }, }); if(!employee) throw new NotFoundException(`no employee with email ${email} found`); + + //gets the employee's full name + const user = await this.prisma.users.findFirst({ + where: { id: employee.user_id }, + select: { + first_name: true, + last_name: true, + } + }); + const employee_full_name: string = ( user?.first_name + " " + user?.last_name ) || " "; //finds the period const period = await this.prisma.payPeriods.findFirst({ @@ -92,7 +105,7 @@ export class TimesheetsQueryService { type: String(expense.bank_code?.type ?? '').toUpperCase(), })); - return buildPeriod(period.period_start, period.period_end, shifts , expenses); + return buildPeriod(period.period_start, period.period_end, shifts , expenses, employee_full_name); } async getTimesheetByEmail(email: string, week_offset = 0): Promise { diff --git a/src/modules/timesheets/utils/timesheet.helpers.ts b/src/modules/timesheets/utils/timesheet.helpers.ts index 95ee5f3..05cfc38 100644 --- a/src/modules/timesheets/utils/timesheet.helpers.ts +++ b/src/modules/timesheets/utils/timesheet.helpers.ts @@ -127,7 +127,7 @@ export function makeEmptyWeek(week_start: Date): WeekDto { } export function makeEmptyPeriod(): TimesheetPeriodDto { - return { week1: makeEmptyWeek(new Date()), week2: makeEmptyWeek(new Date()) }; + return { week1: makeEmptyWeek(new Date()), week2: makeEmptyWeek(new Date()), employee_full_name: " " }; } export function buildWeek( @@ -301,7 +301,8 @@ export function buildPeriod( period_start: Date, period_end: Date, shifts: ShiftRow[], - expenses: ExpenseRow[] + expenses: ExpenseRow[], + employee_full_name: string, ): TimesheetPeriodDto { const week1_start = toUTCDateOnly(period_start); const week1_end = endOfDayUTC(addDays(week1_start, 6)); @@ -311,6 +312,7 @@ export function buildPeriod( return { week1: buildWeek(week1_start, week1_end, shifts, expenses), week2: buildWeek(week2_start, week2_end, shifts, expenses), + employee_full_name, }; } From fa845cf6e646bc0dd46258f4db9f3ee0ba35d18a Mon Sep 17 00:00:00 2001 From: Nicolas Drolet Date: Mon, 6 Oct 2025 16:06:26 -0400 Subject: [PATCH 4/4] fix(timesheet): add some quality of life to get required info, employee name, change pay period response from week 1 and 2 to array of weeks --- src/modules/timesheets/dtos/timesheet-period.dto.ts | 3 +-- src/modules/timesheets/utils/timesheet.helpers.ts | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/modules/timesheets/dtos/timesheet-period.dto.ts b/src/modules/timesheets/dtos/timesheet-period.dto.ts index 6da4551..a084bad 100644 --- a/src/modules/timesheets/dtos/timesheet-period.dto.ts +++ b/src/modules/timesheets/dtos/timesheet-period.dto.ts @@ -59,7 +59,6 @@ export class WeekDto { } export class TimesheetPeriodDto { - week1: WeekDto; - week2: WeekDto; + weeks: WeekDto[]; employee_full_name: string; } diff --git a/src/modules/timesheets/utils/timesheet.helpers.ts b/src/modules/timesheets/utils/timesheet.helpers.ts index 05cfc38..7718f4c 100644 --- a/src/modules/timesheets/utils/timesheet.helpers.ts +++ b/src/modules/timesheets/utils/timesheet.helpers.ts @@ -127,7 +127,7 @@ export function makeEmptyWeek(week_start: Date): WeekDto { } export function makeEmptyPeriod(): TimesheetPeriodDto { - return { week1: makeEmptyWeek(new Date()), week2: makeEmptyWeek(new Date()), employee_full_name: " " }; + return { weeks: [ makeEmptyWeek(new Date()), makeEmptyWeek(new Date())], employee_full_name: " " }; } export function buildWeek( @@ -310,8 +310,10 @@ export function buildPeriod( const week2_end = endOfDayUTC(period_end); return { - week1: buildWeek(week1_start, week1_end, shifts, expenses), - week2: buildWeek(week2_start, week2_end, shifts, expenses), + weeks: [ + buildWeek(week1_start, week1_end, shifts, expenses), + buildWeek(week2_start, week2_end, shifts, expenses), + ], employee_full_name, }; }