im currently developing a shopping cart with the following business logic and need to update the items simultaneously with the latest prices at the time of purchase with the simplest sequelize query posible
Fist the user creates a new item by adding a product to it's cart, with it's asociated productId, userId and quantity
| id | salePrice | quantity | subtotal | status | productId | userId | orderId |
|---|---|---|---|---|---|---|---|
| 1 | null | 5 | null | 0 | 23 | 8 | null |
| 2 | null | 1 | null | 0 | 76 | 8 | null |
| 3 | null | 2 | null | 0 | 193 | 8 | null |
then when the user makes the purchase the item is updated to reflect the current price of the product at the time of purchase with any applying discounts or price changes and the subtotal amount taken from salePrice * quantity
| id | salePrice | quantity | subtotal | status | productId | userId | orderId |
|---|---|---|---|---|---|---|---|
| 1 | 68 | 5 | 340 | 1 | 23 | 8 | 35 |
| 2 | 200 | 1 | 200 | 1 | 76 | 8 | 35 |
| 3 | 500 | 2 | 1000 | 1 | 193 | 8 | 35 |
so the question is how to update the salePrice and subtotal with information from the related product to multiple items simultaneusly using sequelize