Skip to content
Snippets Groups Projects
Commit 3ae87a8a authored by Gomez Goiri, Aitor's avatar Gomez Goiri, Aitor
Browse files

Considering existing cone and stock quantity in merge operations

parent 01392dae
No related branches found
No related tags found
No related merge requests found
......@@ -50,18 +50,44 @@ You can also create a _.env_ file with these default parameters.
## Usage examples
```bash
cd sidenor-cli
node index.js register --asset-name "Slag 1"
node index.js to-cone
node index.js register --asset-name "Slag 2"
node index.js to-cone
node index.js register --asset-name "Slag 3"
node index.js to-cone
node index.js to-stock
cd ../cement-cli
node index.js bid
cd ../sidenor-cli
node index.js bid-accept
$ cd sidenor-cli
$ node index.js register --asset-name "Slag 1"
Registered asset asst_07b75e28-6685-4e18-b810-75e410dd37f2
$ node index.js to-cone
? Select asset asst_07b75e28-6685-4e18-b810-75e410dd37f2 (Slag 1, type: 10, status: slag)
Moved to cone c28bed645434c46376369bc5cc400b4c
$ node index.js register --asset-name "Slag 2"
Registered asset asst_c51fa4b7-078d-4880-bd16-79235c24830e
$ node index.js to-cone
? Select asset asst_c51fa4b7-078d-4880-bd16-79235c24830e (Slag 2, type: 10, status: slag)
Moved to cone 6007feb7e2984c92d8efc13c23606fbb
$ node index.js register --asset-name "Slag 3"
Registered asset asst_8e97b751-be1b-41c1-a425-67c49cdd8a33
$ node index.js to-cone
? Select asset asst_8e97b751-be1b-41c1-a425-67c49cdd8a33 (Slag 3, type: 10, status: slag)
Moved to cone 513be341a8c15c74dc06ca434b33cb36
$ node index.js to-stock
? Select asset 6007feb7e2984c92d8efc13c23606fbb (undefined, type: 1002, status: batched)
? Select the stock where the cone will be merged newStock (New stock, type: 10 02, status: stocked)
Moved to stock caaa642c25d96a5d8f14cf031a898fed
$ cd ../cement-cli
$ node index.js bid
? Select asset 19e2f7a99288dfc9a2902e71bfc9dfe6 (Stock, type: 1002, status: stocked)
? Choose an ammount of slag 34
? Provide the offered price 3
Bid for slag stock 19e2f7a99288dfc9a2902e71bfc9dfe6
$ cd ../sidenor-cli
$ node index.js bid-accept
? Select asset 19e2f7a99288dfc9a2902e71bfc9dfe6 (Stock, type: 1002, status: stocked)
? Select the bidder whose bid will be accepted cement-company1-com:eDUwOTo6Q049dXNlcixPVT1jbGllbnQrT1U9b3JnMStPVT1kZXBhcnRtZW50MTo6Q049Y2EuY2VtZW5
0LWNvbXBhbnkxLmNvbSxPPWNlbWVudC1jb21wYW55MS5jb20sTD1SYWxlaWdoLFNUPU5vcnRoIENhcm9saW5hLEM9VVM= (quantity: 34, price: 3)
Bid from cement-company1-com:eDUwOTo6Q049dXNlcixPVT1jbGllbnQrT1U9b3JnMStPVT1kZXBhcnRtZW50MTo6Q049Y2EuY2VtZW50LWNvbXBhbnkxLmNvbSxPPWNlbWVudC1jb21wYW55MS5jb20sTD1SYWxlaWdoLFNUPU5vcnRoIENhcm9saW5hLEM9VVM= accepted for asset 19e2f7a99288dfc9a2902e71bfc9dfe6
```
......@@ -66,9 +66,13 @@ const sendToCone = async (apiClient, { assetId: paramAssetId }) => {
}
})
const [firstAsset] = assetsInCone
const newConeQuantity =
assetToBeSent.quantity + (firstAsset ? firstAsset.quantity : 0)
const coneAsset = await apiClient.joinAsset(
//`cone_${faker.datatype.uuid()}`,
assetsInCone.length === 0 ? [assetId] : [assetsInCone[0].id, assetId],
firstAsset ? [firstAsset.id, assetId] : [assetId],
{ parentsShouldExist: false, bidirectional: true },
{
type: TYPES.RESIDUO_HIERRO_ACERO,
......@@ -76,6 +80,8 @@ const sendToCone = async (apiClient, { assetId: paramAssetId }) => {
assetsInCone.length === 0
? assetToBeSent.location
: assetsInCone[0].location,
units: "kg",
quantity: newConeQuantity,
fields: {
status: STATUSES.SLAG_BATCH
}
......@@ -122,11 +128,18 @@ const sendToStock = async (apiClient, { assetId: paramAssetId }) => {
"Select the stock where the cone will be merged"
)
if (!selectedStockId === "newStock") {
if (!selectedStockId) {
console.error("You must select a stock")
return
}
let previousStock = false
if (selectedStockId !== "newStock") {
previousStock = await apiClient.getAsset(selectedStockId)
}
const newStockQuantity =
assetToBeSent.quantity + (previousStock ? previousStock.quantity : 0)
const newStockAsset = await apiClient.joinAsset(
selectedStockId === "newStock" ? [assetId] : [selectedStockId, assetId],
{ parentsShouldExist: true, bidirectional: true },
......@@ -138,6 +151,8 @@ const sendToStock = async (apiClient, { assetId: paramAssetId }) => {
: (
await apiClient.getAsset(selectedStockId)
).location,
units: "kg",
quantity: newStockQuantity,
fields: {
status: STATUSES.STOCK,
name: "Stock"
......
# COPYRIGHT: FUNDACIÓN TECNALIA RESEARCH & INNOVATION, 2021.
#! /bin/bash
source ../network/config.sh
source ../config.sh
declare -A confs
confs=(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment