2104193a309f92484ffceefbf61830904aec53f8
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 startSession: function(aid
, number
, password
, callback
)
111 // TODO: security, do not re-do tasks if already done
112 db
.assessments
.update(
116 startTime: Date
.now(),
119 inputs: [ ], //TODO: this is stage 1, stack indexed answers.
120 // then build JSON tree for easier access / correct
126 // https://stackoverflow.com/questions/27874469/mongodb-push-in-nested-array
127 setInput: function(aid
, number
, password
, input
, callback
) //input: index + arrayOfInt (or txt)
129 db
.assessments
.update(
132 "papers.number": number
,
133 "papers.password": password
,
135 { $push: { "papers.$.inputs": input
} },
140 endAssessment: function(aid
, number
, password
, callback
)
142 db
.assessments
.update(
145 "papers.number": number
,
146 "papers.password": password
,
149 "papers.$.endTime": Date
.now(),
150 "papers.$.password": "",
156 getConclusion: function(aid
, callback
)
158 db
.assessments
.findOne(
162 callback(err
, !!res
? res
.conclusion : null);
167 remove: function(aid
, cb
)
169 db
.assessments
.remove(
175 removeGroup: function(cid
, cb
)
177 db
.assessments
.remove(
184 module
.exports
= AssessmentEntity
;