Skip to content

Commit

Permalink
Fix/finish tutoring (#89)
Browse files Browse the repository at this point in the history
* fix/ finish tutoring

* fix/ finish tutoring

* fix/ finish tutoring

* fix/ finish tutoring

* fix/ finish tutoring

* fix/ finish tutoring

* fix/ finish tutoring

* fix/ finish tutoring

* fix/ finish tutoring
  • Loading branch information
seongyunlee authored Oct 11, 2023
1 parent 124a79b commit d7aa0fe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
18 changes: 9 additions & 9 deletions src/offer/offer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -146,11 +151,6 @@ export class OfferService {
JSON.stringify(confirmMessage),
);

await this.chattingRepository.changeStatus(
chattingId,
ChattingStatus.reserved,
);

const rejectMessage = {
text: '죄송합니다.\n다른 선생님과 수업을 진행하기로 했습니다.',
};
Expand All @@ -162,17 +162,17 @@ export class OfferService {
questionId,
offerTeacherId,
);
await this.chattingRepository.changeStatus(
teacherChatId,
ChattingStatus.declined,
);
await this.socketRepository.sendMessageToBothUser(
userId,
offerTeacherId,
teacherChatId,
'text',
JSON.stringify(rejectMessage),
);
await this.chattingRepository.changeStatus(
teacherChatId,
ChattingStatus.declined,
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/question/entities/question.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const QuestionSchema = new Schema({
'reserved',
'canceled',
'expired',
'completed',
'finished',
'declined',
],
},
Expand Down
8 changes: 0 additions & 8 deletions src/socket/socket.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,5 @@ export class SocketRepository {
JSON.stringify({ chattingId, message }),
);
}

// DynamoDB에 메시지 저장
await this.chattingRepository.sendMessage(
chattingId,
senderId,
format,
body,
);
}
}
32 changes: 22 additions & 10 deletions src/tutoring/tutoring.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand All @@ -49,7 +55,8 @@ export class TutoringService {

return new Success('과외가 종료되었습니다.', { tutoringId });
} catch (error) {
return new Fail('과외를 종료할 수 없습니다.');
console.log(error);
return new Fail(`과외를 종료할 수 없습니다.`);
}
}

Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -175,17 +186,18 @@ export class TutoringService {

await this.questionRepository.changeStatus(chattingId, 'declined');

await this.chattingRepository.changeStatus(
chattingId,
ChattingStatus.declined,
);

await this.socketRepository.sendMessageToBothUser(
chatRoomInfo.teacherId,
chatRoomInfo.studentId,
chattingId,
'request-decline',
JSON.stringify({}),
);
await this.chattingRepository.changeStatus(
chattingId,
ChattingStatus.declined,
);

return new Success('과외를 거절했습니다.');
} catch (e) {
Expand Down

0 comments on commit d7aa0fe

Please sign in to comment.