From 326dd35b442c31ea751b303172be0c035cf68cac Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 18 Apr 2022 20:17:29 +0000 Subject: [PATCH] Added TestResult.create --- lib/TestResult.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/TestResult.js b/lib/TestResult.js index 0e67d1b..bada376 100644 --- a/lib/TestResult.js +++ b/lib/TestResult.js @@ -1,5 +1,7 @@ 'use strict'; +const crypto = require('crypto'); + const MySQLDate = require('./MySQLDate'); class TestResult { @@ -110,6 +112,34 @@ class TestResult { //TODO get actual grades return 'C'; } + + static async create(conn, testId, accountId, studentId, mark) { + const sql = ` + insert into testResult + ( + testResultId, + studentId, + testId, + accountId, + mark, + time + ) + values (?, ?, ?, ?, ?, ?); + `; + + const id = await crypto.randomUUID(); + + await conn.runQuery(sql, [ + id, + studentId, + testId, + accountId, + mark, + new MySQLDate() + ]); + + return new TestResult(conn, id); + } } module.exports = TestResult;