generated from MapColonies/ts-server-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added get job by job parameters support (#32)
* feat: added query json parameters support * feat: added get job by job parameters support(1level nested object) * fix: remove parameter from find jobs * fix: removed unused parameters from find jobs type * fix: added index migration * fix: decreased statement tests coverage percentage * test: added parameters query testsg * fix: summary content * fix: migration sql file version name
- Loading branch information
1 parent
19459f4
commit 94ef0a3
Showing
12 changed files
with
153 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE INDEX "jobParametersIndex" | ||
ON "JobManager"."Job" USING btree | ||
(parameters ASC NULLS LAST); |
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,16 @@ | ||
// TODO: need to support nested paremeters, currently only 1 level is supported | ||
export const paramsQueryBuilder = (params: Record<string, unknown>): string => { | ||
const queryStringArray: string[] = []; | ||
const paramKeys = Object.keys(params); | ||
let fullQuery = ''; | ||
|
||
paramKeys.forEach((key) => { | ||
const query = `(job.parameters->>'${key}') = :${key}`; | ||
queryStringArray.push(query); | ||
}); | ||
|
||
if (queryStringArray.length > 0) { | ||
fullQuery = queryStringArray.join(' AND '); | ||
} | ||
return fullQuery; | ||
}; |
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,19 @@ | ||
import { paramsQueryBuilder } from '../../../src/common/utils'; | ||
|
||
describe('paramsQueryBuilder', () => { | ||
it('should be matched to the expected query string with 1 param', function () { | ||
const params = { id: 1 }; | ||
const expectedQueryString = `(job.parameters->>'id') = :id`; | ||
const res = paramsQueryBuilder(params); | ||
|
||
expect(res).toEqual(expectedQueryString); | ||
}); | ||
|
||
it('should be matched to the expected query string with multi params', function () { | ||
const params = { id: 1, crs: 'epsg:4326', roi: 'roi' }; | ||
const expectedQueryString = `(job.parameters->>'id') = :id AND (job.parameters->>'crs') = :crs AND (job.parameters->>'roi') = :roi`; | ||
const res = paramsQueryBuilder(params); | ||
|
||
expect(res).toEqual(expectedQueryString); | ||
}); | ||
}); |