fix(pay-period): removed is_remote from payload and added dynamic returns of timesheet.is_approved

This commit is contained in:
Matthieu Haineault 2025-12-23 07:18:01 -05:00
parent da74a93fa0
commit 15d7821314
2 changed files with 21 additions and 11 deletions

View File

@ -25,7 +25,6 @@ export class EmployeePeriodOverviewDto {
expenses: number;
mileage: number;
is_approved: boolean;
is_remote: boolean;
}
export class PayPeriodBundleDto {

View File

@ -127,11 +127,13 @@ export class PayPeriodsQueryService {
return { success: true, data: overview.data }
}
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
},
options?: { filtered_employee_ids?: number[]; seed_names?: Map<number, { name: string, email: string }> }
): Promise<Result<PayPeriodOverviewDto, string>> {
const toDateString = (d: Date) => d.toISOString().slice(0, 10);
@ -167,6 +169,7 @@ export class PayPeriodsQueryService {
is_remote: true,
timesheet: {
select: {
id: true,
is_approved: true,
employee: {
select: {
@ -193,6 +196,7 @@ export class PayPeriodsQueryService {
amount: true,
timesheet: {
select: {
id: true,
is_approved: true,
employee: {
select: {
@ -211,9 +215,20 @@ export class PayPeriodsQueryService {
bank_code: { select: { categorie: true, modifier: true, type: true } },
},
});
const timesheet_id = shifts[0].timesheet.id ? expenses[0].timesheet.id : null;
if (timesheet_id === null) return { success: false, error: 'INVALID_TIMESHEET' };
const by_employee = new Map<number, EmployeePeriodOverviewDto>();
const timesheet = await this.prisma.timesheets.findFirst({
where: { id: timesheet_id },
select: {
is_approved: true,
id: true,
},
});
if (!timesheet) return { success: false, error: 'INVALID_TIMESHEET' };
// seed for employee without data
if (options?.seed_names) {
for (const [id, { name, email }] of options.seed_names.entries()) {
@ -234,7 +249,6 @@ export class PayPeriodsQueryService {
expenses: 0,
mileage: 0,
is_approved: false,
is_remote: false,
});
}
} else {
@ -245,8 +259,8 @@ export class PayPeriodsQueryService {
first_name: true,
last_name: true,
email: true
}
}
},
},
},
});
@ -256,7 +270,7 @@ export class PayPeriodsQueryService {
if (employee.last_work_day !== null) {
is_active = this.checkForInactiveDate(employee.last_work_day)
}
by_employee.set(employee.id, {
email: employee.user.email,
employee_name: employee.user.first_name + ' ' + employee.user.last_name,
@ -273,8 +287,7 @@ export class PayPeriodsQueryService {
total_hours: 0,
expenses: 0,
mileage: 0,
is_approved: false,
is_remote: false,
is_approved: timesheet.is_approved,
});
}
}
@ -297,8 +310,7 @@ export class PayPeriodsQueryService {
total_hours: 0,
expenses: 0,
mileage: 0,
is_approved: false,
is_remote: false,
is_approved: timesheet.is_approved,
});
}
return by_employee.get(id)!;
@ -336,7 +348,6 @@ export class PayPeriodsQueryService {
}
record.is_approved = record.is_approved && shift.timesheet.is_approved;
record.is_remote = record.is_remote || !!shift.is_remote;
}
for (const expense of expenses) {