diff --git a/internal/db/repository/chat.go b/internal/db/repository/chat.go index 50f12fd..d06ba72 100644 --- a/internal/db/repository/chat.go +++ b/internal/db/repository/chat.go @@ -47,6 +47,9 @@ func (c *Chat) ByIDWithIntegrations(id uint64) (*model.Chat, error) { } func (c *Chat) Save(chat *model.Chat) error { + if chat.ID == 0 { + return c.db.Create(chat).Error + } return c.db.Model(chat).Save(chat).Error } diff --git a/internal/db/repository/integration.go b/internal/db/repository/integration.go index 0f35d13..93f1329 100644 --- a/internal/db/repository/integration.go +++ b/internal/db/repository/integration.go @@ -23,6 +23,9 @@ func (r *Integration) LoadForChatAndType(chatID uint64, typ model.IntegrationTyp } func (r *Integration) Save(integration *model.Integration) error { + if integration.ID == 0 { + return r.db.Create(integration).Error + } return r.db.Model(integration).Save(integration).Error } diff --git a/internal/db/repository/user.go b/internal/db/repository/user.go index a7f4908..2222df4 100644 --- a/internal/db/repository/user.go +++ b/internal/db/repository/user.go @@ -47,5 +47,8 @@ func (u *User) ByIDWithChats(id uint64) (*model.User, error) { } func (u *User) Save(user *model.User) error { + if user.ID == 0 { + return u.db.Create(user).Error + } return u.db.Model(user).Save(user).Error }