fix(用户): 修复删除用户软删除钩子

避免软删除钩子类型断言失败导致 500\n删除无记录时返回未找到错误并记录日志
This commit is contained in:
yangjianbo
2025-12-29 16:57:50 +08:00
parent 5584709ac9
commit 4dab18a94f
3 changed files with 14 additions and 7 deletions

View File

@@ -112,9 +112,6 @@ func (d SoftDeleteMixin) Hooks() []ent.Hook {
// 类型断言,获取 mutation 的扩展接口
mx, ok := m.(interface {
SetOp(ent.Op)
Client() interface {
Mutate(context.Context, ent.Mutation) (ent.Value, error)
}
SetDeletedAt(time.Time)
WhereP(...func(*sql.Selector))
})
@@ -127,7 +124,7 @@ func (d SoftDeleteMixin) Hooks() []ent.Hook {
mx.SetOp(ent.OpUpdate)
// 设置删除时间为当前时间
mx.SetDeletedAt(time.Now())
return mx.Client().Mutate(ctx, m)
return next.Mutate(ctx, m)
})
},
}