middleware/mw.tasks.js
function isTaskHandled(request, reply) {
        var taskName = request.query.task;

        // if no task or task handler, don't do anything
        if (!taskName && !taskHandlers[taskName]) { return false; }

        // if task info doesn't have service or method, don't do anything
        var taskInfo = taskHandlers[taskName];
        if (!taskInfo || !taskInfo.service || !taskInfo.method || !taskInfo.service[taskInfo.method]) {
            return false;
        }

        // if user is not logged in redirect to login then back to here
        if (!request.caller || !request.caller.user) {
            var currentUrl = request.url.pathname;
            var loginUrl = currentUrl + '?modal=auth&submodal=login&redirect=' + currentUrl;
            reply().redirect(loginUrl);
            return true;
        }

        // start collecting the service request
        var serviceReq = { caller: request.caller };

        // get the values from the request object to put into the service request
        _.each(taskInfo.params, function (param) {
            if (request.query[param]) {
                serviceReq[param] = request.query[param];
            }
        });

        // call the service method
        taskInfo.service[taskInfo.method](serviceReq)
            .then(function () {
                reply().redirect(request.path + '?notify=' + taskInfo.notifySuccess);
            })
            .catch(function (err) {
                log.error(err);
                reply().redirect(request.path + '?notify=' + taskInfo.notifyFailure);
            });

        return true;
    }
function isTaskHandled(request, reply) {
        var taskName = request.query.task;

        // if no task or task handler, don't do anything
        if (!taskName && !taskHandlers[taskName]) { return false; }

        // if task info doesn't have service or method, don't do anything
        var taskInfo = taskHandlers[taskName];
        if (!taskInfo || !taskInfo.service || !taskInfo.method || !taskInfo.service[taskInfo.method]) {
            return false;
        }

        // if user is not logged in redirect to login then back to here
        if (!request.caller || !request.caller.user) {
            var currentUrl = request.url.pathname;
            var loginUrl = currentUrl + '?modal=auth&submodal=login&redirect=' + currentUrl;
            reply().redirect(loginUrl);
            return true;
        }

        // start collecting the service request
        var serviceReq = { caller: request.caller };

        // get the values from the request object to put into the service request
        _.each(taskInfo.params, function (param) {
            if (request.query[param]) {
                serviceReq[param] = request.query[param];
            }
        });

        // call the service method
        taskInfo.service[taskInfo.method](serviceReq)
            .then(function () {
                reply().redirect(request.path + '?notify=' + taskInfo.notifySuccess);
            })
            .catch(function (err) {
                log.error(err);
                reply().redirect(request.path + '?notify=' + taskInfo.notifyFailure);
            });

        return true;
    }
function isTaskHandled ( request , reply ) { var taskName = request . query . task ; // if no task or task handler, don't do anything if ( ! taskName && ! taskHandlers [ taskName ] ) { return false ; } // if task info doesn't have service or method, don't do anything var taskInfo = taskHandlers [ taskName ] ; if ( ! taskInfo || ! taskInfo . service || ! taskInfo . method || ! taskInfo . service [ taskInfo . method ] ) { return false ; } // if user is not logged in redirect to login then back to here if ( ! request . caller || ! request . caller . user ) { var currentUrl = request . url . pathname ; var loginUrl = currentUrl + '?modal=auth&submodal=login&redirect=' + currentUrl ; reply ( ) . redirect ( loginUrl ) ; return true ; } // start collecting the service request var serviceReq = { caller : request . caller } ; // get the values from the request object to put into the service request _ . each ( taskInfo . params , function ( param ) { if ( request . query [ param ] ) { serviceReq [ param ] = request . query [ param ] ; } } ) ; // call the service method taskInfo . service [ taskInfo . method ] ( serviceReq ) . then ( function ( ) { reply ( ) . redirect ( request . path + '?notify=' + taskInfo . notifySuccess ) ; } ) . catch ( function ( err ) { log . error ( err ) ; reply ( ) . redirect ( request . path + '?notify=' + taskInfo . notifyFailure ) ; } ) ; return true ; }
Handle one particular task
@param request
@param reply
Handle one particular task