소스 검색

Fixed issue with official playlists

theflametrooper 8 년 전
부모
커밋
013803b989
3개의 변경된 파일12개의 추가작업 그리고 15개의 파일을 삭제
  1. 7 6
      backend/logic/actions/stations.js
  2. 3 6
      backend/logic/songs.js
  3. 2 3
      backend/logic/stations.js

+ 7 - 6
backend/logic/actions/stations.js

@@ -289,12 +289,12 @@ module.exports = {
 
 			(station, next) => {
 				if (!station) return next('Station not found.');
-				if (station.type !== 'official') return next('This is not an official station.');
-				next();
+				else if (station.type !== 'official') return next('This is not an official station.');
+				else next();
 			},
 
 			(next) => {
-				cache.hget("officialPlaylists", stationId, next);
+				cache.hget('officialPlaylists', stationId, next);
 			},
 
 			(playlist, next) => {
@@ -305,10 +305,11 @@ module.exports = {
 			if (err) {
 				err = utils.getError(err);
 				logger.error("STATIONS_GET_PLAYLIST", `Getting playlist for station "${stationId}" failed. "${err}"`);
-				return cb({'status': 'failure', 'message': err});
+				return cb({ status: 'failure', message: err });
+			} else {
+				logger.success("STATIONS_GET_PLAYLIST", `Got playlist for station "${stationId}" successfully.`);
+				cb({ status: 'success', data: playlist.songs });
 			}
-			logger.success("STATIONS_GET_PLAYLIST", `Got playlist for station "${stationId}" successfully.`);
-			cb({status: 'success', data: playlist.songs})
 		});
 	},
 

+ 3 - 6
backend/logic/songs.js

@@ -84,20 +84,17 @@ module.exports = {
 	/**
 	 * Gets a song by song id from the cache or Mongo, and if it isn't in the cache yet, adds it the cache
 	 *
-	 * @param {String} songId - the id of the song we are trying to get
+	 * @param {String} songId - the mongo id of the song we are trying to get
 	 * @param {Function} cb - gets called once we're done initializing
 	 */
 	getSongFromId: function(songId, cb) {
 		async.waterfall([
-
 			(next) => {
-				db.models.song.findOne({songId}, next);
+				db.models.song.findOne({ _id: songId }, next);
 			}
-
 		], (err, song) => {
 			if (err && err !== true) return cb(err);
-
-			cb(null, song);
+			else return cb(null, song);
 		});
 	},
 

+ 2 - 3
backend/logic/stations.js

@@ -183,7 +183,6 @@ module.exports = {
 	getStation: function(stationId, cb) {
 		let _this = this;
 		async.waterfall([
-
 			(next) => {
 				cache.hget('stations', stationId, next);
 			},
@@ -196,7 +195,7 @@ module.exports = {
 			(station, next) => {
 				if (station) {
 					if (station.type === 'official') {
-						_this.calculateOfficialPlaylistList(station._id, station.playlist, ()=>{});
+						_this.calculateOfficialPlaylistList(station._id, station.playlist, () => {});
 					}
 					station = cache.schemas.station(station);
 					cache.hset('stations', stationId, station);
@@ -216,7 +215,7 @@ module.exports = {
 		async.waterfall([
 
 			(next) => {
-				db.models.station.findOne({name: stationName}, next);
+				db.models.station.findOne({ name: stationName }, next);
 			},
 
 			(station, next) => {