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 }) } },