mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-02 05:39:32 +00:00
Lint cleanup with new rules
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-empty-function, getter-return */
|
||||
'use strict';
|
||||
|
||||
const User = require('./User');
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-empty-function */
|
||||
'use strict';
|
||||
|
||||
const DatabaseConnectionPool = require('./DatabaseConnectionPool');
|
||||
@@ -134,11 +135,11 @@ class Class {
|
||||
})();
|
||||
}
|
||||
|
||||
async getSubject() {
|
||||
getSubject() {
|
||||
return new (require('./Subject'))(this.subjectId);
|
||||
}
|
||||
|
||||
async getUsers(ids, type) {
|
||||
getUsers(ids, type) {
|
||||
const types = {
|
||||
account: 'Account',
|
||||
student: 'Student'
|
||||
@@ -212,4 +213,4 @@ class Class {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Class;
|
||||
module.exports = Class;
|
||||
|
||||
@@ -14,6 +14,7 @@ const defaultDbOptions = importJSON('db');
|
||||
*/
|
||||
class DatabaseConnectionPool {
|
||||
#dbOptions;
|
||||
|
||||
#connectionPool;
|
||||
|
||||
/**
|
||||
|
||||
@@ -200,7 +200,7 @@ class EmailBuilder {
|
||||
}
|
||||
|
||||
if (typeof this?.#HTMLBody?.length !== 'undefined')
|
||||
message['html'] = this.#HTMLBody;
|
||||
message.html = this.#HTMLBody;
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-empty-function, getter-return */
|
||||
'use strict';
|
||||
|
||||
const User = require('./User');
|
||||
|
||||
@@ -7,8 +7,11 @@ const DatabaseConnectionPool = require('./DatabaseConnectionPool');
|
||||
|
||||
class PasswordReset {
|
||||
userId;
|
||||
|
||||
token;
|
||||
|
||||
nonce;
|
||||
|
||||
expires;
|
||||
|
||||
constructor(userId, token) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-empty-function, getter-return */
|
||||
'use strict';
|
||||
|
||||
const User = require('./User');
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-empty-function, getter-return */
|
||||
'use strict';
|
||||
|
||||
// Import user defined modules
|
||||
@@ -105,11 +106,11 @@ class Test {
|
||||
})();
|
||||
}
|
||||
|
||||
async getClass() {
|
||||
getClass() {
|
||||
return new (require('./Class'))(this.classId);
|
||||
}
|
||||
|
||||
async getTestTemplate() {
|
||||
getTestTemplate() {
|
||||
return new (require('./TestTemplate'))(this.templateId);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-empty-function, getter-return */
|
||||
'use strict';
|
||||
|
||||
// Import user defined modules
|
||||
@@ -73,7 +74,7 @@ class TestTemplate {
|
||||
})();
|
||||
}
|
||||
|
||||
async getAccount() {
|
||||
getAccount() {
|
||||
return new (require('./Account'))(this.accountId);
|
||||
}
|
||||
|
||||
|
||||
61
lib/User.js
61
lib/User.js
@@ -11,13 +11,21 @@ const Test = require('./Test');
|
||||
|
||||
class User {
|
||||
id;
|
||||
|
||||
firstName;
|
||||
|
||||
otherNames;
|
||||
|
||||
lastName;
|
||||
|
||||
shortName;
|
||||
|
||||
fullName;
|
||||
|
||||
email;
|
||||
|
||||
#password;
|
||||
|
||||
type = null;
|
||||
|
||||
constructor(type, userId) {
|
||||
@@ -33,6 +41,9 @@ class User {
|
||||
}
|
||||
|
||||
return (async () => {
|
||||
const conn = await new DatabaseConnectionPool();
|
||||
const queryPromises = [];
|
||||
|
||||
for (const type of types) {
|
||||
const sql = `
|
||||
select
|
||||
@@ -48,19 +59,27 @@ class User {
|
||||
${type}Id = ?;
|
||||
`;
|
||||
|
||||
const conn = await new DatabaseConnectionPool();
|
||||
const res =
|
||||
await conn.runQuery(sql, [ userId ]);
|
||||
queryPromises.push(conn.runQuery(sql, [
|
||||
userId
|
||||
]));
|
||||
}
|
||||
|
||||
conn.close();
|
||||
const typeResults = await Promise.all(queryPromises);
|
||||
conn.close();
|
||||
|
||||
if (!res.length)
|
||||
for (const [ i, result ] of typeResults.entries()) {
|
||||
if (!result.length)
|
||||
continue;
|
||||
|
||||
const record = res[0];
|
||||
const record = result[0];
|
||||
const type = types[i];
|
||||
|
||||
for (const [ k, v ] of Object.entries(record))
|
||||
this[k] = v;
|
||||
for (const [ k, v ] of Object.entries(record)) {
|
||||
if (k === 'password')
|
||||
this.#password = v;
|
||||
else
|
||||
this[k] = v;
|
||||
}
|
||||
|
||||
this.type = type;
|
||||
this.shortName = this.getShortName();
|
||||
@@ -70,8 +89,8 @@ class User {
|
||||
return this;
|
||||
|
||||
const className =
|
||||
`${type.substring(0, 1).toUpperCase()}`
|
||||
+ `${type.substring(1)}`;
|
||||
`${type.substring(0, 1).toUpperCase()}`+
|
||||
`${type.substring(1)}`;
|
||||
|
||||
return new (require(`./${className}`))(this.id);
|
||||
}
|
||||
@@ -94,7 +113,7 @@ class User {
|
||||
}
|
||||
|
||||
async verifyPassword(password) {
|
||||
return await bcrypt.compare(password, this.password);
|
||||
return await bcrypt.compare(password, this.#password);
|
||||
}
|
||||
|
||||
async changePassword(password) {
|
||||
@@ -173,7 +192,7 @@ class User {
|
||||
if (this.type === 'parent')
|
||||
throw new Error(`Can not fetch class for ${this.type}`);
|
||||
|
||||
let sql = `
|
||||
const sql = `
|
||||
select
|
||||
c.classId as classId
|
||||
from
|
||||
@@ -243,6 +262,8 @@ class User {
|
||||
const conn = await new DatabaseConnectionPool();
|
||||
const types = [ 'account', 'student', 'parent' ];
|
||||
|
||||
const idPromises = [];
|
||||
|
||||
for (const type of types) {
|
||||
const sql = `
|
||||
select
|
||||
@@ -253,18 +274,24 @@ class User {
|
||||
email = ?;
|
||||
`;
|
||||
|
||||
const id = (await conn.runQuery(sql, [
|
||||
idPromises.push(conn.runQuery(sql, [
|
||||
email
|
||||
]))?.[0]?.['id'];
|
||||
]));
|
||||
}
|
||||
|
||||
const ids = await Promise.all(idPromises);
|
||||
|
||||
for (const [ i, records ] of ids.entries()) {
|
||||
const type = types[i];
|
||||
const id = records?.[0]?.id;
|
||||
|
||||
if (typeof id !== 'undefined') {
|
||||
const className =
|
||||
`${type.substring(0, 1).toUpperCase()}`
|
||||
+ `${type.substring(1)}`;
|
||||
`${type.substring(0, 1).toUpperCase()}`+
|
||||
`${type.substring(1)}`;
|
||||
return new (require(`./${className}`))(id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ describe('DatabaseConnectionPool', () => {
|
||||
expect(() => dbp.runQuery(sql, params)).toThrow();
|
||||
});
|
||||
|
||||
test('Query with whitespace after ; should not fail', ()=> {
|
||||
test('Query with whitespace after ; should not fail', () => {
|
||||
const dbp = new DatabaseConnectionPool();
|
||||
|
||||
const sql = `
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
const helpers = {};
|
||||
|
||||
helpers.eq = (arg1, arg2, options) =>
|
||||
arg1 == arg2 ? options.fn(this) : options.inverse(this);
|
||||
arg1 === arg2 ? options.fn(this) : options.inverse(this);
|
||||
|
||||
module.exports = helpers;
|
||||
|
||||
@@ -38,9 +38,7 @@ function passwordsMatch(password1, password2) {
|
||||
* @return {string} - The sanitisied field
|
||||
*/
|
||||
function sanitiseField(field) {
|
||||
let cleanField;
|
||||
|
||||
cleanField = field.trim();
|
||||
const cleanField = field.trim();
|
||||
|
||||
return cleanField;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user