feat: upload multiple payment file
This commit is contained in:
parent
ee858094e0
commit
c62c12642e
1 changed files with 32 additions and 5 deletions
|
|
@ -1,11 +1,12 @@
|
|||
import { Body, Controller, Get, Path, Post, Put, Query, Request, Route, Tags } from "tsoa";
|
||||
import { Body, Controller, Delete, 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";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import { fileLocation, getFile, setFile } from "../utils/minio";
|
||||
import { deleteFile, fileLocation, getFile, listFile, setFile } from "../utils/minio";
|
||||
import { RequestWithUser } from "../interfaces/user";
|
||||
|
||||
@Tags("Quotation")
|
||||
@Route("api/v1/quotation/{quotationId}/payment")
|
||||
|
|
@ -78,19 +79,28 @@ export class QuotationPayment extends Controller {
|
|||
}
|
||||
|
||||
@Get("{paymentId}/file")
|
||||
async listPaymentFile(@Path() quotationId: string, @Path() paymentId: string) {
|
||||
return await listFile(fileLocation.quotation.payment(quotationId, paymentId));
|
||||
}
|
||||
|
||||
@Get("{paymentId}/file/{name}")
|
||||
async getPaymentFile(
|
||||
@Request() req: express.Request,
|
||||
@Path() quotationId: string,
|
||||
@Path() paymentId: string,
|
||||
@Path() name: string,
|
||||
) {
|
||||
return req.res?.redirect(await getFile(fileLocation.quotation.payment(quotationId, paymentId)));
|
||||
return req.res?.redirect(
|
||||
await getFile(fileLocation.quotation.payment(quotationId, paymentId, name)),
|
||||
);
|
||||
}
|
||||
|
||||
@Put("{paymentId}/file")
|
||||
@Put("{paymentId}/file/{name}")
|
||||
async uploadPayment(
|
||||
@Request() req: express.Request,
|
||||
@Path() quotationId: string,
|
||||
@Path() paymentId: string,
|
||||
@Path() name: string,
|
||||
) {
|
||||
const record = await prisma.quotation.findUnique({
|
||||
where: { id: quotationId },
|
||||
|
|
@ -107,7 +117,24 @@ export class QuotationPayment extends Controller {
|
|||
);
|
||||
}
|
||||
|
||||
return req.res?.redirect(await setFile(fileLocation.quotation.payment(quotationId, paymentId)));
|
||||
return req.res?.redirect(
|
||||
await setFile(fileLocation.quotation.payment(quotationId, paymentId, name)),
|
||||
);
|
||||
}
|
||||
|
||||
@Delete("{paymentId}/file/{name}")
|
||||
async deletePayment(
|
||||
@Path() quotationId: string,
|
||||
@Path() paymentId: string,
|
||||
@Path() name: string,
|
||||
) {
|
||||
const record = await prisma.quotation.findUnique({
|
||||
where: { id: quotationId },
|
||||
});
|
||||
|
||||
if (!record) throw notFoundError("Quotation");
|
||||
|
||||
return await deleteFile(fileLocation.quotation.payment(quotationId, paymentId, name));
|
||||
}
|
||||
|
||||
@Post("confirm")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue