From 254a9b8006b11c3a66d80e2779168c2ed05d7ab6 Mon Sep 17 00:00:00 2001 From: matt Date: Sun, 13 Feb 2022 22:03:21 +0000 Subject: [PATCH] Implement user constructor --- lib/User.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/User.js b/lib/User.js index 3eb62b4..6077f0d 100644 --- a/lib/User.js +++ b/lib/User.js @@ -1,5 +1,7 @@ 'use strict'; +const DatabaseConnectionPool = require('./DatabaseConnectionPool'); + class User { id; firstName; @@ -10,7 +12,30 @@ class User { type = null; constructor(type, userId) { + const sql = ` + select + email, + firstName, + otherNames, + lastName, + password, + accountId as id + from ${type} + where + ${type}Id = ?; + `; + this.type = type; + + return (async () => { + const conn = await new DatabaseConnectionPool(); + const record = await conn.runQuery(sql, [ userId ]); + + for (const [ k, v ] of Object.entries(record[0])) + this[k] = v; + + return this; + })(); } get fullName() {