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