Skip to content

Commit

Permalink
fix: role does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor-Lan committed Aug 26, 2022
1 parent 034cfa8 commit cd3fe15
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/core/cmd/api/internal/logic/sys/role/addsysrolelogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func NewAddSysRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddSys
func (l *AddSysRoleLogic) AddSysRole(req *types.AddSysRoleReq) error {
_, err := l.svcCtx.SysRoleModel.FindOneByUniqueKey(l.ctx, req.UniqueKey)
if err == model.ErrNotFound {
if req.ParentId != 0 {
_, err := l.svcCtx.SysRoleModel.FindOne(l.ctx,req.ParentId)
if err != nil {
return errorx.NewDefaultError(errorx.ParentRoleIdErrorCode)
}
}

var sysRole = new(model.SysRole)
err = copier.Copy(sysRole, req)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func NewUpdateSysRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upd
}

func (l *UpdateSysRoleLogic) UpdateSysRole(req *types.UpdateSysRoleReq) error {
if req.ParentId != 0 {
_, err := l.svcCtx.SysRoleModel.FindOne(l.ctx,req.ParentId)
if err != nil {
return errorx.NewDefaultError(errorx.ParentRoleIdErrorCode)
}
}

if req.Id == config.SysProtectRoleId {
return errorx.NewDefaultError(errorx.NotPermMenuErrorCode)
}
Expand Down
4 changes: 4 additions & 0 deletions common/errorx/errormsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const (
DeptIdErrorCode = 1034
ProfessionIdErrorCode = 1035
JobIdErrorCode = 1036
ParentRoleIdErrorCode = 1037
ParentDeptIdErrorCode = 1038
)

func init() {
Expand Down Expand Up @@ -80,6 +82,8 @@ func init() {
errorMsg[DeptIdErrorCode] = "部门不存在"
errorMsg[ProfessionIdErrorCode] = "职称不存在"
errorMsg[JobIdErrorCode] = "岗位不存在"
errorMsg[ParentRoleIdErrorCode] = "父级角色不存在"
errorMsg[ParentDeptIdErrorCode] = "父级部门不存在"
}

func MapErrMsg(errCode int) string {
Expand Down

0 comments on commit cd3fe15

Please sign in to comment.