Skip to content

Commit

Permalink
fix(api) force group id unique among physical (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
helderbetiol authored Dec 7, 2023
1 parent 063c467 commit 8e11502
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion API/models/validateEntity.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ func ValidateEntity(entity int, t map[string]interface{}) *u.Error {
Message: "Unable to verify objects in specified group" +
" please check and try again"}
}

} else if parent["parent"].(string) == "room" {
//If parent is room, retrieve corridors and racks
corridors, err := GetManyObjects("corridor", filter, u.RequestFilters{}, nil)
Expand All @@ -332,6 +331,21 @@ func ValidateEntity(entity int, t map[string]interface{}) *u.Error {
"Please check and try again"}
}
}

// Check if Group ID is unique
entities := u.GetEntitiesByNamespace(u.Physical, t["id"].(string))
for _, entStr := range entities {
// Get objects
entData, err := GetManyObjects(entStr, bson.M{"id": t["id"]}, u.RequestFilters{}, nil)
if err != nil {
err.Message = "Error while check id unicity at " + entStr + ":" + err.Message
return err
}
if len(entData) > 0 {
return &u.Error{Type: u.ErrBadFormat,
Message: "This group ID is not unique among " + entStr + "s"}
}
}
}
}
}
Expand Down

0 comments on commit 8e11502

Please sign in to comment.