diff --git a/backend/index.js b/backend/index.js index d1b6098..2905aeb 100644 --- a/backend/index.js +++ b/backend/index.js @@ -69,6 +69,20 @@ app.get('/card', async (req, res) => { } }) +app.post('/answer', (req, res) => { + if (req.session.loggedIn) { + try { + client.db(process.env.DB_NAME).collection('anwsers').insertOne(req.body.data) + res.status(200).send() + } catch (e) { + console.log("Error: " + e) + res.status(500).send() + } + } else { + res.status(403).send() + } +}) + app.get('/options', async (req, res) => { if (req.session.loggedIn) { res.status(200).send(names) diff --git a/frontend/src/components/Game.vue b/frontend/src/components/Game.vue index 509a79c..6281536 100644 --- a/frontend/src/components/Game.vue +++ b/frontend/src/components/Game.vue @@ -63,6 +63,13 @@ export default { setTimeout(function() { innerThis.showResult = true }, 800) + axios + .post(process.env.VUE_APP_BACKEND + '/answer', { + 'data': { + 'correct': this.correctAnswer, + 'selected': this.selectedAnswer + } + }) } }, mounted() {