Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions classes/Auth.js
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions classes/Cart.js
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions classes/Customer.js
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions classes/Product.js
Original file line number Diff line number Diff line change
@@ -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
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -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')



Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.