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';
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;
}

View File

@ -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'

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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'

View File

@ -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;

View File

@ -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'

View File

@ -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;
}

View File

@ -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
}

View File

@ -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;

View File

@ -21,7 +21,7 @@ export async function handler(
}
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') +
'/lots/' +
previousLotId);
previousLotId.toString());
}
export default handler;

View File

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

View File

@ -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);

View File

@ -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'
)

View File

@ -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(

View File

@ -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;

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'
@ -16,12 +16,13 @@ const debug = Debug('lot-occupancy-system:login')
export const router = Router()
router
.route('/')
.get((request, response) => {
function getHandler(request: Request, response: Response): void {
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 ?? '') as string
)
@ -35,8 +36,12 @@ router
useTestDatabases
})
}
})
.post(async (request, response) => {
}
async function postHandler(
request: Request,
response: Response
): Promise<void> {
const userName = (
typeof request.body.userName === 'string' ? request.body.userName : ''
) as string
@ -107,7 +112,7 @@ router
}
}
if (isAuthenticated && userObject) {
if (isAuthenticated && userObject !== undefined) {
request.session.user = userObject
response.redirect(redirectURL)
@ -119,6 +124,11 @@ router
useTestDatabases
})
}
})
}
router
.route('/')
.get(getHandler)
.post(postHandler as RequestHandler)
export default router

View File

@ -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: '',

View File

@ -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)

View File

@ -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) {