From 74793fa850a841791d8540139bc9a594be6ffc4e Mon Sep 17 00:00:00 2001 From: Jjoobob123 <273hur4747@gmail.com> Date: Mon, 3 Apr 2023 23:03:38 +0900 Subject: [PATCH] =?UTF-8?q?reservation=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__test__/reservation.resolver.spec.ts | 4 +- ...ation.module.ts => reservations.module.ts} | 4 +- ...n.resolver.ts => reservations.resolver.ts} | 69 ++++++++++--------- ...ion.service.ts => reservations.service.ts} | 60 ++-------------- src/app.module.ts | 2 +- 5 files changed, 48 insertions(+), 91 deletions(-) rename src/apis/reservations/{reservation.module.ts => reservations.module.ts} (87%) rename src/apis/reservations/{reservation.resolver.ts => reservations.resolver.ts} (64%) rename src/apis/reservations/{reservation.service.ts => reservations.service.ts} (79%) diff --git a/src/apis/reservations/__test__/reservation.resolver.spec.ts b/src/apis/reservations/__test__/reservation.resolver.spec.ts index c1a9c3d..ee87458 100644 --- a/src/apis/reservations/__test__/reservation.resolver.spec.ts +++ b/src/apis/reservations/__test__/reservation.resolver.spec.ts @@ -11,8 +11,8 @@ import { ShopsService } from 'src/apis/shops/shops.service'; import { UsersService } from 'src/apis/users/user.service'; import { CreateReservationInput } from '../dto/create-reservation.input'; import { Reservation } from '../entities/reservation.entity'; -import { ReservationsResolver } from '../reservation.resolver'; -import { ReservationsService } from '../reservation.service'; +import { ReservationsResolver } from '../reservations.resolver'; +import { ReservationsService } from '../reservations.service'; import { MOCK_RESERVATION, MOCK_REVIEW, diff --git a/src/apis/reservations/reservation.module.ts b/src/apis/reservations/reservations.module.ts similarity index 87% rename from src/apis/reservations/reservation.module.ts rename to src/apis/reservations/reservations.module.ts index 4426a90..e8566c3 100644 --- a/src/apis/reservations/reservation.module.ts +++ b/src/apis/reservations/reservations.module.ts @@ -9,8 +9,8 @@ import { ShopsService } from '../shops/shops.service'; import { User } from '../users/entities/user.entity'; import { UsersService } from '../users/user.service'; import { Reservation } from './entities/reservation.entity'; -import { ReservationsResolver } from './reservation.resolver'; -import { ReservationsService } from './reservation.service'; +import { ReservationsResolver } from './reservations.resolver'; +import { ReservationsService } from './reservations.service'; @Module({ imports: [ diff --git a/src/apis/reservations/reservation.resolver.ts b/src/apis/reservations/reservations.resolver.ts similarity index 64% rename from src/apis/reservations/reservation.resolver.ts rename to src/apis/reservations/reservations.resolver.ts index d668fe2..73faffb 100644 --- a/src/apis/reservations/reservation.resolver.ts +++ b/src/apis/reservations/reservations.resolver.ts @@ -5,7 +5,7 @@ import { GqlAuthGuard } from '../auth/guards/gql-auth.guard'; import { CreateReservationInput } from './dto/create-reservation.input'; import { returnUserWithReviewOutput } from './dto/return-reservation.output'; import { Reservation } from './entities/reservation.entity'; -import { ReservationsService } from './reservation.service'; +import { ReservationsService } from './reservations.service'; @Resolver() export class ReservationsResolver { @@ -13,63 +13,68 @@ export class ReservationsResolver { private readonly reservationsService: ReservationsService, // ) {} - //예약 생성하기 - @Mutation(() => Reservation, { description: 'Return: 생성된 신규 예약 정보' }) - async createReservation( - @Args('createReservationInput') - createReservationInput: CreateReservationInput, // - ): Promise { - return await this.reservationsService.create({ - createReservationInput, - }); - } - - // 예약ID로 예약정보 가져오기 - @Query(() => Reservation, { - description: 'Return : 예약 정보', - }) + @Query( + () => Reservation, // + { description: 'Return : 예약 정보' }, + ) fetchReservation( @Args('reservationId') reservationId: string, // ): Promise { return this.reservationsService.findOne({ reservationId }); } - // 회원의 모든 예약 가져오기 @UseGuards(GqlAuthGuard('access')) - @Query(() => [Reservation], { - description: 'Return : 한 회원의 예약 정보', - }) + @Query( + () => [Reservation], // + { description: 'Return : 한 회원의 모든 예약 정보' }, + ) fetchReservationsByUser( @Context() context: IContext, // ): Promise { const userId = context.req.user.id; - console.log(userId, '@@@@'); return this.reservationsService.findAllByUserId({ userId }); } - // 가게의 모든 예약 가져오기 - @Query(() => [Reservation], { - description: 'Return : 한 가게의 예약 정보', - }) + @Query( + () => [Reservation], // + { description: 'Return : 한 가게의 예약 정보' }, + ) fetchReservationsByShop( @Args('shopId') shopId: string, // ): Promise { return this.reservationsService.findAllByShopId({ shopId }); } - // 가게의 모든 예약과 예약자 가져오기 - @Query(() => [returnUserWithReviewOutput], { - description: - 'Return : { profile: 회원정보 , review: 그 회원이 작성한 리뷰 } 형식의 객체들이 모인 배열', - }) + @Query( + () => [returnUserWithReviewOutput], // + { + description: + 'Return : { profile: 회원정보 , review: 그 회원이 작성한 리뷰 } 형식의 배열', + }, + ) fetchForShopDetailPage( @Args('shopId') shopId: string, // ): Promise { return this.reservationsService.findForShopDetailPage({ shopId }); } - //예약 삭제하기 - @Mutation(() => Boolean, { description: ' Return: 예약 삭제하기' }) + @Mutation( + () => Reservation, // + { description: 'Return: 생성된 신규 예약 정보' }, + ) + async createReservation( + @Args('createReservationInput') + createReservationInput: CreateReservationInput, // + ): Promise { + return await this.reservationsService.create({ + createReservationInput, + }); + } + + @Mutation( + () => Boolean, // + { description: ' Return: 예약 삭제하기' }, + ) deleteReservation( @Args('reservationId') reservationId: string, // ): Promise { diff --git a/src/apis/reservations/reservation.service.ts b/src/apis/reservations/reservations.service.ts similarity index 79% rename from src/apis/reservations/reservation.service.ts rename to src/apis/reservations/reservations.service.ts index b0773c4..a01b22c 100644 --- a/src/apis/reservations/reservation.service.ts +++ b/src/apis/reservations/reservations.service.ts @@ -7,9 +7,7 @@ import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { DogsService } from '../dogs/dogs.service'; import { Review } from '../reviews/entities/review.entity'; -import { ReviewsService } from '../reviews/reviews.service'; import { ShopsService } from '../shops/shops.service'; -import { User } from '../users/entities/user.entity'; import { UsersService } from '../users/user.service'; import { returnUserWithReviewOutput } from './dto/return-reservation.output'; import { Reservation } from './entities/reservation.entity'; @@ -20,7 +18,6 @@ import { IReservationsServiceFindAllByShopId, IReservationsServiceFindAllByUserId, IReservationsServiceFindById, - IReservationsServiceFindDeletedById, IReservationsServiceFindForShopDetailPage, } from './interfaces/reservations-service.interface'; @@ -28,20 +25,19 @@ import { export class ReservationsService { constructor( @InjectRepository(Reservation) - private readonly reservationsRepository: Repository, // + private readonly reservationsRepository: Repository, + @InjectRepository(Review) + private readonly reviewsRepository: Repository, + private readonly usersService: UsersService, private readonly shopsService: ShopsService, private readonly dogsService: DogsService, - @InjectRepository(Review) - private readonly reviewsRepository: Repository, ) {} - // 신규 예약 정보 생성 async create({ createReservationInput, }: IReservationsServiceCreate): Promise { const { date, time, shopId, userId, dogId } = createReservationInput; - const checkReservation = await this.checkDuplication({ date, time, @@ -82,7 +78,6 @@ export class ReservationsService { }); } - // 예약 가능 여부 확인하기 async checkDuplication({ date, time, @@ -98,13 +93,12 @@ export class ReservationsService { return checkReservation; } - // 예약ID로 해당 예약정보 찾기 async findOne({ reservationId, }: IReservationsServiceFindById): Promise { const result = await this.reservationsRepository.findOne({ where: { id: reservationId }, - relations: ['shop', 'user', 'dog'], + relations: ['shop', 'user', 'dog', 'review'], order: { date: 'ASC', time: 'ASC', @@ -118,7 +112,6 @@ export class ReservationsService { return result; } - // 회원의 모든 예약 가져오기 async findAllByUserId({ userId, }: IReservationsServiceFindAllByUserId): Promise { @@ -140,13 +133,12 @@ export class ReservationsService { return result; } - // 가게의 모든 예약 가져오기 async findAllByShopId({ shopId, }: IReservationsServiceFindAllByShopId): Promise { const result = await this.reservationsRepository.find({ where: { shop: { id: shopId } }, - relations: ['shop', 'user', 'dog'], + relations: ['shop', 'user', 'dog', 'review'], order: { date: 'ASC', time: 'ASC', @@ -214,7 +206,6 @@ export class ReservationsService { return fetchList; } - //예약 삭제하기 async delete({ reservationId, }: IReservationsServiceDelete): Promise { @@ -234,43 +225,4 @@ export class ReservationsService { return result.affected ? true : false; } - - // // <--- 기능 필요하다면 주석 해제 ---> - // // 삭제된 예약 정보 가져오기 - // async findDeletedById({ - // reservationId, - // }: IReservationsServiceFindDeletedById): Promise { - // const result = await this.reservationsRepository.findOne({ - // where: { id: reservationId }, - // withDeleted: true, - // // relations: ['shop', 'user', 'dog'], - // }); - - // if (!result) { - // throw new UnprocessableEntityException( - // `예약ID가 ${reservationId}인 예약을 찾을 수 없습니다`, - // ); - // } - - // return result; - // } - - // // 유저의 삭제된 예약 정보 가져오기 - // async findDeletedByUserId({ - // userId, - // }: IReservationsServiceFindAllByUserId): Promise { - // const result = await this.reservationsRepository.find({ - // where: { user: { id: userId } }, - // withDeleted: true, - // // relations: ['shop', 'user', 'dog'], - // }); - - // if (!result) { - // throw new NotFoundException( - // `회원ID가 ${userId}인 예약을 찾을 수 없습니다`, - // ); - // } - - // return result; - // } } diff --git a/src/app.module.ts b/src/app.module.ts index 77a6e3a..04ff6e5 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -16,7 +16,7 @@ import { JwtGoogleStrategy } from './apis/auth/strategies/jwt-social-google.stra import { MailerModule } from '@nestjs-modules/mailer'; import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter'; import { JwtKakaoStrategy } from './apis/auth/strategies/jwt-social-kakao.strategy'; -import { ReservationsModule } from './apis/reservations/reservation.module'; +import { ReservationsModule } from './apis/reservations/reservations.module'; import { ReviewsModule } from './apis/reviews/reviews.module'; import { ShopImagesModule } from './apis/shopImages/shopImage.module'; import { AppController } from './app.controller';