From eeb04e1615874820fcdf71b97ea2d0d6c93d1c94 Mon Sep 17 00:00:00 2001 From: Baber-Jan Date: Sun, 26 Jul 2020 19:12:51 +0400 Subject: [PATCH] Did the required changes --- whatsapp-web.js/src/businessLogic/logic.js | 4 +- whatsapp-web.js/src/models/product.js | 37 ++++++++++++++++++ whatsapp-web.js/src/models/website.js | 8 ++++ .../src/userInteraction/messages.js | 38 +++++++++---------- 4 files changed, 66 insertions(+), 21 deletions(-) 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 8a01ddb..ebbefca 100644 --- a/whatsapp-web.js/src/models/product.js +++ b/whatsapp-web.js/src/models/product.js @@ -8,6 +8,43 @@ class Product { 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 9e32940..cf19e39 100644 --- a/whatsapp-web.js/src/userInteraction/messages.js +++ b/whatsapp-web.js/src/userInteraction/messages.js @@ -4,7 +4,7 @@ const logic = require("../businessLogic/logic"); const { Website } = require("../models/website"); const { Product } = require('../models/product'); -var selected_product = null;// Will keep track of the selected product +var selected_product = new Product;// Will keep track of the selected product var selected_website = null; // Selected website. /////////// @@ -85,7 +85,7 @@ const commands = [ }), new Command({ //User command - command: `wg product `, + command: `wg select product `, //function to be executed callback : (input) => { @@ -99,7 +99,7 @@ const commands = [ return message; } // Find the product with the given id - selected_product = selected_website.products.getData(input['id']); + selected_product = selected_website.getProduct(input['id']); if(selected_product == null) { logic.addProduct(id,selected_website); @@ -112,7 +112,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 ' ]; @@ -136,9 +136,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); @@ -163,11 +163,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; @@ -188,9 +188,9 @@ const commands = [ ]; return message; } - selected_product.name= input['product-name']; + 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; @@ -211,9 +211,9 @@ const commands = [ ]; return message; } - selected_product.cost= input['product-cost']; + 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; @@ -234,9 +234,9 @@ const commands = [ ]; return message; } - selected_product.desc = input['product-desc']; + 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; @@ -257,9 +257,9 @@ const commands = [ ]; return message; } - selected_product.image = input['product-image']; + 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;