As I've read in this article Sequelize increment function returning error
I have done the next code:
exports.create = function (req, res) { models.sparepart_request.create({ codWO: req.body.codWO, codSparePart: req.body.codSparePart, quantity: req.body.quantity, date_request: req.body.date_request, codUser: req.body.codUser, request_return: req.body.request_return, received: req.body.received }).then(function (item) { return models.sparepart.decrement( 'stock', { by: req.body.quantity, where: { codSparePart: req.body.codSparePart } } ); }).then(function (item) { res.status(200); res.json(({ success: true, message: 'Query successful', data: item //This is null, I need the values from creating })); }).catch(function (error) { logger.error(JSON.stringify(error)); res.json({ success: false, message: 'Query not successful and error has occured cretaing', error: error, stackError: error.stack }); return res.status(500); }); The problem is the following:
My JSON answer is the following:
{ "success": true, "message": "Query successful", "data": [ [ null, 1 ] ] } How can I take the value of the create item?
NOTE: I've tried to do a transaction but always return a error or stops and gives me a Time Out error. I don't know how to do a transaction with a instance.