mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 20:39:28 +00:00
Implement TestResult.setMark
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const MySQLDate = require('./MySQLDate');
|
||||
|
||||
class TestResult {
|
||||
id;
|
||||
|
||||
@@ -17,7 +19,7 @@ class TestResult {
|
||||
|
||||
time;
|
||||
|
||||
#mark;
|
||||
mark;
|
||||
|
||||
#conn;
|
||||
|
||||
@@ -76,18 +78,29 @@ class TestResult {
|
||||
this.#loaded = true;
|
||||
}
|
||||
|
||||
set mark(mark) {
|
||||
//TODO handle saving mark
|
||||
this.#mark = mark;
|
||||
}
|
||||
async setMark(mark) {
|
||||
const sql = `
|
||||
update
|
||||
testResult
|
||||
set
|
||||
mark = ?,
|
||||
time = ?
|
||||
where
|
||||
testResultId = ?;
|
||||
`;
|
||||
|
||||
get mark() {
|
||||
return this.#mark;
|
||||
await this.#conn.runQuery(sql, [
|
||||
mark,
|
||||
new MySQLDate(),
|
||||
this.id
|
||||
]);
|
||||
|
||||
this.mark = mark;
|
||||
}
|
||||
|
||||
get percentage() {
|
||||
return (
|
||||
parseInt(this.#mark) /
|
||||
return Math.round(
|
||||
parseInt(this.mark) /
|
||||
parseInt(this.test.template.maxMark) *
|
||||
100
|
||||
);
|
||||
|
||||
@@ -95,7 +95,7 @@ router.post('/:id/results/:resultId/edit', async (req, res) => {
|
||||
return res.redirect(returnURL);
|
||||
}
|
||||
|
||||
tr.mark = fields.get('mark');
|
||||
await tr.setMark(fields.get('mark'));
|
||||
|
||||
res.redirect(returnURL);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user