added and used entity methods
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user