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:
Lee Salminen 2022-08-29 09:40:35 -06:00
parent a6cf19c29d
commit 993511bcd4

View file

@ -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()