Skip to content

Commit 00058b0

Browse files
committed
check if approve node has any nodes to approve before updating db
1 parent 77f9f13 commit 00058b0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

node-registrar/pkg/db/farms.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (db *Database) ApproveNodes(farmID uint64, nodeIDs []uint64) error {
9090
return result.Error
9191
}
9292

93-
// Check if all nodes were found and updated
93+
// Check if all nodes were found, belong to the requested farm and updated
9494
if int(result.RowsAffected) != len(nodeIDs) {
9595
tx.Rollback()
9696
return fmt.Errorf("some nodes were not found, do not belong to farm %d, or are already approved", farmID)

node-registrar/pkg/server/handlers.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ func (s *Server) approveNodesHandler(c *gin.Context) {
863863
return
864864
}
865865

866-
// Ensure the requester owns the farm
866+
// Ensure the farmer approving the nodes is the owner of the farm
867867
ensureOwner(c, farm.TwinID)
868868
if c.IsAborted() {
869869
return
@@ -875,6 +875,11 @@ func (s *Server) approveNodesHandler(c *gin.Context) {
875875
return
876876
}
877877

878+
if len(req.NodeIDs) == 0 {
879+
c.JSON(http.StatusBadRequest, gin.H{"error": "could not find any nodes to approve"})
880+
return
881+
}
882+
878883
if err := s.db.ApproveNodes(id, req.NodeIDs); err != nil {
879884
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
880885
return

0 commit comments

Comments
 (0)