mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 22:19:26 +00:00
Notify when a new test result is added to a test
This commit is contained in:
22
lib/Test.js
22
lib/Test.js
@@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable no-empty-function, getter-return */
|
/* eslint-disable no-empty-function, getter-return */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { EmailBuilder, Emailer } = require('./Emailer');
|
||||||
const TestResult = require('./TestResult');
|
const TestResult = require('./TestResult');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,14 +148,31 @@ class Test {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
addResult(accountId, studentId, mark) {
|
async addResult(accountId, studentId, mark) {
|
||||||
return TestResult.create(
|
const tr = await TestResult.create(
|
||||||
this.#conn,
|
this.#conn,
|
||||||
this.id,
|
this.id,
|
||||||
accountId,
|
accountId,
|
||||||
studentId,
|
studentId,
|
||||||
mark
|
mark
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const email = new EmailBuilder()
|
||||||
|
.addTo([ tr.student.getEmail() ])
|
||||||
|
.setSubject('Stratos - Test result added')
|
||||||
|
.setBody(
|
||||||
|
'Your result has been added for ' +
|
||||||
|
`the test "${this.template.name}" that you ` +
|
||||||
|
`took on ${this.dateString}\n\n` +
|
||||||
|
`You scored ${mark}/${this.template.maxMark} ` +
|
||||||
|
`(${tr.percentage}%) which is a grade ` +
|
||||||
|
`${tr.grade}`
|
||||||
|
);
|
||||||
|
|
||||||
|
const emailer = new Emailer();
|
||||||
|
await emailer.sendEmail(email);
|
||||||
|
|
||||||
|
return tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete() {
|
async delete() {
|
||||||
|
|||||||
Reference in New Issue
Block a user