Updated getting tests

parent 4be6c83b
......@@ -138,10 +138,11 @@ module.exports.getSolutionWithFileInfo = (solutionId) => {
}
if (solution.task.tests) {
promises.push(mongoose.tests.getTests(solution.task.tests)
.then(tests => {
let getTestsPromises = solution.task.tests.map(t => mongoose.tests.getTest(t));
promises.push(Promise.all(getTestsPromises).then(tests => {
solution.task.tests = tests.map(t => t.toObject());
}))
}));
}
return Promise.all(promises);
......
......@@ -48,6 +48,10 @@ const Test = mongoose.connection.model('Test', TestSchema);
module.exports.schema = TestSchema;
module.exports.model = Test;
module.exports.getTest = (id) => {
return Test.findOne({_id: id});
};
module.exports.getTests = (testIds) => {
return Test.find({_id: {$in: testIds}});
};
......@@ -155,9 +159,3 @@ module.exports.removeTestFromContest = (contestId, testIndex) => {
return Test.remove({_id: deleteTestId});
});
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment