You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
async def api_card_update(
data: CreateCardData,
card_id: str,
wallet: WalletTypeInfo = Depends(require_admin_key),
) -> Card:
existing_card = await get_card(card_id)
if not existing_card:
raise HTTPException(detail="Card does not exist.", status_code=404)
if existing_card.wallet != wallet.wallet.id:
raise HTTPException(detail="Not your card.", status_code=403)
# Allowed fields to update
allowed_fields = {"card_name", "daily_limit", "tx_limit", "counter"}
existing_data = existing_card.dict()
incoming_data = data.dict(exclude_unset=True)
filtered_updates = {f: v for f, v in incoming_data.items() if f in allowed_fields}
updated_data = {**existing_data, **filtered_updates}
# new_data now includes all fields that Card requires
new_data = CreateCardData(**updated_data)
updated_card = await update_card(card_id, new_data)
assert updated_card, "update_card should always return a card"
return updated_card
crud.py
async def update_card(card_id: str, data: CreateCardData) -> Card:
# Fetch the existing card
existing_card = await get_card(card_id)
if not existing_card:
raise HTTPException(status_code=404, detail="Card not found")
# Convert existing card to dict to preserve all fields including wallet, external_id, otp, time
card_dict = existing_card.dict()
# Extract updates from data (only the fields you want to allow updating)
allowed_fields = {"card_name", "daily_limit", "tx_limit", "counter"}
updates = data.dict(exclude_unset=True)
for field in allowed_fields:
if field in updates:
card_dict[field] = updates[field]
# Rebuild a new Card object with unchanged fields preserved
card = Card(**card_dict)
# Now perform the update in the database
await db.update("boltcards.cards", card)
return card
boltcards/views_api.py
Line 88 in 8fe5beb
Testing LNbits 1.0.0 and having trouble updating cards. Leaving this here to look into further
The text was updated successfully, but these errors were encountered: