diff --git a/classes/Auth.js b/classes/Auth.js index e69de29..11f6fec 100644 --- a/classes/Auth.js +++ b/classes/Auth.js @@ -0,0 +1,16 @@ +const Customer = require("./Customer.js") + +class Auth{ + constructor(){ + this.customers = [] + } + register(name, email, shippingAddress){ + let newCustomer = new Customer(name, email, shippingAddress) + this.customers.push(newCustomer) + } + login(email){ + return this.customers.find(customer => customer.email === email) || null + } +} + +module.exports = Auth \ No newline at end of file diff --git a/classes/Cart.js b/classes/Cart.js index e69de29..c2fdf39 100644 --- a/classes/Cart.js +++ b/classes/Cart.js @@ -0,0 +1,18 @@ +class Cart{ + constructor(){ + this.products = [] + this.total = 0 + } + addProduct (product){ + this.products.push(product) + this.total += product.price + } + removeProduct(i){ + if(i >= 0 && i < this.products.length){ + const removeProduct = this.products.splice(i, 1)[0] + this.total -= removeProduct.price + } + } +} + +module.exports = Cart \ No newline at end of file diff --git a/classes/Customer.js b/classes/Customer.js index e69de29..673f306 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/classes/Product.js b/classes/Product.js index e69de29..105d8dc 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