Fix: No empty publisher is inserted when not selecting one while creating a new book
This commit is contained in:
parent
82800240a2
commit
a658797b6d
|
@ -178,22 +178,26 @@ export default {
|
|||
DeleteAuthor (obj) {
|
||||
this.showModal = true
|
||||
this.$on('delete-submit', function () {
|
||||
HTTP.delete('authors/' + obj.ID.content)
|
||||
.then(response => {
|
||||
if (response.status === 200 && response.data.Message === 'success') {
|
||||
// Fire a notification
|
||||
this.$notify({
|
||||
type: 'success',
|
||||
title: this.langGeneral.success,
|
||||
text: this.translate('authors').deleteSuccess
|
||||
})
|
||||
// Prevent deleting already deleted authors
|
||||
if (obj) {
|
||||
HTTP.delete('authors/' + obj.ID.content)
|
||||
.then(response => {
|
||||
if (response.status === 200 && response.data.Message === 'success') {
|
||||
// Fire a notification
|
||||
this.$notify({
|
||||
type: 'success',
|
||||
title: this.langGeneral.success,
|
||||
text: this.translate('authors').deleteSuccess
|
||||
})
|
||||
this.loadAuthors()
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
this.errorNotification(e)
|
||||
this.loadAuthors()
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
this.errorNotification(e)
|
||||
this.loadAuthors()
|
||||
})
|
||||
})
|
||||
}
|
||||
obj = null
|
||||
this.showModal = false
|
||||
})
|
||||
},
|
||||
|
|
|
@ -233,22 +233,26 @@ export default {
|
|||
deleteBook (obj) {
|
||||
this.showModal = true
|
||||
this.$on('delete-submit', function () {
|
||||
HTTP.delete('books/' + obj.ID.content)
|
||||
.then(response => {
|
||||
if (response.status === 200 && response.data.Message === 'success') {
|
||||
// Fire a notification
|
||||
this.$notify({
|
||||
type: 'success',
|
||||
title: this.langGeneral.success,
|
||||
text: this.langBook.deleteSuccess
|
||||
})
|
||||
// Prevent deleting already deleted books
|
||||
if (obj) {
|
||||
HTTP.delete('books/' + obj.ID.content)
|
||||
.then(response => {
|
||||
if (response.status === 200 && response.data.Message === 'success') {
|
||||
// Fire a notification
|
||||
this.$notify({
|
||||
type: 'success',
|
||||
title: this.langGeneral.success,
|
||||
text: this.langBook.deleteSuccess
|
||||
})
|
||||
this.loadBooks()
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
this.errorNotification(e)
|
||||
this.loadBooks()
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
this.errorNotification(e)
|
||||
this.loadBooks()
|
||||
})
|
||||
})
|
||||
}
|
||||
obj = null
|
||||
this.showModal = false
|
||||
})
|
||||
},
|
||||
|
|
|
@ -40,9 +40,9 @@
|
|||
this.$emit('close')
|
||||
}
|
||||
// Send it when enter is pressed
|
||||
if (e.keyCode === 13) {
|
||||
/* if (e.keyCode === 13) {
|
||||
this.$emit('submit')
|
||||
}
|
||||
} */
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,21 +177,25 @@ export default {
|
|||
DeletePublisher (obj) {
|
||||
this.showModal = true
|
||||
this.$on('delete-submit', function () {
|
||||
HTTP.delete('publishers/' + obj.ID.content)
|
||||
.then(response => {
|
||||
if (response.status === 200 && response.data.Message === 'success') {
|
||||
// Fire a notification
|
||||
this.$notify({
|
||||
type: 'success',
|
||||
title: this.langGeneral.success,
|
||||
text: this.translate('publishers').deleteSuccess
|
||||
})
|
||||
this.loadPublishers()
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
this.errorNotification(e)
|
||||
})
|
||||
// Prevent again deleting already deleted publishers
|
||||
if (obj) {
|
||||
HTTP.delete('publishers/' + obj.ID.content)
|
||||
.then(response => {
|
||||
if (response.status === 200 && response.data.Message === 'success') {
|
||||
// Fire a notification
|
||||
this.$notify({
|
||||
type: 'success',
|
||||
title: this.langGeneral.success,
|
||||
text: this.translate('publishers').deleteSuccess
|
||||
})
|
||||
this.loadPublishers()
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
this.errorNotification(e)
|
||||
})
|
||||
}
|
||||
obj = null
|
||||
this.showModal = false
|
||||
})
|
||||
},
|
||||
|
|
|
@ -35,12 +35,18 @@ func AddOrUpdateBook(book Book) (newBook Book, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
fmt.Println(publisherid)
|
||||
|
||||
_, exists, err = GetPublisherByID(publisherid)
|
||||
if err != nil {
|
||||
return Book{}, err
|
||||
}
|
||||
|
||||
if !exists {
|
||||
// If the publisher exists, make it the new publisher of the book
|
||||
if exists {
|
||||
book.PublisherID = publisherid
|
||||
} else {
|
||||
// Otherwise insert it and make it the new publisher afterwards
|
||||
newPublisher, err := AddOrUpdatePublisher(Publisher{Name: book.Publisher.Name})
|
||||
if err != nil {
|
||||
return Book{}, err
|
||||
|
|
|
@ -3,10 +3,12 @@ package models
|
|||
// AddOrUpdatePublisher adds or updates a publisher from a publisher struct
|
||||
func AddOrUpdatePublisher(publisher Publisher) (newPublisher Publisher, err error) {
|
||||
if publisher.ID == 0 {
|
||||
_, err = x.Insert(&publisher)
|
||||
if publisher.Name != "" { // Only insert it if the name is not empty
|
||||
_, err = x.Insert(&publisher)
|
||||
|
||||
if err != nil {
|
||||
return Publisher{}, err
|
||||
if err != nil {
|
||||
return Publisher{}, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_, err = x.Where("id = ?", publisher.ID).Update(&publisher)
|
||||
|
|
Loading…
Reference in New Issue