Browse Source

refactor: switched to dedicated action for getting list of songs in EditSongs

Kristian Vos 2 years ago
parent
commit
2ea05cb07f
2 changed files with 40 additions and 3 deletions
  1. 37 0
      backend/logic/actions/songs.js
  2. 3 3
      frontend/src/components/modals/EditSongs.vue

+ 37 - 0
backend/logic/actions/songs.js

@@ -405,6 +405,43 @@ export default {
 		);
 	}),
 
+	/**
+	 * Gets multiple songs from the Musare song ids
+	 * At this time only used in EditSongs
+	 *
+	 * @param {object} session - the session object automatically added by the websocket
+	 * @param {array} songIds - the song ids
+	 * @param {Function} cb
+	 */
+	 getSongsFromSongIds: isAdminRequired(function getSongFromSongId(session, songIds, cb) {
+		async.waterfall(
+			[
+				next => {
+					SongsModule.runJob("GET_SONGS", { songIds, properties: [
+						"youtubeId",
+						"title",
+						"artists",
+						"thumbnail",
+						"duration",
+						"verified",
+						"_id"
+					] }, this)
+						.then(response => next(null, response.songs))
+						.catch(err => next(err));
+				}
+			],
+			async (err, songs) => {
+				if (err) {
+					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
+					this.log("ERROR", "SONGS_GET_SONGS_FROM_MUSARE_IDS", `Failed to get songs. "${err}"`);
+					return cb({ status: "error", message: err });
+				}
+				this.log("SUCCESS", "SONGS_GET_SONGS_FROM_MUSARE_IDS", `Got songs successfully.`);
+				return cb({ status: "success", data: { songs } });
+			}
+		);
+	}),
+
 	/**
 	 * Updates a song
 	 *

+ 3 - 3
frontend/src/components/modals/EditSongs.vue

@@ -130,12 +130,12 @@ export default {
 		})
 	},
 	async mounted() {
-		this.songIds.forEach(songId => {
-			this.socket.dispatch("songs.getSongFromSongId", songId, res => {
+		this.socket.dispatch("songs.getSongsFromSongIds", this.songIds, res => {
+			res.data.songs.forEach(song => {
 				this.items.push({
 					status: "todo",
 					flagged: false,
-					song: res.data.song
+					song
 				});
 			});
 		});