"refactor(timesheet): add full employee name to return data to display in timesheet approval employee details dialog header"

This commit is contained in:
Nicolas Drolet 2025-09-26 11:40:04 -04:00
parent 5621f72342
commit 1c797c348a
3 changed files with 20 additions and 4 deletions

View File

@ -61,4 +61,5 @@ export class WeekDto {
export class TimesheetPeriodDto {
week1: WeekDto;
week2: WeekDto;
employee_full_name: string;
}

View File

@ -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<TimesheetDto> {

View File

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