refactor(module): refactored expenses and shifts approval to be made in batch iva timesheets
This commit is contained in:
parent
7a9adeec69
commit
a23a6299dd
|
|
@ -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;
|
||||
// }
|
||||
}
|
||||
|
|
@ -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;
|
||||
// }
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user