작성
·
260
0
const followers = await user.getFollowers();
const followings = await user.getFollowings();
이 상태로 바로 프론트에게 넘겨주는데 넘겨줄 때
유저의 모든 정보가 넘어갑니다(패스워드 포함)
User.findOne()에서는 attributes, exclude, include
를 사용해서 가져올 정보를 걸러내지 않습니까?
저런 임의로 만들어진 테이블에서는 어떻게 정보를 걸러내나요?
검색도 어떻게 해야 찾을 수 있을까요? 영어로 떠오르질 않아서 질문 드립니다. ㅠㅠ
// GET /user/followings
router.get('/followings', isLoggedIn, async (req: INewRequest, res: Response, next: NextFunction) => {
try {
const user = await UserModel.findOne({
where: { id: req.user.id },
});
if (!user) {
return res.status(403).send('존재하지 않는 유저를 찾을 수 없습니다.');
}
const followings = await user.getFollowings();
res.status(200).json(followings);
} catch (error) {
console.error(error);
next(error); // status 500
}
});