I'm using the following code to use chained promise for invoice
object in Sequelize. But invoice
object is undefined for the second usage of then
.
Invoice.create({
//set values for invoice object
}).then(invoice => { //update company id
//invoice belongs to a company
Company.findOne({where: {id: companyId}}).then(company => {
return invoice.setCompany(company)
})
}).then(invoice => {
console.log('Invoice is: ' + invoice)
//create child items
invoice.createItem({
//set item values
})
}).catch(err => {
console.log('Invoice create error: ' + err)
})
The output in the console is Invoice is :undefined
. What I have done wrongly here?