Merge pull request 'folder-structure' (#10) from folder-structure into develop

Reviewed-on: #10
This commit is contained in:
Fabian 2024-11-19 07:31:14 +00:00
commit 870aebcc70
4 changed files with 175 additions and 137 deletions

View File

@ -1,144 +1,170 @@
CREATE DATABASE 'webshop' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci; CREATE TABLE `discount`
-- example link: https://fabric.inc/blog/commerce/ecommerce-database-design-example
CREATE TABLE 'user'
( (
id int NOT NULL AUTO_INCREMENT, `deleted_at` INT(8) NOT NULL,
lower_name varchar(255), `name` VARCHAR(255) NOT NULL,
name varchar(255) NOT NULL, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
full_name varchar(255), `description` TEXT NOT NULL,
email varchar(255) NOT NULL, `discount_percent` DECIMAL(8, 2) NOT NULL,
passwd varchar(255), `modified_at` INT(8) NOT NULL,
passwd_hash_algo varchar(255), `created_at` INT(8) NOT NULL,
is_admin bool, `active` BOOLEAN NOT NULL
created_at timestamp,
modified_at timestamp,
PRIMARY KEY (id),
UNIQUE (email, passwd)
); );
CREATE TABLE `user_address`
CREATE TABLE 'user_address'
( (
id int, `address_line1` VARCHAR(255) NOT NULL,
user_id int, `city` VARCHAR(255) NOT NULL,
address_line1 varchar(255), `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
address_line2 varchar(255), `country` VARCHAR(2) NOT NULL,
city varchar(255), `user_id` INT UNSIGNED NOT NULL,
postal_code varchar(255), `mobile` VARCHAR(255) NOT NULL,
country varchar(2), `postal_code` INT NOT NULL,
telephone varchar(255), `address_line2` VARCHAR(255) NOT NULL,
mobile varchar(255), `telephone` VARCHAR(255) NOT NULL
UNIQUE (telephone, mobile, user_id)
); );
ALTER TABLE
CREATE TABLE 'user_payment' `user_address`
ADD UNIQUE `user_address_mobile_unique` (`mobile`);
ALTER TABLE
`user_address`
ADD UNIQUE `user_address_telephone_unique` (`telephone`);
CREATE TABLE `product_inventory`
( (
id int, `created_at` INT(8) NOT NULL,
user_id int, `modified_at` INT(8) NOT NULL,
payment_type varchar(255), `quantity` INT NOT NULL,
provider varchar(255), `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
account_no int, `deleted_at` INT(8) NOT NULL
expiry date,
UNIQUE (user_id)
); );
CREATE TABLE `payment_details`
CREATE TABLE 'shopping_session'
( (
id int, `order_id` INT NOT NULL,
user_id varchar(255), `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
total decimal, `status` VARCHAR(255) NOT NULL,
created_at timestamp, `provider` VARCHAR(255) NOT NULL,
modified_at timestamp, `modified_at` INT(8) NOT NULL,
UNIQUE (user_id) `amount` INT NOT NULL,
`created_at` INT(8) NOT NULL
); );
CREATE TABLE `order_details`
CREATE TABLE 'cart_item'
( (
id int, `payment_id` INT UNSIGNED NOT NULL,
session_id int, `total` DECIMAL(8, 2) NOT NULL,
product_id int, `modified_at` INT(8) NOT NULL,
quantity int, `created_at` INT(8) NOT NULL,
created_at timestamp, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
modified_at timestamp `user_id` INT UNSIGNED NOT NULL
); );
CREATE TABLE `order_items`
CREATE TABLE 'payment_details'
( (
id int, `modified_at` INT(8) NOT NULL,
order_id int, `user_id` BIGINT NOT NULL,
amount int, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
provider varchar(255), `quantity` INT NOT NULL,
status varchar(255), `order_id` INT UNSIGNED NOT NULL,
created_at timestamp, `created_at` INT(8) NOT NULL,
modified_at timestamp `product_id` INT UNSIGNED NOT NULL
); );
CREATE TABLE `user_payment`
CREATE TABLE 'order_items'
( (
id int, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
order_id int, `provider` VARCHAR(255) NOT NULL,
product_id int, `account_no` VARCHAR(255) NOT NULL,
quantity int, `expiry` DATE NOT NULL,
created_at timestamp, `payment_type` VARCHAR(255) NOT NULL,
modified_at timestamp `user_id` INT UNSIGNED NOT NULL
); );
CREATE TABLE `product`
CREATE TABLE 'order_details'
( (
id int, `category_id` INT UNSIGNED NOT NULL,
user_id varchar(255), `model` VARCHAR(255) NOT NULL,
total decimal, `color` VARCHAR(255) NOT NULL,
payment_id int, `engine` VARCHAR(255) NOT NULL,
created_at timestamp, `description` TEXT NOT NULL,
modified_at timestamp `make` VARCHAR(255) NOT NULL,
`inventory_id` INT UNSIGNED NOT NULL,
`discount_id` INT UNSIGNED NOT NULL,
`created_at` INT(8) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`deleted_at` INT(8) NOT NULL,
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`modified_at` INT(8) NOT NULL,
`price` DECIMAL(8, 2) NOT NULL
); );
CREATE TABLE `product_category`
CREATE TABLE 'product'
( (
id int NOT NULL, `created_at` INT(8) NOT NULL,
name varchar(255), `name` VARCHAR(255) NOT NULL,
color varchar(255), `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
make varchar(255), `modified_at` INT(8) NOT NULL,
model varchar(255) NOT NULL, `desc` TEXT NOT NULL,
engine varchar(255), `deleted_at` INT(8) NOT NULL
description text,
category_id int,
inventory_id int,
price decimal,
discount_id int,
created_at timestamp,
modified_at timestamp,
deleted_at timestamp
); );
CREATE TABLE `user`
CREATE TABLE 'product_category'
( (
id int, `is_active` BOOLEAN NOT NULL,
name varchar(255), `lower_name` VARCHAR(255) NOT NULL,
description text, `email` VARCHAR(255) NOT NULL,
created_at timestamp, `passwd_hash_algo` VARCHAR(255) NOT NULL,
modified_at timestamp, `modified_at` INT(8) NOT NULL,
deleted_at timestamp `is_admin` BOOLEAN NOT NULL,
`name` VARCHAR(255) NOT NULL,
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`created_at` INT(8) NOT NULL,
`passwd` VARCHAR(255) NOT NULL
); );
ALTER TABLE
CREATE TABLE 'product_inventory' `user`
ADD UNIQUE `user_email_unique` (`email`);
CREATE TABLE `shopping_session`
( (
id int, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
quantity int, `created_at` INT(8) NOT NULL,
created_at timestamp, `user_id` INT UNSIGNED NOT NULL,
modified_at timestamp, `modified_at` INT(8) NOT NULL,
deleted_at timestamp `total` DECIMAL(8, 2) NOT NULL
); );
CREATE TABLE `cart_item`
CREATE TABLE 'discount'
( (
id int, `product_id` INT UNSIGNED NOT NULL,
name varchar(255), `session_id` INT UNSIGNED NOT NULL,
description text, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
discount_percent decimal, `created_at` INT(8) NOT NULL,
active bool, `modified_at` INT(8) NOT NULL,
created_at timestamp, `quantity` INT NOT NULL
modified_at timestamp, );
deleted_at timestamp ALTER TABLE
) `product`
ADD CONSTRAINT `product_inventory_id_foreign` FOREIGN KEY (`inventory_id`) REFERENCES `product_inventory` (`id`);
ALTER TABLE
`order_items`
ADD CONSTRAINT `order_items_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `order_details` (`id`);
ALTER TABLE
`product`
ADD CONSTRAINT `product_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `product_category` (`id`);
ALTER TABLE
`order_details`
ADD CONSTRAINT `order_details_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);
ALTER TABLE
`cart_item`
ADD CONSTRAINT `cart_item_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`);
ALTER TABLE
`order_items`
ADD CONSTRAINT `order_items_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`);
ALTER TABLE
`user_address`
ADD CONSTRAINT `user_address_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);
ALTER TABLE
`order_details`
ADD CONSTRAINT `order_details_payment_id_foreign` FOREIGN KEY (`payment_id`) REFERENCES `payment_details` (`id`);
ALTER TABLE
`product`
ADD CONSTRAINT `product_discount_id_foreign` FOREIGN KEY (`discount_id`) REFERENCES `discount` (`id`);
ALTER TABLE
`user_payment`
ADD CONSTRAINT `user_payment_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);
ALTER TABLE
`shopping_session`
ADD CONSTRAINT `shopping_session_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);
ALTER TABLE
`cart_item`
ADD CONSTRAINT `cart_item_session_id_foreign` FOREIGN KEY (`session_id`) REFERENCES `shopping_session` (`id`);

