forked from fr/deguapp
		
	upload
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								backend/.db.txt.swp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								backend/.db.txt.swp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										59
									
								
								backend/.githooks/pre-push
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										59
									
								
								backend/.githooks/pre-push
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,59 @@
 | 
				
			|||||||
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# @link https://gist.github.com/mattscilipoti/8424018
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Called by "git push" after it has checked the remote status,
 | 
				
			||||||
 | 
					# but before anything has been pushed.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# If this script exits with a non-zero status nothing will be pushed.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Steps to install, from the root directory of your repo...
 | 
				
			||||||
 | 
					# 1. Copy the file into your repo at `.git/hooks/pre-push`
 | 
				
			||||||
 | 
					# 2. Set executable permissions, run `chmod +x .git/hooks/pre-push`
 | 
				
			||||||
 | 
					# 3. Or, use `rake hooks:pre_push` to install
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Try a push to master, you should get a message `*** [Policy] Never push code directly to...`
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# The commands below will not be allowed...
 | 
				
			||||||
 | 
					# `git push origin master`
 | 
				
			||||||
 | 
					# `git push --force origin master`
 | 
				
			||||||
 | 
					# `git push --delete origin master`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					protected_branch='master'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					policy="\n\n[Policy] Never push code directly to the "$protected_branch" branch! (Prevented with pre-push hook.)\n\n"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					push_command=$(ps -ocommand= -p $PPID)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					is_destructive='force|delete|\-f'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					will_remove_protected_branch=':'$protected_branch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					do_exit(){
 | 
				
			||||||
 | 
					  echo -e $policy
 | 
				
			||||||
 | 
					  exit 1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [[ $push_command =~ $is_destructive ]] && [ $current_branch = $protected_branch ]; then
 | 
				
			||||||
 | 
					  do_exit
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [[ $push_command =~ $is_destructive ]] && [[ $push_command =~ $protected_branch ]]; then
 | 
				
			||||||
 | 
					  do_exit
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [[ $push_command =~ $will_remove_protected_branch ]]; then
 | 
				
			||||||
 | 
					  do_exit
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Prevent ALL pushes to protected_branch
 | 
				
			||||||
 | 
					if [[ $push_command =~ $protected_branch ]] || [ $current_branch = $protected_branch ]; then
 | 
				
			||||||
 | 
					  do_exit
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unset do_exit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit 0
 | 
				
			||||||
							
								
								
									
										2
									
								
								backend/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								backend/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					node_modules/
 | 
				
			||||||
 | 
					.env
 | 
				
			||||||
							
								
								
									
										15
									
								
								backend/.prettierrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								backend/.prettierrc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
						"tabWidth": 4,
 | 
				
			||||||
 | 
						"useTabs": true,
 | 
				
			||||||
 | 
						"singleQuote": true,
 | 
				
			||||||
 | 
						"semi": false,
 | 
				
			||||||
 | 
						"trailingComma": "none",
 | 
				
			||||||
 | 
						"jsxSingleQuote": true,
 | 
				
			||||||
 | 
						"jsxBracketSameLine": true,
 | 
				
			||||||
 | 
						"printWidth": 200,
 | 
				
			||||||
 | 
						"bracketSpacing": true,
 | 
				
			||||||
 | 
						"vueIndentScriptAndStyle": true,
 | 
				
			||||||
 | 
						"arrowParens": "always",
 | 
				
			||||||
 | 
						"bracketSameLine": false,
 | 
				
			||||||
 | 
					    "endOfLine": "lf"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1
									
								
								backend/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								backend/README.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					# New Project
 | 
				
			||||||
							
								
								
									
										31
									
								
								backend/db.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								backend/db.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					User
 | 
				
			||||||
 | 
						name
 | 
				
			||||||
 | 
						email
 | 
				
			||||||
 | 
						password
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Beer
 | 
				
			||||||
 | 
						brand
 | 
				
			||||||
 | 
						name
 | 
				
			||||||
 | 
						degree
 | 
				
			||||||
 | 
						packaging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Events
 | 
				
			||||||
 | 
						date
 | 
				
			||||||
 | 
						name
 | 
				
			||||||
 | 
						participants
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Review
 | 
				
			||||||
 | 
						logo
 | 
				
			||||||
 | 
						aroma
 | 
				
			||||||
 | 
						foam
 | 
				
			||||||
 | 
						color
 | 
				
			||||||
 | 
						bitterness
 | 
				
			||||||
 | 
						sweetness
 | 
				
			||||||
 | 
						note
 | 
				
			||||||
 | 
						again
 | 
				
			||||||
 | 
						overall_rating
 | 
				
			||||||
 | 
						final_rating
 | 
				
			||||||
 | 
						date
 | 
				
			||||||
 | 
						participants
 | 
				
			||||||
 | 
						signature
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										12
									
								
								backend/norkconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								backend/norkconfig.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "project_name": "deguapp",
 | 
				
			||||||
 | 
					  "lang": "ts",
 | 
				
			||||||
 | 
					  "author": "Filip Rojek",
 | 
				
			||||||
 | 
					  "database": {
 | 
				
			||||||
 | 
					    "db": "mongodb",
 | 
				
			||||||
 | 
					    "orm": "mongoose"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "website": "http://filiprojek.cz/",
 | 
				
			||||||
 | 
					  "email": "filip@filiprojek.cz",
 | 
				
			||||||
 | 
					  "version": "3.0.5"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										7161
									
								
								backend/package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										7161
									
								
								backend/package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										73
									
								
								backend/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								backend/package.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,73 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "name": "deguapp",
 | 
				
			||||||
 | 
					  "version": "1.0.0",
 | 
				
			||||||
 | 
					  "description": "",
 | 
				
			||||||
 | 
					  "main": "dist/server.js",
 | 
				
			||||||
 | 
					  "private": "true",
 | 
				
			||||||
 | 
					  "keywords": [],
 | 
				
			||||||
 | 
					  "author": "Filip Rojek <filip@filiprojek.cz> (http://filiprojek.cz/)",
 | 
				
			||||||
 | 
					  "repository": "github:username/repo",
 | 
				
			||||||
 | 
					  "license": "ISC",
 | 
				
			||||||
 | 
					  "scripts": {
 | 
				
			||||||
 | 
					    "start": "node dist/server.js",
 | 
				
			||||||
 | 
					    "start:dev": "nodemon src/server.ts",
 | 
				
			||||||
 | 
					    "test": "jest",
 | 
				
			||||||
 | 
					    "clean": "rimraf dist/*",
 | 
				
			||||||
 | 
					    "copy-assets": "npx ts-node src/utils/copyAssets",
 | 
				
			||||||
 | 
					    "tsc": "tsc -p .",
 | 
				
			||||||
 | 
					    "build": "npm-run-all clean tsc copy-assets",
 | 
				
			||||||
 | 
					    "format": "npx prettier --write ."
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "dependencies": {
 | 
				
			||||||
 | 
					    "colors": "1.4.0",
 | 
				
			||||||
 | 
					    "cookie-parser": "^1.4.5",
 | 
				
			||||||
 | 
					    "cors": "^2.8.5",
 | 
				
			||||||
 | 
					    "dotenv": "^8.2.0",
 | 
				
			||||||
 | 
					    "ejs": "^3.1.6",
 | 
				
			||||||
 | 
					    "express": "^4.17.1",
 | 
				
			||||||
 | 
					    "express-validator": "^6.14.2",
 | 
				
			||||||
 | 
					    "fs-extra": "^10.0.0",
 | 
				
			||||||
 | 
					    "jsonwebtoken": "^8.5.1",
 | 
				
			||||||
 | 
					    "mongoose": "^5.12.3",
 | 
				
			||||||
 | 
					    "pg": "^8.7.1",
 | 
				
			||||||
 | 
					    "pg-hstore": "^2.3.4",
 | 
				
			||||||
 | 
					    "sequelize": "^6.15.0"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "devDependencies": {
 | 
				
			||||||
 | 
					    "@types/cookie-parser": "^1.4.2",
 | 
				
			||||||
 | 
					    "@types/cors": "^2.8.10",
 | 
				
			||||||
 | 
					    "@types/ejs": "^3.0.6",
 | 
				
			||||||
 | 
					    "@types/express": "^4.17.11",
 | 
				
			||||||
 | 
					    "@types/fs-extra": "^9.0.12",
 | 
				
			||||||
 | 
					    "@types/jest": "^27.5.2",
 | 
				
			||||||
 | 
					    "@types/jsonwebtoken": "^8.5.8",
 | 
				
			||||||
 | 
					    "@types/mongoose": "^5.10.5",
 | 
				
			||||||
 | 
					    "@types/morgan": "^1.9.2",
 | 
				
			||||||
 | 
					    "@types/node": "^14.14.41",
 | 
				
			||||||
 | 
					    "@types/shelljs": "^0.8.9",
 | 
				
			||||||
 | 
					    "jest": "^27.0.6",
 | 
				
			||||||
 | 
					    "npm-run-all": "^4.1.5",
 | 
				
			||||||
 | 
					    "rimraf": "^3.0.2",
 | 
				
			||||||
 | 
					    "shelljs": "^0.8.4",
 | 
				
			||||||
 | 
					    "ts-jest": "^27.1.5",
 | 
				
			||||||
 | 
					    "ts-node": "^10.8.1",
 | 
				
			||||||
 | 
					    "typescript": "^4.2.4",
 | 
				
			||||||
 | 
					    "morgan": "^1.10.0"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "jest": {
 | 
				
			||||||
 | 
					    "preset": "ts-jest",
 | 
				
			||||||
 | 
					    "testEnvironment": "node"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "nodemonConfig": {
 | 
				
			||||||
 | 
					    "ignore": [
 | 
				
			||||||
 | 
					      "**/*.test.ts",
 | 
				
			||||||
 | 
					      "**/*.spec.ts",
 | 
				
			||||||
 | 
					      ".git",
 | 
				
			||||||
 | 
					      "node_modules"
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "watch": [
 | 
				
			||||||
 | 
					      "src"
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "ext": "ts, js"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										5
									
								
								backend/setup-repo.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										5
									
								
								backend/setup-repo.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cp .githooks/* .git/hooks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo "hooks have been copied"
 | 
				
			||||||
							
								
								
									
										26
									
								
								backend/src/.env.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								backend/src/.env.example
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					# General
 | 
				
			||||||
 | 
					APP_PORT = 6060
 | 
				
			||||||
 | 
					APP_HOSTNAME = 'localhost'
 | 
				
			||||||
 | 
					APP_HOST = 'http://localhost:8080' # frontend url
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Timezone
 | 
				
			||||||
 | 
					TZ = 'Europe/Prague'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CORS_WHITELIST = http://172.15.46.21:8080;http://192.168.0.1:8080
 | 
				
			||||||
 | 
					JWT_SECRET = ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# MongoDB
 | 
				
			||||||
 | 
					DB_URI = 'mongodb://username:password@localhost:27017/database?authSource=admin'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# PostgreSQL
 | 
				
			||||||
 | 
					DB_PORT = 5432
 | 
				
			||||||
 | 
					DB_HOST = '127.0.0.1'
 | 
				
			||||||
 | 
					DB_USERNAME = ''
 | 
				
			||||||
 | 
					DB_PASSWORD = ''
 | 
				
			||||||
 | 
					DB_DATABASE = ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# SMTP
 | 
				
			||||||
 | 
					SMTP_HOST = ''
 | 
				
			||||||
 | 
					SMTP_USER = ''
 | 
				
			||||||
 | 
					SMTP_PASS = ''
 | 
				
			||||||
 | 
					SMTP_FROM = ''
 | 
				
			||||||
							
								
								
									
										42
									
								
								backend/src/app.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								backend/src/app.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
				
			|||||||
 | 
					import express from 'express'
 | 
				
			||||||
 | 
					import morgan from 'morgan'
 | 
				
			||||||
 | 
					import path from 'path'
 | 
				
			||||||
 | 
					import cors from 'cors'
 | 
				
			||||||
 | 
					import cookieParser from 'cookie-parser'
 | 
				
			||||||
 | 
					import { router as routes } from './routes'
 | 
				
			||||||
 | 
					import { router as middlewares } from './middlewares'
 | 
				
			||||||
 | 
					import env from './config/environment'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export let corsWhitelist: Array<string>
 | 
				
			||||||
 | 
					if (env.CORS_WHITELIST != 'undefined') {
 | 
				
			||||||
 | 
						corsWhitelist = [...['http://localhost:8080', 'http://localhost:6040'], ...env.CORS_WHITELIST.split(';')]
 | 
				
			||||||
 | 
					} else {
 | 
				
			||||||
 | 
						corsWhitelist = ['http://localhost:8080', 'http://localhost:6040']
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					const corsOptions = {
 | 
				
			||||||
 | 
						origin: function (origin: any, callback: any) {
 | 
				
			||||||
 | 
							if (!origin || corsWhitelist.indexOf(origin) !== -1) {
 | 
				
			||||||
 | 
								callback(null, true)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								callback(new Error('Not allowed by CORS'))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						optionsSuccessStatus: 200,
 | 
				
			||||||
 | 
						credentials: true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const app = express()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Middlewares
 | 
				
			||||||
 | 
					app.use(middlewares)
 | 
				
			||||||
 | 
					app.set('view engine', 'ejs')
 | 
				
			||||||
 | 
					app.set('views', path.join(__dirname, 'views'))
 | 
				
			||||||
 | 
					app.use(cors(corsOptions))
 | 
				
			||||||
 | 
					app.use(morgan('dev'))
 | 
				
			||||||
 | 
					app.use(express.urlencoded({ extended: true }))
 | 
				
			||||||
 | 
					app.use(express.json())
 | 
				
			||||||
 | 
					app.use(express.static(path.join(__dirname, 'public')))
 | 
				
			||||||
 | 
					app.use(cookieParser())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Routes
 | 
				
			||||||
 | 
					app.use(routes)
 | 
				
			||||||
							
								
								
									
										49
									
								
								backend/src/config/database.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								backend/src/config/database.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
				
			|||||||
 | 
					import mongoose from 'mongoose'
 | 
				
			||||||
 | 
					import env from './environment'
 | 
				
			||||||
 | 
					import { Err, Succ } from '../services/globalService'
 | 
				
			||||||
 | 
					import db from './sequelize.config'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// MongoDB
 | 
				
			||||||
 | 
					const dbURI: string = env.DB_URI
 | 
				
			||||||
 | 
					async function connect() {
 | 
				
			||||||
 | 
						if (!env.NORK.database) {
 | 
				
			||||||
 | 
							new Err(500, 'no database is in norkcfg.json')
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (env.NORK.database.orm == 'mongoose') {
 | 
				
			||||||
 | 
							mongoose
 | 
				
			||||||
 | 
								.connect(dbURI, {
 | 
				
			||||||
 | 
									useNewUrlParser: true,
 | 
				
			||||||
 | 
									useUnifiedTopology: true,
 | 
				
			||||||
 | 
									useCreateIndex: true
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								.then(() => {
 | 
				
			||||||
 | 
									new Succ(200, 'connected to db')
 | 
				
			||||||
 | 
									return true
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								.catch((err: any) => {
 | 
				
			||||||
 | 
									new Err(500, err)
 | 
				
			||||||
 | 
									return false
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (env.NORK.database.orm == 'sequelize') {
 | 
				
			||||||
 | 
							db.sync()
 | 
				
			||||||
 | 
								.then(() => {
 | 
				
			||||||
 | 
									new Succ(200, 'connected to db')
 | 
				
			||||||
 | 
									return true
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								.catch((err: any) => {
 | 
				
			||||||
 | 
									new Err(500, `Can't connect to db\n${err}`)
 | 
				
			||||||
 | 
									return false
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (env.NORK.database.db.length > 0) {
 | 
				
			||||||
 | 
							new Err(500, `unsupported database ${env.NORK.database.db}`)
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default connect
 | 
				
			||||||
							
								
								
									
										59
									
								
								backend/src/config/environment.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								backend/src/config/environment.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
				
			|||||||
 | 
					import path from 'path'
 | 
				
			||||||
 | 
					import fs from 'fs-extra'
 | 
				
			||||||
 | 
					import { Err } from '../services/globalService'
 | 
				
			||||||
 | 
					import dotenv from 'dotenv'
 | 
				
			||||||
 | 
					const env_path = process.env.NODE_ENV ? `../.env.${process.env.NODE_ENV}` : '../.env'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dotenv.config({ path: path.join(__dirname, env_path) })
 | 
				
			||||||
 | 
					const norkcfg = fs.readJSONSync(path.join(__dirname, '../../norkconfig.json'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if (norkcfg.database) {
 | 
				
			||||||
 | 
						if (norkcfg.database.db == 'postgresql') {
 | 
				
			||||||
 | 
							if (!process.env.DB_PORT) {
 | 
				
			||||||
 | 
								process.env.DB_PORT = '5432'
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (!process.env.DB_HOST) {
 | 
				
			||||||
 | 
								process.env.DB_HOST = '127.0.0.1'
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (!process.env.DB_USERNAME || !process.env.DB_PASSWORD || !process.env.DB_DATABASE) {
 | 
				
			||||||
 | 
								new Err(500, 'missing DB parameters in .env file')
 | 
				
			||||||
 | 
								process.exit(1)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if (!fs.existsSync(path.join(__dirname, env_path))) {
 | 
				
			||||||
 | 
						console.log('$env_path = ', env_path)
 | 
				
			||||||
 | 
						console.log('$__dirname = ', __dirname)
 | 
				
			||||||
 | 
						new Err(500, `.env file for ${process.env.NODE_ENV ? process.env.NODE_ENV : ''} environment does not exists`)
 | 
				
			||||||
 | 
						process.exit()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if (process.env.JWT_SECRET === undefined || process.env.JWT_SECRET == '') {
 | 
				
			||||||
 | 
						new Err(500, 'JWT_SECRET is not set!')
 | 
				
			||||||
 | 
						process.exit()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default {
 | 
				
			||||||
 | 
						// General
 | 
				
			||||||
 | 
						APP_PORT: Number(process.env.APP_PORT),
 | 
				
			||||||
 | 
						APP_HOST: String(process.env.APP_HOST),
 | 
				
			||||||
 | 
						APP_HOSTNAME: process.env.APP_HOSTNAME !== undefined ? String(process.env.APP_HOSTNAME) : null,
 | 
				
			||||||
 | 
						CORS_WHITELIST: String(process.env.CORS_WHITELIST),
 | 
				
			||||||
 | 
						JWT_SECRET: String(process.env.JWT_SECRET),
 | 
				
			||||||
 | 
						// MongoDB
 | 
				
			||||||
 | 
						DB_URI: String(process.env.DB_URI),
 | 
				
			||||||
 | 
						// PostgreSQL
 | 
				
			||||||
 | 
						DB_PORT: Number(process.env.DB_PORT),
 | 
				
			||||||
 | 
						DB_HOST: String(process.env.DB_HOST),
 | 
				
			||||||
 | 
						DB_USERNAME: String(process.env.DB_USERNAME),
 | 
				
			||||||
 | 
						DB_PASSWORD: String(process.env.DB_PASSWORD),
 | 
				
			||||||
 | 
						DB_DATABASE: String(process.env.DB_DATABASE),
 | 
				
			||||||
 | 
						// Nork
 | 
				
			||||||
 | 
						NORK: norkcfg,
 | 
				
			||||||
 | 
						// SMTP
 | 
				
			||||||
 | 
						SMTP_HOST: String(process.env.SMTP_HOST),
 | 
				
			||||||
 | 
						SMTP_USER: String(process.env.SMTP_USER),
 | 
				
			||||||
 | 
						SMTP_PASS: String(process.env.SMTP_PASS),
 | 
				
			||||||
 | 
						SMTP_FROM: String(process.env.SMTP_FROM)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										10
									
								
								backend/src/config/sequelize.config.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								backend/src/config/sequelize.config.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					import { Sequelize } from 'sequelize'
 | 
				
			||||||
 | 
					import env from './environment'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const db = new Sequelize(env.DB_DATABASE, env.DB_USERNAME, env.DB_PASSWORD, {
 | 
				
			||||||
 | 
						host: env.DB_HOST,
 | 
				
			||||||
 | 
						dialect: 'postgres',
 | 
				
			||||||
 | 
						logging: false
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default db
 | 
				
			||||||
							
								
								
									
										26
									
								
								backend/src/controllers/beerController.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								backend/src/controllers/beerController.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					import { Request, Response } from 'express'
 | 
				
			||||||
 | 
					import Beer from '../models/Beer'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function add_post(req: Request, res: Response) {
 | 
				
			||||||
 | 
						console.log(req.body, 'request body')	
 | 
				
			||||||
 | 
						const beer = new Beer(req.body)
 | 
				
			||||||
 | 
						beer.save()
 | 
				
			||||||
 | 
						res.json({status: 'ok'})
 | 
				
			||||||
 | 
						return 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function del_post(req: Request, res: Response) {
 | 
				
			||||||
 | 
						return 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function edit_post(req: Request, res: Response) {
 | 
				
			||||||
 | 
						res.json({status: 'ok'})
 | 
				
			||||||
 | 
						return 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export async function get_get(req: Request, res: Response) {
 | 
				
			||||||
 | 
						const beer = await Beer.find();
 | 
				
			||||||
 | 
						res.json(beer)
 | 
				
			||||||
 | 
						return 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										6
									
								
								backend/src/controllers/rootController.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								backend/src/controllers/rootController.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					import { Request, Response } from 'express'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function root_get(req: Request, res: Response) {
 | 
				
			||||||
 | 
						res.render('home')
 | 
				
			||||||
 | 
						return true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										4
									
								
								backend/src/interfaces/globalInterface.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								backend/src/interfaces/globalInterface.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					export interface ErrType {
 | 
				
			||||||
 | 
						code: number
 | 
				
			||||||
 | 
						message: string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										23
									
								
								backend/src/logs/Err.global.log
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								backend/src/logs/Err.global.log
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					Date: "2023-06-30 01:23:29" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 01:23:37" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 01:25:41" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 01:26:27" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 01:26:36" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 11:48:07" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 11:48:37" Type: "Err" Code: "500" Message: "{"message":"connect ENETUNREACH 10.123.0.1:27017 - Local (0.0.0.0:0)","reason":{"type":"Single","setName":null,"maxSetVersion":null,"maxElectionId":null,"servers":{},"stale":false,"compatible":true,"compatibilityError":null,"logicalSessionTimeoutMinutes":null,"heartbeatFrequencyMS":10000,"localThresholdMS":15,"commonWireVersion":null}}"
 | 
				
			||||||
 | 
					Date: "2023-06-30 11:50:18" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:05:10" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:05:37" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:08:25" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:09:14" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:11:02" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:11:59" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:12:25" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:13:33" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:21:16" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:37:40" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:38:33" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 12:39:26" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 13:20:38" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 13:21:43" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
 | 
					Date: "2023-06-30 13:24:42" Type: "Err" Code: "500" Message: "unsupported database mongodb"
 | 
				
			||||||
							
								
								
									
										63
									
								
								backend/src/middlewares/authMiddleware.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								backend/src/middlewares/authMiddleware.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
				
			|||||||
 | 
					import { Request, Response, NextFunction } from 'express'
 | 
				
			||||||
 | 
					import jwt from 'jsonwebtoken'
 | 
				
			||||||
 | 
					import env from '../config/environment'
 | 
				
			||||||
 | 
					import { Err, Succ } from '../services/globalService'
 | 
				
			||||||
 | 
					import User from '../models/User' // uncomment this
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function requireAuth(req: Request, res: Response, next: NextFunction) {
 | 
				
			||||||
 | 
						const token = req.cookies.jwt
 | 
				
			||||||
 | 
						new Err(500, 'uncomment code in authMiddleware before using!')
 | 
				
			||||||
 | 
						if (token) {
 | 
				
			||||||
 | 
							jwt.verify(token, env.JWT_SECRET, async (err: any, decodedToken: any) => {
 | 
				
			||||||
 | 
								if (err) {
 | 
				
			||||||
 | 
									// console.error(err.message)
 | 
				
			||||||
 | 
									res.status(401).json(new Err(401, 'user is not authenticated'))
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if (!err) {
 | 
				
			||||||
 | 
									const user = (async () => {
 | 
				
			||||||
 | 
										if (env.NORK.db.orm) {
 | 
				
			||||||
 | 
											if (env.NORK.db.orm == 'sequelize') {
 | 
				
			||||||
 | 
												return await User.findByPk(decodedToken.id)
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											if (env.NORK.db.orm == 'mongoose') {
 | 
				
			||||||
 | 
												return await User.findById(decodedToken.id)
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										} else {
 | 
				
			||||||
 | 
											return null
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									})()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (user === null) {
 | 
				
			||||||
 | 
										res.status(401).json(new Err(401, 'user is not authenticated'))
 | 
				
			||||||
 | 
										return
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									res.locals.user = user
 | 
				
			||||||
 | 
									new Succ(100, 'user is authenticated')
 | 
				
			||||||
 | 
									next()
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!token) {
 | 
				
			||||||
 | 
							res.status(401).json(new Err(401, 'user is not authenticated'))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function requireVerified(req: Request, res: Response, next: NextFunction) {
 | 
				
			||||||
 | 
						if (res.locals.user._id) {
 | 
				
			||||||
 | 
							if (res.locals.user.verified) {
 | 
				
			||||||
 | 
								new Succ(100, 'user is verified')
 | 
				
			||||||
 | 
								next()
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							res.status(403).json(new Err(403, 'user is not verified'))
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!res.locals.user._id) {
 | 
				
			||||||
 | 
							res.status(401).json(new Err(401, 'user is not authenticated'))
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										16
									
								
								backend/src/middlewares/handleValidation.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								backend/src/middlewares/handleValidation.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					import { Request, Response, NextFunction } from 'express'
 | 
				
			||||||
 | 
					import { validationResult } from 'express-validator'
 | 
				
			||||||
 | 
					import { Err } from '../services/globalService'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Middleware {
 | 
				
			||||||
 | 
						handleValidationError(req: Request, res: Response, next: NextFunction) {
 | 
				
			||||||
 | 
							const error = validationResult(req)
 | 
				
			||||||
 | 
							if (!error.isEmpty()) {
 | 
				
			||||||
 | 
								new Err(400, error)
 | 
				
			||||||
 | 
								return res.status(400).json(new Err(400, 'validation error', error.array()[0]))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							next()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default new Middleware()
 | 
				
			||||||
							
								
								
									
										6
									
								
								backend/src/middlewares/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								backend/src/middlewares/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					import { Router } from 'express'
 | 
				
			||||||
 | 
					import { router as sayHiMiddleware } from '../middlewares/sayHiMiddleware'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const router = Router()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// router.use(sayHiMiddleware)
 | 
				
			||||||
							
								
								
									
										9
									
								
								backend/src/middlewares/sayHiMiddleware.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								backend/src/middlewares/sayHiMiddleware.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					import { Router, Request, Response, NextFunction } from 'express'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const router = Router()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					router.use((req: Request, res: Response, next: NextFunction) => {
 | 
				
			||||||
 | 
						console.log('Hi :)')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						next()
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
							
								
								
									
										32
									
								
								backend/src/models/Beer.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								backend/src/models/Beer.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
				
			|||||||
 | 
					import { Schema, model } from 'mongoose'
 | 
				
			||||||
 | 
					import path from 'path'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const schema = new Schema<any>(
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							brand: {
 | 
				
			||||||
 | 
								type: String,
 | 
				
			||||||
 | 
								required: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							name: {
 | 
				
			||||||
 | 
								type: String,
 | 
				
			||||||
 | 
								required: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							degree: {
 | 
				
			||||||
 | 
								type: String,
 | 
				
			||||||
 | 
								required: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							packaging: {
 | 
				
			||||||
 | 
								type: Number,
 | 
				
			||||||
 | 
								required: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							note: {
 | 
				
			||||||
 | 
								type: String,
 | 
				
			||||||
 | 
								required: false
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							timestamps: true,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default model(path.basename(__filename).split('.')[0], schema)
 | 
				
			||||||
							
								
								
									
										16
									
								
								backend/src/models/Events.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								backend/src/models/Events.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					import { Schema, model } from 'mongoose'
 | 
				
			||||||
 | 
					import path from 'path'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const schemaName = path.basename(__filename).split('.')[0]
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							title: {
 | 
				
			||||||
 | 
								type: String,
 | 
				
			||||||
 | 
								required: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							timestamps: true,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default model(path.basename(__filename).split('.')[0], schema)
 | 
				
			||||||
							
								
								
									
										16
									
								
								backend/src/models/Review.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								backend/src/models/Review.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					import { Schema, model } from 'mongoose'
 | 
				
			||||||
 | 
					import path from 'path'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const schemaName = path.basename(__filename).split('.')[0]
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							title: {
 | 
				
			||||||
 | 
								type: String,
 | 
				
			||||||
 | 
								required: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							timestamps: true,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default model(path.basename(__filename).split('.')[0], schema)
 | 
				
			||||||
							
								
								
									
										40
									
								
								backend/src/models/User.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								backend/src/models/User.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
				
			|||||||
 | 
					import path from 'path'
 | 
				
			||||||
 | 
					import { Schema, model } from 'mongoose'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const schemaName = path.basename(__filename).split('.')[0]
 | 
				
			||||||
 | 
					const schema = new Schema(
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							username: {
 | 
				
			||||||
 | 
								type: String,
 | 
				
			||||||
 | 
								required: true
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							email: {
 | 
				
			||||||
 | 
								type: String,
 | 
				
			||||||
 | 
								required: true,
 | 
				
			||||||
 | 
								unique: true
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							password: {
 | 
				
			||||||
 | 
								type: String,
 | 
				
			||||||
 | 
								required: true
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							domains: [
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									role: Number,
 | 
				
			||||||
 | 
									domain_id: String
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							],
 | 
				
			||||||
 | 
							verification_code: {
 | 
				
			||||||
 | 
								type: Number,
 | 
				
			||||||
 | 
								length: 6
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							verified: {
 | 
				
			||||||
 | 
								type: Boolean,
 | 
				
			||||||
 | 
								default: false
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							timestamps: true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default model(path.basename(__filename).split('.')[0], schema)
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								backend/src/public/expressjs.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								backend/src/public/expressjs.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 4.9 KiB  | 
							
								
								
									
										1
									
								
								backend/src/public/nodejs_logo.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								backend/src/public/nodejs_logo.svg
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| 
		 After Width: | Height: | Size: 5.8 KiB  | 
							
								
								
									
										11
									
								
								backend/src/routes/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								backend/src/routes/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					import { Request, Response, Router } from 'express'
 | 
				
			||||||
 | 
					import { router as rootRoutes } from './rootRoutes'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const router = Router()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					router.use(rootRoutes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 404
 | 
				
			||||||
 | 
					router.use((req: Request, res: Response) => {
 | 
				
			||||||
 | 
						res.status(404).send('E404')
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
							
								
								
									
										18
									
								
								backend/src/routes/rootRoutes.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								backend/src/routes/rootRoutes.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					import { Router } from 'express'
 | 
				
			||||||
 | 
					import * as rootController from '../controllers/rootController'
 | 
				
			||||||
 | 
					import * as beerController from '../controllers/beerController'
 | 
				
			||||||
 | 
					import rootValidator from '../validators/rootValidator'
 | 
				
			||||||
 | 
					import handleValidation from '../middlewares/handleValidation'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const router = Router()
 | 
				
			||||||
 | 
					const mws = [handleValidation.handleValidationError]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					router.get('/', rootValidator.checkRootGet(), mws, rootController.root_get)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					router.post('/api/v1/beer/add', beerController.add_post)
 | 
				
			||||||
 | 
					router.post('/api/v1/beer/del', beerController.del_post)
 | 
				
			||||||
 | 
					router.post('/api/v1/beer/edit', beerController.edit_post)
 | 
				
			||||||
 | 
					router.get('/api/v1/beer/get', beerController.get_get)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					router.post('/api/v1/review/add', beerController.add_post)
 | 
				
			||||||
 | 
					router.post('/api/v1/review/del', beerController.del_post)
 | 
				
			||||||
							
								
								
									
										31
									
								
								backend/src/server.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								backend/src/server.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					import http from 'http'
 | 
				
			||||||
 | 
					import { app } from './app'
 | 
				
			||||||
 | 
					import env from './config/environment'
 | 
				
			||||||
 | 
					import { Succ } from './services/globalService'
 | 
				
			||||||
 | 
					import database from './config/database'
 | 
				
			||||||
 | 
					const port: number = env.APP_PORT || 8080
 | 
				
			||||||
 | 
					const hostname: string = env.APP_HOSTNAME || 'localhost'
 | 
				
			||||||
 | 
					export const server = http.createServer(app)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Server
 | 
				
			||||||
 | 
					export function runServer(): void {
 | 
				
			||||||
 | 
						server.listen(port, hostname, () => {
 | 
				
			||||||
 | 
							new Succ(200, `Server is listening on http://${hostname}:${port}`)
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO: Fix this shit
 | 
				
			||||||
 | 
					//(async () => {
 | 
				
			||||||
 | 
					//	if (!env.NORK.database) {
 | 
				
			||||||
 | 
					//		runServer()
 | 
				
			||||||
 | 
					//	} else {
 | 
				
			||||||
 | 
					//		const db_connection = await database()
 | 
				
			||||||
 | 
					//		if (db_connection) {
 | 
				
			||||||
 | 
					//			runServer()
 | 
				
			||||||
 | 
					//		}
 | 
				
			||||||
 | 
					//	}
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//})()
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					runServer()
 | 
				
			||||||
 | 
					const db_connection = database()
 | 
				
			||||||
							
								
								
									
										173
									
								
								backend/src/services/globalService.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										173
									
								
								backend/src/services/globalService.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,173 @@
 | 
				
			|||||||
 | 
					import colors from 'colors'
 | 
				
			||||||
 | 
					import fs from 'fs'
 | 
				
			||||||
 | 
					import path from 'path'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface ErrType {
 | 
				
			||||||
 | 
						code: number
 | 
				
			||||||
 | 
						message: string
 | 
				
			||||||
 | 
						data?: any
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export class Err implements ErrType {
 | 
				
			||||||
 | 
						code: number
 | 
				
			||||||
 | 
						message: string
 | 
				
			||||||
 | 
						data: any
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						constructor(code: number, message: string | object, data: any = null) {
 | 
				
			||||||
 | 
							this.code = code
 | 
				
			||||||
 | 
							typeof message === 'object' ? (this.message = JSON.stringify(message)) : (this.message = message)
 | 
				
			||||||
 | 
							data ? (this.data = data) : false
 | 
				
			||||||
 | 
							// typeof data === 'object' ? (this.data = JSON.stringify(data)) : (this.data = data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							this.drop()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						drop() {
 | 
				
			||||||
 | 
							if (this.data) {
 | 
				
			||||||
 | 
								console.log(colors.bgRed(`${this.code}`) + colors.bgBlack.red(` ${this.message}`) + this.data)
 | 
				
			||||||
 | 
								Log.make('Err', this.code, this.message, this.data)
 | 
				
			||||||
 | 
								return {
 | 
				
			||||||
 | 
									code: this.code,
 | 
				
			||||||
 | 
									message: this.message,
 | 
				
			||||||
 | 
									data: this.data
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							console.log(colors.bgRed(`${this.code}`) + colors.bgBlack.red(` ${this.message}`))
 | 
				
			||||||
 | 
							Log.make('Err', this.code, this.message)
 | 
				
			||||||
 | 
							return {
 | 
				
			||||||
 | 
								code: this.code,
 | 
				
			||||||
 | 
								message: this.message
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export class Succ {
 | 
				
			||||||
 | 
						code: number
 | 
				
			||||||
 | 
						message: string
 | 
				
			||||||
 | 
						data?: any
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						constructor(code: number, message: string, data: any = null) {
 | 
				
			||||||
 | 
							this.code = code
 | 
				
			||||||
 | 
							this.message = message
 | 
				
			||||||
 | 
							data ? (this.data = data) : false
 | 
				
			||||||
 | 
							this.drop()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						drop() {
 | 
				
			||||||
 | 
							if (this.data) {
 | 
				
			||||||
 | 
								console.log(colors.bgGreen.black(`${this.code}`) + colors.green.bgBlack(` ${this.message}`) + this.data)
 | 
				
			||||||
 | 
								return {
 | 
				
			||||||
 | 
									code: this.code,
 | 
				
			||||||
 | 
									message: this.message,
 | 
				
			||||||
 | 
									data: this.data
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							console.log(colors.bgGreen.black(`${this.code}`) + colors.green.bgBlack(` ${this.message}`))
 | 
				
			||||||
 | 
							return {
 | 
				
			||||||
 | 
								code: this.code,
 | 
				
			||||||
 | 
								message: this.message
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface LogType {
 | 
				
			||||||
 | 
						type: 'Err' | 'Succ' | 'Info'
 | 
				
			||||||
 | 
						code?: number
 | 
				
			||||||
 | 
						message?: string
 | 
				
			||||||
 | 
						data?: any
 | 
				
			||||||
 | 
						logFile?: string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					export class Log implements LogType {
 | 
				
			||||||
 | 
						type: 'Err' | 'Succ' | 'Info'
 | 
				
			||||||
 | 
						code?: number
 | 
				
			||||||
 | 
						message?: string
 | 
				
			||||||
 | 
						data?: any
 | 
				
			||||||
 | 
						logFile?: string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * @param type
 | 
				
			||||||
 | 
						 *  - Type of log
 | 
				
			||||||
 | 
						 *  - Err | Succ | Info
 | 
				
			||||||
 | 
						 * @param code
 | 
				
			||||||
 | 
						 *  - not required
 | 
				
			||||||
 | 
						 *  - HTTP status code
 | 
				
			||||||
 | 
						 * @param message
 | 
				
			||||||
 | 
						 *  - could be anything
 | 
				
			||||||
 | 
						 * @param data
 | 
				
			||||||
 | 
						 *  - could be anything
 | 
				
			||||||
 | 
						 * @param logFile
 | 
				
			||||||
 | 
						 *  - name of logFile
 | 
				
			||||||
 | 
						 *  - default is log type file
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						constructor(type: 'Err' | 'Succ' | 'Info', code?: number, message?: string, data?: any, logFile?: string) {
 | 
				
			||||||
 | 
							this.type = type
 | 
				
			||||||
 | 
							this.code = code
 | 
				
			||||||
 | 
							this.message = message
 | 
				
			||||||
 | 
							this.data = data
 | 
				
			||||||
 | 
							this.logFile = logFile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!this.logFile) {
 | 
				
			||||||
 | 
								this.logFile = `${type}.global.log`
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								this.logFile = this.logFile + '.log'
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							this.logFile = path.join(__dirname, this.logFile)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static pathMake(type: string, name?: string) {
 | 
				
			||||||
 | 
							let logName
 | 
				
			||||||
 | 
							if (!name) {
 | 
				
			||||||
 | 
								logName = `${type}.global.log`
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								logName = name + '.log'
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return path.join(__dirname, '../logs/' + logName)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * returns current date in my custom format
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						static dateNow(): string {
 | 
				
			||||||
 | 
							/**
 | 
				
			||||||
 | 
							 * @param num: number
 | 
				
			||||||
 | 
							 *
 | 
				
			||||||
 | 
							 * receives number and returns two digits number
 | 
				
			||||||
 | 
							 * example:
 | 
				
			||||||
 | 
							 *   input num = 9 => returns string 09
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							function add0(num: number): string {
 | 
				
			||||||
 | 
								if (num.toString().length <= 1) {
 | 
				
			||||||
 | 
									return '0' + String(num)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return String(num)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							const d = new Date()
 | 
				
			||||||
 | 
							return `${d.getFullYear()}-${add0(d.getMonth() + 1)}-${add0(d.getDate())} ${add0(d.getHours())}:${add0(d.getMinutes())}:${add0(d.getSeconds())}`
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static make(type: 'Err' | 'Succ' | 'Info', code?: number, message?: string, data?: any, logFile?: string) {
 | 
				
			||||||
 | 
							let realPath = Log.pathMake(type, logFile)
 | 
				
			||||||
 | 
							let formattedData = `Date: "${Log.dateNow()}" Type: "${type}"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							code ? (formattedData += ` Code: "${code}"`) : false
 | 
				
			||||||
 | 
							message ? (formattedData += ` Message: "${message}"`) : false
 | 
				
			||||||
 | 
							if (data) {
 | 
				
			||||||
 | 
								if (typeof data === 'object') {
 | 
				
			||||||
 | 
									data = JSON.stringify(data)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								formattedData += ` Data: "${data}"`
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							formattedData += '\n'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (fs.existsSync(realPath)) {
 | 
				
			||||||
 | 
								fs.appendFileSync(realPath, formattedData)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								fs.writeFileSync(realPath, formattedData)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										3
									
								
								backend/src/services/rootService.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								backend/src/services/rootService.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					export const helloWorld = () => {
 | 
				
			||||||
 | 
						console.log('hello world')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										7
									
								
								backend/src/utils/copyAssets.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								backend/src/utils/copyAssets.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					import * as shell from 'shelljs'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Copy all the view templates
 | 
				
			||||||
 | 
					shell.cp('-R', 'src/views', 'dist/')
 | 
				
			||||||
 | 
					shell.cp('-R', 'src/public', 'dist/')
 | 
				
			||||||
 | 
					shell.cp('-R', 'src/models', 'dist/')
 | 
				
			||||||
 | 
					shell.cp('-u', 'src/.env', 'dist/')
 | 
				
			||||||
							
								
								
									
										9
									
								
								backend/src/validators/rootValidator.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								backend/src/validators/rootValidator.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					import { body, param, query } from 'express-validator'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class rootValidator {
 | 
				
			||||||
 | 
						checkRootGet() {
 | 
				
			||||||
 | 
							return []
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default new rootValidator()
 | 
				
			||||||
							
								
								
									
										69
									
								
								backend/src/views/home.ejs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								backend/src/views/home.ejs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
				
			|||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html lang="en">
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					    <meta charset="UTF-8">
 | 
				
			||||||
 | 
					    <meta http-equiv="X-UA-Compatible" content="IE=edge">
 | 
				
			||||||
 | 
					    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | 
				
			||||||
 | 
					    <title>New Project</title>
 | 
				
			||||||
 | 
					    <link rel="preconnect" href="https://fonts.googleapis.com">
 | 
				
			||||||
 | 
					    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
 | 
				
			||||||
 | 
					    <link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
 | 
				
			||||||
 | 
					    <style>
 | 
				
			||||||
 | 
					        * {
 | 
				
			||||||
 | 
					            box-sizing: border-box;
 | 
				
			||||||
 | 
					            margin: 0;
 | 
				
			||||||
 | 
					            padding: 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        body {
 | 
				
			||||||
 | 
					            font-family: 'Open Sans', sans-serif;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        .content {
 | 
				
			||||||
 | 
					            width: 100vw;
 | 
				
			||||||
 | 
					            height: 100vh;
 | 
				
			||||||
 | 
					            display: flex;
 | 
				
			||||||
 | 
					            justify-content: space-between;
 | 
				
			||||||
 | 
					            padding-top: 5rem;
 | 
				
			||||||
 | 
					            flex-direction: column;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        footer, .welcome {
 | 
				
			||||||
 | 
					            display: flex;
 | 
				
			||||||
 | 
					            justify-content: center;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        .welcome {
 | 
				
			||||||
 | 
					            display: flex;
 | 
				
			||||||
 | 
					            justify-content: center;
 | 
				
			||||||
 | 
					            align-items: center;
 | 
				
			||||||
 | 
					            flex-direction: column;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        img {
 | 
				
			||||||
 | 
					            width: 200px;
 | 
				
			||||||
 | 
					            padding-top: 2rem;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        footer {
 | 
				
			||||||
 | 
					            padding-bottom: 2rem;
 | 
				
			||||||
 | 
					            text-align: center;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        .logos {
 | 
				
			||||||
 | 
					            display: flex;
 | 
				
			||||||
 | 
					            align-items: center;
 | 
				
			||||||
 | 
					            gap: 1rem;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    </style>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					    <div class="content">
 | 
				
			||||||
 | 
					        <div class="welcome">
 | 
				
			||||||
 | 
					            <h1>Let's make something amazing!</h1>
 | 
				
			||||||
 | 
					            <div class="logos">
 | 
				
			||||||
 | 
					                <img src="/nodejs_logo.svg" alt="node.js logo">
 | 
				
			||||||
 | 
					                <img src="/expressjs.png" alt="express.js logo">
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <footer>
 | 
				
			||||||
 | 
					            <div class="author">
 | 
				
			||||||
 | 
					                <p>Made by </p><a href="http://www.filiprojek.cz">filiprojek.cz</a>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        </footer>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										0
									
								
								backend/tests/beer_routes.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								backend/tests/beer_routes.sh
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								backend/tests/run.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								backend/tests/run.sh
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										63
									
								
								backend/tsconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								backend/tsconfig.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
						"compilerOptions": {
 | 
				
			||||||
 | 
							/* Visit https://aka.ms/tsconfig.json to read more about this file */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* Basic Options */
 | 
				
			||||||
 | 
							// "incremental": true,                         /* Enable incremental compilation */
 | 
				
			||||||
 | 
							"target": "es6",
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
							/* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
 | 
				
			||||||
 | 
							"module": "commonjs",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
 | 
				
			||||||
 | 
							// "lib": [],                                   /* Specify library files to be included in the compilation. */
 | 
				
			||||||
 | 
							// "allowJs": true,                             /* Allow javascript files to be compiled. */
 | 
				
			||||||
 | 
							// "checkJs": true,                             /* Report errors in .js files. */
 | 
				
			||||||
 | 
							// "jsx": "preserve",                           /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
 | 
				
			||||||
 | 
							// "declaration": true,                         /* Generates corresponding '.d.ts' file. */
 | 
				
			||||||
 | 
							// "declarationMap": true,                      /* Generates a sourcemap for each corresponding '.d.ts' file. */
 | 
				
			||||||
 | 
							// "sourceMap": true,                           /* Generates corresponding '.map' file. */
 | 
				
			||||||
 | 
							// "outFile": "./",                             /* Concatenate and emit output to single file. */
 | 
				
			||||||
 | 
							"outDir": "./dist",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* Redirect output structure to the directory. */
 | 
				
			||||||
 | 
							"rootDir": "./src",
 | 
				
			||||||
 | 
							/* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
 | 
				
			||||||
 | 
							// "composite": true,                           /* Enable project compilation */
 | 
				
			||||||
 | 
							// "tsBuildInfoFile": "./",                     /* Specify file to store incremental compilation information */
 | 
				
			||||||
 | 
							// "removeComments": true,                      /* Do not emit comments to output. */
 | 
				
			||||||
 | 
							// "noEmit": true,                              /* Do not emit outputs. */
 | 
				
			||||||
 | 
							// "importHelpers": true,                       /* Import emit helpers from 'tslib'. */
 | 
				
			||||||
 | 
							// "downlevelIteration": true,                  /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
 | 
				
			||||||
 | 
							// "isolatedModules": true,                     /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* Strict Type-Checking Options */
 | 
				
			||||||
 | 
							"strict": true,
 | 
				
			||||||
 | 
							/* Enable all strict type-checking options. */
 | 
				
			||||||
 | 
							// "noImplicitAny": true,                       /* Raise error on expressions and declarations with an implied 'any' type. */
 | 
				
			||||||
 | 
							// "strictNullChecks": true,                    /* Enable strict null checks. */
 | 
				
			||||||
 | 
							// "strictFunctionTypes": true,                 /* Enable strict checking of function types. */
 | 
				
			||||||
 | 
							// "strictBindCallApply": true,                 /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
 | 
				
			||||||
 | 
							// "strictPropertyInitialization": true,        /* Enable strict checking of property initialization in classes. */
 | 
				
			||||||
 | 
							// "noImplicitThis": true,                      /* Raise error on 'this' expressions with an implied 'any' type. */
 | 
				
			||||||
 | 
							// "alwaysStrict": true,                        /* Parse in strict mode and emit "use strict" for each source file. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							"baseUrl": "./",
 | 
				
			||||||
 | 
							"esModuleInterop": true,
 | 
				
			||||||
 | 
							/* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
 | 
				
			||||||
 | 
							"resolveJsonModule": true,
 | 
				
			||||||
 | 
							// "preserveSymlinks": true,                    /* Do not resolve the real path of symlinks. */
 | 
				
			||||||
 | 
							// "allowUmdGlobalAccess": true,                /* Allow accessing UMD globals from modules. */
 | 
				
			||||||
 | 
							/* Experimental Options */
 | 
				
			||||||
 | 
							"experimentalDecorators": true,
 | 
				
			||||||
 | 
							/* Enables experimental support for ES7 decorators. */
 | 
				
			||||||
 | 
							"emitDecoratorMetadata": true,
 | 
				
			||||||
 | 
							/* Enables experimental support for emitting type metadata for decorators. */
 | 
				
			||||||
 | 
							/* Advanced Options */
 | 
				
			||||||
 | 
							"skipLibCheck": true,
 | 
				
			||||||
 | 
							/* Skip type checking of declaration files. */
 | 
				
			||||||
 | 
							"forceConsistentCasingInFileNames": true
 | 
				
			||||||
 | 
							/* Disallow inconsistently-cased references to the same file. */
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"exclude": ["src/tests"]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										11
									
								
								frontend/css/add.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								frontend/css/add.css
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					.form_add {
 | 
				
			||||||
 | 
						display: flex;
 | 
				
			||||||
 | 
						flex-direction: column;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.form_group_label {
 | 
				
			||||||
 | 
						display: flex;
 | 
				
			||||||
 | 
						flex-direction: column;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										0
									
								
								frontend/css/home.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								frontend/css/home.css
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								frontend/css/show.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								frontend/css/show.css
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										58
									
								
								frontend/index.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								frontend/index.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
						require_once("./libs/Router.php");
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Display Errors
 | 
				
			||||||
 | 
						ini_set('display_startup_errors', 1);
 | 
				
			||||||
 | 
						ini_set('display_errors', 1);
 | 
				
			||||||
 | 
						error_reporting(-1);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Display var_dump
 | 
				
			||||||
 | 
						#var_dump($_SESSION);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// Date Time Zone
 | 
				
			||||||
 | 
						date_default_timezone_set('Europe/Prague');
 | 
				
			||||||
 | 
						$API_URL = "http://localhost:6060"
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html lang="cs">
 | 
				
			||||||
 | 
						<head>
 | 
				
			||||||
 | 
							<title>DeguApp</title>
 | 
				
			||||||
 | 
							<meta charset="UTF-8">
 | 
				
			||||||
 | 
							<meta name="viewport" content="width=device-width, initial-scale=1">
 | 
				
			||||||
 | 
							<link href="home.css" rel="stylesheet">
 | 
				
			||||||
 | 
						</head>
 | 
				
			||||||
 | 
						<body>
 | 
				
			||||||
 | 
							<header>
 | 
				
			||||||
 | 
								<div class="flex-left">
 | 
				
			||||||
 | 
									<a href="/">DeguApp</a>
 | 
				
			||||||
 | 
								</div>
 | 
				
			||||||
 | 
								<div class="flex-left">
 | 
				
			||||||
 | 
									<a href="/login">Přihlásit se</a>
 | 
				
			||||||
 | 
									<a href="/signup">Registrace</a>
 | 
				
			||||||
 | 
									<a href="/add_beer">Přidat pivo</a>
 | 
				
			||||||
 | 
									<a href="/add_review">Přidat recenzi</a>
 | 
				
			||||||
 | 
								</div>
 | 
				
			||||||
 | 
							</header>
 | 
				
			||||||
 | 
							<section class="main-wrapper">
 | 
				
			||||||
 | 
								<h1>DeguApp</h1>
 | 
				
			||||||
 | 
								<?php
 | 
				
			||||||
 | 
									$R = new Router();
 | 
				
			||||||
 | 
									$R->route('GET', '/', 'home');
 | 
				
			||||||
 | 
									$R->route('GET', '/add', 'add');
 | 
				
			||||||
 | 
									$R->route('GET', '/login', 'login');
 | 
				
			||||||
 | 
									$R->route('GET', '/signup', 'signup');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									$R->route('POST', '/contact/send', 'contact');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									$R = null;
 | 
				
			||||||
 | 
								?>
 | 
				
			||||||
 | 
							</section>
 | 
				
			||||||
 | 
							<footer>
 | 
				
			||||||
 | 
								<a href="https://git.filiprojek.cz/fr/deguapp">Source</a>
 | 
				
			||||||
 | 
								<a href="http://filiprojek.cz/">(c) Filip Rojek, 2023</a>
 | 
				
			||||||
 | 
							</footer>
 | 
				
			||||||
 | 
						</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										33
									
								
								frontend/libs/Router.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								frontend/libs/Router.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					class Router {
 | 
				
			||||||
 | 
						public $returned = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						function route($method, $url, $filename) {
 | 
				
			||||||
 | 
							$methods = ['GET', 'POST'];
 | 
				
			||||||
 | 
							if(in_array($method, $methods)) {
 | 
				
			||||||
 | 
								if($_SERVER['REQUEST_METHOD'] == $method) {
 | 
				
			||||||
 | 
									if ($_SERVER['REQUEST_URI'] == $url) {
 | 
				
			||||||
 | 
										require_once("./pages/$filename/$filename.php");
 | 
				
			||||||
 | 
										$this->returned = true;
 | 
				
			||||||
 | 
										return;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						function __destruct() {
 | 
				
			||||||
 | 
							if($_SERVER['REQUEST_METHOD'] == 'GET') {
 | 
				
			||||||
 | 
								if(!$this->returned){
 | 
				
			||||||
 | 
									$url = explode("/", $_SERVER['REQUEST_URI']);
 | 
				
			||||||
 | 
									$url = $url[count($url)-1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (file_exists("./pages/$url/$url.php")) {
 | 
				
			||||||
 | 
										require_once("./pages/$url/$url.php");
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										require_once("./pages/errors/404.php");
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										84
									
								
								frontend/pages/add_beer/add_beer.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								frontend/pages/add_beer/add_beer.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,84 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
						$API_URL = "http://localhost:6060"
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
 | 
					<link href="/css/add.css" rel="stylesheet">
 | 
				
			||||||
 | 
					<h1>Přidání piva</h1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<form class="form_add">
 | 
				
			||||||
 | 
						<div class=form_group>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="brand">Značka:</label>
 | 
				
			||||||
 | 
								<input type="text" name="brand" id="brand" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="name">Název:</label>
 | 
				
			||||||
 | 
								<input type="text" name="name" id="name" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="degree">Stupeň:</label>
 | 
				
			||||||
 | 
								<input type="text" name="degree" id="degree" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						<div class=form_group>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="packaging">Obal:</label>
 | 
				
			||||||
 | 
								<select id="packaging" name="packaging" enable>
 | 
				
			||||||
 | 
									<option value="1">Plech</option>
 | 
				
			||||||
 | 
									<option value="2">Sklo</option>
 | 
				
			||||||
 | 
									<option value="3">Jiné</option>
 | 
				
			||||||
 | 
								</select>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="note">Poznámka:</label>
 | 
				
			||||||
 | 
								<input type="text" name="note" id="note" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
						<div class="form_group">
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="photo">Foto:</label>
 | 
				
			||||||
 | 
								<input type="file" name="image" id="image" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						<div class="form_group">
 | 
				
			||||||
 | 
							<button class="btn-send">Přidat záznam</button>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
					</form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script>
 | 
				
			||||||
 | 
						const btn = document.querySelector('.btn-send')
 | 
				
			||||||
 | 
						btn.addEventListener('click', (e) => {
 | 
				
			||||||
 | 
							e.preventDefault()
 | 
				
			||||||
 | 
							console.log('click')
 | 
				
			||||||
 | 
							send()
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						async function send() {
 | 
				
			||||||
 | 
							console.log('click')
 | 
				
			||||||
 | 
							let form = new FormData(document.querySelector("form"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							let body = JSON.stringify(Object.fromEntries(form))
 | 
				
			||||||
 | 
								fetch('<?php echo $API_URL;?>/api/v1/beer/add', {
 | 
				
			||||||
 | 
								credentials: 'include',
 | 
				
			||||||
 | 
								headers: {
 | 
				
			||||||
 | 
									'Content-Type': 'application/json',
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								method: 'POST',
 | 
				
			||||||
 | 
								body: body,
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
								.then(res => {
 | 
				
			||||||
 | 
									console.log(res)
 | 
				
			||||||
 | 
									console.log(res.json())
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								.then(data => {
 | 
				
			||||||
 | 
									console.log(data)
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								.catch(err => {
 | 
				
			||||||
 | 
									console.log(err)
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										188
									
								
								frontend/pages/add_review/add_review.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										188
									
								
								frontend/pages/add_review/add_review.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,188 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
						$API_URL = "http://localhost:6060"
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
 | 
					<link href="/css/add.css" rel="stylesheet">
 | 
				
			||||||
 | 
					<h1>Přidání záznamu</h1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<form class="form_add">
 | 
				
			||||||
 | 
						<div class=form_group>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="user">Uživatel:</label>
 | 
				
			||||||
 | 
								<select id="user" name="user" enable>
 | 
				
			||||||
 | 
									<option value="">Dž</option>
 | 
				
			||||||
 | 
									<option value="">Dý Ej En</option>
 | 
				
			||||||
 | 
									<option value="">frfr</option>
 | 
				
			||||||
 | 
								</select>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
						<div class=form_group>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="beer">Beer:</label>
 | 
				
			||||||
 | 
								<select name="beer" id="beer">
 | 
				
			||||||
 | 
								</select>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						<div class=form_group>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="logo">Logo:</label>
 | 
				
			||||||
 | 
								<input type="number" name="logo" id="logo" min="1" max="10" step="1" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="aroma">Vůně:</label>
 | 
				
			||||||
 | 
								<input type="number" name="aroma" id="aroma" min="1" max="10" step="1" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="foam">Pěna:</label>
 | 
				
			||||||
 | 
								<input type="number" name="foam" id="foam" min="1" max="10" step="1" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="color">Barva:</label>
 | 
				
			||||||
 | 
								<input type="number" name="color" id="color" min="1" max="10" step="1" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						<div class=form_group>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="bitterness">Hořkost:</label>
 | 
				
			||||||
 | 
								<input type="number" name="bitterness" id="bitterness" min="1" max="10" step="1" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="sweetness">Sladkost:</label>
 | 
				
			||||||
 | 
								<input type="number" name="sweetness" id="sweetness" min="1" max="10" step="1" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="note">Poznámka:</label>
 | 
				
			||||||
 | 
								<input type="text" name="note" id="note" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						<div class=form_group>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="again">Dal bych si znovu?</label>
 | 
				
			||||||
 | 
								<select name="again" enable>
 | 
				
			||||||
 | 
									<option value="yes">Ano</option>
 | 
				
			||||||
 | 
									<option value="no">Ne</option>
 | 
				
			||||||
 | 
								</select>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="overall_rating">Celkový dojem:</label>
 | 
				
			||||||
 | 
								<input type="number" name="overall_rating" id="overall_rating" min="1" max="10" step="1" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="final_rating">Hodnocení:</label>
 | 
				
			||||||
 | 
								<input type="number" name="final_rating" id="final_rating" min="1" max="10" step="0.5" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						<div class=form_group>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="date">Datum:</label>
 | 
				
			||||||
 | 
								<input type="date" name="date" id="date" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="attendedts">S kým:</label>
 | 
				
			||||||
 | 
								<input type="text" name="attendedts" id="attendents" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="sign">Podpis:</label>
 | 
				
			||||||
 | 
								<input type="text" name="sign" id="sign" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						<div class="form_group">
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="photo">Foto:</label>
 | 
				
			||||||
 | 
								<input type="file" name="image" id="image" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
							<div class=form_group_label>
 | 
				
			||||||
 | 
								<label for="bebeer">BeBeer:</label>
 | 
				
			||||||
 | 
								<input type="file" name="bebeer" id="bebeer" enable>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						<div class="form_group">
 | 
				
			||||||
 | 
							<button class="btn-send">Přidat záznam</button>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
					</form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script defer>
 | 
				
			||||||
 | 
						async function getBeers() {
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								const res = await fetch('<?php echo $API_URL;?>/api/v1/beer/get')
 | 
				
			||||||
 | 
								const data = await res.json()
 | 
				
			||||||
 | 
								console.log(data)
 | 
				
			||||||
 | 
								return data
 | 
				
			||||||
 | 
							} catch(err) {
 | 
				
			||||||
 | 
								console.log(err, "penis")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const btn = document.querySelector('.btn-send')
 | 
				
			||||||
 | 
						btn.addEventListener('click', (e) => {
 | 
				
			||||||
 | 
							e.preventDefault()
 | 
				
			||||||
 | 
							send()
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						async function send() {
 | 
				
			||||||
 | 
							let form = new FormData(document.querySelector("form"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							let body = JSON.stringify(Object.fromEntries(form))
 | 
				
			||||||
 | 
								fetch('<?php echo $API_URL;?>/api/v1/review/add', {
 | 
				
			||||||
 | 
								credentials: 'include',
 | 
				
			||||||
 | 
								headers: {
 | 
				
			||||||
 | 
									'Content-Type': 'application/json',
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								method: 'POST',
 | 
				
			||||||
 | 
								body: body,
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
								.then(res => {
 | 
				
			||||||
 | 
									console.log(res)
 | 
				
			||||||
 | 
									console.log(res.json())
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								.then(data => {
 | 
				
			||||||
 | 
									console.log(data)
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								.catch(err => {
 | 
				
			||||||
 | 
									console.log(err)
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script async defer>
 | 
				
			||||||
 | 
						const packagingToLang = (id_pckg) => {
 | 
				
			||||||
 | 
							const pckgs = {
 | 
				
			||||||
 | 
								1: "Plech",
 | 
				
			||||||
 | 
								2: "Sklo",
 | 
				
			||||||
 | 
								3: "Plast"
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return pckgs[id_pckg]
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						(async() => {
 | 
				
			||||||
 | 
							// get beers and fill form data
 | 
				
			||||||
 | 
							const beerData = await getBeers()
 | 
				
			||||||
 | 
							const beer = document.querySelector('#beer')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							const beerOptions = beerData?.map((beer) => {
 | 
				
			||||||
 | 
								return `
 | 
				
			||||||
 | 
									<option value="${beer._id}">${beer.name} ${beer.degree} ${packagingToLang(beer.packaging)}</option>
 | 
				
			||||||
 | 
								`
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
							console.log(beerData)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							beer.innerHTML = beerOptions
 | 
				
			||||||
 | 
						})()
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										0
									
								
								frontend/pages/errors/404.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								frontend/pages/errors/404.php
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								frontend/pages/home/home.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								frontend/pages/home/home.php
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								frontend/pages/show/show.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								frontend/pages/show/show.php
									
									
									
									
									
										Normal file
									
								
							
		Reference in New Issue
	
	Block a user