diff --git a/src/controllers/customer-branch-controller.ts b/src/controllers/customer-branch-controller.ts index f27d3cc..258d330 100644 --- a/src/controllers/customer-branch-controller.ts +++ b/src/controllers/customer-branch-controller.ts @@ -556,6 +556,33 @@ export class CustomerAttachmentController extends Controller { return list.map((v) => v.split("/").at(-1) as string); } + @Get("{filename}") + async getAttachment( + @Request() req: RequestWithUser, + @Path() branchId: string, + @Path() filename: string, + ) { + const record = await prisma.customerBranch.findFirst({ + where: { id: branchId }, + }); + + if (!record) { + throw new HttpError( + HttpStatus.NOT_FOUND, + "Customer branch cannot be found.", + "customerBranchNotFound", + ); + } + + return req.res?.redirect( + await minio.presignedGetObject( + MINIO_BUCKET, + `${attachmentLocation(record.customerId, branchId)}/${filename}`, + 12 * 60 * 60, + ), + ); + } + @Put("{filename}") async addAttachment( @Request() req: RequestWithUser,