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) {
|
DeleteAuthor (obj) {
|
||||||
this.showModal = true
|
this.showModal = true
|
||||||
this.$on('delete-submit', function () {
|
this.$on('delete-submit', function () {
|
||||||
HTTP.delete('authors/' + obj.ID.content)
|
// Prevent deleting already deleted authors
|
||||||
.then(response => {
|
if (obj) {
|
||||||
if (response.status === 200 && response.data.Message === 'success') {
|
HTTP.delete('authors/' + obj.ID.content)
|
||||||
// Fire a notification
|
.then(response => {
|
||||||
this.$notify({
|
if (response.status === 200 && response.data.Message === 'success') {
|
||||||
type: 'success',
|
// Fire a notification
|
||||||
title: this.langGeneral.success,
|
this.$notify({
|
||||||
text: this.translate('authors').deleteSuccess
|
type: 'success',
|
||||||
})
|
title: this.langGeneral.success,
|
||||||
|
text: this.translate('authors').deleteSuccess
|
||||||
|
})
|
||||||
|
this.loadAuthors()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
this.errorNotification(e)
|
||||||
this.loadAuthors()
|
this.loadAuthors()
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
.catch(e => {
|
obj = null
|
||||||
this.errorNotification(e)
|
|
||||||
this.loadAuthors()
|
|
||||||
})
|
|
||||||
this.showModal = false
|
this.showModal = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -233,22 +233,26 @@ export default {
|
||||||
deleteBook (obj) {
|
deleteBook (obj) {
|
||||||
this.showModal = true
|
this.showModal = true
|
||||||
this.$on('delete-submit', function () {
|
this.$on('delete-submit', function () {
|
||||||
HTTP.delete('books/' + obj.ID.content)
|
// Prevent deleting already deleted books
|
||||||
.then(response => {
|
if (obj) {
|
||||||
if (response.status === 200 && response.data.Message === 'success') {
|
HTTP.delete('books/' + obj.ID.content)
|
||||||
// Fire a notification
|
.then(response => {
|
||||||
this.$notify({
|
if (response.status === 200 && response.data.Message === 'success') {
|
||||||
type: 'success',
|
// Fire a notification
|
||||||
title: this.langGeneral.success,
|
this.$notify({
|
||||||
text: this.langBook.deleteSuccess
|
type: 'success',
|
||||||
})
|
title: this.langGeneral.success,
|
||||||
|
text: this.langBook.deleteSuccess
|
||||||
|
})
|
||||||
|
this.loadBooks()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
this.errorNotification(e)
|
||||||
this.loadBooks()
|
this.loadBooks()
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
.catch(e => {
|
obj = null
|
||||||
this.errorNotification(e)
|
|
||||||
this.loadBooks()
|
|
||||||
})
|
|
||||||
this.showModal = false
|
this.showModal = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -40,9 +40,9 @@
|
||||||
this.$emit('close')
|
this.$emit('close')
|
||||||
}
|
}
|
||||||
// Send it when enter is pressed
|
// Send it when enter is pressed
|
||||||
if (e.keyCode === 13) {
|
/* if (e.keyCode === 13) {
|
||||||
this.$emit('submit')
|
this.$emit('submit')
|
||||||
}
|
} */
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,21 +177,25 @@ export default {
|
||||||
DeletePublisher (obj) {
|
DeletePublisher (obj) {
|
||||||
this.showModal = true
|
this.showModal = true
|
||||||
this.$on('delete-submit', function () {
|
this.$on('delete-submit', function () {
|
||||||
HTTP.delete('publishers/' + obj.ID.content)
|
// Prevent again deleting already deleted publishers
|
||||||
.then(response => {
|
if (obj) {
|
||||||
if (response.status === 200 && response.data.Message === 'success') {
|
HTTP.delete('publishers/' + obj.ID.content)
|
||||||
// Fire a notification
|
.then(response => {
|
||||||
this.$notify({
|
if (response.status === 200 && response.data.Message === 'success') {
|
||||||
type: 'success',
|
// Fire a notification
|
||||||
title: this.langGeneral.success,
|
this.$notify({
|
||||||
text: this.translate('publishers').deleteSuccess
|
type: 'success',
|
||||||
})
|
title: this.langGeneral.success,
|
||||||
this.loadPublishers()
|
text: this.translate('publishers').deleteSuccess
|
||||||
}
|
})
|
||||||
})
|
this.loadPublishers()
|
||||||
.catch(e => {
|
}
|
||||||
this.errorNotification(e)
|
})
|
||||||
})
|
.catch(e => {
|
||||||
|
this.errorNotification(e)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
obj = null
|
||||||
this.showModal = false
|
this.showModal = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -35,12 +35,18 @@ func AddOrUpdateBook(book Book) (newBook Book, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println(publisherid)
|
||||||
|
|
||||||
_, exists, err = GetPublisherByID(publisherid)
|
_, exists, err = GetPublisherByID(publisherid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Book{}, err
|
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})
|
newPublisher, err := AddOrUpdatePublisher(Publisher{Name: book.Publisher.Name})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Book{}, err
|
return Book{}, err
|
||||||
|
|
|
@ -3,10 +3,12 @@ package models
|
||||||
// AddOrUpdatePublisher adds or updates a publisher from a publisher struct
|
// AddOrUpdatePublisher adds or updates a publisher from a publisher struct
|
||||||
func AddOrUpdatePublisher(publisher Publisher) (newPublisher Publisher, err error) {
|
func AddOrUpdatePublisher(publisher Publisher) (newPublisher Publisher, err error) {
|
||||||
if publisher.ID == 0 {
|
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 {
|
if err != nil {
|
||||||
return Publisher{}, err
|
return Publisher{}, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_, err = x.Where("id = ?", publisher.ID).Update(&publisher)
|
_, err = x.Where("id = ?", publisher.ID).Update(&publisher)
|
||||||
|
|
Loading…
Reference in New Issue