| 71 | |
| 72 | // decrement item quantity by 1 |
| 73 | const decreaseItemQuantityDb = async ({ cart_id, product_id }) => { |
| 74 | await pool.query( |
| 75 | "update cart_item set quantity = quantity - 1 where cart_item.cart_id = $1 AND cart_item.product_id = $2 returning *", |
| 76 | [cart_id, product_id] |
| 77 | ); |
| 78 | |
| 79 | const results = await pool.query( |
| 80 | "Select products.*, cart_item.quantity, round((products.price * cart_item.quantity)::numeric, 2) as subtotal from cart_item join products on cart_item.product_id = products.product_id where cart_item.cart_id = $1", |
| 81 | [cart_id] |
| 82 | ); |
| 83 | return results.rows; |
| 84 | }; |
| 85 | |
| 86 | const emptyCartDb = async (cartId) => { |
| 87 | return await pool.query("delete from cart_item where cart_id = $1", [cartId]); |