Merge branch 'main' of git.targo.ca:Targo/targo_backend

This commit is contained in:
Nicolas Drolet 2026-01-13 16:27:31 -05:00
commit 6c89acbe0e
6 changed files with 109 additions and 9 deletions

View File

@ -0,0 +1,79 @@
// import { PrismaClient as Prisma } from "@prisma/client";
// import { PrismaClient as PrismaLegacy } from "@prisma/client-legacy"
// const prisma_legacy = new PrismaLegacy({});
// const prisma = new Prisma({});
// export const initSupervisor = async () => {
// const list_of_employees = await prisma.employees.findMany();
// for (const employee of list_of_employees) {
// console.log('Start of supervisor checking for employee: ', employee.id);
// //finds in old db employee supervisor's infos
// const old_employee = await prisma_legacy.employees.findFirst({
// where: {
// company: employee.company_code,
// employee_number: (employee.external_payroll_id).toString(),
// },
// });
// if (!old_employee) {
// console.warn('Old DB employee not found : ', employee.id);
// continue;
// }
// if (!old_employee.supervisor) {
// console.warn('Old DB employee supervisor not found for employee:', old_employee.supervisor);
// continue;
// }
// //trims and split the supervisor name
// const supervisor_full_name = old_employee.supervisor.trim();
// let supervisor_first_name = supervisor_full_name.split(/\s+/)[0];
// let supervisor_last_name = supervisor_full_name.split(/\s+/)[1] || '';
// if (supervisor_first_name === '[default]') {
// await prisma.employees.update({
// where: { id: employee.id },
// data: { supervisor_id: null },
// });
// console.log('employee with [default] found: ', employee.id);
// continue;
// }
// if (supervisor_first_name === '') {
// console.warn('No supervisor name found for employee: ', employee.id)
// continue;
// }
// //finds employee id of supervisors
// const supervisor = await prisma.users.findFirst({
// where: { first_name: supervisor_first_name, last_name: supervisor_last_name },
// select: {
// employee: { select: { id: true } },
// }
// });
// if (!supervisor) {
// console.warn('No supervisor found: ', supervisor_first_name, '', supervisor_last_name)
// continue;
// }
// if (!supervisor.employee) {
// console.warn('No supervisor id found: ', supervisor_first_name, '', supervisor_last_name)
// continue;
// }
// //updates the supervisor id
// await prisma.employees.update({
// where: { id: employee.id },
// data: {
// supervisor_id: supervisor.employee.id,
// }
// });
// await prisma.employees.update({
// where: { id: supervisor.employee.id },
// data: {
// is_supervisor: true,
// }
// })
// console.log('supervisor id : ', supervisor.employee.id);
// console.log('supervisor name : ', supervisor_first_name, '', supervisor_last_name);
// }
// }

View File

@ -14,6 +14,7 @@ import * as session from 'express-session';
import * as passport from 'passport'; import * as passport from 'passport';
import { PrismaService } from 'src/prisma/prisma.service'; import { PrismaService } from 'src/prisma/prisma.service';
import { PrismaSessionStore } from '@quixo3/prisma-session-store'; import { PrismaSessionStore } from '@quixo3/prisma-session-store';
// import { initSupervisor } from 'scripts/init-supervisor';
// import { initializePaidTimeOff } from 'scripts/init-paid-time-off'; // import { initializePaidTimeOff } from 'scripts/init-paid-time-off';
// import { initializePreferences } from 'scripts/init-preferences-access'; // import { initializePreferences } from 'scripts/init-preferences-access';
// import { extractOldTimesheets } from 'scripts/migrate-timesheets'; // import { extractOldTimesheets } from 'scripts/migrate-timesheets';
@ -99,5 +100,6 @@ async function bootstrap() {
// await extractOldTimesheets(); // await extractOldTimesheets();
// await extractOldShifts(); // await extractOldShifts();
// await extractOldExpenses(); // await extractOldExpenses();
// await initSupervisor();
} }
bootstrap(); bootstrap();

View File