View File

@ -1,12 +1,24 @@
DROP TABLE IF EXISTS 'user'; drop table if exists cart_item;
DROP TABLE IF EXISTS 'user_address';
DROP TABLE IF EXISTS 'user_payment'; drop table if exists discount;
DROP TABLE IF EXISTS 'shopping_session';
DROP TABLE IF EXISTS 'cart_item'; drop table if exists oder_items;
DROP TABLE IF EXISTS 'payment_details';
DROP TABLE IF EXISTS 'order_items'; drop table if exists order_details;
DROP TABLE IF EXISTS 'order_details';
DROP TABLE IF EXISTS 'product'; drop table if exists payment_details;
DROP TABLE IF EXISTS 'product_category';
DROP TABLE IF EXISTS 'product_inventory'; drop table if exists product;
DROP TABLE IF EXISTS 'discount';
drop table if exists product_category;
drop table if exists product_inventory;
drop table if exists shopping_session;
drop table if exists user;
drop table if exists user_address;
drop table if exists user_payment;

View File

@ -3,14 +3,14 @@ const mysql = require('mysql');
const connection = mysql.createConnection({ const connection = mysql.createConnection({
host: "localhost", host: "localhost",
user: "root", user: "root",
password: "root", password: "",
database: "webshop" database: "webshop"
}); });
connection.connect(function (err) { connection.connect(function (err) {
if (err) throw err; if (err) throw err;
console.log("Connected to database"); console.log("Connected to database");
connection.query("SELECT * FROM users", function (err, result) { connection.query("SELECT * FROM user", function (err, result) {
if (err) throw err; if (err) throw err;
console.log(result); console.log(result);
}) })

View File

@ -2,6 +2,6 @@ let nameEl = document.getElementById("loginMail");
let passwordEl = document.getElementById("loginPassword"); let passwordEl = document.getElementById("loginPassword");
function login() { function login() {
//console.log(nameEl.value) console.log(nameEl.value)
//console.log(passwordEl.value) console.log(passwordEl.value)
} }