Browse Source

Added collection that saves all songs that are deleted in a special collection.

KrisVos130 9 years ago
parent
commit
d25452e195
2 changed files with 20 additions and 2 deletions
  1. 2 1
      app/collections/collections.js
  2. 18 1
      app/server/server.js

+ 2 - 1
app/collections/collections.js

@@ -3,4 +3,5 @@ Rooms = new Mongo.Collection("rooms");
 Queues = new Mongo.Collection("queues");
 Reports = new Mongo.Collection("reports");
 Chat = new Mongo.Collection("chat");
-Alerts = new Mongo.Collection("alerts");
+Alerts = new Mongo.Collection("alerts");
+Deleted = new Mongo.Collection("deleted");

+ 18 - 1
app/server/server.js

@@ -756,7 +756,24 @@ Meteor.methods({
     removeSongFromPlaylist: function(type, mid) {
         if (isModerator() && !isBanned()) {
             type = type.toLowerCase();
+            var songs = Playlists.findOne({type: type}).songs;
+            var song = undefined;
+            songs.forEach(function(curr_song) {
+                if (mid === curr_song.mid) {
+                    song = curr_song;
+                    return;
+                }
+            });
             Playlists.update({type: type}, {$pull: {songs: {mid: mid}}});
+            if (song !== undefined) {
+                song.deletedBy = Meteor.userId();
+                song.deletedAt = new Date(Date.now());
+                if (Deleted.find({type: type}).count() === 0) {
+                    Deleted.insert({type: type, songs: [song]});
+                } else {
+                    Deleted.update({type: type}, {$push: {songs: song}});
+                }
+            }
         } else {
             throw new Meteor.Error(403, "Invalid permissions.");
         }
@@ -783,7 +800,7 @@ Meteor.methods({
                                 title: songData.title,
                                 artist: songData.artist,
                                 duration: songData.duration,
-                                skipDuration: songData.skipDuration,
+                                skipDuration: Number(songData.skipDuration),
                                 img: songData.img,
                                 type: songData.type,
                                 likes: Number(songData.likes),