From 72b8c5adefe8a1f5918d5b2ff5c6c66395a4fb0b Mon Sep 17 00:00:00 2001 From: matt Date: Thu, 21 Apr 2022 15:48:24 +0000 Subject: [PATCH] Notify when a new test result is added to a test --- lib/Test.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/Test.js b/lib/Test.js index 25d4a5f..530b150 100644 --- a/lib/Test.js +++ b/lib/Test.js @@ -1,6 +1,7 @@ /* eslint-disable no-empty-function, getter-return */ 'use strict'; +const { EmailBuilder, Emailer } = require('./Emailer'); const TestResult = require('./TestResult'); /** @@ -147,14 +148,31 @@ class Test { })); } - addResult(accountId, studentId, mark) { - return TestResult.create( + async addResult(accountId, studentId, mark) { + const tr = await TestResult.create( this.#conn, this.id, accountId, studentId, 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() {