Browse Source

Fixed issues with refactoring.

KrisVos130 8 years ago
parent
commit
0fba3629ab

+ 13 - 14
backend/logic/actions/playlists.js

@@ -201,6 +201,7 @@ let lib = {
 				return cb({ status: 'failure', message: error});
 			}
 			logger.log("PLAYLIST_GET", "SUCCESS", `Successfully got private playlist "${playlistId}" for user "${userId}".`);
+			console.log(playlist);
 			cb({
 				status: 'success',
 				data: playlist
@@ -323,7 +324,7 @@ let lib = {
 				function checkDone() {
 					if (processed === songs.length) next();
 				}
-				for (let s = 0; sif (playlist.song < songs.length; s++) {
+				for (let s = 0; s < songs.length; s++) {
 					lib.addSongToPlaylist(session, songs[s].contentDetails.videoId, playlistId, () => {
 						processed++;
 						checkDone();
@@ -368,7 +369,7 @@ let lib = {
 
 			(playlist, next) => {
 				if (!playlist || playlist.createdBy !== userId) return next('Playlist not found');
-				db.models.update({_id: playlistId}, {$pull: {songs: songId}}, next);
+				db.models.playlist.update({_id: playlistId}, {$pull: {songs: songId}}, next);
 			},
 
 			(res, next) => {
@@ -399,7 +400,7 @@ let lib = {
 	updateDisplayName: hooks.loginRequired((session, playlistId, displayName, cb, userId) => {
 		async.waterfall([
 			(next) => {
-				db.models.playlist.update({ _id: playlistId, createdBy: userId }, { $set: displayName }, next);
+				db.models.playlist.update({ _id: playlistId, createdBy: userId }, { $set: { displayName } }, next);
 			},
 
 			(res, next) => {
@@ -436,11 +437,11 @@ let lib = {
 
 			(playlist, next) => {
 				if (!playlist || playlist.createdBy !== userId) return next('Playlist not found');
-				async.each(playlist.songs, (song) => {
-					if (song._id === songId) return next(true, song);
+				async.each(playlist.songs, (song, next) => {
+					if (song._id === songId) return next(song);
 					next();
-				}, (err, song) => {
-					if (err === true) return next(null, song);
+				}, (err) => {
+					if (err && err._id) return next(null, err);
 					next('Song not found');
 				});
 			},
@@ -497,11 +498,11 @@ let lib = {
 
 			(playlist, next) => {
 				if (!playlist || playlist.createdBy !== userId) return next('Playlist not found');
-				async.each(playlist.songs, (song) => {
-					if (song._id === songId) return next(true, song);
+				async.each(playlist.songs, (song, next) => {
+					if (song._id === songId) return next(song);
 					next();
-				}, (err, song) => {
-					if (err === true) return next(null, song);
+				}, (err) => {
+					if (err && err._id) return next(null, err);
 					next('Song not found');
 				});
 			},
@@ -516,9 +517,7 @@ let lib = {
 			(song, next) => {
 				db.models.playlist.update({_id: playlistId}, {
 					$push: {
-						songs: {
-							song
-						}
+						songs: song
 					}
 				}, next);
 			},

+ 1 - 0
backend/logic/actions/queueSongs.js

@@ -2,6 +2,7 @@
 
 const db = require('../db');
 const utils = require('../utils');
+const logger = require('../logger');
 const notifications = require('../notifications');
 const cache = require('../cache');
 const async = require('async');

+ 1 - 1
backend/logic/playlists.js

@@ -133,7 +133,7 @@ module.exports = {
 				db.models.playlist.remove({ _id: playlistId }, next);
 			},
 
-			(next) => {
+			(res, next) => {
 				cache.hdel('playlists', playlistId, next);
 			}
 

+ 7 - 1
backend/logic/stations.js

@@ -486,7 +486,13 @@ module.exports = {
 									}
 								}
 							}
-							console.log(Date.now(), station._id, station.currentSong !== null && station.currentSong._id !== undefined, station.currentSong !== null, station.currentSong._id !== undefined);
+							console.log(
+								Date.now(),
+								(station) ? station._id : "STATION_NULL",
+								station.currentSong !== null && station.currentSong._id !== undefined,
+								station.currentSong !== null,
+								(station.currentSong) ? station.currentSong._id !== undefined : "CURRENTSONG_NULL"
+							);
 							if (station.currentSong !== null && station.currentSong._id !== undefined) {
 								utils.socketsJoinSongRoom(utils.getRoomSockets(`station.${station._id}`), `song.${station.currentSong._id}`);
 								if (!station.paused) {

+ 3 - 3
frontend/components/Modals/Playlists/Edit.vue

@@ -13,11 +13,11 @@
 							<a :href='' target='_blank'>{{ song.title }}</a>
 							<div class='controls'>
 								<a href='#' @click='promoteSong(song._id)'>
-									<i class='material-icons' v-if='$index > 0' @click='promoteSong(song._id)'>keyboard_arrow_up</i>
+									<i class='material-icons' v-if='$index > 0'>keyboard_arrow_up</i>
 									<i class='material-icons' style='opacity: 0' v-else>error</i>
 								</a>
 								<a href='#' @click='demoteSong(song._id)'>
-									<i class='material-icons' v-if='playlist.songs.length - 1 !== $index' @click='demoteSong(song._id)'>keyboard_arrow_down</i>
+									<i class='material-icons' v-if='playlist.songs.length - 1 !== $index'>keyboard_arrow_down</i>
 									<i class='material-icons' style='opacity: 0' v-else>error</i>
 								</a>
 								<a href='#' @click='removeSongFromPlaylist(song._id)'><i class='material-icons'>delete</i></a>
@@ -143,8 +143,8 @@
 			removePlaylist: function () {
 				let _this = this;
 				_this.socket.emit('playlists.remove', _this.playlist._id, res => {
+					Toast.methods.addToast(res.message, 3000);
 					if (res.status === 'success') {
-						Toast.methods.addToast(res.message, 3000);
 						_this.$parent.modals.editPlaylist = !_this.$parent.modals.editPlaylist;
 					}
 				});