deepsource-autofix-76c6eb20
Dan Gowans 2023-01-23 13:07:29 -05:00
parent 3b643d15c7
commit a8981e8154
22 changed files with 134 additions and 123 deletions

View File

@ -4,7 +4,7 @@ import { getLotOccupancy } from '../../helpers/lotOccupancyDB/getLotOccupancy.js
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'; import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js';
export async function handler(request, response) { export async function handler(request, response) {
const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId); const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId);
if (!lotOccupancy) { if (lotOccupancy === undefined) {
response.redirect(`${configFunctions.getProperty('reverseProxy.urlPrefix')}/lotOccupancies/?error=lotOccupancyIdNotFound`); response.redirect(`${configFunctions.getProperty('reverseProxy.urlPrefix')}/lotOccupancies/?error=lotOccupancyIdNotFound`);
return; return;
} }

View File

@ -17,7 +17,7 @@ import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'
export async function handler(request: Request, response: Response): Promise<void> { export async function handler(request: Request, response: Response): Promise<void> {
const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId) const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId)
if (!lotOccupancy) { if (lotOccupancy === undefined) {
response.redirect( response.redirect(
`${configFunctions.getProperty( `${configFunctions.getProperty(
'reverseProxy.urlPrefix' 'reverseProxy.urlPrefix'

View File

@ -9,9 +9,9 @@ export async function handler(request, response) {
occupancyStartDate: dateToInteger(startDate), occupancyStartDate: dateToInteger(startDate),
occupancyStartDateString: dateToString(startDate) occupancyStartDateString: dateToString(startDate)
}; };
if (request.query.lotId) { if (request.query.lotId !== undefined) {
const lot = await getLot(request.query.lotId); const lot = await getLot(request.query.lotId);
if (lot) { if (lot !== undefined) {
lotOccupancy.lotId = lot.lotId; lotOccupancy.lotId = lot.lotId;
lotOccupancy.lotName = lot.lotName; lotOccupancy.lotName = lot.lotName;
lotOccupancy.mapId = lot.mapId; lotOccupancy.mapId = lot.mapId;

View File

@ -30,10 +30,10 @@ export async function handler(
occupancyStartDateString: dateToString(startDate) occupancyStartDateString: dateToString(startDate)
} }
if (request.query.lotId) { if (request.query.lotId !== undefined) {
const lot = await getLot(request.query.lotId as string) const lot = await getLot(request.query.lotId as string)
if (lot) { if (lot !== undefined) {
lotOccupancy.lotId = lot.lotId lotOccupancy.lotId = lot.lotId
lotOccupancy.lotName = lot.lotName lotOccupancy.lotName = lot.lotName
lotOccupancy.mapId = lot.mapId lotOccupancy.mapId = lot.mapId

View File

@ -3,7 +3,7 @@ import * as configFunctions from '../../helpers/functions.config.js';
import { getLotOccupancy } from '../../helpers/lotOccupancyDB/getLotOccupancy.js'; import { getLotOccupancy } from '../../helpers/lotOccupancyDB/getLotOccupancy.js';
export async function handler(request, response) { export async function handler(request, response) {
const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId); const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId);
if (!lotOccupancy) { if (lotOccupancy === undefined) {
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') + response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') +
'/lotOccupancies/?error=lotOccupancyIdNotFound'); '/lotOccupancies/?error=lotOccupancyIdNotFound');
return; return;

View File

@ -11,7 +11,7 @@ export async function handler(
): Promise<void> { ): Promise<void> {
const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId) const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId)
if (!lotOccupancy) { if (lotOccupancy === undefined) {
response.redirect( response.redirect(
configFunctions.getProperty('reverseProxy.urlPrefix') + configFunctions.getProperty('reverseProxy.urlPrefix') +
'/lotOccupancies/?error=lotOccupancyIdNotFound' '/lotOccupancies/?error=lotOccupancyIdNotFound'

View File

@ -4,7 +4,7 @@ import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js';
import * as cacheFunctions from '../../helpers/functions.cache.js'; import * as cacheFunctions from '../../helpers/functions.cache.js';
export async function handler(request, response) { export async function handler(request, response) {
const lot = await getLot(request.params.lotId); const lot = await getLot(request.params.lotId);
if (!lot) { if (lot === undefined) {
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') + response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') +
'/lots/?error=lotIdNotFound'); '/lots/?error=lotIdNotFound');
return; return;

View File

@ -12,7 +12,7 @@ export async function handler(
): Promise<void> { ): Promise<void> {
const lot = await getLot(request.params.lotId) const lot = await getLot(request.params.lotId)
if (!lot) { if (lot === undefined) {
response.redirect( response.redirect(
configFunctions.getProperty('reverseProxy.urlPrefix') + configFunctions.getProperty('reverseProxy.urlPrefix') +
'/lots/?error=lotIdNotFound' '/lots/?error=lotIdNotFound'

View File

@ -7,12 +7,12 @@ export async function handler(request, response) {
lotOccupancies: [] lotOccupancies: []
}; };
const maps = await getMaps(); const maps = await getMaps();
if (request.query.mapId) { if (request.query.mapId !== undefined) {
const mapId = Number.parseInt(request.query.mapId, 10); const mapId = Number.parseInt(request.query.mapId, 10);
const map = maps.find((possibleMap) => { const map = maps.find((possibleMap) => {
return mapId === possibleMap.mapId; return mapId === possibleMap.mapId;
}); });
if (map) { if (map !== undefined) {
lot.mapId = map.mapId; lot.mapId = map.mapId;
lot.mapName = map.mapName; lot.mapName = map.mapName;
} }

View File

@ -18,14 +18,14 @@ export async function handler(
const maps = await getMaps() const maps = await getMaps()
if (request.query.mapId) { if (request.query.mapId !== undefined) {
const mapId = Number.parseInt(request.query.mapId as string, 10) const mapId = Number.parseInt(request.query.mapId as string, 10)
const map = maps.find((possibleMap) => { const map = maps.find((possibleMap) => {
return mapId === possibleMap.mapId return mapId === possibleMap.mapId
}) })
if (map) { if (map !== undefined) {
lot.mapId = map.mapId lot.mapId = map.mapId
lot.mapName = map.mapName lot.mapName = map.mapName
} }

View File

@ -8,6 +8,6 @@ export async function handler(request, response) {
'/lots/?error=noNextLotIdFound'); '/lots/?error=noNextLotIdFound');
return; return;
} }
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') + '/lots/' + nextLotId); response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') + '/lots/' + nextLotId.toString());
} }
export default handler; export default handler;

View File

@ -21,7 +21,7 @@ export async function handler(
} }
response.redirect( response.redirect(
configFunctions.getProperty('reverseProxy.urlPrefix') + '/lots/' + nextLotId configFunctions.getProperty('reverseProxy.urlPrefix') + '/lots/' + nextLotId.toString()
) )
} }

View File

@ -10,6 +10,6 @@ export async function handler(request, response) {
} }
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') + response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') +
'/lots/' + '/lots/' +
previousLotId); previousLotId.toString());
} }
export default handler; export default handler;

View File

@ -23,7 +23,7 @@ export async function handler(
response.redirect( response.redirect(
configFunctions.getProperty('reverseProxy.urlPrefix') + configFunctions.getProperty('reverseProxy.urlPrefix') +
'/lots/' + '/lots/' +
previousLotId previousLotId.toString()
) )
} }

View File

@ -17,7 +17,7 @@ export async function moveOccupancyTypeFieldDown(occupancyTypeFieldId) {
' set orderNumber = orderNumber - 1' + ' set orderNumber = orderNumber - 1' +
' where recordDelete_timeMillis is null' + ' where recordDelete_timeMillis is null' +
(currentField.occupancyTypeId (currentField.occupancyTypeId
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'" ? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'"
: ' and occupancyTypeId is null') + : ' and occupancyTypeId is null') +
' and orderNumber = ? + 1') ' and orderNumber = ? + 1')
.run(currentField.orderNumber); .run(currentField.orderNumber);
@ -70,7 +70,7 @@ export async function moveOccupancyTypeFieldUp(occupancyTypeFieldId) {
' set orderNumber = orderNumber + 1' + ' set orderNumber = orderNumber + 1' +
' where recordDelete_timeMillis is null' + ' where recordDelete_timeMillis is null' +
(currentField.occupancyTypeId (currentField.occupancyTypeId
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'" ? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'"
: ' and occupancyTypeId is null') + : ' and occupancyTypeId is null') +
' and orderNumber = ? - 1') ' and orderNumber = ? - 1')
.run(currentField.orderNumber); .run(currentField.orderNumber);

View File

@ -1,5 +1,3 @@
import sqlite from 'better-sqlite3'
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
import type { PoolConnection } from 'better-sqlite-pool' import type { PoolConnection } from 'better-sqlite-pool'
@ -35,7 +33,7 @@ export async function moveOccupancyTypeFieldDown(
' set orderNumber = orderNumber - 1' + ' set orderNumber = orderNumber - 1' +
' where recordDelete_timeMillis is null' + ' where recordDelete_timeMillis is null' +
(currentField.occupancyTypeId (currentField.occupancyTypeId
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'" ? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'"
: ' and occupancyTypeId is null') + : ' and occupancyTypeId is null') +
' and orderNumber = ? + 1' ' and orderNumber = ? + 1'
) )
@ -127,7 +125,7 @@ export async function moveOccupancyTypeFieldUp(
' set orderNumber = orderNumber + 1' + ' set orderNumber = orderNumber + 1' +
' where recordDelete_timeMillis is null' + ' where recordDelete_timeMillis is null' +
(currentField.occupancyTypeId (currentField.occupancyTypeId
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'" ? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'"
: ' and occupancyTypeId is null') + : ' and occupancyTypeId is null') +
' and orderNumber = ? - 1' ' and orderNumber = ? - 1'
) )

View File

@ -4,9 +4,8 @@ import type * as globalTypes from '../types/globalTypes'
;(() => { ;(() => {
const los = exports.los as globalTypes.LOS const los = exports.los as globalTypes.LOS
const workOrderNumberCircleElements: NodeListOf<HTMLElement> = document.querySelectorAll( const workOrderNumberCircleElements: NodeListOf<HTMLElement> =
'.fa-circle[data-work-order-number' document.querySelectorAll('.fa-circle[data-work-order-number')
)
for (const workOrderNumberCircleElement of workOrderNumberCircleElements) { for (const workOrderNumberCircleElement of workOrderNumberCircleElements) {
workOrderNumberCircleElement.style.color = los.getRandomColor( workOrderNumberCircleElement.style.color = los.getRandomColor(

View File

@ -6,11 +6,10 @@ import { getApiKey } from '../helpers/functions.api.js';
import Debug from 'debug'; import Debug from 'debug';
const debug = Debug('lot-occupancy-system:login'); const debug = Debug('lot-occupancy-system:login');
export const router = Router(); export const router = Router();
router function getHandler(request, response) {
.route('/')
.get((request, response) => {
const sessionCookieName = configFunctions.getProperty('session.cookieName'); 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 ?? '')); const redirectURL = authenticationFunctions.getSafeRedirectURL((request.query.redirect ?? ''));
response.redirect(redirectURL); response.redirect(redirectURL);
} }
@ -22,8 +21,8 @@ router
useTestDatabases useTestDatabases
}); });
} }
}) }
.post(async (request, response) => { async function postHandler(request, response) {
const userName = (typeof request.body.userName === 'string' ? request.body.userName : ''); const userName = (typeof request.body.userName === 'string' ? request.body.userName : '');
const passwordPlain = (typeof request.body.password === 'string' ? request.body.password : ''); const passwordPlain = (typeof request.body.password === 'string' ? request.body.password : '');
const unsafeRedirectURL = request.body.redirect; const unsafeRedirectURL = request.body.redirect;
@ -72,7 +71,7 @@ router
}; };
} }
} }
if (isAuthenticated && userObject) { if (isAuthenticated && userObject !== undefined) {
request.session.user = userObject; request.session.user = userObject;
response.redirect(redirectURL); response.redirect(redirectURL);
} }
@ -84,5 +83,9 @@ router
useTestDatabases useTestDatabases
}); });
} }
}); }
router
.route('/')
.get(getHandler)
.post(postHandler);
export default router; export default router;

