mirror of https://github.com/pelias/api.git
Peter Johnson
10 years ago
1 changed files with 0 additions and 46 deletions
@ -1,46 +0,0 @@
|
||||
|
||||
var check = require('check-types'), |
||||
types = require('../query/types'), |
||||
get_layers = require('../helper/layers'); |
||||
|
||||
// decide which layers can be queried
|
||||
var ALIAS_LAYERS = ['poi', 'admin', 'address'], |
||||
ALIAS_TYPES = types.concat(ALIAS_LAYERS), |
||||
ALIAS_TYPES_JOINED = ALIAS_TYPES.join(','); |
||||
|
||||
// validate inputs, convert types and apply defaults
|
||||
function sanitize( raw, clean ){ |
||||
|
||||
// error & warning messages
|
||||
var messages = { errors: [], warnings: [] }; |
||||
|
||||
// init clean.types
|
||||
clean.types = clean.types || {}; |
||||
|
||||
// default case (no layers specified in GET params)
|
||||
// don't even set the from_layers key in this case
|
||||
if( check.unemptyString( raw.layers ) ){ |
||||
|
||||
// parse GET params
|
||||
var layers = raw.layers.split(',').map( function( layer ){ |
||||
return layer.toLowerCase(); // lowercase inputs
|
||||
}); |
||||
|
||||
// validate layer names
|
||||
for( var x=0; x<layers.length; x++ ){ |
||||
if( -1 === ALIAS_TYPES.indexOf( layers[x] ) ){ |
||||
messages.errors.push('invalid param \'layers\': must be one or more of ' + ALIAS_TYPES_JOINED); |
||||
} |
||||
} |
||||
|
||||
// set 'from_layers' param
|
||||
if( !messages.errors.length ){ |
||||
clean.types.from_layers = get_layers(layers); |
||||
} |
||||
} |
||||
|
||||
return messages; |
||||
} |
||||
|
||||
// export function
|
||||
module.exports = sanitize; |
Loading…
Reference in new issue