diff --git a/bin/environment/wsCreateStuff.js b/bin/environment/wsCreateStuff.js index f22a8ef3..7185f94a 100644 --- a/bin/environment/wsCreateStuff.js +++ b/bin/environment/wsCreateStuff.js @@ -1,7 +1,7 @@ /** * Experimental tool to create some products and batches using api services. * Uses some files common to the setup.js utility, - * #66 + * #66, #119 * * Onde node <= v14 we recommend that you run this script with option * --unhandled-rejections=strict @@ -49,7 +49,7 @@ const WSH1 = require("../../docker/api/env/whs-1.json"); const WSH2 = require("../../docker/api/env/whs-2.json"); const PHA1 = require("../../docker/api/env/pha-1.json"); const PHA2 = require("../../docker/api/env/pha-2.json"); -const SHIPMENTS_ON_PHA = []; +const SHIPMENTS_ON_PHA = []; // records all shipments sent to a PHA, so that they can be sold. const NUM_SALES = 2; // number of sales to perform - for now consume serialNumbers from 1st MSD batch const MY_SALES = []; // array of data returned by /sale/create @@ -607,40 +607,45 @@ const shipmentsCreateTestDfm = async function (conf, sender) { const whs = WSH1; const pha = PHA1; - - const gtin1 = sender.products[0].gtin; - const batch1 = sender.batches[gtin1][0]; - const batchNumber1 = batch1.batchNumber; - const quantity1 = batch1.quantity; - const shipment1MahToWhs = { - "orderId": whs.id.secret + "-" + (new Date()).toISOString(), - "requesterId": whs.id.secret, - "shipmentLines": [ - { - "gtin": gtin1, - "batch": batchNumber1, - "quantity": quantity1 + for (const product of sender.products) { // ship all DFM products + const gtin = product.gtin; + for (const batch of sender.batches[gtin]) { // ship all DFM batches + const batchNumber = batch.batchNumber; + const quantity = batch.quantity; + + const shipment1MahToWhs = { + "orderId": whs.id.secret + "-" + (new Date()).toISOString(), + "requesterId": whs.id.secret, + "shipmentLines": [ + { + "gtin": gtin, + "batch": batchNumber, + "quantity": quantity + } } - ] - }; - - await shipmentCreateAndDeliver(conf, sender, whs, shipment1MahToWhs); - - const shipment2WhsToPha = { - "orderId": pha.id.secret + "-" + (new Date()).toISOString(), - "requesterId": pha.id.secret, - "shipmentLines": [ - { - "gtin": gtin1, - "batch": batchNumber1, - "quantity": quantity1 - } - ] - }; + } + ] + }; + + await shipmentCreateAndDeliver(conf, sender, whs, shipment1MahToWhs); + + const shipment2WhsToPha = { + "orderId": pha.id.secret + "-" + (new Date()).toISOString(), + "requesterId": pha.id.secret, + "shipmentLines": [ + { + "gtin": gtin, + "batch": batchNumber, + "quantity": quantity + } + ] + }; - const resShipToPha = await shipmentCreateAndDeliver(conf, whs, pha, shipment2WhsToPha); - SHIPMENTS_ON_PHA.push(resShipToPha); + const resShipToPha = await shipmentCreateAndDeliver(conf, whs, pha, shipment2WhsToPha); + SHIPMENTS_ON_PHA.push(resShipToPha); + } + } } const shipmentsCreateTestDefault = async function (conf, sender) { @@ -794,42 +799,47 @@ const salesCreateTestDfm = async function (conf, manufActor, sellerActor, mySale if (!SHIPMENTS_ON_PHA.length) { throw new Error("No shipments on pharmacies on this run!"); } - if (!SHIPMENTS_ON_PHA[0].shipmentLines.length) { - throw new Error("No shipmentLines on pharmacies on this run!"); - } - const shipmentLine0 = SHIPMENTS_ON_PHA[0].shipmentLines[0]; - const gtin = shipmentLine0.gtin; - const batchNumber = shipmentLine0.batch; - const batch = findMahOriginalBatch(gtin, batchNumber); - //console.log("batch", batch); - - let i=0; - while (i