Commit 78404b39 authored by Antony Orlovsky's avatar Antony Orlovsky

Added test types

parent 24eec0e6
......@@ -16,6 +16,11 @@ module.exports.TASK_TYPES = {
TESTING: 'testing'
};
module.exports.TEST_TYPES = {
COMMON: 'common',
PERSONAL: 'personal'
};
module.exports.TASK_DIFFICULTY = {
SIMPLE: 'simple',
USUAL: 'usual',
......
......@@ -69,6 +69,10 @@ const TestSchema = new mongoose.Schema({
isExample: {
type: Boolean,
default: false
},
type: {
type: String,
default: defines.TEST_TYPES.COMMON
}
});
......@@ -91,6 +95,7 @@ module.exports.getManyShort = ids => {
module.exports.getForContest = contest => {
return Test.find({
contest,
type: defines.TEST_TYPES.COMMON,
status: {$lte: defines.OBJECT_STATUS.LOCKED }
}).sort({index: 1});
};
......@@ -98,13 +103,24 @@ module.exports.getForContest = contest => {
module.exports.getForTask = task => {
return Test.find({
task,
type: defines.TEST_TYPES.COMMON,
status: {$lte: defines.OBJECT_STATUS.LOCKED }
}).sort({index: 1});
};
module.exports.getForOwnerAndTask = (owner, task) => {
return Test.find({
owner,
task,
type: defines.TEST_TYPES.PERSONAL,
status: {$lte: defines.OBJECT_STATUS.LOCKED}
}).sort({index: 1});
};
module.exports.getExamplesForTask = task => {
return Test.find({
task,
type: defines.TEST_TYPES.COMMON,
status: {$lte: defines.OBJECT_STATUS.LOCKED },
isExample: true
}).sort({index: 1});
......@@ -113,6 +129,7 @@ module.exports.getExamplesForTask = task => {
module.exports.getExamplesForContest = contest => {
return Test.find({
contest,
type: defines.TEST_TYPES.COMMON,
status: {$lte: defines.OBJECT_STATUS.LOCKED },
isExample: true
}).sort({index: 1});
......@@ -121,13 +138,15 @@ module.exports.getExamplesForContest = contest => {
module.exports.getCountForContest = contest => {
return Test.countDocuments({
contest,
type: defines.TEST_TYPES.COMMON,
status: {$lte: defines.OBJECT_STATUS.LOCKED }
});
};
module.exports.getCountForTask = task => {
module.exports.getCountForTaskAndType = (task, type) => {
return Test.countDocuments({
task,
type,
status: {$lte: defines.OBJECT_STATUS.LOCKED }
});
};
......@@ -145,21 +164,53 @@ module.exports.update = (id, update) => {
};
module.exports.getRemovedForTask = task => {
return Test.find({task, status: defines.OBJECT_STATUS.REMOVED})
return Test.find({
task,
type: defines.TEST_TYPES.COMMON,
status: defines.OBJECT_STATUS.REMOVED
});
};
module.exports.getRemovedForContest = contest => {
return Test.find({contest, status: defines.OBJECT_STATUS.REMOVED})
return Test.find({
contest,
type: defines.TEST_TYPES.COMMON,
status: defines.OBJECT_STATUS.REMOVED
});
};
module.exports.lockMany = (ids, reason) => {
return Test.updateMany(
{
_id: {$in: ids},
status: defines.OBJECT_STATUS.ACTIVE
},
{
status: defines.OBJECT_STATUS.LOCKED,
lock: {
reason,
date: Date.now()
}
}
);
};
module.exports.lockForTask = (task, reason) => {
return Test.updateMany({task, status: defines.OBJECT_STATUS.ACTIVE}, {
status: defines.OBJECT_STATUS.LOCKED,
lock: {
reason,
date: Date.now()
return Test.updateMany(
{
task,
type: defines.TEST_TYPES.COMMON,
status: defines.OBJECT_STATUS.ACTIVE
},
{
status: defines.OBJECT_STATUS.LOCKED,
lock: {
reason,
date: Date.now()
}
}
});
);
};
module.exports.remove = id => {
......@@ -170,16 +221,33 @@ module.exports.delete = id => {
return Test.findOneAndUpdate({_id: id}, {status: defines.OBJECT_STATUS.DELETED});
};
module.exports.erase = id => {
return Test.deleteOne({_id: id});
};
module.exports.activate = id => {
return Test.findOneAndUpdate({_id: id}, [{$set: {status: defines.OBJECT_STATUS.ACTIVE}}, {$unset: ["lock"]}]);
};
module.exports.activateForTask = task => {
return Test.updateMany({task, status: defines.OBJECT_STATUS.LOCKED}, [{$set: {status: defines.OBJECT_STATUS.ACTIVE}}, {$unset: ["lock"]}]);
module.exports.activateMany = ids => {
return Test.updateMany(
{_id: {$in: ids}, status: defines.OBJECT_STATUS.LOCKED},
[{$set: {status: defines.OBJECT_STATUS.ACTIVE}}, {$unset: ["lock"]}]
);
};
module.exports.erase = id => {
return Test.deleteOne({_id: id});
module.exports.activateForTask = task => {
return Test.updateMany(
{
task,
type: defines.TEST_TYPES.COMMON,
status: defines.OBJECT_STATUS.LOCKED
},
[
{$set: {status: defines.OBJECT_STATUS.ACTIVE}},
{$unset: ["lock"]}
]
);
};
module.exports.addInputFile = (id, 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