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, }; }