feat: add payment post process
This commit is contained in:
parent
80a407ba61
commit
07742732ac
5 changed files with 133 additions and 6 deletions
|
|
@ -0,0 +1,29 @@
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "RequestData" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"employeeId" TEXT NOT NULL,
|
||||||
|
"quotationId" TEXT NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "RequestData_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "RequestWork" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"requestDataId" TEXT NOT NULL,
|
||||||
|
"productServiceId" TEXT NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "RequestWork_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "RequestData" ADD CONSTRAINT "RequestData_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "Employee"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "RequestData" ADD CONSTRAINT "RequestData_quotationId_fkey" FOREIGN KEY ("quotationId") REFERENCES "Quotation"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "RequestWork" ADD CONSTRAINT "RequestWork_requestDataId_fkey" FOREIGN KEY ("requestDataId") REFERENCES "RequestData"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "RequestWork" ADD CONSTRAINT "RequestWork_productServiceId_fkey" FOREIGN KEY ("productServiceId") REFERENCES "QuotationProductServiceList"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
@ -734,6 +734,7 @@ model Employee {
|
||||||
editHistory EmployeeHistory[]
|
editHistory EmployeeHistory[]
|
||||||
quotationWorker QuotationWorker[]
|
quotationWorker QuotationWorker[]
|
||||||
quotationProductServiceWorker QuotationProductServiceWorker[]
|
quotationProductServiceWorker QuotationProductServiceWorker[]
|
||||||
|
requestData RequestData[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model EmployeeHistory {
|
model EmployeeHistory {
|
||||||
|
|
@ -1119,6 +1120,8 @@ model Quotation {
|
||||||
discount Float @default(0)
|
discount Float @default(0)
|
||||||
finalPrice Float
|
finalPrice Float
|
||||||
|
|
||||||
|
requestData RequestData[]
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
createdBy User? @relation(name: "QuotationCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
|
createdBy User? @relation(name: "QuotationCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
|
||||||
createdByUserId String?
|
createdByUserId String?
|
||||||
|
|
@ -1170,7 +1173,8 @@ model QuotationProductServiceList {
|
||||||
serviceId String?
|
serviceId String?
|
||||||
service Service? @relation(fields: [serviceId], references: [id])
|
service Service? @relation(fields: [serviceId], references: [id])
|
||||||
|
|
||||||
worker QuotationProductServiceWorker[]
|
worker QuotationProductServiceWorker[]
|
||||||
|
RequestWork RequestWork[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model QuotationProductServiceWorker {
|
model QuotationProductServiceWorker {
|
||||||
|
|
@ -1182,3 +1186,25 @@ model QuotationProductServiceWorker {
|
||||||
|
|
||||||
@@id([productServiceId, employeeId])
|
@@id([productServiceId, employeeId])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model RequestData {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
|
||||||
|
employee Employee @relation(fields: [employeeId], references: [id])
|
||||||
|
employeeId String
|
||||||
|
|
||||||
|
quotation Quotation @relation(fields: [quotationId], references: [id])
|
||||||
|
quotationId String
|
||||||
|
|
||||||
|
requestWork RequestWork[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model RequestWork {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
|
||||||
|
request RequestData @relation(fields: [requestDataId], references: [id])
|
||||||
|
requestDataId String
|
||||||
|
|
||||||
|
productService QuotationProductServiceList @relation(fields: [productServiceId], references: [id])
|
||||||
|
productServiceId String
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,16 +51,41 @@ export class QuotationPayment extends Controller {
|
||||||
@Post("confirm")
|
@Post("confirm")
|
||||||
async confirmPayment(@Path("quotationId") id: string) {
|
async confirmPayment(@Path("quotationId") id: string) {
|
||||||
const record = await prisma.quotation.findUnique({
|
const record = await prisma.quotation.findUnique({
|
||||||
|
include: {
|
||||||
|
worker: true,
|
||||||
|
productServiceList: {
|
||||||
|
include: {
|
||||||
|
worker: true,
|
||||||
|
work: true,
|
||||||
|
service: true,
|
||||||
|
product: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
where: { id },
|
where: { id },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!record) throw notFoundError("Quotation");
|
if (!record) throw notFoundError("Quotation");
|
||||||
|
|
||||||
await prisma.quotation.update({
|
await prisma.$transaction(async (tx) => {
|
||||||
where: { id },
|
await tx.quotation.update({
|
||||||
data: { quotationStatus: "PaymentSuccess" },
|
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 {}
|
||||||
|
|
@ -93,4 +93,8 @@ export const fileLocation = {
|
||||||
quotation: {
|
quotation: {
|
||||||
payment: (quotationId: string) => `quotation/payment-${quotationId}`,
|
payment: (quotationId: string) => `quotation/payment-${quotationId}`,
|
||||||
},
|
},
|
||||||
|
request: {
|
||||||
|
attachment: (requestId: string, name?: string) =>
|
||||||
|
`request/attachment-${requestId}/${name || ""}`,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue