Skip to content

Commit

Permalink
fix error|Changes some var|Create|get all courses
Browse files Browse the repository at this point in the history
  • Loading branch information
RatonBiswas committed Dec 11, 2020
1 parent df8deb3 commit 363de51
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
20 changes: 19 additions & 1 deletion contollers/courseAllocationController.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@

import CourseAllocation from '../model/courseAllocationModel.js'
import * as factory from './handlerFactory.js';
// import Course from '../model/courseModel.js';
// import Level from '../model/levelModel.js';
// import Batch from '../model/batchModel.js';
// import Term from '../model/termModel.js';
// import Teacher from '../model/teacherModel.js';
// import Section from '../model/sectionModel.js';

import catchAsync from '../utils/catchAsync.js';
// import AppError from '../utils/appError.js';

export const createCourseAllocationPost = factory.createOne(CourseAllocation);
export const getAllCourseAllocationPost = factory.getAll(CourseAllocation);
export const getCourseAlloOne = factory.getOne(CourseAllocation);

export const getAllCourseAllocationPost = catchAsync (async (req,res) =>{
const data = await CourseAllocation.find()
return res.status(200).json({
status: 'success',
results: data.length,
data
});
})



// export const createOne = catchAsync(async (req, res, next) => {
Expand Down
2 changes: 1 addition & 1 deletion contollers/handlerFactory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AppError from '../utils/appError.js';
import catchAsync from '../utils/catchAsync.js';
import AppError from '../utils/appError.js';

export const deleteOne = Model =>
catchAsync(async (req, res, next) => {
Expand Down
43 changes: 32 additions & 11 deletions model/courseAllocationModel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import mongoose from 'mongoose';


const courseAllocationModel = new mongoose.Schema({
session : {
level: {
Expand All @@ -14,24 +13,46 @@ const courseAllocationModel = new mongoose.Schema({
batch:{
type: mongoose.Schema.ObjectId,
ref: 'Batch',
},
type: Object
}
},
course : {
teacherId:{
course : [{
teacher:{
type: mongoose.Schema.ObjectId,
ref: 'Teacher',
},
section: {
section:[{
type: mongoose.Schema.ObjectId,
ref: 'Section',
},
courseId :{
}],
course :{
type: mongoose.Schema.ObjectId,
ref: 'Course',
},
type: Array
}
}
}]

})
// Query middleware
courseAllocationModel.pre(/^find/, function (next) {
this.populate({
path: 'course.teacher',
select: '-__v'
}).populate({
path: 'course.section',
select: '-__v'
}).populate({
path: 'course.course',
select: '-__v'
}).populate({
path: 'session.level',
select: '-__v'
}).populate({
path: 'session.term',
select: '-__v'
}).populate({
path: 'session.batch',
select: '-__v'
})
next();
});

export default mongoose.model('CourseAllocation',courseAllocationModel);
1 change: 1 addition & 0 deletions routes/courseAllocationRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const router = express.Router();

router.get('/', courseAllocationController.getAllCourseAllocationPost);
router.post('/create-courseAllocation', courseAllocationController.createCourseAllocationPost)
router.get('/:id', courseAllocationController.getCourseAlloOne)

export default router;

0 comments on commit 363de51

Please sign in to comment.