diff --git a/.gitignore b/.gitignore index d3e6c52..a2b6d9c 100644 --- a/.gitignore +++ b/.gitignore @@ -104,7 +104,6 @@ dist # vuepress v2.x temp and cache directory .temp -.cache # Docusaurus cache and generated files .docusaurus @@ -132,3 +131,5 @@ dist .pnp.* /.idea/git_toolbox_blame.xml +.package.json +.package-lock.json \ No newline at end of file diff --git a/database/db_scripts/create_db.sql b/database/db_scripts/create_db.sql index 343c50e..8ce4e11 100644 --- a/database/db_scripts/create_db.sql +++ b/database/db_scripts/create_db.sql @@ -1,10 +1,10 @@ CREATE TABLE `discount` ( - `deleted_at` INT(8) NOT NULL, - `name` VARCHAR(255) NOT NULL, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL, `description` TEXT NOT NULL, `discount_percent` DECIMAL(8, 2) NOT NULL, + `deleted_at` INT(8) NOT NULL, `modified_at` INT(8) NOT NULL, `created_at` INT(8) NOT NULL, `active` BOOLEAN NOT NULL @@ -101,16 +101,16 @@ CREATE TABLE `product_category` ); CREATE TABLE `user` ( - `is_active` BOOLEAN NOT NULL, + `is_active` BOOLEAN NOT NULL DEFAULT '1', `lower_name` VARCHAR(255) NOT NULL, - `email` VARCHAR(255) NOT NULL, - `passwd_hash_algo` VARCHAR(255) NOT NULL, - `modified_at` INT(8) NOT NULL, - `is_admin` BOOLEAN NOT NULL, + `email` VARCHAR(255) NOT NULL DEFAULT 'NONE', + `passwd_hash_algo` VARCHAR(255) NOT NULL DEFAULT 'NONE', + `modified_at` INT(8) NOT NULL DEFAULT '0', + `is_admin` BOOLEAN NOT NULL DEFAULT '0', `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 + `created_at` INT(8) NOT NULL DEFAULT '0', + `passwd` VARCHAR(255) NOT NULL DEFAULT 'NONE' ); ALTER TABLE `user` diff --git a/database/db_scripts/delete_db.sql b/database/db_scripts/delete_db.sql index 29a0cf7..58f5dfd 100644 --- a/database/db_scripts/delete_db.sql +++ b/database/db_scripts/delete_db.sql @@ -20,5 +20,4 @@ drop table if exists user; drop table if exists user_address; -drop table if exists user_payment; - +drop table if exists user_payment; \ No newline at end of file diff --git a/database/db_scripts/fill_database.sql b/database/db_scripts/fill_database.sql new file mode 100644 index 0000000..523ec8b --- /dev/null +++ b/database/db_scripts/fill_database.sql @@ -0,0 +1,15 @@ +CREATE PROCEDURE fill_user_table() +BEGIN + DECLARE i INT DEFAULT 1; + DECLARE emailString CHAR(16) DEFAULT 'test'; + + DELETE FROM webshop.user; + + WHILE i < 100 + DO + SET emailString = CONCAT(emailString, CAST(i AS CHAR(16)), '@test.de'); + INSERT INTO webshop.user(is_active, name, lower_name, email) + VALUES ('1', 'harry', 'potter', emailString); + SET i = i + 1; + END WHILE; +END; \ No newline at end of file diff --git a/database/query/get_users.js b/database/query/get_users.js deleted file mode 100644 index f899821..0000000 --- a/database/query/get_users.js +++ /dev/null @@ -1,17 +0,0 @@ -const mysql = require('mysql'); - -const connection = mysql.createConnection({ - host: "localhost", - user: "root", - password: "", - database: "webshop" -}); - -connection.connect(function (err) { - if (err) throw err; - console.log("Connected to database"); - connection.query("SELECT * FROM user", function (err, result) { - if (err) throw err; - console.log(result); - }) -}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3460d88..016df15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "express": "^4.21.1", "express-session": "^1.18.1", "mysql": "^2.18.1", + "mysql2": "^3.12.0", "path": "^0.12.7" } }, @@ -33,6 +34,15 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, + "node_modules/aws-ssl-profiles": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz", + "integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==", + "license": "MIT", + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/bignumber.js": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", @@ -151,6 +161,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "license": "Apache-2.0", + "engines": { + "node": ">=0.10" + } + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -338,6 +357,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/generate-function": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", + "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", + "license": "MIT", + "dependencies": { + "is-property": "^1.0.2" + } + }, "node_modules/get-intrinsic": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", @@ -450,11 +478,47 @@ "node": ">= 0.10" } }, + "node_modules/is-property": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", + "integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==", + "license": "MIT" + }, "node_modules/isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" }, + "node_modules/long": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==", + "license": "Apache-2.0" + }, + "node_modules/lru-cache": { + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "license": "ISC", + "engines": { + "node": ">=12" + } + }, + "node_modules/lru.min": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.1.tgz", + "integrity": "sha512-FbAj6lXil6t8z4z3j0E5mfRlPzxkySotzUHwRXjlpRh10vc6AI6WN62ehZj82VG7M20rqogJ0GLwar2Xa05a8Q==", + "license": "MIT", + "engines": { + "bun": ">=1.0.0", + "deno": ">=1.30.0", + "node": ">=8.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" + } + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -533,6 +597,59 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, + "node_modules/mysql2": { + "version": "3.12.0", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.12.0.tgz", + "integrity": "sha512-C8fWhVysZoH63tJbX8d10IAoYCyXy4fdRFz2Ihrt9jtPILYynFEKUUzpp1U7qxzDc3tMbotvaBH+sl6bFnGZiw==", + "license": "MIT", + "dependencies": { + "aws-ssl-profiles": "^1.1.1", + "denque": "^2.1.0", + "generate-function": "^2.3.1", + "iconv-lite": "^0.6.3", + "long": "^5.2.1", + "lru.min": "^1.0.0", + "named-placeholders": "^1.1.3", + "seq-queue": "^0.0.5", + "sqlstring": "^2.3.2" + }, + "engines": { + "node": ">= 8.0" + } + }, + "node_modules/mysql2/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/mysql2/node_modules/sqlstring": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", + "integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/named-placeholders": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz", + "integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==", + "license": "MIT", + "dependencies": { + "lru-cache": "^7.14.1" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", @@ -741,6 +858,11 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, + "node_modules/seq-queue": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz", + "integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q==" + }, "node_modules/serve-static": { "version": "1.16.2", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz", diff --git a/package.json b/package.json index 27b6f65..74a3901 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "express": "^4.21.1", "express-session": "^1.18.1", "mysql": "^2.18.1", + "mysql2": "^3.12.0", "path": "^0.12.7" } } diff --git a/process.env b/process.env index 840a0a6..237aa94 100644 --- a/process.env +++ b/process.env @@ -2,7 +2,7 @@ APP_PORT=3000 # configuration for db access -DB_HOST=172.0.0.1:3306 +DB_HOST=localhost DB_USER=root DB_PASSWORD= -DB_DATABASE= +DB_DATABASE=webshop diff --git a/scripts/modules/db-connect.js b/scripts/modules/db-connect.js index 00b0540..97419f7 100644 --- a/scripts/modules/db-connect.js +++ b/scripts/modules/db-connect.js @@ -1,5 +1,7 @@ const mysql = require('mysql2'); -require('dotenv').config({path:'process.env'}); +require('dotenv').config({path: 'C:/Daten/Webshop/process.env'}); +//to-do: '.env' Dateien aus anderen Directories aufrufen ohne absoluten Pfad +// require("dotenv").config({path:'C:/Daten/Webshop/process.env'}) const connection = mysql.createConnection({ host : process.env.DB_HOST, diff --git a/scripts/modules/login.js b/scripts/modules/login.js new file mode 100644 index 0000000..454dccc --- /dev/null +++ b/scripts/modules/login.js @@ -0,0 +1,12 @@ +require('mysql2') + +let userInput = "test1" + +let appRoot = require('app-root-path') +let dbConnect = require(appRoot + '/scripts/modules/db-connect.js') + +dbConnect.query("SELECT * FROM webshop.user WHERE email = " + "'" + userInput + "'", function (err, result) { + if (err) throw err + console.log(result) +}) +dbConnect.end() \ No newline at end of file diff --git a/scripts/query/get_users.js b/scripts/query/get_users.js new file mode 100644 index 0000000..72caeef --- /dev/null +++ b/scripts/query/get_users.js @@ -0,0 +1,17 @@ +const mysql = require('mysql'); + +const connection = mysql.createConnection({ + host: "localhost", + user: "root", + password: "", + database: "webshop" +}) + +connection.connect(function (err) { + if (err) throw err + console.log("Connected to database") + connection.query("SELECT * FROM webshop.user WHERE ID = 15", function (err, result) { + if (err) throw err + console.log(result) + }) +}) \ No newline at end of file