From fc966644ef44301df5521249e7092bb15c5bbcea Mon Sep 17 00:00:00 2001 From: Mohammed Ashab Uddin Date: Tue, 21 Jul 2020 13:56:06 +0400 Subject: [PATCH] added basic functions --- whatsapp-web.js/src/models/website.js | 48 ++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/whatsapp-web.js/src/models/website.js b/whatsapp-web.js/src/models/website.js index d13f47e..1d3d998 100644 --- a/whatsapp-web.js/src/models/website.js +++ b/whatsapp-web.js/src/models/website.js @@ -3,11 +3,20 @@ const {Product} = require('./product'); class Website { /** - * @param {Map} details + * @param {Object} details */ - constructor(details){ - this.details = details; - this.products = []; + constructor(companyName){ + this.firstName = ''; + this.lastName = ''; + this.companyName = companyName; + this.logoUrl = ''; + this.bannerUrl = ''; + this.desc = ''; + this.email = ''; + //uses key value pair to store product + //key is the productId of the product + //value is the product itself + this.products = {}; } /** @@ -15,9 +24,38 @@ class Website { * @param {Product} product */ addProduct(product){ - this.products.push(product); + if(this.products[product.id] == undefined) + { + this.products[product.id] = product; + return true + } + + return false; } + /** + * + * @param {string} productId + * @returns {Product} + */ + getProduct(productId){ + return this.products[productId]; + } + + /** + * + * @param {string} productId + */ + deleteProduct(productId){ + if(this.products[productId] != undefined) + { + return delete this.products[productId]; + } + + return false; + } + + } module.exports.Website = Website; \ No newline at end of file