delete
This commit is contained in:
@@ -122,4 +122,13 @@ export class RestaurantsController {
|
|||||||
return this.restaurantsService.upgradeSubscription(subscriptionId, upgradeSubscriptionDto);
|
return this.restaurantsService.upgradeSubscription(subscriptionId, upgradeSubscriptionDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(SuperAdminAuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@ApiOperation({ summary: 'Hard delete a restaurant and all related data' })
|
||||||
|
@ApiParam({ name: 'id', required: true, description: 'Restaurant ID' })
|
||||||
|
@Delete('super-admin/restaurants/:id/hard-delete')
|
||||||
|
hardDeleteRestaurant(@Param('id') id: string) {
|
||||||
|
return this.restaurantsService.hardDeleteRestaurant(id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ import { Role } from '../../roles/entities/role.entity';
|
|||||||
import { normalizePhone } from 'src/modules/utils/phone.util';
|
import { normalizePhone } from 'src/modules/utils/phone.util';
|
||||||
import { NotificationPreference } from '../../notifications/entities/notification-preference.entity';
|
import { NotificationPreference } from '../../notifications/entities/notification-preference.entity';
|
||||||
import { notificationPreferencesData } from '../../../seeders/data/notification-preferences.data';
|
import { notificationPreferencesData } from '../../../seeders/data/notification-preferences.data';
|
||||||
|
import { Order } from '../../orders/entities/order.entity';
|
||||||
|
import { Coupon } from '../../coupons/entities/coupon.entity';
|
||||||
|
import { Category } from '../../foods/entities/category.entity';
|
||||||
|
import { Food } from '../../foods/entities/food.entity';
|
||||||
|
import { Delivery } from '../../delivery/entities/delivery.entity';
|
||||||
|
import { Schedule } from '../entities/schedule.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RestaurantsService {
|
export class RestaurantsService {
|
||||||
@@ -179,4 +185,42 @@ export class RestaurantsService {
|
|||||||
return restaurant;
|
return restaurant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async hardDeleteRestaurant(id: string): Promise<void> {
|
||||||
|
return await this.em.transactional(async (em) => {
|
||||||
|
// Find the restaurant first
|
||||||
|
const restaurant = await em.findOne(Restaurant, { id });
|
||||||
|
|
||||||
|
if (!restaurant) {
|
||||||
|
throw new NotFoundException(RestMessage.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete orders first (will cascade to order items and payments due to cascade settings)
|
||||||
|
await em.nativeDelete(Order, { restaurant: id });
|
||||||
|
|
||||||
|
// Delete coupons
|
||||||
|
await em.nativeDelete(Coupon, { restaurant: id });
|
||||||
|
|
||||||
|
// Delete foods (will cascade to reviews, favorites, and inventory due to cascade settings)
|
||||||
|
await em.nativeDelete(Food, { restaurant: id });
|
||||||
|
|
||||||
|
// Delete categories (foods should be deleted by cascade, but delete explicitly to be safe)
|
||||||
|
await em.nativeDelete(Category, { restaurant: id });
|
||||||
|
|
||||||
|
// Delete deliveries
|
||||||
|
await em.nativeDelete(Delivery, { restaurant: id });
|
||||||
|
|
||||||
|
// Delete schedules
|
||||||
|
await em.nativeDelete(Schedule, { restId: id });
|
||||||
|
|
||||||
|
// Delete notification preferences
|
||||||
|
await em.nativeDelete(NotificationPreference, { restaurant: id });
|
||||||
|
|
||||||
|
// Delete admin roles for this restaurant
|
||||||
|
await em.nativeDelete(AdminRole, { restaurant: id });
|
||||||
|
|
||||||
|
// Finally, delete the restaurant itself
|
||||||
|
await em.nativeDelete(Restaurant, { id });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user