From 5102f5a826414fe063b4b847db0ebdf93c45ffae Mon Sep 17 00:00:00 2001 From: Daazd Date: Mon, 11 Mar 2024 12:44:02 -0700 Subject: [PATCH 1/3] First exercise --- classes/Product.js | 13 +++++++++++++ index.js | 5 ++--- package-lock.json | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/classes/Product.js b/classes/Product.js index e69de29..efbbddd 100644 --- a/classes/Product.js +++ b/classes/Product.js @@ -0,0 +1,13 @@ +class Product { + constructor(name, price, description) { + this.name = name; + this.price = price; + this.description = description; + this.inStock = true; + } + display() { + return `Name: ${this.name}, Price: $${this.price}, Description: ${this.description}` + } +} + +module.exports = Product; \ No newline at end of file diff --git a/index.js b/index.js index efad601..42b0363 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,6 @@ // Import Classes Here +// Import Classes Here +const Product = require('./classes/Product') @@ -7,9 +9,6 @@ - - -// DO NOT EDIT BELOW THIS LINE try { module.exports = { Product, diff --git a/package-lock.json b/package-lock.json index 9b68881..5713249 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4717,7 +4717,8 @@ "jest-pnp-resolver": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/jest-pnp-resolver/-/jest-pnp-resolver-1.2.3.tgz", - "integrity": "sha512-+3NpwQEnRoIBtx4fyhblQDPgJI0H1IEIkX7ShLUjPGA7TtUTvI1oiKi3SR4oBR0hQhQR80l4WAe5RrXBwWMA8w==" + "integrity": "sha512-+3NpwQEnRoIBtx4fyhblQDPgJI0H1IEIkX7ShLUjPGA7TtUTvI1oiKi3SR4oBR0hQhQR80l4WAe5RrXBwWMA8w==", + "requires": {} }, "jest-regex-util": { "version": "29.4.3", From 850b27d6602e65f785cebff7805c91da83f745c0 Mon Sep 17 00:00:00 2001 From: Cedrick Catalan Date: Mon, 11 Mar 2024 16:06:53 -0400 Subject: [PATCH 2/3] added Cart and Customer classes --- classes/Cart.js | 17 +++++++++++++++++ classes/Customer.js | 13 +++++++++++++ index.js | 6 ++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/classes/Cart.js b/classes/Cart.js index e69de29..c9b6427 100644 --- a/classes/Cart.js +++ b/classes/Cart.js @@ -0,0 +1,17 @@ +class Cart{ + constructor(){ + this.products=[]; + this.total=0; + } + addProduct(prod){ + this.products.push(prod); + this.total+=prod.price; + } + removeProduct(index){ + const [product] = this.products.splice(index,1); + this.total-=product.price; + } +} + + +module.exports = Cart; \ No newline at end of file diff --git a/classes/Customer.js b/classes/Customer.js index e69de29..a9fb0af 100644 --- a/classes/Customer.js +++ b/classes/Customer.js @@ -0,0 +1,13 @@ +class Customer{ + constructor(name,email,shippingAddress){ + this.name=name; + this.email=email; + this.shippingAddress=shippingAddress; + this.orderHistory=[]; + } + addToOrderHistory(cart){ + this.orderHistory.push(cart); + } +} + +module.exports=Customer; \ No newline at end of file diff --git a/index.js b/index.js index 42b0363..3e3569b 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,8 @@ // Import Classes Here // Import Classes Here const Product = require('./classes/Product') - - - - +const Cart = require('./classes/Cart') +const Customer = require('./classes/Customer') From a65d558cb7e4efda236de4822072ef46ccbaed4a Mon Sep 17 00:00:00 2001 From: Daazd Date: Mon, 11 Mar 2024 13:33:30 -0700 Subject: [PATCH 3/3] final product --- classes/Auth.js | 19 +++++++++++++++++++ classes/Cart.js | 7 +++++++ classes/Customer.js | 8 ++++++++ classes/Product.js | 3 +++ index.js | 1 + 5 files changed, 38 insertions(+) diff --git a/classes/Auth.js b/classes/Auth.js index e69de29..e8718a1 100644 --- a/classes/Auth.js +++ b/classes/Auth.js @@ -0,0 +1,19 @@ +const Customer = require('./Customer'); + + +class Auth { + constructor() { + this.customers = []; + } + register(name, email,shippingAddress) { + let newCustomer = new Customer(name, email, shippingAddress); + this.customers.push(newCustomer); + return newCustomer; + } + login(email) { + let customer = this.customers.find(customer => customer.email === email) || null; + return customer; + } +} + +module.exports = Auth; \ No newline at end of file diff --git a/classes/Cart.js b/classes/Cart.js index c9b6427..d509afd 100644 --- a/classes/Cart.js +++ b/classes/Cart.js @@ -11,6 +11,13 @@ class Cart{ const [product] = this.products.splice(index,1); this.total-=product.price; } + getTotal(){ + return this.total; + } + clear(){ + this.products=[]; + this.total=0; + } } diff --git a/classes/Customer.js b/classes/Customer.js index a9fb0af..134ec51 100644 --- a/classes/Customer.js +++ b/classes/Customer.js @@ -4,10 +4,18 @@ class Customer{ this.email=email; this.shippingAddress=shippingAddress; this.orderHistory=[]; + this.rewardPoints = 0; } addToOrderHistory(cart){ this.orderHistory.push(cart); } + getRewardPoints(){ + return this.orderHistory.reduce((total,cart)=>{ + return total+=cart.products.reduce((sum, product)=>{ + return sum+product.rewardPoints; + },0); + },0); + } } module.exports=Customer; \ No newline at end of file diff --git a/classes/Product.js b/classes/Product.js index efbbddd..faece4c 100644 --- a/classes/Product.js +++ b/classes/Product.js @@ -4,10 +4,13 @@ class Product { this.price = price; this.description = description; this.inStock = true; + this.rewardPoints = price * 100; } display() { return `Name: ${this.name}, Price: $${this.price}, Description: ${this.description}` } + + } module.exports = Product; \ No newline at end of file diff --git a/index.js b/index.js index 3e3569b..4144f5b 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ const Product = require('./classes/Product') const Cart = require('./classes/Cart') const Customer = require('./classes/Customer') +const Auth = require('./classes/Auth')