From 9a7d1702bd3eda695b7904e64cda95673680e30c Mon Sep 17 00:00:00 2001 From: Seongyun Lee <79950005+seongyunlee@users.noreply.github.com> Date: Fri, 20 Oct 2023 23:06:43 +0900 Subject: [PATCH] feat/ start record and finish record tutoring (#99) --- src/response.ts | 5 +++-- src/tutoring/tutoring.service.ts | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/response.ts b/src/response.ts index 0fe46ea..f864510 100644 --- a/src/response.ts +++ b/src/response.ts @@ -17,7 +17,8 @@ export class Success extends Response { } export class Fail extends Response { - constructor(message: string) { - super(message, false); + constructor(message: string, errorCode?: number) { + if (errorCode) super(message, false, { errorCode }); + else super(message, false); } } diff --git a/src/tutoring/tutoring.service.ts b/src/tutoring/tutoring.service.ts index 548dfd4..3dd33ab 100644 --- a/src/tutoring/tutoring.service.ts +++ b/src/tutoring/tutoring.service.ts @@ -175,12 +175,26 @@ export class TutoringService { async classrroomInfo(tutoringId: string, userId: string) { try { + const userInfo = await this.userRepository.get(userId); + + const tutoring = await this.tutoringRepository.get(tutoringId); + + if (tutoring == null) { + return new Fail('존재하지 않는 과외입니다.', 100); + } + + if (userInfo.role == 'student' && tutoring.status == 'reserved') { + return new Fail('아직 수업이 시작되지 않았습니다.', 200); + } + if (userInfo.role == 'student' && tutoring.status == 'finished') { + return new Fail('이미 종료된 수업입니다.', 300); + } return new Success( '수업 정보를 가져왔습니다.', - await this.classroomChannel(tutoringId, userId), + this.classroomChannel(tutoringId, userId), ); } catch (e) { - return new Fail('수업 정보를 가져오는데 실패했습니다.'); + return new Fail('수업 정보를 가져오는데 실패했습니다.' + e.message); } }