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

class Auth {
constructor() {
this.customers = [];
}

register(name, email, shippingAddress) {
const newCustomer = new Customer(name, email, shippingAddress);
this.customers.push(newCustomer);
return newCustomer;
}

login(email) {
return this.customers.find((customer) => customer.email === email) || null;
}
}

module.exports = Auth;
23 changes: 23 additions & 0 deletions classes/Cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const Product = require("./Product");

class Cart {
constructor() {
this.products = [];
this.total = 0;
}

addProduct(product) {
if (product instanceof Product) {
this.products.push(product);
this.total += product.price;
}
}

removeProduct(i) {
if (i > this.products.length) return "Product is no longer in stock";
this.total -= this.products[i].price;
this.products.splice(i, 1);
}
}

module.exports = Cart;
18 changes: 18 additions & 0 deletions classes/Customer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const Cart = require("./Cart");

class Customer {
constructor(name, email, shippingAddress) {
this.name = name;
this.email = email;
this.shippingAddress = shippingAddress;
this.orderHistory = [];
}

addToOrderHistory(cart) {
if (cart instanceof Cart) {
this.orderHistory.push(cart);
}
}
}

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

// 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.