Forráskód Böngészése

Fixed bugs with (queue)songs.

KrisVos130 8 éve
szülő
commit
6762606a68

+ 6 - 5
backend/logic/actions/queueSongs.js

@@ -48,15 +48,16 @@ module.exports = {
 		});
 	}),
 
-	remove: hooks.adminRequired((session, _id, cb) => {
-		// TODO Require admin/login
-		db.models.queueSong.remove({ _id });
-		return cb({ status: 'success', message: 'Song was removed successfully' });
+	remove: hooks.adminRequired((session, songId, cb) => {
+		db.models.queueSong.remove({ _id: songId }, (err, res) => {
+			if (err) return cb({ status: 'failure', message: err.message });
+			//TODO Pub/sub for (queue)songs on admin pages.
+			cb({ status: 'success', message: 'Song was removed successfully' });
+		});
 	}),
 
 	add: hooks.loginRequired((session, songId, cb, userId) => {
 		//TODO Check if id is valid
-		//TODO Check if id is already in queue/rotation
 
 		let requestedAt = Date.now();
 

+ 13 - 7
backend/logic/actions/songs.js

@@ -6,6 +6,7 @@ const songs = require('../songs');
 const cache = require('../cache');
 const utils = require('../utils');
 const hooks = require('./hooks');
+const queueSongs = require('./queueSongs');
 
 cache.sub('song.like', (data) => {
 	io.io.to(`song.${data.songId}`).emit('event:song.like', {songId: data.songId, undisliked: data.undisliked});
@@ -63,16 +64,21 @@ module.exports = {
 		db.models.song.remove({ _id: songId });
 	}),
 
-	add: hooks.adminRequired((session, song, cb) => {
-		const newSong = new db.models.song(song);
-		db.models.song.findOne({ _id: song._id }, (err, existingSong) => {
-			if (err) throw err;
-			if (!existingSong) newSong.save(err => {
+	add: hooks.adminRequired((session, song, cb, userId) => {
+		queueSongs.remove(session, song._id, () => {
+			const newSong = new db.models.song(song);
+			db.models.song.findOne({ _id: song._id }, (err, existingSong) => {
 				if (err) throw err;
-				else cb({ status: 'success', message: 'Song has been moved from Queue' })
+				newSong.acceptedBy = userId;
+				newSong.acceptedAt = Date.now();
+				if (!existingSong) newSong.save(err => {
+					console.log(err, 1);
+					if (err) throw err;
+					else cb({ status: 'success', message: 'Song has been moved from Queue' })
+				});
 			});
+			//TODO Check if video is in queue and Add the song to the appropriate stations
 		});
-		//TODO Check if video is in queue and Add the song to the appropriate stations
 	}),
 
 	like: hooks.loginRequired((session, songId, cb, userId) => {

+ 1 - 9
frontend/components/Admin/QueueSongs.vue

@@ -216,17 +216,9 @@
 				_this.toggleModal();
 			},
 			add: function (song) {
-				this.socket.emit('queueSongs.remove', song._id, res => {
+				this.socket.emit('songs.add', song, res => {
 					if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
 				});
-				this.socket.emit('users.findBySession', res => {
-					if (res.status == 'success') {
-						song.acceptedBy = res.data.username;
-						this.socket.emit('songs.add', song, res => {
-							if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
-						});
-					}
-				});
 			},
 			remove: function (id, index) {
 				this.songs.splice(index, 1);

+ 0 - 6
frontend/components/Admin/Songs.vue

@@ -27,7 +27,6 @@
 						<td>{{ song.requestedBy }}</td>
 						<td>
 							<a class='button is-primary' @click='edit(song, index)'>Edit</a>
-							<a class='button is-success' @click='add(song)'>Add</a>
 							<a class='button is-danger' @click='remove(song._id, index)'>Remove</a>
 						</td>
 					</tr>
@@ -215,11 +214,6 @@
 				let _this = this;
 				_this.toggleModal();
 			},
-			add: function (song) {
-				this.socket.emit('songs.add', song, res => {
-					if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
-				});
-			},
 			remove: function (id, index) {
 				this.songs.splice(index, 1);
 				this.socket.emit('songs.remove', id, res => {