deepsource-autofix-76c6eb20
Dan Gowans 2023-01-23 13:37:32 -05:00
parent a8981e8154
commit 4f683e7432
27 changed files with 122 additions and 140 deletions

View File

@ -1,3 +1,3 @@
import type { Request, Response } from 'express';
export declare function handler(request: Request, response: Response, next: any): Promise<void>;
import type { Request, Response, NextFunction } from 'express';
export declare function handler(request: Request, response: Response, next: NextFunction): Promise<void>;
export default handler;

View File

@ -20,7 +20,7 @@ export async function handler(request, response, next) {
return;
}
const printConfig = getPdfPrintConfig(printName);
if (!printConfig) {
if (printConfig === undefined) {
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') +
'/dashboard/?error=printConfigNotFound');
return;

View File

@ -1,4 +1,4 @@
import type { Request, Response } from 'express'
import type { Request, Response, NextFunction } from 'express'
import path from 'node:path'
import * as ejs from 'ejs'
@ -22,7 +22,7 @@ const attachmentOrInline = configFunctions.getProperty(
export async function handler(
request: Request,
response: Response,
next
next: NextFunction
): Promise<void> {
const printName = request.params.printName
@ -43,7 +43,7 @@ export async function handler(
const printConfig = getPdfPrintConfig(printName)
if (!printConfig) {
if (printConfig === undefined) {
response.redirect(
configFunctions.getProperty('reverseProxy.urlPrefix') +
'/dashboard/?error=printConfigNotFound'
@ -58,7 +58,7 @@ export async function handler(
function pdfCallbackFunction(pdf: Buffer): void {
response.setHeader(
'Content-Disposition',
`${attachmentOrInline}; filename=${camelcase(printConfig.title)}.pdf`
`${attachmentOrInline}; filename=${camelcase(printConfig!.title)}.pdf`
)
response.setHeader('Content-Type', 'application/pdf')

View File

@ -13,7 +13,7 @@ export async function handler(request, response) {
return;
}
const printConfig = getScreenPrintConfig(printName);
if (!printConfig) {
if (printConfig === undefined) {
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') +
'/dashboard/?error=printConfigNotFound');
return;

View File

@ -29,7 +29,7 @@ export async function handler(
const printConfig = getScreenPrintConfig(printName)
if (!printConfig) {
if (printConfig === undefined) {
response.redirect(
configFunctions.getProperty('reverseProxy.urlPrefix') +
'/dashboard/?error=printConfigNotFound'

View File

@ -9,7 +9,7 @@ export async function handler(request, response) {
break;
}
}
if (!rows) {
if (rows === undefined) {
response.status(404).json({
success: false,
message: 'Report Not Found'

View File

@ -22,7 +22,7 @@ export async function handler(
}
}
if (!rows) {
if (rows === undefined) {
response.status(404).json({
success: false,
message: 'Report Not Found'

View File

@ -2,8 +2,8 @@ interface PrintConfig {
title: string;
params: string[];
}
export declare function getScreenPrintConfig(printName: string): PrintConfig;
export declare function getPdfPrintConfig(printName: string): PrintConfig;
export declare function getScreenPrintConfig(printName: string): PrintConfig | undefined;
export declare function getPdfPrintConfig(printName: string): PrintConfig | undefined;
export declare function getPrintConfig(screenOrPdfPrintName: string): PrintConfig | undefined;
export declare function getReportData(printConfig: PrintConfig, requestQuery: Record<string, unknown>): Promise<Record<string, unknown>>;
export {};

View File

@ -18,7 +18,7 @@ const screenPrintConfigs: Record<string, PrintConfig> = {
}
}
export function getScreenPrintConfig(printName: string): PrintConfig {
export function getScreenPrintConfig(printName: string): PrintConfig | undefined {
return screenPrintConfigs[printName]
}
@ -43,7 +43,7 @@ const pdfPrintConfigs: Record<string, PrintConfig> = {
}
}
export function getPdfPrintConfig(printName: string): PrintConfig {
export function getPdfPrintConfig(printName: string): PrintConfig | undefined {
return pdfPrintConfigs[printName]
}

View File

@ -1,26 +1,18 @@
import { getUserNameFromApiKey } from './functions.api.js';
import * as configFunctions from './functions.config.js';
export function userIsAdmin(request) {
const user = request.session?.user;
if (!user?.userProperties) {
return false;
}
return user.userProperties.isAdmin;
return request.session?.user?.userProperties?.isAdmin ?? false;
}
export function userCanUpdate(request) {
const user = request.session?.user;
if (!user?.userProperties) {
return false;
}
return user.userProperties.canUpdate;
return request.session?.user?.userProperties?.canUpdate ?? false;
}
export async function apiKeyIsValid(request) {
const apiKey = request.params?.apiKey;
if (!apiKey) {
if (apiKey === undefined) {
return false;
}
const userName = await getUserNameFromApiKey(apiKey);
if (!userName) {
if (userName === undefined) {
return false;
}
const canLogin = configFunctions

View File

@ -16,35 +16,23 @@ export interface APIRequest {
}
export function userIsAdmin(request: UserRequest): boolean {
const user = request.session?.user
if (!user?.userProperties) {
return false
}
return user.userProperties.isAdmin
return request.session?.user?.userProperties?.isAdmin ?? false
}
export function userCanUpdate(request: UserRequest): boolean {
const user = request.session?.user
if (!user?.userProperties) {
return false
}
return user.userProperties.canUpdate
return request.session?.user?.userProperties?.canUpdate ?? false
}
export async function apiKeyIsValid(request: APIRequest): Promise<boolean> {
const apiKey = request.params?.apiKey
if (!apiKey) {
if (apiKey === undefined) {
return false
}
const userName = await getUserNameFromApiKey(apiKey)
if (!userName) {
if (userName === undefined) {
return false
}

View File

@ -61,10 +61,10 @@ export async function moveFeeUpToTop(feeId) {
updateRecordOrderNumber('Fees', feeId, -1, database);
database
.prepare(`update Fees
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and feeCategoryId = ?
and orderNumber < ?`)
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and feeCategoryId = ?
and orderNumber < ?`)
.run(currentFee.feeCategoryId, currentFee.orderNumber);
}
database.release();

View File

@ -107,10 +107,10 @@ export async function moveFeeUpToTop(feeId: number | string): Promise<boolean> {
database
.prepare(
`update Fees
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and feeCategoryId = ?
and orderNumber < ?`
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and feeCategoryId = ?
and orderNumber < ?`
)
.run(currentFee.feeCategoryId, currentFee.orderNumber)
}

View File

@ -34,10 +34,10 @@ export async function moveLotTypeFieldDownToBottom(lotTypeFieldId) {
updateRecordOrderNumber('LotTypeFields', lotTypeFieldId, maxOrderNumber + 1, database);
database
.prepare(`update LotTypeFields
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and lotTypeId = ?
and orderNumber > ?`)
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and lotTypeId = ?
and orderNumber > ?`)
.run(currentField.lotTypeId, currentField.orderNumber);
}
database.release();

View File

@ -73,10 +73,10 @@ export async function moveLotTypeFieldDownToBottom(
database
.prepare(
`update LotTypeFields
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and lotTypeId = ?
and orderNumber > ?`
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and lotTypeId = ?
and orderNumber > ?`
)
.run(currentField.lotTypeId, currentField.orderNumber)
}

View File

@ -26,23 +26,23 @@ export async function moveOccupancyTypePrintDownToBottom(occupancyTypeId, printE
.get(occupancyTypeId, printEJS).orderNumber;
const maxOrderNumber = database
.prepare(`select max(orderNumber) as maxOrderNumber
from OccupancyTypePrints
where recordDelete_timeMillis is null
and occupancyTypeId = ?`)
from OccupancyTypePrints
where recordDelete_timeMillis is null
and occupancyTypeId = ?`)
.get(occupancyTypeId).maxOrderNumber;
if (currentOrderNumber !== maxOrderNumber) {
database
.prepare(`update OccupancyTypePrints
set orderNumber = ? + 1
where occupancyTypeId = ?
and printEJS = ?`)
set orderNumber = ? + 1
where occupancyTypeId = ?
and printEJS = ?`)
.run(maxOrderNumber, occupancyTypeId, printEJS);
database
.prepare(`update OccupancyTypeFields
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and occupancyTypeId = ?
and orderNumber > ?`)
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and occupancyTypeId = ?
and orderNumber > ?`)
.run(occupancyTypeId, currentOrderNumber);
}
database.release();

View File

@ -52,9 +52,9 @@ export async function moveOccupancyTypePrintDownToBottom(
const maxOrderNumber: number = database
.prepare(
`select max(orderNumber) as maxOrderNumber
from OccupancyTypePrints
where recordDelete_timeMillis is null
and occupancyTypeId = ?`
from OccupancyTypePrints
where recordDelete_timeMillis is null
and occupancyTypeId = ?`
)
.get(occupancyTypeId).maxOrderNumber
@ -62,19 +62,19 @@ export async function moveOccupancyTypePrintDownToBottom(
database
.prepare(
`update OccupancyTypePrints
set orderNumber = ? + 1
where occupancyTypeId = ?
and printEJS = ?`
set orderNumber = ? + 1
where occupancyTypeId = ?
and printEJS = ?`
)
.run(maxOrderNumber, occupancyTypeId, printEJS)
database
.prepare(
`update OccupancyTypeFields
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and occupancyTypeId = ?
and orderNumber > ?`
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and occupancyTypeId = ?
and orderNumber > ?`
)
.run(occupancyTypeId, currentOrderNumber)
}

View File

@ -31,16 +31,16 @@ export async function moveOccupancyTypePrintUpToTop(occupancyTypeId, printEJS) {
if (currentOrderNumber > 0) {
database
.prepare(`update OccupancyTypePrints
set orderNumber = -1
where occupancyTypeId = ?
and printEJS = ?`)
set orderNumber = -1
where occupancyTypeId = ?
and printEJS = ?`)
.run(occupancyTypeId, printEJS);
database
.prepare(`update OccupancyTypePrints
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and occupancyTypeId = ?
and orderNumber < ?`)
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and occupancyTypeId = ?
and orderNumber < ?`)
.run(occupancyTypeId, currentOrderNumber);
}
database.release();

View File

@ -58,19 +58,19 @@ export async function moveOccupancyTypePrintUpToTop(
database
.prepare(
`update OccupancyTypePrints
set orderNumber = -1
where occupancyTypeId = ?
and printEJS = ?`
set orderNumber = -1
where occupancyTypeId = ?
and printEJS = ?`
)
.run(occupancyTypeId, printEJS)
database
.prepare(
`update OccupancyTypePrints
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and occupancyTypeId = ?
and orderNumber < ?`
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and occupancyTypeId = ?
and orderNumber < ?`
)
.run(occupancyTypeId, currentOrderNumber)
}

View File

@ -12,8 +12,8 @@ recordIdColumns.set('WorkOrderTypes', 'workOrderTypeId');
function getCurrentOrderNumber(recordTable, recordId, database) {
const currentOrderNumber = database
.prepare(`select orderNumber
from ${recordTable}
where ${recordIdColumns.get(recordTable)} = ?`)
from ${recordTable}
where ${recordIdColumns.get(recordTable)} = ?`)
.get(recordId).orderNumber;
return currentOrderNumber;
}
@ -43,9 +43,9 @@ export async function moveRecordDownToBottom(recordTable, recordId) {
updateRecordOrderNumber(recordTable, recordId, maxOrderNumber + 1, database);
database
.prepare(`update ${recordTable}
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and orderNumber > ?`)
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and orderNumber > ?`)
.run(currentOrderNumber);
}
database.release();
@ -77,9 +77,9 @@ export async function moveRecordUpToTop(recordTable, recordId) {
updateRecordOrderNumber(recordTable, recordId, -1, database);
database
.prepare(`update ${recordTable}
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and orderNumber < ?`)
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and orderNumber < ?`)
.run(currentOrderNumber);
}
database.release();

View File

@ -13,7 +13,7 @@ type RecordTable =
| 'WorkOrderMilestoneTypes'
| 'WorkOrderTypes'
const recordIdColumns: Map<RecordTable, string> = new Map()
const recordIdColumns = new Map<RecordTable, string>()
recordIdColumns.set('FeeCategories', 'feeCategoryId')
recordIdColumns.set('LotOccupantTypes', 'lotOccupantTypeId')
recordIdColumns.set('LotStatuses', 'lotStatusId')
@ -30,8 +30,8 @@ function getCurrentOrderNumber(
const currentOrderNumber: number = database
.prepare(
`select orderNumber
from ${recordTable}
where ${recordIdColumns.get(recordTable)!} = ?`
from ${recordTable}
where ${recordIdColumns.get(recordTable)!} = ?`
)
.get(recordId).orderNumber
@ -99,9 +99,9 @@ export async function moveRecordDownToBottom(
database
.prepare(
`update ${recordTable}
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and orderNumber > ?`
set orderNumber = orderNumber - 1
where recordDelete_timeMillis is null
and orderNumber > ?`
)
.run(currentOrderNumber)
}
@ -171,9 +171,9 @@ export async function moveRecordUpToTop(
database
.prepare(
`update ${recordTable}
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and orderNumber < ?`
set orderNumber = orderNumber + 1
where recordDelete_timeMillis is null
and orderNumber < ?`
)
.run(currentOrderNumber)
}

View File

@ -22,13 +22,13 @@ export async function updateLot(lotForm, requestSession) {
const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(',');
for (const lotTypeFieldId of lotTypeFieldIds) {
const lotFieldValue = lotForm['lotFieldValue_' + lotTypeFieldId];
await (lotFieldValue && lotFieldValue !== ''
? addOrUpdateLotField({
await ((lotFieldValue ?? '') === ''
? deleteLotField(lotForm.lotId, lotTypeFieldId, requestSession, database)
: addOrUpdateLotField({
lotId: lotForm.lotId,
lotTypeFieldId,
lotFieldValue
}, requestSession, database)
: deleteLotField(lotForm.lotId, lotTypeFieldId, requestSession, database));
lotFieldValue: lotFieldValue
}, requestSession, database));
}
}
database.release();

View File

@ -62,21 +62,23 @@ export async function updateLot(
const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(',')
for (const lotTypeFieldId of lotTypeFieldIds) {
const lotFieldValue = lotForm['lotFieldValue_' + lotTypeFieldId] as string
const lotFieldValue = lotForm['lotFieldValue_' + lotTypeFieldId] as
| string
| undefined
await (lotFieldValue && lotFieldValue !== ''
? addOrUpdateLotField(
{
lotId: lotForm.lotId,
lotTypeFieldId,
lotFieldValue
},
await ((lotFieldValue ?? '') === ''
? deleteLotField(
lotForm.lotId,
lotTypeFieldId,
requestSession,
database
)
: deleteLotField(
lotForm.lotId,
lotTypeFieldId,
: addOrUpdateLotField(
{
lotId: lotForm.lotId,
lotTypeFieldId,
lotFieldValue: lotFieldValue!
},
requestSession,
database
))

View File

@ -22,13 +22,13 @@ export async function updateLotOccupancy(lotOccupancyForm, requestSession) {
const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds ?? '').split(',');
for (const occupancyTypeFieldId of occupancyTypeFieldIds) {
const lotOccupancyFieldValue = lotOccupancyForm['lotOccupancyFieldValue_' + occupancyTypeFieldId];
await (lotOccupancyFieldValue && lotOccupancyFieldValue !== ''
? addOrUpdateLotOccupancyField({
await ((lotOccupancyFieldValue ?? '') === ''
? deleteLotOccupancyField(lotOccupancyForm.lotOccupancyId, occupancyTypeFieldId, requestSession, database)
: addOrUpdateLotOccupancyField({
lotOccupancyId: lotOccupancyForm.lotOccupancyId,
occupancyTypeFieldId,
lotOccupancyFieldValue
}, requestSession, database)
: deleteLotOccupancyField(lotOccupancyForm.lotOccupancyId, occupancyTypeFieldId, requestSession, database));
}, requestSession, database));
}
}
database.release();

View File

@ -64,8 +64,14 @@ export async function updateLotOccupancy(
'lotOccupancyFieldValue_' + occupancyTypeFieldId
] as string
await (lotOccupancyFieldValue && lotOccupancyFieldValue !== ''
? addOrUpdateLotOccupancyField(
await ((lotOccupancyFieldValue ?? '') === ''
? deleteLotOccupancyField(
lotOccupancyForm.lotOccupancyId,
occupancyTypeFieldId,
requestSession,
database
)
: addOrUpdateLotOccupancyField(
{
lotOccupancyId: lotOccupancyForm.lotOccupancyId,
occupancyTypeFieldId,
@ -73,12 +79,6 @@ export async function updateLotOccupancy(
},
requestSession,
database
)
: deleteLotOccupancyField(
lotOccupancyForm.lotOccupancyId,
occupancyTypeFieldId,
requestSession,
database
))
}
}

View File

@ -12,7 +12,7 @@ type RecordTable =
| 'WorkOrderMilestoneTypes'
| 'WorkOrderTypes'
const recordNameIdColumns: Map<RecordTable, string[]> = new Map()
const recordNameIdColumns = new Map<RecordTable, string[]>()
recordNameIdColumns.set('FeeCategories', ['feeCategory', 'feeCategoryId'])
recordNameIdColumns.set('LotStatuses', ['lotStatus', 'lotStatusId'])
recordNameIdColumns.set('LotTypes', ['lotType', 'lotTypeId'])

View File

@ -12,7 +12,7 @@ type RecordTable =
| 'WorkOrderMilestoneTypes'
| 'WorkOrderTypes'
const recordIdColumns: Map<RecordTable, string> = new Map()
const recordIdColumns = new Map<RecordTable, string>()
recordIdColumns.set('FeeCategories', 'feeCategoryId')
recordIdColumns.set('Fees', 'feeId')
recordIdColumns.set('LotOccupantTypes', 'lotOccupantTypeId')