Skip to content

Commit

Permalink
fix server delete
Browse files Browse the repository at this point in the history
  • Loading branch information
mSulimenko committed Dec 8, 2024
1 parent 0bc82e8 commit d1b41c9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions server/handlers/server_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,8 @@ func DeleteServer(w http.ResponseWriter, r *http.Request) {
}

serversCollection := db.GetCollection("servers")
var server struct {
Tasks []primitive.ObjectID `bson:"tasks"`
}

var server models.Server
err = serversCollection.FindOne(context.Background(), bson.M{"_id": objectID}).Decode(&server)
if err != nil {
if errors.Is(err, mongo.ErrNoDocuments) {
Expand All @@ -238,8 +237,8 @@ func DeleteServer(w http.ResponseWriter, r *http.Request) {
return
}

if len(server.Tasks) > 0 {
http.Error(w, "Cannot delete server with active tasks", http.StatusConflict)
if len(server.CurrentJobs) > 0 || len(server.CompletedJobs) > 0 {
http.Error(w, "Cannot delete server with associated jobs", http.StatusConflict)
return
}

Expand Down

0 comments on commit d1b41c9

Please sign in to comment.