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