Commit 1b24714b authored by Antony Orlovsky's avatar Antony Orlovsky

Merge branch 'develop' into 'develop'

Added test types

See merge request !23
parents f8b8aa46 78404b39
......@@ -11,26 +11,31 @@ module.exports.COURSE_TYPES = {
THEME: 'theme'
};
module.exports.TASK_TYPES = {
module.exports.TASK_TYPES = {
TESTER: 'tester',
TESTING: 'testing'
};
module.exports.TASK_DIFFICULTY = {
module.exports.TEST_TYPES = {
COMMON: 'common',
PERSONAL: 'personal'
};
module.exports.TASK_DIFFICULTY = {
SIMPLE: 'simple',
USUAL: 'usual',
HARD: 'hard'
};
module.exports.CONTEST_TYPES = {
module.exports.CONTEST_TYPES = {
REGULAR: 'regular',
OPTIONAL: 'optional',
EXAM: 'exam'
};
module.exports.GROUP_TYPES = {
COMMON: "common",
VK: "vk"
COMMON: 'common',
VK: 'vk'
};
module.exports.TESTING_TYPE = {
......@@ -71,15 +76,15 @@ module.exports.FILE_TYPE = {
};
module.exports.TESTER_TYPE = {
TEXT_COMPARE: "text_compare",
BYTE_COMPARE: "byte_compare",
NUMBER_COMPARE: "number_compare",
GREATER_THAN_OR_EQUAL: "greater_than_or_equal",
LESS_THAN_OR_EQUAL: "less_than_or_equal",
IMAGE_COMPARE: "image_compare",
CUSTOM: "custom",
EXTERNAL: "external",
NOT_TEST: "not_test"
TEXT_COMPARE: 'text_compare',
BYTE_COMPARE: 'byte_compare',
NUMBER_COMPARE: 'number_compare',
GREATER_THAN_OR_EQUAL: 'greater_than_or_equal',
LESS_THAN_OR_EQUAL: 'less_than_or_equal',
IMAGE_COMPARE: 'image_compare',
CUSTOM: 'custom',
EXTERNAL: 'external',
NOT_TEST: 'not_test'
};
module.exports.TEST_RESULTS = {
......@@ -109,14 +114,14 @@ module.exports.TEST_RESULTS = {
};
module.exports.TEST_TYPE = {
PROGRAM: "program",
FILE: "file",
PROJECT: "project"
PROGRAM: 'program',
FILE: 'file',
PROJECT: 'project'
};
module.exports.IO_TYPE = {
INPUT: "input",
OUTPUT: "output"
INPUT: 'input',
OUTPUT: 'output'
};
module.exports.KILLING_CODES = {
......
......@@ -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