feat: update product quantity when invoice paid

This commit is contained in:
Vlad Stan 2023-03-16 11:59:38 +02:00
parent 3794eac915
commit b7dfa22026
3 changed files with 70 additions and 10 deletions

14
crud.py
View file

@ -287,6 +287,20 @@ async def update_product(merchant_id: str, product: Product) -> Product:
return updated_product
async def update_product_quantity(
product_id: str, new_quantity: int
) -> Optional[Product]:
await db.execute(
f"UPDATE nostrmarket.products SET quantity = ? WHERE id = ?",
(new_quantity, product_id),
)
row = await db.fetchone(
"SELECT * FROM nostrmarket.products WHERE id = ?",
(product_id,),
)
return Product.from_row(row) if row else None
async def get_product(merchant_id: str, product_id: str) -> Optional[Product]:
row = await db.fetchone(
"SELECT * FROM nostrmarket.products WHERE merchant_id =? AND id = ?",