mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
fixing remove card when associated
This commit is contained in:
parent
17eb18ce6a
commit
24d6eade1e
@ -23,7 +23,7 @@ func RemoveCard(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// load referenced card
|
// load referenced card
|
||||||
var slot store.CardSlot
|
var slot store.CardSlot
|
||||||
if err := store.DB.Preload("Card.Groups").Preload("Card.Channels.Cards").Preload("Card.Channels.ChannelSlot").Where("account_id = ? AND card_slot_id = ?", account.ID, cardID).First(&slot).Error; err != nil {
|
if err := store.DB.Preload("Card.Groups").Preload("Card.Channels.Members.Card").Preload("Card.Channels.ChannelSlot").Where("account_id = ? AND card_slot_id = ?", account.ID, cardID).First(&slot).Error; err != nil {
|
||||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
ErrResponse(w, http.StatusInternalServerError, err)
|
ErrResponse(w, http.StatusInternalServerError, err)
|
||||||
} else {
|
} else {
|
||||||
@ -42,7 +42,7 @@ func RemoveCard(w http.ResponseWriter, r *http.Request) {
|
|||||||
// save and update contact revision
|
// save and update contact revision
|
||||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||||
for _, channel := range slot.Card.Channels {
|
for _, channel := range slot.Card.Channels {
|
||||||
if res := tx.Model(&channel).Association("Cards").Delete(slot.Card); res != nil {
|
if res := tx.Where("card_id = ?", slot.Card.ID).Delete(&store.Member{}).Error; res != nil {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
if res := tx.Model(&channel).Update("detail_revision", account.ChannelRevision+1).Error; res != nil {
|
if res := tx.Model(&channel).Update("detail_revision", account.ChannelRevision+1).Error; res != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user