add courses to mirera db

parent 62517a4d
/**
* Created by danilaeremin on 17.06.16.
*/
'use strict';
var dbUtils = require('./dbUtils');
var Course = require('./models/mongoose').Course;
exports.addCourse = function(owner, name, info, description) {
return dbUtils.dbCreateItem(Course,{ owner: owner, name: name, info: info, description: description});
};
exports.getCourseById = function (courseId) {
return dbUtils.dbFindOne(Course, {_id: courseId}, [{ path: 'owner' }]);
};
exports.getCourseByOwner= function (owner) {
return dbUtils.dbFind(Course, {owner: owner}, [{ path: 'owner' }]);
};
exports.removeCourseById = function (courseId) {
return dbUtils.dbRemoveItem(Course, {_id: courseId});
};
......@@ -15,6 +15,7 @@ importModule('./dbUtils');
importModule('./dbTokens');
importModule('./dbUser');
importModule('./dbCode');
importModule('./dbCourse');
importModule('./dbClient');
exports.mongoose = require('./models/mongoose').mongoose;
......@@ -4,10 +4,6 @@
'use strict';
var safeCallback = function(callback) {
return callback ? callback : function(){};
};
var Mongoose = require('./models/mongoose').mongoose;
exports.str2ObjectId = function (str) {
......
/**
* Created by danilaeremin on 29.08.16.
*/
var mongoose = require('mongoose');
var CourseSchema = new mongoose.Schema({
owner: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
name: {
type: String,
default: '',
required: true
},
info: {
type: String,
default: '',
required: true
},
description: {
type: String,
default: '',
required: true
},
created: {
type: Date,
default: Date.now,
required: true,
}
});
var Course = mongoose.model('Course', CourseSchema);
module.exports = Course;
\ No newline at end of file
......@@ -25,6 +25,8 @@ module.exports = {
Code: require('./Code'),
Client: require('./Client'),
Course: require('./Course'),
mongoose: mongoose
};
......
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