add index field

parent c7724719
......@@ -8,14 +8,17 @@ const dbUtils = require('db-utils');
module.exports = function (Task) {
return {
addTask : function(contestId, name, task, comment, type, meta) {
return dbUtils.dbCreateItem(Task,{ contest: contestId, name: name, task: task, comment: comment, type : type, meta : meta});
addTask : function(contestId, name, task, comment, type, index, meta) {
return dbUtils.dbCreateItem(Task,{ contest: contestId, name: name, task: task, comment: comment, type : type, index : index, meta : meta});
},
getTaskById : function (taskId) {
return dbUtils.dbFindOne(Task, {_id: taskId}, [{ path: 'contest' }]);
},
getTasksByContest : function (contestId) {
return dbUtils.dbFind(Task, {contest: contestId}, {population:[{ path: 'contest' }], sort: {'_id': 1}});
return dbUtils.dbFind(Task, {contest: contestId}, {population:[{ path: 'contest' }], sort: [['index', 1], ['_id', 1]]});
},
getTaskByContestAndIndex : function (contestId, index) {
return dbUtils.dbFindOne(Task, {contest: contestId, index : index}, {population:[{ path: 'contest' }]});
},
removeTaskById : function (taskId) {
return dbUtils.dbRemoveItem(Task, {_id: taskId});
......@@ -26,6 +29,9 @@ module.exports = function (Task) {
updateTaskMeta : function (taskId, meta) {
return dbUtils.dbFindOneAndUpdate(Task, {_id: taskId}, {meta : meta});
},
updateTaskIndex : function (taskId, index) {
return dbUtils.dbFindOneAndUpdate(Task, {_id: taskId}, {index : index});
},
getTaskForTestingTask : function (testingTaskId) {
return dbUtils.dbFindOne(Task, { 'meta.testingTask' : testingTaskId});
}
......
......@@ -37,6 +37,11 @@ var TaskSchema = new mongoose.Schema({
default: Date.now,
required: true
},
index : {
type : Number,
required : true,
default : 0
},
meta: {
type: {},
......
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