Merge forename + name into [identifying] 'name' (more general)
[qomet.git] / entities / course.js
CommitLineData
e99c53fb
BA
1const db = require("../utils/database");
2
3const CourseEntity =
4{
5 /*
6 * Structure:
7 * _id: BSON id
8 * uid: prof ID
9 * code: varchar
10 * description: varchar
11 * password: monitoring password hash
12 * students: array of
13 * number: student number
e99c53fb
BA
14 * name: varchar
15 * group: integer
16 */
17
18 getByUser: function(uid, callback)
19 {
20 db.courses.find(
21 { uid: uid },
22 callback
23 );
24 },
25
26 getById: function(cid, callback)
27 {
28 db.courses.findOne(
29 { _id: cid },
30 callback
31 );
32 },
33
34 getByPath: function(uid, code, callback)
35 {
36 db.courses.findOne(
37 {
38 $and: [
39 { uid: uid },
40 { code: code },
41 ]
42 },
43 callback
44 );
45 },
46
47 insert: function(uid, code, description, cb)
48 {
49 db.courses.insert(
50 {
51 uid: uid,
52 code: code,
53 description: description,
54 students: [ ],
55 },
56 cb);
57 },
58
59 setStudents: function(cid, students, cb)
60 {
61 db.courses.update(
62 { _id: cid },
63 { $set: { students: students } },
64 cb
65 );
66 },
67
68 // Note: return { students: { ... } }, pointing on the requested row
69 getStudent: function(cid, number, cb)
70 {
71 db.courses.findOne(
72 { _id: cid },
73 {
74 _id: 0,
75 students: { $elemMatch: {number: number} }
76 },
77 cb
78 );
79 },
80
81 setPassword: function(cid, pwd, cb)
82 {
83 db.courses.update(
84 { _id: cid },
85 { $set: { password: pwd } },
86 cb
87 );
88 },
89
90 remove: function(cid, cb)
91 {
92 db.courses.remove(
93 { _id: cid },
94 cb
95 );
96 },
97}
98
99module.exports = CourseEntity;