Skip to content

Commit

Permalink
Merge pull request #612 from jay-m-dev/master
Browse files Browse the repository at this point in the history
Add check for running experiments before deleting
  • Loading branch information
jay-m-dev authored Sep 26, 2023
2 parents 329144a + 0a83b76 commit 81e10dc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lab/lab.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ app.delete('/api/v1/datasets/:id', async (req, res, next) => {
let dataset = await db.datasets.findByIdAsync(dataset_id);

if (dataset == null) {
return res.send({ message: 'dataset ' + req.params.id + ' not found'});
return res.status(404).send({ message: 'dataset ' + req.params.id + ' not found'});
}

const dataset_file_id = db.toObjectID(dataset.files[0]._id);
Expand All @@ -648,7 +648,14 @@ app.delete('/api/v1/datasets/:id', async (req, res, next) => {
{"_dataset_id": {"$eq": dataset_id}},
{"_dataset_file_id": {"$eq": dataset_file_id}},
]}

let experiments = await db.experiments.find(query).toArrayAsync();
let runningExp = experiments.find(exp => exp._status == 'running');

if (runningExp) {
return res.status(409).send({message: 'cannot delete dataset, experiments running'});
}

let experimentIds = []; // maybe I don't need this one.
experiments.forEach(exp => {
experimentIds.push(exp._id);
Expand Down

0 comments on commit 81e10dc

Please sign in to comment.