1 const db
= require("../utils/database");
3 const AssessmentEntity
=
10 * active: boolean true/false
11 * mode: secure | exam | open (decreasing security)
12 * fixed: bool (questions in fixed order; default: false)
13 * display: "one" or "all" (generally "all" for open questions, but...)
14 * time: 0, //<=0 means "untimed"; otherwise, time in seconds
16 * conclusion: "https://www.youtube.com/watch?v=6-9AjToJYuw",
17 * coefficient: number, default 1
19 * index: for paper test, like 2.1.a (?!); and quiz: 0, 1, 2, 3...
20 * wording: varchar (HTML)
21 * options: array of varchar --> if present, question type == quiz!
22 * fixed: bool, options in fixed order (default: false)
23 * answer: array of integers (for quiz) or html text (for paper); striped in exam mode
24 * active: boolean, is question in current assessment? --> striped if inactive!
25 * points: points for this question (default 1)
27 * number: student number
28 * inputs: array of indexed arrays of integers (or html text if not quiz)
30 * password: random string identifying student for exam session TEMPORARY
33 getById: function(aid
, callback
)
35 db
.assessments
.findOne(
41 getByPath: function(cid
, name
, callback
)
43 db
.assessments
.findOne(
52 insert: function(cid
, name
, callback
)
54 db
.assessments
.insert(
73 getByCourse: function(cid
, callback
)
81 // arg: full assessment without _id field
82 replace: function(aid
, assessment
, cb
)
84 // Should be: (but unsupported by mongojs)
85 // db.assessments.replaceOne(
90 // Temporary workaround:
91 db
.assessments
.update(
98 getQuestions: function(aid
, callback
)
100 db
.assessments
.findOne(
104 callback(err
, !!res
? res
.questions : null);
109 getPaperByNumber: function(aid
, number
, callback
)
111 db
.assessments
.findOne(
114 "papers.number": number
,
118 return callback(err
,a
);
119 for (let p
of a
.papers
)
121 if (p
.number
== number
)
122 return callback(null,p
); //reached for sure
128 startSession: function(aid
, number
, password
, callback
)
130 db
.assessments
.update(
134 startTime: Date
.now(),
137 inputs: [ ], //TODO: this is stage 1, stack indexed answers.
138 // then build JSON tree for easier access / correct
145 hasInput: function(aid
, number
, password
, idx
, cb
)
147 db
.assessments
.findOne(
150 "papers.number": number
,
151 "papers.password": password
,
156 let papIdx
= a
.papers
.findIndex( item
=> { return item
.number
== number
; });
157 for (let i
of a
.papers
[papIdx
].inputs
)
160 return cb(null,true);
167 // https://stackoverflow.com/questions/27874469/mongodb-push-in-nested-array
168 setInput: function(aid
, number
, password
, input
, callback
) //input: index + arrayOfInt (or txt)
170 db
.assessments
.update(
173 "papers.number": number
,
174 "papers.password": password
,
176 { $push: { "papers.$.inputs": input
} },
181 endAssessment: function(aid
, number
, password
, callback
)
183 db
.assessments
.update(
186 "papers.number": number
,
187 "papers.password": password
,
190 "papers.$.endTime": Date
.now(),
191 "papers.$.password": "",
197 getConclusion: function(aid
, callback
)
199 db
.assessments
.findOne(
203 callback(err
, !!res
? res
.conclusion : null);
208 remove: function(aid
, cb
)
210 db
.assessments
.remove(
216 removeGroup: function(cid
, cb
)
218 db
.assessments
.remove(
225 module
.exports
= AssessmentEntity
;