feat: add payment endpoints (incomplete)
This commit is contained in:
parent
8ae8ec7002
commit
37b4bcfbbe
2 changed files with 69 additions and 0 deletions
66
src/controllers/05-quotation-payment-controller.ts
Normal file
66
src/controllers/05-quotation-payment-controller.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
import { Controller, Path, Post, Put, Route, Tags } from "tsoa";
|
||||||
|
import prisma from "../db";
|
||||||
|
import { notFoundError } from "../utils/error";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
|
||||||
|
@Tags("Quotation")
|
||||||
|
@Route("api/v1/quotation/{quotationId}/payment")
|
||||||
|
export class QuotationPayment extends Controller {
|
||||||
|
@Post("submit")
|
||||||
|
async submitPayment(@Path("quotationId") id: string) {
|
||||||
|
const record = await prisma.quotation.findUnique({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!record) throw notFoundError("Quotation");
|
||||||
|
|
||||||
|
if (record.quotationStatus !== "PaymentPending" && record.quotationStatus !== "PaymentWait") {
|
||||||
|
// NOTE: The quotation must be in waiting for payment or waiting for payment confirmation (re-submit payment)
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatus.PRECONDITION_FAILED,
|
||||||
|
"Cannot submit payment info of this quotation",
|
||||||
|
"quotationStatusWrong",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await prisma.quotation.update({
|
||||||
|
where: { id },
|
||||||
|
data: { quotationStatus: "PaymentWait" },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put("file")
|
||||||
|
async uploadPayment(@Path("quotationId") id: string) {
|
||||||
|
const record = await prisma.quotation.findUnique({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!record) throw notFoundError("Quotation");
|
||||||
|
|
||||||
|
if (record.quotationStatus !== "PaymentPending" && record.quotationStatus !== "PaymentWait") {
|
||||||
|
// NOTE: The quotation must be in waiting for payment or waiting for payment confirmation (re-submit payment)
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatus.PRECONDITION_FAILED,
|
||||||
|
"Cannot submit payment info of this quotation",
|
||||||
|
"quotationStatusWrong",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post("confirm")
|
||||||
|
async confirmPayment(@Path("quotationId") id: string) {
|
||||||
|
const record = await prisma.quotation.findUnique({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!record) throw notFoundError("Quotation");
|
||||||
|
|
||||||
|
await prisma.quotation.update({
|
||||||
|
where: { id },
|
||||||
|
data: { quotationStatus: "PaymentSuccess" },
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: Generate request list (Work) by match product with worker (Employee)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -90,4 +90,7 @@ export const fileLocation = {
|
||||||
service: {
|
service: {
|
||||||
img: (serviceId: string, name?: string) => `service/img-${serviceId}/${name || ""}`,
|
img: (serviceId: string, name?: string) => `service/img-${serviceId}/${name || ""}`,
|
||||||
},
|
},
|
||||||
|
quotation: {
|
||||||
|
payment: (quotationId: string) => `quotation/payment-${quotationId}`,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue