Fix vote bug
This commit is contained in:
@ -163,19 +163,20 @@ module.exports.voteForPlaylist = (roomId, userId, playlistId) => {
|
||||
const room = rooms[roomId];
|
||||
if (room.state !== 'waiting') return false;
|
||||
|
||||
const previousVote = Object.entries(room.playlistVotes)
|
||||
.find(([_, voters]) => voters.includes(userId));
|
||||
|
||||
if (previousVote) {
|
||||
room.playlistVotes[previousVote[0]] =
|
||||
room.playlistVotes[previousVote[0]].filter(id => id !== userId);
|
||||
if (!room.playlistVotes) {
|
||||
room.playlistVotes = {};
|
||||
}
|
||||
|
||||
Object.entries(room.playlistVotes).forEach(([pid, voters]) => {
|
||||
room.playlistVotes[pid] = voters.filter(id => id !== userId);
|
||||
});
|
||||
|
||||
if (!room.playlistVotes[playlistId]) {
|
||||
room.playlistVotes[playlistId] = [];
|
||||
}
|
||||
room.playlistVotes[playlistId].push(userId);
|
||||
|
||||
console.log(`Updated votes for room ${roomId}:`, room.playlistVotes);
|
||||
return true;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user