feat: add payment post process
This commit is contained in:
parent
80a407ba61
commit
07742732ac
5 changed files with 133 additions and 6 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue