Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/apis/shops/interface/shops-service.interface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { Reservation } from 'src/apis/reservations/entities/reservation.entity';
import { CreateShopInput } from '../dto/create-shop.input';
import { UpdateShopInput } from '../dto/update-shop.input';

export interface IShopsServiceCreate {
createShopInput: CreateShopInput;
}

export interface IShopsServiceFindAll {
page: number;
count: number;
}

export interface IShopsServiceFilterReservations {
reservations: Reservation[];
}

export interface IShopsServiceGetLatLngByAddress {
address: string;
}
Expand Down
18 changes: 17 additions & 1 deletion src/apis/shops/shops.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import { Shop } from './entities/shop.entity';
import {
IShopsServiceCreate,
IShopsServiceDelete,
IShopsServiceFilterReservations,
IShopsServiceFindAll,
IShopsServiceFindById,
IShopsServiceGetLatLngByAddress,
IShopsServiceUpdate,
} from './interface/shops-service.interface';
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 {
Expand All @@ -38,7 +41,7 @@ export class ShopsService {
}

// DB의 모든 가게 정보 불러오기 + 페이징 추가
async findAll({ page, count }): Promise<Shop[]> {
async findAll({ page, count }: IShopsServiceFindAll): Promise<Shop[]> {
const allShops = await this.shopsRepository.find({
relations: [
'reservation',
Expand Down Expand Up @@ -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<Shop> {
const myShop = await this.shopsRepository.findOne({
Expand All @@ -92,6 +103,11 @@ export class ShopsService {
],
});

// 유저가 존재하고 리뷰까지 작성한 경우만 필터링
myShop.reservation = this.filterReservations({
reservations: myShop.reservation,
});

if (!myShop) {
throw new UnprocessableEntityException(`가게를 찾을 수 없습니다`);
}
Expand Down