"refactor(timesheet): add full employee name to return data to display in timesheet approval employee details dialog header"
This commit is contained in:
parent
5621f72342
commit
1c797c348a
|
|
@ -61,4 +61,5 @@ export class WeekDto {
|
|||
export class TimesheetPeriodDto {
|
||||
week1: WeekDto;
|
||||
week2: WeekDto;
|
||||
employee_full_name: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,23 @@ 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({
|
||||
where: { pay_year: year, pay_period_no: period_no },
|
||||
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user