refactor(module): refactored expenses and shifts approval to be made in batch iva timesheets

This commit is contained in:
Matthieu Haineault 2025-08-19 08:44:36 -04:00
parent 7a9adeec69
commit a23a6299dd
2 changed files with 50 additions and 2 deletions

View File

@ -1,5 +1,7 @@
import { Injectable } from "@nestjs/common";
import { Expenses } from "@prisma/client";
import { Expenses, Prisma } from "@prisma/client";
import { Decimal } from "@prisma/client/runtime/library";
import { transcode } from "buffer";
import { BaseApprovalService } from "src/common/shared/base-approval.service";
import { PrismaService } from "src/prisma/prisma.service";
@ -10,4 +12,27 @@ export class ExpensesCommandService extends BaseApprovalService<Expenses> {
protected get delegate() {
return this.prisma.expenses;
}
protected delegateFor(transaction: Prisma.TransactionClient){
return transaction.expenses;
}
async updateApproval(id: number, isApproved: boolean): Promise<Expenses> {
return this.prisma.$transaction((transaction) =>
this.updateApprovalWithTx(transaction, id, isApproved),
);
}
// deprecated since batch transaction are made with timesheets
// async updateManyWithTx(
// tx: Prisma.TransactionClient,
// ids: number[],
// isApproved: boolean,
// ): Promise<number> {
// const { count } = await tx.expenses.updateMany({
// where: { id: { in: ids } },
// data: { is_approved: isApproved },
// });
// return count;
// }
}

View File

@ -1,5 +1,5 @@
import { Injectable } from "@nestjs/common";
import { Shifts } from "@prisma/client";
import { Prisma, Shifts } from "@prisma/client";
import { BaseApprovalService } from "src/common/shared/base-approval.service";
import { PrismaService } from "src/prisma/prisma.service";
@ -10,4 +10,27 @@ export class ShiftsCommandService extends BaseApprovalService<Shifts> {
protected get delegate() {
return this.prisma.shifts;
}
protected delegateFor(transaction: Prisma.TransactionClient) {
return transaction.shifts;
}
async updateApproval(id: number, isApproved: boolean): Promise<Shifts> {
return this.prisma.$transaction((transaction) =>
this.updateApprovalWithTx(transaction, id, isApproved),
);
}
// deprecated since batch transaction are made with timesheets
// async updateManyWithTx(
// tx: Prisma.TransactionClient,
// ids: number[],
// isApproved: boolean,
// ): Promise<number> {
// const { count } = await tx.shifts.updateMany({
// where: { id: { in: ids } },
// data: { is_approved: isApproved },
// });
// return count;
// }
}