1 const CourseEntity
= require("../entities/course");
2 const UserEntity
= require("../entities/user");
3 const AssessmentEntity
= require("../entities/assessment");
7 getByInitials: function(initials
, callback
)
9 UserEntity
.getByInitials(initials
, (err
,user
) => {
14 CourseEntity
.getByUser(user
._id
, (err2
,courseArray
) => {
15 callback(err2
, courseArray
);
21 getByRefs: function(initials
, code
, callback
)
23 UserEntity
.getByInitials(initials
, (err
,user
) => {
28 CourseEntity
.getByPath(user
._id
, code
, (err2
,course
) => {
29 callback(err2
, course
);
35 importStudents: function(uid
, cid
, students
, cb
)
37 // 1) check if uid == course uid
38 CourseEntity
.getById(cid
, (err
,course
) => {
39 if (!!err
|| !course
|| !course
.uid
.equals(uid
))
40 return cb({errmsg:"Not your course"},{});
42 CourseEntity
.setStudents(cid
, students
, cb
);
46 setPassword: function(uid
, cid
, pwd
, cb
)
48 // 1) check if uid == course uid
49 CourseEntity
.getById(cid
, (err
,course
) => {
50 if (!!err
|| !course
|| !course
.uid
.equals(uid
))
51 return cb({errmsg:"Not your course"},{});
52 // 2) Insert new student (overwrite if number already exists)
53 CourseEntity
.setPassword(cid
, pwd
, cb
);
57 remove: function(uid
, cid
, cb
)
59 // 1) check if uid == course uid
60 CourseEntity
.getById(cid
, (err
,course
) => {
61 if (!!err
|| !course
|| !course
.uid
.equals(uid
))
62 return cb({errmsg:"Not your course"},{});
63 // 2) remove all associated assessments
64 AssessmentEntity
.removeGroup(cid
, (err2
,ret
) => {
67 // 3) remove course (with its students)
68 CourseEntity
.remove(cid
, cb
);
74 module
.exports
= CourseModel
;