From cb63b092b8f98c7d9aa147cb9416a26f287161af Mon Sep 17 00:00:00 2001 From: Hector Pulido <87735459+hepulido@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:51:17 -0500 Subject: [PATCH 1/4] created first test (#1) --- classes/Product.js | 15 +++++++++++++++ index.js | 5 +++-- package-lock.json | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/classes/Product.js b/classes/Product.js index e69de29..b6c13de 100644 --- a/classes/Product.js +++ b/classes/Product.js @@ -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; diff --git a/index.js b/index.js index efad601..a98e822 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,8 @@ // Import Classes Here +const Product = require("./classes/Product.js") - - +const carrots = new Product("Carrots", 4, "Bushel of carrots that have been freshly harvested for you"); +console.log(carrots); 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", From af299e054abeb3a7055b6a968f34c9a1e9ba5c49 Mon Sep 17 00:00:00 2001 From: Kevin Dutzy <35307720+Keffdu@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:04:37 -0700 Subject: [PATCH 2/4] created cart class, tests passing (#2) --- classes/Cart.js | 19 +++++++++++++++++++ index.js | 6 +----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/classes/Cart.js b/classes/Cart.js index e69de29..fcac07e 100644 --- a/classes/Cart.js +++ b/classes/Cart.js @@ -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 \ No newline at end of file diff --git a/index.js b/index.js index a98e822..6b42c5f 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,6 @@ // Import Classes Here const Product = require("./classes/Product.js") - -const carrots = new Product("Carrots", 4, "Bushel of carrots that have been freshly harvested for you"); -console.log(carrots); - - +const Cart = require("./classes/Cart.js") From 537f94b34f2b90ad89dbf12b2a515211a6b2f76b Mon Sep 17 00:00:00 2001 From: Kaikaine <37594711+Kaikaine@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:15:08 -0600 Subject: [PATCH 3/4] added Customer class (#3) --- classes/Customer.js | 14 +++++++++++ index.js | 61 +++++++++++++++++++-------------------------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/classes/Customer.js b/classes/Customer.js index e69de29..1826c19 100644 --- a/classes/Customer.js +++ b/classes/Customer.js @@ -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; diff --git a/index.js b/index.js index 6b42c5f..416e736 100644 --- a/index.js +++ b/index.js @@ -1,46 +1,35 @@ // Import Classes Here -const Product = require("./classes/Product.js") -const Cart = require("./classes/Cart.js") - - - - +const Product = require("./classes/Product.js"); +const Cart = require("./classes/Cart.js"); +const Customer = require("./classes/Customer.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){ - -} \ No newline at end of file + module.exports = { + Product, + Cart, + Customer, + Auth, + }; +} catch (e) {} From 0b02bb22142ff3a7b00b70f59ed80d4acb6bb420 Mon Sep 17 00:00:00 2001 From: hector Date: Mon, 6 Nov 2023 17:26:07 -0500 Subject: [PATCH 4/4] Created Auth test done --- classes/Auth.js | 25 +++++++++++++++++++++++++ index.js | 1 + 2 files changed, 26 insertions(+) diff --git a/classes/Auth.js b/classes/Auth.js index e69de29..6843903 100644 --- a/classes/Auth.js +++ b/classes/Auth.js @@ -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; \ No newline at end of file diff --git a/index.js b/index.js index 416e736..c28e1b7 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ 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 {