1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 20:39:28 +00:00

Don't block main thread waiting for email to build and send

This commit is contained in:
2022-04-24 19:02:37 +00:00
parent 9ae60ef85b
commit 62364baa1d
3 changed files with 35 additions and 34 deletions

View File

@@ -173,23 +173,23 @@ class Test {
mark mark
); );
const parents = await tr.student.getParents(); const body = 'Your result has been added for ' +
`the test "${this.template.name}" that you ` +
`took on ${this.getDateString()}\n\n` +
`You scored ${mark}/${this.template.maxMark} ` +
`(${tr.percentage}%) which is a grade ` +
`${tr.grade}`;
const email = new EmailBuilder() tr.student.getParents().then(parents => {
.addTo([ tr.student, ...parents ] const email = new EmailBuilder()
.map(u => u.getEmail())) .addTo([ tr.student, ...parents ]
.setSubject('Stratos - Test result added') .map(u => u.getEmail()))
.setBody( .setSubject('Stratos - Test result added')
'Your result has been added for ' + .setBody(body);
`the test "${this.template.name}" that you ` +
`took on ${this.getDateString()}\n\n` +
`You scored ${mark}/${this.template.maxMark} ` +
`(${tr.percentage}%) which is a grade ` +
`${tr.grade}`
);
const emailer = new Emailer(); const emailer = new Emailer();
await emailer.sendEmail(email); emailer.sendEmail(email);
});
return tr; return tr;
} }

View File

@@ -114,16 +114,16 @@ class TestResult {
`(${this.percentage}%) which is a grade ` + `(${this.percentage}%) which is a grade ` +
`${this.grade}`; `${this.grade}`;
const parents = await this.student.getParents(); this.student.getParents().then(parents => {
const email = new EmailBuilder()
.addTo([ this.student, ...parents ]
.map(u => u.getEmail()))
.setSubject('Stratos - Test result changed')
.setBody(body);
const email = new EmailBuilder() const emailer = new Emailer();
.addTo([ this.student, ...parents ] emailer.sendEmail(email);
.map(u => u.getEmail())) });
.setSubject('Stratos - Test result changed')
.setBody(body);
const emailer = new Emailer();
await emailer.sendEmail(email);
} }
get percentage() { get percentage() {

View File

@@ -139,17 +139,18 @@ class TestTemplate {
const t = await new Test(this.#conn, id); const t = await new Test(this.#conn, id);
const email = (await EmailBuilder.generateFromClass(c)) const body = `New test added for class ${c.name}:\n` +
.setSubject('Stratos - New Test') `Test name: ${this.name}\n` +
.setBody( `Test date: ${t.getDateString()}\n` +
`New test added for class ${c.name}:\n` + `Maximum mark: ${this.maxMark}`;
`Test name: ${this.name}\n` +
`Test date: ${t.getDateString()}\n` +
`Maximum mark: ${this.maxMark}`
);
const emailer = new Emailer(); EmailBuilder.generateFromClass(c).then(email => {
await emailer.sendEmail(email); email.setSubject('Stratos - New Test')
.setBody(body);
const emailer = new Emailer();
emailer.sendEmail(email);
});
return t; return t;
} }