From e4a1a47345d9d5a6431761aa67ba183a413cdadc Mon Sep 17 00:00:00 2001 From: Anatoly Kopyl Date: Mon, 29 Mar 2021 10:20:32 +0300 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=D0=A1=D0=B1=D0=BE=D1=80=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D0=B8=D1=81=D1=82=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/index.js | 14 ++++++++++++++ frontend/src/components/Game.vue | 7 +++++++ 2 files changed, 21 insertions(+) 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() {