Parcourir la source

fix(AccountRemoval): station playlists aren't deleted when a station is

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan il y a 3 ans
Parent
commit
2c6f97636b

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

@@ -2380,6 +2380,7 @@ export default {
 						.catch(next);
 				},
 
+				// remove the playlist for the station
 				(station, next) => {
 					if (station.playlist)
 						PlaylistsModule.runJob("DELETE_PLAYLIST", { playlistId: station.playlist })

+ 33 - 1
backend/logic/actions/users.js

@@ -221,18 +221,50 @@ export default {
 
 		async.waterfall(
 			[
+				// activities related to the user
 				next => {
 					activityModel.deleteMany({ userId: session.userId }, next);
 				},
 
+				// user's stations
 				(res, next) => {
-					stationModel.deleteMany({ owner: session.userId }, next);
+					stationModel.find({ owner: session.userId }, (err, stations) => {
+						if (err) return next(err);
+
+						return async.each(
+							stations,
+							(station, callback) => {
+								// delete the station
+								stationModel.deleteOne({ _id: station._id }, err => {
+									if (err) return callback(err);
+
+									// if applicable, delete the corresponding playlist for the station
+									if (station.playlist)
+										return PlaylistsModule.runJob("DELETE_PLAYLIST", {
+											playlistId: station.playlist
+										})
+											.then(() => callback())
+											.catch(callback);
+
+									return callback();
+								});
+							},
+							err => next(err)
+						);
+					});
+				},
+
+				// playlists for a user's stations
+				next => {
+					playlistModel.deleteMany({ owner: session.userId }, next);
 				},
 
+				// user's playlists
 				(res, next) => {
 					playlistModel.deleteMany({ createdBy: session.userId }, next);
 				},
 
+				// user object
 				(res, next) => {
 					userModel.deleteMany({ _id: session.userId }, next);
 				}

+ 1 - 2
frontend/src/components/modals/RemoveAccount.vue

@@ -104,8 +104,7 @@
 			>
 				<h2 class="content-box-title">Verify your GitHub</h2>
 				<p class="content-box-description">
-					Check your GitHub account is still linked in order to remove
-					your account.
+					Check your account is still linked to remove your account.
 				</p>
 
 				<div class="content-box-inputs">