feat(agents): align delete scope
This commit is contained in:
@@ -245,10 +245,15 @@ func (r *AgentRepo) UpdateAgent(ctx context.Context, userID, accountID uint, nam
|
||||
// Reference: Chatwoot agents_controller.rb#destroy → current_account_user.destroy!
|
||||
// If the user has no other account memberships, deletes the user record too.
|
||||
func (r *AgentRepo) DeleteAgent(ctx context.Context, userID, accountID uint) error {
|
||||
// Delete the AccountUser
|
||||
var accountUser model.AccountUser
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("account_id = ? AND user_id = ?", accountID, userID).
|
||||
Delete(&model.AccountUser{}).Error; err != nil {
|
||||
First(&accountUser).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete the AccountUser after the scoped lookup succeeds.
|
||||
if err := r.db.WithContext(ctx).Delete(&accountUser).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user