feat(supervisor): allow up to 3 supervisors per owner
This commit is contained in:
@@ -40,14 +40,17 @@ type SupervisorStatusResult struct {
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInviteNotFound = errors.New("邀请不存在")
|
||||
ErrInviteExpired = errors.New("邀请已过期")
|
||||
ErrInviteUsed = errors.New("邀请已被使用")
|
||||
ErrCannotBindSelf = errors.New("不能绑定自己为监督人")
|
||||
ErrBindingExists = errors.New("监督关系已存在")
|
||||
ErrBindingNotFound = errors.New("监督关系不存在")
|
||||
ErrInviteNotFound = errors.New("邀请不存在")
|
||||
ErrInviteExpired = errors.New("邀请已过期")
|
||||
ErrInviteUsed = errors.New("邀请已被使用")
|
||||
ErrCannotBindSelf = errors.New("不能绑定自己为监督人")
|
||||
ErrBindingExists = errors.New("监督关系已存在")
|
||||
ErrBindingNotFound = errors.New("监督关系不存在")
|
||||
ErrSupervisorLimitReached = errors.New("监督人已达上限")
|
||||
)
|
||||
|
||||
const maxSupervisorsPerOwner = 3
|
||||
|
||||
func (s *Service) CreateSupervisorInvite(ctx context.Context, ownerUID int, now time.Time, days int) (SupervisorInviteResult, error) {
|
||||
if days <= 0 {
|
||||
days = 7
|
||||
@@ -113,6 +116,18 @@ func (s *Service) BindSupervisorInvite(ctx context.Context, supervisorUID int, t
|
||||
return err
|
||||
}
|
||||
|
||||
// 多人监督:允许多个 supervisor,但限制最多 3 个 active supervisor。
|
||||
var activeCount int64
|
||||
if err := tx.WithContext(ctx).
|
||||
Model(&quitmodel.SupervisorBinding{}).
|
||||
Where("owner_uid = ? AND status = ?", invite.OwnerUID, "active").
|
||||
Count(&activeCount).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if activeCount >= maxSupervisorsPerOwner {
|
||||
return ErrSupervisorLimitReached
|
||||
}
|
||||
|
||||
binding := quitmodel.SupervisorBinding{
|
||||
OwnerUID: invite.OwnerUID,
|
||||
SupervisorUID: supervisorUID,
|
||||
|
||||
Reference in New Issue
Block a user