feat(campaigns): derive chatwoot scheduling
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/gochat/gochat/internal/campaign"
|
||||
"github.com/gochat/gochat/internal/model"
|
||||
)
|
||||
|
||||
// CampaignRepo implements GORM repository for Campaign.
|
||||
@@ -46,6 +47,26 @@ func (r *CampaignRepo) FindByIDAndAccount(ctx context.Context, id, accountID uin
|
||||
return r.FindByDisplayIDAndAccountOrID(ctx, id, accountID)
|
||||
}
|
||||
|
||||
// FindInboxByIDAndAccount retrieves the campaign inbox scoped to the same account.
|
||||
func (r *CampaignRepo) FindInboxByIDAndAccount(ctx context.Context, inboxID, accountID uint) (*model.Inbox, error) {
|
||||
var inbox model.Inbox
|
||||
if err := r.db.WithContext(ctx).Where("id = ? AND account_id = ?", inboxID, accountID).First(&inbox).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &inbox, nil
|
||||
}
|
||||
|
||||
// AccountHasUser returns whether the user belongs to the account.
|
||||
func (r *CampaignRepo) AccountHasUser(ctx context.Context, accountID, userID uint) (bool, error) {
|
||||
var count int64
|
||||
if err := r.db.WithContext(ctx).Model(&model.AccountUser{}).
|
||||
Where("account_id = ? AND user_id = ?", accountID, userID).
|
||||
Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// FindByDisplayIDAndAccountOrID retrieves a campaign by Chatwoot display_id, falling back to primary key for legacy callers/tests.
|
||||
func (r *CampaignRepo) FindByDisplayIDAndAccountOrID(ctx context.Context, routeID, accountID uint) (*campaign.Campaign, error) {
|
||||
var c campaign.Campaign
|
||||
|
||||
Reference in New Issue
Block a user