fix: get_payments where clause does query wrong payments including tests (#2844)

* fix: get_payments where clause does query wrong payments (#2841)
This commit is contained in:
dni ⚡
2024-12-19 10:22:37 +01:00
committed by GitHub
parent f17ff3d12b
commit 3a2cf12052
3 changed files with 82 additions and 7 deletions
+16 -5
View File
@@ -123,15 +123,20 @@ async def get_payments_paginated(
clause.append("wallet_id = :wallet_id")
if complete and pending:
pass
clause.append(
f"(status = '{PaymentState.SUCCESS}' OR status = '{PaymentState.PENDING}')"
)
elif complete:
clause.append(
f"((amount > 0 AND status = '{PaymentState.SUCCESS}') OR amount < 0)"
f"""
(
status = '{PaymentState.SUCCESS}'
OR (amount < 0 AND status = '{PaymentState.PENDING}')
)
"""
)
elif pending:
clause.append(f"status = '{PaymentState.PENDING}'")
else:
pass
if outgoing and incoming:
pass
@@ -289,8 +294,14 @@ async def get_payments_history(
values = {
"wallet_id": wallet_id,
}
# count outgoing payments if they are still pending
where = [
f"wallet_id = :wallet_id AND (status = '{PaymentState.SUCCESS}' OR amount < 0)"
f"""
wallet_id = :wallet_id AND (
status = '{PaymentState.SUCCESS}'
OR (amount < 0 AND status = '{PaymentState.PENDING}')
)
"""
]
transactions: list[dict] = await db.fetchall(
f"""
-2
View File
@@ -108,8 +108,6 @@ async def api_payments_paginated(
await update_pending_payments(key_info.wallet.id)
page = await get_payments_paginated(
wallet_id=key_info.wallet.id,
pending=True,
complete=True,
filters=filters,
)
return page