-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] 학습 노트 조회 api
- Loading branch information
Showing
14 changed files
with
651 additions
and
875 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { default as interviewController } from './interviewController'; | ||
export { default as userController } from './userController'; | ||
export { default as historyController } from './historyController'; | ||
export { default as questionController } from './questionController'; | ||
export { default as questionController } from './questionController'; | ||
export { default as studyNoteController } from './studyNoteController'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { message, statusCode } from '../module/constant'; | ||
import { success } from '../module/constant/utils'; | ||
import { studyNoteService } from '../service'; | ||
|
||
const getStudyNote = async (req: Request, res: Response, next: NextFunction) => { | ||
const refreshToken = req.body; | ||
const {sortNum} = req.params; | ||
try { | ||
const data = await studyNoteService.getStudyNote(refreshToken, +sortNum); | ||
return res | ||
.status(statusCode.CREATED) | ||
.send(success(statusCode.CREATED, message.GET_STUDYNOTE_SUCCESS, data)); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export default { | ||
getStudyNote, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Router } from 'express'; | ||
import { body, header, param } from 'express-validator'; | ||
import { studyNoteController } from '../controller'; | ||
import errorValidator from '../middleware/error/errorValidator'; | ||
|
||
const router: Router = Router(); | ||
|
||
router.get( | ||
'/:sortNum', | ||
[ | ||
param('sortNum').notEmpty(), | ||
body('refreshToken').notEmpty(), | ||
], | ||
errorValidator, | ||
studyNoteController.getStudyNote, | ||
); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { default as interviewService } from './interviewService'; | ||
export { default as userService } from './userService'; | ||
export { default as historyService } from './historyService'; | ||
export { default as questionService } from './questionService'; | ||
export { default as questionService } from './questionService'; | ||
export { default as studyNoteService } from './studyNoteService'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
import errorGenerator from '../middleware/error/errorGenerator'; | ||
import { message, statusCode } from '../module/constant'; | ||
const prisma = new PrismaClient(); | ||
|
||
const getStudyNote = async (refreshToken: string, sortNum: number) => { | ||
try { | ||
const getUser= await prisma.user.findFirst({ | ||
where: { | ||
refreshToken: refreshToken | ||
}, | ||
select: { | ||
id: true | ||
} | ||
}); | ||
|
||
const interviews = await prisma.interview.findMany({ | ||
where: { | ||
userId: getUser!.id, | ||
}, | ||
select: { | ||
id: true | ||
} | ||
}) | ||
|
||
const questionList = []; | ||
for (const interview of interviews) { | ||
const interviewQuestions = await prisma.interviewQuestion.findMany({ | ||
where: { | ||
interviewId: interview.id | ||
}, | ||
select: { | ||
questionId: true, | ||
interviewId: true, | ||
} | ||
}); | ||
for (const interviewQuestion of interviewQuestions) { | ||
const question = await prisma.question.findFirst({ | ||
where: { | ||
id: interviewQuestion.questionId | ||
}, | ||
select: { | ||
id: true, | ||
subjectId: true, | ||
questionText: true, | ||
pin: true, | ||
again: true | ||
} | ||
}) | ||
const getAnswer = await prisma.answer.findFirst({ | ||
where: { | ||
questionId: interviewQuestion.questionId | ||
}, | ||
select: { | ||
id: true | ||
} | ||
}) | ||
const getFeedback = await prisma.feedback.findFirst({ | ||
where: { | ||
answerId: getAnswer!.id | ||
}, | ||
select: { | ||
score: true, | ||
} | ||
}) | ||
const getTitle = await prisma.interview.findFirst({ | ||
where:{ | ||
id: interviewQuestion.interviewId | ||
}, | ||
select: { | ||
title: true, | ||
} | ||
}) | ||
const getSubjectText = await prisma.subject.findFirst({ | ||
where: { | ||
id: question?.subjectId | ||
}, | ||
select: { | ||
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 | ||
} | ||
}); | ||
questionList.push(result) | ||
} | ||
} | ||
return { | ||
data: { | ||
questionList | ||
} | ||
} | ||
} catch(error) { | ||
throw error; | ||
} | ||
}; | ||
|
||
export default { | ||
getStudyNote, | ||
}; |
Oops, something went wrong.