New data model update for Match tab

This commit is contained in:
advplyr 2022-03-14 08:12:28 -05:00
parent 7d66f1eec9
commit 7348432594
3 changed files with 45 additions and 15 deletions

View File

@ -169,14 +169,18 @@ export default {
async updateDetails(updatedDetails) { async updateDetails(updatedDetails) {
this.isProcessing = true this.isProcessing = true
console.log('Sending update', updatedDetails.updatePayload) 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) console.error('Failed to update', error)
return false return false
}) })
this.isProcessing = false this.isProcessing = false
if (updatedAudiobook) { if (updateResult) {
this.$toast.success('Update Successful') if (updateResult.updated) {
this.$emit('close') this.$toast.success('Item details updated')
// this.$emit('close')
} else {
this.$toast.info('No updates were necessary')
}
} }
}, },
removeItem() { removeItem() {

View File

@ -229,9 +229,28 @@ export default {
}, },
buildMatchUpdatePayload() { buildMatchUpdatePayload() {
var updatePayload = {} var updatePayload = {}
var volumeNumber = this.selectedMatchUsage.volumeNumber ? this.selectedMatch.volumeNumber || null : null
for (const key in this.selectedMatchUsage) { for (const key in this.selectedMatchUsage) {
if (this.selectedMatchUsage[key] && this.selectedMatch[key]) { 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 return updatePayload
@ -252,28 +271,32 @@ export default {
return false return false
}) })
if (success) { if (success) {
this.$toast.success('Book Cover Updated') this.$toast.success('Item Cover Updated')
} else { } else {
this.$toast.error('Book Cover Failed to Update') this.$toast.error('Item Cover Failed to Update')
} }
console.log('Updated cover') console.log('Updated cover')
delete updatePayload.cover delete updatePayload.cover
} }
if (Object.keys(updatePayload).length) { if (Object.keys(updatePayload).length) {
var bookUpdatePayload = { var mediaUpdatePayload = {
book: updatePayload 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) console.error('Failed to update', error)
return false return false
}) })
if (success) { if (updateResult) {
this.$toast.success('Book Details Updated') if (updateResult.updated) {
this.$toast.success('Item details updated')
} else {
this.$toast.info('No detail updates were necessary')
}
this.selectedMatch = null this.selectedMatch = null
this.$emit('selectTab', 'details') this.$emit('selectTab', 'details')
} else { } else {
this.$toast.error('Book Details Failed to Update') this.$toast.error('Item Details Failed to Update')
} }
} else { } else {
this.selectedMatch = null this.selectedMatch = null

View File

@ -49,12 +49,15 @@ class LibraryItemController {
await this.db.updateLibraryItem(libraryItem) await this.db.updateLibraryItem(libraryItem)
this.emitter('item_updated', libraryItem.toJSONExpanded()) this.emitter('item_updated', libraryItem.toJSONExpanded())
} }
res.json(libraryItem) res.json({
updated: hasUpdates,
libraryItem
})
} }
// POST: api/items/:id/cover // POST: api/items/:id/cover
async uploadCover(req, res) { 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) Logger.warn('User attempted to upload a cover without permission', req.user)
return res.sendStatus(403) return res.sendStatus(403)
} }