diff --git a/src/offer/offer.service.ts b/src/offer/offer.service.ts index 8cf6ceb..f84b194 100644 --- a/src/offer/offer.service.ts +++ b/src/offer/offer.service.ts @@ -123,6 +123,11 @@ export class OfferService { const question = await this.questionRepository.getInfo(questionId); + await this.chattingRepository.changeStatus( + chattingId, + ChattingStatus.reserved, + ); + const offerTeacherIds = question.offerTeachers; await this.questionRepository.changeStatus(questionId, 'reserved'); @@ -146,11 +151,6 @@ export class OfferService { JSON.stringify(confirmMessage), ); - await this.chattingRepository.changeStatus( - chattingId, - ChattingStatus.reserved, - ); - const rejectMessage = { text: '죄송합니다.\n다른 선생님과 수업을 진행하기로 했습니다.', }; @@ -162,6 +162,10 @@ export class OfferService { questionId, offerTeacherId, ); + await this.chattingRepository.changeStatus( + teacherChatId, + ChattingStatus.declined, + ); await this.socketRepository.sendMessageToBothUser( userId, offerTeacherId, @@ -169,10 +173,6 @@ export class OfferService { 'text', JSON.stringify(rejectMessage), ); - await this.chattingRepository.changeStatus( - teacherChatId, - ChattingStatus.declined, - ); } } diff --git a/src/question/entities/question.schema.ts b/src/question/entities/question.schema.ts index 555cc81..dccd745 100644 --- a/src/question/entities/question.schema.ts +++ b/src/question/entities/question.schema.ts @@ -31,7 +31,7 @@ export const QuestionSchema = new Schema({ 'reserved', 'canceled', 'expired', - 'completed', + 'finished', 'declined', ], }, diff --git a/src/socket/socket.repository.ts b/src/socket/socket.repository.ts index a69fceb..f02832d 100644 --- a/src/socket/socket.repository.ts +++ b/src/socket/socket.repository.ts @@ -149,13 +149,5 @@ export class SocketRepository { JSON.stringify({ chattingId, message }), ); } - - // DynamoDB에 메시지 저장 - await this.chattingRepository.sendMessage( - chattingId, - senderId, - format, - body, - ); } } diff --git a/src/tutoring/tutoring.service.ts b/src/tutoring/tutoring.service.ts index e5cd0ee..7120d13 100644 --- a/src/tutoring/tutoring.service.ts +++ b/src/tutoring/tutoring.service.ts @@ -24,23 +24,29 @@ export class TutoringService { async finish(tutoringId: string) { try { const tutoring = await this.tutoringRepository.finishTutoring(tutoringId); - const { whiteBoardUUID } = tutoring; - await this.agoraService.disableWhiteBoardChannel(whiteBoardUUID); await this.questionRepository.changeStatus( tutoring.questionId, 'finished', ); + const { whiteBoardUUID } = tutoring; + await this.agoraService.disableWhiteBoardChannel(whiteBoardUUID); + const finishMessage = { startAt: tutoring.startedAt, endAt: tutoring.endedAt, }; + const chatId = await this.chattingRepository.getIdByQuestionAndTeacher( + tutoring.questionId, + tutoring.teacherId, + ); + await this.socketRepository.sendMessageToBothUser( tutoring.teacherId, tutoring.studentId, - tutoring.questionId, + chatId, 'tutoring-finished', JSON.stringify(finishMessage), ); @@ -49,7 +55,8 @@ export class TutoringService { return new Success('과외가 종료되었습니다.', { tutoringId }); } catch (error) { - return new Fail('과외를 종료할 수 없습니다.'); + console.log(error); + return new Fail(`과외를 종료할 수 없습니다.`); } } @@ -83,6 +90,12 @@ export class TutoringService { questionId, question.selectedTeacherId, ); + await this.chattingRepository.changeStatus( + chatRoomId, + ChattingStatus.reserved, + ); + + await this.questionRepository.changeStatus(questionId, 'reserved'); await this.socketRepository.sendMessageToBothUser( question.selectedTeacherId, @@ -92,8 +105,6 @@ export class TutoringService { JSON.stringify(reserveConfirmMessage), ); - await this.questionRepository.changeStatus(questionId, 'reserved'); - return new Success('수업 시간이 확정되었습니다.'); } catch (error) { return new Fail(error.message); @@ -175,6 +186,11 @@ export class TutoringService { await this.questionRepository.changeStatus(chattingId, 'declined'); + await this.chattingRepository.changeStatus( + chattingId, + ChattingStatus.declined, + ); + await this.socketRepository.sendMessageToBothUser( chatRoomInfo.teacherId, chatRoomInfo.studentId, @@ -182,10 +198,6 @@ export class TutoringService { 'request-decline', JSON.stringify({}), ); - await this.chattingRepository.changeStatus( - chattingId, - ChattingStatus.declined, - ); return new Success('과외를 거절했습니다.'); } catch (e) {