View File

@ -1,4 +1,4 @@
import { Router } from 'express' import { Router, RequestHandler, Request, Response } from 'express'
import * as configFunctions from '../helpers/functions.config.js' import * as configFunctions from '../helpers/functions.config.js'
@ -16,109 +16,119 @@ const debug = Debug('lot-occupancy-system:login')
export const router = Router() export const router = Router()
router function getHandler(request: Request, response: Response): void {
.route('/') const sessionCookieName = configFunctions.getProperty('session.cookieName')
.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
if (
request.session.user !== undefined &&
request.cookies[sessionCookieName] !== undefined
) {
const redirectURL = authenticationFunctions.getSafeRedirectURL( 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) === '*') { async function postHandler(
if (useTestDatabases && userName === passwordPlain) { request: Request,
isAuthenticated = configFunctions response: Response
.getProperty('users.testing') ): Promise<void> {
.includes(userName) const userName = (
typeof request.body.userName === 'string' ? request.body.userName : ''
) as string
if (isAuthenticated) { const passwordPlain = (
debug('Authenticated testing user: ' + userName) 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) { if (isAuthenticated) {
const userNameLowerCase = userName.toLowerCase() const userNameLowerCase = userName.toLowerCase()
const canLogin = configFunctions const canLogin = configFunctions
.getProperty('users.canLogin') .getProperty('users.canLogin')
.some((currentUserName) => {
return userNameLowerCase === currentUserName.toLowerCase()
})
if (canLogin) {
const canUpdate = configFunctions
.getProperty('users.canUpdate')
.some((currentUserName) => { .some((currentUserName) => {
return userNameLowerCase === currentUserName.toLowerCase() return userNameLowerCase === currentUserName.toLowerCase()
}) })
if (canLogin) { const isAdmin = configFunctions
const canUpdate = configFunctions .getProperty('users.isAdmin')
.getProperty('users.canUpdate') .some((currentUserName) => {
.some((currentUserName) => { return userNameLowerCase === currentUserName.toLowerCase()
return userNameLowerCase === currentUserName.toLowerCase() })
})
const isAdmin = configFunctions const apiKey = await getApiKey(userNameLowerCase)
.getProperty('users.isAdmin')
.some((currentUserName) => {
return userNameLowerCase === currentUserName.toLowerCase()
})
const apiKey = await getApiKey(userNameLowerCase) userObject = {
userName: userNameLowerCase,
userObject = { userProperties: {
userName: userNameLowerCase, canUpdate,
userProperties: { isAdmin,
canUpdate, apiKey
isAdmin,
apiKey
}
} }
} }
} }
}
if (isAuthenticated && userObject) { if (isAuthenticated && userObject !== undefined) {
request.session.user = userObject request.session.user = userObject
response.redirect(redirectURL) response.redirect(redirectURL)
} else { } else {
response.render('login', { response.render('login', {
userName, userName,
message: 'Login Failed', message: 'Login Failed',
redirect: redirectURL, redirect: redirectURL,
useTestDatabases useTestDatabases
}) })
} }
}) }
router
.route('/')
.get(getHandler)
.post(postHandler as RequestHandler)
export default router export default router

View File

@ -108,7 +108,7 @@ async function getMap(dataRow) {
if (!map) { if (!map) {
console.log('Creating map: ' + dataRow.cemetery); console.log('Creating map: ' + dataRow.cemetery);
const mapId = await addMap({ const mapId = await addMap({
mapName: cemeteryToMapName[dataRow.cemetery] || dataRow.cemetery, mapName: cemeteryToMapName[dataRow.cemetery] ?? dataRow.cemetery,
mapDescription: dataRow.cemetery, mapDescription: dataRow.cemetery,
mapSVG: '', mapSVG: '',
mapLatitude: '', mapLatitude: '',

View File

@ -291,7 +291,7 @@ const cemeteryToMapName = {
WK: 'West Korah' 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> { async function getMap(dataRow: { cemetery: string }): Promise<recordTypes.Map> {
const mapCacheKey = dataRow.cemetery const mapCacheKey = dataRow.cemetery
@ -314,7 +314,7 @@ async function getMap(dataRow: { cemetery: string }): Promise<recordTypes.Map> {
const mapId = await addMap( const mapId = await addMap(
{ {
mapName: cemeteryToMapName[dataRow.cemetery] || dataRow.cemetery, mapName: cemeteryToMapName[dataRow.cemetery] ?? dataRow.cemetery,
mapDescription: dataRow.cemetery, mapDescription: dataRow.cemetery,
mapSVG: '', mapSVG: '',
mapLatitude: '', mapLatitude: '',
@ -329,7 +329,7 @@ async function getMap(dataRow: { cemetery: string }): Promise<recordTypes.Map> {
user user
) )
map = await getMapFromDatabase(mapId) map = await getMapFromDatabase(mapId) as recordTypes.Map
} }
mapCache.set(mapCacheKey, map) mapCache.set(mapCacheKey, map)

View File

@ -1,4 +1,5 @@
/* eslint-disable unicorn/no-await-expression-member */ /* eslint-disable unicorn/no-await-expression-member */
import sqlite from 'better-sqlite3' import sqlite from 'better-sqlite3'
import { lotOccupancyDB as databasePath } from '../data/databasePaths.js' import { lotOccupancyDB as databasePath } from '../data/databasePaths.js'
@ -8,7 +9,7 @@ import * as cacheFunctions from '../helpers/functions.cache.js'
* Fee IDs * Fee IDs
*/ */
const feeCache: Map<string, number> = new Map() const feeCache = new Map<string, number>()
export function getFeeIdByFeeDescription(feeDescription: string): number { export function getFeeIdByFeeDescription(feeDescription: string): number {
if (feeCache.keys.length === 0) { if (feeCache.keys.length === 0) {