Reputation: 145
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)
}
})
}
Upvotes: 0
Views: 1969
Reputation: 7
You miss raw = false, most likely in db you have set raw = true, now you want to update you need to switch to raw = false
const user = await db.User.findOne({ where: { id: data.id }, raw: false})
Upvotes: 1
Reputation: 76
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.
Upvotes: 1