'INSERT INTO Session (SessionName) VALUES (\"'+spielname+'\");',
(error)=>{
error=>{
if(error){
console.error(error);
res.status(500).json({status:'false'});
}else{
res.status(200).json({status:'true'});
}
}
);
//Init new Gamestatus
db.query(
'INSERT INTO Gamestatus (SessionID, Red, Blue, RedTurn, ActiveExplainer, ActiveWatchdog) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), 0, 0, 1, 0, 0);',
error=>{
if(error){
console.error(error);
res.status(500).json({status:'false'});
}else{
res.status(200).json({status:'true'});
}
});
}else{
res.status(500).json({status:'error'});
}
});
//Check if Session exist
router.post('/isSession',(req,res)=>{
varspielname=req.body.spielname;
constspielname=req.body.spielname;
if(spielname.match(/^[0-9a-zA-Z]+$/)!=null){
db.query(
'SELECT SessionName FROM Session WHERE SessionName = \''+spielname+'\';',
...
...
@@ -46,6 +58,7 @@ function createRouter(db) {
}
});
//Return all Sessions (Not neccesary)
router.get('/Session',function(req,res){
db.query(
'SELECT * FROM Session',
...
...
@@ -60,6 +73,36 @@ function createRouter(db) {
);
});
//Return GameStatus
router.post('/getGamestatus',(req,res)=>{
constspielname=req.body.spielname;
if(spielname.match(/^[0-9a-zA-Z]+$/)!=null){
db.query(
'SELECT SessionID, Red, Blue, RedTurn, ActiveExplainer, ActiveWatchdog FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")',