mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-02 05:59:30 +00:00
Added Class constructor
This commit is contained in:
49
lib/Class.js
49
lib/Class.js
@@ -1,10 +1,57 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const DatabaseConnectionPool = require('./DatabaseConnectionPool');
|
||||||
|
|
||||||
class Class {
|
class Class {
|
||||||
classId;
|
/**
|
||||||
|
* The id of the class
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the subject the class is for
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
subjectId;
|
subjectId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the class
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
name;
|
name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} classID - The id of the class to fetch
|
||||||
|
*/
|
||||||
|
constructor(classId) {
|
||||||
|
const sql = `
|
||||||
|
select
|
||||||
|
classId as id,
|
||||||
|
name,
|
||||||
|
subjectId
|
||||||
|
from
|
||||||
|
class
|
||||||
|
where
|
||||||
|
classId = ?;
|
||||||
|
`;
|
||||||
|
|
||||||
|
return (async () => {
|
||||||
|
const conn = await new DatabaseConnectionPool();
|
||||||
|
const record = await conn.runQuery(sql, [
|
||||||
|
classId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!record.length)
|
||||||
|
throw new Error('No class found');
|
||||||
|
|
||||||
|
for (const [ k, v ] of Object.entries(record[0]))
|
||||||
|
this[k] = v;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
get subject() {
|
get subject() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user