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
698 B
38 lines
698 B
var logger = require('pelias-logger').get('api'); |
|
|
|
/** |
|
* Parses the bounding box property in docs, if one is found |
|
*/ |
|
|
|
function setup() { |
|
return function (req, res, next) { |
|
// do nothing if no result data set |
|
if (!res || !res.data) { |
|
return next(); |
|
} |
|
|
|
res.data = res.data.map(parseBBox); |
|
|
|
next(); |
|
}; |
|
} |
|
|
|
/* |
|
* Parse the bbox property and form an object |
|
*/ |
|
function parseBBox(place) { |
|
|
|
if (place && place.bounding_box) { |
|
try { |
|
place.bounding_box = JSON.parse(place.bounding_box); |
|
} |
|
catch (err) { |
|
logger.error('Invalid bounding_box json string:', place); |
|
delete place.bounding_box; |
|
} |
|
} |
|
|
|
return place; |
|
} |
|
|
|
module.exports = setup;
|
|
|