fix(pay-period): removed is_remote from payload and added dynamic returns of timesheet.is_approved
This commit is contained in:
parent
da74a93fa0
commit
15d7821314
|
|
@ -25,7 +25,6 @@ export class EmployeePeriodOverviewDto {
|
||||||
expenses: number;
|
expenses: number;
|
||||||
mileage: number;
|
mileage: number;
|
||||||
is_approved: boolean;
|
is_approved: boolean;
|
||||||
is_remote: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PayPeriodBundleDto {
|
export class PayPeriodBundleDto {
|
||||||
|
|
|
||||||
|
|
@ -127,11 +127,13 @@ export class PayPeriodsQueryService {
|
||||||
return { success: true, data: overview.data }
|
return { success: true, data: overview.data }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private async buildOverview(
|
private async buildOverview(
|
||||||
period: {
|
period: {
|
||||||
period_start: string | Date; period_end: string | Date; payday: string | Date;
|
period_start: string | Date; period_end: string | Date; payday: string | Date;
|
||||||
period_no: number; pay_year: number; label: string;
|
period_no: number; pay_year: number; label: string;
|
||||||
}, //add is_approved
|
},
|
||||||
options?: { filtered_employee_ids?: number[]; seed_names?: Map<number, { name: string, email: string }> }
|
options?: { filtered_employee_ids?: number[]; seed_names?: Map<number, { name: string, email: string }> }
|
||||||
): Promise<Result<PayPeriodOverviewDto, string>> {
|
): Promise<Result<PayPeriodOverviewDto, string>> {
|
||||||
const toDateString = (d: Date) => d.toISOString().slice(0, 10);
|
const toDateString = (d: Date) => d.toISOString().slice(0, 10);
|
||||||
|
|
@ -167,6 +169,7 @@ export class PayPeriodsQueryService {
|
||||||
is_remote: true,
|
is_remote: true,
|
||||||
timesheet: {
|
timesheet: {
|
||||||
select: {
|
select: {
|
||||||
|
id: true,
|
||||||
is_approved: true,
|
is_approved: true,
|
||||||
employee: {
|
employee: {
|
||||||
select: {
|
select: {
|
||||||
|
|
@ -193,6 +196,7 @@ export class PayPeriodsQueryService {
|
||||||
amount: true,
|
amount: true,
|
||||||
timesheet: {
|
timesheet: {
|
||||||
select: {
|
select: {
|
||||||
|
id: true,
|
||||||
is_approved: true,
|
is_approved: true,
|
||||||
employee: {
|
employee: {
|
||||||
select: {
|
select: {
|
||||||
|
|
@ -211,9 +215,20 @@ export class PayPeriodsQueryService {
|
||||||
bank_code: { select: { categorie: true, modifier: true, type: true } },
|
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 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
|
// seed for employee without data
|
||||||
if (options?.seed_names) {
|
if (options?.seed_names) {
|
||||||
for (const [id, { name, email }] of options.seed_names.entries()) {
|
for (const [id, { name, email }] of options.seed_names.entries()) {
|
||||||
|
|
@ -234,7 +249,6 @@ export class PayPeriodsQueryService {
|
||||||
expenses: 0,
|
expenses: 0,
|
||||||
mileage: 0,
|
mileage: 0,
|
||||||
is_approved: false,
|
is_approved: false,
|
||||||
is_remote: false,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -245,8 +259,8 @@ export class PayPeriodsQueryService {
|
||||||
first_name: true,
|
first_name: true,
|
||||||
last_name: true,
|
last_name: true,
|
||||||
email: true
|
email: true
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -256,7 +270,7 @@ export class PayPeriodsQueryService {
|
||||||
if (employee.last_work_day !== null) {
|
if (employee.last_work_day !== null) {
|
||||||
is_active = this.checkForInactiveDate(employee.last_work_day)
|
is_active = this.checkForInactiveDate(employee.last_work_day)
|
||||||
}
|
}
|
||||||
|
|
||||||
by_employee.set(employee.id, {
|
by_employee.set(employee.id, {
|
||||||
email: employee.user.email,
|
email: employee.user.email,
|
||||||
employee_name: employee.user.first_name + ' ' + employee.user.last_name,
|
employee_name: employee.user.first_name + ' ' + employee.user.last_name,
|
||||||
|
|
@ -273,8 +287,7 @@ export class PayPeriodsQueryService {
|
||||||
total_hours: 0,
|
total_hours: 0,
|
||||||
expenses: 0,
|
expenses: 0,
|
||||||
mileage: 0,
|
mileage: 0,
|
||||||
is_approved: false,
|
is_approved: timesheet.is_approved,
|
||||||
is_remote: false,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -297,8 +310,7 @@ export class PayPeriodsQueryService {
|
||||||
total_hours: 0,
|
total_hours: 0,
|
||||||
expenses: 0,
|
expenses: 0,
|
||||||
mileage: 0,
|
mileage: 0,
|
||||||
is_approved: false,
|
is_approved: timesheet.is_approved,
|
||||||
is_remote: false,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return by_employee.get(id)!;
|
return by_employee.get(id)!;
|
||||||
|
|
@ -336,7 +348,6 @@ export class PayPeriodsQueryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
record.is_approved = record.is_approved && shift.timesheet.is_approved;
|
record.is_approved = record.is_approved && shift.timesheet.is_approved;
|
||||||
record.is_remote = record.is_remote || !!shift.is_remote;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const expense of expenses) {
|
for (const expense of expenses) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user