mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 17:59:25 +00:00
Implement user constructor
This commit is contained in:
25
lib/User.js
25
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() {
|
||||
|
||||
Reference in New Issue
Block a user