lib/api/formtools/list.js
function renderSearchFilters(req, fieldNames, data, modelName, cb) {

    if (!req) {
        throw new Error('req is required.');
    }

    if (!Array.isArray(fieldNames) || !fieldNames.length) {
        throw new Error('fieldNames is required and must be of type Array and cannot be empty.');
    }

    if (typeof modelName !== 'string' || !modelName.length) {
        throw new Error('modelName is required and must be of type String and cannot be empty.');
    }

    if (!(!Object.is(data, null) && !Array.isArray(data) && data === Object(data))) {
        throw new Error('data is required and must be of type Object.');
    }

    // Sort fieldNames (to make MongoDB queries more predictable, and therefore easier to create indexes for), remove duplicates, and remove anything that doesn't have associated data.
    fieldNames = dedupe(fieldNames.sort().filter(fieldName => Object.keys(data).indexOf(fieldName) >= 0));

    linz.api.model.list(req, modelName, function (err, list) {

        if (err) {
            return cb(err);
        }

        if (!Object.keys(list.filters).length) {
            return cb(null);
        }

        var model = linz.api.model.get(modelName),
            dataKeys = Object.keys(data),
            filters = {};

        async.each(fieldNames, function (fieldName, filtersDone) {

            if (!dataKeys.includes(fieldName)) {
                return filtersDone(null);
            }

            // call the filter renderer and update the content with the result
            list.filters[fieldName].filter.filter(fieldName, data, function (filterErr, result) {

                if (filterErr) {
                    return filtersDone(filterErr);
                }

                filters = model.addSearchFilter(filters, result);

                return filtersDone(null);

            });

        }, function (filterErr) {

            if (filterErr) {
                return cb(filterErr);
            }

            // consolidate filters into query
            filters = model.setFiltersAsQuery(filters);

            return cb(filterErr, filters);
        });

    });

}
function renderSearchFilters(req, fieldNames, data, modelName, cb) {

    if (!req) {
        throw new Error('req is required.');
    }

    if (!Array.isArray(fieldNames) || !fieldNames.length) {
        throw new Error('fieldNames is required and must be of type Array and cannot be empty.');
    }

    if (typeof modelName !== 'string' || !modelName.length) {
        throw new Error('modelName is required and must be of type String and cannot be empty.');
    }

    if (!(!Object.is(data, null) && !Array.isArray(data) && data === Object(data))) {
        throw new Error('data is required and must be of type Object.');
    }

    // Sort fieldNames (to make MongoDB queries more predictable, and therefore easier to create indexes for), remove duplicates, and remove anything that doesn't have associated data.
    fieldNames = dedupe(fieldNames.sort().filter(fieldName => Object.keys(data).indexOf(fieldName) >= 0));

    linz.api.model.list(req, modelName, function (err, list) {

        if (err) {
            return cb(err);
        }

        if (!Object.keys(list.filters).length) {
            return cb(null);
        }

        var model = linz.api.model.get(modelName),
            dataKeys = Object.keys(data),
            filters = {};

        async.each(fieldNames, function (fieldName, filtersDone) {

            if (!dataKeys.includes(fieldName)) {
                return filtersDone(null);
            }

            // call the filter renderer and update the content with the result
            list.filters[fieldName].filter.filter(fieldName, data, function (filterErr, result) {

                if (filterErr) {
                    return filtersDone(filterErr);
                }

                filters = model.addSearchFilter(filters, result);

                return filtersDone(null);

            });

        }, function (filterErr) {

            if (filterErr) {
                return cb(filterErr);
            }

            // consolidate filters into query
            filters = model.setFiltersAsQuery(filters);

            return cb(filterErr, filters);
        });

    });

}
function renderSearchFilters ( req , fieldNames , data , modelName , cb ) { if ( ! req ) { throw new Error ( 'req is required.' ) ; } if ( ! Array . isArray ( fieldNames ) || ! fieldNames . length ) { throw new Error ( 'fieldNames is required and must be of type Array and cannot be empty.' ) ; } if ( typeof modelName !== 'string' || ! modelName . length ) { throw new Error ( 'modelName is required and must be of type String and cannot be empty.' ) ; } if ( ! ( ! Object . is ( data , null ) && ! Array . isArray ( data ) && data === Object ( data ) ) ) { throw new Error ( 'data is required and must be of type Object.' ) ; } // Sort fieldNames (to make MongoDB queries more predictable, and therefore easier to create indexes for), remove duplicates, and remove anything that doesn't have associated data. fieldNames = dedupe ( fieldNames . sort ( ) . filter ( fieldName => Object . keys ( data ) . indexOf ( fieldName ) >= 0 ) ) ; linz . api . model . list ( req , modelName , function ( err , list ) { if ( err ) { return cb ( err ) ; } if ( ! Object . keys ( list . filters ) . length ) { return cb ( null ) ; } var model = linz . api . model . get ( modelName ) , dataKeys = Object . keys ( data ) , filters = { } ; async . each ( fieldNames , function ( fieldName , filtersDone ) { if ( ! dataKeys . includes ( fieldName ) ) { return filtersDone ( null ) ; } // call the filter renderer and update the content with the result list . filters [ fieldName ] . filter . filter ( fieldName , data , function ( filterErr , result ) { if ( filterErr ) { return filtersDone ( filterErr ) ; } filters = model . addSearchFilter ( filters , result ) ; return filtersDone ( null ) ; } ) ; } , function ( filterErr ) { if ( filterErr ) { return cb ( filterErr ) ; } // consolidate filters into query filters = model . setFiltersAsQuery ( filters ) ; return cb ( filterErr , filters ) ; } ) ; } ) ; }
Get search filters as a mongodb query
@param {Array}   fieldNames Field names
@param {Object}   data       Form data
@param {String}   modelName  Name of model
@param {Function} cb         Callback function
@return {Object} or undefined
@api public
Get search filters as a mongodb query