Repaired /quiz-results bug and removed unnecessary code

This commit is contained in:
Maciej Krzyżanowski 2023-03-13 19:31:17 +01:00
parent 53c923581b
commit 92abec5fb3

52
app.js
View File

@ -514,7 +514,7 @@ app.post('/quiz-results', async (req, res) => {
return; return;
} }
if(points <= 0 || points >= 10) { if(points < 0 || points > 10) {
res.status(400); res.status(400);
res.json({ res.json({
fieldErrors: { fieldErrors: {
@ -525,10 +525,6 @@ app.post('/quiz-results', async (req, res) => {
return; return;
} }
// TODO: Zapis do sesji lub do bazy
console.log('Zapis', req.body);
if(!req.session.accountNickname) { if(!req.session.accountNickname) {
// Zapis do sesji // Zapis do sesji
if(!req.session.quizResults) { if(!req.session.quizResults) {
@ -559,52 +555,6 @@ app.post('/quiz-results', async (req, res) => {
res.sendStatus(204); res.sendStatus(204);
}); });
// TESTY CIASTECZEK:
/* app.get('/cookieaddone', (req, res) => {
req.session.counter = (req.session.counter || 0) + 1
res.status(200);
res.send('Added!');
});
app.get('/cookiegetvalue', (req, res) => {
const val = req.session.counter || 0;
res.status(200);
res.send(`Value: ${val}`);
}); */
// TODO: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// CAUTION: Only for testing purposes! Should be deleted ASAP when not needed anymore.
app.get('/simulate-login', (req, res) => {
const nickToAuth = req.query.nickname;
if(!nickToAuth) {
res.status(400);
res.send('You must pass nickname as query parameter to simulate login');
return;
}
req.session.accountNickname = nickToAuth;
res.status(200);
res.send(`Logged in as ${nickToAuth}`);
});
app.get('/simulate-logout', (req, res) => {
if(!req.session.accountNickname) {
res.status(401);
res.json({
fieldErrors: {},
otherErrors: [
'Użytkownik nie jest zalogowany!'
]
});
return;
}
req.session.destroy();
res.status(200);
res.send(`Logged out!`);
});
// This should remain at the end of all routes // This should remain at the end of all routes
// It will direct every not matched route to index.html file // It will direct every not matched route to index.html file
app.get('/*', function (req, res) { app.get('/*', function (req, res) {