In the product table add one field like sellcounter and do following the operation.
After placing an order make one update query in product Table Like...
await productModel.updateAll({
id: product.id
}, {
sellcounter: product.sellcounter + 1
});
Above code is for loopback Node
The idea here is to increment the number of sales by one on a specific product.
To do so, you'll need to use the method findOne
or findById
to update the specific product.
The resulted code should look like this (assuming that you have the product object with its id):
const productToUpdate = await productModel.findById(product.id);
await productToUpdate.updateAttributes({ sellcounter: product.sellcounter + 1 });