You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
960 B
JavaScript
29 lines
960 B
JavaScript
module.exports = class {
|
|
constructor(sellerUsername, minBuy, lots) {
|
|
this.sellerUsername = sellerUsername;
|
|
this.minBuy = minBuy;
|
|
this.lots = lots || [];
|
|
}
|
|
addToCart(lot) {
|
|
this.lots.push(lot);
|
|
}
|
|
removeFromCart(partNumber, colorId){
|
|
this.lots = this.lots.filter(lot => lot.legoPartNumber !== partNumber && lot.colorId !== colorId)
|
|
}
|
|
removeListingIdFromCart(listingId) {
|
|
if(this.hasListingId(listingId))
|
|
this.lots.splice(this.lots.findIndex((lot) => lot.listingId === listingId), 1);
|
|
}
|
|
getPrice(){
|
|
return this.lots.reduce((totalPrice, lot) => totalPrice + lot.getPrice(lot.quantity), 0);
|
|
|
|
}
|
|
toString() {
|
|
return `Store: ${this.sellerUsername}
|
|
Price: ${this.getPrice()}
|
|
${this.lots.map(lot => '\t' + lot.toString() + '\n').join('')}`
|
|
}
|
|
hasListingId(id) {
|
|
return this.lots.findIndex((lot) => lot.listingId === id) !== -1;
|
|
}
|
|
} |