@universis/evaluations 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/models/access-token-model.js +4 -1
- package/dist/models/access-token-model.js.map +1 -1
- package/dist/models/class-instructor-evaluation-event-model.js +27 -5
- package/dist/models/class-instructor-evaluation-event-model.js.map +1 -1
- package/dist/models/evaluation-event-model.js +47 -9
- package/dist/models/evaluation-event-model.js.map +1 -1
- package/package.json +1 -1
- package/src/models/access-token-model.js +8 -5
- package/src/models/class-instructor-evaluation-event-model.js +24 -2
- package/src/models/evaluation-event-model.js +43 -5
|
@@ -31,7 +31,10 @@ AccessToken = (_dec = _data.EdmMapping.entityType('AccessToken'), _dec(_class =
|
|
|
31
31
|
if (this.expires == null) {
|
|
32
32
|
return true;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
// check only date parts
|
|
35
|
+
const currentDate = new Date().setHours(0, 0, 0, 0);
|
|
36
|
+
const expires = this.expires.setHours(0, 0, 0, 0);
|
|
37
|
+
return expires < currentDate;
|
|
35
38
|
}}) || _class);
|
|
36
39
|
|
|
37
40
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/access-token-model.js"],"names":["AccessToken","EdmMapping","entityType","DataObject","constructor","inspect","context","access_token","token","model","where","equal","silent","getTypedItem","active","isExpired","username","user_id","client_id","refresh_token","scope","expires","Date","
|
|
1
|
+
{"version":3,"sources":["../../src/models/access-token-model.js"],"names":["AccessToken","EdmMapping","entityType","DataObject","constructor","inspect","context","access_token","token","model","where","equal","silent","getTypedItem","active","isExpired","username","user_id","client_id","refresh_token","scope","expires","currentDate","Date","setHours","module","exports"],"mappings":"aAAA,qC;;;AAGMA,W,WADLC,iBAAWC,UAAX,CAAsB,aAAtB,C,gBAAD,MACMF,WADN,SAC0BG,gBAD1B,CACqC;;AAEjCC,EAAAA,WAAW,GAAG;AACV;AACH;;AAEmB,eAAPC,OAAO,CAACC,OAAD,EAAUC,YAAV,EAAwB;AACxC,UAAMC,KAAK,GAAG,MAAMF,OAAO,CAACG,KAAR,CAAc,aAAd;AACjBC,IAAAA,KADiB,CACX,cADW,EACKC,KADL,CACWJ,YADX;AAEjBK,IAAAA,MAFiB;AAGjBC,IAAAA,YAHiB,EAApB;AAIA,QAAIL,KAAK,IAAI,IAAb,EAAmB;AACjB,aAAO;AACLM,QAAAA,MAAM,EAAE,KADH,EAAP;;AAGD;AACD,WAAO;AACLA,MAAAA,MAAM,EAAE,CAACN,KAAK,CAACO,SAAN,EADJ;AAELC,MAAAA,QAAQ,EAAER,KAAK,CAACS,OAFX;AAGLC,MAAAA,SAAS,EAAEV,KAAK,CAACU,SAHZ;AAILX,MAAAA,YAAY,EAAEC,KAAK,CAACD,YAJf;AAKLY,MAAAA,aAAa,EAAEX,KAAK,CAACW,aALhB;AAMLC,MAAAA,KAAK,EAAEZ,KAAK,CAACY,KANR,EAAP;;AAQD;;AAEDL,EAAAA,SAAS,GAAG;AACR,QAAI,KAAKM,OAAL,IAAgB,IAApB,EAA0B;AACtB,aAAO,IAAP;AACH;AACD;AACA,UAAMC,WAAW,GAAG,IAAIC,IAAJ,GAAWC,QAAX,CAAoB,CAApB,EAAuB,CAAvB,EAA0B,CAA1B,EAA6B,CAA7B,CAApB;AACA,UAAMH,OAAO,GAAG,KAAKA,OAAL,CAAaG,QAAb,CAAsB,CAAtB,EAAyB,CAAzB,EAA4B,CAA5B,EAA+B,CAA/B,CAAhB;AACA,WAAQH,OAAO,GAAGC,WAAlB;AACH,GAlC8B,C;;;AAqCrCG,MAAM,CAACC,OAAP,GAAiB1B,WAAjB","sourcesContent":["import {DataObject, EdmMapping} from '@themost/data';\n\n@EdmMapping.entityType('AccessToken')\nclass AccessToken extends DataObject {\n\n constructor() {\n super();\n }\n\n static async inspect(context, access_token) {\n const token = await context.model('AccessToken')\n .where('access_token').equal(access_token)\n .silent()\n .getTypedItem();\n if (token == null) {\n return {\n active: false\n }\n }\n return {\n active: !token.isExpired(),\n username: token.user_id,\n client_id: token.client_id,\n access_token: token.access_token,\n refresh_token: token.refresh_token,\n scope: token.scope\n };\n }\n\n isExpired() {\n if (this.expires == null) {\n return true;\n }\n // check only date parts\n const currentDate = new Date().setHours(0, 0, 0, 0);\n const expires = this.expires.setHours(0, 0, 0, 0);\n return (expires < currentDate);\n }\n}\n\nmodule.exports = AccessToken;\n"],"file":"access-token-model.js"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";var _data = require("@themost/data");
|
|
2
2
|
var _evaluationEventModel = _interopRequireDefault(require("./evaluation-event-model"));
|
|
3
3
|
var _common = require("@themost/common");
|
|
4
|
-
var _mailer = require("@themost/mailer");
|
|
4
|
+
var _mailer = require("@themost/mailer");
|
|
5
|
+
var _moment = _interopRequireDefault(require("moment"));var _dec, _dec2, _dec3, _dec4, _class, _class2;function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {var desc = {};Object.keys(descriptor).forEach(function (key) {desc[key] = descriptor[key];});desc.enumerable = !!desc.enumerable;desc.configurable = !!desc.configurable;if ('value' in desc || desc.initializer) {desc.writable = true;}desc = decorators.slice().reverse().reduce(function (desc, decorator) {return decorator(target, property, desc) || desc;}, desc);if (context && desc.initializer !== void 0) {desc.value = desc.initializer ? desc.initializer.call(context) : void 0;desc.initializer = undefined;}if (desc.initializer === void 0) {Object.defineProperty(target, property, desc);desc = null;}return desc;}
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @class
|
|
@@ -128,9 +129,12 @@ _data.EdmMapping.action('SendEvaluationTokens', 'SendInstructorTokenAction'), _d
|
|
|
128
129
|
const generateAction = await context.model('GenerateInstructorTokenAction').save(action);const generateOptions = { evaluationEvent: event.id, n: action.numberOfStudents, expires: event.endDate };try {// save number of students to event
|
|
129
130
|
event.numberOfStudents = action.numberOfStudents;await context.model('ClassInstructorEvaluationEvent').save(event);if (event.numberOfStudents > 0) {await _evaluationEventModel.default.generateTokens(context, generateOptions);}generateAction.total = action.numberOfStudents;generateAction.actionStatus = { alternateName: 'CompletedActionStatus' };return await context.model('GenerateInstructorTokenAction').save(generateAction);} catch (err) {_common.TraceUtils.error(err); // update also action status
|
|
130
131
|
generateAction.total = 0;generateAction.actionStatus = { alternateName: 'FailedActionStatus' };generateAction.description = err.message;return await context.model('GenerateInstructorTokenAction').save(generateAction);}}}async getTokenStatistics() {const tokenInfo = { total: 0, used: 0, sent: 0 }; // get number if tokens
|
|
131
|
-
const tokens = await this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.getId()).select('count(evaluationEvent) as total', 'used', 'sent').groupBy('used', 'sent', 'evaluationEvent').silent().getItems();tokens.map((item) => {tokenInfo.total += item.total;tokenInfo.used += item.used ? item.total : 0;tokenInfo.sent += item.sent ? item.total : 0;});return tokenInfo;}async sendEvaluationTokens() {const context = this.context; // get event
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
const tokens = await this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.getId()).select('count(evaluationEvent) as total', 'used', 'sent').groupBy('used', 'sent', 'evaluationEvent').silent().getItems();tokens.map((item) => {tokenInfo.total += item.total;tokenInfo.used += item.used ? item.total : 0;tokenInfo.sent += item.sent ? item.total : 0;});return tokenInfo;}async sendEvaluationTokens() {const context = this.context; // get event and check if event endDate has passed
|
|
133
|
+
// get current date
|
|
134
|
+
const currentDate = (0, _moment.default)(new Date()).startOf('day').toDate(); // get only date format
|
|
135
|
+
const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(this.getId()).and('date(endDate)').greaterOrEqual(currentDate).expand({ name: 'courseClassInstructor', options: { '$expand': 'courseClass($expand=course), instructor' // expand course and instructor so their attributes are available in the mail template
|
|
136
|
+
} }, { name: 'actions', options: {
|
|
137
|
+
'$expand': 'actionStatus' } }).
|
|
134
138
|
|
|
135
139
|
|
|
136
140
|
getItem();
|
|
@@ -225,6 +229,24 @@ _data.EdmMapping.action('SendEvaluationTokens', 'SendInstructorTokenAction'), _d
|
|
|
225
229
|
const succeeded = [];
|
|
226
230
|
const failed = [];
|
|
227
231
|
try {
|
|
232
|
+
// format mail subject expected params ${course}, ${instructor}
|
|
233
|
+
const exp = new RegExp('\\$\\{\\w+\\}+', 'ig');
|
|
234
|
+
let subject = mailTemplate.subject;
|
|
235
|
+
const params = subject.match(exp);
|
|
236
|
+
if (params.length > 0) {
|
|
237
|
+
// parse only custom parameters ${instructor},${course}
|
|
238
|
+
params.forEach((param) => {
|
|
239
|
+
if (param === '${instructor}') {
|
|
240
|
+
// get instructor full name
|
|
241
|
+
subject = subject.replace(param, eventInstructor ? `${eventInstructor.familyName} ${eventInstructor.givenName}` : '');
|
|
242
|
+
} else if (param === '${course}') {
|
|
243
|
+
// get courseClass code and title
|
|
244
|
+
subject = subject.replace(param, courseClass.course ? `${courseClass.course.displayCode} ${courseClass.title}` : '');
|
|
245
|
+
} else {
|
|
246
|
+
subject = subject.replace(param, '');
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
228
250
|
// use an async function to send emails
|
|
229
251
|
await (async () => {
|
|
230
252
|
for (const student of students) {
|
|
@@ -236,7 +258,7 @@ _data.EdmMapping.action('SendEvaluationTokens', 'SendInstructorTokenAction'), _d
|
|
|
236
258
|
await new Promise((resolve) => {
|
|
237
259
|
mailer.
|
|
238
260
|
template(mailTemplate.template).
|
|
239
|
-
subject(
|
|
261
|
+
subject(subject).
|
|
240
262
|
to(student.email).
|
|
241
263
|
send(Object.assign(event, {
|
|
242
264
|
access_token }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/class-instructor-evaluation-event-model.js"],"names":["ClassInstructorEvaluationEvent","EdmMapping","entityType","action","func","EdmType","CollectionOf","EvaluationEvent","constructor","generateEvaluationTokens","context","event","id","numberOfStudents","total","actionStatus","alternateName","model","where","equal","expand","name","options","getItem","prevAction","and","notEqual","silent","Error","courseClass","courseClassInstructor","eventInstructor","instructor","sections","getItems","length","mustRegisterSection","instructorSections","select","description","save","sectionIds","map","section","sectionId","in","count","generateAction","generateOptions","evaluationEvent","n","expires","endDate","generateTokens","err","TraceUtils","error","message","getTokenStatistics","tokenInfo","used","sent","tokens","getId","groupBy","item","sendEvaluationTokens","DataNotFoundError","eventStatus","DataError","actions","successfulTokenAction","find","generateTokenAction","students","getAllItems","Array","isArray","mailRegex","invalidEmail","student","email","test","token","access_token","mailTemplate","succeeded","failed","mailer","pop","Promise","resolve","template","subject","to","send","Object","assign","err1","push","succededToken","$state","sendTokensAction","module","exports"],"mappings":"aAAA;AACA;AACA;AACA,yC;;AAEA;AACA;AACA,G;;AAEMA,8B,WADLC,iBAAWC,UAAX,CAAsB,gCAAtB,C;;;;;;;;AASID,iBAAWE,MAAX,CAAkB,0BAAlB,EAA8C,+BAA9C,C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFAF,iBAAWG,IAAX,CAAgB,WAAhB,EAA6BC,cAAQC,YAAR,CAAqB,QAArB,CAA7B,C;;;;;;;;;;;;;;;;;;;;AAoBAL,iBAAWE,MAAX,CAAkB,sBAAlB,EAA0C,2BAA1C,C,2BA9GL,MACMH,8BADN,SAC8CO,6BAD9C,CAC8D,CAC1D;AACJ;AACA,KACIC,WAAW,GAAG,CACV,QACH,CAG8B,MAAxBC,wBAAwB,GAAG,CAC9B,MAAMC,OAAO,GAAG,KAAKA,OAArB,CACA,MAAMP,MAAM,GAAG,EACXQ,KAAK,EAAE,KAAKC,EADD,EAEXC,gBAAgB,EAAE,CAFP,EAGXC,KAAK,EAAE,CAHI,EAIXC,YAAY,EAAE,EAACC,aAAa,EAAE,uBAAhB,EAJH,EAAf,CAF8B,CAQ9B;AACA,UAAML,KAAK,GAAG,MAAMD,OAAO,CAACO,KAAR,CAAc,gCAAd,EAAgDC,KAAhD,CAAsD,IAAtD,EAA4D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;;;AAUA;AACA,aAAO,MAAMN,OAAO,CAACO,KAAR,CAAc,2BAAd,EAA2CU,MAA3C,GAAoDa,IAApD,CAAyD8D,gBAAzD,CAAb;AACH,KAtDD,CAsDE,OAAOhD,GAAP,EAAY;AACV;AACAC,yBAAWC,KAAX,CAAiBF,GAAjB;AACA;AACA,WAAK,MAAM8C,aAAX,IAA4Bd,SAA5B,EAAuC;AACnC,cAAM5E,OAAO,CAACO,KAAR,CAAc,uBAAd,EAAuCU,MAAvC,GAAgDa,IAAhD,CAAqD;AACvD4C,UAAAA,YAAY,EAAEgB,aADyC,EAC1B;AAC7BvC,UAAAA,IAAI,EAAE,IAFiD;AAGvDwC,UAAAA,MAAM,EAAE,CAH+C,EAArD,CAAN;;AAKH;AACD;AACA,YAAMC,gBAAgB,GAAG;AACrB3F,QAAAA,KAAK,EAAE,KAAKoD,KAAL,EADc;AAErBlD,QAAAA,gBAAgB,EAAE6D,QAAQ,CAACvC,MAFN;AAGrBrB,QAAAA,KAAK,EAAE6C,SAAS,CAAC7C,KAHI;AAIrB+C,QAAAA,IAAI,EAAEyB,SAAS,CAACnD,MAJK;AAKrBoD,QAAAA,MAAM,EAAED,SAAS,CAACnD,MAAV,GAAmBwB,SAAS,CAAC7C,KAAV,GAAkBwE,SAAS,CAACnD,MAA/C,GAAwDwB,SAAS,CAAC7C,KALrD;AAMrBC,QAAAA,YAAY,EAAE;AACVC,UAAAA,aAAa,EAAE,uBADL,EANO,EAAzB;;;AAUA;AACA,aAAO,MAAMN,OAAO,CAACO,KAAR,CAAc,2BAAd,EAA2CU,MAA3C,GAAoDa,IAApD,CAAyD8D,gBAAzD,CAAb;AACH;AACJ,GAxSyD,C;;AA0S9DC,MAAM,CAACC,OAAP,GAAiBxG,8BAAjB","sourcesContent":["import {EdmMapping, EdmType} from '@themost/data';\nimport EvaluationEvent from \"./evaluation-event-model\";\nimport {DataError, TraceUtils, DataNotFoundError} from \"@themost/common\";\nimport {getMailer} from \"@themost/mailer\";\n\n/**\n * @class\n */\n@EdmMapping.entityType('ClassInstructorEvaluationEvent')\nclass ClassInstructorEvaluationEvent extends EvaluationEvent {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n @EdmMapping.action('GenerateEvaluationTokens', 'GenerateInstructorTokenAction')\n async generateEvaluationTokens() {\n const context = this.context;\n const action = {\n event: this.id,\n numberOfStudents: 0,\n total: 0,\n actionStatus: {alternateName: 'PotentialActionStatus'}\n };\n // get courseClass instructor\n const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(this.id)\n .expand({\n name: 'courseClassInstructor',\n options: {\n '$expand': 'courseClass'\n }\n })\n .getItem();\n if (event) {\n //check if a GenerateInstructorTokenAction exists\n const prevAction = await context.model('GenerateInstructorTokenAction').where('event').equal(this.id)\n .and('actionStatus/alternateName').notEqual('FailedActionStatus')\n .silent().getItem();\n if (prevAction) {\n throw new Error('A previous action for generating evaluation tokens has been found.');\n }\n const courseClass = event.courseClassInstructor && event.courseClassInstructor.courseClass;\n const eventInstructor = event.courseClassInstructor && event.courseClassInstructor.instructor;\n // get class sections\n const sections = await context.model('CourseClassSection').where('courseClass').equal(courseClass.id).getItems();\n // check if course class has sections\n if (sections && sections.length > 0 && courseClass.mustRegisterSection !== 0) {\n // get only number of students registered at specific section\n const instructorSections = await context.model('CourseClassSectionInstructor').where('courseClass').equal(courseClass.id)\n .and('instructor').equal(eventInstructor).select('section/section as sectionId').silent().getItems();\n if (instructorSections && instructorSections.length === 0) {\n action.actionStatus.alternateName = 'FailedActionStatus';\n action.description = 'Instructor is not related with any of sections';\n return await context.model('GenerateInstructorTokenAction').save(action);\n } else {\n const sectionIds = instructorSections.map(section => {\n return section.sectionId;\n });\n // get number of students for specific course class sections\n action.numberOfStudents = await context.model('StudentCourseClass').where('courseClass').equal(courseClass.id)\n .and('section').in(sectionIds)\n .silent().count();\n }\n } else {\n action.numberOfStudents = await context.model('StudentCourseClass').where('courseClass').equal(courseClass.id).silent().count();\n }\n // save action and then generateTokens\n const generateAction = await context.model('GenerateInstructorTokenAction').save(action);\n const generateOptions =\n {\n evaluationEvent: event.id,\n n: action.numberOfStudents,\n expires : event.endDate\n };\n try {\n // save number of students to event\n event.numberOfStudents = action.numberOfStudents;\n await context.model('ClassInstructorEvaluationEvent').save(event);\n if (event.numberOfStudents>0) {\n await EvaluationEvent.generateTokens(context, generateOptions);\n }\n generateAction.total = action.numberOfStudents;\n generateAction.actionStatus = {alternateName: 'CompletedActionStatus'}\n return await context.model('GenerateInstructorTokenAction').save(generateAction);\n }\n catch (err) {\n TraceUtils.error(err);\n // update also action status\n generateAction.total = 0;\n generateAction.actionStatus = {alternateName: 'FailedActionStatus'}\n generateAction.description = err.message;\n return await context.model('GenerateInstructorTokenAction').save(generateAction);\n\n }\n }\n }\n @EdmMapping.func('TokenInfo', EdmType.CollectionOf('Object'))\n async getTokenStatistics() {\n const tokenInfo = {\n total: 0,\n used: 0,\n sent: 0\n };\n // get number if tokens\n const tokens = await this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.getId())\n .select('count(evaluationEvent) as total', 'used', 'sent')\n .groupBy('used', 'sent', 'evaluationEvent')\n .silent().getItems();\n tokens.map(item => {\n tokenInfo.total += item.total;\n tokenInfo.used += item.used ? item.total : 0;\n tokenInfo.sent += item.sent ? item.total : 0;\n });\n return tokenInfo;\n }\n\n @EdmMapping.action('SendEvaluationTokens', 'SendInstructorTokenAction')\n async sendEvaluationTokens() {\n const context = this.context;\n // get event\n const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(this.getId())\n .expand({\n name: 'courseClassInstructor',\n options: {\n '$expand': 'courseClass($expand=course), instructor' // expand course and instructor so their attributes are available in the mail template\n }\n },\n {\n name: 'actions',\n options: {\n '$expand': 'actionStatus'\n }\n })\n .getItem();\n // validate event\n if (event == null) {\n throw new DataNotFoundError('The event cannot be found or is inaccessible.');\n }\n // validate status\n if (!(event.eventStatus && event.eventStatus.alternateName === 'EventOpened')) {\n throw new DataError('Send tokens action may only be executed for Open/Active events.');\n }\n // validate event actions\n if (!(event.actions && event.actions.length)) {\n throw new DataNotFoundError('There are not generate token actions for the specified event or they are inaccessible.');\n }\n // find completed token generation action (can only be one)\n const successfulTokenAction = event.actions.find(generateTokenAction => generateTokenAction.actionStatus.alternateName === 'CompletedActionStatus');\n if (successfulTokenAction == null) {\n throw new DataError('The specified event does not have a completed token generation action.');\n }\n // get tokenInfo for this event\n const tokenInfo = await this.getTokenStatistics();\n // validate sent-used seperately for descriptive errors\n if (tokenInfo.sent) {\n throw new DataError(`Cannot proceed with sending tokens, because ${tokenInfo.sent} of them is/are already sent.`);\n }\n if (tokenInfo.used) {\n throw new DataError(`Cannot proceed with sending tokens, because ${tokenInfo.used} of them is/are already used.`);\n }\n // start gathering students\n let students;\n const courseClass = event.courseClassInstructor && event.courseClassInstructor.courseClass;\n const eventInstructor = event.courseClassInstructor && event.courseClassInstructor.instructor;\n // get class sections\n const sections = await context.model('CourseClassSection').where('courseClass').equal(courseClass.id).getItems();\n // check if course class has sections\n if (sections && sections.length > 0 && courseClass.mustRegisterSection !== 0) {\n // get only number of students registered at specific section\n const instructorSections = await context.model('CourseClassSectionInstructor').where('courseClass').equal(courseClass.id)\n .and('instructor').equal(eventInstructor).select('section/section as sectionId').silent().getItems();\n if (instructorSections && instructorSections.length === 0) {\n throw new DataError('Instructor is not related with any of sections');\n } \n const sectionIds = instructorSections.map(section => {\n return section.sectionId;\n });\n // get students for specific course class sections\n students = await context.model('StudentCourseClass')\n .where('courseClass').equal(courseClass.id)\n .and('section').in(sectionIds)\n .select('email')\n .silent()\n .getAllItems();\n } else {\n students = await context.model('StudentCourseClass')\n .where('courseClass').equal(courseClass.id)\n .select('email')\n .silent()\n .getAllItems();\n }\n if (!(Array.isArray(students) && students.length)) {\n throw new DataError('No recipients/students found.');\n }\n // check total of students\n if (students.length !== tokenInfo.total) {\n throw new DataError(`Cannot proceed to sending tokens. Students are ${students.length} and generated tokens are ${tokenInfo.total}.`);\n }\n // validate student emails, must all exist and have a valid format\n // https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address\n const mailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;\n const invalidEmail = students.find(student => {\n return !(student.email && mailRegex.test(student.email));\n });\n if (invalidEmail) {\n throw new DataError(`Cannot procced to sending tokens because at least one student's email is null or invalid. Found invalid email: ${invalidEmail.email || 'empty'}`);\n }\n // get tokens\n let tokens = await this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.getId())\n .select('access_token')\n .silent()\n .getAllItems();\n // and map them to an array\n tokens = tokens.map(token => token.access_token);\n // get mail template\n const mailTemplate = await context.model('MailConfiguration')\n .where('target').equal('SendInstructorTokenAction')\n .silent()\n .getItem();\n if (mailTemplate == null) {\n throw new DataError('Cannot execute send tokens action because template is missing for SendInstructorTokenAction.');\n }\n const succeeded = [];\n const failed = [];\n try {\n // use an async function to send emails\n await (async () => {\n for (const student of students) {\n // refresh mailer\n const mailer = getMailer(context); // maybe investigate why this has to be refreshed.\n // pop an access token\n const access_token = tokens.pop();\n // send message\n await new Promise(resolve => {\n mailer\n .template(mailTemplate.template)\n .subject(mailTemplate.subject)\n .to(student.email)\n .send(Object.assign(event, {\n access_token\n }), (err) => {\n if (err) {\n try {\n TraceUtils.error(`SendEvaluationTokensAction', 'An error occurred while trying to send token to student email ${student.email}`);\n TraceUtils.error(err);\n } catch (err1) {\n // do nothing\n }\n failed.push(access_token);\n return resolve();\n }\n succeeded.push(access_token);\n return resolve();\n });\n });\n }\n })();\n // update successfully sent tokens\n for (const succededToken of succeeded) {\n await context.model('EvaluationAccessToken').silent().save({\n access_token: succededToken, // access_token is primary\n sent: true,\n $state: 2\n });\n }\n // create send tokens action\n const sendTokensAction = {\n event: this.getId(),\n numberOfStudents: students.length,\n total: tokenInfo.total,\n sent: succeeded.length,\n failed: failed.length,\n actionStatus: {\n alternateName: 'CompletedActionStatus'\n }\n }\n // and save\n return await context.model('SendInstructorTokenAction').silent().save(sendTokensAction);\n } catch (err) {\n // log error\n TraceUtils.error(err);\n // update successfully sent tokens\n for (const succededToken of succeeded) {\n await context.model('EvaluationAccessToken').silent().save({\n access_token: succededToken, // access_token is primary\n sent: true,\n $state: 2\n });\n }\n // create send tokens action\n const sendTokensAction = {\n event: this.getId(),\n numberOfStudents: students.length,\n total: tokenInfo.total,\n sent: succeeded.length,\n failed: succeeded.length ? tokenInfo.total - succeeded.length : tokenInfo.total,\n actionStatus: {\n alternateName: 'CompletedActionStatus'\n }\n }\n // and save\n return await context.model('SendInstructorTokenAction').silent().save(sendTokensAction);\n }\n }\n}\nmodule.exports = ClassInstructorEvaluationEvent;\n"],"file":"class-instructor-evaluation-event-model.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/models/class-instructor-evaluation-event-model.js"],"names":["ClassInstructorEvaluationEvent","EdmMapping","entityType","action","func","EdmType","CollectionOf","EvaluationEvent","constructor","generateEvaluationTokens","context","event","id","numberOfStudents","total","actionStatus","alternateName","model","where","equal","expand","name","options","getItem","prevAction","and","notEqual","silent","Error","courseClass","courseClassInstructor","eventInstructor","instructor","sections","getItems","length","mustRegisterSection","instructorSections","select","description","save","sectionIds","map","section","sectionId","in","count","generateAction","generateOptions","evaluationEvent","n","expires","endDate","generateTokens","err","TraceUtils","error","message","getTokenStatistics","tokenInfo","used","sent","tokens","getId","groupBy","item","sendEvaluationTokens","currentDate","Date","startOf","toDate","greaterOrEqual","DataNotFoundError","eventStatus","DataError","actions","successfulTokenAction","find","generateTokenAction","students","getAllItems","Array","isArray","mailRegex","invalidEmail","student","email","test","token","access_token","mailTemplate","succeeded","failed","exp","RegExp","subject","params","match","forEach","param","replace","familyName","givenName","course","displayCode","title","mailer","pop","Promise","resolve","template","to","send","Object","assign","err1","push","succededToken","$state","sendTokensAction","module","exports"],"mappings":"aAAA;AACA;A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L,EADc;AAErBlD,QAAAA,gBAAgB,EAAEkE,QAAQ,CAAC5C,MAFN;AAGrBrB,QAAAA,KAAK,EAAE6C,SAAS,CAAC7C,KAHI;AAIrB+C,QAAAA,IAAI,EAAE8B,SAAS,CAACxD,MAJK;AAKrByD,QAAAA,MAAM,EAAED,SAAS,CAACxD,MAAV,GAAmBwB,SAAS,CAAC7C,KAAV,GAAkB6E,SAAS,CAACxD,MAA/C,GAAwDwB,SAAS,CAAC7C,KALrD;AAMrBC,QAAAA,YAAY,EAAE;AACVC,UAAAA,aAAa,EAAE,uBADL,EANO,EAAzB;;;AAUA;AACA,aAAO,MAAMN,OAAO,CAACO,KAAR,CAAc,2BAAd,EAA2CU,MAA3C,GAAoDa,IAApD,CAAyD+E,gBAAzD,CAAb;AACH;AACJ,GA7TyD,C;;AA+T9DC,MAAM,CAACC,OAAP,GAAiBzH,8BAAjB","sourcesContent":["import {EdmMapping, EdmType} from '@themost/data';\nimport EvaluationEvent from \"./evaluation-event-model\";\nimport {DataError, TraceUtils, DataNotFoundError} from \"@themost/common\";\nimport {getMailer} from \"@themost/mailer\";\nimport moment from \"moment\";\n\n/**\n * @class\n */\n@EdmMapping.entityType('ClassInstructorEvaluationEvent')\nclass ClassInstructorEvaluationEvent extends EvaluationEvent {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n @EdmMapping.action('GenerateEvaluationTokens', 'GenerateInstructorTokenAction')\n async generateEvaluationTokens() {\n const context = this.context;\n const action = {\n event: this.id,\n numberOfStudents: 0,\n total: 0,\n actionStatus: {alternateName: 'PotentialActionStatus'}\n };\n // get courseClass instructor\n const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(this.id)\n .expand({\n name: 'courseClassInstructor',\n options: {\n '$expand': 'courseClass'\n }\n })\n .getItem();\n if (event) {\n //check if a GenerateInstructorTokenAction exists\n const prevAction = await context.model('GenerateInstructorTokenAction').where('event').equal(this.id)\n .and('actionStatus/alternateName').notEqual('FailedActionStatus')\n .silent().getItem();\n if (prevAction) {\n throw new Error('A previous action for generating evaluation tokens has been found.');\n }\n const courseClass = event.courseClassInstructor && event.courseClassInstructor.courseClass;\n const eventInstructor = event.courseClassInstructor && event.courseClassInstructor.instructor;\n // get class sections\n const sections = await context.model('CourseClassSection').where('courseClass').equal(courseClass.id).getItems();\n // check if course class has sections\n if (sections && sections.length > 0 && courseClass.mustRegisterSection !== 0) {\n // get only number of students registered at specific section\n const instructorSections = await context.model('CourseClassSectionInstructor').where('courseClass').equal(courseClass.id)\n .and('instructor').equal(eventInstructor).select('section/section as sectionId').silent().getItems();\n if (instructorSections && instructorSections.length === 0) {\n action.actionStatus.alternateName = 'FailedActionStatus';\n action.description = 'Instructor is not related with any of sections';\n return await context.model('GenerateInstructorTokenAction').save(action);\n } else {\n const sectionIds = instructorSections.map(section => {\n return section.sectionId;\n });\n // get number of students for specific course class sections\n action.numberOfStudents = await context.model('StudentCourseClass').where('courseClass').equal(courseClass.id)\n .and('section').in(sectionIds)\n .silent().count();\n }\n } else {\n action.numberOfStudents = await context.model('StudentCourseClass').where('courseClass').equal(courseClass.id).silent().count();\n }\n // save action and then generateTokens\n const generateAction = await context.model('GenerateInstructorTokenAction').save(action);\n const generateOptions =\n {\n evaluationEvent: event.id,\n n: action.numberOfStudents,\n expires : event.endDate\n };\n try {\n // save number of students to event\n event.numberOfStudents = action.numberOfStudents;\n await context.model('ClassInstructorEvaluationEvent').save(event);\n if (event.numberOfStudents>0) {\n await EvaluationEvent.generateTokens(context, generateOptions);\n }\n generateAction.total = action.numberOfStudents;\n generateAction.actionStatus = {alternateName: 'CompletedActionStatus'}\n return await context.model('GenerateInstructorTokenAction').save(generateAction);\n }\n catch (err) {\n TraceUtils.error(err);\n // update also action status\n generateAction.total = 0;\n generateAction.actionStatus = {alternateName: 'FailedActionStatus'}\n generateAction.description = err.message;\n return await context.model('GenerateInstructorTokenAction').save(generateAction);\n\n }\n }\n }\n @EdmMapping.func('TokenInfo', EdmType.CollectionOf('Object'))\n async getTokenStatistics() {\n const tokenInfo = {\n total: 0,\n used: 0,\n sent: 0\n };\n // get number if tokens\n const tokens = await this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.getId())\n .select('count(evaluationEvent) as total', 'used', 'sent')\n .groupBy('used', 'sent', 'evaluationEvent')\n .silent().getItems();\n tokens.map(item => {\n tokenInfo.total += item.total;\n tokenInfo.used += item.used ? item.total : 0;\n tokenInfo.sent += item.sent ? item.total : 0;\n });\n return tokenInfo;\n }\n\n @EdmMapping.action('SendEvaluationTokens', 'SendInstructorTokenAction')\n async sendEvaluationTokens() {\n const context = this.context;\n // get event and check if event endDate has passed\n // get current date\n const currentDate = moment(new Date()).startOf('day').toDate(); // get only date format\n const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(this.getId())\n .and('date(endDate)').greaterOrEqual(currentDate)\n .expand({\n name: 'courseClassInstructor',\n options: {\n '$expand': 'courseClass($expand=course), instructor' // expand course and instructor so their attributes are available in the mail template\n }\n },\n {\n name: 'actions',\n options: {\n '$expand': 'actionStatus'\n }\n })\n .getItem();\n // validate event\n if (event == null) {\n throw new DataNotFoundError('The event cannot be found or is inaccessible.');\n }\n // validate status\n if (!(event.eventStatus && event.eventStatus.alternateName === 'EventOpened')) {\n throw new DataError('Send tokens action may only be executed for Open/Active events.');\n }\n // validate event actions\n if (!(event.actions && event.actions.length)) {\n throw new DataNotFoundError('There are not generate token actions for the specified event or they are inaccessible.');\n }\n // find completed token generation action (can only be one)\n const successfulTokenAction = event.actions.find(generateTokenAction => generateTokenAction.actionStatus.alternateName === 'CompletedActionStatus');\n if (successfulTokenAction == null) {\n throw new DataError('The specified event does not have a completed token generation action.');\n }\n // get tokenInfo for this event\n const tokenInfo = await this.getTokenStatistics();\n // validate sent-used seperately for descriptive errors\n if (tokenInfo.sent) {\n throw new DataError(`Cannot proceed with sending tokens, because ${tokenInfo.sent} of them is/are already sent.`);\n }\n if (tokenInfo.used) {\n throw new DataError(`Cannot proceed with sending tokens, because ${tokenInfo.used} of them is/are already used.`);\n }\n // start gathering students\n let students;\n const courseClass = event.courseClassInstructor && event.courseClassInstructor.courseClass;\n const eventInstructor = event.courseClassInstructor && event.courseClassInstructor.instructor;\n // get class sections\n const sections = await context.model('CourseClassSection').where('courseClass').equal(courseClass.id).getItems();\n // check if course class has sections\n if (sections && sections.length > 0 && courseClass.mustRegisterSection !== 0) {\n // get only number of students registered at specific section\n const instructorSections = await context.model('CourseClassSectionInstructor').where('courseClass').equal(courseClass.id)\n .and('instructor').equal(eventInstructor).select('section/section as sectionId').silent().getItems();\n if (instructorSections && instructorSections.length === 0) {\n throw new DataError('Instructor is not related with any of sections');\n } \n const sectionIds = instructorSections.map(section => {\n return section.sectionId;\n });\n // get students for specific course class sections\n students = await context.model('StudentCourseClass')\n .where('courseClass').equal(courseClass.id)\n .and('section').in(sectionIds)\n .select('email')\n .silent()\n .getAllItems();\n } else {\n students = await context.model('StudentCourseClass')\n .where('courseClass').equal(courseClass.id)\n .select('email')\n .silent()\n .getAllItems();\n }\n if (!(Array.isArray(students) && students.length)) {\n throw new DataError('No recipients/students found.');\n }\n // check total of students\n if (students.length !== tokenInfo.total) {\n throw new DataError(`Cannot proceed to sending tokens. Students are ${students.length} and generated tokens are ${tokenInfo.total}.`);\n }\n // validate student emails, must all exist and have a valid format\n // https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address\n const mailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;\n const invalidEmail = students.find(student => {\n return !(student.email && mailRegex.test(student.email));\n });\n if (invalidEmail) {\n throw new DataError(`Cannot procced to sending tokens because at least one student's email is null or invalid. Found invalid email: ${invalidEmail.email || 'empty'}`);\n }\n // get tokens\n let tokens = await this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.getId())\n .select('access_token')\n .silent()\n .getAllItems();\n // and map them to an array\n tokens = tokens.map(token => token.access_token);\n // get mail template\n const mailTemplate = await context.model('MailConfiguration')\n .where('target').equal('SendInstructorTokenAction')\n .silent()\n .getItem();\n if (mailTemplate == null) {\n throw new DataError('Cannot execute send tokens action because template is missing for SendInstructorTokenAction.');\n }\n const succeeded = [];\n const failed = [];\n try {\n // format mail subject expected params ${course}, ${instructor}\n const exp = new RegExp('\\\\$\\\\{\\\\w+\\\\}+','ig');\n let subject = mailTemplate.subject;\n const params = subject.match(exp);\n if (params.length>0) {\n // parse only custom parameters ${instructor},${course}\n params.forEach(param => {\n if (param === '${instructor}') {\n // get instructor full name\n subject = subject.replace(param, eventInstructor? `${eventInstructor.familyName} ${eventInstructor.givenName}` : '');\n } else if (param === '${course}') {\n // get courseClass code and title\n subject = subject.replace(param, courseClass.course ? `${courseClass.course.displayCode} ${courseClass.title}` : '');\n } else {\n subject = subject.replace(param, '');\n }\n });\n }\n // use an async function to send emails\n await (async () => {\n for (const student of students) {\n // refresh mailer\n const mailer = getMailer(context); // maybe investigate why this has to be refreshed.\n // pop an access token\n const access_token = tokens.pop();\n // send message\n await new Promise(resolve => {\n mailer\n .template(mailTemplate.template)\n .subject(subject)\n .to(student.email)\n .send(Object.assign(event, {\n access_token\n }), (err) => {\n if (err) {\n try {\n TraceUtils.error(`SendEvaluationTokensAction', 'An error occurred while trying to send token to student email ${student.email}`);\n TraceUtils.error(err);\n } catch (err1) {\n // do nothing\n }\n failed.push(access_token);\n return resolve();\n }\n succeeded.push(access_token);\n return resolve();\n });\n });\n }\n })();\n // update successfully sent tokens\n for (const succededToken of succeeded) {\n await context.model('EvaluationAccessToken').silent().save({\n access_token: succededToken, // access_token is primary\n sent: true,\n $state: 2\n });\n }\n // create send tokens action\n const sendTokensAction = {\n event: this.getId(),\n numberOfStudents: students.length,\n total: tokenInfo.total,\n sent: succeeded.length,\n failed: failed.length,\n actionStatus: {\n alternateName: 'CompletedActionStatus'\n }\n }\n // and save\n return await context.model('SendInstructorTokenAction').silent().save(sendTokensAction);\n } catch (err) {\n // log error\n TraceUtils.error(err);\n // update successfully sent tokens\n for (const succededToken of succeeded) {\n await context.model('EvaluationAccessToken').silent().save({\n access_token: succededToken, // access_token is primary\n sent: true,\n $state: 2\n });\n }\n // create send tokens action\n const sendTokensAction = {\n event: this.getId(),\n numberOfStudents: students.length,\n total: tokenInfo.total,\n sent: succeeded.length,\n failed: succeeded.length ? tokenInfo.total - succeeded.length : tokenInfo.total,\n actionStatus: {\n alternateName: 'CompletedActionStatus'\n }\n }\n // and save\n return await context.model('SendInstructorTokenAction').silent().save(sendTokensAction);\n }\n }\n}\nmodule.exports = ClassInstructorEvaluationEvent;\n"],"file":"class-instructor-evaluation-event-model.js"}
|
|
@@ -77,6 +77,9 @@ _data.EdmMapping.func('Current', 'EvaluationEvent'), _dec3 =
|
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
80
83
|
|
|
81
84
|
|
|
82
85
|
|
|
@@ -262,6 +265,41 @@ _data.EdmMapping.func('FormAttributes', _data.EdmType.CollectionOf('Object')), _
|
|
|
262
265
|
|
|
263
266
|
|
|
264
267
|
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
265
303
|
|
|
266
304
|
|
|
267
305
|
|
|
@@ -292,9 +330,8 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
292
330
|
*/static async getCurrent(context) {// get evaluation key
|
|
293
331
|
const token = await EvaluationAccessToken.inspect(context, context.user && context.user.authenticationToken);if (token.active === false) {throw new _common.HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');} // get evaluation event
|
|
294
332
|
// get current date
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
let evaluationEvent = await context.model('EvaluationEvent').where('id').equal(token.sub).and('date(startDate)').lowerOrEqual(startDate).and('date(endDate)').greaterOrEqual(endDate).and('eventStatus/alternateName').equal('EventOpened').silent().getTypedItem();if (evaluationEvent == null) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found');}if (evaluationEvent.additionalType !== 'EvaluationEvent') {if (evaluationEvent.additionalType === 'ClassInstructorEvaluationEvent') {const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(token.sub).expand({ name: 'courseClassInstructor', options: { $expand: 'courseClass($expand=course,year,period),instructor' } }).silent().getTypedItem();const courseClass = event.courseClassInstructor.courseClass;const instructor = event.courseClassInstructor.instructor;evaluationEvent.courseClass = `${courseClass.course.displayCode}-${courseClass.title} (${courseClass.year.alternateName}-${courseClass.period.name}) `;evaluationEvent.instructor = `${instructor.familyName} ${instructor.givenName}`;} else {evaluationEvent = await evaluationEvent.silent().getAdditionalObject();}}return evaluationEvent;}async getForm() {const form = await this.property('evaluationDocument').getItem();const service = this.context.getApplication().getService(function PrivateContentService() {}); /**
|
|
333
|
+
let evaluationEvent = await context.model('EvaluationEvent').where('id').equal(token.sub).and('eventStatus/alternateName').equal('EventOpened').silent().getTypedItem();if (evaluationEvent == null) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found');} // check dates
|
|
334
|
+
const currentDate = new Date().setHours(0, 0, 0, 0);const startDate = evaluationEvent.startDate.setHours(0, 0, 0, 0);const endDate = evaluationEvent.endDate.setHours(0, 0, 0, 0);if (startDate > currentDate || endDate < currentDate) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found, it is expired or not started.');}if (evaluationEvent.additionalType !== 'EvaluationEvent') {if (evaluationEvent.additionalType === 'ClassInstructorEvaluationEvent') {const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(token.sub).expand({ name: 'courseClassInstructor', options: { $expand: 'courseClass($expand=course,year,period),instructor' } }).silent().getTypedItem();const courseClass = event.courseClassInstructor.courseClass;const instructor = event.courseClassInstructor.instructor;evaluationEvent.courseClass = `${courseClass.course.displayCode}-${courseClass.title} (${courseClass.year.alternateName}-${courseClass.period.name}) `;evaluationEvent.instructor = `${instructor.familyName} ${instructor.givenName}`;} else {evaluationEvent = await evaluationEvent.silent().getAdditionalObject();}}return evaluationEvent;}async getForm() {const form = await this.property('evaluationDocument').getItem();const service = this.context.getApplication().getService(function PrivateContentService() {}); /**
|
|
298
335
|
* @type {string}
|
|
299
336
|
*/const formPath = await new Promise((resolve, reject) => {service.resolvePhysicalPath(this.context, form, (err, physicalPath) => {if (err) {return reject(err);}return resolve(physicalPath);});});const readFileAsync = _util.default.promisify(_fs.default.readFile);let content = await readFileAsync(formPath);if (content == null) {throw new _common.HttpNotFoundError('Evaluation form cannot be found');}let buffer = Buffer.from(content, 'base64');let result;result = JSON.parse(buffer.toString('utf8'));try {result.properties = result.properties || {};Object.assign(result.properties, { name: form.resultType, _id: form.id, _event: this.id }); // post-processing
|
|
300
337
|
let shouldUpgrade = true;let model = this.context.model(form.resultType);if (model != null) {shouldUpgrade = (0, _semver.lt)(model.version, form.version);}if (shouldUpgrade) {// load for inspector
|
|
@@ -316,17 +353,18 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
316
353
|
*/const context = this.context;const result = [];const form = await this.getForm();this.setParentLegend(form); // get model attributes
|
|
317
354
|
/**
|
|
318
355
|
* @type {DataConfigurationStrategy|*}
|
|
319
|
-
*/const dataConfiguration = context.getApplication().getConfiguration().getStrategy(_data.DataConfigurationStrategy);const dataTypes = dataConfiguration.dataTypes;const q = context.model(form.properties.name).asQueryable();const selectArguments = [];const model = dataConfiguration.model(form.properties.name);const attributes = model.fields;attributes.forEach((attribute) => {const key = this.findByKey(form.components, attribute.name);if (key) {attribute = Object.assign(attribute, { name: attribute.name, label: key.label });attribute.isNumber = false;attribute.legend = key.customProperties && key.customProperties.legend;if (Object.prototype.hasOwnProperty.call(dataTypes, attribute.type)) {attribute.isNumber = dataTypes[attribute.type].type === 'number';}selectArguments.push(`${attribute.name}`);
|
|
320
|
-
|
|
356
|
+
*/const dataConfiguration = context.getApplication().getConfiguration().getStrategy(_data.DataConfigurationStrategy);const dataTypes = dataConfiguration.dataTypes;const q = context.model(form.properties.name).asQueryable();const selectArguments = [];const model = dataConfiguration.model(form.properties.name);const attributes = model.fields;attributes.forEach((attribute) => {const key = this.findByKey(form.components, attribute.name);if (key) {attribute = Object.assign(attribute, { name: attribute.name, label: key.label });attribute.isNumber = false;attribute.legend = key.customProperties && key.customProperties.legend;if (Object.prototype.hasOwnProperty.call(dataTypes, attribute.type)) {attribute.isNumber = dataTypes[attribute.type].type === 'number';}selectArguments.push(`${attribute.name}`); // clear std,avg and responses from model attribute
|
|
357
|
+
attribute.std = 0;attribute.avg = 0;delete attribute.responses;result.push(attribute);}});const showResults = await this.showResults(context);if (selectArguments.length && showResults === true) {const responses = await q.select.apply(q, selectArguments).where('evaluationEvent').equal(this.getId()).silent().getAllItems();for (let i = 0; i < result.length; i++) {const qElement = result[i];qElement.responses = [];if (qElement.isNumber) {// add mean value and standard deviation
|
|
358
|
+
qElement.std = responses.length ? math.std(responses.map((x) => {return x[qElement.name];})) : 0;qElement.avg = responses.length ? math.mean(responses.map((x) => {return x[qElement.name];})) : 0;} else {qElement.responses = responses.map((x) => {return x[qElement.name];});}}}return result;}async showResults(context) {// this is a custom way to get permissions based on eventStatus and user groups
|
|
359
|
+
let showResults = true;let found = false;const eventStatusesResults = context.getConfiguration().getSourceAt('settings/evaluation/results/statuses') || [];const groupsAllowed = context.getConfiguration().getSourceAt('settings/evaluation/results/groupsAllowed') || [];if (eventStatusesResults.length > 0) {// check if eventStatus is allowed
|
|
360
|
+
if (groupsAllowed.length > 0) {// but first check if user belongs to allowed groups
|
|
361
|
+
const userName = context.interactiveUser ? context.interactiveUser.name : context.user.name;const user = await context.model('User').where('name').equal(userName).expand('groups').getItem();found = user.groups.some((r) => groupsAllowed.indexOf(r.name) >= 0);}if (!found) {const evaluationEvent = await context.model('EvaluationEvent').where('id').equal(this.getId()).select('id', 'eventStatus/alternateName as eventStatus').getItem();if (evaluationEvent == null) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found');}showResults = eventStatusesResults.findIndex((x) => {return x === evaluationEvent.eventStatus;}) >= 0;}}return showResults;}findByKey(array, key) {for (let index = 0; index < array.length; index++) {const element = array[index];if (element.key === key) {return element;} else {if (element.components) {const found = this.findByKey(element.components, key);if (found) {return found;}}}}}setParentLegend(component) {if (Array.isArray(component.components)) {component.components.forEach((item) => {if (component.legend) {item.customProperties = item.customProperties || {};item.customProperties.legend = component.legend;}this.setParentLegend(item);});}}async evaluate(data) {const token = await EvaluationAccessToken.inspect(this.context, this.context.user.authenticationToken);if (token.active === false) {throw new _common.HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');}if (this.id !== token.sub) {throw new _common.HttpBadRequestError('Evaluation access token is invalid');} // get evaluation form
|
|
321
362
|
const form = await this.getForm(); // get evaluation document
|
|
322
363
|
if (form == null) {throw new _common.HttpNotFoundError('Evaluation form cannot be found');} // get evaluation document
|
|
323
364
|
const evaluationDocument = await this.context.model(_evaluationDocumentModel.default).where('id').equal(form.properties._id).silent().getItem();if (evaluationDocument == null) {throw new _common.HttpNotFoundError('Evaluation document cannot be found');} // assign defaults
|
|
324
365
|
Object.assign(data, { evaluationEvent: this.id, evaluationDocument: evaluationDocument.id }); // and finally append evaluation
|
|
325
366
|
await this.context.model(evaluationDocument.resultType).on('after.save', (event, callback) => {const context = event.model.context;context.model(EvaluationAccessToken).where('access_token').equal(context.user && context.user.authenticationToken).silent().getItem().then((token) => {if (token == null) {throw new _common.HttpTokenExpiredError('Evaluation token is required');}return context.model(EvaluationAccessToken).silent().save({ access_token: token.access_token, expires: new Date(0), // set epoch date
|
|
326
|
-
used: true });
|
|
327
|
-
}).then(() => {
|
|
328
|
-
return callback();
|
|
329
|
-
}).catch((err) => {
|
|
367
|
+
used: true });}).then(() => {return callback();}).catch((err) => {
|
|
330
368
|
_common.TraceUtils.error('An error occurred while submitting evaluation');
|
|
331
369
|
return callback(err);
|
|
332
370
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/evaluation-event-model.js"],"names":["EvaluationAccessToken","require","math","EvaluationEvent","EdmMapping","entityType","func","EdmType","CollectionOf","param","action","DataObject","constructor","getCurrent","context","token","inspect","user","authenticationToken","active","HttpTokenExpiredError","startDate","Date","endDate","startOf","toDate","evaluationEvent","model","where","equal","sub","and","lowerOrEqual","greaterOrEqual","silent","getTypedItem","HttpNotFoundError","additionalType","event","expand","name","options","$expand","courseClass","courseClassInstructor","instructor","course","displayCode","title","year","alternateName","period","familyName","givenName","getAdditionalObject","getForm","form","property","getItem","service","getApplication","getService","PrivateContentService","formPath","Promise","resolve","reject","resolvePhysicalPath","err","physicalPath","readFileAsync","util","promisify","fs","readFile","content","buffer","Buffer","from","result","JSON","parse","toString","properties","Object","assign","resultType","_id","id","_event","shouldUpgrade","version","inspector","JsonFormInspector","source","view","hidden","fields","push","apply","type","getModel","editable","nullable","indexed","dataConfiguration","getConfiguration","getStrategy","DataConfigurationStrategy","privileges","splice","thisModel","Array","isArray","resultPrivileges","setModelDefinition","builder","ODataModelBuilder","addEntitySet","removeEntitySet","save","TraceUtils","error","HttpServerError","getResults","prepare","getAccessTokens","getFormAttributes","setParentLegend","dataTypes","q","asQueryable","selectArguments","attributes","forEach","attribute","key","findByKey","components","label","isNumber","legend","customProperties","prototype","hasOwnProperty","call","length","responses","select","getId","getAllItems","i","qElement","std","map","x","avg","mean","array","index","element","found","component","item","evaluate","data","HttpBadRequestError","evaluationDocument","EvaluationDocument","on","callback","then","access_token","expires","used","catch","generateTokens","generateOptions","items","n","newItems","itemGenerateOptions","generateManyTokens","Args","check","maximumGenerateTokens","LangUtils","parseInt","getSourceAt","module","exports"],"mappings":"aAAA;;;;;;AAMA;;;;;;;;AAQA;AACA;AACA;;;AAGA;AACA;AACA;AACA,wD,s2BAJA,MAAMA,qBAAqB,GAAGC,OAAO,CAAC,iCAAD,CAArC;AAKA,MAAMC,IAAI,GAAGD,OAAO,CAAC,QAAD,CAApB;;AAEA;AACA;AACA,G;;AAEME,e,WADLC,iBAAWC,UAAX,CAAsB,iBAAtB,C;;;;;;;;;;;;AAaID,iBAAWE,IAAX,CAAgB,SAAhB,EAA2B,iBAA3B,C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CAF,iBAAWE,IAAX,CAAgB,MAAhB,EAAwB,QAAxB,C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGAF,iBAAWE,IAAX,CAAgB,SAAhB,EAA2BC,cAAQC,YAAR,CAAqB,QAArB,CAA3B,C;;;;;;AAMAJ,iBAAWE,IAAX,CAAgB,QAAhB,EAA0BC,cAAQC,YAAR,CAAqB,uBAArB,CAA1B,C;;;;;AAKAJ,iBAAWE,IAAX,CAAgB,gBAAhB,EAAkCC,cAAQC,YAAR,CAAqB,QAArB,CAAlC,C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuFAJ,iBAAWK,KAAX,CAAiB,MAAjB,EAAyB,QAAzB,EAAmC,KAAnC,EAA0C,IAA1C,C;AACAL,iBAAWM,MAAX,CAAkB,UAAlB,EAA8B,QAA9B,C,2BAlQL,MACMP,eADN,S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pBadRequestError,\n Args,\n LangUtils} from '@themost/common';\n\nimport {\n DataConfigurationStrategy,\n DataContext,\n DataObject,\n EdmMapping,\n EdmType,\n ODataModelBuilder\n} from '@themost/data';\nimport { HttpContext } from '@themost/web';\nimport { JsonFormInspector } from '@themost/form-inspector';\nimport EvaluationDocument from './evaluation-document-model';\n\nconst EvaluationAccessToken = require('./evaluation-access-token-model');\nimport {lt} from 'semver';\nimport util from \"util\";\nimport fs from \"fs\";\nimport moment from \"moment\";\nconst math = require('mathjs');\n\n/**\n * @class\n */\n@EdmMapping.entityType('EvaluationEvent')\nclass EvaluationEvent extends DataObject {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n /**\n * Get current evaluation based on the evaluation key contained in Evaluation-Key HTTP header\n * @param {HttpContext} context\n */\n @EdmMapping.func('Current', 'EvaluationEvent')\n static async getCurrent(context) {\n // get evaluation key\n const token = await EvaluationAccessToken.inspect(context, context.user && context.user.authenticationToken);\n if (token.active === false) {\n throw new HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');\n }\n // get evaluation event\n // get current date\n const startDate = new Date(); // get current date with time\n const endDate = moment(new Date()).startOf('day').toDate(); // get only date format\n let evaluationEvent = await context.model('EvaluationEvent')\n .where('id').equal(token.sub)\n .and('date(startDate)').lowerOrEqual(startDate)\n .and('date(endDate)').greaterOrEqual(endDate)\n .and('eventStatus/alternateName').equal('EventOpened')\n .silent().getTypedItem();\n if (evaluationEvent == null) {\n throw new HttpNotFoundError('The specified evaluation cannot be found');\n }\n if (evaluationEvent.additionalType !== 'EvaluationEvent') {\n if (evaluationEvent.additionalType === 'ClassInstructorEvaluationEvent') {\n const event = await context.model('ClassInstructorEvaluationEvent')\n .where('id').equal(token.sub)\n .expand({\n name: 'courseClassInstructor',\n options: {\n $expand: 'courseClass($expand=course,year,period),instructor'\n }\n })\n .silent().getTypedItem();\n const courseClass= event.courseClassInstructor.courseClass;\n const instructor = event.courseClassInstructor.instructor;\n evaluationEvent.courseClass = `${courseClass.course.displayCode}-${courseClass.title} (${courseClass.year.alternateName}-${courseClass.period.name}) `;\n evaluationEvent.instructor = `${instructor.familyName} ${instructor.givenName}`;\n } else {\n evaluationEvent = await evaluationEvent.silent().getAdditionalObject();\n }\n }\n return evaluationEvent;\n }\n\n @EdmMapping.func('form', 'Object')\n async getForm() {\n const form = await this.property('evaluationDocument').getItem();\n const service = this.context.getApplication().getService(function PrivateContentService(){});\n /**\n * @type {string}\n */\n const formPath = await new Promise((resolve, reject) => {\n service.resolvePhysicalPath(this.context, form, (err, physicalPath) => {\n if (err) {\n return reject(err);\n }\n return resolve(physicalPath);\n })\n });\n const readFileAsync = util.promisify(fs.readFile);\n let content = await readFileAsync(formPath);\n if (content == null) {\n throw new HttpNotFoundError('Evaluation form cannot be found');\n }\n let buffer = Buffer.from(content,'base64');\n let result;\n result = JSON.parse(buffer.toString('utf8'));\n\n try {\n result.properties = result.properties || {};\n Object.assign(result.properties, {\n name: form.resultType,\n _id: form.id,\n _event: this.id\n });\n // post-processing\n let shouldUpgrade = true;\n let model = this.context.model(form.resultType);\n if (model != null) {\n shouldUpgrade = lt(model.version, form.version)\n }\n if (shouldUpgrade) {\n // load for inspector\n const inspector = new JsonFormInspector();\n model = inspector.inspect(result);\n // post processing steps\n Object.assign(model, {\n source: form.resultType, // add source from evaluation document e.g. Evaluation1\n view: form.resultType, // add view from evaluation document e.g. Evaluation1\n version: model.version ,// set version (follow updates)\n hidden: true\n });\n // add evaluation event and evaluation document associations\n // for further processing of evaluation results\n model.fields.push.apply(model.fields, [\n {\n name: 'evaluationEvent',\n type: this.getModel().name,\n editable: false,\n nullable: false,\n indexed: true,\n }\n ]);\n // reset privileges\n /**\n * @type {DataConfigurationStrategy|*}\n */\n const dataConfiguration = this.context.getApplication()\n .getConfiguration().getStrategy(DataConfigurationStrategy);\n\n model.privileges.splice(0);\n // get resultPrivileges\n const thisModel = dataConfiguration.model(this.getModel().name);\n\n model.privileges.push.apply(model.privileges, [\n {\n \"mask\": 15,\n \"type\": \"global\"\n },\n {\n \"mask\": 1,\n \"type\": \"global\",\n \"account\": \"Administrators\"\n }\n ]);\n // add extra privileges\n if (Array.isArray(thisModel.resultPrivileges)) {\n model.privileges.push.apply(model.privileges, thisModel.resultPrivileges);\n }\n dataConfiguration.setModelDefinition(model);\n // add entity set\n const builder = this.context.getApplication().getService(ODataModelBuilder);\n builder.addEntitySet(model.name, model.name);\n if (model.hidden) {\n builder.removeEntitySet(model.name);\n }\n // update version\n form.version= model.version;\n await this.context.model('EvaluationDocument').silent().save(form);\n }\n return result;\n } catch (err) {\n TraceUtils.error(`Error while decoding evaluation form ${form.id} content.`);\n TraceUtils.error(err);\n throw new HttpServerError('An error occurred while decoding evaluation form.');\n }\n }\n\n @EdmMapping.func('Results', EdmType.CollectionOf('Object'))\n async getResults() {\n const form = await this.getForm();\n return this.context.model(form.properties.name).where('evaluationEvent').equal(this.id).prepare();\n }\n\n @EdmMapping.func('Tokens', EdmType.CollectionOf('EvaluationAccessToken'))\n async getAccessTokens() {\n return this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.id).prepare();\n }\n\n @EdmMapping.func('FormAttributes', EdmType.CollectionOf('Object'))\n async getFormAttributes() {\n /**\n * @type {DataContext|*}\n */\n const context = this.context;\n const result = [];\n const form = await this.getForm();\n this.setParentLegend(form);\n // get model attributes\n /**\n * @type {DataConfigurationStrategy|*}\n */\n const dataConfiguration = context.getApplication()\n .getConfiguration().getStrategy(DataConfigurationStrategy);\n const dataTypes = dataConfiguration.dataTypes;\n const q = context.model(form.properties.name).asQueryable();\n const selectArguments = [];\n const model = dataConfiguration.model(form.properties.name);\n const attributes = model.fields;\n attributes.forEach(attribute => {\n const key = this.findByKey(form.components, attribute.name);\n if (key) {\n attribute = Object.assign(attribute, {\n name: attribute.name, label: key.label\n });\n attribute.isNumber = false;\n attribute.legend = key.customProperties && key.customProperties.legend;\n if (Object.prototype.hasOwnProperty.call(dataTypes, attribute.type)) {\n attribute.isNumber = dataTypes[attribute.type].type === 'number';\n }\n selectArguments.push(`${attribute.name}`);\n result.push(attribute);\n }\n\n });\n if (selectArguments.length) {\n const responses = await q.select.apply(q, selectArguments).where('evaluationEvent').equal(this.getId()).silent().getAllItems();\n for (let i = 0; i < result.length; i++) {\n const qElement = result[i];\n qElement.responses=[];\n if (qElement.isNumber) {\n // add mean value and standard deviation\n qElement.std = responses.length? math.std(responses.map(x => {\n return x[qElement.name];\n })):0;\n qElement.avg = responses.length? math.mean(responses.map(x => {\n return x[qElement.name];\n })):0;\n } else {\n qElement.responses = responses.map(x => {\n return x[qElement.name];\n });\n }\n }\n }\n return result;\n }\n\n findByKey(array, key) {\n for (let index = 0; index < array.length; index++) {\n const element = array[index];\n if (element.key === key) {\n return element;\n } else {\n if (element.components) {\n const found = this.findByKey(element.components, key);\n if (found) {\n return found;\n }\n }\n }\n }\n }\n\n setParentLegend(component) {\n if (Array.isArray(component.components)) {\n component.components.forEach(item => {\n if (component.legend) {\n item.customProperties = item.customProperties || {};\n item.customProperties.legend = component.legend;\n }\n this.setParentLegend(item);\n });\n }\n }\n\n @EdmMapping.param('data', 'Object', false, true)\n @EdmMapping.action('Evaluate', 'Object')\n async evaluate(data) {\n const token = await EvaluationAccessToken.inspect(this.context, this.context.user.authenticationToken);\n if (token.active === false) {\n throw new HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');\n }\n if (this.id !== token.sub) {\n throw new HttpBadRequestError('Evaluation access token is invalid');\n }\n // get evaluation form\n const form = await this.getForm();\n // get evaluation document\n if (form == null) {\n throw new HttpNotFoundError('Evaluation form cannot be found');\n }\n // get evaluation document\n const evaluationDocument = await this.context.model(EvaluationDocument)\n .where('id').equal(form.properties._id)\n .silent().getItem();\n if (evaluationDocument == null) {\n throw new HttpNotFoundError('Evaluation document cannot be found');\n }\n // assign defaults\n Object.assign(data, {\n evaluationEvent: this.id,\n evaluationDocument: evaluationDocument.id\n });\n // and finally append evaluation\n await this.context.model(evaluationDocument.resultType).on('after.save', (event, callback) => {\n const context = event.model.context;\n context.model(EvaluationAccessToken).where('access_token').equal(context.user && context.user.authenticationToken)\n .silent().getItem().then((token) => {\n if (token == null) {\n throw new HttpTokenExpiredError('Evaluation token is required');\n }\n return context.model(EvaluationAccessToken).silent().save({\n access_token: token.access_token,\n expires: new Date(0), // set epoch date\n used: true\n });\n }).then(() => {\n return callback();\n }).catch((err) => {\n TraceUtils.error('An error occurred while submitting evaluation');\n return callback(err);\n });\n }).silent().save(data);\n return data;\n }\n\n static async generateTokens(context, generateOptions) {\n let items = [];\n if (Array.isArray(generateOptions)) {\n let n = 0;\n let newItems;\n // eslint-disable-next-line no-unused-vars\n for(let itemGenerateOptions of generateOptions) {\n newItems = await EvaluationEvent.generateManyTokens(context, itemGenerateOptions);\n n += newItems.length;\n items.push.apply(items, newItems);\n }\n await context.model('EvaluationAccessToken').silent().save(items);\n return n\n } else {\n items = await EvaluationEvent.generateManyTokens(context, generateOptions);\n await context.model('EvaluationAccessToken').silent().save(items);\n return items.length;\n } \n }\n /**\n * Generates a number of access tokens for the given event \n * @param {DataContext} context\n * @param {{evaluationEvent: number, n: number, expires?: DateTime}} generateOptions\n */\n static async generateManyTokens(context, generateOptions) {\n const n = generateOptions.n;\n Args.check(typeof n === 'number', 'Expected a number greater than zero');\n Args.check(n > 0, 'The number of access tokens must be greater than zero');\n let maximumGenerateTokens = LangUtils.parseInt(context.getConfiguration().getSourceAt('settings/evaluation/maximumGenerateTokens'));\n if (maximumGenerateTokens === 0) {\n maximumGenerateTokens = 1000;\n }\n Args.check(n < maximumGenerateTokens, `The specified number of tokens exceeded the maximum allowed (${maximumGenerateTokens})`);\n const items = [];\n // generate tokens\n for (let index = 0; index < n; index++) {\n items.push({\n evaluationEvent: generateOptions.evaluationEvent,\n expires: generateOptions.expires\n });\n }\n return items;\n }\n}\nmodule.exports = EvaluationEvent;\n"],"file":"evaluation-event-model.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/models/evaluation-event-model.js"],"names":["EvaluationAccessToken","require","math","EvaluationEvent","EdmMapping","entityType","func","EdmType","CollectionOf","param","action","DataObject","constructor","getCurrent","context","token","inspect","user","authenticationToken","active","HttpTokenExpiredError","evaluationEvent","model","where","equal","sub","and","silent","getTypedItem","HttpNotFoundError","currentDate","Date","setHours","startDate","endDate","additionalType","event","expand","name","options","$expand","courseClass","courseClassInstructor","instructor","course","displayCode","title","year","alternateName","period","familyName","givenName","getAdditionalObject","getForm","form","property","getItem","service","getApplication","getService","PrivateContentService","formPath","Promise","resolve","reject","resolvePhysicalPath","err","physicalPath","readFileAsync","util","promisify","fs","readFile","content","buffer","Buffer","from","result","JSON","parse","toString","properties","Object","assign","resultType","_id","id","_event","shouldUpgrade","version","inspector","JsonFormInspector","source","view","hidden","fields","push","apply","type","getModel","editable","nullable","indexed","dataConfiguration","getConfiguration","getStrategy","DataConfigurationStrategy","privileges","splice","thisModel","Array","isArray","resultPrivileges","setModelDefinition","builder","ODataModelBuilder","addEntitySet","removeEntitySet","save","TraceUtils","error","HttpServerError","getResults","prepare","getAccessTokens","getFormAttributes","setParentLegend","dataTypes","q","asQueryable","selectArguments","attributes","forEach","attribute","key","findByKey","components","label","isNumber","legend","customProperties","prototype","hasOwnProperty","call","std","avg","responses","showResults","length","select","getId","getAllItems","i","qElement","map","x","mean","found","eventStatusesResults","getSourceAt","groupsAllowed","userName","interactiveUser","groups","some","r","indexOf","findIndex","eventStatus","array","index","element","component","item","evaluate","data","HttpBadRequestError","evaluationDocument","EvaluationDocument","on","callback","then","access_token","expires","used","catch","generateTokens","generateOptions","items","n","newItems","itemGenerateOptions","generateManyTokens","Args","check","maximumGenerateTokens","LangUtils","parseInt","module","exports"],"mappings":"aAAA;;;;;;AAMA;;;;;;;;AAQA;AACA;AACA;;;AAGA;AACA;AACA;AACA,wD,s2BAJA,MAAMA,qBAAqB,GAAGC,OAAO,CAAC,iCAAD,CAArC;AAKA,MAAMC,IAAI,GAAGD,OAAO,CAAC,QAAD,CAApB;;AAEA;AACA;AACA,G;;AAEME,e,WAD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A,KAAK,CAAC5F,IAAN,CAAW;AACP3E,QAAAA,eAAe,EAAEsK,eAAe,CAACtK,eAD1B;AAEPkK,QAAAA,OAAO,EAAEI,eAAe,CAACJ,OAFlB,EAAX;;AAIH;AACD,WAAOK,KAAP;AACH,GAnYoC,C;;AAqYzCU,MAAM,CAACC,OAAP,GAAiBpM,eAAjB","sourcesContent":["import { HttpNotFoundError, HttpTokenExpiredError, HttpServerError,\n TraceUtils, \n HttpBadRequestError,\n Args,\n LangUtils} from '@themost/common';\n\nimport {\n DataConfigurationStrategy,\n DataContext,\n DataObject,\n EdmMapping,\n EdmType,\n ODataModelBuilder\n} from '@themost/data';\nimport { HttpContext } from '@themost/web';\nimport { JsonFormInspector } from '@themost/form-inspector';\nimport EvaluationDocument from './evaluation-document-model';\n\nconst EvaluationAccessToken = require('./evaluation-access-token-model');\nimport {lt} from 'semver';\nimport util from \"util\";\nimport fs from \"fs\";\nimport moment from \"moment\";\nconst math = require('mathjs');\n\n/**\n * @class\n */\n@EdmMapping.entityType('EvaluationEvent')\nclass EvaluationEvent extends DataObject {\n /**\n * @constructor\n */\n constructor() {\n super();\n }\n\n /**\n * Get current evaluation based on the evaluation key contained in Evaluation-Key HTTP header\n * @param {HttpContext} context\n */\n @EdmMapping.func('Current', 'EvaluationEvent')\n static async getCurrent(context) {\n // get evaluation key\n const token = await EvaluationAccessToken.inspect(context, context.user && context.user.authenticationToken);\n if (token.active === false) {\n throw new HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');\n }\n // get evaluation event\n // get current date\n let evaluationEvent = await context.model('EvaluationEvent')\n .where('id').equal(token.sub)\n .and('eventStatus/alternateName').equal('EventOpened')\n .silent().getTypedItem();\n if (evaluationEvent == null) {\n throw new HttpNotFoundError('The specified evaluation cannot be found');\n }\n // check dates\n const currentDate = new Date().setHours(0,0,0,0);\n const startDate = evaluationEvent.startDate.setHours(0,0,0,0);\n const endDate = evaluationEvent.endDate.setHours(0,0,0,0);\n if (startDate>currentDate || endDate<currentDate) {\n throw new HttpNotFoundError('The specified evaluation cannot be found, it is expired or not started.');\n }\n if (evaluationEvent.additionalType !== 'EvaluationEvent') {\n if (evaluationEvent.additionalType === 'ClassInstructorEvaluationEvent') {\n const event = await context.model('ClassInstructorEvaluationEvent')\n .where('id').equal(token.sub)\n .expand({\n name: 'courseClassInstructor',\n options: {\n $expand: 'courseClass($expand=course,year,period),instructor'\n }\n })\n .silent().getTypedItem();\n const courseClass= event.courseClassInstructor.courseClass;\n const instructor = event.courseClassInstructor.instructor;\n evaluationEvent.courseClass = `${courseClass.course.displayCode}-${courseClass.title} (${courseClass.year.alternateName}-${courseClass.period.name}) `;\n evaluationEvent.instructor = `${instructor.familyName} ${instructor.givenName}`;\n } else {\n evaluationEvent = await evaluationEvent.silent().getAdditionalObject();\n }\n }\n return evaluationEvent;\n }\n\n @EdmMapping.func('form', 'Object')\n async getForm() {\n const form = await this.property('evaluationDocument').getItem();\n const service = this.context.getApplication().getService(function PrivateContentService(){});\n /**\n * @type {string}\n */\n const formPath = await new Promise((resolve, reject) => {\n service.resolvePhysicalPath(this.context, form, (err, physicalPath) => {\n if (err) {\n return reject(err);\n }\n return resolve(physicalPath);\n })\n });\n const readFileAsync = util.promisify(fs.readFile);\n let content = await readFileAsync(formPath);\n if (content == null) {\n throw new HttpNotFoundError('Evaluation form cannot be found');\n }\n let buffer = Buffer.from(content,'base64');\n let result;\n result = JSON.parse(buffer.toString('utf8'));\n\n try {\n result.properties = result.properties || {};\n Object.assign(result.properties, {\n name: form.resultType,\n _id: form.id,\n _event: this.id\n });\n // post-processing\n let shouldUpgrade = true;\n let model = this.context.model(form.resultType);\n if (model != null) {\n shouldUpgrade = lt(model.version, form.version)\n }\n if (shouldUpgrade) {\n // load for inspector\n const inspector = new JsonFormInspector();\n model = inspector.inspect(result);\n // post processing steps\n Object.assign(model, {\n source: form.resultType, // add source from evaluation document e.g. Evaluation1\n view: form.resultType, // add view from evaluation document e.g. Evaluation1\n version: model.version ,// set version (follow updates)\n hidden: true\n });\n // add evaluation event and evaluation document associations\n // for further processing of evaluation results\n model.fields.push.apply(model.fields, [\n {\n name: 'evaluationEvent',\n type: this.getModel().name,\n editable: false,\n nullable: false,\n indexed: true,\n }\n ]);\n // reset privileges\n /**\n * @type {DataConfigurationStrategy|*}\n */\n const dataConfiguration = this.context.getApplication()\n .getConfiguration().getStrategy(DataConfigurationStrategy);\n\n model.privileges.splice(0);\n // get resultPrivileges\n const thisModel = dataConfiguration.model(this.getModel().name);\n\n model.privileges.push.apply(model.privileges, [\n {\n \"mask\": 15,\n \"type\": \"global\"\n },\n {\n \"mask\": 1,\n \"type\": \"global\",\n \"account\": \"Administrators\"\n }\n ]);\n // add extra privileges\n if (Array.isArray(thisModel.resultPrivileges)) {\n model.privileges.push.apply(model.privileges, thisModel.resultPrivileges);\n }\n dataConfiguration.setModelDefinition(model);\n // add entity set\n const builder = this.context.getApplication().getService(ODataModelBuilder);\n builder.addEntitySet(model.name, model.name);\n if (model.hidden) {\n builder.removeEntitySet(model.name);\n }\n // update version\n form.version= model.version;\n await this.context.model('EvaluationDocument').silent().save(form);\n }\n return result;\n } catch (err) {\n TraceUtils.error(`Error while decoding evaluation form ${form.id} content.`);\n TraceUtils.error(err);\n throw new HttpServerError('An error occurred while decoding evaluation form.');\n }\n }\n\n @EdmMapping.func('Results', EdmType.CollectionOf('Object'))\n async getResults() {\n const form = await this.getForm();\n return this.context.model(form.properties.name).where('evaluationEvent').equal(this.id).prepare();\n }\n\n @EdmMapping.func('Tokens', EdmType.CollectionOf('EvaluationAccessToken'))\n async getAccessTokens() {\n return this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.id).prepare();\n }\n\n @EdmMapping.func('FormAttributes', EdmType.CollectionOf('Object'))\n async getFormAttributes() {\n /**\n * @type {DataContext|*}\n */\n const context = this.context;\n const result = [];\n const form = await this.getForm();\n this.setParentLegend(form);\n // get model attributes\n /**\n * @type {DataConfigurationStrategy|*}\n */\n const dataConfiguration = context.getApplication()\n .getConfiguration().getStrategy(DataConfigurationStrategy);\n const dataTypes = dataConfiguration.dataTypes;\n const q = context.model(form.properties.name).asQueryable();\n const selectArguments = [];\n const model = dataConfiguration.model(form.properties.name);\n const attributes = model.fields;\n attributes.forEach(attribute => {\n const key = this.findByKey(form.components, attribute.name);\n if (key) {\n attribute = Object.assign(attribute, {\n name: attribute.name, label: key.label\n });\n attribute.isNumber = false;\n attribute.legend = key.customProperties && key.customProperties.legend;\n if (Object.prototype.hasOwnProperty.call(dataTypes, attribute.type)) {\n attribute.isNumber = dataTypes[attribute.type].type === 'number';\n }\n selectArguments.push(`${attribute.name}`);\n // clear std,avg and responses from model attribute\n attribute.std = 0;\n attribute.avg = 0;\n delete attribute.responses;\n result.push(attribute);\n }\n\n });\n const showResults = await this.showResults(context);\n if (selectArguments.length && showResults === true) {\n const responses = await q.select.apply(q, selectArguments).where('evaluationEvent').equal(this.getId()).silent().getAllItems();\n for (let i = 0; i < result.length; i++) {\n const qElement = result[i];\n qElement.responses=[];\n if (qElement.isNumber) {\n // add mean value and standard deviation\n qElement.std = responses.length? math.std(responses.map(x => {\n return x[qElement.name];\n })):0;\n qElement.avg = responses.length? math.mean(responses.map(x => {\n return x[qElement.name];\n })):0;\n } else {\n qElement.responses = responses.map(x => {\n return x[qElement.name];\n });\n }\n }\n }\n return result;\n }\n\n async showResults (context) {\n\n // this is a custom way to get permissions based on eventStatus and user groups\n let showResults = true;\n let found = false;\n const eventStatusesResults = context.getConfiguration().getSourceAt('settings/evaluation/results/statuses') || [];\n const groupsAllowed = context.getConfiguration().getSourceAt('settings/evaluation/results/groupsAllowed') || [];\n if (eventStatusesResults.length > 0) {\n // check if eventStatus is allowed\n if (groupsAllowed.length > 0) {\n // but first check if user belongs to allowed groups\n const userName = context.interactiveUser ? context.interactiveUser.name : context.user.name;\n const user = await context.model('User').where('name').equal(userName).expand('groups').getItem();\n found = user.groups.some(r => groupsAllowed.indexOf(r.name) >= 0);\n }\n if (!found) {\n const evaluationEvent = await context.model('EvaluationEvent').where('id').equal(this.getId())\n .select('id', 'eventStatus/alternateName as eventStatus')\n .getItem();\n if (evaluationEvent == null) {\n throw new HttpNotFoundError('The specified evaluation cannot be found');\n }\n showResults = eventStatusesResults.findIndex(x => {\n return x === evaluationEvent.eventStatus;\n }) >= 0;\n }\n }\n return showResults;\n }\n\n findByKey(array, key) {\n for (let index = 0; index < array.length; index++) {\n const element = array[index];\n if (element.key === key) {\n return element;\n } else {\n if (element.components) {\n const found = this.findByKey(element.components, key);\n if (found) {\n return found;\n }\n }\n }\n }\n }\n\n setParentLegend(component) {\n if (Array.isArray(component.components)) {\n component.components.forEach(item => {\n if (component.legend) {\n item.customProperties = item.customProperties || {};\n item.customProperties.legend = component.legend;\n }\n this.setParentLegend(item);\n });\n }\n }\n\n @EdmMapping.param('data', 'Object', false, true)\n @EdmMapping.action('Evaluate', 'Object')\n async evaluate(data) {\n const token = await EvaluationAccessToken.inspect(this.context, this.context.user.authenticationToken);\n if (token.active === false) {\n throw new HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');\n }\n if (this.id !== token.sub) {\n throw new HttpBadRequestError('Evaluation access token is invalid');\n }\n // get evaluation form\n const form = await this.getForm();\n // get evaluation document\n if (form == null) {\n throw new HttpNotFoundError('Evaluation form cannot be found');\n }\n // get evaluation document\n const evaluationDocument = await this.context.model(EvaluationDocument)\n .where('id').equal(form.properties._id)\n .silent().getItem();\n if (evaluationDocument == null) {\n throw new HttpNotFoundError('Evaluation document cannot be found');\n }\n // assign defaults\n Object.assign(data, {\n evaluationEvent: this.id,\n evaluationDocument: evaluationDocument.id\n });\n // and finally append evaluation\n await this.context.model(evaluationDocument.resultType).on('after.save', (event, callback) => {\n const context = event.model.context;\n context.model(EvaluationAccessToken).where('access_token').equal(context.user && context.user.authenticationToken)\n .silent().getItem().then((token) => {\n if (token == null) {\n throw new HttpTokenExpiredError('Evaluation token is required');\n }\n return context.model(EvaluationAccessToken).silent().save({\n access_token: token.access_token,\n expires: new Date(0), // set epoch date\n used: true\n });\n }).then(() => {\n return callback();\n }).catch((err) => {\n TraceUtils.error('An error occurred while submitting evaluation');\n return callback(err);\n });\n }).silent().save(data);\n return data;\n }\n\n static async generateTokens(context, generateOptions) {\n let items = [];\n if (Array.isArray(generateOptions)) {\n let n = 0;\n let newItems;\n // eslint-disable-next-line no-unused-vars\n for(let itemGenerateOptions of generateOptions) {\n newItems = await EvaluationEvent.generateManyTokens(context, itemGenerateOptions);\n n += newItems.length;\n items.push.apply(items, newItems);\n }\n await context.model('EvaluationAccessToken').silent().save(items);\n return n\n } else {\n items = await EvaluationEvent.generateManyTokens(context, generateOptions);\n await context.model('EvaluationAccessToken').silent().save(items);\n return items.length;\n } \n }\n /**\n * Generates a number of access tokens for the given event \n * @param {DataContext} context\n * @param {{evaluationEvent: number, n: number, expires?: DateTime}} generateOptions\n */\n static async generateManyTokens(context, generateOptions) {\n const n = generateOptions.n;\n Args.check(typeof n === 'number', 'Expected a number greater than zero');\n Args.check(n > 0, 'The number of access tokens must be greater than zero');\n let maximumGenerateTokens = LangUtils.parseInt(context.getConfiguration().getSourceAt('settings/evaluation/maximumGenerateTokens'));\n if (maximumGenerateTokens === 0) {\n maximumGenerateTokens = 1000;\n }\n Args.check(n < maximumGenerateTokens, `The specified number of tokens exceeded the maximum allowed (${maximumGenerateTokens})`);\n const items = [];\n // generate tokens\n for (let index = 0; index < n; index++) {\n items.push({\n evaluationEvent: generateOptions.evaluationEvent,\n expires: generateOptions.expires\n });\n }\n return items;\n }\n}\nmodule.exports = EvaluationEvent;\n"],"file":"evaluation-event-model.js"}
|
package/package.json
CHANGED
|
@@ -28,11 +28,14 @@ class AccessToken extends DataObject {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
isExpired() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (this.expires == null) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
// check only date parts
|
|
35
|
+
const currentDate = new Date().setHours(0, 0, 0, 0);
|
|
36
|
+
const expires = this.expires.setHours(0, 0, 0, 0);
|
|
37
|
+
return (expires < currentDate);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
module.exports = AccessToken;
|
|
41
|
+
module.exports = AccessToken;
|
|
@@ -2,6 +2,7 @@ import {EdmMapping, EdmType} from '@themost/data';
|
|
|
2
2
|
import EvaluationEvent from "./evaluation-event-model";
|
|
3
3
|
import {DataError, TraceUtils, DataNotFoundError} from "@themost/common";
|
|
4
4
|
import {getMailer} from "@themost/mailer";
|
|
5
|
+
import moment from "moment";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @class
|
|
@@ -119,8 +120,11 @@ class ClassInstructorEvaluationEvent extends EvaluationEvent {
|
|
|
119
120
|
@EdmMapping.action('SendEvaluationTokens', 'SendInstructorTokenAction')
|
|
120
121
|
async sendEvaluationTokens() {
|
|
121
122
|
const context = this.context;
|
|
122
|
-
// get event
|
|
123
|
+
// get event and check if event endDate has passed
|
|
124
|
+
// get current date
|
|
125
|
+
const currentDate = moment(new Date()).startOf('day').toDate(); // get only date format
|
|
123
126
|
const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(this.getId())
|
|
127
|
+
.and('date(endDate)').greaterOrEqual(currentDate)
|
|
124
128
|
.expand({
|
|
125
129
|
name: 'courseClassInstructor',
|
|
126
130
|
options: {
|
|
@@ -225,6 +229,24 @@ class ClassInstructorEvaluationEvent extends EvaluationEvent {
|
|
|
225
229
|
const succeeded = [];
|
|
226
230
|
const failed = [];
|
|
227
231
|
try {
|
|
232
|
+
// format mail subject expected params ${course}, ${instructor}
|
|
233
|
+
const exp = new RegExp('\\$\\{\\w+\\}+','ig');
|
|
234
|
+
let subject = mailTemplate.subject;
|
|
235
|
+
const params = subject.match(exp);
|
|
236
|
+
if (params.length>0) {
|
|
237
|
+
// parse only custom parameters ${instructor},${course}
|
|
238
|
+
params.forEach(param => {
|
|
239
|
+
if (param === '${instructor}') {
|
|
240
|
+
// get instructor full name
|
|
241
|
+
subject = subject.replace(param, eventInstructor? `${eventInstructor.familyName} ${eventInstructor.givenName}` : '');
|
|
242
|
+
} else if (param === '${course}') {
|
|
243
|
+
// get courseClass code and title
|
|
244
|
+
subject = subject.replace(param, courseClass.course ? `${courseClass.course.displayCode} ${courseClass.title}` : '');
|
|
245
|
+
} else {
|
|
246
|
+
subject = subject.replace(param, '');
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
228
250
|
// use an async function to send emails
|
|
229
251
|
await (async () => {
|
|
230
252
|
for (const student of students) {
|
|
@@ -236,7 +258,7 @@ class ClassInstructorEvaluationEvent extends EvaluationEvent {
|
|
|
236
258
|
await new Promise(resolve => {
|
|
237
259
|
mailer
|
|
238
260
|
.template(mailTemplate.template)
|
|
239
|
-
.subject(
|
|
261
|
+
.subject(subject)
|
|
240
262
|
.to(student.email)
|
|
241
263
|
.send(Object.assign(event, {
|
|
242
264
|
access_token
|
|
@@ -48,17 +48,20 @@ class EvaluationEvent extends DataObject {
|
|
|
48
48
|
}
|
|
49
49
|
// get evaluation event
|
|
50
50
|
// get current date
|
|
51
|
-
const startDate = new Date(); // get current date with time
|
|
52
|
-
const endDate = moment(new Date()).startOf('day').toDate(); // get only date format
|
|
53
51
|
let evaluationEvent = await context.model('EvaluationEvent')
|
|
54
52
|
.where('id').equal(token.sub)
|
|
55
|
-
.and('date(startDate)').lowerOrEqual(startDate)
|
|
56
|
-
.and('date(endDate)').greaterOrEqual(endDate)
|
|
57
53
|
.and('eventStatus/alternateName').equal('EventOpened')
|
|
58
54
|
.silent().getTypedItem();
|
|
59
55
|
if (evaluationEvent == null) {
|
|
60
56
|
throw new HttpNotFoundError('The specified evaluation cannot be found');
|
|
61
57
|
}
|
|
58
|
+
// check dates
|
|
59
|
+
const currentDate = new Date().setHours(0,0,0,0);
|
|
60
|
+
const startDate = evaluationEvent.startDate.setHours(0,0,0,0);
|
|
61
|
+
const endDate = evaluationEvent.endDate.setHours(0,0,0,0);
|
|
62
|
+
if (startDate>currentDate || endDate<currentDate) {
|
|
63
|
+
throw new HttpNotFoundError('The specified evaluation cannot be found, it is expired or not started.');
|
|
64
|
+
}
|
|
62
65
|
if (evaluationEvent.additionalType !== 'EvaluationEvent') {
|
|
63
66
|
if (evaluationEvent.additionalType === 'ClassInstructorEvaluationEvent') {
|
|
64
67
|
const event = await context.model('ClassInstructorEvaluationEvent')
|
|
@@ -228,11 +231,16 @@ class EvaluationEvent extends DataObject {
|
|
|
228
231
|
attribute.isNumber = dataTypes[attribute.type].type === 'number';
|
|
229
232
|
}
|
|
230
233
|
selectArguments.push(`${attribute.name}`);
|
|
234
|
+
// clear std,avg and responses from model attribute
|
|
235
|
+
attribute.std = 0;
|
|
236
|
+
attribute.avg = 0;
|
|
237
|
+
delete attribute.responses;
|
|
231
238
|
result.push(attribute);
|
|
232
239
|
}
|
|
233
240
|
|
|
234
241
|
});
|
|
235
|
-
|
|
242
|
+
const showResults = await this.showResults(context);
|
|
243
|
+
if (selectArguments.length && showResults === true) {
|
|
236
244
|
const responses = await q.select.apply(q, selectArguments).where('evaluationEvent').equal(this.getId()).silent().getAllItems();
|
|
237
245
|
for (let i = 0; i < result.length; i++) {
|
|
238
246
|
const qElement = result[i];
|
|
@@ -255,6 +263,36 @@ class EvaluationEvent extends DataObject {
|
|
|
255
263
|
return result;
|
|
256
264
|
}
|
|
257
265
|
|
|
266
|
+
async showResults (context) {
|
|
267
|
+
|
|
268
|
+
// this is a custom way to get permissions based on eventStatus and user groups
|
|
269
|
+
let showResults = true;
|
|
270
|
+
let found = false;
|
|
271
|
+
const eventStatusesResults = context.getConfiguration().getSourceAt('settings/evaluation/results/statuses') || [];
|
|
272
|
+
const groupsAllowed = context.getConfiguration().getSourceAt('settings/evaluation/results/groupsAllowed') || [];
|
|
273
|
+
if (eventStatusesResults.length > 0) {
|
|
274
|
+
// check if eventStatus is allowed
|
|
275
|
+
if (groupsAllowed.length > 0) {
|
|
276
|
+
// but first check if user belongs to allowed groups
|
|
277
|
+
const userName = context.interactiveUser ? context.interactiveUser.name : context.user.name;
|
|
278
|
+
const user = await context.model('User').where('name').equal(userName).expand('groups').getItem();
|
|
279
|
+
found = user.groups.some(r => groupsAllowed.indexOf(r.name) >= 0);
|
|
280
|
+
}
|
|
281
|
+
if (!found) {
|
|
282
|
+
const evaluationEvent = await context.model('EvaluationEvent').where('id').equal(this.getId())
|
|
283
|
+
.select('id', 'eventStatus/alternateName as eventStatus')
|
|
284
|
+
.getItem();
|
|
285
|
+
if (evaluationEvent == null) {
|
|
286
|
+
throw new HttpNotFoundError('The specified evaluation cannot be found');
|
|
287
|
+
}
|
|
288
|
+
showResults = eventStatusesResults.findIndex(x => {
|
|
289
|
+
return x === evaluationEvent.eventStatus;
|
|
290
|
+
}) >= 0;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return showResults;
|
|
294
|
+
}
|
|
295
|
+
|
|
258
296
|
findByKey(array, key) {
|
|
259
297
|
for (let index = 0; index < array.length; index++) {
|
|
260
298
|
const element = array[index];
|