sequelize.sync().then(function () {
var _oppty;
Opportunities.findOne({where: {id: form.id}}).then(
function (oppty) {
var attrs = Opportunities.attributes;
for (var key in attrs) {
if (attrs.hasOwnProperty(key)) {
oppty[key] = form[key];
}
}
_oppty = oppty;
return _oppty.save()
}
)
OpptyInvoices.destroy({where: {oppid: form.id}}).then(function(){
form.invoices.map(function(instance){
instance['oppid'] = form.id
})
OpptyInvoices.bulkCreate(form.invoices)
})
OpptyProducts.destroy({where: {oppid: form.id}}).then(function(){
form.products.map(function(instance){
instance['oppid'] = form.id
})
OpptyProducts.bulkCreate(form.products)
})
});
Above code is to edit specific instance that has relation with other database entities, which is the reason why I should edit one instance by multiple async jobs.
edit: OpptyInvoices and OpptyProducts entities have reference key that refer to Opportunity id.
Cause server should response to client and send exact data, server need to know if whole async tasks are end.
How can I let server know the end of whole tasks without falling into callback-hell?
via 오현준
No comments:
Post a Comment