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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
43
src/controllers/06-request-list-controller.ts
Normal file
43
src/controllers/06-request-list-controller.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { Controller, Delete, Get, Path, Put, Query, Request, Route, Security, Tags } from "tsoa";
|
||||
import { RequestWithUser } from "../interfaces/user";
|
||||
import prisma from "../db";
|
||||
|
||||
@Route("api/v1/request-list")
|
||||
@Tags("Request List")
|
||||
export class RequestListController extends Controller {
|
||||
@Get()
|
||||
@Security("keycloak")
|
||||
async getRequest(
|
||||
@Request() req: RequestWithUser,
|
||||
@Query() page: number = 1,
|
||||
@Query() pageSize: number = 30,
|
||||
) {
|
||||
return await prisma.requestWork.findMany({
|
||||
include: { request: true },
|
||||
take: pageSize,
|
||||
skip: (page - 1) * pageSize,
|
||||
});
|
||||
}
|
||||
|
||||
@Get("{requestId}")
|
||||
async getRequestById(@Path() requestId: string) {
|
||||
return await prisma.requestWork.findFirst({
|
||||
include: { request: true },
|
||||
where: { id: requestId },
|
||||
});
|
||||
}
|
||||
|
||||
/** @todo */
|
||||
@Put("{requestId}")
|
||||
async updateRequestById(@Request() req: RequestWithUser, @Path() requestId: string) {
|
||||
return {};
|
||||
}
|
||||
|
||||
/** @todo */
|
||||
@Delete("{requestId}")
|
||||
async deleteRequestById(@Request() req: RequestWithUser, @Path() requestId: string) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export class RequestListAttachmentController extends Controller {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue