feat: show DMs for customers

This commit is contained in:
Vlad Stan 2023-03-16 18:34:56 +02:00
parent 482961a2ef
commit b45927a15d
4 changed files with 78 additions and 12 deletions

View file

@ -39,6 +39,8 @@ from .crud import (
get_orders_for_stall,
get_product,
get_products,
get_public_keys_for_direct_messages,
get_public_keys_for_orders,
get_stall,
get_stalls,
get_zone,
@ -727,6 +729,35 @@ async def api_create_message(
)
######################################## CUSTOMERS ########################################
@nostrmarket_ext.get("/api/v1/customers")
async def api_create_message(
wallet: WalletTypeInfo = Depends(get_key_type),
) -> DirectMessage:
try:
merchant = await get_merchant_for_user(wallet.wallet.user)
assert merchant, f"Merchant cannot be found"
dm_pubkeys = await get_public_keys_for_direct_messages(merchant.id)
orders_pubkeys = await get_public_keys_for_orders(merchant.id)
return list(dict.fromkeys(dm_pubkeys + orders_pubkeys))
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 create message",
)
######################################## OTHER ########################################