MCPcopy Create free account
hub / github.com/dhatGuy/PERN-Store / decreaseItemQuantityDb

Function decreaseItemQuantityDb

server/db/cart.db.js:73–84  ·  view source on GitHub ↗
({ cart_id, product_id })

Source from the content-addressed store, hash-verified

71
72// decrement item quantity by 1
73const 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
86const emptyCartDb = async (cartId) => {
87 return await pool.query("delete from cart_item where cart_id = $1", [cartId]);

Callers 1

CartServiceClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected