Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make OR clause for transfers with same from/to #40

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export async function makeUsageQuery(ctx: Context, endpoint: UsageEndpoints, use
page = 1;

let filters = "";
for (const k of Object.keys(query_params).filter(k => k !== "limit")) // Don't add limit to WHERE clause
filters += ` (${k} == {${k}: String}) AND`;
for (const k of Object.keys(query_params).filter(k => k !== "limit")) // Don't add `limit` to WHERE clause
filters += ` (${k} = {${k}: String}) AND`;
filters = filters.substring(0, filters.lastIndexOf(' ')); // Remove last item ` AND`

if (filters.length)
Expand Down Expand Up @@ -48,6 +48,13 @@ export async function makeUsageQuery(ctx: Context, endpoint: UsageEndpoints, use

const q = query_params as ValidUserParams<typeof endpoint>;
if (q.from) {
// Find all incoming and outgoing transfers from single account
if (q.to && q.to === q.from)
filters = filters.replace(
"(from = {from: String}) AND (to = {to: String})",
"((from = {from: String}) OR (to = {to: String}))",
)

query += `transfers_from`;
} else if (q.to) {
query += `transfers_to`;
Expand Down
Loading