From 3d53f0d3b24028ea95eb2ff74d704ff40d810ffb Mon Sep 17 00:00:00 2001 From: chaeyoung Date: Wed, 3 Apr 2024 22:19:52 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=ED=95=99=EC=8A=B5=20=EB=85=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20API=20=ED=95=84=ED=84=B0?= =?UTF-8?q?=EB=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/studyNoteController.ts | 6 +++-- src/router/studyNoteRouter.ts | 4 +++- src/service/interviewService.ts | 2 -- src/service/studyNoteService.ts | 32 +++++++++++++++++---------- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/controller/studyNoteController.ts b/src/controller/studyNoteController.ts index 00020ac..d4823af 100644 --- a/src/controller/studyNoteController.ts +++ b/src/controller/studyNoteController.ts @@ -5,9 +5,11 @@ import { studyNoteService } from '../service'; const getStudyNote = async (req: Request, res: Response, next: NextFunction) => { const refreshToken = req.body; - const {sortNum} = req.params; + const sortNum = +req.params.sortNum; + const subjectText = req.query.subjectText as string; + const onlyWrong = req.query.onlyWrong === 'true'; try { - const data = await studyNoteService.getStudyNote(refreshToken, +sortNum); + const data = await studyNoteService.getStudyNote(refreshToken, subjectText, onlyWrong, +sortNum); return res .status(statusCode.CREATED) .send(success(statusCode.CREATED, message.GET_STUDYNOTE_SUCCESS, data)); diff --git a/src/router/studyNoteRouter.ts b/src/router/studyNoteRouter.ts index 52f5e19..33ba756 100644 --- a/src/router/studyNoteRouter.ts +++ b/src/router/studyNoteRouter.ts @@ -1,5 +1,5 @@ import { Router } from 'express'; -import { body, header, param } from 'express-validator'; +import { body, header, param, query } from 'express-validator'; import { studyNoteController } from '../controller'; import errorValidator from '../middleware/error/errorValidator'; @@ -9,6 +9,8 @@ router.get( '/:sortNum', [ param('sortNum').notEmpty(), + query('subjectText').notEmpty(), + query('onlyWrong').notEmpty(), body('refreshToken').notEmpty(), ], errorValidator, diff --git a/src/service/interviewService.ts b/src/service/interviewService.ts index e9cb33d..8f06a96 100644 --- a/src/service/interviewService.ts +++ b/src/service/interviewService.ts @@ -111,8 +111,6 @@ const makeFeedback = async (makeFeedbackDTO: makeFeedbackDTO, interviewQuestionI questionId: true, userId: true, subjectId: true, - pin: true, - again: true, } }); diff --git a/src/service/studyNoteService.ts b/src/service/studyNoteService.ts index 1720a34..e43d0f8 100644 --- a/src/service/studyNoteService.ts +++ b/src/service/studyNoteService.ts @@ -3,7 +3,7 @@ import errorGenerator from '../middleware/error/errorGenerator'; import { message, statusCode } from '../module/constant'; const prisma = new PrismaClient(); -const getStudyNote = async (refreshToken: string, sortNum: number) => { +const getStudyNote = async (refreshToken: string, subjectText: string, onlyWrong: boolean, sortNum: number) => { try { const getUser= await prisma.user.findFirst({ where: { @@ -79,20 +79,28 @@ const getStudyNote = async (refreshToken: string, sortNum: number) => { subjectText: true } }) - const result = ({ - data: { - id: question!.id, - subjectText: getSubjectText!.subjectText, - title: getTitle?.title, - again: question!.again, - questionText: question!.questionText, - score: getFeedback?.score, - pin: question!.pin + if ((subjectText === 'ALL' || subjectText === getSubjectText!.subjectText) && + (!onlyWrong || (getFeedback?.score !== 1 && getFeedback!.score !== 0.5))) { + const result = ({ + data: { + id: question!.id, + subjectText: getSubjectText!.subjectText, + title: getTitle?.title, + again: question!.again, + questionText: question!.questionText, + score: getFeedback?.score, + pin: question!.pin + } + }); + questionList.push(result) } - }); - questionList.push(result) } } + if (sortNum === 2) { + questionList.filter(question => question.data.again === true); + } else if (sortNum === 3) { + questionList.filter(question => question.data.pin === true); + } return { data: { questionList