|
@@ -181,7 +181,10 @@ export default {
|
|
|
|
|
|
return cb({
|
|
return cb({
|
|
status: "success",
|
|
status: "success",
|
|
- message: "Successfully created artist"
|
|
|
|
|
|
+ message: "Successfully created artist",
|
|
|
|
+ data: {
|
|
|
|
+ artistId: artist._id
|
|
|
|
+ }
|
|
});
|
|
});
|
|
}
|
|
}
|
|
);
|
|
);
|
|
@@ -265,13 +268,59 @@ export default {
|
|
);
|
|
);
|
|
}),
|
|
}),
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Deletes an artist - shouldn't be used outside of testing
|
|
|
|
+ * @param {object} session - the session object automatically added by the websocket
|
|
|
|
+ * @param {string} artistId - the id of the artist item
|
|
|
|
+ * @param {Function} cb - gets called with the result
|
|
|
|
+ */
|
|
|
|
+ remove: useHasPermission("artists.update", async function remove(session, artistId, cb) {
|
|
|
|
+ const artistModel = await DBModule.runJob("GET_MODEL", { modelName: "artist" }, this);
|
|
|
|
+
|
|
|
|
+ async.waterfall(
|
|
|
|
+ [
|
|
|
|
+ next => {
|
|
|
|
+ if (!artistId) return next("Please provide an artist item id to remove.");
|
|
|
|
+ return next();
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ next => {
|
|
|
|
+ artistModel.remove({ _id: artistId }, err => next(err));
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ async err => {
|
|
|
|
+ if (err) {
|
|
|
|
+ err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
|
+ this.log(
|
|
|
|
+ "ERROR",
|
|
|
|
+ "ARTIST_REMOVE",
|
|
|
|
+ `Removing artist item "${artistId}" failed for user "${session.userId}". "${err}"`
|
|
|
|
+ );
|
|
|
|
+ return cb({ status: "error", message: err });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ CacheModule.runJob("PUB", { channel: "artists.remove", value: artistId });
|
|
|
|
+
|
|
|
|
+ this.log(
|
|
|
|
+ "SUCCESS",
|
|
|
|
+ "ARTIST_REMOVE",
|
|
|
|
+ `Removing artist item "${artistId}" successful for user "${session.userId}".`
|
|
|
|
+ );
|
|
|
|
+ return cb({
|
|
|
|
+ status: "success",
|
|
|
|
+ message: "Successfully removed artist item"
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ }),
|
|
|
|
+
|
|
getMusicbrainzArtist: useHasPermission(
|
|
getMusicbrainzArtist: useHasPermission(
|
|
"artists.update",
|
|
"artists.update",
|
|
async function getMusicbrainzArtist(session, musicbrainzIdentifier, cb) {
|
|
async function getMusicbrainzArtist(session, musicbrainzIdentifier, cb) {
|
|
const ArtistApiResponse = await MusicBrainzModule.runJob(
|
|
const ArtistApiResponse = await MusicBrainzModule.runJob(
|
|
"API_CALL",
|
|
"API_CALL",
|
|
{
|
|
{
|
|
- url: `https://musicbrainz.org/ws/2/artist/${musicbrainzIdentifier}/`,
|
|
|
|
|
|
+ url: `https://musicbrainz.org/ws/2/artist/${musicbrainzIdentifier}`,
|
|
params: {
|
|
params: {
|
|
fmt: "json",
|
|
fmt: "json",
|
|
inc: "aliases"
|
|
inc: "aliases"
|
|
@@ -335,5 +384,70 @@ export default {
|
|
status: "error",
|
|
status: "error",
|
|
message: "Invalid type"
|
|
message: "Invalid type"
|
|
});
|
|
});
|
|
- })
|
|
|
|
|
|
+ }),
|
|
|
|
+
|
|
|
|
+ saveLinkingData: useHasPermission("artists.update", async function saveLinkingData(session, artistId, data, cb) {
|
|
|
|
+ const artistModel = await DBModule.runJob("GET_MODEL", { modelName: "artist" }, this);
|
|
|
|
+
|
|
|
|
+ async.waterfall(
|
|
|
|
+ [
|
|
|
|
+ next => {
|
|
|
|
+ if (!artistId) return next("Please provide an artist item id to update.");
|
|
|
|
+ return next();
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ next => {
|
|
|
|
+ artistModel.updateOne({ _id: artistId }, { $set: { linkingData: data } }, err => next(err));
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ next => {
|
|
|
|
+ artistModel.findOne({ _id: artistId }, next);
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ async (err, artist) => {
|
|
|
|
+ if (err) {
|
|
|
|
+ err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
|
+ this.log(
|
|
|
|
+ "ERROR",
|
|
|
|
+ "ARTIST_SAVE_LINKING_DATA",
|
|
|
|
+ `Saving linking data for artist "${artistId}" failed for user "${session.userId}". "${err}"`
|
|
|
|
+ );
|
|
|
|
+ return cb({ status: "error", message: err });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ CacheModule.runJob("PUB", { channel: "artists.update", value: artist });
|
|
|
|
+
|
|
|
|
+ this.log(
|
|
|
|
+ "SUCCESS",
|
|
|
|
+ "ARTIST_SAVE_LINKING_DATA",
|
|
|
|
+ `Saving linking data for artist "${artistId}" was successful for user "${session.userId}".`
|
|
|
|
+ );
|
|
|
|
+ return cb({
|
|
|
|
+ status: "success",
|
|
|
|
+ message: "Successfully saved linking data"
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ }),
|
|
|
|
+
|
|
|
|
+ searchMusicbrainzArtists: useHasPermission(
|
|
|
|
+ "artists.update",
|
|
|
|
+ async function searchMusicbrainzArtists(session, query, cb) {
|
|
|
|
+ MusicBrainzModule.runJob("SEARCH_MUSICBRAINZ_ARTISTS", {
|
|
|
|
+ query
|
|
|
|
+ })
|
|
|
|
+ .then(({ musicbrainzArtists }) => {
|
|
|
|
+ cb({
|
|
|
|
+ status: "success",
|
|
|
|
+ data: {
|
|
|
|
+ musicbrainzArtists
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+ .catch(async err => {
|
|
|
|
+ err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
|
+ cb({ status: "error", message: err });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ )
|
|
};
|
|
};
|