mirror of
https://github.com/anatolykopyl/vk-bingo.git
synced 2026-03-26 04:44:26 +00:00
🎨 Упростил функцию ответа
This commit is contained in:
@@ -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) {
|
||||
const correct = card.name === req.body.data.name
|
||||
if (correct) {
|
||||
req.session.right++
|
||||
answersCollection.insertOne({
|
||||
correct: true,
|
||||
selected: req.body.data.name
|
||||
})
|
||||
res.status(200).send({
|
||||
correct: true,
|
||||
name: card.name,
|
||||
date: card.date
|
||||
})
|
||||
} else {
|
||||
req.session.wrong++
|
||||
}
|
||||
answersCollection.insertOne({
|
||||
correct: false,
|
||||
correct,
|
||||
selected: req.body.data.name
|
||||
})
|
||||
res.status(200).send({
|
||||
correct: false,
|
||||
name: card.name,
|
||||
date: card.date
|
||||
correct,
|
||||
card
|
||||
})
|
||||
}
|
||||
} else {
|
||||
res.status(500).send()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user