User.controller.js
var mongoose = require('../mongoose.config');
var UserSchema = mongoose.model('User');
var UserSchema2 = mongoose.model('Specimen');
var testReqSchema = mongoose.model('TestRequest');
var patientSchema = mongoose.model('Patient');
var courseSchema = mongoose.model('course');
var subjectSchema = mongoose.model('subject');
var UserController = function() {
this.add = function(userInstance) {
return new Promise((resolve, reject) => {
var user = new UserSchema({
name: userInstance.name
})
user.save().then(() => {
resolve({'status': 200, 'message':'added new user'});
}).catch(err => {
reject({'status': 404, 'message':'err:-'+err});
})
})
}
//get all course
this.getAllCourses=function(){
return new Promise((resolve, reject) => {
courseSchema.find().exec().then(data => {
resolve({'status': 200, 'message':'get all course
data', 'data': data});
}).catch(err => {
reject({'status': 404, 'message':'err:-'+err});
})
})
}
//get specific course details
this.getSpecificCourse = function(id){
return new Promise((resolve, reject) => {
courseSchema.find({code: id}).exec().then(data => {
resolve({'status': 200, 'message':'get single data',
'data': data});
}).catch(err => {
reject({'status': 404, 'message':'err:-'+err});
})
})
}
//update
this.update = function(id, updateData) {
return new Promise((resolve, reject) => {
UserSchema.update({_id: id}, updateData).then(() => {
resolve({'status': 200, 'message':'update user'});
}).catch(err => {
reject({'status': 404, 'message':'err:-'+err});
})
})
}
this.delete = function(id) {
return new Promise((resolve, reject) => {
UserSchema.remove({_id: id}).then(() => {
resolve({'status': 200, 'message':'delete user'});
}).catch(err => {
reject({'status': 404, 'message':'err:-'+err});
})
})
}
}