diff --git a/apps/sidenor-cli/index.js b/apps/sidenor-cli/index.js index 88c53edf90f1c70ac7f49948b0c1ee65d2d96edc..0320297da5972cbc33c905c2435a05a32e1d7404 100644 --- a/apps/sidenor-cli/index.js +++ b/apps/sidenor-cli/index.js @@ -27,6 +27,7 @@ program "--asset-id [value]", "Identifier of the slag whose composition has been measured" ) + .option("--cao-percentage [value]", "CaO percentage in the slag") .action(loginAndCallAfterwards(editComposition)) program diff --git a/apps/sidenor-cli/lib.js b/apps/sidenor-cli/lib.js index ea6eb6244a7966b047449f3622d0019e18de302d..816c74ffb714686beadf1e513e335c7a5acb01b4 100644 --- a/apps/sidenor-cli/lib.js +++ b/apps/sidenor-cli/lib.js @@ -30,10 +30,28 @@ const createAsset = async (apiClient, { assetName }) => { return newAsset.id } -const editComposition = async (apiClient, { assetId: paramAssetId }) => { +const editComposition = async ( + apiClient, + { assetId: paramAssetId, caoPercentage } +) => { const assetId = paramAssetId || (await promptAssetSelection(await apiClient.richQuery())) + let chosenCaoPercentage = caoPercentage + if (!caoPercentage) { + const { inputCaoPercentage } = await inquirer.prompt([ + { + type: "number", + name: "inputQuantity", + message: + "Choose the percentage of CaO content in the slag (min: 40%, max 70%):", + default: faker.datatype.number({ min: 40, max: 70 }), + validate: n => n >= 40 && n <= 70 + } + ]) + chosenCaoPercentage = inputCaoPercentage + } + const previousVersion = await apiClient.getAsset(assetId) await apiClient.modifyAsset({ @@ -41,7 +59,7 @@ const editComposition = async (apiClient, { assetId: paramAssetId }) => { id: assetId, fields: { ...previousVersion.fields, - composition: "comp1" + composition: { cao: chosenCaoPercentage } } })