diff --git a/helpers/functions.cache.ts b/helpers/functions.cache.ts index 44eda96e..fdd2946b 100644 --- a/helpers/functions.cache.ts +++ b/helpers/functions.cache.ts @@ -17,7 +17,7 @@ import type * as recordTypes from "../types/recordTypes"; * Lot Occupant Types */ -let lotOccupantTypes: recordTypes.LotOccupantType[]; +let lotOccupantTypes: recordTypes.LotOccupantType[] | undefined; export function getLotOccupantTypes() { if (!lotOccupantTypes) { @@ -53,7 +53,7 @@ export function clearLotOccupantTypesCache() { * Lot Statuses */ -let lotStatuses: recordTypes.LotStatus[]; +let lotStatuses: recordTypes.LotStatus[] | undefined; export function getLotStatuses() { if (!lotStatuses) { @@ -89,7 +89,7 @@ export function clearLotStatusesCache() { * Lot Types */ -let lotTypes: recordTypes.LotType[]; +let lotTypes: recordTypes.LotType[] | undefined; export function getLotTypes() { if (!lotTypes) { @@ -125,8 +125,8 @@ export function clearLotTypesCache() { * Occupancy Types */ -let occupancyTypes: recordTypes.OccupancyType[]; -let allOccupancyTypeFields: recordTypes.OccupancyTypeField[]; +let occupancyTypes: recordTypes.OccupancyType[] | undefined; +let allOccupancyTypeFields: recordTypes.OccupancyTypeField[] | undefined; export function getOccupancyTypes() { if (!occupancyTypes) { @@ -170,7 +170,7 @@ export function clearOccupancyTypesCache() { * Work Order Types */ -let workOrderTypes: recordTypes.WorkOrderType[]; +let workOrderTypes: recordTypes.WorkOrderType[] | undefined; export function getWorkOrderTypes() { if (!workOrderTypes) { @@ -188,7 +188,7 @@ export function clearWorkOrderTypesCache() { * Work Order Milestone Types */ -let workOrderMilestoneTypes: recordTypes.WorkOrderMilestoneType[]; +let workOrderMilestoneTypes: recordTypes.WorkOrderMilestoneType[] | undefined; export function getWorkOrderMilestoneTypes() { if (!workOrderMilestoneTypes) { diff --git a/helpers/functions.lotOccupancy.d.ts b/helpers/functions.lotOccupancy.d.ts index 07d0ab7b..41758bb8 100644 --- a/helpers/functions.lotOccupancy.d.ts +++ b/helpers/functions.lotOccupancy.d.ts @@ -1,5 +1,5 @@ import type * as recordTypes from "../types/recordTypes"; export declare const filterOccupantsByLotOccupantType: (lotOccupancy: recordTypes.LotOccupancy, lotOccupantType: string) => recordTypes.LotOccupancyOccupant[]; -export declare const getFieldValueByOccupancyTypeField: (lotOccupancy: recordTypes.LotOccupancy, occupancyTypeField: string) => string; +export declare const getFieldValueByOccupancyTypeField: (lotOccupancy: recordTypes.LotOccupancy, occupancyTypeField: string) => string | undefined; export declare const getFeesByFeeCategory: (lotOccupancy: recordTypes.LotOccupancy, feeCategory: string, feeCategoryContains?: boolean) => recordTypes.LotOccupancyFee[]; export declare const getTransactionTotal: (lotOccupancy: recordTypes.LotOccupancy) => number; diff --git a/helpers/functions.lotOccupancy.js b/helpers/functions.lotOccupancy.js index b92749b2..2e7f1f56 100644 --- a/helpers/functions.lotOccupancy.js +++ b/helpers/functions.lotOccupancy.js @@ -1,13 +1,13 @@ export const filterOccupantsByLotOccupantType = (lotOccupancy, lotOccupantType) => { const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase(); - const occupants = lotOccupancy.lotOccupancyOccupants.filter((possibleOccupant) => { - return possibleOccupant.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase; + const occupants = (lotOccupancy.lotOccupancyOccupants || []).filter((possibleOccupant) => { + return (possibleOccupant.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase); }); return occupants; }; export const getFieldValueByOccupancyTypeField = (lotOccupancy, occupancyTypeField) => { const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase(); - const field = lotOccupancy.lotOccupancyFields.find((possibleField) => { + const field = (lotOccupancy.lotOccupancyFields || []).find((possibleField) => { return possibleField.occupancyTypeField.toLowerCase() === occupancyTypeFieldLowerCase; }); if (field) { @@ -17,7 +17,7 @@ export const getFieldValueByOccupancyTypeField = (lotOccupancy, occupancyTypeFie }; export const getFeesByFeeCategory = (lotOccupancy, feeCategory, feeCategoryContains = false) => { const feeCategoryLowerCase = feeCategory.toLowerCase(); - const fees = lotOccupancy.lotOccupancyFees.filter((possibleFee) => { + const fees = (lotOccupancy.lotOccupancyFees || []).filter((possibleFee) => { return feeCategoryContains ? possibleFee.feeCategory.toLowerCase().includes(feeCategoryLowerCase) : possibleFee.feeCategory.toLowerCase() === feeCategoryLowerCase; diff --git a/helpers/functions.lotOccupancy.ts b/helpers/functions.lotOccupancy.ts index be984a39..ff822de9 100644 --- a/helpers/functions.lotOccupancy.ts +++ b/helpers/functions.lotOccupancy.ts @@ -6,8 +6,10 @@ export const filterOccupantsByLotOccupantType = ( ): recordTypes.LotOccupancyOccupant[] => { const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase(); - const occupants = lotOccupancy.lotOccupancyOccupants.filter((possibleOccupant) => { - return possibleOccupant.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase; + const occupants = (lotOccupancy.lotOccupancyOccupants || []).filter((possibleOccupant) => { + return ( + (possibleOccupant.lotOccupantType as string).toLowerCase() === lotOccupantTypeLowerCase + ); }); return occupants; @@ -16,11 +18,11 @@ export const filterOccupantsByLotOccupantType = ( export const getFieldValueByOccupancyTypeField = ( lotOccupancy: recordTypes.LotOccupancy, occupancyTypeField: string -): string => { +): string | undefined => { const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase(); - const field = lotOccupancy.lotOccupancyFields.find((possibleField) => { - return possibleField.occupancyTypeField.toLowerCase() === occupancyTypeFieldLowerCase; + const field = (lotOccupancy.lotOccupancyFields || []).find((possibleField) => { + return (possibleField.occupancyTypeField as string).toLowerCase() === occupancyTypeFieldLowerCase; }); if (field) { @@ -37,10 +39,10 @@ export const getFeesByFeeCategory = ( ) => { const feeCategoryLowerCase = feeCategory.toLowerCase(); - const fees = lotOccupancy.lotOccupancyFees.filter((possibleFee) => { + const fees = (lotOccupancy.lotOccupancyFees || []).filter((possibleFee) => { return feeCategoryContains - ? possibleFee.feeCategory.toLowerCase().includes(feeCategoryLowerCase) - : possibleFee.feeCategory.toLowerCase() === feeCategoryLowerCase; + ? (possibleFee.feeCategory as string).toLowerCase().includes(feeCategoryLowerCase) + : (possibleFee.feeCategory as string).toLowerCase() === feeCategoryLowerCase; }); return fees; diff --git a/helpers/functions.print.d.ts b/helpers/functions.print.d.ts index a9f3d810..83bf333d 100644 --- a/helpers/functions.print.d.ts +++ b/helpers/functions.print.d.ts @@ -4,7 +4,7 @@ interface PrintConfig { } export declare const getScreenPrintConfig: (printName: string) => PrintConfig; export declare const getPdfPrintConfig: (printName: string) => PrintConfig; -export declare const getPrintConfig: (screenOrPdf_printName: string) => PrintConfig; +export declare const getPrintConfig: (screenOrPdf_printName: string) => PrintConfig | undefined; export declare const getReportData: (printConfig: PrintConfig, requestQuery: { [paramName: string]: unknown; }) => { diff --git a/helpers/functions.print.js b/helpers/functions.print.js index 1af3ef7e..3968c1b1 100644 --- a/helpers/functions.print.js +++ b/helpers/functions.print.js @@ -15,7 +15,7 @@ export const getScreenPrintConfig = (printName) => { return screenPrintConfigs[printName]; }; const pdfPrintConfigs = { - "workOrder": { + workOrder: { title: "Work Order Field Sheet", params: ["workOrderId"] }, @@ -38,11 +38,14 @@ export const getPdfPrintConfig = (printName) => { export const getPrintConfig = (screenOrPdf_printName) => { const printNameSplit = screenOrPdf_printName.split("/"); switch (printNameSplit[0]) { - case "screen": + case "screen": { return getScreenPrintConfig(printNameSplit[1]); - case "pdf": + } + case "pdf": { return getPdfPrintConfig(printNameSplit[1]); + } } + return undefined; }; export const getReportData = (printConfig, requestQuery) => { const reportData = { @@ -50,11 +53,11 @@ export const getReportData = (printConfig, requestQuery) => { }; if (printConfig.params.includes("lotOccupancyId") && typeof requestQuery.lotOccupancyId === "string") { - reportData.lotOccupancy = getLotOccupancy(requestQuery.lotOccupancyId); - if (reportData.lotOccupancy && - reportData.lotOccupancy.lotId) { - reportData.lot = getLot(reportData.lotOccupancy.lotId); + const lotOccupancy = getLotOccupancy(requestQuery.lotOccupancyId); + if (lotOccupancy && lotOccupancy.lotId) { + reportData.lot = getLot(lotOccupancy.lotId); } + reportData.lotOccupancy = lotOccupancy; } if (printConfig.params.includes("workOrderId") && typeof requestQuery.workOrderId === "string") { diff --git a/helpers/functions.print.ts b/helpers/functions.print.ts index a111fe0f..f0378b77 100644 --- a/helpers/functions.print.ts +++ b/helpers/functions.print.ts @@ -4,8 +4,6 @@ import { getLot } from "./lotOccupancyDB/getLot.js"; import { getLotOccupancy } from "./lotOccupancyDB/getLotOccupancy.js"; import { getWorkOrder } from "./lotOccupancyDB/getWorkOrder.js"; -import type * as recordTypes from "../types/recordTypes"; - interface PrintConfig { title: string; params: string[]; @@ -27,7 +25,7 @@ export const getScreenPrintConfig = (printName: string): PrintConfig => { }; const pdfPrintConfigs: { [printName: string]: PrintConfig } = { - "workOrder": { + workOrder: { title: "Work Order Field Sheet", params: ["workOrderId"] }, @@ -51,16 +49,19 @@ export const getPdfPrintConfig = (printName: string): PrintConfig => { return pdfPrintConfigs[printName]; }; -export const getPrintConfig = (screenOrPdf_printName: string): PrintConfig => { +export const getPrintConfig = (screenOrPdf_printName: string): PrintConfig | undefined => { const printNameSplit = screenOrPdf_printName.split("/"); switch (printNameSplit[0]) { - case "screen": + case "screen": { return getScreenPrintConfig(printNameSplit[1]); - - case "pdf": + } + case "pdf": { return getPdfPrintConfig(printNameSplit[1]); + } } + + return undefined; }; export const getReportData = ( @@ -75,14 +76,13 @@ export const getReportData = ( printConfig.params.includes("lotOccupancyId") && typeof requestQuery.lotOccupancyId === "string" ) { - reportData.lotOccupancy = getLotOccupancy(requestQuery.lotOccupancyId); + const lotOccupancy = getLotOccupancy(requestQuery.lotOccupancyId); - if ( - reportData.lotOccupancy && - (reportData.lotOccupancy as recordTypes.LotOccupancy).lotId - ) { - reportData.lot = getLot((reportData.lotOccupancy as recordTypes.LotOccupancy).lotId); + if (lotOccupancy && lotOccupancy.lotId) { + reportData.lot = getLot(lotOccupancy.lotId); } + + reportData.lotOccupancy = lotOccupancy; } if ( diff --git a/helpers/functions.user.js b/helpers/functions.user.js index 2e880d27..20675d27 100644 --- a/helpers/functions.user.js +++ b/helpers/functions.user.js @@ -3,7 +3,7 @@ import * as configFunctions from "./functions.config.js"; export const userIsAdmin = (request) => { var _a; const user = (_a = request.session) === null || _a === void 0 ? void 0 : _a.user; - if (!user) { + if (!user || !user.userProperties) { return false; } return user.userProperties.isAdmin; @@ -11,7 +11,7 @@ export const userIsAdmin = (request) => { export const userCanUpdate = (request) => { var _a; const user = (_a = request.session) === null || _a === void 0 ? void 0 : _a.user; - if (!user) { + if (!user || !user.userProperties) { return false; } return user.userProperties.canUpdate; diff --git a/helpers/functions.user.ts b/helpers/functions.user.ts index 447adb18..975ebf9a 100644 --- a/helpers/functions.user.ts +++ b/helpers/functions.user.ts @@ -18,7 +18,7 @@ export interface APIRequest { export const userIsAdmin = (request: UserRequest): boolean => { const user = request.session?.user; - if (!user) { + if (!user || !user.userProperties) { return false; } @@ -28,7 +28,7 @@ export const userIsAdmin = (request: UserRequest): boolean => { export const userCanUpdate = (request: UserRequest): boolean => { const user = request.session?.user; - if (!user) { + if (!user || !user.userProperties) { return false; } diff --git a/types/recordTypes.d.ts b/types/recordTypes.d.ts index cb92c532..fd580446 100644 --- a/types/recordTypes.d.ts +++ b/types/recordTypes.d.ts @@ -26,8 +26,8 @@ export interface Map extends Record { lotCount?: number; } export interface LotType extends Record { - lotTypeId?: number; - lotType?: string; + lotTypeId: number; + lotType: string; orderNumber?: number; lotTypeFields?: LotTypeField[]; } @@ -44,8 +44,8 @@ export interface LotTypeField extends Record { orderNumber?: number; } export interface LotStatus extends Record { - lotStatusId?: number; - lotStatus?: string; + lotStatusId: number; + lotStatus: string; orderNumber?: number; } export interface Lot extends Record { @@ -76,8 +76,8 @@ export interface LotComment extends Record { lotComment?: string; } export interface OccupancyType extends Record { - occupancyTypeId?: number; - occupancyType?: string; + occupancyTypeId: number; + occupancyType: string; orderNumber?: number; occupancyTypeFields?: OccupancyTypeField[]; } @@ -93,8 +93,8 @@ export interface OccupancyTypeField { orderNumber?: number; } export interface LotOccupantType extends Record { - lotOccupantTypeId?: number; - lotOccupantType?: string; + lotOccupantTypeId: number; + lotOccupantType: string; orderNumber?: number; } export interface FeeCategory extends Record { @@ -137,7 +137,7 @@ export interface LotOccupancyTransaction extends Record { transactionDateString?: string; transactionTime?: number; transactionTimeString?: string; - transactionAmount?: number; + transactionAmount: number; externalReceiptNumber?: string; transactionNote?: string; } @@ -197,8 +197,8 @@ export interface WorkOrderType extends Record { orderNumber?: number; } export interface WorkOrderMilestoneType extends Record { - workOrderMilestoneTypeId?: number; - workOrderMilestoneType?: string; + workOrderMilestoneTypeId: number; + workOrderMilestoneType: string; orderNumber?: number; } export interface WorkOrderComment extends Record { diff --git a/types/recordTypes.ts b/types/recordTypes.ts index 216d75d5..1cd0ce38 100644 --- a/types/recordTypes.ts +++ b/types/recordTypes.ts @@ -37,8 +37,8 @@ export interface Map extends Record { } export interface LotType extends Record { - lotTypeId?: number; - lotType?: string; + lotTypeId: number; + lotType: string; orderNumber?: number; lotTypeFields?: LotTypeField[]; } @@ -60,8 +60,8 @@ export interface LotTypeField extends Record { } export interface LotStatus extends Record { - lotStatusId?: number; - lotStatus?: string; + lotStatusId: number; + lotStatus: string; orderNumber?: number; } @@ -104,8 +104,8 @@ export interface LotComment extends Record { } export interface OccupancyType extends Record { - occupancyTypeId?: number; - occupancyType?: string; + occupancyTypeId: number; + occupancyType: string; orderNumber?: number; occupancyTypeFields?: OccupancyTypeField[]; } @@ -123,8 +123,8 @@ export interface OccupancyTypeField { } export interface LotOccupantType extends Record { - lotOccupantTypeId?: number; - lotOccupantType?: string; + lotOccupantTypeId: number; + lotOccupantType: string; orderNumber?: number; } @@ -182,7 +182,7 @@ export interface LotOccupancyTransaction extends Record { transactionDateString?: string; transactionTime?: number; transactionTimeString?: string; - transactionAmount?: number; + transactionAmount: number; externalReceiptNumber?: string; transactionNote?: string; } @@ -265,8 +265,8 @@ export interface WorkOrderType extends Record { } export interface WorkOrderMilestoneType extends Record { - workOrderMilestoneTypeId?: number; - workOrderMilestoneType?: string; + workOrderMilestoneTypeId: number; + workOrderMilestoneType: string; orderNumber?: number; }