UNPKG

@trusthab/composable-resources

Version:

migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable

81 lines (77 loc) 2.15 kB
const _ = require('lodash'); module.exports = App => ({ locations_second_tier_children: { insertion_path: 'query.bool.must', // to be used when areas are added to search callback: id => App.Areas.send('get', [`/areas/?filter_parent=${id}`]) .then(result => result.content.map(item => item.id)) .then(ids => App.Areas.send('get', [`/areas/?filter_parent=${ids.join(',')}`])) .then(areas => (!areas.content.length ? [{ bool: { should: [ { term: { 'additional_properties.root_location_id.value.keyword': id } }, { term: { 'additional_properties.location_id.value.keyword': id } } ] } }] : [{ bool: { should: areas.content.map(item => ({ term: { 'additional_properties.root_location_id.value.keyword': item.id } })).concat(areas.content.map(item => ({ term: { 'additional_properties.location_id.value.keyword': item.id } })) ) } }])) }, location_id_and_children: { insertion_path: 'query.bool.must', callback: id => Promise.resolve([{ bool: { should: [ { term: { 'additional_properties.location_id.value.keyword': id } }, { term: { 'additional_properties.parent_location_id.value.keyword': id } }, { term: { 'additional_properties.root_location_id.value.keyword': id } } ] } }]) }, allowed_by_personas: { insertion_path: 'query.bool.must', callback: persona => Promise.resolve(persona) .then(persona => ([{ bool: { should: [{ term: { 'additional_properties.personas.values.value.keyword': persona } }] } }])) } });