@universis/evaluations 1.0.6 → 1.0.9
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/config/models/ClassInstructorEvaluationEvent.json +33 -15
- package/dist/config/models/EvaluationAccessToken.json +15 -0
- package/dist/config/models/EvaluationDocument.json +0 -8
- package/dist/config/models/GenerateInstructorTokenAction.json +19 -2
- package/dist/config/models/SendInstructorTokenAction.json +52 -0
- package/dist/config/models/SendTokenAction.json +45 -0
- package/dist/models/class-instructor-evaluation-event-model.js +281 -68
- package/dist/models/class-instructor-evaluation-event-model.js.map +1 -1
- package/dist/models/evaluation-event-model.js +19 -3
- package/dist/models/evaluation-event-model.js.map +1 -1
- package/package.json +1 -1
- package/src/config/models/ClassInstructorEvaluationEvent.json +33 -15
- package/src/config/models/EvaluationAccessToken.json +15 -0
- package/src/config/models/EvaluationDocument.json +0 -8
- package/src/config/models/GenerateInstructorTokenAction.json +19 -2
- package/src/config/models/SendInstructorTokenAction.json +52 -0
- package/src/config/models/SendTokenAction.json +45 -0
- package/src/models/class-instructor-evaluation-event-model.js +216 -3
- package/src/models/evaluation-event-model.js +20 -4
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"sealed": false,
|
|
8
8
|
"inherits": "EvaluationEvent",
|
|
9
9
|
"classPath": "./models/class-instructor-evaluation-event-model",
|
|
10
|
-
"version": "1.
|
|
10
|
+
"version": "1.2",
|
|
11
11
|
"fields": [
|
|
12
12
|
{
|
|
13
13
|
"@id": "http://schema.org/courseClassInstructor",
|
|
@@ -54,7 +54,21 @@
|
|
|
54
54
|
"many": true,
|
|
55
55
|
"mapping": {
|
|
56
56
|
"parentModel": "ClassInstructorEvaluationEvent",
|
|
57
|
-
"childModel": "
|
|
57
|
+
"childModel": "GenerateInstructorTokenAction",
|
|
58
|
+
"parentField": "id",
|
|
59
|
+
"childField": "event",
|
|
60
|
+
"cascade": "delete",
|
|
61
|
+
"associationType": "association"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "sendActions",
|
|
66
|
+
"title": "Send token actions",
|
|
67
|
+
"type": "SendTokenAction",
|
|
68
|
+
"many": true,
|
|
69
|
+
"mapping": {
|
|
70
|
+
"parentModel": "ClassInstructorEvaluationEvent",
|
|
71
|
+
"childModel": "SendInstructorTokenAction",
|
|
58
72
|
"parentField": "id",
|
|
59
73
|
"childField": "event",
|
|
60
74
|
"cascade": "delete",
|
|
@@ -83,28 +97,32 @@
|
|
|
83
97
|
"type": "global"
|
|
84
98
|
},
|
|
85
99
|
{
|
|
86
|
-
"mask":
|
|
100
|
+
"mask": 31,
|
|
87
101
|
"type": "global",
|
|
88
|
-
"account": "
|
|
102
|
+
"account": "Administrators"
|
|
89
103
|
},
|
|
90
104
|
{
|
|
91
|
-
"mask":
|
|
105
|
+
"mask": 17,
|
|
106
|
+
"type": "self",
|
|
107
|
+
"account": "Registrar",
|
|
108
|
+
"filter": "courseClassInstructor/courseClass/course/department eq departments()"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"mask": 17,
|
|
92
112
|
"type": "global",
|
|
93
|
-
"account": "
|
|
94
|
-
}
|
|
95
|
-
],
|
|
96
|
-
"resultPrivileges": [
|
|
113
|
+
"account": "QualityAssuranceUnit"
|
|
114
|
+
},
|
|
97
115
|
{
|
|
98
|
-
"mask":
|
|
116
|
+
"mask": 17,
|
|
99
117
|
"type": "self",
|
|
100
|
-
"account": "
|
|
101
|
-
"filter": "
|
|
118
|
+
"account": "QualityAssuranceDepartment",
|
|
119
|
+
"filter": "courseClassInstructor/courseClass/course/department eq departments()"
|
|
102
120
|
},
|
|
103
121
|
{
|
|
104
|
-
"mask":
|
|
122
|
+
"mask": 17,
|
|
105
123
|
"type": "self",
|
|
106
|
-
"account": "
|
|
107
|
-
"filter": "
|
|
124
|
+
"account": "Instructors",
|
|
125
|
+
"filter": "courseClassInstructor/instructor eq instructor()"
|
|
108
126
|
}
|
|
109
127
|
]
|
|
110
128
|
}
|
|
@@ -106,6 +106,21 @@
|
|
|
106
106
|
"mask": 15,
|
|
107
107
|
"type": "global",
|
|
108
108
|
"account": "Administrators"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"mask": 1,
|
|
112
|
+
"type": "global",
|
|
113
|
+
"account": "QualityAssuranceDepartment"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"mask": 1,
|
|
117
|
+
"type": "global",
|
|
118
|
+
"account": "QualityAssuranceUnit"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"mask": 1,
|
|
122
|
+
"type": "global",
|
|
123
|
+
"account": "Registrar"
|
|
109
124
|
}
|
|
110
125
|
],
|
|
111
126
|
"eventListeners": [
|
|
@@ -28,13 +28,30 @@
|
|
|
28
28
|
],
|
|
29
29
|
"privileges": [
|
|
30
30
|
{
|
|
31
|
-
"mask":
|
|
31
|
+
"mask": 31,
|
|
32
32
|
"type": "global"
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
|
-
"mask":
|
|
35
|
+
"mask": 31,
|
|
36
36
|
"type": "global",
|
|
37
37
|
"account": "Administrators"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"mask": 17,
|
|
41
|
+
"type": "self",
|
|
42
|
+
"account": "Registrar",
|
|
43
|
+
"filter": "event/courseClassInstructor/courseClass/course/department eq departments()"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"mask": 17,
|
|
47
|
+
"type": "global",
|
|
48
|
+
"account": "QualityAssuranceUnit"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"mask": 17,
|
|
52
|
+
"type": "self",
|
|
53
|
+
"account": "QualityAssuranceDepartment",
|
|
54
|
+
"filter": "event/courseClassInstructor/courseClass/course/department eq departments()"
|
|
38
55
|
}
|
|
39
56
|
]
|
|
40
57
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
|
|
3
|
+
"@id": "http://schema.org/SendInstructorTokenAction",
|
|
4
|
+
"name": "SendInstructorTokenAction",
|
|
5
|
+
"description": "The act of organizing tasks/objects/events by associating resources to it.",
|
|
6
|
+
"title": "SendInstructorTokenAction",
|
|
7
|
+
"abstract": false,
|
|
8
|
+
"sealed": false,
|
|
9
|
+
"inherits": "SendTokenAction",
|
|
10
|
+
"version": "1.1",
|
|
11
|
+
"fields": [
|
|
12
|
+
{
|
|
13
|
+
"name": "event",
|
|
14
|
+
"title": "Γεγονός αξιολόγησης",
|
|
15
|
+
"type": "ClassInstructorEvaluationEvent",
|
|
16
|
+
"nullable": false
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "numberOfStudents",
|
|
20
|
+
"description": "Σύνολο φοιτητών",
|
|
21
|
+
"type": "Integer"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"privileges": [
|
|
25
|
+
{
|
|
26
|
+
"mask": 15,
|
|
27
|
+
"type": "global"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"mask": 15,
|
|
31
|
+
"type": "global",
|
|
32
|
+
"account": "Administrators"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"mask": 1,
|
|
36
|
+
"type": "self",
|
|
37
|
+
"account": "Registrar",
|
|
38
|
+
"filter": "event/courseClassInstructor/courseClass/course/department eq departments()"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"mask": 1,
|
|
42
|
+
"type": "global",
|
|
43
|
+
"account": "QualityAssuranceUnit"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"mask": 1,
|
|
47
|
+
"type": "self",
|
|
48
|
+
"account": "QualityAssuranceDepartment",
|
|
49
|
+
"filter": "event/courseClassInstructor/courseClass/course/department eq departments()"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
|
|
3
|
+
"@id": "http://schema.org/SendTokenAction",
|
|
4
|
+
"name": "SendTokenAction",
|
|
5
|
+
"description": "The act of organizing tasks/objects/events by associating resources to it.",
|
|
6
|
+
"title": "SendTokenAction",
|
|
7
|
+
"abstract": false,
|
|
8
|
+
"sealed": false,
|
|
9
|
+
"inherits": "Action",
|
|
10
|
+
"version": "1.0",
|
|
11
|
+
"fields": [
|
|
12
|
+
{
|
|
13
|
+
"name": "event",
|
|
14
|
+
"title": "Γεγονός αξιολόγησης",
|
|
15
|
+
"type": "EvaluationEvent",
|
|
16
|
+
"nullable": false
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "total",
|
|
20
|
+
"description": "Σύνολο tokens προς αποστολή",
|
|
21
|
+
"type": "Integer"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "sent",
|
|
25
|
+
"description": "Σύνολο tokens που στάλθηκαν επιτυχώς",
|
|
26
|
+
"type": "Integer"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "failed",
|
|
30
|
+
"description": "Σύνολο tokens των οποίων τη αποστολή απέτυχε",
|
|
31
|
+
"type": "Integer"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"privileges": [
|
|
35
|
+
{
|
|
36
|
+
"mask": 15,
|
|
37
|
+
"type": "global"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"mask": 15,
|
|
41
|
+
"type": "global",
|
|
42
|
+
"account": "Administrators"
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";var _data = require("@themost/data");
|
|
2
2
|
var _evaluationEventModel = _interopRequireDefault(require("./evaluation-event-model"));
|
|
3
|
-
var _common = require("@themost/common");
|
|
3
|
+
var _common = require("@themost/common");
|
|
4
|
+
var _mailer = require("@themost/mailer");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;}
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @class
|
|
@@ -14,83 +15,295 @@ ClassInstructorEvaluationEvent = (_dec = _data.EdmMapping.entityType('ClassInstr
|
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
_data.EdmMapping.action('GenerateEvaluationTokens', 'GenerateInstructorTokenAction'),
|
|
18
|
+
_data.EdmMapping.action('GenerateEvaluationTokens', 'GenerateInstructorTokenAction'), _dec3 =
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
_data.EdmMapping.func('TokenInfo', _data.EdmType.CollectionOf('Object')), _dec4 =
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
_data.EdmMapping.action('SendEvaluationTokens', 'SendInstructorTokenAction'), _dec(_class = (_class2 = class ClassInstructorEvaluationEvent extends _evaluationEventModel.default {/**
|
|
18
120
|
* @constructor
|
|
19
|
-
*/constructor() {super();}async generateEvaluationTokens() {const context = this.context;
|
|
20
|
-
const
|
|
21
|
-
event
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
121
|
+
*/constructor() {super();}async generateEvaluationTokens() {const context = this.context;const action = { event: this.id, numberOfStudents: 0, total: 0, actionStatus: { alternateName: 'PotentialActionStatus' } }; // get courseClass instructor
|
|
122
|
+
const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(this.id).expand({ name: 'courseClassInstructor', options: { '$expand': 'courseClass' } }).getItem();if (event) {//check if a GenerateInstructorTokenAction exists
|
|
123
|
+
const prevAction = await context.model('GenerateInstructorTokenAction').where('event').equal(this.id).and('actionStatus/alternateName').notEqual('FailedActionStatus').silent().getItem();if (prevAction) {throw new Error('A previous action for generating evaluation tokens has been found.');}const courseClass = event.courseClassInstructor && event.courseClassInstructor.courseClass;const eventInstructor = event.courseClassInstructor && event.courseClassInstructor.instructor; // get class sections
|
|
124
|
+
const sections = await context.model('CourseClassSection').where('courseClass').equal(courseClass.id).getItems(); // check if course class has sections
|
|
125
|
+
if (sections && sections.length > 0 && courseClass.mustRegisterSection !== 0) {// get only number of students registered at specific section
|
|
126
|
+
const instructorSections = await context.model('CourseClassSectionInstructor').where('courseClass').equal(courseClass.id).and('instructor').equal(eventInstructor).select('section/section as sectionId').silent().getItems();if (instructorSections && instructorSections.length === 0) {action.actionStatus.alternateName = 'FailedActionStatus';action.description = 'Instructor is not related with any of sections';return await context.model('GenerateInstructorTokenAction').save(action);} else {const sectionIds = instructorSections.map((section) => {return section.sectionId;}); // get number of students for specific course class sections
|
|
127
|
+
action.numberOfStudents = await context.model('StudentCourseClass').where('courseClass').equal(courseClass.id).and('section').in(sectionIds).silent().count();}} else {action.numberOfStudents = await context.model('StudentCourseClass').where('courseClass').equal(courseClass.id).silent().count();} // save action and then generateTokens
|
|
128
|
+
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
|
+
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
|
+
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
|
+
const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(this.getId()).expand({ name: 'courseClassInstructor', options: { '$expand': 'courseClass($expand=course), instructor' // expand course and instructor so their attributes are available in the mail template
|
|
133
|
+
} }, { name: 'actions', options: { '$expand': 'actionStatus' } }).
|
|
134
|
+
|
|
135
|
+
|
|
29
136
|
getItem();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
137
|
+
// validate event
|
|
138
|
+
if (event == null) {
|
|
139
|
+
throw new _common.DataNotFoundError('The event cannot be found or is inaccessible.');
|
|
140
|
+
}
|
|
141
|
+
// validate status
|
|
142
|
+
if (!(event.eventStatus && event.eventStatus.alternateName === 'EventOpened')) {
|
|
143
|
+
throw new _common.DataError('Send tokens action may only be executed for Open/Active events.');
|
|
144
|
+
}
|
|
145
|
+
// validate event actions
|
|
146
|
+
if (!(event.actions && event.actions.length)) {
|
|
147
|
+
throw new _common.DataNotFoundError('There are not generate token actions for the specified event or they are inaccessible.');
|
|
148
|
+
}
|
|
149
|
+
// find completed token generation action (can only be one)
|
|
150
|
+
const successfulTokenAction = event.actions.find((generateTokenAction) => generateTokenAction.actionStatus.alternateName === 'CompletedActionStatus');
|
|
151
|
+
if (successfulTokenAction == null) {
|
|
152
|
+
throw new _common.DataError('The specified event does not have a completed token generation action.');
|
|
153
|
+
}
|
|
154
|
+
// get tokenInfo for this event
|
|
155
|
+
const tokenInfo = await this.getTokenStatistics();
|
|
156
|
+
// validate sent-used seperately for descriptive errors
|
|
157
|
+
if (tokenInfo.sent) {
|
|
158
|
+
throw new _common.DataError(`Cannot proceed with sending tokens, because ${tokenInfo.sent} of them is/are already sent.`);
|
|
159
|
+
}
|
|
160
|
+
if (tokenInfo.used) {
|
|
161
|
+
throw new _common.DataError(`Cannot proceed with sending tokens, because ${tokenInfo.used} of them is/are already used.`);
|
|
162
|
+
}
|
|
163
|
+
// start gathering students
|
|
164
|
+
let students;
|
|
165
|
+
const courseClass = event.courseClassInstructor && event.courseClassInstructor.courseClass;
|
|
166
|
+
const eventInstructor = event.courseClassInstructor && event.courseClassInstructor.instructor;
|
|
167
|
+
// get class sections
|
|
168
|
+
const sections = await context.model('CourseClassSection').where('courseClass').equal(courseClass.id).getItems();
|
|
169
|
+
// check if course class has sections
|
|
170
|
+
if (sections && sections.length > 0 && courseClass.mustRegisterSection !== 0) {
|
|
171
|
+
// get only number of students registered at specific section
|
|
172
|
+
const instructorSections = await context.model('CourseClassSectionInstructor').where('courseClass').equal(courseClass.id).
|
|
173
|
+
and('instructor').equal(eventInstructor).select('section/section as sectionId').silent().getItems();
|
|
174
|
+
if (instructorSections && instructorSections.length === 0) {
|
|
175
|
+
throw new _common.DataError('Instructor is not related with any of sections');
|
|
37
176
|
}
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
177
|
+
const sectionIds = instructorSections.map((section) => {
|
|
178
|
+
return section.sectionId;
|
|
179
|
+
});
|
|
180
|
+
// get students for specific course class sections
|
|
181
|
+
students = await context.model('StudentCourseClass').
|
|
182
|
+
where('courseClass').equal(courseClass.id).
|
|
183
|
+
and('section').in(sectionIds).
|
|
184
|
+
select('email').
|
|
185
|
+
silent().
|
|
186
|
+
getAllItems();
|
|
187
|
+
} else {
|
|
188
|
+
students = await context.model('StudentCourseClass').
|
|
189
|
+
where('courseClass').equal(courseClass.id).
|
|
190
|
+
select('email').
|
|
191
|
+
silent().
|
|
192
|
+
getAllItems();
|
|
193
|
+
}
|
|
194
|
+
if (!(Array.isArray(students) && students.length)) {
|
|
195
|
+
throw new _common.DataError('No recipients/students found.');
|
|
196
|
+
}
|
|
197
|
+
// check total of students
|
|
198
|
+
if (students.length !== tokenInfo.total) {
|
|
199
|
+
throw new _common.DataError(`Cannot proceed to sending tokens. Students are ${students.length} and generated tokens are ${tokenInfo.total}.`);
|
|
200
|
+
}
|
|
201
|
+
// validate student emails, must all exist and have a valid format
|
|
202
|
+
// https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
|
|
203
|
+
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])?)*$/;
|
|
204
|
+
const invalidEmail = students.find((student) => {
|
|
205
|
+
return !(student.email && mailRegex.test(student.email));
|
|
206
|
+
});
|
|
207
|
+
if (invalidEmail) {
|
|
208
|
+
throw new _common.DataError(`Cannot procced to sending tokens because at least one student's email is null or invalid. Found invalid email: ${invalidEmail.email || 'empty'}`);
|
|
209
|
+
}
|
|
210
|
+
// get tokens
|
|
211
|
+
let tokens = await this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.getId()).
|
|
212
|
+
select('access_token').
|
|
213
|
+
silent().
|
|
214
|
+
getAllItems();
|
|
215
|
+
// and map them to an array
|
|
216
|
+
tokens = tokens.map((token) => token.access_token);
|
|
217
|
+
// get mail template
|
|
218
|
+
const mailTemplate = await context.model('MailConfiguration').
|
|
219
|
+
where('target').equal('SendInstructorTokenAction').
|
|
220
|
+
silent().
|
|
221
|
+
getItem();
|
|
222
|
+
if (mailTemplate == null) {
|
|
223
|
+
throw new _common.DataError('Cannot execute send tokens action because template is missing for SendInstructorTokenAction.');
|
|
224
|
+
}
|
|
225
|
+
const succeeded = [];
|
|
226
|
+
const failed = [];
|
|
227
|
+
try {
|
|
228
|
+
// use an async function to send emails
|
|
229
|
+
await (async () => {
|
|
230
|
+
for (const student of students) {
|
|
231
|
+
// refresh mailer
|
|
232
|
+
const mailer = (0, _mailer.getMailer)(context); // maybe investigate why this has to be refreshed.
|
|
233
|
+
// pop an access token
|
|
234
|
+
const access_token = tokens.pop();
|
|
235
|
+
// send message
|
|
236
|
+
await new Promise((resolve) => {
|
|
237
|
+
mailer.
|
|
238
|
+
template(mailTemplate.template).
|
|
239
|
+
subject(mailTemplate.subject).
|
|
240
|
+
to(student.email).
|
|
241
|
+
send(Object.assign(event, {
|
|
242
|
+
access_token }),
|
|
243
|
+
(err) => {
|
|
244
|
+
if (err) {
|
|
245
|
+
try {
|
|
246
|
+
_common.TraceUtils.error(`SendEvaluationTokensAction', 'An error occurred while trying to send token to student email ${student.email}`);
|
|
247
|
+
_common.TraceUtils.error(err);
|
|
248
|
+
} catch (err1) {
|
|
249
|
+
// do nothing
|
|
250
|
+
}
|
|
251
|
+
failed.push(access_token);
|
|
252
|
+
return resolve();
|
|
253
|
+
}
|
|
254
|
+
succeeded.push(access_token);
|
|
255
|
+
return resolve();
|
|
256
|
+
});
|
|
54
257
|
});
|
|
55
|
-
// get number of students for specific course class sections
|
|
56
|
-
action.numberOfStudents = await context.model('StudentCourseClass').where('courseClass').equal(courseClass.id).
|
|
57
|
-
and('section').in(sectionIds).
|
|
58
|
-
silent().count();
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
action.numberOfStudents = await context.model('StudentCourseClass').where('courseClass').equal(courseClass.id).silent().count();
|
|
62
|
-
}
|
|
63
|
-
// save action and then generateTokens
|
|
64
|
-
const generateAction = await context.model('GenerateInstructorTokenAction').save(action);
|
|
65
|
-
const generateOptions =
|
|
66
|
-
{
|
|
67
|
-
evaluationEvent: event.id,
|
|
68
|
-
n: action.numberOfStudents,
|
|
69
|
-
expires: event.endDate };
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
// save number of students to event
|
|
73
|
-
event.numberOfStudents = action.numberOfStudents;
|
|
74
|
-
await context.model('ClassInstructorEvaluationEvent').save(event);
|
|
75
|
-
if (event.numberOfStudents > 0) {
|
|
76
|
-
await _evaluationEventModel.default.generateTokens(context, generateOptions);
|
|
77
258
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
259
|
+
})();
|
|
260
|
+
// update successfully sent tokens
|
|
261
|
+
for (const succededToken of succeeded) {
|
|
262
|
+
await context.model('EvaluationAccessToken').silent().save({
|
|
263
|
+
access_token: succededToken, // access_token is primary
|
|
264
|
+
sent: true,
|
|
265
|
+
$state: 2 });
|
|
266
|
+
|
|
81
267
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
268
|
+
// create send tokens action
|
|
269
|
+
const sendTokensAction = {
|
|
270
|
+
event: this.getId(),
|
|
271
|
+
numberOfStudents: students.length,
|
|
272
|
+
total: tokenInfo.total,
|
|
273
|
+
sent: succeeded.length,
|
|
274
|
+
failed: failed.length,
|
|
275
|
+
actionStatus: {
|
|
276
|
+
alternateName: 'CompletedActionStatus' } };
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
// and save
|
|
280
|
+
return await context.model('SendInstructorTokenAction').silent().save(sendTokensAction);
|
|
281
|
+
} catch (err) {
|
|
282
|
+
// log error
|
|
283
|
+
_common.TraceUtils.error(err);
|
|
284
|
+
// update successfully sent tokens
|
|
285
|
+
for (const succededToken of succeeded) {
|
|
286
|
+
await context.model('EvaluationAccessToken').silent().save({
|
|
287
|
+
access_token: succededToken, // access_token is primary
|
|
288
|
+
sent: true,
|
|
289
|
+
$state: 2 });
|
|
89
290
|
|
|
90
291
|
}
|
|
292
|
+
// create send tokens action
|
|
293
|
+
const sendTokensAction = {
|
|
294
|
+
event: this.getId(),
|
|
295
|
+
numberOfStudents: students.length,
|
|
296
|
+
total: tokenInfo.total,
|
|
297
|
+
sent: succeeded.length,
|
|
298
|
+
failed: succeeded.length ? tokenInfo.total - succeeded.length : tokenInfo.total,
|
|
299
|
+
actionStatus: {
|
|
300
|
+
alternateName: 'CompletedActionStatus' } };
|
|
301
|
+
|
|
91
302
|
|
|
303
|
+
// and save
|
|
304
|
+
return await context.model('SendInstructorTokenAction').silent().save(sendTokensAction);
|
|
92
305
|
}
|
|
93
|
-
}}, (_applyDecoratedDescriptor(_class2.prototype, "generateEvaluationTokens", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "generateEvaluationTokens"), _class2.prototype)), _class2)) || _class);
|
|
306
|
+
}}, (_applyDecoratedDescriptor(_class2.prototype, "generateEvaluationTokens", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "generateEvaluationTokens"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getTokenStatistics", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "getTokenStatistics"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "sendEvaluationTokens", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "sendEvaluationTokens"), _class2.prototype)), _class2)) || _class);
|
|
94
307
|
|
|
95
308
|
module.exports = ClassInstructorEvaluationEvent;
|
|
96
309
|
//# sourceMappingURL=class-instructor-evaluation-event-model.js.map
|