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'); ...@@ -3,6 +3,29 @@ const express = require('express');
function createRouter(db) { function createRouter(db) {
const router = express.Router(); 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 // the routes are defined here
//Generate new Session //Generate new Session
...@@ -40,26 +63,7 @@ function createRouter(db) { ...@@ -40,26 +63,7 @@ function createRouter(db) {
//Check if Session exist //Check if Session exist
router.post('/isSession', (req, res) => { router.post('/isSession', (req, res) => {
const spielname = req.body.spielname; isSession(req, res)
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'});
}
}); });
//Return all Sessions (Not neccesary) //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