인프런 커뮤니티 질문&답변
이미지 수정 백(routes) 질문
작성
·
200
0
안녕하세요 선생님. 유저 프로필 정보 수정을 만들고 있는데
//프로필 정보 수정
router.patch('/info', isLoggedIn, upload.none(), async(req, res, next) => {
try{
const user = await User.update({
info: req.body.info
}, {
where: {UserId: req.user.id}
});
if(req.body.image){
console.log('image:::' + req.body.image);
console.log('user:::' + req.user.id);
const image = await Image.create({src: req.body.image});
await user.addImage(image);
}
res.status(200).json({info: req.body.info});
}
catch(error){
console.error(error);
next(error);
}
});
이 코드에서 자꾸 user.addImage is not a function이라는 에러가 뜹니다.
user와 Image 테이블의 관계가 일대일이어서(hasOne, belongsTo로 맺었습니다.) addImage로 하면 이미지가 들어갈 거라 생각했는데 어디서 잘못된건지 알 수 있을까요..?ㅠ
콘솔에서 image도 들어간 대로 잘 나오고 user도 아이디 번호 찍혀서 user가 비거나 undefined라서 나는 에러는 아닌것 같다고 생각합니다...선생님의 조언 부탁드립니다ㅠㅠ




