mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-24 14:51:05 +01:00
fix validation check for existing card UID, was preventing all edits of cards. we should validate a bit differently for updates vs. creates
This commit is contained in:
parent
a6cf19c29d
commit
993511bcd4
1 changed files with 12 additions and 6 deletions
|
@ -73,12 +73,6 @@ async def api_card_create_or_update(
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
detail="Invalid byte data provided.", status_code=HTTPStatus.BAD_REQUEST
|
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:
|
if card_id:
|
||||||
card = await get_card(card_id)
|
card = await get_card(card_id)
|
||||||
if not card:
|
if not card:
|
||||||
|
@ -89,8 +83,20 @@ async def api_card_create_or_update(
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
detail="Not your card.", status_code=HTTPStatus.FORBIDDEN
|
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())
|
card = await update_card(card_id, **data.dict())
|
||||||
else:
|
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)
|
card = await create_card(wallet_id=wallet.wallet.id, data=data)
|
||||||
return card.dict()
|
return card.dict()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue