UNPKG

docparse-supplier-nge

Version:

process ngrid electric utility bill data for use in the docparse system

60 lines (55 loc) 1.46 kB
/** * @param {String} text holds the supply text section of the bill */ var async = require('async'); var rk = require('required-keys'); module.exports = function(data, callback) { var keys = ['text']; var err = rk.truthySync(data, keys); if (err) { return callback(err); } var text = data.text.replace(/,/g, ''); var getCostOther = data.getCostOther; if (!getCostOther) { getCostOther = require('./otherCosts/getCostOther'); } var getUse = data.getUse; if (!getUse) { getUse = require('./getUse'); } var getCostDelivery = data.getCostDelivery; if (!getCostDelivery) { getCostDelivery = require('./getCostDelivery'); } // test if on competitive supply var output = {}; async.series([ // get cost supply function (cb) { getCostDelivery(text, function (err, reply) { if (err) { return cb(err); } output.costDelivery = reply; cb(); }); }, function (cb) { getUse(text, function (err, reply) { if (err) { return cb(err); } output.use = reply; cb(); }); }, function (cb) { getCostOther(text, function (err, reply) { if (err) { return cb(err); } output.costOther = reply; cb(); }); } // function confirm_cost_other_supply(cb) { // check_cost_other_supply(output, cb); // } ], function (err) { if (err) { return callback(err); } callback(null, output); }); };