diff --git a/client/public/auth.mjs b/client/public/auth.mjs index ba36520..d7977c4 100644 --- a/client/public/auth.mjs +++ b/client/public/auth.mjs @@ -58,15 +58,13 @@ export async function InitAuth0() { const fetchOptions = { method: 'GET', + // bear hug headers: { Authorization: `Bearer ${token}` }, }; const res = await fetch('/api/auth/login', fetchOptions).then(res => res.json()); - console.log(res); localStorage.setItem('admin', res.user.admin); - - // do stuff } } diff --git a/client/public/basket/index.html b/client/public/basket/index.html index e6f6d80..5fe5670 100644 --- a/client/public/basket/index.html +++ b/client/public/basket/index.html @@ -1,6 +1,6 @@ - LegoLog! + LegoLog Basket @@ -22,12 +22,8 @@ - - - - diff --git a/client/public/checkout/index.html b/client/public/checkout/index.html new file mode 100644 index 0000000..911edd1 --- /dev/null +++ b/client/public/checkout/index.html @@ -0,0 +1,36 @@ + + + LegoLog Checkout + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/public/components/basket.mjs b/client/public/components/basket.mjs index 2cf674a..4b6ab29 100644 --- a/client/public/components/basket.mjs +++ b/client/public/components/basket.mjs @@ -68,7 +68,7 @@ class Basket extends Component { `, diff --git a/client/public/components/checkout.mjs b/client/public/components/checkout.mjs new file mode 100644 index 0000000..6095c74 --- /dev/null +++ b/client/public/components/checkout.mjs @@ -0,0 +1,70 @@ +import { GetBasketTotalPrice } from './basket-popout.mjs'; +import { RegisterComponent, Component } from './components.mjs'; + +class Checkout extends Component { + static __IDENTIFY() { return 'checkout'; } + + constructor() { + super(Checkout); + } + + async OnMount() { + this.setState({ + total: parseFloat(await GetBasketTotalPrice()).toFixed(2), + }); + } + + Render() { + return { + template: /* html */` +
+
+ Checkout + Total: £{this.state.total} +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + + +
+ `, + style: ` + .checkout { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; + } + + + .checkout-form-row-input { + border: 1px solid #79747E; + box-sizing: border-box; + border-radius: 4px; + } + `, + }; + } + + + OnRender() { + } +} + +RegisterComponent(Checkout); diff --git a/client/public/components/navbar.mjs b/client/public/components/navbar.mjs index 6754ffd..199a3fb 100644 --- a/client/public/components/navbar.mjs +++ b/client/public/components/navbar.mjs @@ -1,6 +1,6 @@ import { RegisterComponent, Component, SideLoad } from './components.mjs'; import { LoginSignup, Signout } from '../auth.mjs'; -import * as StorageListener from '../localStorage-listener.mjs'; +import * as StorageListener from '../localstorage-listener.mjs'; // due to peculiarities in asynchronus loading of components, // we need to have this remember the state of the logged in user @@ -46,13 +46,19 @@ class NavBar extends Component { return; } + if (localStorage.admin === 'true' || localStorage.admin === true) { + this.root.querySelector('.stock-mode').style.display = 'flex'; + } else { + this.root.querySelector('.stock-mode').style.display = 'none'; + } + const account = this.root.querySelector('.account-item'); // doing this with proper dom manipulation wasn't working account.innerHTML = ` ${localStorage.user}▾ `; @@ -76,12 +82,6 @@ class NavBar extends Component { this.SetupHamburger(); this.OnLogin(); - if (localStorage.admin === true) { - this.root.querySelector('.stock-mode').style.display = 'flex'; - } else { - this.root.querySelector('.stock-mode').style.display = 'none'; - } - StorageListener.ListenOnKey('admin', (e) => { const admin = e.value; if (admin) { @@ -91,8 +91,9 @@ class NavBar extends Component { } }); - this.root.querySelector('stock-slider').addEventListener('change', (e) => { - console.log(e); + this.root.querySelector('.stock-slider').addEventListener('change', (e) => { + const stock = e.target.checked; + localStorage.setItem('stock-mode', stock); }); // setup log in button diff --git a/client/public/featured/index.html b/client/public/featured/index.html index cf4c118..6bf8fb7 100644 --- a/client/public/featured/index.html +++ b/client/public/featured/index.html @@ -1,6 +1,6 @@ - LegoLog: Featured Sets + LegoLog Featured Sets @@ -22,11 +22,9 @@ - - diff --git a/client/public/index.mjs b/client/public/index.mjs index c1df717..0f4c110 100644 --- a/client/public/index.mjs +++ b/client/public/index.mjs @@ -1,7 +1,7 @@ // import { RendererPreInit, BrickRenderer } from './brick-renderer/index.mjs'; import { InitAuth0 } from './auth.mjs'; -import * as StorageListener from './localStorage-listener.mjs'; +import * as StorageListener from './localstorage-listener.mjs'; function main() { InitAuth0(); diff --git a/client/public/localStorage-listener.mjs b/client/public/localStorage-listener.mjs index b8f89cb..f92ec20 100644 --- a/client/public/localStorage-listener.mjs +++ b/client/public/localStorage-listener.mjs @@ -1,4 +1,8 @@ - +// this was made for the purpose of being able to listen to changes in localStorage +// because i needed that to see if the user was admin or not to display certain elements +// in the navbar +// HOWEVERRRRRRRRRRRRRRRRR it would have been like SUPER SUPER useful when making the +// basket. hey whatever it's done now. TODO for a future refractor i guess... const CallbackKeyArray = []; const OldSetItem = localStorage.setItem; @@ -19,6 +23,7 @@ function OnStorage(event) { } export function Init() { + // WHAAAAAAAAAAAAAAAAAAAAAT localStorage.setItem = function (key, value) { OldSetItem.apply(this, arguments); OnStorage({ diff --git a/client/public/product/index.html b/client/public/product/index.html index 4878c78..27a768f 100644 --- a/client/public/product/index.html +++ b/client/public/product/index.html @@ -1,6 +1,6 @@ - LegoLog! + LegoLog Product Page @@ -18,7 +18,6 @@ - diff --git a/client/public/search/index.html b/client/public/search/index.html index 610696d..36e5cb5 100644 --- a/client/public/search/index.html +++ b/client/public/search/index.html @@ -1,6 +1,6 @@ - LegoLog: Featured Sets + LegoLog Search Results diff --git a/db/dump.sql b/db/dump.sql index 823cf10..928b6b7 100644 --- a/db/dump.sql +++ b/db/dump.sql @@ -16539,3 +16539,7 @@ INSERT INTO lego_set_inventory (set_id, stock, price, new_price, last_updated) V -- admin user INSERT INTO users (id, email, admin, nickname, date_created, date_updated) VALUES ('62686cdead060b0068fe7d38', 'systemadmin@legolog.com', true, 'systemadmin', NOW(), NOW()); + +-- offer code + +INSERT INTO offer_code (code, discount, discount_type, min_order_value, type, expiry_date) VALUES ('LEGO10', 10, 1, 10.00, 'set', '2022-06-10'); diff --git a/db/schema.sql b/db/schema.sql index e17b183..696a61a 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -90,22 +90,34 @@ CREATE TABLE IF NOT EXISTS users ( date_updated TIMESTAMP WITHOUT TIME ZONE NOT NULL ); -CREATE TABLE IF NOT EXISTS orders ( +CREATE TABLE IF NOT EXISTS order_log ( id VARCHAR (50) NOT NULL PRIMARY KEY, - user_id VARCHAR (50) NOT NULL, + user_id VARCHAR (50) NOT NULL, -- 0 if guest + subtotal DECIMAL NOT NULL, date_placed TIMESTAMP WITHOUT TIME ZONE NOT NULL, FOREIGN KEY ( user_id ) REFERENCES users( id ) ); -CREATE TABLE IF NOT EXISTS order_items ( +CREATE TABLE IF NOT EXISTS order_item ( order_id VARCHAR (50) NOT NULL, brick_id VARCHAR (50), -- colour is a modifier for the brick brick_colour INT, set_id VARCHAR (50), amount INT NOT NULL, - FOREIGN KEY ( order_id ) REFERENCES orders( id ), + price_paid DECIMAL NOT NULL, + FOREIGN KEY ( order_id ) REFERENCES order_log( id ), FOREIGN KEY ( brick_id ) REFERENCES lego_brick( id ), FOREIGN KEY ( brick_colour ) REFERENCES lego_brick_colour( id ), FOREIGN KEY ( set_id ) REFERENCES lego_set( id ) ); + +CREATE TABLE IF NOT EXISTS offer_code ( + id SERIAL NOT NULL PRIMARY KEY, + code TEXT NOT NULL, + discount DECIMAL NOT NULL, -- percentage or fixed amount + discount_type INT NOT NULL, -- 0 = percentage, 1 = fixed amount + min_order_value DECIMAL NOT NULL, + type TEXT NOT NULL, -- set or brick + expiry_date TIMESTAMP WITHOUT TIME ZONE NOT NULL +); diff --git a/src/routes/helpers.js b/src/routes/helpers.js index e117dfa..a2e65fd 100644 --- a/src/routes/helpers.js +++ b/src/routes/helpers.js @@ -2,8 +2,7 @@ const BrickController = require('../controllers/brick-controller.js'); const SetController = require('../controllers/set-controller.js'); const Logger = require('../logger.js'); -// AppEng Deadline -const EndDate = new Date(1651269600 * 1000); +const EndDate = new Date('2022-06-10T00:00:00.000Z'); function Special(req, res) { res.send({ @@ -15,6 +14,8 @@ function Special(req, res) { } async function CalculateBasketPrice(req, res) { + // and here we remmeber the c days where you had to declare all + // of your variables at the top of the scope *ah* const setList = []; const setQuantities = []; const brickList = [];