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
28 changes: 16 additions & 12 deletions src/apis/reviews/reviews.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Review> {
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, //
Expand All @@ -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,
Expand All @@ -54,9 +57,10 @@ export class ReviewsResolver {
});
}

@Mutation(() => Boolean, {
description: 'Return: 리뷰 삭제 후 true 반환',
})
@Mutation(
() => Boolean, //
{ description: 'Return: 리뷰 삭제 후 true 반환' },
)
deleteReview(
@Args('reviewId') id: string, //
): Promise<boolean> {
Expand Down
2 changes: 0 additions & 2 deletions src/apis/reviews/reviews.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export class ReviewsService {
private readonly shopsService: ShopsService,
) {}

// 리뷰 가져오기
async find({ reviewId }: IReviewServiceFindById): Promise<Review> {
const result = await this.reviewsRepository.findOne({
where: { id: reviewId },
Expand All @@ -37,7 +36,6 @@ export class ReviewsService {
return result;
}

// 가게의 모든 리뷰 가져오기
async findByShopIdWithPage({
page,
count, //
Expand Down
41 changes: 25 additions & 16 deletions src/apis/shopImages/shopImage.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShopImage> {
return this.shopImagesService.findThumbnailByShopId({ shopId });
}

@Query(() => [ShopImage], {
description: 'Return: 입력한 가게의 모든 가게이미지',
})
@Query(
() => [ShopImage], //
{ description: 'Return: 입력한 가게의 모든 가게이미지' },
)
fetchShopImagesByShop(
@Args('shopId') shopId: string, //
): Promise<ShopImage[]> {
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<ShopImage> {
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<ShopImage> {
return await this.shopImagesService.update({ updateShopImageInput });
}

@Mutation(() => Boolean, {
description: 'Return: 가게 이미지 삭제 완료 시, true',
})
@Mutation(
() => Boolean, //
{ description: 'Return: 가게 이미지 삭제 완료 시, true' },
)
deleteShopImage(
@Args('shopImageId') shopImageId: string, //
): Promise<boolean> {
Expand Down
15 changes: 2 additions & 13 deletions src/apis/shopImages/shopImage.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ConflictException,
Injectable,
NotFoundException,
UnprocessableEntityException,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
Expand All @@ -24,7 +23,6 @@ export class ShopImagesService {
private readonly shopsService: ShopsService,
) {}

// 가게ID로 썸네일 찾기
async findThumbnailByShopId({
shopId,
}: IShopImagesServiceFindThumbnail): Promise<ShopImage> {
Expand All @@ -44,7 +42,6 @@ export class ShopImagesService {
});
}

// 가게ID로 해당 이미지 찾기
async findByShopId({
shopId,
}: IShopImagesServiceFindByShopId): Promise<ShopImage[]> {
Expand All @@ -61,8 +58,7 @@ export class ShopImagesService {
});
}

// DB테이블에 신규 이미지 저장
async save({
async create({
imageUrl,
isThumbnail,
shopId,
Expand All @@ -81,7 +77,6 @@ export class ShopImagesService {
});
}

// DB테이블에서 이미지 업데이트
async update({
updateShopImageInput,
}: IShopImagesServiceUpdate): Promise<ShopImage> {
Expand All @@ -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<boolean> {
const checkImage = await this.shopImageRepository.findOne({
where: { id: shopImageId },
Expand All @@ -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;
}
Expand Down