This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix invalid db filter on transactions api
- Loading branch information
1 parent
ff42326
commit 043d0b6
Showing
10 changed files
with
100 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import knex from 'knex' | ||
import { TABLE, Where } from './types.js' | ||
|
||
// reduces the where condition on a knex query. Gracefully handles undefined values in WhereMatch objects | ||
export const reduceWhere = <M extends TABLE>( | ||
query: knex.Knex.QueryBuilder, | ||
where?: Where<M> | ||
): knex.Knex.QueryBuilder => { | ||
if (where) { | ||
if (!Array.isArray(where)) { | ||
where = [where] | ||
} | ||
query = where.reduce((acc, w) => { | ||
if (Array.isArray(w)) { | ||
return acc.where(w[0], w[1], w[2]) | ||
} | ||
return acc.where( | ||
Object.entries(w).reduce( | ||
(acc, [k, v]) => { | ||
if (v !== undefined) acc[k] = v | ||
return acc | ||
}, | ||
{} as Record<string, unknown> | ||
) | ||
) | ||
}, query) | ||
} | ||
return query | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters