|
@@ -365,27 +365,13 @@ func (r *Role) UpdateAccess(ctx context.Context, req entity.AccessUpdateReq) err
|
|
|
// update
|
|
|
var updateFields = bson.M{
|
|
|
"module_name": req.ModuleName,
|
|
|
+ "parent_id": req.ParentId,
|
|
|
"action_name": req.ActionName,
|
|
|
"url": req.URL,
|
|
|
"type": req.Type,
|
|
|
"description": req.Description,
|
|
|
"sort": req.Sort,
|
|
|
"status": req.Status}
|
|
|
- // 去掉为空的字段
|
|
|
- for k, v := range updateFields {
|
|
|
- switch v.(type) {
|
|
|
- case string:
|
|
|
- if v == "" {
|
|
|
- delete(updateFields, k)
|
|
|
- }
|
|
|
- case int:
|
|
|
- if v == 0 {
|
|
|
- delete(updateFields, k)
|
|
|
- }
|
|
|
- default:
|
|
|
- continue
|
|
|
- }
|
|
|
- }
|
|
|
// 检查是否有需要更新的字段
|
|
|
if len(updateFields) == 0 {
|
|
|
return errors.New("no fields to update")
|
|
@@ -395,7 +381,6 @@ func (r *Role) UpdateAccess(ctx context.Context, req entity.AccessUpdateReq) err
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("invalid ObjectID: %v", err)
|
|
|
}
|
|
|
-
|
|
|
_, err = collection.UpdateByID(ctx, objID, bson.M{"$set": updateFields})
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("update failed: %v", err)
|