fix(backend): Add the lower cap of the user credits to zero (#8682)

fix(backend): Add lower cap of the user credits to zero
This commit is contained in:
Zamil Majdy
2024-11-18 17:12:42 +04:00
committed by GitHub
parent f36d95aaa8
commit 6fa4b8cb11

View File

@@ -124,7 +124,8 @@ def execute_graph_block(block_id: str, data: BlockInput) -> CompletedBlockOutput
async def get_user_credits(
user_id: Annotated[str, Depends(get_user_id)]
) -> dict[str, int]:
return {"credits": await _user_credit_model.get_or_refill_credit(user_id)}
# Credits can go negative, so ensure it's at least 0 for user to see.
return {"credits": max(await _user_credit_model.get_or_refill_credit(user_id), 0)}
########################################################