timelineMgr.js

/**
 * Created by WORKER on 1-09-2015.
 */
var async = require("async");
var financeQuery = require('../components/finance/financeQueryHelper');

/**
 * Build timeline data from different modules.
 * Updates the response based on resulting data.
 * @param  {Object} options Input parameters
 */
function buildTimeline(options) {
    var result = {};
    var asyncTasks = [];
    asyncTasks.push(function(_callback){
        options._callback = _callback;
        financeQuery(options, result);
    });
    async.parallel(asyncTasks, function(){
        console.log(result);
        var financeResultSet = {
            spent: result['SPNT'],
            received: result['RCVD'],
            borrowed: result['BRWD'],
            lent: result['LENT'],
            remaining: (result['RCVD'] - (result['SPNT']+result['BRWD']+result['LENT']))
        }
        var timeline = {
            finance: financeResultSet
        }
        options.res.json(timeline);
    });
}
module.exports = buildTimeline;