@ -40,7 +40,7 @@ export class BankedHoursService {
const new_balance = await tx.paidTimeOff.update({ const new_balance = await tx.paidTimeOff.update({
where: { employee_id: employee.id }, where: { employee_id: employee.id },
data: { data: {
banked_hours: { increment: asked_hours }, banked_hours: { increment: (asked_hours) },
last_updated: new Date(), last_updated: new Date(),
}, },
select: { banked_hours: true }, select: { banked_hours: true },

View File

@ -25,8 +25,14 @@ export class PaidTimeOFfBankHoursService {
og_start: Date, og_start: Date,
og_end: Date og_end: Date
): Promise<Result<boolean, string>> => { ): Promise<Result<boolean, string>> => {
const original_hours = computeHours(og_start, og_end); let original_hours = computeHours(og_start, og_end);
const ajusted_hours = computeHours(start_time, end_time); let ajusted_hours = computeHours(start_time, end_time);
if (type === 'BANKING') {
original_hours = original_hours * 1.5;
ajusted_hours = ajusted_hours * 1.5;
}
const diff_hours = Math.abs(ajusted_hours - original_hours); const diff_hours = Math.abs(ajusted_hours - original_hours);
if (diff_hours === 0) return { success: true, data: true }; if (diff_hours === 0) return { success: true, data: true };
@ -83,8 +89,11 @@ export class PaidTimeOFfBankHoursService {
//called during delete function of Shifts Module //called during delete function of Shifts Module
updatePaidTimeoffBankHoursWhenShiftDelete = async (start: Date, end: Date, type: string, employee_id: number) => { updatePaidTimeoffBankHoursWhenShiftDelete = async (start: Date, end: Date, type: string, employee_id: number) => {
const ajusted_hours = computeHours(start, end); let ajusted_hours = computeHours(start, end);
if (!paid_time_off_types.includes(type)) return; if (!paid_time_off_types.includes(type)) return;
if (type === 'BANKING') {
ajusted_hours = ajusted_hours * 1.5;
}
const config = paid_time_off_mapping[type]; const config = paid_time_off_mapping[type];
await this.prisma.paidTimeOff.update({ await this.prisma.paidTimeOff.update({

View File

@ -103,13 +103,17 @@ export class ShiftsCreateService {
let adjusted_end_time = normed_shift.data.end_time; let adjusted_end_time = normed_shift.data.end_time;
if (paid_time_off_types.includes(dto.type)) {
const amount_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time);
const banking_types: string[] = ['BANKING', 'WITHDRAW_BANKED'];
if (paid_time_off_types.includes(dto.type)) {
let result: Result<number, string>; let result: Result<number, string>;
let amount_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time);
const banking_types: string[] = ['BANKING', 'WITHDRAW_BANKED'];
if (banking_types.includes(dto.type)) { if (banking_types.includes(dto.type)) {
if (dto.type === 'BANKING') {
amount_hours = amount_hours * 1.5;
}
result = await this.bankingService.manageBankingHours(employee_id, amount_hours, dto.type); result = await this.bankingService.manageBankingHours(employee_id, amount_hours, dto.type);
} else { } else {
switch (dto.type) { switch (dto.type) {

View File

@ -92,13 +92,19 @@ export class ShiftsUpdateService {
//call to ajust paid_time_off hour banks //call to ajust paid_time_off hour banks
if (paid_time_off_types.includes(original_type) || paid_time_off_types.includes(new_type)) { if (paid_time_off_types.includes(original_type) || paid_time_off_types.includes(new_type)) {
if (type_changed) { if (type_changed) {
const original_hours = computeHours(original.start_time, original.end_time); let original_hours = computeHours(original.start_time, original.end_time);
if (original_type === 'BANKING') {
original_hours = original_hours * 1.5;
}
if (paid_time_off_types.includes(original_type)) { if (paid_time_off_types.includes(original_type)) {
const restoration = await this.paidTimeOffService.restorePaidTimeOffHours(employee.data, original_type, original_hours); const restoration = await this.paidTimeOffService.restorePaidTimeOffHours(employee.data, original_type, original_hours);
if (!restoration.success) return { success: false, error: restoration.error }; if (!restoration.success) return { success: false, error: restoration.error };
} }
if (paid_time_off_types.includes(new_type)) { if (paid_time_off_types.includes(new_type)) {
const new_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time); let new_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time);
if (new_type === 'BANKING') {
new_hours = new_hours * 1.5;
}
const validation = await this.paidTimeOffService.validateAndDeductPaidTimeOff(employee.data, new_type, new_hours); const validation = await this.paidTimeOffService.validateAndDeductPaidTimeOff(employee.data, new_type, new_hours);
if (!validation.success) return { success: false, error: validation.error }; if (!validation.success) return { success: false, error: validation.error };
} }