added basic functions
This commit is contained in:
@@ -3,11 +3,20 @@ const {Product} = require('./product');
|
|||||||
class Website {
|
class Website {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Map<string,string>} details
|
* @param {Object} details
|
||||||
*/
|
*/
|
||||||
constructor(details){
|
constructor(companyName){
|
||||||
this.details = details;
|
this.firstName = '';
|
||||||
this.products = [];
|
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
|
* @param {Product} product
|
||||||
*/
|
*/
|
||||||
addProduct(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;
|
module.exports.Website = Website;
|
||||||
Reference in New Issue
Block a user