added and used entity methods
This commit is contained in:
@@ -8,43 +8,6 @@ class Product {
|
|||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
this.image = image;
|
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;
|
module.exports.Product = Product;
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
|
|
||||||
|
const { Entity } = require('./entity');
|
||||||
const {Website} = require('./website');
|
const {Website} = require('./website');
|
||||||
|
|
||||||
class User{
|
class User{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} id
|
||||||
|
*/
|
||||||
constructor(id){
|
constructor(id){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
//uses key value pair to store website
|
this.websites = new Entity();
|
||||||
//key is the companyName of the website
|
|
||||||
//value is the website itself
|
|
||||||
this.websites = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,26 +18,15 @@ class User{
|
|||||||
* @param {Website} website
|
* @param {Website} website
|
||||||
*/
|
*/
|
||||||
addWebsite(website){
|
addWebsite(website){
|
||||||
if(this.websites[website.companyName] != undefined)
|
return this.websites.addData(website.companyName, website);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}else{
|
|
||||||
this.websites[website.companyName] = website;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteWebsite(companyName){
|
deleteWebsite(companyName){
|
||||||
if(this.websites[companyName] != undefined)
|
return this.websites.deleteData(companyName);
|
||||||
{
|
|
||||||
return delete this.websites[companyName];
|
|
||||||
}else{
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getWebsite(companyName){
|
getWebsite(companyName){
|
||||||
return this.websites[companyName];
|
return this.websites.getData(companyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const { Entity } = require('./entity');
|
||||||
const {Product} = require('./product');
|
const {Product} = require('./product');
|
||||||
|
|
||||||
class Website {
|
class Website {
|
||||||
@@ -16,7 +17,7 @@ class Website {
|
|||||||
//uses key value pair to store product
|
//uses key value pair to store product
|
||||||
//key is the productId of the product
|
//key is the productId of the product
|
||||||
//value is the product itself
|
//value is the product itself
|
||||||
this.products = {};
|
this.products = new Entity();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,13 +25,7 @@ class Website {
|
|||||||
* @param {Product} product
|
* @param {Product} product
|
||||||
*/
|
*/
|
||||||
addProduct(product){
|
addProduct(product){
|
||||||
if(this.products[product.id] == undefined)
|
return this.products.addData(product.id, product);
|
||||||
{
|
|
||||||
this.products[product.id] = product;
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,7 +34,7 @@ class Website {
|
|||||||
* @returns {Product}
|
* @returns {Product}
|
||||||
*/
|
*/
|
||||||
getProduct(productId){
|
getProduct(productId){
|
||||||
return this.products[productId];
|
return this.products.getData(productId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,12 +42,8 @@ class Website {
|
|||||||
* @param {string} productId
|
* @param {string} productId
|
||||||
*/
|
*/
|
||||||
deleteProduct(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