diff --git a/client/components/modals/edit-tabs/Details.vue b/client/components/modals/edit-tabs/Details.vue index 81cf1cb8..f30bd583 100644 --- a/client/components/modals/edit-tabs/Details.vue +++ b/client/components/modals/edit-tabs/Details.vue @@ -169,14 +169,18 @@ export default { async updateDetails(updatedDetails) { this.isProcessing = true console.log('Sending update', updatedDetails.updatePayload) - var updatedAudiobook = await this.$axios.$patch(`/api/items/${this.libraryItemId}/media`, updatedDetails.updatePayload).catch((error) => { + var updateResult = await this.$axios.$patch(`/api/items/${this.libraryItemId}/media`, updatedDetails.updatePayload).catch((error) => { console.error('Failed to update', error) return false }) this.isProcessing = false - if (updatedAudiobook) { - this.$toast.success('Update Successful') - this.$emit('close') + if (updateResult) { + if (updateResult.updated) { + this.$toast.success('Item details updated') + // this.$emit('close') + } else { + this.$toast.info('No updates were necessary') + } } }, removeItem() { diff --git a/client/components/modals/edit-tabs/Match.vue b/client/components/modals/edit-tabs/Match.vue index 06049b56..3dedba03 100644 --- a/client/components/modals/edit-tabs/Match.vue +++ b/client/components/modals/edit-tabs/Match.vue @@ -229,9 +229,28 @@ export default { }, buildMatchUpdatePayload() { var updatePayload = {} + + var volumeNumber = this.selectedMatchUsage.volumeNumber ? this.selectedMatch.volumeNumber || null : null for (const key in this.selectedMatchUsage) { if (this.selectedMatchUsage[key] && this.selectedMatch[key]) { - updatePayload[key] = this.selectedMatch[key] + if (key === 'series') { + var seriesItem = { + id: `new-${Math.floor(Math.random() * 10000)}`, + name: this.selectedMatch[key], + sequence: volumeNumber + } + updatePayload.series = [seriesItem] + } else if (key === 'author') { + var authorItem = { + id: `new-${Math.floor(Math.random() * 10000)}`, + name: this.selectedMatch[key] + } + updatePayload.authors = [authorItem] + } else if (key === 'narrator') { + updatePayload.narrators = [this.selectedMatch[key]] + } else if (key !== 'volumeNumber') { + updatePayload[key] = this.selectedMatch[key] + } } } return updatePayload @@ -252,28 +271,32 @@ export default { return false }) if (success) { - this.$toast.success('Book Cover Updated') + this.$toast.success('Item Cover Updated') } else { - this.$toast.error('Book Cover Failed to Update') + this.$toast.error('Item Cover Failed to Update') } console.log('Updated cover') delete updatePayload.cover } if (Object.keys(updatePayload).length) { - var bookUpdatePayload = { - book: updatePayload + var mediaUpdatePayload = { + metadata: updatePayload } - var success = await this.$axios.$patch(`/api/items/${this.libraryItemId}`, bookUpdatePayload).catch((error) => { + var updateResult = await this.$axios.$patch(`/api/items/${this.libraryItemId}/media`, mediaUpdatePayload).catch((error) => { console.error('Failed to update', error) return false }) - if (success) { - this.$toast.success('Book Details Updated') + if (updateResult) { + if (updateResult.updated) { + this.$toast.success('Item details updated') + } else { + this.$toast.info('No detail updates were necessary') + } this.selectedMatch = null this.$emit('selectTab', 'details') } else { - this.$toast.error('Book Details Failed to Update') + this.$toast.error('Item Details Failed to Update') } } else { this.selectedMatch = null diff --git a/server/controllers/LibraryItemController.js b/server/controllers/LibraryItemController.js index a0aca65e..741a13a7 100644 --- a/server/controllers/LibraryItemController.js +++ b/server/controllers/LibraryItemController.js @@ -49,12 +49,15 @@ class LibraryItemController { await this.db.updateLibraryItem(libraryItem) this.emitter('item_updated', libraryItem.toJSONExpanded()) } - res.json(libraryItem) + res.json({ + updated: hasUpdates, + libraryItem + }) } // POST: api/items/:id/cover async uploadCover(req, res) { - if (!req.user.canUpload || !req.user.canUpdate) { + if (!req.user.canUpload) { Logger.warn('User attempted to upload a cover without permission', req.user) return res.sendStatus(403) }