Skip to content

Commit

Permalink
Merge pull request #47 from TEAM-ITERVIEW/#46
Browse files Browse the repository at this point in the history
[feat] 학습 노트 조회 API 필터링 추가
  • Loading branch information
cha2y0ung authored Apr 3, 2024
2 parents cd817a4 + 3d53f0d commit b7b3c87
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/controller/studyNoteController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 3 additions & 1 deletion src/router/studyNoteRouter.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -9,6 +9,8 @@ router.get(
'/:sortNum',
[
param('sortNum').notEmpty(),
query('subjectText').notEmpty(),
query('onlyWrong').notEmpty(),
body('refreshToken').notEmpty(),
],
errorValidator,
Expand Down
2 changes: 0 additions & 2 deletions src/service/interviewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ const makeFeedback = async (makeFeedbackDTO: makeFeedbackDTO, interviewQuestionI
questionId: true,
userId: true,
subjectId: true,
pin: true,
again: true,
}
});

Expand Down
32 changes: 20 additions & 12 deletions src/service/studyNoteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b7b3c87

Please sign in to comment.