diff --git a/sanitiser/_id.js b/sanitiser/_id.js index d2fee937..6620a280 100644 --- a/sanitiser/_id.js +++ b/sanitiser/_id.js @@ -4,21 +4,22 @@ function sanitize( req ){ - req.clean = req.clean || {}; - var params= req.query; + req.clean = req.clean || {}; + var params = req.query; + var indeces = require('../query/indeces'); // ensure params is a valid object if( Object.prototype.toString.call( params ) !== '[object Object]' ){ params = {}; } - var errormessage = function(fieldname) { + var errormessage = function(fieldname, message) { return { 'error': true, - 'message': 'invalid param \''+ fieldname + '\': text length, must be >0' + 'message': message || ('invalid param \''+ fieldname + '\': text length, must be >0') } }; - + // id text if('string' !== typeof params.id || !params.id.length){ return errormessage('id'); @@ -31,6 +32,12 @@ function sanitize( req ){ } req.clean.type = params.type; + // type text must be one of the indeces + if(indeces.indexOf(params.type) == -1){ + return errormessage('type', 'type must be one of these values - [' + indeces.join(", ") + ']'); + } + req.clean.type = params.type; + return { 'error': false }; }