-
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.
[feature] Entities Wikidata id filter (#406)
* added patch endpoint to collectable items * small change to make it redeploy * added wikidata id filter
- Loading branch information
Showing
9 changed files
with
327 additions
and
231 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,30 @@ | ||
import { Filter } from 'impresso-jscommons' | ||
import { Op } from 'sequelize' | ||
|
||
interface FilterTuple { | ||
solrFilters: Filter[] | ||
sequelizeFilters: Filter[] | ||
} | ||
|
||
export const sortFindEntitiesFilters = (filters: Filter[]): FilterTuple => { | ||
const solrFilters = filters.filter(f => f.type !== 'wikidataId') | ||
const sequelizeFilters = filters.filter(f => f.type === 'wikidataId') | ||
return { solrFilters, sequelizeFilters } | ||
} | ||
|
||
export const buildSequelizeWikidataIdFindEntitiesCondition = (filters: Filter[]): Record<string, any> | undefined => { | ||
const supportedFilters = filters.filter(f => f.type === 'wikidataId' && f.q != null) | ||
|
||
const items = supportedFilters.map(f => { | ||
const operator = f.context === 'exclude' ? Op.notIn : Op.in | ||
return { | ||
[operator]: typeof f.q === 'string' ? [f.q] : f.q, | ||
} | ||
}) | ||
|
||
if (items.length === 0) { | ||
return undefined | ||
} | ||
|
||
return { wikidataId: { [Op.and]: items } } | ||
} |
Oops, something went wrong.