lib/modelValidator/lib/modelValidator.js
function (values, schema, options) {
    var virtualList = find(schema, 'virtual');

    //Set default value for virtual if not exists in values
    if (options && options.query === true) {
    }
    else {
        for (var virtual in virtualList) {

            if (_.isArray(virtualList[virtual])) {

                for (var thisVirtual in virtualList[virtual]) {

                    if (_.isArray(values[virtual])) {
                        for (var thisValue in values[virtual]) {
                            setVirtuals(values[virtual][thisValue], virtualList[virtual][thisVirtual], options);
                        }
                    }
                }
            }
            else {
                if (values[virtual] === undefined && virtualList[virtual] && virtualList[virtual].hasOwnProperty('default') && options && options.partial !== true) {
                    values[virtual] = (virtualList[virtual]).default;
                }
            }
        }
    }

    for (var value in values) {

        if (virtualList[value] && virtualList[value].virtual) {

            var setFunction = virtualList[value].virtual;

            //Check for setter and getter
            if (virtualList[value].virtual.set) {
                setFunction = virtualList[value].virtual.set;
            }

            //Check conditions and apply virtual
            rulesMatch(value, values[value], setFunction, null, function (err, data) {
                if (!err) {
                    if (_.isFunction(setFunction)) {
                        var virtualResult = setFunction(values[value]);
                        if (_.isObject(virtualResult) && !_.isEmpty(virtualResult)) {
                            //Check if virtual values does not exists in given values list. Do not overwrite given
                            for (var vValue in virtualResult) {
                                {
                                    if (vValue == 'this') {
                                        virtualResult[value] = virtualResult[vValue];
                                        delete(virtualResult[vValue]);
                                    }
                                    else {
                                        // Prevent overwrite of given values
                                        if (values[vValue] !== undefined) {
                                            delete(virtualResult[vValue]);
                                        }
                                    }
                                }
                            }
                            values = _.assign(values, virtualResult);
                        }
                    }
                }
            });
        }
    }
    return values;
}
function (values, schema, options) {
    var virtualList = find(schema, 'virtual');

    //Set default value for virtual if not exists in values
    if (options && options.query === true) {
    }
    else {
        for (var virtual in virtualList) {

            if (_.isArray(virtualList[virtual])) {

                for (var thisVirtual in virtualList[virtual]) {

                    if (_.isArray(values[virtual])) {
                        for (var thisValue in values[virtual]) {
                            setVirtuals(values[virtual][thisValue], virtualList[virtual][thisVirtual], options);
                        }
                    }
                }
            }
            else {
                if (values[virtual] === undefined && virtualList[virtual] && virtualList[virtual].hasOwnProperty('default') && options && options.partial !== true) {
                    values[virtual] = (virtualList[virtual]).default;
                }
            }
        }
    }

    for (var value in values) {

        if (virtualList[value] && virtualList[value].virtual) {

            var setFunction = virtualList[value].virtual;

            //Check for setter and getter
            if (virtualList[value].virtual.set) {
                setFunction = virtualList[value].virtual.set;
            }

            //Check conditions and apply virtual
            rulesMatch(value, values[value], setFunction, null, function (err, data) {
                if (!err) {
                    if (_.isFunction(setFunction)) {
                        var virtualResult = setFunction(values[value]);
                        if (_.isObject(virtualResult) && !_.isEmpty(virtualResult)) {
                            //Check if virtual values does not exists in given values list. Do not overwrite given
                            for (var vValue in virtualResult) {
                                {
                                    if (vValue == 'this') {
                                        virtualResult[value] = virtualResult[vValue];
                                        delete(virtualResult[vValue]);
                                    }
                                    else {
                                        // Prevent overwrite of given values
                                        if (values[vValue] !== undefined) {
                                            delete(virtualResult[vValue]);
                                        }
                                    }
                                }
                            }
                            values = _.assign(values, virtualResult);
                        }
                    }
                }
            });
        }
    }
    return values;
}
function ( values , schema , options ) { var virtualList = find ( schema , 'virtual' ) ; //Set default value for virtual if not exists in values if ( options && options . query === true ) { } else { for ( var virtual in virtualList ) { if ( _ . isArray ( virtualList [ virtual ] ) ) { for ( var thisVirtual in virtualList [ virtual ] ) { if ( _ . isArray ( values [ virtual ] ) ) { for ( var thisValue in values [ virtual ] ) { setVirtuals ( values [ virtual ] [ thisValue ] , virtualList [ virtual ] [ thisVirtual ] , options ) ; } } } } else { if ( values [ virtual ] === undefined && virtualList [ virtual ] && virtualList [ virtual ] . hasOwnProperty ( 'default' ) && options && options . partial !== true ) { values [ virtual ] = ( virtualList [ virtual ] ) . default ; } } } } for ( var value in values ) { if ( virtualList [ value ] && virtualList [ value ] . virtual ) { var setFunction = virtualList [ value ] . virtual ; //Check for setter and getter if ( virtualList [ value ] . virtual . set ) { setFunction = virtualList [ value ] . virtual . set ; } //Check conditions and apply virtual rulesMatch ( value , values [ value ] , setFunction , null , function ( err , data ) { if ( ! err ) { if ( _ . isFunction ( setFunction ) ) { var virtualResult = setFunction ( values [ value ] ) ; if ( _ . isObject ( virtualResult ) && ! _ . isEmpty ( virtualResult ) ) { //Check if virtual values does not exists in given values list. Do not overwrite given for ( var vValue in virtualResult ) { { if ( vValue == 'this' ) { virtualResult [ value ] = virtualResult [ vValue ] ; delete ( virtualResult [ vValue ] ) ; } else { // Prevent overwrite of given values if ( values [ vValue ] !== undefined ) { delete ( virtualResult [ vValue ] ) ; } } } } values = _ . assign ( values , virtualResult ) ; } } } } ) ; } } return values ; }
Apply virtual functions defined in schema
@param values
@param model
@param options
@returns {*}
Apply virtual functions defined in schema