Browse Source

feat(findbyid): Add lang query param for placeholder

This will reduce network transfer and speedup requests
Related: https://github.com/pelias/placeholder/pull/128
pull/1191/head
Joxit 6 years ago committed by Peter Johnson
parent
commit
7d9e3e29fd
  1. 10
      service/configurations/Language.js
  2. 18
      test/unit/service/configurations/Language.js

10
service/configurations/Language.js

@ -15,12 +15,18 @@ class Language extends ServiceConfiguration {
Array.prototype.push.apply(acc, _.values(_.pickBy(doc.parent, (v, k) => _.endsWith(k, '_id') ) ) );
return acc;
}, []);
return {
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) {

18
test/unit/service/configurations/Language.js

@ -117,6 +117,24 @@ module.exports.tests.all = (test, common) => {
});
test('getParameters should return lang when req.clean.lang.iso6393 is defined', (t) => {
const configBlob = {
url: 'http://localhost:1234',
timeout: 17,
retries: 19
};
const req = {clean: {lang: {iso6393: 'eng' }}};
const res = { };
const language = new Language(configBlob);
t.deepEquals(language.getParameters(req, res), { ids: '', lang: 'eng' });
t.end();
});
test('getHeaders should return empty object', (t) => {
const configBlob = {
url: 'base url',

Loading…
Cancel
Save