docparse-dumpinvoices
Version:
takes a list of couchdb invoice ids and exports the data contained within those invoices to an Excel spreadsheet
35 lines (34 loc) • 928 B
JavaScript
var inspect = require('eyespect').inspector();
var getFeed = require('./getFeed.js')
var processStream = require('./processStream')
var rk = require('required-keys')
module.exports = function(data, cb) {
var keys = ['db', 'invoiceIDs','res']
var err = rk.truthySync(data, keys)
if (err) {
data = null
return cb({
message: 'missing key when dumping invoices',
error: err,
stack: new Error().stack
})
}
var invoiceIDs = data.invoiceIDs
if (invoiceIDs.length === 0) {
return cb({
message: 'errro exporting invoices to spreadsheet, no invoiceIDs to exports',
error: 'data.invoiceIDs.length is zero',
stack: new Error().stack
})
}
getFeed(data, function (err, feed) {
if (err) { return cb(err) }
var res = data.res
data = null
processStream(feed, res, function (err) {
res = null
if (err) { return cb(err) }
cb()
})
})
}