feat: customer branch attachment
This commit is contained in:
parent
7cfc49eae0
commit
fea4bd874f
2 changed files with 148 additions and 4 deletions
|
|
@ -45,7 +45,11 @@ export type CustomerUpdate = {
|
|||
};
|
||||
|
||||
function imageLocation(id: string) {
|
||||
return `customer/img-${id}`;
|
||||
return `customer/${id}/profile-image`;
|
||||
}
|
||||
|
||||
function attachmentLocation(customerId: string, branchId: string) {
|
||||
return `customer/${customerId}/branch/${branchId}`;
|
||||
}
|
||||
|
||||
@Route("api/v1/customer")
|
||||
|
|
@ -357,6 +361,23 @@ export class CustomerController extends Controller {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, "Customer is in used.", "data_in_used");
|
||||
}
|
||||
|
||||
return await prisma.customer.delete({ where: { id: customerId } });
|
||||
return await prisma.customer.delete({ where: { id: customerId } }).then((v) => {
|
||||
new Promise<string[]>((resolve, reject) => {
|
||||
const item: string[] = [];
|
||||
|
||||
const stream = minio.listObjectsV2(MINIO_BUCKET, `customer/${customerId}`);
|
||||
|
||||
stream.on("data", (v) => v && v.name && item.push(v.name));
|
||||
stream.on("end", () => resolve(item));
|
||||
stream.on("error", () => reject(new Error("MinIO error.")));
|
||||
}).then((list) => {
|
||||
list.map(async (v) => {
|
||||
await minio.removeObject(MINIO_BUCKET, v, {
|
||||
forceDelete: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
return v;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue