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.
34 lines
827 B
34 lines
827 B
10 years ago
|
var isObject = require('is-object');
|
||
|
var query_parser = require('../helper/query_parser');
|
||
10 years ago
|
|
||
9 years ago
|
// validate texts, convert types and apply defaults
|
||
10 years ago
|
function sanitize( req ){
|
||
|
req.clean = req.clean || {};
|
||
|
var params= req.query;
|
||
10 years ago
|
|
||
9 years ago
|
// ensure the text params are a valid object
|
||
10 years ago
|
if( !isObject( params ) ){
|
||
10 years ago
|
params = {};
|
||
|
}
|
||
|
|
||
9 years ago
|
// text text
|
||
|
if('string' !== typeof params.text || !params.text.length){
|
||
10 years ago
|
return {
|
||
10 years ago
|
'error': true,
|
||
9 years ago
|
'message': 'invalid param \'text\': text length, must be >0'
|
||
10 years ago
|
};
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
req.clean.text = params.text;
|
||
10 years ago
|
|
||
9 years ago
|
req.clean.parsed_text = query_parser.get_parsed_address(params.text);
|
||
10 years ago
|
|
||
|
req.clean.types = req.clean.layers || {};
|
||
9 years ago
|
req.clean.types.from_address_parsing = query_parser.get_layers(params.text);
|
||
10 years ago
|
|
||
10 years ago
|
return { 'error': false };
|
||
|
}
|
||
|
|
||
|
// export function
|
||
10 years ago
|
module.exports = sanitize;
|