mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 16:19:26 +00:00
Add TestTemplate.assignClass
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
const crypto = require('crypto');
|
||||
|
||||
// Import user defined modules
|
||||
const Class = require('./Class');
|
||||
const DatabaseConnectionPool = require('./DatabaseConnectionPool');
|
||||
const Test = require('./Test');
|
||||
|
||||
/**
|
||||
* A class that represents a test template
|
||||
@@ -80,8 +82,31 @@ class TestTemplate {
|
||||
return new (require('./Account'))(this.accountId);
|
||||
}
|
||||
|
||||
assignClass() {
|
||||
async assignClass(classId, date) {
|
||||
const c = await new Class(classId);
|
||||
const id = crypto.randomUUID();
|
||||
const epochDate = date.getTime() / 1000;
|
||||
|
||||
const sql = `
|
||||
insert into test(
|
||||
testId,
|
||||
testTemplateId,
|
||||
classId,
|
||||
testDate)
|
||||
values
|
||||
(?, ?, ?, FROM_UNIXTIME(?));
|
||||
`;
|
||||
|
||||
const conn = await new DatabaseConnectionPool();
|
||||
|
||||
await conn.runQuery(sql, [
|
||||
id,
|
||||
this.id,
|
||||
c.id,
|
||||
epochDate
|
||||
]);
|
||||
|
||||
return new Test(id);
|
||||
}
|
||||
|
||||
get classes() {
|
||||
|
||||
Reference in New Issue
Block a user