diff --git a/whatsapp-web.js/src/businessLogic/logic.js b/whatsapp-web.js/src/businessLogic/logic.js index f96eca2..489aad5 100644 --- a/whatsapp-web.js/src/businessLogic/logic.js +++ b/whatsapp-web.js/src/businessLogic/logic.js @@ -33,12 +33,12 @@ module.exports.addProduct = (id,website) => { // Create a product and select it. At this point all the product properties will be default including the id will be empty var product = new Product(); - product.id =id; + product.setId(id); // Add a product to the selected website. We will add the id based on the count of the products on the website website.addProduct(product); return product; } module.exports.deleteProduct = (id,website) => { - return website.products.deleteData(id); + return website.deleteProduct(id); } diff --git a/whatsapp-web.js/src/models/product.js b/whatsapp-web.js/src/models/product.js index 0878b60..ebbefca 100644 --- a/whatsapp-web.js/src/models/product.js +++ b/whatsapp-web.js/src/models/product.js @@ -1,13 +1,50 @@ class Product { - constructor({ id = '', name = '', desc = '', cost = 0, image = null }) { + constructor({ id = '', name = '', desc = '', cost = 0, image = null } = {}) { this.id = id; this.name = name; this.desc = desc; this.cost = cost; this.image = image; } + + /** + * + * @param {Number} id + */ + setId(id){ + return this.id = id; + } + /** + * + * @param {String} name + */ + setName(name){ + return this.name = name; + } + /** + * + * @param {String} description + */ + setDesc(description){ + return this.desc = description; + } + /** + * + * @param {Number} cost + */ + setCost(cost){ + return this.cost = cost; + } + /** + * + * @param {String} image + */ + setImage(image){ + return this.image = image; + } + } module.exports.Product = Product; diff --git a/whatsapp-web.js/src/models/website.js b/whatsapp-web.js/src/models/website.js index 9584f76..86e0f35 100644 --- a/whatsapp-web.js/src/models/website.js +++ b/whatsapp-web.js/src/models/website.js @@ -37,6 +37,14 @@ class Website { return this.products.getData(productId); } + /** + * + * @returns {[]} + */ + getAllProduct(){ + return this.products.getAllData().values(); + } + /** * * @param {string} productId diff --git a/whatsapp-web.js/src/userInteraction/messages.js b/whatsapp-web.js/src/userInteraction/messages.js index b4a86dc..1fd12e0 100644 --- a/whatsapp-web.js/src/userInteraction/messages.js +++ b/whatsapp-web.js/src/userInteraction/messages.js @@ -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 `, + command: `wg product delete `, //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 `, + command: `wg select product `, //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 \n3. wg product cost \n4. wg product desc \n5. wg 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;