delete business
This commit is contained in:
@@ -89,10 +89,16 @@ export class BusinessCategoriesService {
|
||||
});
|
||||
|
||||
const businessIds = businesses.map((b) => b.id);
|
||||
const imageUrls = (
|
||||
await Promise.all(
|
||||
businessIds.map((businessId) => this.images.listUrlsForBusiness(businessId)),
|
||||
)
|
||||
).flat();
|
||||
|
||||
await this.dataSource.transaction(async (manager) => {
|
||||
await deleteCategoryCascade(manager, id, businessIds, async (businessId) => {
|
||||
await this.images.removeAllForBusiness(businessId);
|
||||
});
|
||||
await deleteCategoryCascade(manager, id, businessIds);
|
||||
});
|
||||
|
||||
this.images.deleteFiles(imageUrls);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,11 +116,23 @@ export class BusinessImagesService {
|
||||
}
|
||||
}
|
||||
|
||||
async removeAllForBusiness(businessId: string): Promise<void> {
|
||||
const images = await this.imageRepo.find({ where: { businessId } });
|
||||
for (const image of images) {
|
||||
this.deleteFile(image.url);
|
||||
async listUrlsForBusiness(businessId: string): Promise<string[]> {
|
||||
const images = await this.imageRepo.find({
|
||||
where: { businessId },
|
||||
select: ['url'],
|
||||
});
|
||||
return images.map((image) => image.url);
|
||||
}
|
||||
|
||||
deleteFiles(urls: string[]): void {
|
||||
for (const url of urls) {
|
||||
this.deleteFile(url);
|
||||
}
|
||||
}
|
||||
|
||||
async removeAllForBusiness(businessId: string): Promise<void> {
|
||||
const urls = await this.listUrlsForBusiness(businessId);
|
||||
this.deleteFiles(urls);
|
||||
await this.imageRepo.delete({ businessId });
|
||||
}
|
||||
|
||||
|
||||
@@ -148,11 +148,13 @@ export class BusinessesService {
|
||||
async remove(id: string): Promise<void> {
|
||||
await this.findOne(id);
|
||||
|
||||
const imageUrls = await this.images.listUrlsForBusiness(id);
|
||||
|
||||
await this.dataSource.transaction(async (manager) => {
|
||||
await deleteBusinessCascade(manager, id, async (businessId) => {
|
||||
await this.images.removeAllForBusiness(businessId);
|
||||
});
|
||||
await deleteBusinessCascade(manager, id);
|
||||
});
|
||||
|
||||
this.images.deleteFiles(imageUrls);
|
||||
}
|
||||
|
||||
async getAvailability(businessId: string) {
|
||||
|
||||
Reference in New Issue
Block a user