From 9dd5c1dd32122f632f922e96c3d68e5f230f4d76 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 7 Mar 2022 14:45:33 +0000 Subject: [PATCH] Added Subject.getAllSubjects method --- lib/Subject.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/Subject.js b/lib/Subject.js index 21c63dd..1ca8020 100644 --- a/lib/Subject.js +++ b/lib/Subject.js @@ -46,6 +46,29 @@ class Subject { return this; })(); } + + static async getAllSubjects() { + const sql = ` + select + subjectId as id + from + subject; + `; + + const conn = await new DatabaseConnectionPool(); + const records = await conn.runQuery(sql); + conn.close(); + + const objectPromises = []; + + records.forEach(record => { + objectPromises.push(new Subject(record.id)); + }); + + const objects = await Promise.all(objectPromises); + + return objects; + } } module.exports = Subject;