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

User constructor should return the correct child class is type is unspecified

This commit is contained in:
2022-02-25 13:03:26 +00:00
parent 6c843731d1
commit f0e865803e

View File

@@ -19,10 +19,13 @@ class User {
type = type ?? false;
let types = [];
if (type)
let knownType = false;
if (type) {
types.push(type);
else
knownType = true;
} else {
types = [ 'account', 'student', 'parent' ];
}
return (async () => {
for (const type of types) {
@@ -43,7 +46,7 @@ class User {
const res =
await conn.runQuery(sql, [ userId ]);
if (!res)
if (!res.length)
continue;
const record = res[0];
@@ -53,7 +56,14 @@ class User {
this.type = type;
return this;
if (knownType)
return this;
const className =
`${type.substring(0, 1).toUpperCase()}`
+ `${type.substring(1)}`;
return new (require(`./${className}`))(this.id);
}
})();
}