I've got "user.save is not a function" error when I try to run these code. I don't know why. I'll happy if you figure out that.
let updateUserInfo = (data) => {
return new Promise(async (resolve, reject) => {
try {
const user = await db.User.findOne({
where: { id: data.id }
})
if (user) {
user.first_name = data.first_name;
user.last_name = data.last_name;
user.email = data.email;
await user.save();
resolve();
}
else {
resolve();
}
} catch (e) {
reject(e)
}
})
}
CodePudding user response:
this error shows your code have mistake. that is if you wants to pass findAll method with async and await use it instead of your code:
var [err, user] = await to(
db.User.findOne({
where: { id: data.id },
})
);
then use user.save() i hope it helpful.