Merge branch 'main' of git.targo.ca:Targo/targo_backend
This commit is contained in:
commit
6c89acbe0e
79
scripts/init-supervisor.ts
Normal file
79
scripts/init-supervisor.ts
Normal 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);
|
||||
// }
|
||||
// }
|
||||
|
|
@ -14,6 +14,7 @@ import * as session from 'express-session';
|
|||
import * as passport from 'passport';
|
||||
import { PrismaService } from 'src/prisma/prisma.service';
|
||||
import { PrismaSessionStore } from '@quixo3/prisma-session-store';
|
||||
// import { initSupervisor } from 'scripts/init-supervisor';
|
||||
// import { initializePaidTimeOff } from 'scripts/init-paid-time-off';
|
||||
// import { initializePreferences } from 'scripts/init-preferences-access';
|
||||
// import { extractOldTimesheets } from 'scripts/migrate-timesheets';
|
||||
|
|
@ -99,5 +100,6 @@ async function bootstrap() {
|
|||
// await extractOldTimesheets();
|
||||
// await extractOldShifts();
|
||||
// await extractOldExpenses();
|
||||
// await initSupervisor();
|
||||
}
|
||||
bootstrap();
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ export class BankedHoursService {
|
|||
const new_balance = await tx.paidTimeOff.update({
|
||||
where: { employee_id: employee.id },
|
||||
data: {
|
||||
banked_hours: { increment: asked_hours },
|
||||
banked_hours: { increment: (asked_hours) },
|
||||
last_updated: new Date(),
|
||||
},
|
||||
select: { banked_hours: true },
|
||||
|
|
|
|||
|
|
@ -25,8 +25,14 @@ export class PaidTimeOFfBankHoursService {
|
|||
og_start: Date,
|
||||
og_end: Date
|
||||
): Promise<Result<boolean, string>> => {
|
||||
const original_hours = computeHours(og_start, og_end);
|
||||
const ajusted_hours = computeHours(start_time, end_time);
|
||||
let original_hours = computeHours(og_start, og_end);
|
||||
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);
|
||||
|
||||
if (diff_hours === 0) return { success: true, data: true };
|
||||
|
|
@ -83,8 +89,11 @@ export class PaidTimeOFfBankHoursService {
|
|||
|
||||
//called during delete function of Shifts Module
|
||||
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 (type === 'BANKING') {
|
||||
ajusted_hours = ajusted_hours * 1.5;
|
||||
}
|
||||
|
||||
const config = paid_time_off_mapping[type];
|
||||
await this.prisma.paidTimeOff.update({
|
||||
|
|
|
|||
|
|
@ -103,13 +103,17 @@ export class ShiftsCreateService {
|
|||
|
||||
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 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 (dto.type === 'BANKING') {
|
||||
amount_hours = amount_hours * 1.5;
|
||||
}
|
||||
result = await this.bankingService.manageBankingHours(employee_id, amount_hours, dto.type);
|
||||
} else {
|
||||
switch (dto.type) {
|
||||
|
|
|
|||
|
|
@ -92,13 +92,19 @@ export class ShiftsUpdateService {
|
|||
//call to ajust paid_time_off hour banks
|
||||
if (paid_time_off_types.includes(original_type) || paid_time_off_types.includes(new_type)) {
|
||||
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)) {
|
||||
const restoration = await this.paidTimeOffService.restorePaidTimeOffHours(employee.data, original_type, original_hours);
|
||||
if (!restoration.success) return { success: false, error: restoration.error };
|
||||
}
|
||||
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);
|
||||
if (!validation.success) return { success: false, error: validation.error };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user