refactor: update customer branch file upload endpoint
This commit is contained in:
parent
2d056d3b56
commit
9c8786bf62
1 changed files with 19 additions and 33 deletions
|
|
@ -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 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue