mirror of
https://github.com/anatolykopyl/vk-bingo.git
synced 2026-03-26 12:54:25 +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) {
|
if (req.body.data.id && req.body.data.name) {
|
||||||
const card = await cardsCollection.findOne({ _id: ObjectId(req.body.data.id) })
|
const card = await cardsCollection.findOne({ _id: ObjectId(req.body.data.id) })
|
||||||
if (card) {
|
if (card) {
|
||||||
if (card.name === req.body.data.name) {
|
const correct = card.name === req.body.data.name
|
||||||
|
if (correct) {
|
||||||
req.session.right++
|
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 {
|
} else {
|
||||||
req.session.wrong++
|
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 {
|
} else {
|
||||||
res.status(500).send()
|
res.status(500).send()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ export default {
|
|||||||
return {
|
return {
|
||||||
options: null,
|
options: null,
|
||||||
card: null,
|
card: null,
|
||||||
oldCard: null,
|
|
||||||
correctAnswer: null, // True or False
|
correctAnswer: null, // True or False
|
||||||
selectedAnswer: null, // Чье-то имя
|
selectedAnswer: null, // Чье-то имя
|
||||||
showResult: false
|
showResult: false
|
||||||
@@ -79,7 +78,6 @@ export default {
|
|||||||
innerThis.score.wrong++
|
innerThis.score.wrong++
|
||||||
}
|
}
|
||||||
}, 805)
|
}, 805)
|
||||||
this.oldCard = this.card
|
|
||||||
axios
|
axios
|
||||||
.post(process.env.VUE_APP_BACKEND + '/answer', {
|
.post(process.env.VUE_APP_BACKEND + '/answer', {
|
||||||
'data': {
|
'data': {
|
||||||
@@ -89,8 +87,7 @@ export default {
|
|||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.correctAnswer = response.data.correct
|
this.correctAnswer = response.data.correct
|
||||||
this.card.name = response.data.name
|
this.card = response.data.card
|
||||||
this.card.date = response.data.date
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user