浏览代码

refactor: Station, user and playlist update events frontend & eslint fix

Owen Diffey 2 年之前
父节点
当前提交
6e0e3f0772

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

@@ -237,14 +237,24 @@ CacheModule.runJob("SUB", {
 			modelName: "playlist"
 		});
 
-		playlistModel.findOne({ _id: data.playlistId }, [ "_id", "displayName", "type", "privacy", "songs", "createdBy", "createdAt", "createdFor" ], (err, playlist) => {
-			const newPlaylist = { ...playlist._doc, songsCount: playlist.songs.length, songsLength: playlist.songs.reduce((previous, current) => ({ duration: previous.duration + current.duration })).duration };
-			delete newPlaylist["songs"];
-			WSModule.runJob("EMIT_TO_ROOMS", {
-				rooms: ["admin.playlists"],
-				args: ["event:admin.playlist.updated", { data: { playlist: newPlaylist } }]
-			});
-		});
+		playlistModel.findOne(
+			{ _id: data.playlistId },
+			["_id", "displayName", "type", "privacy", "songs", "createdBy", "createdAt", "createdFor"],
+			(err, playlist) => {
+				const newPlaylist = {
+					...playlist._doc,
+					songsCount: playlist.songs.length,
+					songsLength: playlist.songs.reduce((previous, current) => ({
+						duration: previous.duration + current.duration
+					})).duration
+				};
+				delete newPlaylist.songs;
+				WSModule.runJob("EMIT_TO_ROOMS", {
+					rooms: ["admin.playlists"],
+					args: ["event:admin.playlist.updated", { data: { playlist: newPlaylist } }]
+				});
+			}
+		);
 	}
 });
 
@@ -1135,7 +1145,7 @@ export default {
 
 				CacheModule.runJob("PUB", {
 					channel: "playlist.updated",
-					value: { playlistId: playlistId }
+					value: { playlistId }
 				});
 
 				if (ratings && (playlist.type === "user-liked" || playlist.type === "user-disliked")) {
@@ -1520,7 +1530,7 @@ export default {
 
 				CacheModule.runJob("PUB", {
 					channel: "playlist.updated",
-					value: { playlistId: playlistId }
+					value: { playlistId }
 				});
 
 				return cb({
@@ -1599,7 +1609,7 @@ export default {
 
 				CacheModule.runJob("PUB", {
 					channel: "playlist.updated",
-					value: { playlistId: playlistId }
+					value: { playlistId }
 				});
 
 				ActivitiesModule.runJob("ADD_ACTIVITY", {
@@ -1833,7 +1843,7 @@ export default {
 
 				CacheModule.runJob("PUB", {
 					channel: "playlist.updated",
-					value: { playlistId: playlistId }
+					value: { playlistId }
 				});
 
 				ActivitiesModule.runJob("ADD_ACTIVITY", {
@@ -1911,7 +1921,7 @@ export default {
 
 				CacheModule.runJob("PUB", {
 					channel: "playlist.updated",
-					value: { playlistId: playlistId }
+					value: { playlistId }
 				});
 
 				return cb({

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

@@ -531,12 +531,16 @@ CacheModule.runJob("SUB", {
 			modelName: "station"
 		});
 
-		stationModel.findOne({ _id: data.stationId }, [ "_id", "name", "displayName", "description", "type", "privacy", "owner", "partyMode", "playMode", "theme" ], (err, station) => {
-			WSModule.runJob("EMIT_TO_ROOMS", {
-				rooms: ["admin.stations"],
-				args: ["event:admin.station.updated", { data: { station } }]
-			});
-		});
+		stationModel.findOne(
+			{ _id: data.stationId },
+			["_id", "name", "displayName", "description", "type", "privacy", "owner", "partyMode", "playMode", "theme"],
+			(err, station) => {
+				WSModule.runJob("EMIT_TO_ROOMS", {
+					rooms: ["admin.stations"],
+					args: ["event:admin.station.updated", { data: { station } }]
+				});
+			}
+		);
 	}
 });
 

+ 23 - 8
backend/logic/actions/users.js

@@ -174,14 +174,29 @@ CacheModule.runJob("SUB", {
 			modelName: "user"
 		});
 
-		userModel.findOne({ _id: data.userId }, [ "_id", "name", "username", "avatar", "services.github.id", "role", "email.address", "email.verified", "statistics.songsRequested", "services.password.password" ], (err, user) => {
-			const newUser = { ...user._doc, hasPassword: !!user.services.password.password };
-			delete newUser.services["password"];
-			WSModule.runJob("EMIT_TO_ROOMS", {
-				rooms: ["admin.users", `edit-user.${data.userId}`],
-				args: ["event:admin.user.updated", { data: { user: newUser } }]
-			});
-		});
+		userModel.findOne(
+			{ _id: data.userId },
+			[
+				"_id",
+				"name",
+				"username",
+				"avatar",
+				"services.github.id",
+				"role",
+				"email.address",
+				"email.verified",
+				"statistics.songsRequested",
+				"services.password.password"
+			],
+			(err, user) => {
+				const newUser = { ...user._doc, hasPassword: !!user.services.password.password };
+				delete newUser.services.password;
+				WSModule.runJob("EMIT_TO_ROOMS", {
+					rooms: ["admin.users", `edit-user.${data.userId}`],
+					args: ["event:admin.user.updated", { data: { user: newUser } }]
+				});
+			}
+		);
 	}
 });
 

+ 5 - 0
frontend/src/pages/Admin/tabs/Playlists.vue

@@ -293,6 +293,11 @@ export default {
 			],
 			events: {
 				adminRoom: "playlists",
+				updated: {
+					event: "admin.playlist.updated",
+					id: "playlist._id",
+					item: "playlist"
+				},
 				removed: {
 					event: "admin.playlist.deleted",
 					id: "playlistId"

+ 5 - 0
frontend/src/pages/Admin/tabs/Stations.vue

@@ -359,6 +359,11 @@ export default {
 			],
 			events: {
 				adminRoom: "stations",
+				updated: {
+					event: "admin.station.updated",
+					id: "station._id",
+					item: "station"
+				},
 				removed: {
 					event: "admin.station.deleted",
 					id: "stationId"

+ 6 - 1
frontend/src/pages/Admin/tabs/Users.vue

@@ -204,7 +204,7 @@ export default {
 						name: "type",
 						displayName: "Type",
 						properties: ["type"],
-						sortProperty: "type"
+						sortable: false
 					},
 					{
 						name: "userId",
@@ -417,6 +417,11 @@ export default {
 				],
 				events: {
 					adminRoom: "users",
+					updated: {
+						event: "admin.user.updated",
+						id: "user._id",
+						item: "user"
+					},
 					removed: {
 						event: "user.removed",
 						id: "userId"