diff --git a/src/apis/reviews/reviews.resolver.ts b/src/apis/reviews/reviews.resolver.ts index 56619ff..5e5a2b0 100644 --- a/src/apis/reviews/reviews.resolver.ts +++ b/src/apis/reviews/reviews.resolver.ts @@ -12,18 +12,20 @@ export class ReviewsResolver { private readonly reviewsService: ReviewsService, // ) {} - @Query(() => Review, { - description: 'Return: 리뷰ID 기준으로 1개 불러오기', - }) + @Query( + () => Review, // + { description: 'Return: 리뷰ID 기준으로 1개 불러오기' }, + ) fetchReview( @Args('reviewId') reviewId: string, // ): Promise { return this.reviewsService.find({ reviewId }); } - @Query(() => [Review], { - description: 'Return: 가게ID 기준으로 모든 리뷰 불러오기', - }) + @Query( + () => [Review], // + { description: 'Return: 가게ID 기준으로 모든 리뷰 불러오기' }, + ) async fetchReviewsByShopId( @Args({ name: 'page', defaultValue: 1, nullable: true }) page: number, // @@ -40,9 +42,10 @@ export class ReviewsResolver { } @UseGuards(GqlAuthGuard('access')) - @Mutation(() => Review, { - description: 'Return: 신규 생성된 리뷰 데이터', - }) + @Mutation( + () => Review, // + { description: 'Return: 신규 생성된 리뷰 데이터' }, + ) createReview( @Args('createReviewInput') createReviewInput: CreateReviewInput, // @Context() context: IContext, @@ -54,9 +57,10 @@ export class ReviewsResolver { }); } - @Mutation(() => Boolean, { - description: 'Return: 리뷰 삭제 후 true 반환', - }) + @Mutation( + () => Boolean, // + { description: 'Return: 리뷰 삭제 후 true 반환' }, + ) deleteReview( @Args('reviewId') id: string, // ): Promise { diff --git a/src/apis/reviews/reviews.service.ts b/src/apis/reviews/reviews.service.ts index ca96de7..5e57d8b 100644 --- a/src/apis/reviews/reviews.service.ts +++ b/src/apis/reviews/reviews.service.ts @@ -23,7 +23,6 @@ export class ReviewsService { private readonly shopsService: ShopsService, ) {} - // 리뷰 가져오기 async find({ reviewId }: IReviewServiceFindById): Promise { const result = await this.reviewsRepository.findOne({ where: { id: reviewId }, @@ -37,7 +36,6 @@ export class ReviewsService { return result; } - // 가게의 모든 리뷰 가져오기 async findByShopIdWithPage({ page, count, // diff --git a/src/apis/shopImages/dto/save-shopImage.input.ts b/src/apis/shopImages/dto/save-shopImage.input.ts deleted file mode 100644 index bb19ab4..0000000 --- a/src/apis/shopImages/dto/save-shopImage.input.ts +++ /dev/null @@ -1,16 +0,0 @@ -// import { Field, InputType } from '@nestjs/graphql'; - -// @InputType() -// export class SaveShopImageInput { -// @Field(() => String) -// imageUrl: string; - -// @Field(() => Boolean) -// isThumbnail: boolean; - -// @Field(() => String) -// shopId: string; -// } - -// service.ts의 로직에서 가독성 향상을 위해 input 파일 대신 서비스에서 직접 정의함 -// 인자가 3개밖에 없어서. diff --git a/src/apis/shopImages/shopImage.resolver.ts b/src/apis/shopImages/shopImage.resolver.ts index aa5bc39..e41cce5 100644 --- a/src/apis/shopImages/shopImage.resolver.ts +++ b/src/apis/shopImages/shopImage.resolver.ts @@ -9,47 +9,56 @@ export class ShopImagesResolver { private readonly shopImagesService: ShopImagesService, // ) {} - @Query(() => ShopImage, { - description: 'Return: 입력한 가게의 썸네일 가게이미지(1개)', - }) + @Query( + () => ShopImage, // + { description: 'Return: 입력한 가게의 썸네일 가게이미지(1개)' }, + ) fetchThumbnailByShop( @Args('shopId') shopId: string, // ): Promise { return this.shopImagesService.findThumbnailByShopId({ shopId }); } - @Query(() => [ShopImage], { - description: 'Return: 입력한 가게의 모든 가게이미지', - }) + @Query( + () => [ShopImage], // + { description: 'Return: 입력한 가게의 모든 가게이미지' }, + ) fetchShopImagesByShop( @Args('shopId') shopId: string, // ): Promise { return this.shopImagesService.findByShopId({ shopId }); } - @Mutation(() => ShopImage, { - description: 'Return: 신규 생성된 가게이미지 데이터', - }) + @Mutation( + () => ShopImage, // + { description: 'Return: 신규 생성된 가게이미지 데이터' }, + ) async createShopImage( @Args('imageUrl') imageUrl: string, @Args('isThumbnail') isThumbnail: boolean, @Args('shopId') shopId: string, ): Promise { - return await this.shopImagesService.save({ imageUrl, isThumbnail, shopId }); + return await this.shopImagesService.create({ + imageUrl, + isThumbnail, + shopId, + }); } - @Mutation(() => ShopImage, { - description: 'Return: 업데이트된 가게이미지 데이터', - }) + @Mutation( + () => ShopImage, // + { description: 'Return: 업데이트된 가게이미지 데이터' }, + ) async updateShopImage( @Args('updateShopImageInput') updateShopImageInput: UpdateShopImageInput, ): Promise { return await this.shopImagesService.update({ updateShopImageInput }); } - @Mutation(() => Boolean, { - description: 'Return: 가게 이미지 삭제 완료 시, true', - }) + @Mutation( + () => Boolean, // + { description: 'Return: 가게 이미지 삭제 완료 시, true' }, + ) deleteShopImage( @Args('shopImageId') shopImageId: string, // ): Promise { diff --git a/src/apis/shopImages/shopImage.service.ts b/src/apis/shopImages/shopImage.service.ts index cff94d0..67c9508 100644 --- a/src/apis/shopImages/shopImage.service.ts +++ b/src/apis/shopImages/shopImage.service.ts @@ -1,7 +1,6 @@ import { ConflictException, Injectable, - NotFoundException, UnprocessableEntityException, } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; @@ -24,7 +23,6 @@ export class ShopImagesService { private readonly shopsService: ShopsService, ) {} - // 가게ID로 썸네일 찾기 async findThumbnailByShopId({ shopId, }: IShopImagesServiceFindThumbnail): Promise { @@ -44,7 +42,6 @@ export class ShopImagesService { }); } - // 가게ID로 해당 이미지 찾기 async findByShopId({ shopId, }: IShopImagesServiceFindByShopId): Promise { @@ -61,8 +58,7 @@ export class ShopImagesService { }); } - // DB테이블에 신규 이미지 저장 - async save({ + async create({ imageUrl, isThumbnail, shopId, @@ -81,7 +77,6 @@ export class ShopImagesService { }); } - // DB테이블에서 이미지 업데이트 async update({ updateShopImageInput, }: IShopImagesServiceUpdate): Promise { @@ -90,14 +85,10 @@ export class ShopImagesService { imageUrl: updateShopImageInput.imageUrl, }); return await this.shopImageRepository.save({ - id: updateShopImageInput.id, - imageUrl: updateShopImageInput.imageUrl, - isThumbnail: updateShopImageInput.isThumbnail, - shop: { id: updateShopImageInput.shopId }, + ...updateShopImageInput, }); } - // DB테이블에서 이미지 삭제 async delete({ shopImageId }: IShopImagesServiceDelete): Promise { const checkImage = await this.shopImageRepository.findOne({ where: { id: shopImageId }, @@ -108,12 +99,10 @@ export class ShopImagesService { `가게이미지ID가 ${shopImageId}인 이미지를 찾을 수 없습니다`, ); } - console.log('찾았음'); const result = await this.shopImageRepository.delete({ id: shopImageId, }); - console.log('✨✨✨ 삭제 완료 ✨✨✨'); return result.affected ? true : false; } diff --git a/src/apis/shops/shops.resolver.ts b/src/apis/shops/shops.resolver.ts index 11f09a5..c910db3 100644 --- a/src/apis/shops/shops.resolver.ts +++ b/src/apis/shops/shops.resolver.ts @@ -1,10 +1,7 @@ import { ElasticsearchService } from '@nestjs/elasticsearch'; import { Args, Mutation, Resolver, Query } from '@nestjs/graphql'; import { CreateShopInput } from './dto/create-shop.input'; -import { - AutocompleteShopsOutput, - ReturnShopOutput, -} from './dto/return-shop.output'; +import { AutocompleteShopsOutput } from './dto/return-shop.output'; import { UpdateShopInput } from './dto/update-shop.input'; import { Shop } from './entities/shop.entity'; import { ShopsService } from './shops.service'; @@ -16,11 +13,14 @@ export class ShopsResolver { private readonly elasticsearchService: ElasticsearchService, // ) {} - @Query(() => [AutocompleteShopsOutput], { - nullable: true, - description: - 'Return : 검색값(주소: 구, 동 검색 가능)을 포함한 데이터 배열(리뷰 점수 높은 순 정렬). 주소를 포함하는 데이터가 없는 경우 null.', - }) + @Query( + () => [AutocompleteShopsOutput], // + { + nullable: true, + description: + 'Return : 검색값(주소: 구, 동 검색 가능)을 포함한 데이터 배열(리뷰 점수 높은 순 정렬). 주소를 포함하는 데이터가 없는 경우 null.', + }, + ) async autocompleteShops( @Args({ name: 'search', @@ -46,10 +46,13 @@ export class ShopsResolver { }); } - @Query(() => [Shop], { - description: - 'Return : DB에 등록된 가게 중 검색값을 포함한 데이터(검색값이 Null인 경우 모든 가게). 이미지는 썸네일만 불러오며, 등록된 이미지가 있더라도 썸네일로 지정한 이미지가 없는 경우 Null(빈 배열)', - }) + @Query( + () => [Shop], // + { + description: + 'Return : DB에 등록된 가게 중 검색값을 포함한 데이터(검색값이 Null인 경우 모든 가게). 이미지는 썸네일만 불러오며, 등록된 이미지가 있더라도 썸네일로 지정한 이미지가 없는 경우 Null(빈 배열)', + }, + ) async fetchShops( @Args('page') page: number, @Args('count') count: number, @@ -57,28 +60,37 @@ export class ShopsResolver { return this.shopsService.findAll({ page, count }); } - @Query(() => Shop, { - description: - 'Return : 입력한 shopId와 일치하는 가게 데이터. 리뷰 작성 권한 확인 안 해줌 ', - }) + @Query( + () => Shop, // + { + description: + 'Return : 입력한 shopId와 일치하는 가게 데이터. 리뷰 작성 권한 확인 안 해줌 ', + }, + ) async fetchShop( @Args('shopId') shopId: string, // ): Promise { return this.shopsService.findById({ shopId }); } - @Mutation(() => Shop, { - description: 'Return : 신규 가게 데이터', - }) + @Mutation( + () => Shop, // + { + description: 'Return : 신규 가게 데이터', + }, + ) createShop( @Args('createShopInput') createShopInput: CreateShopInput, ): Promise { return this.shopsService.create({ createShopInput }); } - @Mutation(() => Shop, { - description: 'Return : 수정 후 가게 데이터', - }) + @Mutation( + () => Shop, // + { + description: 'Return : 수정 후 가게 데이터', + }, + ) updateShop( @Args('shopId') shopId: string, @Args('updateShopInput') updateShopInput: UpdateShopInput, @@ -86,40 +98,15 @@ export class ShopsResolver { return this.shopsService.update({ shopId, updateShopInput }); } - //가게 삭제 - @Mutation(() => Boolean, { - description: 'Return : 가게 정보 삭제 완료 시 true', - }) + @Mutation( + () => Boolean, // + { + description: 'Return : 가게 정보 삭제 완료 시 true', + }, + ) deleteShop( @Args('shopId') shopId: string, // ): Promise { return this.shopsService.delete({ shopId }); } - - // // <--- 기능 필요하면 주석 해제 ---> - // //삭제된 가게 리스트 불러오기 - // @Query(() => [Shop], { - // description: 'Return : 모든 삭제된 가게 목록', - // }) - // fetchShopsWithDeleted(): Promise { - // return this.shopsService.findAllDeleted(); - // } - - // @Query(() => Shop, { - // description: 'Return : 삭제된 가게 1개', - // }) - // fetchShopWithDeleted( - // @Args('shopId') shopId: string, // - // ): Promise { - // return this.shopsService.findDeleted({ shopId }); - // } - - // @Mutation(() => Boolean, { - // description: 'Return : 가게 정보 복구 완료 시 true', - // }) - // restoreShop( - // @Args('shopId') shopId: string, // - // ): Promise { - // return this.shopsService.restore({ shopId }); - // } } diff --git a/src/apis/shops/shops.service.ts b/src/apis/shops/shops.service.ts index a97ff27..784e24d 100644 --- a/src/apis/shops/shops.service.ts +++ b/src/apis/shops/shops.service.ts @@ -27,7 +27,6 @@ export class ShopsService { private readonly shopsRepository: Repository, // ) {} - // 리뷰 평점 순으로 검색 결과 반환 sortByAvgStar({ hits: _hits }): AutocompleteShopsOutput[] { if (_hits.length === 0) { return null; @@ -40,7 +39,6 @@ export class ShopsService { return hits; } - // DB의 모든 가게 정보 불러오기 + 페이징 추가 async findAll({ page, count }: IShopsServiceFindAll): Promise { const allShops = await this.shopsRepository.find({ relations: [ @@ -54,9 +52,6 @@ export class ShopsService { take: count, }); - // <---------- 썸네일 이미지 관련 로직 ----------> - // 썸네일 이미지가 있는지 확인 - // 썸네일이 있으면 각 가게의 image = 썸네일 이미지 let checkThumbnail = 0; allShops.forEach((el) => { const idx = el.image.findIndex((el) => el.isThumbnail === true); @@ -66,13 +61,10 @@ export class ShopsService { } }); - // 썸네일 이미지가 없으면 각 가게의 image = null if (checkThumbnail < 0) { allShops.forEach((el) => (el.image = null)); } - // <---------- 별점 관련 로직 ----------> - // 별점평균이 Null인 경우, 리턴 타입이 number 이므로 0으로 변환하기 allShops.forEach((el) => { el.averageStar === null ? (el.averageStar = 0) @@ -90,7 +82,6 @@ export class ShopsService { ); } - // 가게 데이터 찾기 async findById({ shopId }: IShopsServiceFindById): Promise { const myShop = await this.shopsRepository.findOne({ where: { id: shopId }, @@ -126,7 +117,6 @@ export class ShopsService { }; } - // 가게 신규 생성 async create({ createShopInput }: IShopsServiceCreate): Promise { const { address } = createShopInput; const checkShop = await this.shopsRepository.findOne({ @@ -139,11 +129,9 @@ export class ShopsService { ); } - // 지역구를 지역코드로 변환하기 const district = address.split(' ')[1]; const code = districtCode({ district }); - // 주소에 대한 위도, 경도 가져오기 const [lat, lng] = await this.getLatLngByAddress({ address }); const result = await this.shopsRepository.save({ @@ -174,7 +162,6 @@ export class ShopsService { } } - // 가게 업데이트 async update({ shopId, updateShopInput, @@ -200,7 +187,6 @@ export class ShopsService { return result; } - // 가게 삭제 async delete({ shopId }: IShopsServiceDelete): Promise { const checkShop = await this.shopsRepository.findOne({ where: { id: shopId }, @@ -216,75 +202,4 @@ export class ShopsService { return result.affected ? true : false; } - - // // <--- 기능 필요하면 주석 해제 ---> - // // 삭제된 가게 리스트 불러오기 - // async findAllDeleted(): Promise { - // return await this.shopsRepository.find({ - // withDeleted: true, - // relations: ['reservation'], - // }); - // } - - // // 가게 연락처(phone)로 해당 가게 정보 찾기 - // async findByPhone({ phone }: IShopsServiceFindByPhone): Promise { - // const result = await this.shopsRepository.findOne({ - // where: { phone: phone }, - // relations: ['reservation', 'image', 'review'], - // }); - - // if (!result) { - // throw new UnprocessableEntityException( - // `연락처가 ${phone}인 가게를 찾을 수 없습니다`, - // ); - // } - - // return result; - // } - - // // 가게 주소(address)로 해당 가게 정보 찾기 - // async findByAddress({ address }: IShopsServiceFindByAddress): Promise { - // const result = await this.shopsRepository.findOne({ - // where: { address: address }, - // relations: ['reservation', 'image', 'review'], - // }); - - // if (!result) { - // throw new UnprocessableEntityException( - // `주소가 ${address}인 가게를 찾을 수 없습니다`, - // ); - // } - - // return result; - // } - - // // 삭제된 가게ID로 해당 가게 정보 가져오기 - // async findDeleted({ shopId }: IShopsServiceFindDeleted): Promise { - // const result = await this.shopsRepository.findOne({ - // where: { id: shopId }, - // withDeleted: true, - // // relations: ['reservation'], - // }); - - // if (!result) { - // throw new NotFoundException( - // `삭제된 목록에서 ID가 ${shopId}인 가게를 찾을 수 없습니다`, - // ); - // } - - // return result; - // } - - // // 삭제된 가게 정보 복원 - // async restore({ shopId }: IShopsServiceRestore): Promise { - // const checkDeletedShop = await this.findDeleted({ shopId }); - - // if (!checkDeletedShop) { - // throw new NotFoundException(`ID가 ${shopId}인 가게를 찾을 수 없습니다`); - // } - - // const result = await this.shopsRepository.restore({ id: shopId }); - - // return result.affected ? true : false; - // } }