code cleanup

deepsource-autofix-76c6eb20
Dan Gowans 2023-11-29 13:44:56 -05:00
parent 4a529fad3c
commit 92458596c8
31 changed files with 57 additions and 81 deletions

View File

@ -1,7 +1,4 @@
/* eslint-disable unicorn/filename-case, promise/catch-or-return, promise/always-return */
import { testAdmin } from '../../../test/_globals.js' import { testAdmin } from '../../../test/_globals.js'
import { logout, login } from '../../support/index.js' import { logout, login } from '../../support/index.js'
describe('Admin - Config Table Management', () => { describe('Admin - Config Table Management', () => {

View File

@ -1,6 +1,6 @@
import * as configFunctions from '../../../helpers/functions.config.js';
import { testUpdate } from '../../../test/_globals.js'; import { testUpdate } from '../../../test/_globals.js';
import { logout, login } from '../../support/index.js'; import { logout, login } from '../../support/index.js';
import * as configFunctions from '../../../helpers/functions.config.js';
describe('Update - Maps', () => { describe('Update - Maps', () => {
beforeEach('Loads page', () => { beforeEach('Loads page', () => {
logout(); logout();

View File

@ -1,12 +1,10 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/no-non-null-assertion */
import { testUpdate } from '../../../test/_globals.js'
import { logout, login } from '../../support/index.js'
import * as configFunctions from '../../../helpers/functions.config.js' import * as configFunctions from '../../../helpers/functions.config.js'
import { testUpdate } from '../../../test/_globals.js'
import type * as recordTypes from '../../../types/recordTypes' import type { MapRecord } from '../../../types/recordTypes.js'
import { logout, login } from '../../support/index.js'
describe('Update - Maps', () => { describe('Update - Maps', () => {
beforeEach('Loads page', () => { beforeEach('Loads page', () => {
@ -33,7 +31,7 @@ describe('Update - Maps', () => {
cy.log('Populate the fields') cy.log('Populate the fields')
// eslint-disable-next-line promise/catch-or-return, promise/always-return // eslint-disable-next-line promise/catch-or-return, promise/always-return
cy.fixture('map.json').then((mapJSON: recordTypes.Map) => { cy.fixture('map.json').then((mapJSON: MapRecord) => {
cy.get("input[name='mapName']").clear().type(mapJSON.mapName!) cy.get("input[name='mapName']").clear().type(mapJSON.mapName!)
cy.get("textarea[name='mapDescription']") cy.get("textarea[name='mapDescription']")
.clear() .clear()
@ -77,7 +75,7 @@ describe('Update - Maps', () => {
.should('contain', '/edit') .should('contain', '/edit')
// eslint-disable-next-line promise/catch-or-return, promise/always-return // eslint-disable-next-line promise/catch-or-return, promise/always-return
cy.fixture('map.json').then((mapJSON: recordTypes.Map) => { cy.fixture('map.json').then((mapJSON: MapRecord) => {
cy.get("input[name='mapName']").should('have.value', mapJSON.mapName) cy.get("input[name='mapName']").should('have.value', mapJSON.mapName)
cy.get("textarea[name='mapDescription']").should( cy.get("textarea[name='mapDescription']").should(
'have.value', 'have.value',

View File

@ -1,7 +1,7 @@
import * as cacheFunctions from '../../helpers/functions.cache.js';
import * as configFunctions from '../../helpers/functions.config.js'; import * as configFunctions from '../../helpers/functions.config.js';
import { getLot } from '../../helpers/lotOccupancyDB/getLot.js'; import { getLot } from '../../helpers/lotOccupancyDB/getLot.js';
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'; import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.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 === undefined) { if (lot === undefined) {

View File

@ -1,10 +1,9 @@
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import * as cacheFunctions from '../../helpers/functions.cache.js'
import * as configFunctions from '../../helpers/functions.config.js' import * as configFunctions from '../../helpers/functions.config.js'
import { getLot } from '../../helpers/lotOccupancyDB/getLot.js' import { getLot } from '../../helpers/lotOccupancyDB/getLot.js'
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js' import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'
import * as cacheFunctions from '../../helpers/functions.cache.js'
export async function handler( export async function handler(
request: Request, request: Request,

View File

@ -1,6 +1,6 @@
import * as cacheFunctions from '../../helpers/functions.cache.js';
import * as configFunctions from '../../helpers/functions.config.js'; import * as configFunctions from '../../helpers/functions.config.js';
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'; import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js';
import * as cacheFunctions from '../../helpers/functions.cache.js';
export async function handler(request, response) { export async function handler(request, response) {
const lot = { const lot = {
lotId: -1, lotId: -1,

View File

@ -1,17 +1,15 @@
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js'
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'
import * as cacheFunctions from '../../helpers/functions.cache.js' import * as cacheFunctions from '../../helpers/functions.cache.js'
import * as configFunctions from '../../helpers/functions.config.js'
import type * as recordTypes from '../../types/recordTypes' import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'
import type { Lot } from '../../types/recordTypes.js'
export async function handler( export async function handler(
request: Request, request: Request,
response: Response response: Response
): Promise<void> { ): Promise<void> {
const lot: recordTypes.Lot = { const lot: Lot = {
lotId: -1, lotId: -1,
lotOccupancies: [] lotOccupancies: []
} }

View File

@ -1,7 +1,6 @@
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js' import * as configFunctions from '../../helpers/functions.config.js'
import { getNextLotId } from '../../helpers/functions.lots.js' import { getNextLotId } from '../../helpers/functions.lots.js'
export async function handler( export async function handler(

View File

@ -1,7 +1,6 @@
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js' import * as configFunctions from '../../helpers/functions.config.js'
import { getPreviousLotId } from '../../helpers/functions.lots.js' import { getPreviousLotId } from '../../helpers/functions.lots.js'
export async function handler( export async function handler(

View File

@ -1,6 +1,6 @@
import { getLotTypes, getLotStatuses } from '../../helpers/functions.cache.js';
import * as configFunctions from '../../helpers/functions.config.js'; import * as configFunctions from '../../helpers/functions.config.js';
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'; import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js';
import { getLotTypes, getLotStatuses } from '../../helpers/functions.cache.js';
export async function handler(request, response) { export async function handler(request, response) {
const maps = await getMaps(); const maps = await getMaps();
const lotTypes = await getLotTypes(); const lotTypes = await getLotTypes();

View File

@ -1,10 +1,8 @@
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js'
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'
import { getLotTypes, getLotStatuses } from '../../helpers/functions.cache.js' import { getLotTypes, getLotStatuses } from '../../helpers/functions.cache.js'
import * as configFunctions from '../../helpers/functions.config.js'
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'
export async function handler( export async function handler(
request: Request, request: Request,

View File

@ -2,7 +2,6 @@ import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js' import * as configFunctions from '../../helpers/functions.config.js'
import { getNextLotId, getPreviousLotId } from '../../helpers/functions.lots.js' import { getNextLotId, getPreviousLotId } from '../../helpers/functions.lots.js'
import { getLot } from '../../helpers/lotOccupancyDB/getLot.js' import { getLot } from '../../helpers/lotOccupancyDB/getLot.js'
export async function handler( export async function handler(

View File

@ -1,8 +1,8 @@
import * as configFunctions from '../../helpers/functions.config.js'; import * as configFunctions from '../../helpers/functions.config.js';
import { getMap } from '../../helpers/lotOccupancyDB/getMap.js';
import { getMapSVGs } from '../../helpers/functions.map.js'; import { getMapSVGs } from '../../helpers/functions.map.js';
import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummary.js';
import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSummary.js'; import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSummary.js';
import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummary.js';
import { getMap } from '../../helpers/lotOccupancyDB/getMap.js';
export async function handler(request, response) { export async function handler(request, response) {
const map = await getMap(request.params.mapId); const map = await getMap(request.params.mapId);
if (map === undefined) { if (map === undefined) {

View File

@ -1,12 +1,10 @@
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js' import * as configFunctions from '../../helpers/functions.config.js'
import { getMap } from '../../helpers/lotOccupancyDB/getMap.js'
import { getMapSVGs } from '../../helpers/functions.map.js' import { getMapSVGs } from '../../helpers/functions.map.js'
import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummary.js'
import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSummary.js' import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSummary.js'
import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummary.js'
import { getMap } from '../../helpers/lotOccupancyDB/getMap.js'
export async function handler( export async function handler(
request: Request, request: Request,

View File

@ -1,16 +1,14 @@
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js' import * as configFunctions from '../../helpers/functions.config.js'
import { getMapSVGs } from '../../helpers/functions.map.js' import { getMapSVGs } from '../../helpers/functions.map.js'
import type { MapRecord } from '../../types/recordTypes.js'
import * as recordTypes from '../../types/recordTypes'
export async function handler( export async function handler(
_request: Request, _request: Request,
response: Response response: Response
): Promise<void> { ): Promise<void> {
const map: recordTypes.Map = { const map: MapRecord = {
mapCity: configFunctions.getProperty('settings.map.mapCityDefault'), mapCity: configFunctions.getProperty('settings.map.mapCityDefault'),
mapProvince: configFunctions.getProperty('settings.map.mapProvinceDefault') mapProvince: configFunctions.getProperty('settings.map.mapProvinceDefault')
} }

View File

@ -1,7 +1,6 @@
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js' import * as configFunctions from '../../helpers/functions.config.js'
import { getNextMapId } from '../../helpers/lotOccupancyDB/getNextMapId.js' import { getNextMapId } from '../../helpers/lotOccupancyDB/getNextMapId.js'
export async function handler( export async function handler(

View File

@ -1,7 +1,6 @@
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js' import * as configFunctions from '../../helpers/functions.config.js'
import { getPreviousMapId } from '../../helpers/lotOccupancyDB/getPreviousMapId.js' import { getPreviousMapId } from '../../helpers/lotOccupancyDB/getPreviousMapId.js'
export async function handler( export async function handler(

View File

@ -1,7 +1,6 @@
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js' import * as configFunctions from '../../helpers/functions.config.js'
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js' 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> {

View File

@ -1,7 +1,7 @@
import * as configFunctions from '../../helpers/functions.config.js'; import * as configFunctions from '../../helpers/functions.config.js';
import { getMap } from '../../helpers/lotOccupancyDB/getMap.js';
import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSummary.js'; import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSummary.js';
import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummary.js'; import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummary.js';
import { getMap } from '../../helpers/lotOccupancyDB/getMap.js';
export async function handler(request, response) { export async function handler(request, response) {
const map = await getMap(request.params.mapId); const map = await getMap(request.params.mapId);
if (map === undefined) { if (map === undefined) {

View File

@ -1,18 +1,20 @@
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import * as configFunctions from '../../helpers/functions.config.js' import * as configFunctions from '../../helpers/functions.config.js'
import { getMap } from '../../helpers/lotOccupancyDB/getMap.js'
import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSummary.js' import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSummary.js'
import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummary.js' import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummary.js'
import { getMap } from '../../helpers/lotOccupancyDB/getMap.js'
export async function handler(request: Request, response: Response): Promise<void> { export async function handler(
request: Request,
response: Response
): Promise<void> {
const map = await getMap(request.params.mapId) const map = await getMap(request.params.mapId)
if (map === undefined) { if (map === undefined) {
response.redirect( response.redirect(
configFunctions.getProperty('reverseProxy.urlPrefix') + configFunctions.getProperty('reverseProxy.urlPrefix') +
'/maps/?error=mapIdNotFound' '/maps/?error=mapIdNotFound'
) )
return return
} }

View File

@ -5,9 +5,7 @@ import {
getWorkOrderMilestoneTypes, getWorkOrderMilestoneTypes,
getWorkOrderTypes getWorkOrderTypes
} from '../../helpers/functions.cache.js' } from '../../helpers/functions.cache.js'
import * as configFunctions from '../../helpers/functions.config.js' import * as configFunctions from '../../helpers/functions.config.js'
import { getWorkOrder } from '../../helpers/lotOccupancyDB/getWorkOrder.js' import { getWorkOrder } from '../../helpers/lotOccupancyDB/getWorkOrder.js'
export async function handler( export async function handler(

View File

@ -1,12 +1,8 @@
import { import { dateToInteger, dateToString } from '@cityssm/utils-datetime'
dateToInteger,
dateToString
} from '@cityssm/utils-datetime'
import type { Request, Response } from 'express' import type { Request, Response } from 'express'
import { getWorkOrderTypes } from '../../helpers/functions.cache.js' import { getWorkOrderTypes } from '../../helpers/functions.cache.js'
import type { WorkOrder } from '../../types/recordTypes.js'
import type * as recordTypes from '../../types/recordTypes'
export async function handler( export async function handler(
request: Request, request: Request,
@ -14,7 +10,7 @@ export async function handler(
): Promise<void> { ): Promise<void> {
const currentDate = new Date() const currentDate = new Date()
const workOrder: recordTypes.WorkOrder = { const workOrder: WorkOrder = {
workOrderOpenDate: dateToInteger(currentDate), workOrderOpenDate: dateToInteger(currentDate),
workOrderOpenDateString: dateToString(currentDate) workOrderOpenDateString: dateToString(currentDate)
} }

View File

@ -1,3 +1,3 @@
import type * as recordTypes from '../../types/recordTypes'; import type { MapRecord } from '../../types/recordTypes.js';
export declare function getMap(mapId: number | string): Promise<recordTypes.Map | undefined>; export declare function getMap(mapId: number | string): Promise<MapRecord | undefined>;
export default getMap; export default getMap;

View File

@ -1,10 +1,10 @@
import { acquireConnection } from './pool.js' import type { MapRecord } from '../../types/recordTypes.js'
import type * as recordTypes from '../../types/recordTypes' import { acquireConnection } from './pool.js'
export async function getMap( export async function getMap(
mapId: number | string mapId: number | string
): Promise<recordTypes.Map | undefined> { ): Promise<MapRecord | undefined> {
const database = await acquireConnection() const database = await acquireConnection()
const map = database const map = database
@ -29,7 +29,7 @@ export async function getMap(
m.recordUpdate_userName, m.recordUpdate_timeMillis, m.recordUpdate_userName, m.recordUpdate_timeMillis,
m.recordDelete_userName, m.recordDelete_timeMillis` m.recordDelete_userName, m.recordDelete_timeMillis`
) )
.get(mapId) as recordTypes.Map | undefined .get(mapId) as MapRecord | undefined
database.release() database.release()

View File

@ -1,3 +1,3 @@
import type * as recordTypes from '../../types/recordTypes'; import type { MapRecord } from '../../types/recordTypes.js';
export declare function getMaps(): Promise<recordTypes.Map[]>; export declare function getMaps(): Promise<MapRecord[]>;
export default getMaps; export default getMaps;

View File

@ -1,8 +1,8 @@
import type { MapRecord } from '../../types/recordTypes.js'
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
import type * as recordTypes from '../../types/recordTypes' export async function getMaps(): Promise<MapRecord[]> {
export async function getMaps(): Promise<recordTypes.Map[]> {
const database = await acquireConnection() const database = await acquireConnection()
const maps = database const maps = database
@ -20,7 +20,7 @@ export async function getMaps(): Promise<recordTypes.Map[]> {
) l on m.mapId = l.mapId ) l on m.mapId = l.mapId
where m.recordDelete_timeMillis is null order by m.mapName, m.mapId` where m.recordDelete_timeMillis is null order by m.mapName, m.mapId`
) )
.all() as recordTypes.Map[] .all() as MapRecord[]
database.release() database.release()

View File

@ -661,7 +661,7 @@ declare const bulmaJS: BulmaJS
'#lotCreate--mapId' '#lotCreate--mapId'
) as HTMLSelectElement ) as HTMLSelectElement
for (const map of exports.maps as recordTypes.Map[]) { for (const map of exports.maps as recordTypes.MapRecord[]) {
const optionElement = document.createElement('option') const optionElement = document.createElement('option')
optionElement.value = map.mapId!.toString() optionElement.value = map.mapId!.toString()
optionElement.textContent = optionElement.textContent =

View File

@ -9,7 +9,7 @@ declare const cityssm: cityssmGlobal
;(() => { ;(() => {
const los = exports.los as globalTypes.LOS const los = exports.los as globalTypes.LOS
const maps: recordTypes.Map[] = exports.maps const maps: recordTypes.MapRecord[] = exports.maps
const searchFilterElement = document.querySelector( const searchFilterElement = document.querySelector(
'#searchFilter--map' '#searchFilter--map'

View File

@ -232,14 +232,14 @@ function purgeConfigTables(): void {
console.timeEnd('purgeConfigTables') console.timeEnd('purgeConfigTables')
} }
function getMapByMapDescription(mapDescription: string): recordTypes.Map { function getMapByMapDescription(mapDescription: string): recordTypes.MapRecord {
const database = sqlite(databasePath, { const database = sqlite(databasePath, {
readonly: true readonly: true
}) })
const map: recordTypes.Map = database const map = database
.prepare('select * from Maps where mapDescription = ?') .prepare('select * from Maps where mapDescription = ?')
.get(mapDescription) .get(mapDescription) as recordTypes.MapRecord
database.close() database.close()
@ -274,9 +274,9 @@ const cemeteryToMapName = {
WK: 'West Korah' WK: 'West Korah'
} }
const mapCache = new Map<string, recordTypes.Map>() const mapCache = new Map<string, recordTypes.MapRecord>()
async function getMap(dataRow: { cemetery: string }): Promise<recordTypes.Map> { async function getMap(dataRow: { cemetery: string }): Promise<recordTypes.MapRecord> {
const mapCacheKey = dataRow.cemetery const mapCacheKey = dataRow.cemetery
/* /*
@ -312,7 +312,7 @@ async function getMap(dataRow: { cemetery: string }): Promise<recordTypes.Map> {
user user
) )
map = (await getMapFromDatabase(mapId)) as recordTypes.Map map = (await getMapFromDatabase(mapId)) as recordTypes.MapRecord
} }
mapCache.set(mapCacheKey, map) mapCache.set(mapCacheKey, map)

View File

@ -10,7 +10,7 @@ export interface Record {
recordDelete_timeMillis?: number; recordDelete_timeMillis?: number;
recordDelete_dateString?: string; recordDelete_dateString?: string;
} }
export interface Map extends Record { export interface MapRecord extends Record {
mapId?: number; mapId?: number;
mapName?: string; mapName?: string;
mapDescription?: string; mapDescription?: string;
@ -55,7 +55,7 @@ export interface Lot extends Record {
lotType?: string; lotType?: string;
mapId?: number; mapId?: number;
mapName?: string; mapName?: string;
map?: Map; map?: MapRecord;
mapSVG?: string; mapSVG?: string;
mapKey?: string; mapKey?: string;
lotLatitude?: number; lotLatitude?: number;

View File

@ -17,7 +17,7 @@ export interface Record {
* LOT OCCUPANCY DB TYPES * LOT OCCUPANCY DB TYPES
*/ */
export interface Map extends Record { export interface MapRecord extends Record {
mapId?: number mapId?: number
mapName?: string mapName?: string
mapDescription?: string mapDescription?: string
@ -74,7 +74,7 @@ export interface Lot extends Record {
mapId?: number mapId?: number
mapName?: string mapName?: string
map?: Map map?: MapRecord
mapSVG?: string mapSVG?: string
mapKey?: string mapKey?: string