-
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.
Merge pull request #24 from TeamBookTez/feat/myInfo-api
Feat/my info api
- Loading branch information
Showing
6 changed files
with
100 additions
and
2 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,48 @@ | ||
import { Request, Response } from "express"; | ||
|
||
// slack | ||
import slack from "../others/slack/slack"; | ||
|
||
// libraries | ||
import response from "../library/response"; | ||
import returnCode from "../library/returnCode"; | ||
import constant from "../library/constant"; | ||
|
||
// service | ||
import userService from "../service/user"; | ||
import { resolveModelGetter } from "sequelize-typescript"; | ||
|
||
/** | ||
* @유저정보조회 | ||
* @route GET /user/myInfo | ||
* @access public | ||
* @err | ||
*/ | ||
|
||
const getMyInfoController = async (req: Request, res: Response) => { | ||
try { | ||
const resData = await userService.getMyInfoService(req.body.userID.id); | ||
response.dataResponse( | ||
res, | ||
returnCode.OK, | ||
"마이페이지 조회 성공.", | ||
true, | ||
resData | ||
); | ||
} catch (err) { | ||
slack.slackWebhook(req, err.message); | ||
console.error(err.message); | ||
response.basicResponse( | ||
res, | ||
returnCode.INTERNAL_SERVER_ERROR, | ||
false, | ||
"서버 오류" | ||
); | ||
} | ||
}; | ||
|
||
const userController = { | ||
getMyInfoController, | ||
}; | ||
|
||
export default userController; |
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,11 @@ | ||
import express from "express"; | ||
import userController from "../controller/user"; | ||
|
||
// middleware | ||
import authMiddleware from "../middleware/auth"; | ||
|
||
const router = express.Router(); | ||
|
||
router.get("/myInfo", authMiddleware, userController.getMyInfoController); | ||
|
||
module.exports = 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,39 @@ | ||
// sequelize | ||
import Sequelize, { Op } from 'sequelize'; | ||
|
||
// library | ||
// import jwt from "jsonwebtoken"; | ||
// import bcrypt from 'bcryptjs'; | ||
// import constant from "../library/constant"; | ||
// import index from "../config"; | ||
|
||
// model | ||
import { User, Review } from "../models"; | ||
|
||
/** | ||
* @유저정보조회 | ||
* @route GET /user/myInfo | ||
* @access public | ||
* @err | ||
*/ | ||
const getMyInfoService = async ( userId: number ) => { | ||
// TODO: - user isDeleted 상태 확인 | ||
const user = await User.findOne({ where: { id: userId } }); | ||
const nickname = user.nickname; | ||
const email = user.email; | ||
const review = await Review.findAll({ | ||
where: { | ||
user_id: userId, | ||
is_deleted: false, | ||
}, | ||
}); | ||
const reviewCount = review.length; | ||
return { nickname, email, reviewCount }; | ||
}; | ||
|
||
const userService = { | ||
getMyInfoService, | ||
}; | ||
|
||
export default userService; | ||
|