This commit is contained in:
Filip Rojek 2023-07-01 23:22:11 +02:00
parent 2ab62770dc
commit 02e8cf1cd3
10 changed files with 200 additions and 38 deletions

View File

@ -0,0 +1,15 @@
import { Request, Response } from 'express'
import Review from '../models/Review'
export const root_get = (req: Request, res: Response) => {
res.render('home')
return true
}
export function add_post(req: Request, res: Response) {
console.log(req.body)
const review = new Review(req.body);
review.save()
res.json({status: "ok"})
}

View File

@ -0,0 +1,9 @@
import { Request, Response } from 'express'
import User from '../models/User'
export function add_post(req: Request, res: Response) {
const user = new User(req.body)
user.save()
res.json({status: 'ok'})
return 0
}

View File

@ -21,3 +21,29 @@ Date: "2023-06-30 12:39:26" Type: "Err" Code: "500" Message: "unsupported databa
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"
Date: "2023-06-30 20:14:29" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 20:24:27" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 20:28:58" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 21:37:00" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 21:37:06" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 21:45:43" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:18:05" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:22:38" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:22:54" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:23:00" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:28:16" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:29:59" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:32:14" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:38:24" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:50:25" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:50:44" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:51:12" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:51:40" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 22:51:53" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 23:00:51" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-06-30 23:01:52" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-07-01 10:46:49" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-07-01 18:30:40" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-07-01 18:31:01" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-07-01 18:31:26" Type: "Err" Code: "500" Message: "unsupported database mongodb"
Date: "2023-07-01 18:32:01" Type: "Err" Code: "500" Message: "unsupported database mongodb"

View File

@ -3,25 +3,29 @@ import path from 'path'
const schema = new Schema<any>(
{
brand: {
type: String,
required: true,
},
name: {
type: String,
required: true,
required: true
},
degree: {
type: String,
type: Number,
required: true,
},
percentage: {
type: Number,
required: true
},
packaging: {
type: Number,
required: true,
required: true
},
note: {
type: String,
required: false
},
photo: {
type: Array,
required: false,
}
},
{
@ -30,3 +34,4 @@ const schema = new Schema<any>(
)
export default model(path.basename(__filename).split('.')[0], schema)

View File

@ -1,12 +1,64 @@
import { Schema, model } from 'mongoose'
import path from 'path'
export const schemaName = path.basename(__filename).split('.')[0]
const schema = new Schema<any>(
{
title: {
beer_id: {
type: String,
required: true
},
logo: {
type: Number,
required: true
},
aroma: {
type: Number,
required: true
},
foam: {
type: Number,
required: true
},
color: {
type: Number,
required: true
},
bitterness: {
type: Number,
required: true
},
sweetness: {
type: Number,
required: true
},
note: {
type: String,
required: false
},
again: {
type: Boolean,
required: true
},
overall_rating: {
type: Number,
required: true
},
final_rating: {
type: Number,
required: true
},
date: {
type: Date,
required: true,
},
participants: {
type: Array,
required: false,
},
signature: {
type: String,
required: false
}
},
{
timestamps: true,

View File

@ -17,20 +17,6 @@ const schema = new Schema(
type: String,
required: true
},
domains: [
{
role: Number,
domain_id: String
}
],
verification_code: {
type: Number,
length: 6
},
verified: {
type: Boolean,
default: false
}
},
{
timestamps: true

View File

@ -1,6 +1,8 @@
import { Router } from 'express'
import * as rootController from '../controllers/rootController'
import * as beerController from '../controllers/beerController'
import * as reviewController from '../controllers/reviewController'
import * as userController from '../controllers/userController'
import rootValidator from '../validators/rootValidator'
import handleValidation from '../middlewares/handleValidation'
@ -14,5 +16,7 @@ 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)
router.post('/api/v1/review/add', reviewController.add_post)
//router.post('/api/v1/review/del', reviewController.del_post)
router.post('/api/v1/user/add', userController.add_post)

View File

@ -7,17 +7,17 @@
<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>
<label for="name">Název, značka:</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 class=form_group_label>
<label for="percentage">Procento:</label>
<input type="text" name="percentage" id="percentage" enable>
</div>
</div>
<div class=form_group>
@ -26,7 +26,9 @@
<select id="packaging" name="packaging" enable>
<option value="1">Plech</option>
<option value="2">Sklo</option>
<option value="3">Jiné</option>
<option value="3">Sud</option>
<option value="4">Tank</option>
<option value="5">Jiné</option>
</select>
</div>
</div>
@ -38,7 +40,7 @@
<div class="form_group">
<div class=form_group_label>
<label for="photo">Foto:</label>
<input type="file" name="image" id="image" enable>
<input type="file" name="photo" id="photo" enable>
</div>
</div>

View File

@ -9,16 +9,18 @@
<div class=form_group_label>
<label for="user">Uživatel:</label>
<select id="user" name="user" enable>
<option value=""></option>
<option value=""> Ej En</option>
<option value="">frfr</option>
<option value="649f42f62b93542c8a465526"></option>
<option value="649f43182b93542c8a465528"> Ej En</option>
<option value="649f42c32b93542c8a465524">frfr</option>
<option value="649f43332b93542c8a46552a">Pch</option>
<option value="649f46072b93542c8a46552f"></option>
</select>
</div>
</div>
<div class=form_group>
<div class=form_group_label>
<label for="beer">Beer:</label>
<select name="beer" id="beer">
<select name="beer_id" id="beer_id">
</select>
</div>
</div>
@ -90,7 +92,13 @@
<div class=form_group_label>
<label for="attendedts">S kým:</label>
<input type="text" name="attendedts" id="attendents" enable>
<select id="attendedts" name="attendedts" multiple size="3" enable>
<option value="649f42f62b93542c8a465526"></option>
<option value="649f43182b93542c8a465528"> Ej En</option>
<option value="649f42c32b93542c8a465524">frfr</option>
<option value="649f43332b93542c8a46552a">Pch</option>
<option value="649f46072b93542c8a46552f"></option>
</select>
</div>
<div class=form_group_label>
@ -170,10 +178,11 @@
}
return pckgs[id_pckg]
}
(async() => {
// get beers and fill form data
const beerData = await getBeers()
const beer = document.querySelector('#beer')
const beer = document.querySelector('#beer_id')
const beerOptions = beerData?.map((beer) => {
return `

View File

@ -0,0 +1,54 @@
<?php
$API_URL = "http://localhost:6060"
?>
<link rel="stylesheet" href="/css/add.css">
<form class="form_add">
<label for="username">Uživatelské jméno:</label>
<input type="text" name="username" id="username">
<label for="email">E-mail:</label>
<input type="email" name="email" id="email">
<label for="password">Heslo:</label>
<input type="password" name="password" id="password">
<button id="submit" class="btn-send">Registrovat se</button>
</form>
<script>
const btn = document.querySelector('.btn-send')
console.log(btn)
btn.addEventListener('click', (e) => {
e.preventDefault()
send()
})
function send() {
let form = new FormData(document.querySelector("form"));
let body = JSON.stringify(Object.fromEntries(form))
fetch('<?php echo $API_URL;?>/api/v1/user/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>