From 7b0779d5525cd0963cc5552532917f918dec4dfb Mon Sep 17 00:00:00 2001 From: Mohammed Ashab Uddin Date: Wed, 22 Jul 2020 10:51:29 +0400 Subject: [PATCH] added and used entity methods --- whatsapp-web.js/src/models/product.js | 37 --------------------------- whatsapp-web.js/src/models/user.js | 27 +++++++------------ whatsapp-web.js/src/models/website.js | 21 +++++---------- 3 files changed, 15 insertions(+), 70 deletions(-) diff --git a/whatsapp-web.js/src/models/product.js b/whatsapp-web.js/src/models/product.js index 4214921..0878b60 100644 --- a/whatsapp-web.js/src/models/product.js +++ b/whatsapp-web.js/src/models/product.js @@ -8,43 +8,6 @@ class Product { this.cost = cost; this.image = image; } - - getId(){ - return this.id; - } - - setName(name){ - this.name = name; - } - - getName(){ - return this.name; - } - - setDesc(desc){ - this.desc = desc; - } - - getDesc(){ - return this.desc; - } - - setCost(cost){ - this.cost = cost; - } - - getCost(){ - return this.cost; - } - - setImage(image){ - this.imageUrl = image; - } - - getImage(){ - return this.imageUrl; - } - } module.exports.Product = Product; diff --git a/whatsapp-web.js/src/models/user.js b/whatsapp-web.js/src/models/user.js index febb440..2c915c6 100644 --- a/whatsapp-web.js/src/models/user.js +++ b/whatsapp-web.js/src/models/user.js @@ -1,14 +1,16 @@ +const { Entity } = require('./entity'); const {Website} = require('./website'); class User{ + /** + * + * @param {string} id + */ constructor(id){ this.id = id; - //uses key value pair to store website - //key is the companyName of the website - //value is the website itself - this.websites = {}; + this.websites = new Entity(); } /** @@ -16,26 +18,15 @@ class User{ * @param {Website} website */ addWebsite(website){ - if(this.websites[website.companyName] != undefined) - { - return false; - }else{ - this.websites[website.companyName] = website; - return true; - } + return this.websites.addData(website.companyName, website); } deleteWebsite(companyName){ - if(this.websites[companyName] != undefined) - { - return delete this.websites[companyName]; - }else{ - return false - } + return this.websites.deleteData(companyName); } getWebsite(companyName){ - return this.websites[companyName]; + return this.websites.getData(companyName); } } diff --git a/whatsapp-web.js/src/models/website.js b/whatsapp-web.js/src/models/website.js index 1d3d998..9584f76 100644 --- a/whatsapp-web.js/src/models/website.js +++ b/whatsapp-web.js/src/models/website.js @@ -1,3 +1,4 @@ +const { Entity } = require('./entity'); const {Product} = require('./product'); class Website { @@ -16,7 +17,7 @@ class Website { //uses key value pair to store product //key is the productId of the product //value is the product itself - this.products = {}; + this.products = new Entity(); } /** @@ -24,13 +25,7 @@ class Website { * @param {Product} product */ addProduct(product){ - if(this.products[product.id] == undefined) - { - this.products[product.id] = product; - return true - } - - return false; + return this.products.addData(product.id, product); } /** @@ -39,7 +34,7 @@ class Website { * @returns {Product} */ getProduct(productId){ - return this.products[productId]; + return this.products.getData(productId); } /** @@ -47,12 +42,8 @@ class Website { * @param {string} productId */ deleteProduct(productId){ - if(this.products[productId] != undefined) - { - return delete this.products[productId]; - } - - return false; + + return this.products.deleteData(productId); }