updates for courses

parent b4300623
......@@ -9,17 +9,20 @@ const dbUtils = require('db-utils');
module.exports = function (Course) {
return {
addCourse : function(owner, name, info, description) {
return dbUtils.dbCreateItem(Course,{ owner: owner, name: name, info: info, description: description});
return dbUtils.dbCreateItem(Course,{ owner: owner, name: name, info: info, description: description, teachers : [owner]});
},
updateCourse : function(courseId, owner, name, info, description) {
return dbUtils.dbFindOneAndUpdate(Course,{_id:courseId}, { owner: owner, name: name, info: info, description: description});
updateCourse : function(courseId, name, info, description) {
return dbUtils.dbFindOneAndUpdate(Course,{_id:courseId}, { name: name, info: info, description: description});
},
getCourseById : function (courseId) {
return dbUtils.dbFindOne(Course, {_id: courseId}, [{ path: 'owner' }]);
},
getCourseByOwner : function (owner) {
getCoursesByOwner : function (owner) {
return dbUtils.dbFind(Course, {owner: owner}, {population : [{ path: 'owner' }]});
},
getCoursesByTeacher : function (teacherId) {
return dbUtils.dbFind(Course, {teachers: teacherId}, {population : [{ path: 'owner' }]});
},
removeCourseById : function (courseId) {
return dbUtils.dbRemoveItem(Course, {_id: courseId});
},
......@@ -28,6 +31,18 @@ module.exports = function (Course) {
},
getCoursesCount : function () {
return dbUtils.dbCount(Course, {});
},
addTeacher : function (courseId, teacherId) {
return dbUtils.dbFindOneAndUpdate(Course, {_id : courseId}, { $push: { teachers: teacherId } });
},
deleteTeacher : function (courseId, teacherId) {
return dbUtils.dbFindOneAndUpdate(Course, {_id : courseId}, {$pull : {teachers : teacherId}});
},
addGroup : function (courseId, groupId) {
return dbUtils.dbFindOneAndUpdate(Course, {_id : courseId}, { $push: { groups: groupId } });
},
deleteGroup : function (courseId, groupId) {
return dbUtils.dbFindOneAndUpdate(Course, {_id : courseId}, {$pull : {groups : groupId}});
}
};
};
......
......@@ -10,7 +10,22 @@ var CourseSchema = new mongoose.Schema({
ref: 'User',
required: true
},
teachers : {
type: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
}],
default: []
},
groups : {
type: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Group',
required: true
}],
default: []
},
name: {
type: String,
default: '',
......
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