Commit c72ab85c authored by Dennis Willers's avatar Dennis Willers 🏀

Check if Cards still exist for a room. Return -1 as new card if no new card exist

parent defeee15
Pipeline #426 passed with stages
in 2 minutes and 19 seconds
......@@ -148,6 +148,40 @@ function createRouter(db) {
);
};
const cardsExist = function cardExist(req, res, next) {
const spielname = req.body.spielname;
if (spielname.match(/^[0-9a-z]+$/) != null) {
const sql = 'SELECT Card.CardID, Solution, Tabu1, Tabu2, Tabu3, Tabu4, Tabu5 \n' +
'FROM Card \n' +
'WHERE Card.CardID NOT IN \n' +
'(\n' +
' SELECT S2C.CardID\n' +
' FROM S2C\n' +
' WHERE S2C.CardID IS NOT NULL AND S2C.SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")\n' +
');';
console.log('getS2C1: ', sql);
db.query(
sql,
(error, results) => {
if (error) {
console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
if (results.length > 0) {
next();
} else {
res.header('Access-Control-Allow-Origin', "*").status(502).json({
status: 'false',
reason: 'Alle Karten sind durchgespielt'
});
}
}
});
} else {
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'error'});
}
};
const getS2C = async function getS2C(req, res) {
const spielname = req.body.spielname;
if (spielname.match(/^[0-9a-z]+$/) != null) {
......@@ -195,7 +229,7 @@ function createRouter(db) {
(error, results) => {
if (error) {
console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
res.header('Access-Control-Allow-Origin', "*").status(502).json({status: 'false', reason: 'Alle Karten sind durchgespielt'});
} else {
const checkUpdate = results[0].affectedRows;
console.log('CheckUpdate: ', results[0].affectedRows);
......@@ -227,7 +261,11 @@ function createRouter(db) {
}
});
} else {
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'error alle Karten durch'});
socket.emit('newCard', {
'sessionName': spielname,
'cardID': -1
});
res.header('Access-Control-Allow-Origin', "*").status(502).json({status: 'error alle Karten durch'});
}
}
});
......@@ -678,7 +716,7 @@ function createRouter(db) {
router.post('/getS2C', [getS2C]);
//Start a new Round and lock the game positions
router.post('/newRound', [isSession, isActiveExplainer, newRound]);
router.post('/newRound', [cardsExist, isSession, isActiveExplainer, newRound]);
//End a Round and unlock the game positions and invert RedTurn
router.post('/endRound', [endRound]);
......
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