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; } }