@universis/evaluations 1.0.25 → 1.0.27
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 +1 -1
- package/dist/config/models/CourseClassEvaluationEvent.json +89 -4
- package/dist/config/models/EvaluationAccessToken.json +19 -1
- package/dist/config/models/EvaluationDocument.json +17 -1
- package/dist/config/models/EvaluationEvent.json +13 -0
- package/dist/config/models/GenerateCourseClassTokenAction.json +57 -0
- package/dist/config/models/SendCourseClassTokenAction.json +52 -0
- package/dist/listeners/access-token-listener.js +76 -0
- package/dist/listeners/access-token-listener.js.map +1 -0
- package/dist/listeners/class-event-listener.js +184 -0
- package/dist/listeners/class-event-listener.js.map +1 -0
- package/dist/locales/el.json +3 -1
- package/dist/models/class-instructor-evaluation-event-model.js +1 -5
- package/dist/models/class-instructor-evaluation-event-model.js.map +1 -1
- package/dist/models/course-class-evaluation-event-model.js +340 -0
- package/dist/models/course-class-evaluation-event-model.js.map +1 -0
- package/dist/models/evaluation-event-model.js +200 -12
- package/dist/models/evaluation-event-model.js.map +1 -1
- package/package.json +1 -1
- package/src/config/models/ClassInstructorEvaluationEvent.json +1 -1
- package/src/config/models/CourseClassEvaluationEvent.json +89 -4
- package/src/config/models/EvaluationAccessToken.json +19 -1
- package/src/config/models/EvaluationDocument.json +17 -1
- package/src/config/models/EvaluationEvent.json +13 -0
- package/src/config/models/GenerateCourseClassTokenAction.json +57 -0
- package/src/config/models/SendCourseClassTokenAction.json +52 -0
- package/src/listeners/access-token-listener.js +75 -0
- package/src/listeners/class-event-listener.js +183 -0
- package/src/locales/el.json +3 -1
- package/src/models/class-instructor-evaluation-event-model.js +1 -5
- package/src/models/course-class-evaluation-event-model.js +339 -0
- package/src/models/evaluation-event-model.js +204 -16
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
|
|
3
|
+
"@id": "http://schema.org/SendCourseClassTokenAction",
|
|
4
|
+
"name": "SendCourseClassTokenAction",
|
|
5
|
+
"description": "The act of organizing tasks/objects/events by associating resources to it.",
|
|
6
|
+
"title": "SendCourseClassTokenAction",
|
|
7
|
+
"abstract": false,
|
|
8
|
+
"sealed": false,
|
|
9
|
+
"inherits": "SendTokenAction",
|
|
10
|
+
"version": "1.1",
|
|
11
|
+
"fields": [
|
|
12
|
+
{
|
|
13
|
+
"name": "event",
|
|
14
|
+
"title": "Γεγονός αξιολόγησης",
|
|
15
|
+
"type": "CourseClassEvaluationEvent",
|
|
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/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/courseClass/course/department eq departments()"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { DataObjectState } from '@themost/data';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {DataEventArgs} event
|
|
6
|
+
*/
|
|
7
|
+
async function afterSaveAsync(event) {
|
|
8
|
+
// get organizer from courseClass
|
|
9
|
+
const context = event.model.context;
|
|
10
|
+
const target = event.target;
|
|
11
|
+
if (event.state === DataObjectState.Update) {
|
|
12
|
+
const previous = event.previous;
|
|
13
|
+
// update also child evaluation tokens (send, used, metadata)
|
|
14
|
+
let relatedTokens = await context.model('EvaluationAccessToken')
|
|
15
|
+
.where('parentToken').equal(event.target.access_token)
|
|
16
|
+
.silent()
|
|
17
|
+
.getAllItems();
|
|
18
|
+
if (relatedTokens && relatedTokens.length > 0) {
|
|
19
|
+
relatedTokens = relatedTokens.map(x => {
|
|
20
|
+
x.sent = target.hasOwnProperty('sent') ? target.sent : x.sent;
|
|
21
|
+
x.metadata = target.hasOwnProperty('metadata') ? target.metadata : x.metadata;
|
|
22
|
+
return x;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
await context.model('EvaluationAccessToken')
|
|
26
|
+
.silent().save(relatedTokens)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function afterExecute(event, callback) {
|
|
31
|
+
return afterExecuteAsync(event).then(() => {
|
|
32
|
+
return callback();
|
|
33
|
+
}).catch(err => {
|
|
34
|
+
return callback(err);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export async function afterExecuteAsync(event) {
|
|
40
|
+
// calculate total tokens and total used tokens if events are expanded
|
|
41
|
+
if (event.emitter && event.emitter.$expand && Array.isArray(event.emitter.$expand)) {
|
|
42
|
+
// if tokens of classInstructorEvaluationEvents are expanded and $select and $groupby are present to mapping options
|
|
43
|
+
if (event.emitter.$expand.find(mapping => {
|
|
44
|
+
// $select and $groupby are present to mapping options
|
|
45
|
+
return typeof mapping === 'object'
|
|
46
|
+
? mapping.name === 'tokens' && (mapping.options && mapping.options.$select && mapping.options.$groupby)
|
|
47
|
+
: mapping === 'tokens'
|
|
48
|
+
})) {
|
|
49
|
+
const results = Array.isArray(event.result) ? event.result : [event.result]
|
|
50
|
+
for (const result of results) {
|
|
51
|
+
if (Array.isArray(result.tokens) && result.tokens.length) {
|
|
52
|
+
// calculate total and used tokens
|
|
53
|
+
result.calculatedTotal = result.tokens.reduce((partial_sum, a) => partial_sum + a.total, 0)
|
|
54
|
+
const findUsed = result.tokens.find(x=>{
|
|
55
|
+
return x.used;
|
|
56
|
+
});
|
|
57
|
+
result.calculatedUsed = findUsed?findUsed.total:0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {DataEventArgs} event
|
|
66
|
+
* @param {Function} callback
|
|
67
|
+
*/
|
|
68
|
+
export function afterSave(event, callback) {
|
|
69
|
+
// execute async method
|
|
70
|
+
return afterSaveAsync(event).then(() => {
|
|
71
|
+
return callback();
|
|
72
|
+
}).catch(err => {
|
|
73
|
+
return callback(err);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { DataObjectState } from '@themost/data';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {DataEventArgs} event
|
|
5
|
+
*/
|
|
6
|
+
async function beforeSaveAsync(event) {
|
|
7
|
+
// get organizer from courseClass
|
|
8
|
+
const context = event.model.context;
|
|
9
|
+
if (event.target.courseClass) {
|
|
10
|
+
const organizer = await context.model('CourseClass')
|
|
11
|
+
.where('id').equal(event.target.courseClass)
|
|
12
|
+
.select('course/department').value();
|
|
13
|
+
event.target.organizer = organizer;
|
|
14
|
+
}
|
|
15
|
+
if (event.state === DataObjectState.Update) {
|
|
16
|
+
const previous = event.previous;
|
|
17
|
+
// check if endDate is changed and update expired field for tokens
|
|
18
|
+
if (event.target.endDate) {
|
|
19
|
+
const prevEndDate = event.previous.endDate;
|
|
20
|
+
const endDate = event.target.endDate;
|
|
21
|
+
prevEndDate.setHours(0, 0, 0, 0);
|
|
22
|
+
endDate.setHours(0, 0, 0, 0);
|
|
23
|
+
if (prevEndDate - endDate !== 0) {
|
|
24
|
+
let tokens = await context.model('EvaluationAccessToken').where('evaluationEvent').equal(event.target.id)
|
|
25
|
+
.and('used').notEqual(1)
|
|
26
|
+
.silent().getItems();
|
|
27
|
+
if (tokens.length > 0) {
|
|
28
|
+
tokens = tokens.map(x => {
|
|
29
|
+
x.expires = event.target.endDate;
|
|
30
|
+
return x;
|
|
31
|
+
});
|
|
32
|
+
// update tokens
|
|
33
|
+
await context.model('EvaluationAccessToken').silent().save(tokens);
|
|
34
|
+
}
|
|
35
|
+
// change endDate of related ClassInstructorEvaluationEvent - if any
|
|
36
|
+
const events = await context.model('ClassInstructorEvaluationEvent')
|
|
37
|
+
.where('superEvent').equal(event.target.id)
|
|
38
|
+
.getItems();
|
|
39
|
+
if (events && events.length > 0) {
|
|
40
|
+
events.map(x => {
|
|
41
|
+
x.endDate = event.target.endDate;
|
|
42
|
+
return x;
|
|
43
|
+
});
|
|
44
|
+
await context.model('ClassInstructorEvaluationEvent').silent().save(events);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @param {DataEventArgs} event
|
|
52
|
+
* @param {Function} callback
|
|
53
|
+
*/
|
|
54
|
+
export function beforeSave(event, callback) {
|
|
55
|
+
beforeSaveAsync(event).then(() => {
|
|
56
|
+
return callback()
|
|
57
|
+
}).catch( err => {
|
|
58
|
+
return callback(err);
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param {DataEventArgs} event
|
|
65
|
+
*/
|
|
66
|
+
async function afterSaveAsync(event) {
|
|
67
|
+
// get organizer from courseClass
|
|
68
|
+
const context = event.model.context;
|
|
69
|
+
if (event.state === DataObjectState.Insert) {
|
|
70
|
+
// get all courseClassInstructors and check if ClassInstructorEvaluationEvents should be created
|
|
71
|
+
const evaluationEvent = await context.model('CourseClassEvaluationEvent')
|
|
72
|
+
.where('id').equal(event.target.id).flatten()
|
|
73
|
+
.silent().getItem();
|
|
74
|
+
const childEvaluationDocument = await context.model('EvaluationDocument')
|
|
75
|
+
.where('parentDocument').equal(evaluationEvent.evaluationDocument).getItem();
|
|
76
|
+
if (childEvaluationDocument) {
|
|
77
|
+
const classInstructors = await context.model('CourseClassInstructor')
|
|
78
|
+
.where('courseClass').equal(evaluationEvent.courseClass).getAllItems();
|
|
79
|
+
const events = classInstructors.map(x => {
|
|
80
|
+
x.courseClassInstructor = x.id;
|
|
81
|
+
x.superEvent = event.target.id;
|
|
82
|
+
x.evaluationDocument = childEvaluationDocument
|
|
83
|
+
x.startDate = event.target.startDate;
|
|
84
|
+
x.endDate = event.target.endDate;
|
|
85
|
+
delete x.id;
|
|
86
|
+
return x;
|
|
87
|
+
});
|
|
88
|
+
await context.model('ClassInstructorEvaluationEvent').silent().save(events);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function afterExecute(event, callback) {
|
|
94
|
+
return afterExecuteAsync(event).then(() => {
|
|
95
|
+
return callback();
|
|
96
|
+
}).catch(err => {
|
|
97
|
+
return callback(err);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
export async function afterExecuteAsync(event) {
|
|
103
|
+
// calculate total tokens and total used tokens if events are expanded
|
|
104
|
+
if (event.emitter && event.emitter.$expand && Array.isArray(event.emitter.$expand)) {
|
|
105
|
+
// if tokens of classInstructorEvaluationEvents are expanded and $select and $groupby are present to mapping options
|
|
106
|
+
if (event.emitter.$expand.find(mapping => {
|
|
107
|
+
// $select and $groupby are present to mapping options
|
|
108
|
+
return typeof mapping === 'object'
|
|
109
|
+
? mapping.name === 'tokens' && (mapping.options && mapping.options.$select && mapping.options.$groupby)
|
|
110
|
+
: mapping === 'tokens'
|
|
111
|
+
})) {
|
|
112
|
+
const results = Array.isArray(event.result) ? event.result : [event.result]
|
|
113
|
+
for (const result of results) {
|
|
114
|
+
if (Array.isArray(result.tokens) && result.tokens.length) {
|
|
115
|
+
// calculate total and used tokens
|
|
116
|
+
result.calculatedTotal = result.tokens.reduce((partial_sum, a) => partial_sum + a.total, 0)
|
|
117
|
+
const findUsed = result.tokens.find(x=>{
|
|
118
|
+
return x.used;
|
|
119
|
+
});
|
|
120
|
+
result.calculatedUsed = findUsed?findUsed.total:0;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @async
|
|
129
|
+
* @param {DataEventArgs} event
|
|
130
|
+
*/
|
|
131
|
+
async function beforeRemoveAsync(event) {
|
|
132
|
+
// ensure associations
|
|
133
|
+
const context = event.model.context;
|
|
134
|
+
const evaluationEvent = context.model('EvaluationEvent').convert(event.target);
|
|
135
|
+
const form = await evaluationEvent.property('evaluationDocument').getItem();
|
|
136
|
+
if (form && form.resultType) {
|
|
137
|
+
if (context.model(form.resultType) == null) {
|
|
138
|
+
// ensure model is added to configuration
|
|
139
|
+
await evaluationEvent.getForm();
|
|
140
|
+
}
|
|
141
|
+
const answers = await context.model(form.resultType)
|
|
142
|
+
.where('evaluationEvent').equal(event.target.id)
|
|
143
|
+
.silent().count();
|
|
144
|
+
if (answers) {
|
|
145
|
+
throw new Error('Cannot remove evaluation event since there are responses associated with it')
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// remove also related ClassInstructorEvaluationEvents
|
|
149
|
+
const relatedEvents = await context.model('ClassInstructorEvaluationEvent')
|
|
150
|
+
.where('superEvent').equal(event.target.id).select('id')
|
|
151
|
+
.getItems();
|
|
152
|
+
if (relatedEvents && relatedEvents.length > 0) {
|
|
153
|
+
await context.model('ClassInstructorEvaluationEvent').remove(relatedEvents);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @param {DataEventArgs} event
|
|
160
|
+
* @param {Function} callback
|
|
161
|
+
*/
|
|
162
|
+
export function beforeRemove(event, callback) {
|
|
163
|
+
// execute async method
|
|
164
|
+
return beforeRemoveAsync(event).then(() => {
|
|
165
|
+
return callback();
|
|
166
|
+
}).catch(err => {
|
|
167
|
+
return callback(err);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @param {DataEventArgs} event
|
|
174
|
+
* @param {Function} callback
|
|
175
|
+
*/
|
|
176
|
+
export function afterSave(event, callback) {
|
|
177
|
+
// execute async method
|
|
178
|
+
return afterSaveAsync(event).then(() => {
|
|
179
|
+
return callback();
|
|
180
|
+
}).catch(err => {
|
|
181
|
+
return callback(err);
|
|
182
|
+
});
|
|
183
|
+
}
|
package/src/locales/el.json
CHANGED
|
@@ -16,5 +16,7 @@
|
|
|
16
16
|
"Evaluation token has been expired" : "Ο κωδικός αξιολόγησης έχει λήξει",
|
|
17
17
|
"The course evaluation has been closed and is no longer available": "Η αξιολόγηση του μαθήματος έχει κλείσει και δεν είναι πλέον διαθέσιμη",
|
|
18
18
|
"Evaluation access token has been expired or is invalid.": "Ο κωδικός αξιολόγησης έχει λήξει ή δεν είναι έγκυρος",
|
|
19
|
-
"The bulk sending process of tokens is already in progress": "Η μαζική αποστολή των μηνυμάτων έχει ήδη ξεκινήσει"
|
|
19
|
+
"The bulk sending process of tokens is already in progress": "Η μαζική αποστολή των μηνυμάτων έχει ήδη ξεκινήσει",
|
|
20
|
+
"Select at least one instructor to evaluate":"Επιλέξτε τουλάχιστον έναν/μία διδάσκοντα/ουσα για να αξιολογήσετε",
|
|
21
|
+
"A previous action for generating evaluation tokens has been found.": "Μια ενέργεια έκδοσης tokens είναι ήδη σε εξέλιξη"
|
|
20
22
|
}
|
|
@@ -197,13 +197,11 @@ class ClassInstructorEvaluationEvent extends EvaluationEvent {
|
|
|
197
197
|
students = await context.model('StudentCourseClass')
|
|
198
198
|
.where('courseClass').equal(courseClass.id)
|
|
199
199
|
.and('section').in(sectionIds)
|
|
200
|
-
.select('email')
|
|
201
200
|
.silent()
|
|
202
201
|
.getAllItems();
|
|
203
202
|
} else {
|
|
204
203
|
students = await context.model('StudentCourseClass')
|
|
205
204
|
.where('courseClass').equal(courseClass.id)
|
|
206
|
-
.select('email', 'student')
|
|
207
205
|
.silent()
|
|
208
206
|
.getAllItems();
|
|
209
207
|
}
|
|
@@ -227,11 +225,9 @@ class ClassInstructorEvaluationEvent extends EvaluationEvent {
|
|
|
227
225
|
}
|
|
228
226
|
// get tokens
|
|
229
227
|
let tokens = await this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.getId())
|
|
230
|
-
.select('access_token')
|
|
231
228
|
.silent()
|
|
232
229
|
.getAllItems();
|
|
233
|
-
|
|
234
|
-
tokens = tokens.map(token => token.access_token);
|
|
230
|
+
|
|
235
231
|
// get mail template
|
|
236
232
|
const mailTemplate = await context.model('MailConfiguration')
|
|
237
233
|
.where('target').equal('SendInstructorTokenAction')
|