feat: customer branch attachment

This commit is contained in:
Methapon2001 2024-06-07 10:44:40 +07:00
parent 7cfc49eae0
commit fea4bd874f
2 changed files with 148 additions and 4 deletions

View file

@ -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;
});
}
}