mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 22:59:28 +00:00
Implemented base TestResult functionality
This commit is contained in:
@@ -1,40 +1,101 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
class TestResult {
|
class TestResult {
|
||||||
|
id;
|
||||||
|
|
||||||
studentId;
|
studentId;
|
||||||
|
|
||||||
|
student;
|
||||||
|
|
||||||
accountId;
|
accountId;
|
||||||
|
|
||||||
|
account;
|
||||||
|
|
||||||
testId;
|
testId;
|
||||||
|
|
||||||
constructor() {
|
test;
|
||||||
|
|
||||||
|
time;
|
||||||
|
|
||||||
|
#mark;
|
||||||
|
|
||||||
|
#conn;
|
||||||
|
|
||||||
|
#loaded = false;
|
||||||
|
|
||||||
|
constructor(conn, id) {
|
||||||
|
this.#conn = conn;
|
||||||
|
|
||||||
|
const sql = `
|
||||||
|
select
|
||||||
|
testResultId as id,
|
||||||
|
studentId,
|
||||||
|
testId,
|
||||||
|
accountId,
|
||||||
|
mark,
|
||||||
|
time
|
||||||
|
from
|
||||||
|
testResult
|
||||||
|
where
|
||||||
|
testResultId = ?;
|
||||||
|
`;
|
||||||
|
|
||||||
|
return (async () => {
|
||||||
|
const record = await this.#conn.runQuery(sql, [ id ]);
|
||||||
|
|
||||||
|
if (!record.length)
|
||||||
|
throw new Error('No test result found');
|
||||||
|
|
||||||
|
for (const [ k, v ] of Object.entries(record[0]))
|
||||||
|
this[k] = v;
|
||||||
|
|
||||||
|
await this.load();
|
||||||
|
|
||||||
|
return this;
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
set mark() {
|
#getObject(classFile, id) {
|
||||||
|
return new (require(`./${classFile}`))(this.#conn, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
async load() {
|
||||||
|
if (this.#loaded)
|
||||||
|
return;
|
||||||
|
|
||||||
|
[
|
||||||
|
this.student,
|
||||||
|
this.account,
|
||||||
|
this.test
|
||||||
|
] = await Promise.all([
|
||||||
|
this.#getObject('Student', this.studentId),
|
||||||
|
this.#getObject('Account', this.accountId),
|
||||||
|
this.#getObject('Test', this.testId)
|
||||||
|
]);
|
||||||
|
|
||||||
|
this.#loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
set mark(mark) {
|
||||||
|
//TODO handle saving mark
|
||||||
|
this.#mark = mark;
|
||||||
}
|
}
|
||||||
|
|
||||||
get mark() {
|
get mark() {
|
||||||
|
return this.#mark;
|
||||||
}
|
}
|
||||||
|
|
||||||
get percentage() {
|
get percentage() {
|
||||||
|
return (
|
||||||
|
parseInt(this.#mark) /
|
||||||
|
parseInt(this.test.template.maxMark) *
|
||||||
|
100
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get grade() {
|
get grade() {
|
||||||
|
//TODO get actual grades
|
||||||
}
|
return 'C';
|
||||||
|
|
||||||
get student() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
get account() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
get test {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user