From f4e7a49df8b275d01f2fb02172b15c06899e19cd Mon Sep 17 00:00:00 2001 From: Anatoly Date: Thu, 13 Jan 2022 00:08:25 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=D0=A3=D0=BF=D1=80=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=D0=BB=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E?= =?UTF-8?q?=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/index.js | 31 +++++++++++-------------------- frontend/src/components/Game.vue | 5 +---- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/backend/index.js b/backend/index.js index 1f27d07..d314a8a 100644 --- a/backend/index.js +++ b/backend/index.js @@ -140,29 +140,20 @@ app.post('/api/answer', async (req, res) => { if (req.body.data.id && req.body.data.name) { const card = await cardsCollection.findOne({ _id: ObjectId(req.body.data.id) }) if (card) { - if (card.name === req.body.data.name) { - req.session.right++ - answersCollection.insertOne({ - correct: true, - selected: req.body.data.name - }) - res.status(200).send({ - correct: true, - name: card.name, - date: card.date - }) + const correct = card.name === req.body.data.name + if (correct) { + req.session.right++ } else { req.session.wrong++ - answersCollection.insertOne({ - correct: false, - selected: req.body.data.name - }) - res.status(200).send({ - correct: false, - name: card.name, - date: card.date - }) } + answersCollection.insertOne({ + correct, + selected: req.body.data.name + }) + res.status(200).send({ + correct, + card + }) } else { res.status(500).send() } diff --git a/frontend/src/components/Game.vue b/frontend/src/components/Game.vue index 1a1be2a..35aa60b 100644 --- a/frontend/src/components/Game.vue +++ b/frontend/src/components/Game.vue @@ -45,7 +45,6 @@ export default { return { options: null, card: null, - oldCard: null, correctAnswer: null, // True or False selectedAnswer: null, // Чье-то имя showResult: false @@ -79,7 +78,6 @@ export default { innerThis.score.wrong++ } }, 805) - this.oldCard = this.card axios .post(process.env.VUE_APP_BACKEND + '/answer', { 'data': { @@ -89,8 +87,7 @@ export default { }) .then((response) => { this.correctAnswer = response.data.correct - this.card.name = response.data.name - this.card.date = response.data.date + this.card = response.data.card }) } },