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,6 +178,8 @@ export default {
|
|||
DeleteAuthor (obj) {
|
||||
this.showModal = true
|
||||
this.$on('delete-submit', function () {
|
||||
// Prevent deleting already deleted authors
|
||||
if (obj) {
|
||||
HTTP.delete('authors/' + obj.ID.content)
|
||||
.then(response => {
|
||||
if (response.status === 200 && response.data.Message === 'success') {
|
||||
|
@ -194,6 +196,8 @@ export default {
|
|||
this.errorNotification(e)
|
||||
this.loadAuthors()
|
||||
})
|
||||
}
|
||||
obj = null
|
||||
this.showModal = false
|
||||
})
|
||||
},
|
||||
|
|
|
@ -233,6 +233,8 @@ export default {
|
|||
deleteBook (obj) {
|
||||
this.showModal = true
|
||||
this.$on('delete-submit', function () {
|
||||
// Prevent deleting already deleted books
|
||||
if (obj) {
|
||||
HTTP.delete('books/' + obj.ID.content)
|
||||
.then(response => {
|
||||
if (response.status === 200 && response.data.Message === 'success') {
|
||||
|
@ -249,6 +251,8 @@ export default {
|
|||
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,6 +177,8 @@ export default {
|
|||
DeletePublisher (obj) {
|
||||
this.showModal = true
|
||||
this.$on('delete-submit', function () {
|
||||
// Prevent again deleting already deleted publishers
|
||||
if (obj) {
|
||||
HTTP.delete('publishers/' + obj.ID.content)
|
||||
.then(response => {
|
||||
if (response.status === 200 && response.data.Message === 'success') {
|
||||
|
@ -192,6 +194,8 @@ export default {
|
|||
.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,11 +3,13 @@ package models
|
|||
// AddOrUpdatePublisher adds or updates a publisher from a publisher struct
|
||||
func AddOrUpdatePublisher(publisher Publisher) (newPublisher Publisher, err error) {
|
||||
if publisher.ID == 0 {
|
||||
if publisher.Name != "" { // Only insert it if the name is not empty
|
||||
_, err = x.Insert(&publisher)
|
||||
|
||||
if err != nil {
|
||||
return Publisher{}, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_, err = x.Where("id = ?", publisher.ID).Update(&publisher)
|
||||
|
||||
|
|
Loading…
Reference in New Issue