Reputation: 6363
I'm making a request to DELETE a record, but then want to immediately query remaining records. How can I query remaining records after the DELETE is successful.
So far I have this where I make the DELETE request and then query based on the status code (1 is a success, 0 is failure), but wondering if there is a better way to handle this:
app.delete('/projects', (req, res) => {
const { id } = req.query;
Item
.destroy({ where: { id: id } })
.then(status => {
if (status === 1) {
// make query here, something like:
// Item.findAll().then(...)
}
})
.catch(err => err);
});
Upvotes: 0
Views: 181
Reputation: 27609
Your only option of doing it in a single call to the database would be to wrap it in a stored procedure. In this case I don't see any real advantages to doing it that way and would recommend using two calls as you have in your example.
Upvotes: 1