Browse Source

Fixed a bug with Stations on Admin Side, also tightened syntax a bit

theflametrooper 8 years ago
parent
commit
71c30f1d7c
2 changed files with 16 additions and 17 deletions
  1. 8 8
      backend/logic/actions/stations.js
  2. 8 9
      backend/logic/songs.js

+ 8 - 8
backend/logic/actions/stations.js

@@ -263,9 +263,9 @@ module.exports = {
 		});
 	},
 
-	remove: (sessionId, stationId, cb) => {
-		cache.hdel('stations', stationId, () => {
-			// TODO: Update Mongo
+	remove: (sessionId, _id, cb) => {
+		db.models.station.find({ _id }).remove().exec();
+		cache.hdel('stations', _id, () => {
 			return cb({ status: 'success', message: 'Station successfully removed' });
 		});
 	},
@@ -279,16 +279,16 @@ module.exports = {
 			},
 
 			// check the cache for the station
-			(next) => cache.hget('stations', data.name, next),
+			(next) => cache.hget('stations', data._id, next),
 
 			// if the cached version exist
 			(station, next) => {
-				if (station) return next({ 'status': 'failure', 'message': 'A station with that name already exists' });
-				db.models.station.findOne({ _id: data.name }, next);
+				if (station) return next({ 'status': 'failure', 'message': 'A station with that id already exists' });
+				db.models.station.findOne({ _id: data._id }, next);
 			},
 
 			(station, next) => {
-				if (station) return next({ 'status': 'failure', 'message': 'A station with that name already exists' });
+				if (station) return next({ 'status': 'failure', 'message': 'A station with that id already exists' });
 				const { _id, displayName, description, genres, playlist } = data;
 				db.models.station.create({
 					_id,
@@ -304,7 +304,7 @@ module.exports = {
 		], (err, station) => {
 			if (err) throw err;
 			stations.calculateSongForStation(station, () => {
-				cache.pub('station.create', data.name);
+				cache.pub('station.create', data._id);
 				return cb(null, { 'status': 'success', 'message': 'Successfully created station.' });
 			});
 		});

+ 8 - 9
backend/logic/songs.js

@@ -8,8 +8,7 @@ const async = require('async');
 
 module.exports = {
 
-	init: function(cb) {
-		let _this = this;
+	init: cb => {
 		db.models.song.find({}, (err, songs) => {
 			if (!err) {
 				songs.forEach((song) => {
@@ -21,22 +20,22 @@ module.exports = {
 	},
 
 	// Attempts to get the song from Reids. If it's not in Redis, get it from Mongo and add it to Redis.
-	getSong: function(songId, cb) {
+	getSong: function(_id, cb) {
 		async.waterfall([
 
 			(next) => {
-				cache.hget('songs', songId, next);
+				cache.hget('songs', _id, next);
 			},
 
 			(song, next) => {
 				if (song) return next(true, song);
 
-				db.models.song.findOne({_id: songId}, next);
+				db.models.song.findOne({ _id }, next);
 			},
 
 			(song, next) => {
 				if (song) {
-					cache.hset('songs', songId, song);
+					cache.hset('songs', _id, song);
 					next(true, song);
 				} else next('Song not found.');
 			},
@@ -48,17 +47,17 @@ module.exports = {
 		});
 	},
 
-	updateSong: (songId, cb) => {
+	updateSong: (_id, cb) => {
 		async.waterfall([
 
 			(next) => {
-				db.models.song.findOne({_id: songId}, next);
+				db.models.song.findOne({ _id }, next);
 			},
 
 			(song, next) => {
 				if (!song) return next('Song not found.');
 
-				cache.hset('songs', songId, song, next);
+				cache.hset('songs', _id, song, next);
 			}
 
 		], (err, song) => {