From 6af5db27d5a7707e2454d51a7deee17dba5c2a3e Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Mon, 22 Apr 2024 23:36:50 -0700 Subject: [PATCH 1/8] Product class completed --- classes/Product.js | 16 ++++++++++++++++ index.js | 2 +- package-lock.json | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/classes/Product.js b/classes/Product.js index e69de29..dd05394 100644 --- a/classes/Product.js +++ b/classes/Product.js @@ -0,0 +1,16 @@ +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..3621ea6 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ // Import Classes Here - +const Product = require('./classes/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 44bbd9dcad2cb533d180527e5ed4935312c61f7c Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Mon, 22 Apr 2024 23:48:17 -0700 Subject: [PATCH 2/8] Cart class completed --- classes/Cart.js | 21 +++++++++++++++++++++ index.js | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/classes/Cart.js b/classes/Cart.js index e69de29..b71cdab 100644 --- a/classes/Cart.js +++ b/classes/Cart.js @@ -0,0 +1,21 @@ +class Cart { + + constructor() { + this.products = [] + this.total = 0 + } + + addProduct(product) { + this.products.push(product); + this.total += product.price; + } + + removeProduct(i) { + let price = this.products[i].price; + this.total -= price + + this.products.splice(i, 1) + } +} + +module.exports = Cart \ No newline at end of file diff --git a/index.js b/index.js index 3621ea6..f023e53 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ // Import Classes Here const Product = require('./classes/Product') - +const Cart = require('./classes/Cart') From 445a7f13ba487d7ae43e884927ec25839c9caff5 Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Mon, 22 Apr 2024 23:52:41 -0700 Subject: [PATCH 3/8] Customer class completed --- classes/Customer.js | 15 +++++++++++++++ index.js | 4 +--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/classes/Customer.js b/classes/Customer.js index e69de29..177175a 100644 --- a/classes/Customer.js +++ b/classes/Customer.js @@ -0,0 +1,15 @@ +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 f023e53..b54270a 100644 --- a/index.js +++ b/index.js @@ -2,9 +2,7 @@ const Product = require('./classes/Product') const Cart = require('./classes/Cart') - - - +const Customer = require('./classes/Customer') From c5af3c700d70c987ce6f1a31d940bae5e9e9dbf9 Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Mon, 22 Apr 2024 23:59:36 -0700 Subject: [PATCH 4/8] Auth class completed --- classes/Auth.js | 26 ++++++++++++++++++++++++++ index.js | 1 + 2 files changed, 27 insertions(+) diff --git a/classes/Auth.js b/classes/Auth.js index e69de29..2a578cb 100644 --- a/classes/Auth.js +++ b/classes/Auth.js @@ -0,0 +1,26 @@ +const Customer = require("./Customer") + +class Auth { + + constructor() { + this.customers = [] + } + + register(name, email, shippingAddress) { + const newCustomer = new Customer(name, email, shippingAddress) + this.customers.push(newCustomer) + } + + login(email) { + for(let i = 0; i < this.customers.length; i++) { + if(this.customers[i].email === email) { + return this.customers[i] + } + } + + return null; + } + +} + +module.exports = Auth \ No newline at end of file diff --git a/index.js b/index.js index b54270a..379f260 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') From 3b98e26935d8b1e1aa8b11afa97898f1d911a8d5 Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Tue, 23 Apr 2024 00:10:52 -0700 Subject: [PATCH 5/8] added getTotal of all products functionality --- classes/Cart.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/classes/Cart.js b/classes/Cart.js index b71cdab..f75986d 100644 --- a/classes/Cart.js +++ b/classes/Cart.js @@ -16,6 +16,10 @@ class Cart { this.products.splice(i, 1) } + + getTotal() { + return this.total + } } module.exports = Cart \ No newline at end of file From 2ff6358d86e8de6fa46c023cbae043555f2bdca2 Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Tue, 23 Apr 2024 00:12:32 -0700 Subject: [PATCH 6/8] added clear method functionality --- classes/Cart.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/classes/Cart.js b/classes/Cart.js index f75986d..e24dbf1 100644 --- a/classes/Cart.js +++ b/classes/Cart.js @@ -20,6 +20,14 @@ class Cart { getTotal() { return this.total } + + clear(){ + let length = this.products.length; + + this.products.splice(0, length) + this.total = 0 + + } } module.exports = Cart \ No newline at end of file From e4f7bac4f3c24805d2856f4259789c0c81bcfaaa Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Tue, 23 Apr 2024 00:18:14 -0700 Subject: [PATCH 7/8] completed rewardPoints and getRewardPoints logic --- classes/Customer.js | 13 +++++++++++++ classes/Product.js | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/classes/Customer.js b/classes/Customer.js index 177175a..3db4e9f 100644 --- a/classes/Customer.js +++ b/classes/Customer.js @@ -5,11 +5,24 @@ class Customer { this.email = email this.shippingAddress = shippingAddress this.orderHistory = [] + this.rewardPoints = 0 } addToOrderHistory(cart) { this.orderHistory.push(cart) } + + getRewardPoints() { + for(let i = 0; i < this.orderHistory.length; i++) { + let cartItems = this.orderHistory[i].products + + for(let j = 0; j < cartItems.length; j++) { + let productRewardPoints = cartItems[j].rewardPoints + + this.rewardPoints += productRewardPoints + } + } + } } module.exports = Customer \ No newline at end of file diff --git a/classes/Product.js b/classes/Product.js index dd05394..1b94050 100644 --- a/classes/Product.js +++ b/classes/Product.js @@ -1,10 +1,11 @@ class Product { - constructor(name, price, description) { + constructor(name, price, description, rewardPoints) { this.name = name this.price = price this.description = description this.inStock = true + this.rewardPoints = rewardPoints } display() { From b073402757079aec0f47abb2d8d24ad0e88d7976 Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Tue, 23 Apr 2024 00:20:28 -0700 Subject: [PATCH 8/8] completed removeItemByName functionality --- classes/Cart.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/classes/Cart.js b/classes/Cart.js index e24dbf1..e85c32b 100644 --- a/classes/Cart.js +++ b/classes/Cart.js @@ -28,6 +28,16 @@ class Cart { this.total = 0 } + + removeItemByName(name) { + for (let i = 0; i < this.products.length; i++) { + let productName = this.products[i].name + + if(productName === name) { + this.products.splice(i, 1) + } + } + } } module.exports = Cart \ No newline at end of file