refactor(paid-time-off): refactor functions to use paid-time-off service instead.
This commit is contained in:
parent
c03ea4cb6f
commit
4c7c596d02
10
src/time-and-attendance/paid-time-off/paid-time-off.dto.ts
Normal file
10
src/time-and-attendance/paid-time-off/paid-time-off.dto.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
export const paid_time_off_types: string[] = ['SICK', 'VACATION', 'BANKING', 'WITHDRAW_BANKED'];
|
||||||
|
|
||||||
|
//used to simplify services
|
||||||
|
export const paid_time_off_mapping: Record<string, { field: string; invert_logic: boolean; operation: string; }> = {
|
||||||
|
SICK: { field: 'sick_hours', invert_logic: false, operation: 'increment' },
|
||||||
|
VACATION: { field: 'vacation_hours', invert_logic: false, operation: 'increment' },
|
||||||
|
WITHDRAW_BANKED: { field: 'banked_hours', invert_logic: true, operation: 'increment' },
|
||||||
|
BANKING: { field: 'banked_hours', invert_logic: false, operation: 'decrement' },
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { Module } from "@nestjs/common";
|
||||||
|
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
|
||||||
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
|
import { BankedHoursService } from "src/time-and-attendance/domains/services/banking-hours.service";
|
||||||
|
import { SickLeaveService } from "src/time-and-attendance/domains/services/sick-leave.service";
|
||||||
|
import { VacationService } from "src/time-and-attendance/domains/services/vacation.service";
|
||||||
|
import { PaidTimeOFfBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service";
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
providers: [
|
||||||
|
PrismaService,
|
||||||
|
EmailToIdResolver,
|
||||||
|
PaidTimeOFfBankHoursService,
|
||||||
|
VacationService,
|
||||||
|
SickLeaveService,
|
||||||
|
BankedHoursService,
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
PaidTimeOFfBankHoursService,
|
||||||
|
],
|
||||||
|
}) export class PaidTimeOffModule { }
|
||||||
|
|
@ -0,0 +1,95 @@
|
||||||
|
import { Injectable } from "@nestjs/common";
|
||||||
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
|
import { computeHours } from "src/common/utils/date-utils";
|
||||||
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
|
import { BankedHoursService } from "src/time-and-attendance/domains/services/banking-hours.service";
|
||||||
|
import { SickLeaveService } from "src/time-and-attendance/domains/services/sick-leave.service";
|
||||||
|
import { VacationService } from "src/time-and-attendance/domains/services/vacation.service";
|
||||||
|
import { paid_time_off_mapping, paid_time_off_types } from "src/time-and-attendance/paid-time-off/paid-time-off.dto";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class PaidTimeOFfBankHoursService {
|
||||||
|
constructor(
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
private readonly bankingService: BankedHoursService,
|
||||||
|
private readonly vacationService: VacationService,
|
||||||
|
private readonly sickLeaveService: SickLeaveService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
//called during update function of Shifts Module
|
||||||
|
updatePaidTimeOffBankHoursWhenShiftUpdate = async (
|
||||||
|
start_time: Date,
|
||||||
|
end_time: Date,
|
||||||
|
type: string,
|
||||||
|
employee_id: number,
|
||||||
|
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);
|
||||||
|
const diff_hours = Math.abs(ajusted_hours - original_hours);
|
||||||
|
|
||||||
|
if (diff_hours === 0) return { success: true, data: true };
|
||||||
|
if (!paid_time_off_types.includes(type)) return { success: false, error: 'INVALID_SHIFT_TYPE' };
|
||||||
|
|
||||||
|
if (ajusted_hours > original_hours) {
|
||||||
|
const validation = await this.validateAndDeductPaidTimeOff(employee_id, type, diff_hours);
|
||||||
|
if (!validation.success) return { success: false, error: validation.error };
|
||||||
|
} else {
|
||||||
|
const restoration = await this.restorePaidTimeOffHours(employee_id, type, diff_hours);
|
||||||
|
if (!restoration.success) return { success: false, error: restoration.error };
|
||||||
|
}
|
||||||
|
return { success: true, data: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
validateAndDeductPaidTimeOff = async (employee_id: number, type: string, hours: number): Promise<Result<number, string>> => {
|
||||||
|
const banking_types: string[] = ['BANKING', 'WITHDRAW_BANKED'];
|
||||||
|
if (banking_types.includes(type)) {
|
||||||
|
return await this.bankingService.manageBankingHours(employee_id, hours, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'VACATION': {
|
||||||
|
return await this.vacationService.manageVacationHoursBank(employee_id, hours);
|
||||||
|
}
|
||||||
|
case 'SICK': {
|
||||||
|
return await this.sickLeaveService.takeSickLeaveHours(employee_id, hours);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return { success: false, error: 'INVALID_PAID_TIME_OFF_TYPE' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
restorePaidTimeOffHours = async (employee_id: number, type: string, hours: number): Promise<Result<boolean, string>> => {
|
||||||
|
try {
|
||||||
|
const config = paid_time_off_mapping[type];
|
||||||
|
if (!config) return { success: false, error: 'INVALID_PAID_TIME_OFF_TYPE' }
|
||||||
|
const operation = config.invert_logic ? 'decrement' : 'increment';
|
||||||
|
|
||||||
|
await this.prisma.paidTimeOff.update({
|
||||||
|
where: { employee_id },
|
||||||
|
data: { [config.field]: { [operation]: hours } },
|
||||||
|
});
|
||||||
|
return { success: true, data: true };
|
||||||
|
} catch (error) {
|
||||||
|
return { success: false, error: 'PAID_TIME_OFF_NOT_FOUND' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//called during delete function of Shifts Module
|
||||||
|
updatePaidTimeoffBankHoursWhenShiftDelete = async (start: Date, end: Date, type: string, employee_id: number) => {
|
||||||
|
const ajusted_hours = computeHours(start, end);
|
||||||
|
if (!paid_time_off_types.includes(type)) return;
|
||||||
|
|
||||||
|
const config = paid_time_off_mapping[type];
|
||||||
|
await this.prisma.paidTimeOff.update({
|
||||||
|
where: { employee_id },
|
||||||
|
data: {
|
||||||
|
[config.field]: { [config.operation]: ajusted_hours },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ import { ShiftDto } from "src/time-and-attendance/shifts/shift.dto";
|
||||||
import { VacationService } from "src/time-and-attendance/domains/services/vacation.service";
|
import { VacationService } from "src/time-and-attendance/domains/services/vacation.service";
|
||||||
import { BankedHoursService } from "src/time-and-attendance/domains/services/banking-hours.service";
|
import { BankedHoursService } from "src/time-and-attendance/domains/services/banking-hours.service";
|
||||||
import { SickLeaveService } from "src/time-and-attendance/domains/services/sick-leave.service";
|
import { SickLeaveService } from "src/time-and-attendance/domains/services/sick-leave.service";
|
||||||
|
import { paid_time_off_types } from "src/time-and-attendance/paid-time-off/paid-time-off.dto";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ShiftsCreateService {
|
export class ShiftsCreateService {
|
||||||
|
|
@ -100,31 +101,36 @@ export class ShiftsCreateService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//api call to validate available hours in vacation_bank and ajust end_time accordingly
|
let adjusted_end_time = normed_shift.data.end_time;
|
||||||
if (dto.type === 'VACATION') {
|
|
||||||
const asked_hours = computeHours(toDateFromHHmm(dto.start_time), toDateFromHHmm(dto.end_time));
|
|
||||||
const vacation_shift = await this.vacationService.manageVacationHoursBank(employee_id, asked_hours)
|
|
||||||
if (!vacation_shift.success) return { success: false, error: vacation_shift.error };
|
|
||||||
dto.end_time = this.addHourstoDateString(dto.start_time, vacation_shift.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
//api call to validate available hours in banked_hours and ajust end_time accordingly
|
if (paid_time_off_types.includes(dto.type)) {
|
||||||
const banking_types: string[] = ['BANKING', 'WITHDRAW_BANKED'];
|
const amount_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time);
|
||||||
if (banking_types.includes(dto.type)) {
|
const banking_types: string[] = ['BANKING', 'WITHDRAW_BANKED'];
|
||||||
const hours = computeHours(toDateFromHHmm(dto.start_time), toDateFromHHmm(dto.end_time));
|
|
||||||
const banking_shift = await this.bankingService.manageBankingHours(employee_id, hours, dto.type);
|
let result: Result<number, string>;
|
||||||
if (!banking_shift.success) return { success: false, error: banking_shift.error };
|
|
||||||
dto.end_time = this.addHourstoDateString(dto.start_time, banking_shift.data);
|
if (banking_types.includes(dto.type)) {
|
||||||
}
|
result = await this.bankingService.manageBankingHours(employee_id, amount_hours, dto.type);
|
||||||
|
} else {
|
||||||
//api call to validate available hours in sick_hours and ajust end_time accordingly
|
switch (dto.type) {
|
||||||
if (dto.type === 'SICK') {
|
case 'VACATION': {
|
||||||
console.log('got here')
|
result = await this.vacationService.manageVacationHoursBank(employee_id, amount_hours);
|
||||||
const hours = computeHours(toDateFromHHmm(dto.start_time), toDateFromHHmm(dto.end_time));
|
break;
|
||||||
const sick_hours = await this.sickService.takeSickLeaveHours(employee_id, hours);
|
}
|
||||||
if (!sick_hours.success) return { success: false, error: sick_hours.error };
|
case 'SICK': {
|
||||||
console.log(sick_hours.data)
|
result = await this.sickService.takeSickLeaveHours(employee_id, amount_hours);
|
||||||
dto.end_time = this.addHourstoDateString(dto.start_time, sick_hours.data);
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
result = { success: false, error: 'INVALID_PAID_TIME_OFF_TYPE' };
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result.success) return { success: false, error: result.error };
|
||||||
|
const valid_hours = result.data;
|
||||||
|
adjusted_end_time = new Date(normed_shift.data.start_time);
|
||||||
|
adjusted_end_time.setHours(adjusted_end_time.getHours() + valid_hours);
|
||||||
}
|
}
|
||||||
|
|
||||||
//sends data for creation of a shift in db
|
//sends data for creation of a shift in db
|
||||||
|
|
@ -134,7 +140,7 @@ export class ShiftsCreateService {
|
||||||
bank_code_id: bank_code_id.data,
|
bank_code_id: bank_code_id.data,
|
||||||
date: normed_shift.data.date,
|
date: normed_shift.data.date,
|
||||||
start_time: normed_shift.data.start_time,
|
start_time: normed_shift.data.start_time,
|
||||||
end_time: normed_shift.data.end_time,
|
end_time: adjusted_end_time,
|
||||||
is_approved: dto.is_approved,
|
is_approved: dto.is_approved,
|
||||||
is_remote: dto.is_remote,
|
is_remote: dto.is_remote,
|
||||||
comment: dto.comment ?? '',
|
comment: dto.comment ?? '',
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,14 @@ import { Injectable } from "@nestjs/common";
|
||||||
import { Result } from "src/common/errors/result-error.factory";
|
import { Result } from "src/common/errors/result-error.factory";
|
||||||
import { computeHours } from "src/common/utils/date-utils";
|
import { computeHours } from "src/common/utils/date-utils";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
|
import { PaidTimeOFfBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ShiftsDeleteService {
|
export class ShiftsDeleteService {
|
||||||
constructor(private readonly prisma: PrismaService) { }
|
constructor(
|
||||||
|
private readonly prisma: PrismaService,
|
||||||
|
private readonly paidTimeOffService: PaidTimeOFfBankHoursService,
|
||||||
|
) { }
|
||||||
//_________________________________________________________________
|
//_________________________________________________________________
|
||||||
// DELETE
|
// DELETE
|
||||||
//_________________________________________________________________
|
//_________________________________________________________________
|
||||||
|
|
@ -15,7 +19,6 @@ export class ShiftsDeleteService {
|
||||||
async deleteShift(shift_id: number): Promise<Result<number, string>> {
|
async deleteShift(shift_id: number): Promise<Result<number, string>> {
|
||||||
try {
|
try {
|
||||||
return await this.prisma.$transaction(async (tx) => {
|
return await this.prisma.$transaction(async (tx) => {
|
||||||
const paid_time_off_types: string[] = ['SICK', 'VACATION', 'BANKING', 'WITHDRAW_BANKED'];
|
|
||||||
const shift = await tx.shifts.findUnique({
|
const shift = await tx.shifts.findUnique({
|
||||||
where: { id: shift_id },
|
where: { id: shift_id },
|
||||||
select: {
|
select: {
|
||||||
|
|
@ -24,56 +27,26 @@ export class ShiftsDeleteService {
|
||||||
start_time: true,
|
start_time: true,
|
||||||
end_time: true,
|
end_time: true,
|
||||||
timesheet: true,
|
timesheet: true,
|
||||||
bank_code: { select: { type: true } }
|
is_approved: true,
|
||||||
|
bank_code: { select: { type: true } },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!shift) return { success: false, error: `SHIFT_NOT_FOUND` };
|
if (!shift) return { success: false, error: `SHIFT_NOT_FOUND` };
|
||||||
const ajusted_hours = computeHours(shift.start_time, shift.end_time);
|
if (shift.is_approved) return { success: false, error: 'APPROUVED_SHIFT' };
|
||||||
|
|
||||||
//manage banked types, ensures update of amount of hours in bank is ajusted when a paid_time_off shift is deleted
|
//call to ajust paid_time_off hour banks
|
||||||
if (paid_time_off_types.includes(shift.bank_code.type)) {
|
await this.paidTimeOffService.updatePaidTimeoffBankHoursWhenShiftDelete(
|
||||||
switch (shift.bank_code.type) {
|
shift.start_time,
|
||||||
case 'SICK':
|
shift.end_time,
|
||||||
await this.prisma.paidTimeOff.update({
|
shift.bank_code.type,
|
||||||
where: { employee_id: shift.timesheet.employee_id },
|
shift.timesheet.employee_id
|
||||||
data: {
|
);
|
||||||
sick_hours: { increment: ajusted_hours },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case 'VACATION':
|
|
||||||
await this.prisma.paidTimeOff.update({
|
|
||||||
where: { employee_id: shift.timesheet.employee_id },
|
|
||||||
data: {
|
|
||||||
vacation_hours: { increment: ajusted_hours },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case 'WITHDRAW_BANKED':
|
|
||||||
await this.prisma.paidTimeOff.update({
|
|
||||||
where: { employee_id: shift.timesheet.employee_id },
|
|
||||||
data: {
|
|
||||||
banked_hours: { decrement: ajusted_hours },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
case 'BANKING':
|
|
||||||
await this.prisma.paidTimeOff.update({
|
|
||||||
where: { employee_id: shift.timesheet.employee_id },
|
|
||||||
data: {
|
|
||||||
banked_hours: { increment: ajusted_hours },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await tx.shifts.delete({ where: { id: shift_id } });
|
await tx.shifts.delete({ where: { id: shift_id } });
|
||||||
return { success: true, data: shift.id };
|
return { success: true, data: shift.id };
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { success: false, error: `SHIFT_NOT_FOUND` }
|
return { success: false, error: `SHIFT_NOT_FOUND` };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,6 +10,8 @@ import { shift_select } from "src/time-and-attendance/utils/selects.utils";
|
||||||
import { Normalized } from "src/time-and-attendance/utils/type.utils";
|
import { Normalized } from "src/time-and-attendance/utils/type.utils";
|
||||||
import { ShiftDto } from "src/time-and-attendance/shifts/shift.dto";
|
import { ShiftDto } from "src/time-and-attendance/shifts/shift.dto";
|
||||||
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
|
import { EmailToIdResolver } from "src/common/mappers/email-id.mapper";
|
||||||
|
import { PaidTimeOFfBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service";
|
||||||
|
import { paid_time_off_types } from "src/time-and-attendance/paid-time-off/paid-time-off.dto";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ShiftsUpdateService {
|
export class ShiftsUpdateService {
|
||||||
|
|
@ -18,6 +20,7 @@ export class ShiftsUpdateService {
|
||||||
private readonly typeResolver: BankCodesResolver,
|
private readonly typeResolver: BankCodesResolver,
|
||||||
private readonly timesheetResolver: EmployeeTimesheetResolver,
|
private readonly timesheetResolver: EmployeeTimesheetResolver,
|
||||||
private readonly emailResolver: EmailToIdResolver,
|
private readonly emailResolver: EmailToIdResolver,
|
||||||
|
private readonly paidTimeOffService: PaidTimeOFfBankHoursService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
async updateOneOrManyShifts(shifts: ShiftDto[], email: string): Promise<Result<boolean, string>> {
|
async updateOneOrManyShifts(shifts: ShiftDto[], email: string): Promise<Result<boolean, string>> {
|
||||||
|
|
@ -62,12 +65,10 @@ export class ShiftsUpdateService {
|
||||||
//_________________________________________________________________
|
//_________________________________________________________________
|
||||||
async updateShift(dto: ShiftDto, email: string): Promise<Result<ShiftDto, string>> {
|
async updateShift(dto: ShiftDto, email: string): Promise<Result<ShiftDto, string>> {
|
||||||
try {
|
try {
|
||||||
// const paid_time_off_types: string[] = ['SICK', 'VACATION', 'BANKING', 'WITHDRAW_BANKED'];
|
|
||||||
const timesheet = await this.timesheetResolver.findTimesheetIdByEmail(email, toDateFromString(dto.date));
|
const timesheet = await this.timesheetResolver.findTimesheetIdByEmail(email, toDateFromString(dto.date));
|
||||||
if (!timesheet.success) return { success: false, error: timesheet.error };
|
if (!timesheet.success) return { success: false, error: timesheet.error };
|
||||||
const employee = await this.emailResolver.findIdByEmail(email);
|
const employee = await this.emailResolver.findIdByEmail(email);
|
||||||
if (!employee.success) return { success: false, error: employee.error };
|
if (!employee.success) return { success: false, error: employee.error };
|
||||||
|
|
||||||
//finds original shift
|
//finds original shift
|
||||||
const original = await this.prisma.shifts.findFirst({
|
const original = await this.prisma.shifts.findFirst({
|
||||||
where: { id: dto.id, timesheet_id: timesheet.data.id },
|
where: { id: dto.id, timesheet_id: timesheet.data.id },
|
||||||
|
|
@ -83,51 +84,37 @@ export class ShiftsUpdateService {
|
||||||
//finds bank_code_id using the type
|
//finds bank_code_id using the type
|
||||||
const bank_code = await this.typeResolver.findBankCodeIDByType(dto.type);
|
const bank_code = await this.typeResolver.findBankCodeIDByType(dto.type);
|
||||||
if (!bank_code.success) return { success: false, error: bank_code.error };
|
if (!bank_code.success) return { success: false, error: bank_code.error };
|
||||||
// const original_hours = computeHours(original.start_time, original.end_time);
|
|
||||||
// const ajusted_hours = computeHours(toDateFromHHmm(dto.start_time), toDateFromHHmm(dto.end_time));
|
|
||||||
|
|
||||||
// if (paid_time_off_types.includes(dto.type)) {
|
const original_type = original.bank_code.type;
|
||||||
// switch (dto.type) {
|
const new_type = dto.type;
|
||||||
// case 'SICK':
|
const type_changed = original_type !== new_type;
|
||||||
// if (ajusted_hours < original_hours){
|
|
||||||
// const diff_hours = original_hours - ajusted_hours;
|
//call to ajust paid_time_off hour banks
|
||||||
// await this.prisma.paidTimeOff.update({
|
if (paid_time_off_types.includes(original_type) || paid_time_off_types.includes(new_type)) {
|
||||||
// where: { employee_id: employee.data },
|
if (type_changed) {
|
||||||
// data: {
|
const original_hours = computeHours(original.start_time, original.end_time);
|
||||||
// sick_hours: { decrement: diff_hours },
|
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 };
|
||||||
// } else {
|
}
|
||||||
|
if (paid_time_off_types.includes(new_type)) {
|
||||||
// }
|
const new_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time);
|
||||||
// break;
|
const validation = await this.paidTimeOffService.validateAndDeductPaidTimeOff(employee.data, new_type, new_hours);
|
||||||
// case 'VACATION':
|
if (!validation.success) return { success: false, error: validation.error };
|
||||||
// await this.prisma.paidTimeOff.update({
|
}
|
||||||
// where: { employee_id: shift.timesheet.employee_id },
|
} else {
|
||||||
// data: {
|
const result = await this.paidTimeOffService.updatePaidTimeOffBankHoursWhenShiftUpdate(
|
||||||
// vacation_hours: { increment: ajusted_hours },
|
normed_shift.data.start_time,
|
||||||
// },
|
normed_shift.data.end_time,
|
||||||
// });
|
dto.type,
|
||||||
// break;
|
employee.data,
|
||||||
// case 'WITHDRAW_BANKED':
|
original.start_time,
|
||||||
// await this.prisma.paidTimeOff.update({
|
original.end_time
|
||||||
// where: { employee_id: shift.timesheet.employee_id },
|
);
|
||||||
// data: {
|
if (!result.success) return { success: false, error: result.error };
|
||||||
// banked_hours: { decrement: ajusted_hours },
|
}
|
||||||
// },
|
|
||||||
// });
|
}
|
||||||
// case 'BANKING':
|
|
||||||
// await this.prisma.paidTimeOff.update({
|
|
||||||
// where: { employee_id: shift.timesheet.employee_id },
|
|
||||||
// data: {
|
|
||||||
// banked_hours: { increment: ajusted_hours },
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
//updates sent to DB
|
//updates sent to DB
|
||||||
const updated = await this.prisma.shifts.update({
|
const updated = await this.prisma.shifts.update({
|
||||||
|
|
@ -3,7 +3,7 @@ import { Modules as ModulesEnum } from ".prisma/client";
|
||||||
|
|
||||||
import { ShiftDto } from "src/time-and-attendance/shifts/shift.dto";
|
import { ShiftDto } from "src/time-and-attendance/shifts/shift.dto";
|
||||||
import { ShiftsCreateService } from "src/time-and-attendance/shifts/services/shifts-create.service";
|
import { ShiftsCreateService } from "src/time-and-attendance/shifts/services/shifts-create.service";
|
||||||
import { ShiftsUpdateService } from "src/time-and-attendance/shifts/services/shifts-update-delete.service";
|
import { ShiftsUpdateService } from "src/time-and-attendance/shifts/services/shifts-update.service";
|
||||||
import { ShiftsDeleteService } from "src/time-and-attendance/shifts/services/shifts-delete.service";
|
import { ShiftsDeleteService } from "src/time-and-attendance/shifts/services/shifts-delete.service";
|
||||||
|
|
||||||
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,29 @@ import { Module } from '@nestjs/common';
|
||||||
import { ShiftController } from 'src/time-and-attendance/shifts/shift.controller';
|
import { ShiftController } from 'src/time-and-attendance/shifts/shift.controller';
|
||||||
import { ShiftsCreateService } from 'src/time-and-attendance/shifts/services/shifts-create.service';
|
import { ShiftsCreateService } from 'src/time-and-attendance/shifts/services/shifts-create.service';
|
||||||
import { ShiftsDeleteService } from 'src/time-and-attendance/shifts/services/shifts-delete.service';
|
import { ShiftsDeleteService } from 'src/time-and-attendance/shifts/services/shifts-delete.service';
|
||||||
import { ShiftsUpdateService } from 'src/time-and-attendance/shifts/services/shifts-update-delete.service';
|
import { ShiftsUpdateService } from 'src/time-and-attendance/shifts/services/shifts-update.service';
|
||||||
import { VacationService } from 'src/time-and-attendance/domains/services/vacation.service';
|
import { VacationService } from 'src/time-and-attendance/domains/services/vacation.service';
|
||||||
import { BankedHoursService } from 'src/time-and-attendance/domains/services/banking-hours.service';
|
import { BankedHoursService } from 'src/time-and-attendance/domains/services/banking-hours.service';
|
||||||
|
import { PaidTimeOffModule } from 'src/time-and-attendance/paid-time-off/paid-time-off.module';
|
||||||
|
import { ShiftsGetService } from 'src/time-and-attendance/shifts/services/shifts-get.service';
|
||||||
|
import { PaidTimeOFfBankHoursService } from 'src/time-and-attendance/paid-time-off/paid-time-off.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
|
imports: [PaidTimeOffModule],
|
||||||
controllers: [ShiftController],
|
controllers: [ShiftController],
|
||||||
providers: [ShiftsCreateService, ShiftsUpdateService, ShiftsDeleteService, VacationService, BankedHoursService],
|
providers: [
|
||||||
exports: [ShiftsCreateService, ShiftsUpdateService, ShiftsDeleteService],
|
ShiftsCreateService,
|
||||||
|
ShiftsUpdateService,
|
||||||
|
ShiftsDeleteService,
|
||||||
|
VacationService,
|
||||||
|
BankedHoursService,
|
||||||
|
PaidTimeOFfBankHoursService,
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
ShiftsCreateService,
|
||||||
|
ShiftsUpdateService,
|
||||||
|
ShiftsDeleteService,
|
||||||
|
ShiftsGetService,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class ShiftsModule { }
|
export class ShiftsModule { }
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import { CsvExportController } from "src/time-and-attendance/exports/csv-exports
|
||||||
import { ShiftController } from "src/time-and-attendance/shifts/shift.controller";
|
import { ShiftController } from "src/time-and-attendance/shifts/shift.controller";
|
||||||
import { ShiftsCreateService } from "src/time-and-attendance/shifts/services/shifts-create.service";
|
import { ShiftsCreateService } from "src/time-and-attendance/shifts/services/shifts-create.service";
|
||||||
import { ShiftsGetService } from "src/time-and-attendance/shifts/services/shifts-get.service";
|
import { ShiftsGetService } from "src/time-and-attendance/shifts/services/shifts-get.service";
|
||||||
import { ShiftsUpdateService } from "src/time-and-attendance/shifts/services/shifts-update-delete.service";
|
import { ShiftsUpdateService } from "src/time-and-attendance/shifts/services/shifts-update.service";
|
||||||
import { ShiftsDeleteService } from "src/time-and-attendance/shifts/services/shifts-delete.service";
|
import { ShiftsDeleteService } from "src/time-and-attendance/shifts/services/shifts-delete.service";
|
||||||
|
|
||||||
import { SchedulePresetsGetService } from "src/time-and-attendance/schedule-presets/services/schedule-presets-get.service";
|
import { SchedulePresetsGetService } from "src/time-and-attendance/schedule-presets/services/schedule-presets-get.service";
|
||||||
|
|
@ -41,6 +41,8 @@ import { SchedulePresetsApplyService } from "src/time-and-attendance/schedule-pr
|
||||||
import { CsvGeneratorService } from "src/time-and-attendance/exports/services/csv-builder.service";
|
import { CsvGeneratorService } from "src/time-and-attendance/exports/services/csv-builder.service";
|
||||||
import { VacationService } from "src/time-and-attendance/domains/services/vacation.service";
|
import { VacationService } from "src/time-and-attendance/domains/services/vacation.service";
|
||||||
import { BankedHoursService } from "src/time-and-attendance/domains/services/banking-hours.service";
|
import { BankedHoursService } from "src/time-and-attendance/domains/services/banking-hours.service";
|
||||||
|
import { PaidTimeOffModule } from "src/time-and-attendance/paid-time-off/paid-time-off.module";
|
||||||
|
import { PaidTimeOFfBankHoursService } from "src/time-and-attendance/paid-time-off/paid-time-off.service";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
|
@ -51,6 +53,7 @@ import { BankedHoursService } from "src/time-and-attendance/domains/services/ban
|
||||||
PayperiodsModule,
|
PayperiodsModule,
|
||||||
CsvExportModule,
|
CsvExportModule,
|
||||||
SchedulePresetsModule,
|
SchedulePresetsModule,
|
||||||
|
PaidTimeOffModule,
|
||||||
],
|
],
|
||||||
controllers: [
|
controllers: [
|
||||||
TimesheetController,
|
TimesheetController,
|
||||||
|
|
@ -84,6 +87,7 @@ import { BankedHoursService } from "src/time-and-attendance/domains/services/ban
|
||||||
CsvGeneratorService,
|
CsvGeneratorService,
|
||||||
VacationService,
|
VacationService,
|
||||||
BankedHoursService,
|
BankedHoursService,
|
||||||
|
PaidTimeOFfBankHoursService,
|
||||||
],
|
],
|
||||||
exports: [TimesheetApprovalService],
|
exports: [TimesheetApprovalService],
|
||||||
}) export class TimeAndAttendanceModule { };
|
}) export class TimeAndAttendanceModule { };
|
||||||
Loading…
Reference in New Issue
Block a user