Update task and tests model fns

parent 51ca19ee
......@@ -11,6 +11,14 @@ const TaskSchema = new mongoose.Schema({
type: Number,
default: defines.OBJECT_STATUS.ACTIVE
},
lock: {
reason: {
type: String
},
date: {
type: Date,
}
},
created: {
type: Date,
default: Date.now
......@@ -505,11 +513,17 @@ module.exports.removeManyForContest = (contest, ids) => {
};
module.exports.activate = id => {
return Task.findOneAndUpdate({_id: id}, {status: defines.OBJECT_STATUS.ACTIVE });
return Task.findOneAndUpdate({_id: id}, [{$set: {status: defines.OBJECT_STATUS.ACTIVE}}, {$unset: ["lock"]}]);
};
module.exports.lock = id => {
return Task.findOneAndUpdate({_id: id}, {status: defines.OBJECT_STATUS.LOCKED });
module.exports.lock = (id, reason) => {
return Task.findOneAndUpdate({_id: id}, {
status: defines.OBJECT_STATUS.LOCKED,
lock: {
reason,
date: Date.now()
}
});
};
module.exports.activateForContest = contest => {
......
......@@ -148,8 +148,14 @@ module.exports.getRemoved = task => {
return Test.find({task, status: defines.OBJECT_STATUS.REMOVED})
};
module.exports.lockForTask = task => {
return Test.findOneAndUpdate({task}, {status: defines.OBJECT_STATUS.LOCKED });
module.exports.lockForTask = (task, reason) => {
return Test.findOneAndUpdate({task}, {
status: defines.OBJECT_STATUS.LOCKED,
lock: {
reason,
date: Date.now()
}
});
};
module.exports.remove = id => {
......@@ -161,11 +167,11 @@ module.exports.delete = id => {
};
module.exports.activate = id => {
return Test.findOneAndUpdate({_id: id}, {status: defines.OBJECT_STATUS.ACTIVE });
return Test.findOneAndUpdate({_id: id}, [{$set: {status: defines.OBJECT_STATUS.ACTIVE}}, {$unset: ["lock"]}]);
};
module.exports.activateForTask = task => {
return Test.findOneAndUpdate({task}, {status: defines.OBJECT_STATUS.ACTIVE });
return Test.findOneAndUpdate({task}, [{$set: {status: defines.OBJECT_STATUS.ACTIVE}}, {$unset: ["lock"]}]);
};
module.exports.erase = id => {
......
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