1차 코드
const { users } = require('../../models');
module.exports = {
put: (req, res) => {
const { password, githubId } = req.body;
users
.findOne({
where: {
password: password,
githubId: githubId,
},
})
.then((data) => {
if (!data) {
res.status(500).send('err');
} else {
users.update({
where: {
password: password,
githubId: githubId,
},
});
}
});
},
};
최종 코드
users.update({뭘 업데이트 할 건지},
{where:{어느 정보를 가진 row에서?}}
update문이 password, githubId를 기준으로 사용자를 찾게끔 작성되어있기 때문에 이 단계에서는 해당 데이터를 찾을 수 없다. where의 기준에는 개인정보수정이 불가한 email이 해당된다.
3) 개인정보를 수정한 뒤에는 수정된 정보로 재로그인을 해야 하므로 세션도 제거해줘야 한다. 그래야 클라이언트에서 로그인 페이지로 리다이렉트해줄 수 있다.
const { users } = require('../../models');
module.exports = {
put: (req, res) => {
const { useremail, password, githubId } = req.body;
users
.update(
{
password: password,
githubId: githubId,
},
{
where: {
email: useremail,
},
},
)
.then((data) => {
console.log('개인정보수정 완료');
req.session.destroy((err) => {
if (err) {
res.status(400).send('you are currently not logined');
} else {
console.log('세션 제거 완료');
res.status(200).send('정보수정 완료');
}
});
})
.catch((err) => {
console.log(err);
res.sendStatus(500);
});
},
};
3-1. 참고한 고마운 글들
시퀄라이즈 쿼리
다음에는
➤계속 공부하고 있습니다. 더 나은 의견과 질문이 있으시다면 언제든, 어떤 경로로든 이야기해주세요.