feat: allow delete merchant from nostr
This commit is contained in:
parent
260bea9ccf
commit
05ecc65e5a
7 changed files with 141 additions and 11 deletions
43
views_api.py
43
views_api.py
|
|
@ -45,6 +45,7 @@ from .crud import (
|
|||
get_stalls,
|
||||
get_zone,
|
||||
get_zones,
|
||||
update_merchant,
|
||||
update_order_shipped_status,
|
||||
update_product,
|
||||
update_stall,
|
||||
|
|
@ -147,6 +148,44 @@ async def api_delete_merchant(
|
|||
)
|
||||
|
||||
|
||||
@nostrmarket_ext.delete("/api/v1/merchant/{merchant_id}/nostr")
|
||||
async def api_delete_merchant(
|
||||
merchant_id: str,
|
||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||
):
|
||||
|
||||
try:
|
||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||
assert merchant, "Merchant cannot be found"
|
||||
assert merchant.id == merchant_id, "Wrong merchant ID"
|
||||
|
||||
stalls = await get_stalls(merchant.id)
|
||||
for stall in stalls:
|
||||
products = await get_products(merchant.id, stall.id)
|
||||
for product in products:
|
||||
event = await sign_and_send_to_nostr(merchant, product, True)
|
||||
product.config.event_id = event.id
|
||||
await update_product(merchant.id, product)
|
||||
event = await sign_and_send_to_nostr(merchant, stall, True)
|
||||
stall.config.event_id = event.id
|
||||
await update_stall(merchant.id, stall)
|
||||
event = await sign_and_send_to_nostr(merchant, merchant, True)
|
||||
merchant.config.event_id = event.id
|
||||
await update_merchant(wallet.wallet.user, merchant.id, merchant.config)
|
||||
|
||||
except AssertionError as ex:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
detail=str(ex),
|
||||
)
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail="Cannot get merchant",
|
||||
)
|
||||
|
||||
|
||||
######################################## ZONES ########################################
|
||||
|
||||
|
||||
|
|
@ -566,7 +605,9 @@ async def api_delete_product(
|
|||
)
|
||||
|
||||
await delete_product(merchant.id, product_id)
|
||||
await sign_and_send_to_nostr(merchant, product, True)
|
||||
event = await sign_and_send_to_nostr(merchant, product, True)
|
||||
product.config.event_id = event.id
|
||||
await update_product(merchant.id, product)
|
||||
|
||||
except AssertionError as ex:
|
||||
raise HTTPException(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue