Commit 00542a98 authored by Dennis Willers's avatar Dennis Willers 🏀

Sort Out isSession into function

parent 368c5391
Pipeline #299 failed with stages
in 1 minute and 45 seconds
......@@ -3,6 +3,29 @@ const express = require('express');
function createRouter(db) {
const router = express.Router();
function isSession(req, res) {
const spielname = req.body.spielname;
if (spielname.match(/^[0-9a-zA-Z]+$/) != null) {
db.query(
'SELECT SessionName FROM Session WHERE SessionName = \''+spielname+'\';',
(error, results) => {
if (error) {
console.log(error);
return res.status(500).json({status: 'error'});
} else {
if (results.length > 0) {
return res.status(200).json({status: 'true'});
} else {
return res.status(200).json({status: 'false'});
}
}
}
);
} else {
return res.status(500).json({status: 'error'});
}
}
// the routes are defined here
//Generate new Session
......@@ -40,26 +63,7 @@ function createRouter(db) {
//Check if Session exist
router.post('/isSession', (req, res) => {
const spielname = req.body.spielname;
if (spielname.match(/^[0-9a-zA-Z]+$/) != null) {
db.query(
'SELECT SessionName FROM Session WHERE SessionName = \''+spielname+'\';',
(error, results) => {
if (error) {
console.log(error);
res.status(500).json({status: 'error'});
} else {
if (results.length > 0) {
res.status(200).json({status: 'true'});
} else {
res.status(200).json({status: 'false'});
}
}
}
);
} else {
res.status(500).json({status: 'error'});
}
isSession(req, res)
});
//Return all Sessions (Not neccesary)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment