Update test for new mirera

parent cd5fdfc0
......@@ -62,6 +62,9 @@ module.exports = (connectionUri, relaxed) => {
module.exports.tasks = require('./task');
mongoose.tasks = module.exports.tasks;
module.exports.tests = require('./test');
mongoose.tests = module.exports.tests;
module.exports.groups = require('./group');
mongoose.groups = module.exports.groups;
......
......@@ -137,6 +137,13 @@ module.exports.getSolutionWithFileInfo = (solutionId) => {
}))
}
if (solution.task.tests) {
promises.push(mongoose.tests.getTests(solution.task.tests)
.then(tests => {
solution.task.tests = tests.map(t => t.toObject());
}))
}
return Promise.all(promises);
})
.then(() => {
......
"use strict";
const mongoose = require("mongoose");
const dbContests = require('./contest');
const dbTasks = require('./task');
const TestSchema = new mongoose.Schema({
inputType: {
type: String,
required: true
},
inputProgramArgs: {
type: String
},
inputFiles: {
type: [mongoose.Schema.Types.ObjectId],
refs: 'fs'
},
stdinFile: {
type: mongoose.Schema.Types.ObjectId,
refs: 'fs'
},
outputType: {
type: String,
required: true
},
outputProgramArgs: {
type: String
},
outputFiles: {
type: [mongoose.Schema.Types.ObjectId],
refs: 'fs'
},
stdoutFile: {
type: mongoose.Schema.Types.ObjectId,
refs: 'fs'
},
runArgs: {
type: String
},
exitCode: {
type: Number,
}
});
const Test = mongoose.connection.model('Test', TestSchema);
module.exports.schema = TestSchema;
module.exports.model = Test;
module.exports.getTests = (testIds) => {
return Test.find({_id: {$in: testIds}});
};
module.exports.createTest = (test) => {
return new Test(test).save();
};
module.exports.updateTest = (testId, test) => {
return Test.findOneAndUpdate({_id: testId}, test);
};
module.exports.copyTestToTask = (taskId, testIndex) => {
let newTask = {};
return dbTasks.model.findOne({_id: taskId})
.then((task) => {
newTask = task;
return Test.findOne({_id: task.tests[testIndex]});
})
.then((test) => {
test = test.toObject();
test._id = undefined;
return module.exports.createTest(test);
})
.then((newTest) => {
newTask = newTask.toObject();
newTask.tests.push(newTest._id);
return dbTasks.model.update({_id: taskId}, newTask);
});
};
module.exports.copyTestToContest = (contestId, testIndex) => {
let newContest = {};
return dbContests.model.findOne({_id: contestId})
.then((contest) => {
newContest = contest;
return Test.findOne({_id: contest.tests[testIndex]});
})
.then((test) => {
test = test.toObject();
test._id = undefined;
return module.exports.createTest(test);
})
.then((newTest) => {
newContest = newContest.toObject();
newContest.tests.push(newTest._id);
return dbContests.model.update({_id: contestId}, newContest);
});
};
module.exports.addTestToTask = (taskId, test) => {
return module.exports.createTest(test)
.then((test) => {
return dbTasks.model.findOneAndUpdate({_id : taskId}, { $push: { tests: test._id } });
});
};
module.exports.addTestToContest = (contestId, test) => {
return module.exports.createTest(test)
.then((test) => {
return dbContests.model.findOneAndUpdate({_id : contestId}, { $push: { tests: test._id } });
});
};
module.exports.removeTestFromTask = (taskId, testIndex) => {
let deleteTestId = {};
return dbTasks.model.findOne({_id: taskId})
.then((task) => {
let newTask = task.toObject();
deleteTestId = newTask.tests[testIndex];
newTask.tests.splice(testIndex, 1);
return dbTasks.model.update({_id: taskId}, newTask);
})
.then(() => {
return Test.remove({_id: deleteTestId});
});
};
module.exports.removeTestFromContest = (contestId, testIndex) => {
let deleteTestId = {};
return dbContests.model.findOne({_id: contestId})
.then((contest) => {
let newContest = contest.toObject();
deleteTestId = newContest.tests[testIndex];
newContest.tests.splice(testIndex, 1);
return dbContests.model.update({_id: contestId}, newContest);
})
.then(() => {
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