fix various bugs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pavel 2024-05-23 14:22:44 +03:00
parent be2cc7ddfa
commit 5ffbac8dd2
4 changed files with 8 additions and 8 deletions

View File

@ -24,7 +24,7 @@ func (c *Chat) ByID(id uint64) (*model.Chat, error) {
func (c *Chat) ByTelegramID(id int64) (*model.Chat, error) {
var chat model.Chat
if err := c.db.Model(model.Chat{TelegramID: id}).First(&chat).Error; err != nil {
if err := c.db.Model(&model.Chat{}).Where("telegram_id = ?", id).First(&chat).Error; err != nil {
return nil, util.HandleRecordNotFound(err)
}
return &chat, nil
@ -32,7 +32,7 @@ func (c *Chat) ByTelegramID(id int64) (*model.Chat, error) {
func (c *Chat) ByTelegramIDWithIntegrations(id int64) (*model.Chat, error) {
var chat model.Chat
if err := c.db.Model(model.Chat{TelegramID: id}).Preload("Integrations").First(&chat).Error; err != nil {
if err := c.db.Model(&model.Chat{}).Where("telegram_id = ?", id).Preload("Integrations").First(&chat).Error; err != nil {
return nil, util.HandleRecordNotFound(err)
}
return &chat, nil

View File

@ -16,7 +16,7 @@ func NewIntegration(db *gorm.DB) *Integration {
func (r *Integration) LoadForChatAndType(chatID uint64, typ model.IntegrationType) (*model.Integration, error) {
var integration model.Integration
if err := r.db.Model(model.Integration{ChatID: chatID, Type: typ}).First(&integration).Error; err != nil {
if err := r.db.Model(&model.Integration{}).Where(`chat_id = ? and "type" = ?`, chatID, typ).First(&integration).Error; err != nil {
return nil, util.HandleRecordNotFound(err)
}
return &integration, nil

View File

@ -24,7 +24,7 @@ func (u *User) ByID(id uint64) (*model.User, error) {
func (u *User) ByTelegramID(id int64) (*model.User, error) {
var user model.User
if err := u.db.Model(model.User{TelegramID: id}).First(&user).Error; err != nil {
if err := u.db.Model(&model.User{}).Where("telegram_id = ?", id).First(&user).Error; err != nil {
return nil, util.HandleRecordNotFound(err)
}
return &user, nil
@ -32,7 +32,7 @@ func (u *User) ByTelegramID(id int64) (*model.User, error) {
func (u *User) ByTelegramIDs(ids []int64) ([]model.User, error) {
var users []model.User
if err := u.db.Model(model.User{}).Where("telegram_id in (?)", ids).Find(&users).Error; err != nil {
if err := u.db.Model(&model.User{}).Where("telegram_id in (?)", ids).Find(&users).Error; err != nil {
return nil, util.HandleRecordNotFound(err)
}
return users, nil

View File

@ -44,7 +44,7 @@ func (p Payload) Vote() (val Vote) {
}
func (p Payload) KeyboardChoice() (val KBChooserData) {
if p.Action != PayloadActionVote {
if p.Action != PayloadActionChooseKeyboard {
return
}
_ = json.Unmarshal(p.Data, &val)
@ -65,7 +65,7 @@ type Member struct {
}
type KBChooserData struct {
Type uint8 `json:"k"`
Type int64 `json:"k"`
}
type Vote struct {
@ -83,7 +83,7 @@ func NewKeyboardChooserPayload(userID, chatID int64, kbType uint8) *Payload {
User: userID,
Chat: chatID,
Data: marshal(KBChooserData{
Type: kbType,
Type: int64(kbType),
}),
}
}