diff --git a/src/apis/shops/interface/shops-service.interface.ts b/src/apis/shops/interface/shops-service.interface.ts index 8c18e86..5a4a501 100644 --- a/src/apis/shops/interface/shops-service.interface.ts +++ b/src/apis/shops/interface/shops-service.interface.ts @@ -1,3 +1,4 @@ +import { Reservation } from 'src/apis/reservations/entities/reservation.entity'; import { CreateShopInput } from '../dto/create-shop.input'; import { UpdateShopInput } from '../dto/update-shop.input'; @@ -5,6 +6,15 @@ export interface IShopsServiceCreate { createShopInput: CreateShopInput; } +export interface IShopsServiceFindAll { + page: number; + count: number; +} + +export interface IShopsServiceFilterReservations { + reservations: Reservation[]; +} + export interface IShopsServiceGetLatLngByAddress { address: string; } diff --git a/src/apis/shops/shops.service.ts b/src/apis/shops/shops.service.ts index b48da45..a97ff27 100644 --- a/src/apis/shops/shops.service.ts +++ b/src/apis/shops/shops.service.ts @@ -9,6 +9,8 @@ import { Shop } from './entities/shop.entity'; import { IShopsServiceCreate, IShopsServiceDelete, + IShopsServiceFilterReservations, + IShopsServiceFindAll, IShopsServiceFindById, IShopsServiceGetLatLngByAddress, IShopsServiceUpdate, @@ -16,6 +18,7 @@ import { import axios from 'axios'; import { districtCode } from 'src/commons/utils/addresscode'; import { AutocompleteShopsOutput } from './dto/return-shop.output'; +import { Reservation } from '../reservations/entities/reservation.entity'; @Injectable() export class ShopsService { @@ -38,7 +41,7 @@ export class ShopsService { } // DB의 모든 가게 정보 불러오기 + 페이징 추가 - async findAll({ page, count }): Promise { + async findAll({ page, count }: IShopsServiceFindAll): Promise { const allShops = await this.shopsRepository.find({ relations: [ 'reservation', @@ -79,6 +82,14 @@ export class ShopsService { return allShops; } + filterReservations({ + reservations, + }: IShopsServiceFilterReservations): Reservation[] { + return reservations.filter( + (reservation) => reservation.user && reservation.review, + ); + } + // 가게 데이터 찾기 async findById({ shopId }: IShopsServiceFindById): Promise { const myShop = await this.shopsRepository.findOne({ @@ -92,6 +103,11 @@ export class ShopsService { ], }); + // 유저가 존재하고 리뷰까지 작성한 경우만 필터링 + myShop.reservation = this.filterReservations({ + reservations: myShop.reservation, + }); + if (!myShop) { throw new UnprocessableEntityException(`가게를 찾을 수 없습니다`); }