mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
966 B
38 lines
966 B
const url = require('url'); |
|
|
|
const _ = require('lodash'); |
|
|
|
const ServiceConfiguration = require('pelias-microservice-wrapper').ServiceConfiguration; |
|
|
|
class Language extends ServiceConfiguration { |
|
constructor(o) { |
|
super('language', o); |
|
} |
|
|
|
getParameters(req, res) { |
|
// find all the values for all keys with names that end with '_id' |
|
const ids = _.get(res, 'data', []).reduce((acc, doc) => { |
|
Array.prototype.push.apply(acc, _.values(_.pickBy(doc.parent, (v, k) => _.endsWith(k, '_id') ) ) ); |
|
return acc; |
|
}, []); |
|
const lang = _.get(req, 'clean.lang.iso6393'); |
|
const parameters = { |
|
// arrays will be nested, so flatten first, then uniqify, and finally join elements with comma |
|
ids: _.uniq(_.flattenDeep(ids)).join(',') |
|
}; |
|
|
|
if (lang) { |
|
parameters.lang = lang; |
|
} |
|
|
|
return parameters; |
|
|
|
} |
|
|
|
getUrl(req) { |
|
return url.resolve(this.baseUrl, 'parser/findbyid'); |
|
} |
|
|
|
} |
|
|
|
module.exports = Language;
|
|
|