feat: add payment post process

This commit is contained in:
Methapon Metanipat 2024-10-09 15:04:59 +07:00
parent 80a407ba61
commit 07742732ac
5 changed files with 133 additions and 6 deletions

View file

@ -51,16 +51,41 @@ export class QuotationPayment extends Controller {
@Post("confirm")
async confirmPayment(@Path("quotationId") id: string) {
const record = await prisma.quotation.findUnique({
include: {
worker: true,
productServiceList: {
include: {
worker: true,
work: true,
service: true,
product: true,
},
},
},
where: { id },
});
if (!record) throw notFoundError("Quotation");
await prisma.quotation.update({
where: { id },
data: { quotationStatus: "PaymentSuccess" },
await prisma.$transaction(async (tx) => {
await tx.quotation.update({
where: { id },
data: {
quotationStatus: "PaymentSuccess",
requestData: {
create: record.worker.map((v) => ({
employeeId: v.employeeId,
requestWork: {
create: record.productServiceList.flatMap((item) =>
item.worker.findIndex((w) => w.employeeId === v.employeeId) !== -1
? { productServiceId: item.id }
: [],
),
},
})),
},
},
});
});
// TODO: Generate request list (Work) by match product with worker (Employee)
}
}