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/classes/Cart.js b/classes/Cart.js index e69de29..e85c32b 100644 --- a/classes/Cart.js +++ b/classes/Cart.js @@ -0,0 +1,43 @@ +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) + } + + getTotal() { + return this.total + } + + clear(){ + let length = this.products.length; + + this.products.splice(0, length) + 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 diff --git a/classes/Customer.js b/classes/Customer.js index e69de29..3db4e9f 100644 --- a/classes/Customer.js +++ b/classes/Customer.js @@ -0,0 +1,28 @@ +class Customer { + + constructor(name, email, shippingAddress) { + this.name = name + 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 e69de29..1b94050 100644 --- a/classes/Product.js +++ b/classes/Product.js @@ -0,0 +1,17 @@ +class Product { + + constructor(name, price, description, rewardPoints) { + this.name = name + this.price = price + this.description = description + this.inStock = true + this.rewardPoints = rewardPoints + } + + 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..379f260 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,9 @@ // Import Classes Here - - - - - +const Product = require('./classes/Product') +const Cart = require('./classes/Cart') +const Customer = require('./classes/Customer') +const Auth = require('./classes/Auth') 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",