-try { var _ = require("underscore"); } catch (err) {} //for server
+try { var _ = require("underscore"); } catch (err) { } //for server
let Validator = { };
-// Cell in assessment.questions array
+// Cell in evaluation.questions array
Validator.Question = {
"index": "section", //"2.2.1", "3.2", "1" ...etc
"wording": "string",
"options": "stringArray", //only for quiz
"fixed": "boolean",
- "answer": "string", //both this and next are mutually exclusive
- "choice": "integerArray",
- "active": "boolean",
"points": "number",
};
+Validator.Answer = {
+ "index": "section",
+ "value": "stringOrIntegerArray",
+};
+
Validator.Input = {
"index": "section",
"input": "stringOrIntegerArray",
// One student response to an exam
Validator.Paper = {
"number": "code",
- // (array of) strings for open questions, arrays of integers for quizzes:
"inputs": Validator.Input,
"startTime": "positiveInteger",
- "endTime": "positiveInteger",
+ "current": "positiveInteger",
"discoTime": "positiveInteger",
"discoCount": "positiveInteger",
"totalDisco": "positiveInteger",
"password": "password",
};
-Validator.Assessment = {
+Validator.Evaluation = {
"_id": "bson",
"cid": "bson",
"name": "code",
"display": "alphanumeric", //"one" or "all"
"time": "integer",
"introduction": "string",
- "conclusion": "string",
"coefficient": "number",
"questions": Validator.Question,
+ "answers": Validator.Answer,
"papers": Validator.Paper,
};
"_id": "bson",
"email": "email",
"name": "name",
- "initials": "unchecked", //not a user input
- "loginToken": "unchecked",
- "sessionTokens": "unchecked",
- "token": "alphanumeric", //exception: for the purpose of user registration
+ "initials": "alphanumeric",
+ "loginToken": "alphanumeric",
+ "sessionTokens": "alphanumericArray",
};
Validator.Student = {
{
if (!model[key])
return "Unknown field";
- if (model[key] == "unchecked") //not a user input (ignored)
- continue;
if (_.isObject(model[key]))
{
// TODO: next loop seems too heavy... (only a concern if big class import?)
"check_string": function(arg)
{
+ if (!_.isString(arg))
+ return "not a string";
return ""; //strings are unchecked, but sanitized
},
return "";
},
- "check_stringArray": function(arg)
- {
- return !_.isArray(arg) ? "not an array" : "";
- },
-
"check_alphanumeric": function(arg)
{
return arg.match(/^[\w]{1,32}$/) === null ? "[1,32] alphanumerics" : "";
if (!_.isString(arg))
return "not a string";
if (!/^[\x21-\x7E]{1,16}$/.test(arg))
- return "[1,16] ASCII characters with code in [33,126]";
+ return "{1,16} ASCII characters with code in [33,126]";
return "";
},
return "";
},
+ "check_stringArray": function(arg)
+ {
+ if (!_.isArray(arg))
+ return "not an array";
+ for (let i=0; i<arg.length; i++)
+ {
+ if (!_.isString(arg[i]));
+ return "not a string";
+ }
+ return "";
+ },
+
+ "check_alphanumericArray": function(arg)
+ {
+ if (!_.isArray(arg))
+ return "not an array";
+ for (let i=0; i<arg.length; i++)
+ {
+ let error = Validator["check_alphanumeric"](arg[i]);
+ if (error.length > 0)
+ return error;
+ }
+ return "";
+ },
+
"check_stringOrIntegerArray": function(arg)
{
if (!_.isString(arg))
},
});
-try { module.exports = Validator.checkObject; } catch (err) {} //for server
+try { module.exports = Validator.checkObject; } catch (err) { } //for server