29 lines
939 B
Go
29 lines
939 B
Go
package repository
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
// softDeleteAgentIMChannels participates in the caller's agent deletion
|
||
|
|
// transaction. Runtime invalidation must happen only after that transaction
|
||
|
|
// commits. The IM package depends on repositories, so use its durable table
|
||
|
|
// contract here rather than importing its runtime service.
|
||
|
|
func softDeleteAgentIMChannels(tx *gorm.DB, agentID string, tenantID uint64) ([]string, error) {
|
||
|
|
var ids []string
|
||
|
|
query := tx.Table("im_channels").Where("agent_id = ? AND tenant_id = ? AND deleted_at IS NULL", agentID, tenantID)
|
||
|
|
if err := query.Pluck("id", &ids).Error; err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if len(ids) == 0 {
|
||
|
|
return ids, nil
|
||
|
|
}
|
||
|
|
now := time.Now()
|
||
|
|
if err := tx.Table("im_channels").Where("id IN ? AND tenant_id = ?", ids, tenantID).
|
||
|
|
Updates(map[string]any{"enabled": false, "deleted_at": now, "updated_at": now}).Error; err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return ids, nil
|
||
|
|
}
|