UNPKG

@trusthab/composable-resources

Version:

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

47 lines (38 loc) 1.59 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(result => result.content.map(item => item.id)) .then(ids => (ids.length ? `filter__id=${ids.join(',')}` : `filter__id=${id}`)) }, buildings: { // insertion_path: 'query.bool.must', // to be used when areas are added to search callback: id => App.Areas.send('get', [`/areas/${id}`]) .then((result) => { const type = _.get(result, 'additional_properties.type.value', 'property'); if (type === 'property') { return 'additional_properties.parent_location_id.value'; } return '_id'; }) .then(property => `filter_${property}=${id}`) }, location_id_and_children: { // insertion_path: 'query.bool.must', // to be used when areas are added to search callback: id => App.Areas.send('get', [`/areas/${id}`]) .then((result) => { const type = _.get(result, 'additional_properties.type.value', 'property'); if (type === 'property') { return 'additional_properties.root_location_id.value'; } if (type === 'building') { return 'parent'; } return '_id'; }) .then(property => `filter_${property}=${id}`) } });