Skip to content

Commit

Permalink
Merge pull request #27 from TEAM-ITERVIEW/#21
Browse files Browse the repository at this point in the history
[feat] 프로필 조회 API
  • Loading branch information
cha2y0ung authored Mar 27, 2024
2 parents 67e0e06 + cb74fec commit 159ddbc
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/controller/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as interviewController } from './interviewController';
export { default as interviewController } from './interviewController';
export { default as userController } from './userController';
22 changes: 22 additions & 0 deletions src/controller/userController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Request, Response, NextFunction } from 'express';
import { message, statusCode } from '../module/constant';
import { success } from '../module/constant/utils';
import { userService } from '../service';

const accessUserInfo = async (req: Request, res: Response, next: NextFunction) => {
const refreshToken = req.body;

try {
const data = await userService.accessUserInfo(refreshToken);

return res
.status(statusCode.CREATED)
.send(success(statusCode.CREATED, message.ACCESS_USERINFO_SUCCESS, data));
} catch (error) {
next(error);
}
};

export default {
accessUserInfo
};
1 change: 1 addition & 0 deletions src/module/constant/responseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export default {
START_INTERVIEW_SUCCESS: "인터뷰 시작 성공",
MAKE_FEEDBACK_SUCCESS: "피드백 생성 성공",
SAVE_EMOTION_SUCCESS: "감정 저장 성공",
ACCESS_USERINFO_SUCCESS: "프로필 조회 성공",
};
2 changes: 2 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Router } from "express";
import interviewRouter from './interviewRouter';
import userRouter from "./userRouter";

const router: Router = Router();

router.use('/interview', interviewRouter);
router.use('/accounts', userRouter);

export default router;
17 changes: 17 additions & 0 deletions src/router/userRouter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Router } from 'express';
import { body, header, param } from 'express-validator';
import { userController } from '../controller';
import errorValidator from '../middleware/error/errorValidator';

const router: Router = Router();

router.get(
'/',
[
body('refreshToken').notEmpty(),
],
errorValidator,
userController.accessUserInfo,
);

export default router;
3 changes: 2 additions & 1 deletion src/service/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as interviewService } from './interviewService';
export { default as interviewService } from './interviewService';
export { default as userService } from './userService';
28 changes: 28 additions & 0 deletions src/service/userService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { PrismaClient } from '@prisma/client';
import errorGenerator from '../middleware/error/errorGenerator';
import { message, statusCode } from '../module/constant';
const prisma = new PrismaClient();

const accessUserInfo = async (refreshToken: string) => {
try {
const userInfo = await prisma.user.findfirst({
where: {
refreshToken: refreshToken,
},
select: {
id: true,
userName: true,
pictureURL: true,
themeColor: true,
refreshToken: true,
}
});
return userInfo;
} catch(error) {
throw error;
}
};

export default {
accessUserInfo,
};

0 comments on commit 159ddbc

Please sign in to comment.