Selaa lähdekoodia

fix(Songs): Create song job does not set requested/verified at/by attributes

Owen Diffey 3 vuotta sitten
vanhempi
commit
241e68f1bf
2 muutettua tiedostoa jossa 23 lisäystä ja 2 poistoa
  1. 1 1
      backend/logic/actions/songs.js
  2. 22 1
      backend/logic/songs.js

+ 1 - 1
backend/logic/actions/songs.js

@@ -452,7 +452,7 @@ export default {
 		async.waterfall(
 			[
 				next => {
-					SongsModule.runJob("CREATE_SONG", { song: newSong }, this)
+					SongsModule.runJob("CREATE_SONG", { song: newSong, userId: session.userId }, this)
 						.then(song => next(null, song))
 						.catch(next);
 				}

+ 22 - 1
backend/logic/songs.js

@@ -289,6 +289,7 @@ class _SongsModule extends CoreClass {
 	 *
 	 * @param {object} payload - an object containing the payload
 	 * @param {string} payload.song - the song object
+	 * @param {string} payload.userId - the user id of the person requesting the song
 	 * @returns {Promise} - returns a promise (resolve, reject)
 	 */
 	CREATE_SONG(payload) {
@@ -296,7 +297,27 @@ class _SongsModule extends CoreClass {
 			async.waterfall(
 				[
 					next => {
-						const song = new SongsModule.SongModel(payload.song);
+						DBModule.runJob("GET_MODEL", { modelName: "user" }, this)
+							.then(UserModel => {
+								UserModel.findOne(
+									{ _id: payload.userId },
+									{ "preferences.anonymousSongRequests": 1 },
+									next
+								);
+							})
+							.catch(next);
+					},
+
+					(user, next) => {
+						const song = new SongsModule.SongModel({
+							...payload.song,
+							requestedBy: user.preferences.anonymousSongRequests ? null : payload.userId,
+							requestedAt: Date.now()
+						});
+						if (song.verified) {
+							song.verifiedBy = payload.userId;
+							song.verifiedAt = Date.now();
+						}
 						song.save({ validateBeforeSave: true }, err => {
 							if (err) return next(err, song);
 							return next(null, song);