Reputation: 485
Sooo it's another async/await question. I use npm ORM to create an edit function for my models, and this works out perfectly using this code:
module.exports = {
edit: (model, id, data) => {
model.get(id, (err, result) => {
result.save(data)
})
}
}
I learned about async and await the other day but when I was experimenting with it, it didn't matter what I do I always got the following error:
"Missing Model.get() callback"
Please help me where I'm going wrong..
Upvotes: 0
Views: 2079
Reputation: 37383
model.get
doesn't return a promise, use getAsync
instead :
module.exports = {
edit: async (model, id, data) => {
let result = await model.getAsync(id);
result.save(data)
return "done";
}
}
call it like this :
let service = require("./service");
service.edit(model,id,data).then( data => console.log(data))
Upvotes: 3