1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 22:19:26 +00:00

Implement user constructor

This commit is contained in:
2022-02-13 22:03:21 +00:00
parent 2de64cdf40
commit 254a9b8006

View File

@@ -1,5 +1,7 @@
'use strict'; 'use strict';
const DatabaseConnectionPool = require('./DatabaseConnectionPool');
class User { class User {
id; id;
firstName; firstName;
@@ -10,7 +12,30 @@ class User {
type = null; type = null;
constructor(type, userId) { 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() { get fullName() {