targo-backend/src/time-and-attendance/domains/services/banking-hours.service.service.ts
2026-01-08 14:20:05 -05:00

64 lines
2.3 KiB
TypeScript

// import { Injectable } from "@nestjs/common";
// import { Result } from "src/common/errors/result-error.factory";
// import { PrismaService } from "src/prisma/prisma.service";
// @Injectable()
// export class BankedHoursService {
// constructor(private readonly prisma: PrismaService) { }
// //manage shifts with bank_code.type BANKING
// bankingHours = async (employee_id: number, hours: number): Promise<Result<number, string>> => {
// if (hours <= 0) return { success: false, error: 'INVALID_BANKING_HOURS' };
// try {
// const result = await this.prisma.$transaction(async (tx) => {
// const employee = await this.prisma.employees.findUnique({
// where: { id: employee_id },
// select: {
// id: true,
// paid_time_off: {
// select: {
// banked_hours: true
// },
// },
// },
// });
// if (!employee) {
// return { success: false, error: 'EMPLOYEE_NOT_FOUND' } as Result<number, string>
// }
// if (!employee.paid_time_off) {
// return { success: false, error: 'VACATION_HOURS_BANK_NOT_FOUND' } as Result<number, string>
// }
// const new_balance = await tx.paidTimeOff.update({
// where: { employee_id: employee.id },
// data: {
// banked_hours: { increment: hours },
// },
// select: {
// banked_hours: true,
// },
// });
// return { success: true, data: new_balance };
// });
// return result;
// } catch (error) {
// return { success: false, error: 'INVALID_BANKING_SHIFT' };
// }
// }
// //manage shifts with bank_code.type WITHDRAW_BANKED
// withdrawBankedHours = async (employee_id: number, asked_hours: number): Promise<Result<number, string>> => {
// if (asked_hours <= 0) return { success: false, error: 'INVALID_WITHDRAW_BANKED' };
// }
// }