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
25 changes: 25 additions & 0 deletions classes/Auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const Customer = require("./Customer.js");

class Auth {
constructor(customers = []) {
this.customers = customers
}
register(name, email, shippingAddress) {
let customer1 = new Customer(name, email, shippingAddress);
this.customers.push(customer1);
}
login(email) {
let result = null
this.customers.map((customer) => {
if (email === customer.email) {
result = customer

}

})
return result


}
}
module.exports = Auth;
19 changes: 19 additions & 0 deletions classes/Cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Cart {
constructor(products = [], total = 0) {
this.products = products,
this.total = total
}

addProduct(product) {
this.products.push(product)
this.total += product.price
}

removeProduct(i) {
let product = this.products[i]
this.total -= product.price
this.products.splice(i, 1)
}
}

module.exports = Cart
14 changes: 14 additions & 0 deletions classes/Customer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Customer {
constructor(name, email, shippingAddress, orderHistory = []) {
this.name = name;
this.email = email;
this.shippingAddress = shippingAddress;
this.orderHistory = orderHistory;
}

addToOrderHistory(cart) {
this.orderHistory.push(cart);
}
}

module.exports = Customer;
15 changes: 15 additions & 0 deletions classes/Product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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;
65 changes: 26 additions & 39 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,36 @@
// Import Classes Here









const Product = require("./classes/Product.js");
const Cart = require("./classes/Cart.js");
const Customer = require("./classes/Customer.js");
const Auth = require("./classes/Auth.js")

// DO NOT EDIT BELOW THIS LINE
try {
module.exports = {
Product,
}
} catch(e){

}
module.exports = {
Product,
};
} catch (e) {}

try {
module.exports = {
Product,
Cart
}
} catch(e){

}
module.exports = {
Product,
Cart,
};
} catch (e) {}

try {
module.exports = {
Product,
Cart,
Customer
}
} catch(e){

}
module.exports = {
Product,
Cart,
Customer,
};
} catch (e) {}

try {
module.exports = {
Product,
Cart,
Customer,
Auth
}
} catch(e){

}
module.exports = {
Product,
Cart,
Customer,
Auth,
};
} catch (e) {}
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.