diff --git a/lnbits/extensions/boltcards/views_api.py b/lnbits/extensions/boltcards/views_api.py index 5f057036..7b8357cf 100644 --- a/lnbits/extensions/boltcards/views_api.py +++ b/lnbits/extensions/boltcards/views_api.py @@ -73,12 +73,6 @@ async def api_card_create_or_update( raise HTTPException( detail="Invalid byte data provided.", status_code=HTTPStatus.BAD_REQUEST ) - checkUid = await get_card_by_uid(data.uid) - if checkUid: - raise HTTPException( - detail="UID already registered. Delete registered card and try again.", - status_code=HTTPStatus.BAD_REQUEST, - ) if card_id: card = await get_card(card_id) if not card: @@ -89,8 +83,20 @@ async def api_card_create_or_update( raise HTTPException( detail="Not your card.", status_code=HTTPStatus.FORBIDDEN ) + checkUid = await get_card_by_uid(data.uid) + if checkUid and checkUid.id != card_id: + raise HTTPException( + detail="UID already registered. Delete registered card and try again.", + status_code=HTTPStatus.BAD_REQUEST, + ) card = await update_card(card_id, **data.dict()) else: + checkUid = await get_card_by_uid(data.uid) + if checkUid: + raise HTTPException( + detail="UID already registered. Delete registered card and try again.", + status_code=HTTPStatus.BAD_REQUEST, + ) card = await create_card(wallet_id=wallet.wallet.id, data=data) return card.dict()