-
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
9 changed files
with
131 additions
and
9 deletions.
There are no files selected for viewing
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,23 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { message, statusCode } from '../module/constant'; | ||
import { success } from '../module/constant/utils'; | ||
import { historyService } from '../service'; | ||
|
||
const getInterviewList = async (req: Request, res: Response, next: NextFunction) => { | ||
const refreshToken = req.body; | ||
const {sortNum} = req.params; | ||
|
||
try { | ||
const data = await historyService.getInterviewList(refreshToken, +sortNum); | ||
|
||
return res | ||
.status(statusCode.CREATED) | ||
.send(success(statusCode.CREATED, message.GET_INTERVIEWLIST_SUCCESS, data)); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export default { | ||
getInterviewList, | ||
}; |
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,2 +1,3 @@ | ||
export { default as interviewController } from './interviewController'; | ||
export { default as userController } from './userController'; | ||
export { default as userController } from './userController'; | ||
export { default as historyController } from './historyController'; |
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 { historyController } from '../controller'; | ||
import errorValidator from '../middleware/error/errorValidator'; | ||
|
||
const router: Router = Router(); | ||
|
||
router.get( | ||
'/:sortNum', | ||
[ | ||
param('sortNum'), | ||
body('refreshToken').notEmpty(), | ||
], | ||
errorValidator, | ||
historyController.getInterviewList, | ||
); | ||
|
||
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,10 +1,12 @@ | ||
import { Router } from "express"; | ||
import interviewRouter from './interviewRouter'; | ||
import userRouter from "./userRouter"; | ||
import historyRouter from "./historyRouter"; | ||
|
||
const router: Router = Router(); | ||
|
||
router.use('/interview', interviewRouter); | ||
router.use('/accounts', userRouter); | ||
router.use('/history', historyRouter); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
import errorGenerator from '../middleware/error/errorGenerator'; | ||
import { message, statusCode } from '../module/constant'; | ||
const prisma = new PrismaClient(); | ||
|
||
const getIntervewDetails = async (refreshToken: string) => { | ||
const findUserId = await prisma.user.findFirst({ | ||
where: { | ||
refreshToken: refreshToken | ||
}, | ||
select: { | ||
id: true, | ||
} | ||
}); | ||
const findInterview = await prisma.interview.findMany({ | ||
where: { | ||
userId: findUserId!.id | ||
}, | ||
select: { | ||
id: true, | ||
subjectId: true, | ||
startDateTime: true, | ||
endDateTime: true, | ||
title: true, | ||
score: true, | ||
questionNum: true, | ||
} | ||
}); | ||
const interviewDetails = await Promise.all(findInterview.map(async (interview) => { | ||
const subject = await prisma.subject.findUnique({ | ||
where: { | ||
id: interview.subjectId | ||
}, | ||
select: { | ||
subjectText: true | ||
} | ||
}); | ||
|
||
const timeInSeconds = (interview.endDateTime.getTime() - interview.startDateTime.getTime()) / 1000; | ||
|
||
return { | ||
...interview, | ||
subjectText: subject?.subjectText, | ||
time: timeInSeconds | ||
}; | ||
})); | ||
|
||
return interviewDetails; | ||
} | ||
|
||
const getInterviewList = async (refreshToken: string, sortNum: number) => { | ||
try { | ||
let interviewList = await getIntervewDetails(refreshToken); | ||
if (sortNum === 1) { | ||
interviewList.sort((a, b) => b.startDateTime.getTime() - a.startDateTime.getTime()); | ||
} else if (sortNum === 2) { | ||
interviewList.sort((a, b) => (b.score || 0) - (a.score || 0)); | ||
} else if (sortNum === 3) { | ||
interviewList.sort((a, b) => (a.score || 0) - (b.score || 0)); | ||
} else { | ||
interviewList | ||
} | ||
return { data: { interviewList } }; | ||
} catch(error) { | ||
throw error; | ||
} | ||
}; | ||
|
||
export default { | ||
getInterviewList, | ||
}; |
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,2 +1,3 @@ | ||
export { default as interviewService } from './interviewService'; | ||
export { default as userService } from './userService'; | ||
export { default as userService } from './userService'; | ||
export { default as historyService } from './historyService'; |
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