diff --git a/wh.order.import.cached.js b/wh.order.import.cached.js index 345412c..c6e4064 100644 --- a/wh.order.import.cached.js +++ b/wh.order.import.cached.js @@ -16,7 +16,7 @@ try { var path = require('path'); var Promise = require('bluebird'); var _ = require('underscore'); - + var vendSdk = require('vend-nodejs-sdk')({}); // Global variable for logging var commandName = path.basename(__filename, '.js'); // gives the filename without the .js extension @@ -228,7 +228,7 @@ try { for (var i=0; i i; i += 1) { + if (failedItems[i] === sku) { + return true; + } + } + return false; + }; + + return Promise.map(lineitems, + function(lineitem) { + if (failedFromCache(lineitem.sku, itemsFailedFromIronCache)) { + + return vendSdk.products.fetchBySku({sku: {value: lineitem.sku}}, connectionInfo) + .then(function (response) { + var product = response.products[0]; + var neoProduct = _.pick(product,'name','supply_price','id','sku','type'); + neoProduct.inventory = _.find(product.inventory, function(inv){ + return inv.outlet_id === params.outletId; + }); + + lineitem.productId = neoProduct.id; + lineitem.name = neoProduct.name; + lineitem.quantityOnHand = Number(neoProduct.inventory.count); + lineitem.desiredStockLevel = Number(neoProduct.inventory['reorder_point']); + lineitem.fulfilledQuantity = lineitem.orderQuantity; + lineitem.type = neoProduct.type; + if (lineitem.type) { // warehouse folks can choose to box those lacking department/product-type, manually + lineitem.state = BOXED; // boxed by default + lineitem.boxNumber = 1; // boxed together by default + } + console.log(lineitem); + return Promise.resolve(); + }); + } + }, + {concurrency:1} + ) + .then(function(){ + console.log('cross-referenced and filled out lineitems against data from IronCache'); + console.log('will send update(s) to loopback'); + return client.models.ReportModel.updateRowsAsync(params.reportId, lineitems); + }); + }) }); }, {concurrency: 1} @@ -332,4 +377,4 @@ catch (e) { console.error('last catch block'); console.error(e); process.exit(FAILURE); -} \ No newline at end of file +}