linting
parent
3b643d15c7
commit
a8981e8154
|
|
@ -4,7 +4,7 @@ import { getLotOccupancy } from '../../helpers/lotOccupancyDB/getLotOccupancy.js
|
|||
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js';
|
||||
export async function handler(request, response) {
|
||||
const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId);
|
||||
if (!lotOccupancy) {
|
||||
if (lotOccupancy === undefined) {
|
||||
response.redirect(`${configFunctions.getProperty('reverseProxy.urlPrefix')}/lotOccupancies/?error=lotOccupancyIdNotFound`);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'
|
|||
export async function handler(request: Request, response: Response): Promise<void> {
|
||||
const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId)
|
||||
|
||||
if (!lotOccupancy) {
|
||||
if (lotOccupancy === undefined) {
|
||||
response.redirect(
|
||||
`${configFunctions.getProperty(
|
||||
'reverseProxy.urlPrefix'
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ export async function handler(request, response) {
|
|||
occupancyStartDate: dateToInteger(startDate),
|
||||
occupancyStartDateString: dateToString(startDate)
|
||||
};
|
||||
if (request.query.lotId) {
|
||||
if (request.query.lotId !== undefined) {
|
||||
const lot = await getLot(request.query.lotId);
|
||||
if (lot) {
|
||||
if (lot !== undefined) {
|
||||
lotOccupancy.lotId = lot.lotId;
|
||||
lotOccupancy.lotName = lot.lotName;
|
||||
lotOccupancy.mapId = lot.mapId;
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ export async function handler(
|
|||
occupancyStartDateString: dateToString(startDate)
|
||||
}
|
||||
|
||||
if (request.query.lotId) {
|
||||
if (request.query.lotId !== undefined) {
|
||||
const lot = await getLot(request.query.lotId as string)
|
||||
|
||||
if (lot) {
|
||||
if (lot !== undefined) {
|
||||
lotOccupancy.lotId = lot.lotId
|
||||
lotOccupancy.lotName = lot.lotName
|
||||
lotOccupancy.mapId = lot.mapId
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as configFunctions from '../../helpers/functions.config.js';
|
|||
import { getLotOccupancy } from '../../helpers/lotOccupancyDB/getLotOccupancy.js';
|
||||
export async function handler(request, response) {
|
||||
const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId);
|
||||
if (!lotOccupancy) {
|
||||
if (lotOccupancy === undefined) {
|
||||
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') +
|
||||
'/lotOccupancies/?error=lotOccupancyIdNotFound');
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export async function handler(
|
|||
): Promise<void> {
|
||||
const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId)
|
||||
|
||||
if (!lotOccupancy) {
|
||||
if (lotOccupancy === undefined) {
|
||||
response.redirect(
|
||||
configFunctions.getProperty('reverseProxy.urlPrefix') +
|
||||
'/lotOccupancies/?error=lotOccupancyIdNotFound'
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js';
|
|||
import * as cacheFunctions from '../../helpers/functions.cache.js';
|
||||
export async function handler(request, response) {
|
||||
const lot = await getLot(request.params.lotId);
|
||||
if (!lot) {
|
||||
if (lot === undefined) {
|
||||
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') +
|
||||
'/lots/?error=lotIdNotFound');
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export async function handler(
|
|||
): Promise<void> {
|
||||
const lot = await getLot(request.params.lotId)
|
||||
|
||||
if (!lot) {
|
||||
if (lot === undefined) {
|
||||
response.redirect(
|
||||
configFunctions.getProperty('reverseProxy.urlPrefix') +
|
||||
'/lots/?error=lotIdNotFound'
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ export async function handler(request, response) {
|
|||
lotOccupancies: []
|
||||
};
|
||||
const maps = await getMaps();
|
||||
if (request.query.mapId) {
|
||||
if (request.query.mapId !== undefined) {
|
||||
const mapId = Number.parseInt(request.query.mapId, 10);
|
||||
const map = maps.find((possibleMap) => {
|
||||
return mapId === possibleMap.mapId;
|
||||
});
|
||||
if (map) {
|
||||
if (map !== undefined) {
|
||||
lot.mapId = map.mapId;
|
||||
lot.mapName = map.mapName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,14 +18,14 @@ export async function handler(
|
|||
|
||||
const maps = await getMaps()
|
||||
|
||||
if (request.query.mapId) {
|
||||
if (request.query.mapId !== undefined) {
|
||||
const mapId = Number.parseInt(request.query.mapId as string, 10)
|
||||
|
||||
const map = maps.find((possibleMap) => {
|
||||
return mapId === possibleMap.mapId
|
||||
})
|
||||
|
||||
if (map) {
|
||||
if (map !== undefined) {
|
||||
lot.mapId = map.mapId
|
||||
lot.mapName = map.mapName
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@ export async function handler(request, response) {
|
|||
'/lots/?error=noNextLotIdFound');
|
||||
return;
|
||||
}
|
||||
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') + '/lots/' + nextLotId);
|
||||
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') + '/lots/' + nextLotId.toString());
|
||||
}
|
||||
export default handler;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export async function handler(
|
|||
}
|
||||
|
||||
response.redirect(
|
||||
configFunctions.getProperty('reverseProxy.urlPrefix') + '/lots/' + nextLotId
|
||||
configFunctions.getProperty('reverseProxy.urlPrefix') + '/lots/' + nextLotId.toString()
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@ export async function handler(request, response) {
|
|||
}
|
||||
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') +
|
||||
'/lots/' +
|
||||
previousLotId);
|
||||
previousLotId.toString());
|
||||
}
|
||||
export default handler;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export async function handler(
|
|||
response.redirect(
|
||||
configFunctions.getProperty('reverseProxy.urlPrefix') +
|
||||
'/lots/' +
|
||||
previousLotId
|
||||
previousLotId.toString()
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export async function moveOccupancyTypeFieldDown(occupancyTypeFieldId) {
|
|||
' set orderNumber = orderNumber - 1' +
|
||||
' where recordDelete_timeMillis is null' +
|
||||
(currentField.occupancyTypeId
|
||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'"
|
||||
: ' and occupancyTypeId is null') +
|
||||
' and orderNumber = ? + 1')
|
||||
.run(currentField.orderNumber);
|
||||
|
|
@ -70,7 +70,7 @@ export async function moveOccupancyTypeFieldUp(occupancyTypeFieldId) {
|
|||
' set orderNumber = orderNumber + 1' +
|
||||
' where recordDelete_timeMillis is null' +
|
||||
(currentField.occupancyTypeId
|
||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'"
|
||||
: ' and occupancyTypeId is null') +
|
||||
' and orderNumber = ? - 1')
|
||||
.run(currentField.orderNumber);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
|
|
@ -35,7 +33,7 @@ export async function moveOccupancyTypeFieldDown(
|
|||
' set orderNumber = orderNumber - 1' +
|
||||
' where recordDelete_timeMillis is null' +
|
||||
(currentField.occupancyTypeId
|
||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'"
|
||||
: ' and occupancyTypeId is null') +
|
||||
' and orderNumber = ? + 1'
|
||||
)
|
||||
|
|
@ -127,7 +125,7 @@ export async function moveOccupancyTypeFieldUp(
|
|||
' set orderNumber = orderNumber + 1' +
|
||||
' where recordDelete_timeMillis is null' +
|
||||
(currentField.occupancyTypeId
|
||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'"
|
||||
: ' and occupancyTypeId is null') +
|
||||
' and orderNumber = ? - 1'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ import type * as globalTypes from '../types/globalTypes'
|
|||
;(() => {
|
||||
const los = exports.los as globalTypes.LOS
|
||||
|
||||
const workOrderNumberCircleElements: NodeListOf<HTMLElement> = document.querySelectorAll(
|
||||
'.fa-circle[data-work-order-number'
|
||||
)
|
||||
const workOrderNumberCircleElements: NodeListOf<HTMLElement> =
|
||||
document.querySelectorAll('.fa-circle[data-work-order-number')
|
||||
|
||||
for (const workOrderNumberCircleElement of workOrderNumberCircleElements) {
|
||||
workOrderNumberCircleElement.style.color = los.getRandomColor(
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@ import { getApiKey } from '../helpers/functions.api.js';
|
|||
import Debug from 'debug';
|
||||
const debug = Debug('lot-occupancy-system:login');
|
||||
export const router = Router();
|
||||
router
|
||||
.route('/')
|
||||
.get((request, response) => {
|
||||
function getHandler(request, response) {
|
||||
const sessionCookieName = configFunctions.getProperty('session.cookieName');
|
||||
if (request.session.user && request.cookies[sessionCookieName]) {
|
||||
if (request.session.user !== undefined &&
|
||||
request.cookies[sessionCookieName] !== undefined) {
|
||||
const redirectURL = authenticationFunctions.getSafeRedirectURL((request.query.redirect ?? ''));
|
||||
response.redirect(redirectURL);
|
||||
}
|
||||
|
|
@ -22,8 +21,8 @@ router
|
|||
useTestDatabases
|
||||
});
|
||||
}
|
||||
})
|
||||
.post(async (request, response) => {
|
||||
}
|
||||
async function postHandler(request, response) {
|
||||
const userName = (typeof request.body.userName === 'string' ? request.body.userName : '');
|
||||
const passwordPlain = (typeof request.body.password === 'string' ? request.body.password : '');
|
||||
const unsafeRedirectURL = request.body.redirect;
|
||||
|
|
@ -72,7 +71,7 @@ router
|
|||
};
|
||||
}
|
||||
}
|
||||
if (isAuthenticated && userObject) {
|
||||
if (isAuthenticated && userObject !== undefined) {
|
||||
request.session.user = userObject;
|
||||
response.redirect(redirectURL);
|
||||
}
|
||||
|
|
@ -84,5 +83,9 @@ router
|
|||
useTestDatabases
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
router
|
||||
.route('/')
|
||||
.get(getHandler)
|
||||
.post(postHandler);
|
||||
export default router;
|
||||
|
|
|
|||
176
routes/login.ts
176
routes/login.ts
|
|
@ -1,4 +1,4 @@
|
|||
import { Router } from 'express'
|
||||
import { Router, RequestHandler, Request, Response } from 'express'
|
||||
|
||||
import * as configFunctions from '../helpers/functions.config.js'
|
||||
|
||||
|
|
@ -16,109 +16,119 @@ const debug = Debug('lot-occupancy-system:login')
|
|||
|
||||
export const router = Router()
|
||||
|
||||
router
|
||||
.route('/')
|
||||
.get((request, response) => {
|
||||
const sessionCookieName = configFunctions.getProperty('session.cookieName')
|
||||
|
||||
if (request.session.user && request.cookies[sessionCookieName]) {
|
||||
const redirectURL = authenticationFunctions.getSafeRedirectURL(
|
||||
(request.query.redirect ?? '') as string
|
||||
)
|
||||
|
||||
response.redirect(redirectURL)
|
||||
} else {
|
||||
response.render('login', {
|
||||
userName: '',
|
||||
message: '',
|
||||
redirect: request.query.redirect,
|
||||
useTestDatabases
|
||||
})
|
||||
}
|
||||
})
|
||||
.post(async (request, response) => {
|
||||
const userName = (
|
||||
typeof request.body.userName === 'string' ? request.body.userName : ''
|
||||
) as string
|
||||
|
||||
const passwordPlain = (
|
||||
typeof request.body.password === 'string' ? request.body.password : ''
|
||||
) as string
|
||||
|
||||
const unsafeRedirectURL = request.body.redirect
|
||||
function getHandler(request: Request, response: Response): void {
|
||||
const sessionCookieName = configFunctions.getProperty('session.cookieName')
|
||||
|
||||
if (
|
||||
request.session.user !== undefined &&
|
||||
request.cookies[sessionCookieName] !== undefined
|
||||
) {
|
||||
const redirectURL = authenticationFunctions.getSafeRedirectURL(
|
||||
typeof unsafeRedirectURL === 'string' ? unsafeRedirectURL : ''
|
||||
(request.query.redirect ?? '') as string
|
||||
)
|
||||
|
||||
let isAuthenticated = false
|
||||
response.redirect(redirectURL)
|
||||
} else {
|
||||
response.render('login', {
|
||||
userName: '',
|
||||
message: '',
|
||||
redirect: request.query.redirect,
|
||||
useTestDatabases
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (userName.charAt(0) === '*') {
|
||||
if (useTestDatabases && userName === passwordPlain) {
|
||||
isAuthenticated = configFunctions
|
||||
.getProperty('users.testing')
|
||||
.includes(userName)
|
||||
async function postHandler(
|
||||
request: Request,
|
||||
response: Response
|
||||
): Promise<void> {
|
||||
const userName = (
|
||||
typeof request.body.userName === 'string' ? request.body.userName : ''
|
||||
) as string
|
||||
|
||||
if (isAuthenticated) {
|
||||
debug('Authenticated testing user: ' + userName)
|
||||
}
|
||||
const passwordPlain = (
|
||||
typeof request.body.password === 'string' ? request.body.password : ''
|
||||
) as string
|
||||
|
||||
const unsafeRedirectURL = request.body.redirect
|
||||
|
||||
const redirectURL = authenticationFunctions.getSafeRedirectURL(
|
||||
typeof unsafeRedirectURL === 'string' ? unsafeRedirectURL : ''
|
||||
)
|
||||
|
||||
let isAuthenticated = false
|
||||
|
||||
if (userName.charAt(0) === '*') {
|
||||
if (useTestDatabases && userName === passwordPlain) {
|
||||
isAuthenticated = configFunctions
|
||||
.getProperty('users.testing')
|
||||
.includes(userName)
|
||||
|
||||
if (isAuthenticated) {
|
||||
debug('Authenticated testing user: ' + userName)
|
||||
}
|
||||
} else if (userName !== '' && passwordPlain !== '') {
|
||||
isAuthenticated = await authenticationFunctions.authenticate(
|
||||
userName,
|
||||
passwordPlain
|
||||
)
|
||||
}
|
||||
} else if (userName !== '' && passwordPlain !== '') {
|
||||
isAuthenticated = await authenticationFunctions.authenticate(
|
||||
userName,
|
||||
passwordPlain
|
||||
)
|
||||
}
|
||||
|
||||
let userObject: recordTypes.User | undefined
|
||||
let userObject: recordTypes.User | undefined
|
||||
|
||||
if (isAuthenticated) {
|
||||
const userNameLowerCase = userName.toLowerCase()
|
||||
if (isAuthenticated) {
|
||||
const userNameLowerCase = userName.toLowerCase()
|
||||
|
||||
const canLogin = configFunctions
|
||||
.getProperty('users.canLogin')
|
||||
const canLogin = configFunctions
|
||||
.getProperty('users.canLogin')
|
||||
.some((currentUserName) => {
|
||||
return userNameLowerCase === currentUserName.toLowerCase()
|
||||
})
|
||||
|
||||
if (canLogin) {
|
||||
const canUpdate = configFunctions
|
||||
.getProperty('users.canUpdate')
|
||||
.some((currentUserName) => {
|
||||
return userNameLowerCase === currentUserName.toLowerCase()
|
||||
})
|
||||
|
||||
if (canLogin) {
|
||||
const canUpdate = configFunctions
|
||||
.getProperty('users.canUpdate')
|
||||
.some((currentUserName) => {
|
||||
return userNameLowerCase === currentUserName.toLowerCase()
|
||||
})
|
||||
const isAdmin = configFunctions
|
||||
.getProperty('users.isAdmin')
|
||||
.some((currentUserName) => {
|
||||
return userNameLowerCase === currentUserName.toLowerCase()
|
||||
})
|
||||
|
||||
const isAdmin = configFunctions
|
||||
.getProperty('users.isAdmin')
|
||||
.some((currentUserName) => {
|
||||
return userNameLowerCase === currentUserName.toLowerCase()
|
||||
})
|
||||
const apiKey = await getApiKey(userNameLowerCase)
|
||||
|
||||
const apiKey = await getApiKey(userNameLowerCase)
|
||||
|
||||
userObject = {
|
||||
userName: userNameLowerCase,
|
||||
userProperties: {
|
||||
canUpdate,
|
||||
isAdmin,
|
||||
apiKey
|
||||
}
|
||||
userObject = {
|
||||
userName: userNameLowerCase,
|
||||
userProperties: {
|
||||
canUpdate,
|
||||
isAdmin,
|
||||
apiKey
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isAuthenticated && userObject) {
|
||||
request.session.user = userObject
|
||||
if (isAuthenticated && userObject !== undefined) {
|
||||
request.session.user = userObject
|
||||
|
||||
response.redirect(redirectURL)
|
||||
} else {
|
||||
response.render('login', {
|
||||
userName,
|
||||
message: 'Login Failed',
|
||||
redirect: redirectURL,
|
||||
useTestDatabases
|
||||
})
|
||||
}
|
||||
})
|
||||
response.redirect(redirectURL)
|
||||
} else {
|
||||
response.render('login', {
|
||||
userName,
|
||||
message: 'Login Failed',
|
||||
redirect: redirectURL,
|
||||
useTestDatabases
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
router
|
||||
.route('/')
|
||||
.get(getHandler)
|
||||
.post(postHandler as RequestHandler)
|
||||
|
||||
export default router
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ async function getMap(dataRow) {
|
|||
if (!map) {
|
||||
console.log('Creating map: ' + dataRow.cemetery);
|
||||
const mapId = await addMap({
|
||||
mapName: cemeteryToMapName[dataRow.cemetery] || dataRow.cemetery,
|
||||
mapName: cemeteryToMapName[dataRow.cemetery] ?? dataRow.cemetery,
|
||||
mapDescription: dataRow.cemetery,
|
||||
mapSVG: '',
|
||||
mapLatitude: '',
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ const cemeteryToMapName = {
|
|||
WK: 'West Korah'
|
||||
}
|
||||
|
||||
const mapCache: Map<string, recordTypes.Map> = new Map()
|
||||
const mapCache = new Map<string, recordTypes.Map>()
|
||||
|
||||
async function getMap(dataRow: { cemetery: string }): Promise<recordTypes.Map> {
|
||||
const mapCacheKey = dataRow.cemetery
|
||||
|
|
@ -314,7 +314,7 @@ async function getMap(dataRow: { cemetery: string }): Promise<recordTypes.Map> {
|
|||
|
||||
const mapId = await addMap(
|
||||
{
|
||||
mapName: cemeteryToMapName[dataRow.cemetery] || dataRow.cemetery,
|
||||
mapName: cemeteryToMapName[dataRow.cemetery] ?? dataRow.cemetery,
|
||||
mapDescription: dataRow.cemetery,
|
||||
mapSVG: '',
|
||||
mapLatitude: '',
|
||||
|
|
@ -329,7 +329,7 @@ async function getMap(dataRow: { cemetery: string }): Promise<recordTypes.Map> {
|
|||
user
|
||||
)
|
||||
|
||||
map = await getMapFromDatabase(mapId)
|
||||
map = await getMapFromDatabase(mapId) as recordTypes.Map
|
||||
}
|
||||
|
||||
mapCache.set(mapCacheKey, map)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
/* eslint-disable unicorn/no-await-expression-member */
|
||||
|
||||
import sqlite from 'better-sqlite3'
|
||||
import { lotOccupancyDB as databasePath } from '../data/databasePaths.js'
|
||||
|
||||
|
|
@ -8,7 +9,7 @@ import * as cacheFunctions from '../helpers/functions.cache.js'
|
|||
* Fee IDs
|
||||
*/
|
||||
|
||||
const feeCache: Map<string, number> = new Map()
|
||||
const feeCache = new Map<string, number>()
|
||||
|
||||
export function getFeeIdByFeeDescription(feeDescription: string): number {
|
||||
if (feeCache.keys.length === 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue