Prechádzať zdrojové kódy

fix(BulkActions): Prevent adding duplicate items

Owen Diffey 2 rokov pred
rodič
commit
cb46d2ddce
1 zmenil súbory, kde vykonal 30 pridanie a 0 odobranie
  1. 30 0
      backend/logic/actions/songs.js

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

@@ -1893,6 +1893,16 @@ export default {
 				(songsFound, next) => {
 					const query = {};
 					if (method === "add") {
+						songModel.updateMany(
+							{ _id: { $in: songsFound } },
+							{ $pullAll: { genres } },
+							{ runValidators: true },
+							err => {
+								if (err) {
+									next(err);
+								}
+							}
+						);
 						query.$push = { genres: { $each: genres } };
 					} else if (method === "remove") {
 						query.$pullAll = { genres };
@@ -1991,6 +2001,16 @@ export default {
 				(songsFound, next) => {
 					const query = {};
 					if (method === "add") {
+						songModel.updateMany(
+							{ _id: { $in: songsFound } },
+							{ $pullAll: { artists } },
+							{ runValidators: true },
+							err => {
+								if (err) {
+									next(err);
+								}
+							}
+						);
 						query.$push = { artists: { $each: artists } };
 					} else if (method === "remove") {
 						query.$pullAll = { artists };
@@ -2089,6 +2109,16 @@ export default {
 				(songsFound, next) => {
 					const query = {};
 					if (method === "add") {
+						songModel.updateMany(
+							{ _id: { $in: songsFound } },
+							{ $pullAll: { tags } },
+							{ runValidators: true },
+							err => {
+								if (err) {
+									next(err);
+								}
+							}
+						);
 						query.$push = { tags: { $each: tags } };
 					} else if (method === "remove") {
 						query.$pullAll = { tags };