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

Implement TestResult.setMark

This commit is contained in:
2022-04-18 19:13:58 +00:00
parent facb9ba124
commit 5def59357c
2 changed files with 23 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
'use strict'; 'use strict';
const MySQLDate = require('./MySQLDate');
class TestResult { class TestResult {
id; id;
@@ -17,7 +19,7 @@ class TestResult {
time; time;
#mark; mark;
#conn; #conn;
@@ -76,18 +78,29 @@ class TestResult {
this.#loaded = true; this.#loaded = true;
} }
set mark(mark) { async setMark(mark) {
//TODO handle saving mark const sql = `
this.#mark = mark; update
} testResult
set
mark = ?,
time = ?
where
testResultId = ?;
`;
get mark() { await this.#conn.runQuery(sql, [
return this.#mark; mark,
new MySQLDate(),
this.id
]);
this.mark = mark;
} }
get percentage() { get percentage() {
return ( return Math.round(
parseInt(this.#mark) / parseInt(this.mark) /
parseInt(this.test.template.maxMark) * parseInt(this.test.template.maxMark) *
100 100
); );

View File

@@ -95,7 +95,7 @@ router.post('/:id/results/:resultId/edit', async (req, res) => {
return res.redirect(returnURL); return res.redirect(returnURL);
} }
tr.mark = fields.get('mark'); await tr.setMark(fields.get('mark'));
res.redirect(returnURL); res.redirect(returnURL);
}); });