find all rest
This commit is contained in:
@@ -31,6 +31,7 @@ import { Notification } from '../../notifications/entities/notification.entity';
|
||||
import { CacheService } from 'src/modules/utils/cache.service';
|
||||
import { CacheKeys } from 'src/common/constants/cache-keys.constant';
|
||||
import { BackgroundRepository } from '../repositories/background.repository';
|
||||
import { ActiveRestaurantListItemDto } from '../dto/active-restaurant-list-item.dto';
|
||||
|
||||
|
||||
@Injectable()
|
||||
@@ -108,6 +109,8 @@ export class RestaurantsService {
|
||||
em.persist([restaurant, admin, adminRole, ...notificationPreferences]);
|
||||
await em.flush();
|
||||
|
||||
await this.invalidateActiveRestaurantsListCache();
|
||||
|
||||
return restaurant;
|
||||
});
|
||||
}
|
||||
@@ -156,6 +159,19 @@ export class RestaurantsService {
|
||||
const restaurant = await this.findBySlug(slug);
|
||||
return restaurant;
|
||||
}
|
||||
|
||||
async findAllActiveRestaurants(): Promise<ActiveRestaurantListItemDto[]> {
|
||||
const restaurants = await this.restRepository.findAllActive();
|
||||
|
||||
return restaurants.map(({ slug, name, seoTitle, address, score, logo, establishedYear }) => ({
|
||||
slug,
|
||||
name,
|
||||
title: seoTitle,
|
||||
address,
|
||||
logo,
|
||||
establishedYear,
|
||||
}));
|
||||
}
|
||||
// TODO : it must be done inside transaction
|
||||
async update(id: string, dto: UpdateRestaurantDto): Promise<Restaurant> {
|
||||
|
||||
@@ -204,12 +220,21 @@ export class RestaurantsService {
|
||||
}
|
||||
|
||||
private async invalidateRestaurantCache(slug?: string): Promise<void> {
|
||||
if (!slug) return;
|
||||
await Promise.all([
|
||||
this.cacheService.del(CacheKeys.restaurantSpec(slug)),
|
||||
this.cacheService.del(CacheKeys.foodsByRestaurant(slug)),
|
||||
this.cacheService.del(CacheKeys.categoriesByRestaurant(slug)),
|
||||
]);
|
||||
const tasks = [this.invalidateActiveRestaurantsListCache()];
|
||||
|
||||
if (slug) {
|
||||
tasks.push(
|
||||
this.cacheService.del(CacheKeys.restaurantSpec(slug)),
|
||||
this.cacheService.del(CacheKeys.foodsByRestaurant(slug)),
|
||||
this.cacheService.del(CacheKeys.categoriesByRestaurant(slug)),
|
||||
);
|
||||
}
|
||||
|
||||
await Promise.all(tasks);
|
||||
}
|
||||
|
||||
private async invalidateActiveRestaurantsListCache(): Promise<void> {
|
||||
await this.cacheService.del(CacheKeys.activeRestaurantsList());
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
@@ -222,6 +247,7 @@ export class RestaurantsService {
|
||||
|
||||
restaurant.isActive = false;
|
||||
await this.em.persistAndFlush(restaurant);
|
||||
await this.invalidateRestaurantCache(restaurant.slug);
|
||||
|
||||
return restaurant;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user