Skip to content

Commit

Permalink
Merge pull request #37 from TEAM-ITERVIEW/#36
Browse files Browse the repository at this point in the history
[feat] 면접 기록 상세조회 API
  • Loading branch information
cha2y0ung authored Mar 29, 2024
2 parents 78aa9d1 + 073e124 commit a005fdd
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/controller/historyController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ const getInterviewList = async (req: Request, res: Response, next: NextFunction)
}
};

const getInterviewDetail = async (req: Request, res: Response, next: NextFunction) => {
const {interviewId} = req.params;

try {
const data = await historyService.getInterviewDetail(+interviewId);

return res
.status(statusCode.CREATED)
.send(success(statusCode.CREATED, message.GET_INTERVIEWDETAIL_SUCCESS, data));
} catch (error) {
next(error);
}
};

export default {
getInterviewList,
getInterviewDetail,
};
1 change: 1 addition & 0 deletions src/module/constant/responseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export default {
END_INTERVIEW_SUCCESS: "인터뷰 종료 성공",
FIRST_RESULT_INTERVIEW_SUCCESS: "첫번째 인터뷰 결과 조회 성공",
GET_INTERVIEWLIST_SUCCESS: "면접 기록 리스트 조회 성공",
GET_INTERVIEWDETAIL_SUCCESS: "면접 기록 상세 조회 성공",
};
8 changes: 8 additions & 0 deletions src/router/historyRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ router.get(
historyController.getInterviewList,
);

router.get(
'/:interviewId',
[
param('interviewId').notEmpty(),
],
errorValidator,
historyController.getInterviewDetail,
)
export default router;
112 changes: 112 additions & 0 deletions src/service/historyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,118 @@ const getInterviewList = async (refreshToken: string, sortNum: number) => {
}
};

const getAnswerAndFeedback = async (questionId: number, interviewId: number) => {
const answer = await prisma.answer.findFirst({
where: {
questionId: questionId,
interviewId: interviewId
}
});
const question = await prisma.question.findFirst({
where: {
id: questionId,
},
select: {
questionText: true,
sampleAnswer: true
}
})
if (answer && question) {
const feedback = await prisma.feedback.findFirst({
where: {
answerId: answer.id,
interviewId: interviewId
}
});
if (feedback) {
return {
questionId: questionId,
questionText: question.questionText,
sampleAnswer: question.sampleAnswer,
score: feedback.score,
text: answer.text,
feedbackText: feedback.feedbackText,
time: answer.time,
}
}
}
if (!answer || !question) {
return {};
}
}

const getQuestionDetails = async (interviewId: number) => {
const findQuestionList = await prisma.interviewQuestion.findMany({
where: {
interviewId: interviewId,
},
select: {
id: true,
interviewId: true,
questionId: true,
}
})
const questionDetails = [];
for (const question of findQuestionList) {
const details = await getAnswerAndFeedback(question.questionId, question.interviewId);
questionDetails.push(details);
}
return questionDetails;
}

const getInterviewDetail = async(interviewId: number) => {
try {
const questionDetails = await getQuestionDetails(interviewId)
const findInterview = await prisma.interview.findFirst({
where: {
id: interviewId,
},
select: {
id: true,
userId: true,
subjectId: true,
startDateTime: true,
endDateTime: true,
questionNum: true,
score: true,
otherFeedback: true,
title: true,
onlyVoice: true,
}
})

if (findInterview){
const findSubjectText = await prisma.subject.findFirst({
where: {
id: findInterview.subjectId
},
select: {
subjectText: true,
}
})
const result = ({
data: {
id: findInterview.id,
subjectText: findSubjectText?.subjectText,
startDateTime: findInterview.startDateTime,
endDateTime: findInterview.endDateTime,
questionNum: findInterview.questionNum,
score: findInterview.score,
title: findInterview.title,
otherFeedback: findInterview.otherFeedback,
onlyVoice: findInterview.onlyVoice,
questionList: questionDetails,
}
})
return result
}

} catch(error) {
throw error;
}
};

export default {
getInterviewList,
getInterviewDetail,
};

0 comments on commit a005fdd

Please sign in to comment.