-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: add lat, lon to planter registration model * feat: add country to registrations route * fix: add filter support to planter registration * fix: abstract buildFilterQuery * fix: remove redundant filter
- Loading branch information
1 parent
46583de
commit 22a2900
Showing
4 changed files
with
158 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ParameterizedSQL } from 'loopback-connector'; | ||
|
||
export function getConnector(repo) { | ||
return repo?.dataSource?.connector; | ||
} | ||
|
||
export function buildFilterQuery(sql, params) { | ||
let query = new ParameterizedSQL(sql); | ||
|
||
if (params.filter) { | ||
const connector = getConnector(params.repo); | ||
if (connector) { | ||
const model = connector._models[params.model].model; | ||
|
||
if (model) { | ||
let safeWhere = model._sanitizeQuery(params.filter); | ||
safeWhere = model._coerce(safeWhere); | ||
|
||
const whereObjClause = connector._buildWhere(params.model, safeWhere); | ||
|
||
if (whereObjClause.sql) { | ||
const hasWhere = /WHERE(?![^(]*\))/i.test(sql); | ||
query.sql += ` ${hasWhere ? 'AND' : 'WHERE'} ${whereObjClause.sql}`; | ||
query.params = whereObjClause.params; | ||
} | ||
|
||
query = connector.parameterize(query); | ||
} | ||
} | ||
} | ||
|
||
return query; | ||
} |
Oops, something went wrong.