feat: add new endpoint for get or download file

This commit is contained in:
Methapon Metanipat 2024-08-27 09:07:14 +07:00
parent 9c8786bf62
commit 91f7cf2a9b

View file

@ -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,