Fix answer counting

This commit is contained in:
2023-06-18 20:29:31 +03:00
parent d6f1e9ef71
commit 210fd3f90e
4 changed files with 16 additions and 4 deletions

View File

@@ -8,7 +8,7 @@ import { createNanoEvents } from 'nanoevents';
import "dotenv/config";
import names from './names.json' assert { type: "json" };
import names from './names'
const app = express();
@@ -175,6 +175,7 @@ const client = new MongoClient(process.env.URI, { useUnifiedTopology: true });
});
players[req.body.data.username] = req.body.data.name;
answers += 1
emitter.emit('answer', {
username: req.body.data.username,
selected: req.body.data.name
@@ -283,8 +284,6 @@ const client = new MongoClient(process.env.URI, { useUnifiedTopology: true });
res.write(`data: ${JSON.stringify(data)}\nevent: answer\n\n`);
answers += 1
if (answers === Object.keys(players).length) {
Object.keys(players).forEach((key) => {
if (card.name === players[key]) {