Merge branch 'develop' into 'develop'

Updated test model

See merge request !1
parents e993bf69 2f0687fc
"use strict";
const mongoose = require("mongoose");
const mongoose = require('mongoose');
const defines = require('./defines');
const TestSchema = new mongoose.Schema({
owner: {
......@@ -9,7 +11,7 @@ const TestSchema = new mongoose.Schema({
},
created: {
type: Date,
default: new Date()
default: Date.now
},
task: {
type: mongoose.Schema.Types.ObjectId
......@@ -33,10 +35,6 @@ const TestSchema = new mongoose.Schema({
refs: 'fs',
default: []
},
useStdin: {
type: Boolean,
default: false,
},
stdinFile: {
type: mongoose.Schema.Types.ObjectId,
refs: 'fs'
......@@ -53,10 +51,6 @@ const TestSchema = new mongoose.Schema({
refs: 'fs',
default: []
},
checkStdout: {
type: Boolean,
default: false,
},
stdoutFile: {
type: mongoose.Schema.Types.ObjectId,
refs: 'fs'
......@@ -67,6 +61,10 @@ const TestSchema = new mongoose.Schema({
exitCode: {
type: Number,
default: 0
},
status: {
type: Number,
default: defines.OBJECT_STATUS.ACTIVE
}
});
......@@ -78,20 +76,38 @@ module.exports.getMany = ids => {
return Test.find({_id: {$in: ids}});
};
module.exports.getManyShort = ids => {
return Test.find({
_id: {$in: ids}
}).select({task: 1, contest: 1, index: 1});
};
module.exports.getForContest = contest => {
return Test.find({contest}).sort({index: 1});
return Test.find({
contest,
status: defines.OBJECT_STATUS.ACTIVE
}).sort({index: 1});
};
module.exports.getForTask = task => {
return Test.find({task}).sort({index: 1});
return Test.find({
task,
status: defines.OBJECT_STATUS.ACTIVE
}).sort({index: 1});
};
module.exports.getCountForContest = contest => {
return Test.countDocuments({contest});
return Test.countDocuments({
contest,
status: defines.OBJECT_STATUS.ACTIVE
});
};
module.exports.getCountForTask = task => {
return Test.countDocuments({task});
return Test.countDocuments({
task,
status: defines.OBJECT_STATUS.ACTIVE
});
};
module.exports.get = id => {
......@@ -106,7 +122,23 @@ module.exports.update = (id, update) => {
return Test.findOneAndUpdate({_id: id}, update);
};
module.exports.getRemoved = task => {
return Test.find({task, status: defines.OBJECT_STATUS.REMOVED})
};
module.exports.remove = id => {
return Test.findOneAndUpdate({_id: id}, {status: defines.OBJECT_STATUS.REMOVED});
};
module.exports.delete = id => {
return Test.findOneAndUpdate({_id: id}, {status: defines.OBJECT_STATUS.DELETED});
};
module.exports.activate = id => {
return Test.findOneAndUpdate({_id: id}, {status: defines.OBJECT_STATUS.ACTIVE});
};
module.exports.erase = id => {
return Test.deleteOne({_id: id});
};
......@@ -118,29 +150,33 @@ module.exports.addOutputFile = (id, fileName) => {
return Test.findOneAndUpdate({_id: id}, {$push: {outputFiles: fileName}});
};
module.exports.popInputFileMany = ids => {
return Test.findOneAndUpdate({_id: {$in: ids}}, {$pop: {inputFiles: 1}});
module.exports.popInputFileManyForTask = task => {
return Test.findOneAndUpdate({task}, {$pop: {inputFiles: 1}});
};
module.exports.popOutputFileManyForTask = task => {
return Test.findOneAndUpdate({task}, {$pop: {outputFiles: 1}});
};
module.exports.popOutputFileMany = ids => {
return Test.findOneAndUpdate({_id: {$in: ids}}, {$pop: {outputFiles: 1}});
module.exports.setIndex = (id, index) => {
return Test.findOneAndUpdate({_id: id}, {index});
};
module.exports.setInputFile = (id, index, file) => {
return Test.findOneAndUpdate({_id: id}, {[`inputFiles.${index}`]: file});
}
};
module.exports.setOutputFile = (id, index, file) => {
return Test.findOneAndUpdate({_id: id}, {[`outputFiles.${index}`]: file});
}
};
module.exports.setStdinFile = (id, file) => {
return Test.findOneAndUpdate({_id: id}, {'stdinFile': file});
}
};
module.exports.setStdoutFile = (id, file) => {
return Test.findOneAndUpdate({_id: id}, {'stdoutFile': file});
}
};
......
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