diff --git a/src/controllers/05-quotation-payment-controller.ts b/src/controllers/05-quotation-payment-controller.ts index 2b68ce3..7b5d637 100644 --- a/src/controllers/05-quotation-payment-controller.ts +++ b/src/controllers/05-quotation-payment-controller.ts @@ -1,5 +1,6 @@ import { Body, Controller, Get, Path, Post, Put, Query, Request, Route, Tags } from "tsoa"; import express from "express"; +import { PaymentStatus } from "@prisma/client"; import prisma from "../db"; import { notFoundError } from "../utils/error"; import HttpError from "../interfaces/http-error"; @@ -26,7 +27,7 @@ export class QuotationPayment extends Controller { @Post() async addPayment( @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({ where: { id: quotationId }, @@ -34,7 +35,7 @@ export class QuotationPayment extends Controller { 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) throw new HttpError( 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") async getPaymentFile( @Request() req: express.Request,