add Tasks collection

parent e815dc72
/**
* Created by danilaeremin on 17.06.16.
*/
'use strict';
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});
},
getTaskById : function (taskId) {
return dbUtils.dbFindOne(Task, {_id: taskId}, [{ path: 'contest' }]);
},
getTasksByContest : function (contestId) {
return dbUtils.dbFind(Task, {contest: contestId}, [{ path: 'contest' }]);
},
removeTaskById : function (taskId) {
return dbUtils.dbRemoveItem(Task, {_id: taskId});
}
};
};
......@@ -21,7 +21,7 @@ module.exports = function (uri) {
return dbUtils.connect(uri)
.then(connection => {
let models = ['AccessToken','RefreshToken','User','Code','Client','Course', 'Contest'];
let models = ['AccessToken','RefreshToken','User','Code','Client','Course', 'Contest', 'Task'];
for (let i = 0; i < models.length; i++) {
let schema = require('./models/' + models[i]);
......
......@@ -7,7 +7,7 @@ var mongoose = require('mongoose');
var ContestSchema = new mongoose.Schema({
course: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Contest',
ref: 'Course',
required: true
},
......
/**
* Created by danilaeremin on 06.09.16.
*/
var mongoose = require('mongoose');
var TaskSchema = new mongoose.Schema({
contest: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Contest',
required: true
},
name: {
type: String,
default: '',
required: true
},
task: {
type: String,
default: '',
required: true
},
comment: {
type: String,
default: '',
required: true
},
type: {
type: String,
default: '',
required: true
},
created: {
type: Date,
default: Date.now,
required: true,
},
meta: {
type: {},
required: true,
default: {}
}
});
module.exports = TaskSchema;
\ No newline at end of file
{
"name": "mirera-db",
"version": "1.1.0",
"version": "1.2.0",
"description": "DB utils for mirera program testing server",
"main": "index.js",
"scripts": {
......
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