66 lines
2 KiB
TypeScript
66 lines
2 KiB
TypeScript
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)
|
|
}
|
|
}
|