From 60a151a07542681a1f3c44840fcdefa967a49b9c Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Mon, 21 Oct 2024 17:55:03 +0700 Subject: [PATCH] feat: add head method --- .../05-quotation-payment-controller.ts | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/controllers/05-quotation-payment-controller.ts b/src/controllers/05-quotation-payment-controller.ts index 95294aa..72843f9 100644 --- a/src/controllers/05-quotation-payment-controller.ts +++ b/src/controllers/05-quotation-payment-controller.ts @@ -1,11 +1,31 @@ -import { Body, Controller, Delete, Get, Path, Post, Put, Query, Request, Route, Tags } from "tsoa"; +import { + Body, + Controller, + Delete, + Get, + Head, + 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 { deleteFile, fileLocation, getFile, listFile, setFile } from "../utils/minio"; +import { + deleteFile, + fileLocation, + getFile, + getFilePresigned, + listFile, + setFile, +} from "../utils/minio"; import { RequestWithUser } from "../interfaces/user"; @Tags("Quotation") @@ -83,6 +103,18 @@ export class QuotationPayment extends Controller { return await listFile(fileLocation.quotation.payment(quotationId, paymentId)); } + @Head("{paymentId}/attachment/{name}") + async headPaymentFile( + @Request() req: express.Request, + @Path() quotationId: string, + @Path() paymentId: string, + @Path() name: string, + ) { + return req.res?.redirect( + await getFilePresigned("head", fileLocation.quotation.payment(quotationId, paymentId, name)), + ); + } + @Get("{paymentId}/attachment/{name}") async getPaymentFile( @Request() req: express.Request,