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

Validating numbers received from the user

parent efa1b351
No related branches found
No related tags found
No related merge requests found
...@@ -63,6 +63,10 @@ $ cd sidenor-cli ...@@ -63,6 +63,10 @@ $ cd sidenor-cli
$ node index.js register --asset-name "Slag 1" $ node index.js register --asset-name "Slag 1"
Registered asset asst_07b75e28-6685-4e18-b810-75e410dd37f2 Registered asset asst_07b75e28-6685-4e18-b810-75e410dd37f2
$ node index.js composition
? Select asset asst_a9e0bd5d-aaa2-412e-95ee-c7cff1f831dc (Slag 1, type: 10, status: slag)
? Choose the percentage of CaO content in the slag (min: 40%, max 70%): 43
$ node index.js to-cone $ node index.js to-cone
? Select asset asst_07b75e28-6685-4e18-b810-75e410dd37f2 (Slag 1, type: 10, status: slag) ? Select asset asst_07b75e28-6685-4e18-b810-75e410dd37f2 (Slag 1, type: 10, status: slag)
Moved to cone c28bed645434c46376369bc5cc400b4c Moved to cone c28bed645434c46376369bc5cc400b4c
...@@ -82,9 +86,9 @@ $ node index.js to-cone ...@@ -82,9 +86,9 @@ $ node index.js to-cone
Moved to cone 513be341a8c15c74dc06ca434b33cb36 Moved to cone 513be341a8c15c74dc06ca434b33cb36
$ node index.js to-stock $ node index.js to-stock
? Select asset 6007feb7e2984c92d8efc13c23606fbb (undefined, type: 1002, status: batched) ? Select asset 513be341a8c15c74dc06ca434b33cb36 (Slag batch (in cone), type: 1002, status: batched)
? Select the stock where the cone will be merged newStock (New stock, type: 10 02, status: stocked) ? Select the stock where the cone will be merged newStock (New stock, type: 10 02, status: stocked)
Moved to stock caaa642c25d96a5d8f14cf031a898fed Moved to stock 6007feb7e2984c92d8efc13c23606fbb
$ cd ../cement-cli $ cd ../cement-cli
$ node index.js bid $ node index.js bid
......
...@@ -20,7 +20,11 @@ const bidAsset = async ( ...@@ -20,7 +20,11 @@ const bidAsset = async (
type: "number", type: "number",
name: "inputQuantity", name: "inputQuantity",
message: `Choose an amount of slag to bid for (max: ${assetToBid.quantity} ${assetToBid.units}):`, message: `Choose an amount of slag to bid for (max: ${assetToBid.quantity} ${assetToBid.units}):`,
default: Math.floor(assetToBid.quantity * 0.1) // Default: 10% default: Math.floor(assetToBid.quantity * 0.1), // Default: 10%
validate: n => {
if (n > 0) return true
return "Please, provide a quantity to bid for."
}
} }
]) ])
chosenQuantity = inputQuantity chosenQuantity = inputQuantity
...@@ -32,7 +36,12 @@ const bidAsset = async ( ...@@ -32,7 +36,12 @@ const bidAsset = async (
{ {
type: "number", type: "number",
name: "inputPrice", name: "inputPrice",
message: "Provide the offered price (in €):" message: "Provide the offered price (in €):",
default: 0,
validate: n => {
if (n > 0) return true
return `Please, provide a price for ${chosenQuantity} ${assetToBid.units} in €.`
}
} }
]) ])
chosenPrice = inputPrice chosenPrice = inputPrice
......
...@@ -15,7 +15,7 @@ const createAsset = async (apiClient, { assetName }) => { ...@@ -15,7 +15,7 @@ const createAsset = async (apiClient, { assetName }) => {
id: `asst_${faker.datatype.uuid()}`, id: `asst_${faker.datatype.uuid()}`,
type: TYPES.RESIDUO_PROCESOS_TERMICOS, type: TYPES.RESIDUO_PROCESOS_TERMICOS,
units: "kg", units: "kg",
quantity: faker.datatype.number({ max: 5000 }), quantity: faker.datatype.number({ min: 0, max: 5000 }),
fields: { fields: {
description: "Escoria", description: "Escoria",
name: assetName, name: assetName,
...@@ -42,11 +42,14 @@ const editComposition = async ( ...@@ -42,11 +42,14 @@ const editComposition = async (
const { inputCaoPercentage } = await inquirer.prompt([ const { inputCaoPercentage } = await inquirer.prompt([
{ {
type: "number", type: "number",
name: "inputQuantity", name: "inputCaoPercentage",
message: message:
"Choose the percentage of CaO content in the slag (min: 40%, max 70%):", "Choose the percentage of CaO content in the slag (min: 40%, max 70%):",
default: faker.datatype.number({ min: 40, max: 70 }), default: faker.datatype.number({ min: 40, max: 70 }),
validate: n => n >= 40 && n <= 70 validate: n => {
if (n >= 40 && n <= 70) return true
return "The CaO percentage must be between 40 and 70"
}
} }
]) ])
chosenCaoPercentage = inputCaoPercentage chosenCaoPercentage = inputCaoPercentage
...@@ -101,6 +104,7 @@ const sendToCone = async (apiClient, { assetId: paramAssetId }) => { ...@@ -101,6 +104,7 @@ const sendToCone = async (apiClient, { assetId: paramAssetId }) => {
units: "kg", units: "kg",
quantity: newConeQuantity, quantity: newConeQuantity,
fields: { fields: {
name: "Slag batch (in cone)",
status: STATUSES.SLAG_BATCH status: STATUSES.SLAG_BATCH
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment