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:
25
lib/User.js
25
lib/User.js
@@ -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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user