This commit is contained in:
Mohammed Ashab Uddin
2020-07-27 10:15:48 +04:00
4 changed files with 70 additions and 25 deletions

View File

@@ -5,7 +5,7 @@ const { Website } = require("../models/website");
const { Product } = require('../models/product');
var selected_product = null;// Will keep track of the selected product
var selected_website = new Website; // Selected website.
var selected_website = null; // Selected website.
///////////
//add the commands here
@@ -42,7 +42,7 @@ const commands = [
];
return message;
}
selected_product= logic.addProduct(input,selected_website);
selected_product= logic.addProduct(input['id'],selected_website);
//mesage to be sent to the user
let message = [
`The product has been created with the id : ` + selected_product.id ,
@@ -54,7 +54,7 @@ const commands = [
}),
new Command({
//User command
command: `wg delete product <id>`,
command: `wg product delete <id>`,
//function to be executed
callback : (input) => {
@@ -67,7 +67,7 @@ const commands = [
return message;
}
if(logic.deleteProduct(input,selected_website) == false)
if(logic.deleteProduct(input['id'],selected_website) == false)
{
let message = [
`No product with the given id`
@@ -83,7 +83,7 @@ const commands = [
}),
new Command({
//User command
command: `wg product <id>`,
command: `wg select product <id>`,
//function to be executed
callback : (input) => {
@@ -96,7 +96,7 @@ const commands = [
return message;
}
// Find the product with the given id
selected_product = selected_website.products.getData(input);
selected_product = selected_website.getProduct(input['id']);
if(selected_product == null)
{
logic.addProduct(id,selected_website);
@@ -109,7 +109,7 @@ const commands = [
}
let message = [
`The product has been selected with the id : ` + id ,
`The product has been selected with the id : ` + selected_product.id ,
'Now you can make change to the product with the following commands : \n1. wg product info \n2. wg product name <product-name> \n3. wg product cost <product-cost> \n4. wg product desc <product-desc> \n5. wg product image <product-image>'
];
@@ -132,9 +132,9 @@ const commands = [
return message;
}
let message = [
'Your website has following products'
'Your website has following products: '
];
for(let p of selected_website.products.getAllData().values())
for(let p of selected_website.getAllProduct())
{
let m = 'Product id: ' + p.id + '\nProduct Name : ' + p.name + '\nProduct description : '+ p.desc + '\nProduct Cost: ' + p.cost + '\nProduct Image : '+ p.image
message.push(m);
@@ -158,11 +158,11 @@ const commands = [
return message;
}
let message = [
'Product id: ' + p.id,
'Product Name : ' + p.name ,
'Product description : '+ p.desc ,
'Product Cost: ' + p.cost ,
'Product Image : '+ p.image
'Product id: ' + selected_product.id,
'Product Name : ' + selected_product.name ,
'Product description : '+ selected_product.desc ,
'Product Cost: ' + selected_product.cost ,
'Product Image : '+ selected_product.image
];
return message;
@@ -182,9 +182,9 @@ const commands = [
];
return message;
}
selected_product.name= input;
selected_product.setName(input['product-name']);
let message = [
'The product name has been set to '+ given_name
'The product name has been set to '+ selected_product.name
];
return message;
@@ -204,9 +204,9 @@ const commands = [
];
return message;
}
selected_product.cost= input;
selected_product.setCost(input['product-cost']);
let message = [
'The product cost has been set to '+ given_cost
'The product cost has been set to '+ selected_product.cost
];
return message;
@@ -226,9 +226,9 @@ const commands = [
];
return message;
}
selected_product.desc = input;
selected_product.setDesc(input['product-desc']);
let message = [
'The product description has been set to : '+ given_desc
'The product description has been set to : '+ selected_product.desc
];
return message;
@@ -248,9 +248,9 @@ const commands = [
];
return message;
}
selected_product.image = input;
selected_product.setImage(input['product-image']);
let message = [
'The product image has been set to : '+ given_image
'The product image has been set to : '+ selected_product.image
];
return message;