feat: update payload and update endpoint
This commit is contained in:
parent
4835b22294
commit
db2323a24b
1 changed files with 21 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { Body, Controller, Get, Path, Post, Put, Query, Request, Route, Tags } from "tsoa";
|
import { Body, Controller, Get, Path, Post, Put, Query, Request, Route, Tags } from "tsoa";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
|
import { PaymentStatus } from "@prisma/client";
|
||||||
import prisma from "../db";
|
import prisma from "../db";
|
||||||
import { notFoundError } from "../utils/error";
|
import { notFoundError } from "../utils/error";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
|
|
@ -26,7 +27,7 @@ export class QuotationPayment extends Controller {
|
||||||
@Post()
|
@Post()
|
||||||
async addPayment(
|
async addPayment(
|
||||||
@Path() quotationId: string,
|
@Path() quotationId: string,
|
||||||
@Body() body: { amount: number; date: Date; remark: string },
|
@Body() body: { amount: number; date: Date; remark: string; paymentStatus?: PaymentStatus },
|
||||||
) {
|
) {
|
||||||
const record = await prisma.quotation.findUnique({
|
const record = await prisma.quotation.findUnique({
|
||||||
where: { id: quotationId },
|
where: { id: quotationId },
|
||||||
|
|
@ -34,7 +35,7 @@ export class QuotationPayment extends Controller {
|
||||||
|
|
||||||
if (!record) throw notFoundError("Quotation");
|
if (!record) throw notFoundError("Quotation");
|
||||||
|
|
||||||
if (record.quotationStatus !== "PaymentPending") {
|
if (!body.paymentStatus && record.quotationStatus !== "PaymentPending") {
|
||||||
// NOTE: The quotation must be in waiting for payment or waiting for payment confirmation (re-submit payment)
|
// NOTE: The quotation must be in waiting for payment or waiting for payment confirmation (re-submit payment)
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatus.PRECONDITION_FAILED,
|
HttpStatus.PRECONDITION_FAILED,
|
||||||
|
|
@ -58,6 +59,24 @@ export class QuotationPayment extends Controller {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Put("{paymentId}")
|
||||||
|
async updatePayment(
|
||||||
|
@Path() quotationId: string,
|
||||||
|
@Path() paymentId: string,
|
||||||
|
@Body() body: { amount?: number; date?: Date; remark?: string; paymentStatus?: PaymentStatus },
|
||||||
|
) {
|
||||||
|
const record = await prisma.quotationPayment.findUnique({
|
||||||
|
where: { id: paymentId, quotationId },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!record) throw notFoundError("Quotation Payment");
|
||||||
|
|
||||||
|
return await prisma.quotationPayment.update({
|
||||||
|
where: { id: paymentId, quotationId },
|
||||||
|
data: body,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Get("{paymentId}/file")
|
@Get("{paymentId}/file")
|
||||||
async getPaymentFile(
|
async getPaymentFile(
|
||||||
@Request() req: express.Request,
|
@Request() req: express.Request,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue