diff --git a/src/controllers/customer-branch-controller.ts b/src/controllers/customer-branch-controller.ts index 1561867..f27d3cc 100644 --- a/src/controllers/customer-branch-controller.ts +++ b/src/controllers/customer-branch-controller.ts @@ -553,16 +553,15 @@ export class CustomerAttachmentController extends Controller { stream.on("error", () => reject(new Error("MinIO error."))); }); - return await Promise.all( - list.map(async (v) => ({ - name: v.split("/").at(-1) as string, - url: await minio.presignedGetObject(MINIO_BUCKET, v, 12 * 60 * 60), - })), - ); + return list.map((v) => v.split("/").at(-1) as string); } - @Post() - async addAttachment(@Path() branchId: string, @Body() payload: { file: string[] }) { + @Put("{filename}") + async addAttachment( + @Request() req: RequestWithUser, + @Path() branchId: string, + @Path() filename: string, + ) { const record = await prisma.customerBranch.findFirst({ where: { id: branchId }, }); @@ -575,24 +574,17 @@ export class CustomerAttachmentController extends Controller { ); } - return await Promise.all( - payload.file.map(async (v) => ({ - name: v, - url: await minio.presignedGetObject( - MINIO_BUCKET, - `${attachmentLocation(record.customerId, branchId)}/${v}`, - ), - uploadUrl: await minio.presignedPutObject( - MINIO_BUCKET, - `${attachmentLocation(record.customerId, branchId)}/${v}`, - 12 * 60 * 60, - ), - })), + return req.res?.redirect( + await minio.presignedPutObject( + MINIO_BUCKET, + `${attachmentLocation(record.customerId, branchId)}/${filename}`, + 12 * 60 * 60, + ), ); } - @Delete() - async deleteAttachment(@Path() branchId: string, @Body() payload: { file: string[] }) { + @Delete("{filename}") + async deleteAttachment(@Path() branchId: string, @Path() filename: string) { const record = await prisma.customerBranch.findFirst({ where: { id: branchId }, }); @@ -605,16 +597,10 @@ export class CustomerAttachmentController extends Controller { ); } - await Promise.all( - payload.file.map(async (v) => { - await minio.removeObject( - MINIO_BUCKET, - `${attachmentLocation(record.customerId, branchId)}/${v}`, - { - forceDelete: true, - }, - ); - }), + await minio.removeObject( + MINIO_BUCKET, + `${attachmentLocation(record.customerId, branchId)}/${filename}`, + { forceDelete: true }, ); } }