lib/routesHandler/lib/preconditionsCheck.js
function (req, controller) {
        var parameters = [];
        if (controller.conditions && controller.conditions.parameters && controller.conditions.parameters.header) {
            parameters.push(_checkValues(req.headers, controller.conditions.parameters.header, "header"))
        }

        if (controller.conditions && controller.conditions.parameters && controller.conditions.parameters.query) {
            parameters.push(_checkValues(req.query, controller.conditions.parameters.query, "query"))
        }

        if (controller.conditions && controller.conditions.parameters && controller.conditions.parameters.body) {
            parameters.push(_checkValues(req.body, controller.conditions.parameters.body, "body"))
        }

        if (controller.conditions && controller.conditions.parameters && controller.conditions.parameters.path) {
            parameters.push(_checkValues(req.params, controller.conditions.parameters.path, "path"))
        }

        return Q.all(parameters).then(function (results) {
            var validatedData = [];
            var errors = [];
            results.forEach(function (result) {
                if (result.data) {
                    if (!validatedData[result.type]) {
                        validatedData[result.type] = {};
                    }
                    validatedData[result.type] = result.data;
                }

                // Collect validation errors
                if (result.err && result.err.err && result.err.name == "ValidationError") {
                    var resultErrors = result.err.err;
                    resultErrors.forEach(function (error) {
                        error.in = result.type;
                        errors.push(error);
                    });
                }
            });

            return Q({
                validatedData: {
                    name: controller.name,
                    version: controller.version,
                    method: controller.method,
                    function: controller.function,
                    data: validatedData
                },
                errors: errors
            });
        });
    }
function (req, controller) {
        var parameters = [];
        if (controller.conditions && controller.conditions.parameters && controller.conditions.parameters.header) {
            parameters.push(_checkValues(req.headers, controller.conditions.parameters.header, "header"))
        }

        if (controller.conditions && controller.conditions.parameters && controller.conditions.parameters.query) {
            parameters.push(_checkValues(req.query, controller.conditions.parameters.query, "query"))
        }

        if (controller.conditions && controller.conditions.parameters && controller.conditions.parameters.body) {
            parameters.push(_checkValues(req.body, controller.conditions.parameters.body, "body"))
        }

        if (controller.conditions && controller.conditions.parameters && controller.conditions.parameters.path) {
            parameters.push(_checkValues(req.params, controller.conditions.parameters.path, "path"))
        }

        return Q.all(parameters).then(function (results) {
            var validatedData = [];
            var errors = [];
            results.forEach(function (result) {
                if (result.data) {
                    if (!validatedData[result.type]) {
                        validatedData[result.type] = {};
                    }
                    validatedData[result.type] = result.data;
                }

                // Collect validation errors
                if (result.err && result.err.err && result.err.name == "ValidationError") {
                    var resultErrors = result.err.err;
                    resultErrors.forEach(function (error) {
                        error.in = result.type;
                        errors.push(error);
                    });
                }
            });

            return Q({
                validatedData: {
                    name: controller.name,
                    version: controller.version,
                    method: controller.method,
                    function: controller.function,
                    data: validatedData
                },
                errors: errors
            });
        });
    }
function ( req , controller ) { var parameters = [ ] ; if ( controller . conditions && controller . conditions . parameters && controller . conditions . parameters . header ) { parameters . push ( _checkValues ( req . headers , controller . conditions . parameters . header , "header" ) ) } if ( controller . conditions && controller . conditions . parameters && controller . conditions . parameters . query ) { parameters . push ( _checkValues ( req . query , controller . conditions . parameters . query , "query" ) ) } if ( controller . conditions && controller . conditions . parameters && controller . conditions . parameters . body ) { parameters . push ( _checkValues ( req . body , controller . conditions . parameters . body , "body" ) ) } if ( controller . conditions && controller . conditions . parameters && controller . conditions . parameters . path ) { parameters . push ( _checkValues ( req . params , controller . conditions . parameters . path , "path" ) ) } return Q . all ( parameters ) . then ( function ( results ) { var validatedData = [ ] ; var errors = [ ] ; results . forEach ( function ( result ) { if ( result . data ) { if ( ! validatedData [ result . type ] ) { validatedData [ result . type ] = { } ; } validatedData [ result . type ] = result . data ; } // Collect validation errors if ( result . err && result . err . err && result . err . name == "ValidationError" ) { var resultErrors = result . err . err ; resultErrors . forEach ( function ( error ) { error . in = result . type ; errors . push ( error ) ; } ) ; } } ) ; return Q ( { validatedData : { name : controller . name , version : controller . version , method : controller . method , function : controller . function , data : validatedData } , errors : errors } ) ; } ) ; }
Parse parameter model of controller and validate all request parameters for header,query and body
@param req
@param controller
@returns {*}
@private
Parse parameter model of controller and validate all request parameters for header query and body