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'; import type { Request, Response, NextFunction } from 'express';
export declare function handler(request: Request, response: Response, next: any): Promise<void>; export declare function handler(request: Request, response: Response, next: NextFunction): Promise<void>;
export default handler; export default handler;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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