From f2a059a1a3f307479acd60711d36dceb14c570e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Thu, 16 Apr 2015 12:17:45 +0200 Subject: [PATCH] Fixed when it is changing song twice --- server/server.js | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/server/server.js b/server/server.js index a8cb36b9..89f24ede 100755 --- a/server/server.js +++ b/server/server.js @@ -324,7 +324,7 @@ function vote(coll, id, guid, socket) } -function change_song(coll) +function change_song(coll, id) { db.collection(coll).find({views:{$exists:true}}, function(err, docs){ if(docs[0]["removeplay"] == true) @@ -335,15 +335,27 @@ function change_song(coll) }) }else { - db.collection(coll).update({now_playing:true}, - {$set:{ - now_playing:false, - votes:0, - guids:[] - }}, function(err, docs) - { - change_song_post(coll); - }); + if(id === undefined){ + db.collection(coll).update({now_playing:true}, + {$set:{ + now_playing:false, + votes:0, + guids:[] + }}, function(err, docs) + { + change_song_post(coll); + }); + }else{ + db.collection(coll).update({now_playing:true, id:id}, + {$set:{ + now_playing:false, + votes:0, + guids:[] + }}, function(err, docs) + { + change_song_post(coll); + }); + } } }) }