Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
- rename getConfigProperty() function
- pass user object to db functions instead of session
- fix pdf print issue
  • Loading branch information
dangowans committed May 23, 2024
1 parent 5202483 commit 3a6d6e3
Show file tree
Hide file tree
Showing 245 changed files with 905 additions and 1,286 deletions.
18 changes: 9 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import { version } from './version.js';
const debugApp = debug('general-licence-manager:app');
databaseInitializer.initLicencesDB();
export const app = express();
if (!configFunctions.getProperty('reverseProxy.disableEtag')) {
if (!configFunctions.getConfigProperty('reverseProxy.disableEtag')) {
app.set('etag', false);
}
app.set('views', path.join('views'));
app.set('view engine', 'ejs');
if (!configFunctions.getProperty('reverseProxy.disableCompression')) {
if (!configFunctions.getConfigProperty('reverseProxy.disableCompression')) {
app.use(compression());
}
app.use((request, _response, next) => {
Expand All @@ -43,18 +43,18 @@ app.use(cookieParser());
app.use(csurf({ cookie: true }));
const limiter = rateLimit({
windowMs: 1000,
max: 25 * Math.max(3, configFunctions.getProperty('users.canLogin').length)
max: 25 * Math.max(3, configFunctions.getConfigProperty('users.canLogin').length)
});
app.use(limiter);
const urlPrefix = configFunctions.getProperty('reverseProxy.urlPrefix');
const urlPrefix = configFunctions.getConfigProperty('reverseProxy.urlPrefix');
if (urlPrefix !== '') {
debugApp('urlPrefix = ' + urlPrefix);
}
app.use(urlPrefix, express.static(path.join('public')));
app.use(urlPrefix + '/lib/fa', express.static(path.join('node_modules', '@fortawesome', 'fontawesome-free')));
app.use(urlPrefix + '/lib/cityssm-bulma-webapp-js', express.static(path.join('node_modules', '@cityssm', 'bulma-webapp-js')));
app.use(urlPrefix + '/lib/cityssm-bulma-js', express.static(path.join('node_modules', '@cityssm', 'bulma-js', 'dist')));
const sessionCookieName = configFunctions.getProperty('session.cookieName');
const sessionCookieName = configFunctions.getConfigProperty('session.cookieName');
const FileStoreSession = FileStore(session);
app.use(session({
store: new FileStoreSession({
Expand All @@ -63,12 +63,12 @@ app.use(session({
retries: 20
}),
name: sessionCookieName,
secret: configFunctions.getProperty('session.secret'),
secret: configFunctions.getConfigProperty('session.secret'),
resave: true,
saveUninitialized: false,
rolling: true,
cookie: {
maxAge: configFunctions.getProperty('session.maxAgeMillis'),
maxAge: configFunctions.getConfigProperty('session.maxAgeMillis'),
sameSite: 'strict'
}
}));
Expand All @@ -93,15 +93,15 @@ app.use((request, response, next) => {
response.locals.dateTimeFns = dateTimeFns;
response.locals.stringFns = stringFns;
response.locals.htmlFns = htmlFns;
response.locals.urlPrefix = configFunctions.getProperty('reverseProxy.urlPrefix');
response.locals.urlPrefix = configFunctions.getConfigProperty('reverseProxy.urlPrefix');
next();
});
app.get(`${urlPrefix}/`, sessionChecker, (_request, response) => {
response.redirect(`${urlPrefix}/dashboard`);
});
app.use(`${urlPrefix}/dashboard`, sessionChecker, routerDashboard);
app.use(`${urlPrefix}/licences`, sessionChecker, routerLicences);
if (configFunctions.getProperty('settings.includeBatches')) {
if (configFunctions.getConfigProperty('settings.includeBatches')) {
app.use(`${urlPrefix}/batches`, sessionChecker, routerBatches);
}
app.use(`${urlPrefix}/reports`, sessionChecker, routerReports);
Expand Down
18 changes: 9 additions & 9 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ databaseInitializer.initLicencesDB()

export const app = express()

if (!configFunctions.getProperty('reverseProxy.disableEtag')) {
if (!configFunctions.getConfigProperty('reverseProxy.disableEtag')) {
app.set('etag', false)
}

// View engine setup
app.set('views', path.join('views'))
app.set('view engine', 'ejs')

if (!configFunctions.getProperty('reverseProxy.disableCompression')) {
if (!configFunctions.getConfigProperty('reverseProxy.disableCompression')) {
app.use(compression())
}

Expand All @@ -71,7 +71,7 @@ app.use(csurf({ cookie: true }))

const limiter = rateLimit({
windowMs: 1000,
max: 25 * Math.max(3, configFunctions.getProperty('users.canLogin').length)
max: 25 * Math.max(3, configFunctions.getConfigProperty('users.canLogin').length)
})

app.use(limiter)
Expand All @@ -80,7 +80,7 @@ app.use(limiter)
* STATIC ROUTES
*/

const urlPrefix = configFunctions.getProperty('reverseProxy.urlPrefix')
const urlPrefix = configFunctions.getConfigProperty('reverseProxy.urlPrefix')

if (urlPrefix !== '') {
debugApp('urlPrefix = ' + urlPrefix)
Expand Down Expand Up @@ -108,7 +108,7 @@ app.use(
*/

const sessionCookieName: string =
configFunctions.getProperty('session.cookieName')
configFunctions.getConfigProperty('session.cookieName')

const FileStoreSession = FileStore(session)

Expand All @@ -121,12 +121,12 @@ app.use(
retries: 20
}),
name: sessionCookieName,
secret: configFunctions.getProperty('session.secret'),
secret: configFunctions.getConfigProperty('session.secret'),
resave: true,
saveUninitialized: false,
rolling: true,
cookie: {
maxAge: configFunctions.getProperty('session.maxAgeMillis'),
maxAge: configFunctions.getConfigProperty('session.maxAgeMillis'),
sameSite: 'strict'
}
})
Expand Down Expand Up @@ -172,7 +172,7 @@ app.use((request, response, next) => {
response.locals.stringFns = stringFns
response.locals.htmlFns = htmlFns

response.locals.urlPrefix = configFunctions.getProperty(
response.locals.urlPrefix = configFunctions.getConfigProperty(
'reverseProxy.urlPrefix'
)

Expand All @@ -186,7 +186,7 @@ app.get(`${urlPrefix}/`, sessionChecker, (_request, response) => {
app.use(`${urlPrefix}/dashboard`, sessionChecker, routerDashboard)
app.use(`${urlPrefix}/licences`, sessionChecker, routerLicences)

if (configFunctions.getProperty('settings.includeBatches')) {
if (configFunctions.getConfigProperty('settings.includeBatches')) {
app.use(`${urlPrefix}/batches`, sessionChecker, routerBatches)
}

Expand Down
2 changes: 1 addition & 1 deletion bin/www.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function onListening(server) {
debug(`Listening on ${bind}`);
}
}
const httpPort = configFunctions.getProperty('application.httpPort');
const httpPort = configFunctions.getConfigProperty('application.httpPort');
const httpServer = http.createServer(app);
httpServer.listen(httpPort);
httpServer.on('error', onError);
Expand Down
2 changes: 1 addition & 1 deletion bin/www.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function onListening(server: http.Server): void {
* Initialize HTTP
*/

const httpPort = configFunctions.getProperty('application.httpPort')
const httpPort = configFunctions.getConfigProperty('application.httpPort')

const httpServer = http.createServer(app)

Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/02-update/licences.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ describe('Update - Licences', () => {
cy.checkA11y();
cy.get("select[name='licenceCategoryKey']").select(0);
cy.get("input[name='baseLicenceFee']").should('have.value', '');
if (configFunctions.getProperty('settings.includeReplacementFee')) {
if (configFunctions.getConfigProperty('settings.includeReplacementFee')) {
cy.get("input[name='baseReplacementFee']").should('have.value', '');
}
cy.get("select[name='licenceCategoryKey'] option").should('have.lengthOf.gt', 1);
cy.get("select[name='licenceCategoryKey']").select(1);
cy.get("input[name='baseLicenceFee']").should('not.have.value', '');
if (configFunctions.getProperty('settings.includeReplacementFee')) {
if (configFunctions.getConfigProperty('settings.includeReplacementFee')) {
cy.get("input[name='baseReplacementFee']").should('not.have.value', '');
}
cy.get("input[name='licenceNumber']").should('have.attr', 'readonly');
Expand Down Expand Up @@ -70,8 +70,8 @@ describe('Update - Licences', () => {
}
});
});
cy.get("input[name='licenseeCity']").should('have.value', configFunctions.getProperty('defaults.licenseeCity'));
cy.get("input[name='licenseeProvince']").should('have.value', configFunctions.getProperty('defaults.licenseeProvince'));
cy.get("input[name='licenseeCity']").should('have.value', configFunctions.getConfigProperty('defaults.licenseeCity'));
cy.get("input[name='licenseeProvince']").should('have.value', configFunctions.getConfigProperty('defaults.licenseeProvince'));
cy.get("input[name^='field--']").each(($fieldElement, index) => {
$fieldElement.val('Field ' + index);
});
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/02-update/licences.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Update - Licences', () => {

cy.get("input[name='baseLicenceFee']").should('have.value', '')

if (configFunctions.getProperty('settings.includeReplacementFee')) {
if (configFunctions.getConfigProperty('settings.includeReplacementFee')) {
cy.get("input[name='baseReplacementFee']").should('have.value', '')
}

Expand All @@ -50,7 +50,7 @@ describe('Update - Licences', () => {

cy.get("input[name='baseLicenceFee']").should('not.have.value', '')

if (configFunctions.getProperty('settings.includeReplacementFee')) {
if (configFunctions.getConfigProperty('settings.includeReplacementFee')) {
cy.get("input[name='baseReplacementFee']").should('not.have.value', '')
}

Expand Down Expand Up @@ -117,12 +117,12 @@ describe('Update - Licences', () => {

cy.get("input[name='licenseeCity']").should(
'have.value',
configFunctions.getProperty('defaults.licenseeCity')
configFunctions.getConfigProperty('defaults.licenseeCity')
)

cy.get("input[name='licenseeProvince']").should(
'have.value',
configFunctions.getProperty('defaults.licenseeProvince')
configFunctions.getConfigProperty('defaults.licenseeProvince')
)

cy.get("input[name^='field--']").each(($fieldElement, index) => {
Expand Down
38 changes: 38 additions & 0 deletions data/config.defaultValues.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { ADWebAuthConfig } from '@cityssm/ad-web-auth-connector';
import type { AdditionalFeeFunction, ConfigActiveDirectory, ConfigBatchExport, LicenceLengthFunction, LicenceNumberFunction, ReportDefinition } from '../types/configTypes.js';
export declare const configDefaultValues: {
activeDirectory: ConfigActiveDirectory | undefined;
adWebAuthConfig: ADWebAuthConfig | undefined;
'application.applicationName': string;
'application.logoURL': string;
'application.httpPort': number;
'application.userDomain': string;
'application.useTestDatabases': boolean;
'reverseProxy.disableCompression': boolean;
'reverseProxy.disableEtag': boolean;
'reverseProxy.urlPrefix': string;
'session.cookieName': string;
'session.secret': string;
'session.maxAgeMillis': number;
'session.doKeepAlive': boolean;
'users.testing': string[];
'users.canLogin': string[];
'users.canUpdate': string[];
'users.isAdmin': string[];
'defaults.licenceNumberFunction': LicenceNumberFunction;
'defaults.licenseeCity': string;
'defaults.licenseeProvince': string;
'settings.licenceAlias': string;
'settings.licenceAliasPlural': string;
'settings.licenseeAlias': string;
'settings.licenseeAliasPlural': string;
'settings.renewalAlias': string;
'settings.includeRelated': boolean;
'settings.includeBatches': boolean;
'settings.includeReplacementFee': boolean;
'settings.includeYearEnd': boolean;
'exports.batches': ConfigBatchExport | undefined;
licenceLengthFunctions: Record<string, LicenceLengthFunction>;
additionalFeeFunctions: Record<string, AdditionalFeeFunction>;
customReports: ReportDefinition[];
};
36 changes: 36 additions & 0 deletions data/config.defaultValues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export const configDefaultValues = {
activeDirectory: undefined,
adWebAuthConfig: undefined,
'application.applicationName': 'General Licence Manager',
'application.logoURL': '/images/stamp.png',
'application.httpPort': 7000,
'application.userDomain': '',
'application.useTestDatabases': false,
'reverseProxy.disableCompression': false,
'reverseProxy.disableEtag': false,
'reverseProxy.urlPrefix': '',
'session.cookieName': 'general-licence-manager-user-sid',
'session.secret': 'cityssm/general-licence-manager',
'session.maxAgeMillis': 60 * 60 * 1000,
'session.doKeepAlive': false,
'users.testing': [],
'users.canLogin': ['administrator'],
'users.canUpdate': [],
'users.isAdmin': ['administrator'],
'defaults.licenceNumberFunction': 'year-fourDigits',
'defaults.licenseeCity': '',
'defaults.licenseeProvince': 'ON',
'settings.licenceAlias': 'Licence',
'settings.licenceAliasPlural': 'Licences',
'settings.licenseeAlias': 'Licensee',
'settings.licenseeAliasPlural': 'Licensees',
'settings.renewalAlias': 'Renewal',
'settings.includeRelated': true,
'settings.includeBatches': false,
'settings.includeReplacementFee': true,
'settings.includeYearEnd': false,
'exports.batches': undefined,
licenceLengthFunctions: {},
additionalFeeFunctions: {},
customReports: []
};
64 changes: 64 additions & 0 deletions data/config.defaultValues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/indent */

import type { ADWebAuthConfig } from '@cityssm/ad-web-auth-connector'

import type {
AdditionalFeeFunction,
ConfigActiveDirectory,
ConfigBatchExport,
LicenceLengthFunction,
LicenceNumberFunction,
ReportDefinition
} from '../types/configTypes.js'

export const configDefaultValues = {
activeDirectory: undefined as unknown as ConfigActiveDirectory | undefined,
adWebAuthConfig: undefined as unknown as ADWebAuthConfig | undefined,

'application.applicationName': 'General Licence Manager',
'application.logoURL': '/images/stamp.png',
'application.httpPort': 7000,
'application.userDomain': '',
'application.useTestDatabases': false,

'reverseProxy.disableCompression': false,
'reverseProxy.disableEtag': false,
'reverseProxy.urlPrefix': '',

'session.cookieName': 'general-licence-manager-user-sid',
'session.secret': 'cityssm/general-licence-manager',
'session.maxAgeMillis': 60 * 60 * 1000,
'session.doKeepAlive': false,

'users.testing': [] as string[],
'users.canLogin': ['administrator'],
'users.canUpdate': [] as string[],
'users.isAdmin': ['administrator'],

'defaults.licenceNumberFunction': 'year-fourDigits' as LicenceNumberFunction,
'defaults.licenseeCity': '',
'defaults.licenseeProvince': 'ON',

'settings.licenceAlias': 'Licence',
'settings.licenceAliasPlural': 'Licences',
'settings.licenseeAlias': 'Licensee',
'settings.licenseeAliasPlural': 'Licensees',
'settings.renewalAlias': 'Renewal',
'settings.includeRelated': true,
'settings.includeBatches': false,
'settings.includeReplacementFee': true,
'settings.includeYearEnd': false,

'exports.batches': undefined as unknown as ConfigBatchExport | undefined,

licenceLengthFunctions: {} as unknown as Record<
string,
LicenceLengthFunction
>,
additionalFeeFunctions: {} as unknown as Record<
string,
AdditionalFeeFunction
>,
customReports: [] as ReportDefinition[]
}
2 changes: 1 addition & 1 deletion data/databasePaths.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Debug from 'debug';
import * as configFunctions from '../helpers/functions.config.js';
const debug = Debug('general-licence-manager:databasePaths');
export const useTestDatabases = configFunctions.getProperty('application.useTestDatabases') ||
export const useTestDatabases = configFunctions.getConfigProperty('application.useTestDatabases') ||
process.env.TEST_DATABASES === 'true';
if (useTestDatabases) {
debug('Using "-testing" databases.');
Expand Down
2 changes: 1 addition & 1 deletion data/databasePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const debug = Debug('general-licence-manager:databasePaths')
// Determine if test databases should be used

export const useTestDatabases =
configFunctions.getProperty('application.useTestDatabases') ||
configFunctions.getConfigProperty('application.useTestDatabases') ||
process.env.TEST_DATABASES === 'true'

if (useTestDatabases) {
Expand Down
2 changes: 1 addition & 1 deletion exports/batchExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function getBatchExport(batchDate) {
if (outstandingBatchTransactions.length === 0) {
return undefined;
}
const batchExportConfig = configFunctions.getProperty('exports.batches');
const batchExportConfig = configFunctions.getConfigProperty('exports.batches');
if (!batchExportConfig) {
return undefined;
}
Expand Down
Loading

0 comments on commit 3a6d6e3

Please sign in to comment.