more linting and cleanup

deepsource-autofix-76c6eb20
Dan Gowans 2022-10-31 15:23:09 -04:00
parent 55ffb3118d
commit 302875ee57
11 changed files with 72 additions and 67 deletions

View File

@ -17,7 +17,7 @@ import type * as recordTypes from "../types/recordTypes";
* Lot Occupant Types * Lot Occupant Types
*/ */
let lotOccupantTypes: recordTypes.LotOccupantType[]; let lotOccupantTypes: recordTypes.LotOccupantType[] | undefined;
export function getLotOccupantTypes() { export function getLotOccupantTypes() {
if (!lotOccupantTypes) { if (!lotOccupantTypes) {
@ -53,7 +53,7 @@ export function clearLotOccupantTypesCache() {
* Lot Statuses * Lot Statuses
*/ */
let lotStatuses: recordTypes.LotStatus[]; let lotStatuses: recordTypes.LotStatus[] | undefined;
export function getLotStatuses() { export function getLotStatuses() {
if (!lotStatuses) { if (!lotStatuses) {
@ -89,7 +89,7 @@ export function clearLotStatusesCache() {
* Lot Types * Lot Types
*/ */
let lotTypes: recordTypes.LotType[]; let lotTypes: recordTypes.LotType[] | undefined;
export function getLotTypes() { export function getLotTypes() {
if (!lotTypes) { if (!lotTypes) {
@ -125,8 +125,8 @@ export function clearLotTypesCache() {
* Occupancy Types * Occupancy Types
*/ */
let occupancyTypes: recordTypes.OccupancyType[]; let occupancyTypes: recordTypes.OccupancyType[] | undefined;
let allOccupancyTypeFields: recordTypes.OccupancyTypeField[]; let allOccupancyTypeFields: recordTypes.OccupancyTypeField[] | undefined;
export function getOccupancyTypes() { export function getOccupancyTypes() {
if (!occupancyTypes) { if (!occupancyTypes) {
@ -170,7 +170,7 @@ export function clearOccupancyTypesCache() {
* Work Order Types * Work Order Types
*/ */
let workOrderTypes: recordTypes.WorkOrderType[]; let workOrderTypes: recordTypes.WorkOrderType[] | undefined;
export function getWorkOrderTypes() { export function getWorkOrderTypes() {
if (!workOrderTypes) { if (!workOrderTypes) {
@ -188,7 +188,7 @@ export function clearWorkOrderTypesCache() {
* Work Order Milestone Types * Work Order Milestone Types
*/ */
let workOrderMilestoneTypes: recordTypes.WorkOrderMilestoneType[]; let workOrderMilestoneTypes: recordTypes.WorkOrderMilestoneType[] | undefined;
export function getWorkOrderMilestoneTypes() { export function getWorkOrderMilestoneTypes() {
if (!workOrderMilestoneTypes) { if (!workOrderMilestoneTypes) {

View File

@ -1,5 +1,5 @@
import type * as recordTypes from "../types/recordTypes"; import type * as recordTypes from "../types/recordTypes";
export declare const filterOccupantsByLotOccupantType: (lotOccupancy: recordTypes.LotOccupancy, lotOccupantType: string) => recordTypes.LotOccupancyOccupant[]; 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 getFeesByFeeCategory: (lotOccupancy: recordTypes.LotOccupancy, feeCategory: string, feeCategoryContains?: boolean) => recordTypes.LotOccupancyFee[];
export declare const getTransactionTotal: (lotOccupancy: recordTypes.LotOccupancy) => number; export declare const getTransactionTotal: (lotOccupancy: recordTypes.LotOccupancy) => number;

View File

@ -1,13 +1,13 @@
export const filterOccupantsByLotOccupantType = (lotOccupancy, lotOccupantType) => { export const filterOccupantsByLotOccupantType = (lotOccupancy, lotOccupantType) => {
const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase(); const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase();
const occupants = lotOccupancy.lotOccupancyOccupants.filter((possibleOccupant) => { const occupants = (lotOccupancy.lotOccupancyOccupants || []).filter((possibleOccupant) => {
return possibleOccupant.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase; return (possibleOccupant.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase);
}); });
return occupants; return occupants;
}; };
export const getFieldValueByOccupancyTypeField = (lotOccupancy, occupancyTypeField) => { export const getFieldValueByOccupancyTypeField = (lotOccupancy, occupancyTypeField) => {
const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase(); const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase();
const field = lotOccupancy.lotOccupancyFields.find((possibleField) => { const field = (lotOccupancy.lotOccupancyFields || []).find((possibleField) => {
return possibleField.occupancyTypeField.toLowerCase() === occupancyTypeFieldLowerCase; return possibleField.occupancyTypeField.toLowerCase() === occupancyTypeFieldLowerCase;
}); });
if (field) { if (field) {
@ -17,7 +17,7 @@ export const getFieldValueByOccupancyTypeField = (lotOccupancy, occupancyTypeFie
}; };
export const getFeesByFeeCategory = (lotOccupancy, feeCategory, feeCategoryContains = false) => { export const getFeesByFeeCategory = (lotOccupancy, feeCategory, feeCategoryContains = false) => {
const feeCategoryLowerCase = feeCategory.toLowerCase(); const feeCategoryLowerCase = feeCategory.toLowerCase();
const fees = lotOccupancy.lotOccupancyFees.filter((possibleFee) => { const fees = (lotOccupancy.lotOccupancyFees || []).filter((possibleFee) => {
return feeCategoryContains return feeCategoryContains
? possibleFee.feeCategory.toLowerCase().includes(feeCategoryLowerCase) ? possibleFee.feeCategory.toLowerCase().includes(feeCategoryLowerCase)
: possibleFee.feeCategory.toLowerCase() === feeCategoryLowerCase; : possibleFee.feeCategory.toLowerCase() === feeCategoryLowerCase;

View File

@ -6,8 +6,10 @@ export const filterOccupantsByLotOccupantType = (
): recordTypes.LotOccupancyOccupant[] => { ): recordTypes.LotOccupancyOccupant[] => {
const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase(); const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase();
const occupants = lotOccupancy.lotOccupancyOccupants.filter((possibleOccupant) => { const occupants = (lotOccupancy.lotOccupancyOccupants || []).filter((possibleOccupant) => {
return possibleOccupant.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase; return (
(possibleOccupant.lotOccupantType as string).toLowerCase() === lotOccupantTypeLowerCase
);
}); });
return occupants; return occupants;
@ -16,11 +18,11 @@ export const filterOccupantsByLotOccupantType = (
export const getFieldValueByOccupancyTypeField = ( export const getFieldValueByOccupancyTypeField = (
lotOccupancy: recordTypes.LotOccupancy, lotOccupancy: recordTypes.LotOccupancy,
occupancyTypeField: string occupancyTypeField: string
): string => { ): string | undefined => {
const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase(); const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase();
const field = lotOccupancy.lotOccupancyFields.find((possibleField) => { const field = (lotOccupancy.lotOccupancyFields || []).find((possibleField) => {
return possibleField.occupancyTypeField.toLowerCase() === occupancyTypeFieldLowerCase; return (possibleField.occupancyTypeField as string).toLowerCase() === occupancyTypeFieldLowerCase;
}); });
if (field) { if (field) {
@ -37,10 +39,10 @@ export const getFeesByFeeCategory = (
) => { ) => {
const feeCategoryLowerCase = feeCategory.toLowerCase(); const feeCategoryLowerCase = feeCategory.toLowerCase();
const fees = lotOccupancy.lotOccupancyFees.filter((possibleFee) => { const fees = (lotOccupancy.lotOccupancyFees || []).filter((possibleFee) => {
return feeCategoryContains return feeCategoryContains
? possibleFee.feeCategory.toLowerCase().includes(feeCategoryLowerCase) ? (possibleFee.feeCategory as string).toLowerCase().includes(feeCategoryLowerCase)
: possibleFee.feeCategory.toLowerCase() === feeCategoryLowerCase; : (possibleFee.feeCategory as string).toLowerCase() === feeCategoryLowerCase;
}); });
return fees; return fees;

View File

@ -4,7 +4,7 @@ interface PrintConfig {
} }
export declare const getScreenPrintConfig: (printName: string) => PrintConfig; export declare const getScreenPrintConfig: (printName: string) => PrintConfig;
export declare const getPdfPrintConfig: (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: { export declare const getReportData: (printConfig: PrintConfig, requestQuery: {
[paramName: string]: unknown; [paramName: string]: unknown;
}) => { }) => {

View File

@ -15,7 +15,7 @@ export const getScreenPrintConfig = (printName) => {
return screenPrintConfigs[printName]; return screenPrintConfigs[printName];
}; };
const pdfPrintConfigs = { const pdfPrintConfigs = {
"workOrder": { workOrder: {
title: "Work Order Field Sheet", title: "Work Order Field Sheet",
params: ["workOrderId"] params: ["workOrderId"]
}, },
@ -38,11 +38,14 @@ export const getPdfPrintConfig = (printName) => {
export const getPrintConfig = (screenOrPdf_printName) => { export const getPrintConfig = (screenOrPdf_printName) => {
const printNameSplit = screenOrPdf_printName.split("/"); const printNameSplit = screenOrPdf_printName.split("/");
switch (printNameSplit[0]) { switch (printNameSplit[0]) {
case "screen": case "screen": {
return getScreenPrintConfig(printNameSplit[1]); return getScreenPrintConfig(printNameSplit[1]);
case "pdf": }
case "pdf": {
return getPdfPrintConfig(printNameSplit[1]); return getPdfPrintConfig(printNameSplit[1]);
} }
}
return undefined;
}; };
export const getReportData = (printConfig, requestQuery) => { export const getReportData = (printConfig, requestQuery) => {
const reportData = { const reportData = {
@ -50,11 +53,11 @@ export const getReportData = (printConfig, requestQuery) => {
}; };
if (printConfig.params.includes("lotOccupancyId") && if (printConfig.params.includes("lotOccupancyId") &&
typeof requestQuery.lotOccupancyId === "string") { typeof requestQuery.lotOccupancyId === "string") {
reportData.lotOccupancy = getLotOccupancy(requestQuery.lotOccupancyId); const lotOccupancy = getLotOccupancy(requestQuery.lotOccupancyId);
if (reportData.lotOccupancy && if (lotOccupancy && lotOccupancy.lotId) {
reportData.lotOccupancy.lotId) { reportData.lot = getLot(lotOccupancy.lotId);
reportData.lot = getLot(reportData.lotOccupancy.lotId);
} }
reportData.lotOccupancy = lotOccupancy;
} }
if (printConfig.params.includes("workOrderId") && if (printConfig.params.includes("workOrderId") &&
typeof requestQuery.workOrderId === "string") { typeof requestQuery.workOrderId === "string") {

View File

@ -4,8 +4,6 @@ import { getLot } from "./lotOccupancyDB/getLot.js";
import { getLotOccupancy } from "./lotOccupancyDB/getLotOccupancy.js"; import { getLotOccupancy } from "./lotOccupancyDB/getLotOccupancy.js";
import { getWorkOrder } from "./lotOccupancyDB/getWorkOrder.js"; import { getWorkOrder } from "./lotOccupancyDB/getWorkOrder.js";
import type * as recordTypes from "../types/recordTypes";
interface PrintConfig { interface PrintConfig {
title: string; title: string;
params: string[]; params: string[];
@ -27,7 +25,7 @@ export const getScreenPrintConfig = (printName: string): PrintConfig => {
}; };
const pdfPrintConfigs: { [printName: string]: PrintConfig } = { const pdfPrintConfigs: { [printName: string]: PrintConfig } = {
"workOrder": { workOrder: {
title: "Work Order Field Sheet", title: "Work Order Field Sheet",
params: ["workOrderId"] params: ["workOrderId"]
}, },
@ -51,16 +49,19 @@ export const getPdfPrintConfig = (printName: string): PrintConfig => {
return pdfPrintConfigs[printName]; return pdfPrintConfigs[printName];
}; };
export const getPrintConfig = (screenOrPdf_printName: string): PrintConfig => { export const getPrintConfig = (screenOrPdf_printName: string): PrintConfig | undefined => {
const printNameSplit = screenOrPdf_printName.split("/"); const printNameSplit = screenOrPdf_printName.split("/");
switch (printNameSplit[0]) { switch (printNameSplit[0]) {
case "screen": case "screen": {
return getScreenPrintConfig(printNameSplit[1]); return getScreenPrintConfig(printNameSplit[1]);
}
case "pdf": case "pdf": {
return getPdfPrintConfig(printNameSplit[1]); return getPdfPrintConfig(printNameSplit[1]);
} }
}
return undefined;
}; };
export const getReportData = ( export const getReportData = (
@ -75,14 +76,13 @@ export const getReportData = (
printConfig.params.includes("lotOccupancyId") && printConfig.params.includes("lotOccupancyId") &&
typeof requestQuery.lotOccupancyId === "string" typeof requestQuery.lotOccupancyId === "string"
) { ) {
reportData.lotOccupancy = getLotOccupancy(requestQuery.lotOccupancyId); const lotOccupancy = getLotOccupancy(requestQuery.lotOccupancyId);
if ( if (lotOccupancy && lotOccupancy.lotId) {
reportData.lotOccupancy && reportData.lot = getLot(lotOccupancy.lotId);
(reportData.lotOccupancy as recordTypes.LotOccupancy).lotId
) {
reportData.lot = getLot((reportData.lotOccupancy as recordTypes.LotOccupancy).lotId);
} }
reportData.lotOccupancy = lotOccupancy;
} }
if ( if (

View File

@ -3,7 +3,7 @@ import * as configFunctions from "./functions.config.js";
export const userIsAdmin = (request) => { export const userIsAdmin = (request) => {
var _a; var _a;
const user = (_a = request.session) === null || _a === void 0 ? void 0 : _a.user; const user = (_a = request.session) === null || _a === void 0 ? void 0 : _a.user;
if (!user) { if (!user || !user.userProperties) {
return false; return false;
} }
return user.userProperties.isAdmin; return user.userProperties.isAdmin;
@ -11,7 +11,7 @@ export const userIsAdmin = (request) => {
export const userCanUpdate = (request) => { export const userCanUpdate = (request) => {
var _a; var _a;
const user = (_a = request.session) === null || _a === void 0 ? void 0 : _a.user; const user = (_a = request.session) === null || _a === void 0 ? void 0 : _a.user;
if (!user) { if (!user || !user.userProperties) {
return false; return false;
} }
return user.userProperties.canUpdate; return user.userProperties.canUpdate;

View File

@ -18,7 +18,7 @@ export interface APIRequest {
export const userIsAdmin = (request: UserRequest): boolean => { export const userIsAdmin = (request: UserRequest): boolean => {
const user = request.session?.user; const user = request.session?.user;
if (!user) { if (!user || !user.userProperties) {
return false; return false;
} }
@ -28,7 +28,7 @@ export const userIsAdmin = (request: UserRequest): boolean => {
export const userCanUpdate = (request: UserRequest): boolean => { export const userCanUpdate = (request: UserRequest): boolean => {
const user = request.session?.user; const user = request.session?.user;
if (!user) { if (!user || !user.userProperties) {
return false; return false;
} }

View File

@ -26,8 +26,8 @@ export interface Map extends Record {
lotCount?: number; lotCount?: number;
} }
export interface LotType extends Record { export interface LotType extends Record {
lotTypeId?: number; lotTypeId: number;
lotType?: string; lotType: string;
orderNumber?: number; orderNumber?: number;
lotTypeFields?: LotTypeField[]; lotTypeFields?: LotTypeField[];
} }
@ -44,8 +44,8 @@ export interface LotTypeField extends Record {
orderNumber?: number; orderNumber?: number;
} }
export interface LotStatus extends Record { export interface LotStatus extends Record {
lotStatusId?: number; lotStatusId: number;
lotStatus?: string; lotStatus: string;
orderNumber?: number; orderNumber?: number;
} }
export interface Lot extends Record { export interface Lot extends Record {
@ -76,8 +76,8 @@ export interface LotComment extends Record {
lotComment?: string; lotComment?: string;
} }
export interface OccupancyType extends Record { export interface OccupancyType extends Record {
occupancyTypeId?: number; occupancyTypeId: number;
occupancyType?: string; occupancyType: string;
orderNumber?: number; orderNumber?: number;
occupancyTypeFields?: OccupancyTypeField[]; occupancyTypeFields?: OccupancyTypeField[];
} }
@ -93,8 +93,8 @@ export interface OccupancyTypeField {
orderNumber?: number; orderNumber?: number;
} }
export interface LotOccupantType extends Record { export interface LotOccupantType extends Record {
lotOccupantTypeId?: number; lotOccupantTypeId: number;
lotOccupantType?: string; lotOccupantType: string;
orderNumber?: number; orderNumber?: number;
} }
export interface FeeCategory extends Record { export interface FeeCategory extends Record {
@ -137,7 +137,7 @@ export interface LotOccupancyTransaction extends Record {
transactionDateString?: string; transactionDateString?: string;
transactionTime?: number; transactionTime?: number;
transactionTimeString?: string; transactionTimeString?: string;
transactionAmount?: number; transactionAmount: number;
externalReceiptNumber?: string; externalReceiptNumber?: string;
transactionNote?: string; transactionNote?: string;
} }
@ -197,8 +197,8 @@ export interface WorkOrderType extends Record {
orderNumber?: number; orderNumber?: number;
} }
export interface WorkOrderMilestoneType extends Record { export interface WorkOrderMilestoneType extends Record {
workOrderMilestoneTypeId?: number; workOrderMilestoneTypeId: number;
workOrderMilestoneType?: string; workOrderMilestoneType: string;
orderNumber?: number; orderNumber?: number;
} }
export interface WorkOrderComment extends Record { export interface WorkOrderComment extends Record {

View File

@ -37,8 +37,8 @@ export interface Map extends Record {
} }
export interface LotType extends Record { export interface LotType extends Record {
lotTypeId?: number; lotTypeId: number;
lotType?: string; lotType: string;
orderNumber?: number; orderNumber?: number;
lotTypeFields?: LotTypeField[]; lotTypeFields?: LotTypeField[];
} }
@ -60,8 +60,8 @@ export interface LotTypeField extends Record {
} }
export interface LotStatus extends Record { export interface LotStatus extends Record {
lotStatusId?: number; lotStatusId: number;
lotStatus?: string; lotStatus: string;
orderNumber?: number; orderNumber?: number;
} }
@ -104,8 +104,8 @@ export interface LotComment extends Record {
} }
export interface OccupancyType extends Record { export interface OccupancyType extends Record {
occupancyTypeId?: number; occupancyTypeId: number;
occupancyType?: string; occupancyType: string;
orderNumber?: number; orderNumber?: number;
occupancyTypeFields?: OccupancyTypeField[]; occupancyTypeFields?: OccupancyTypeField[];
} }
@ -123,8 +123,8 @@ export interface OccupancyTypeField {
} }
export interface LotOccupantType extends Record { export interface LotOccupantType extends Record {
lotOccupantTypeId?: number; lotOccupantTypeId: number;
lotOccupantType?: string; lotOccupantType: string;
orderNumber?: number; orderNumber?: number;
} }
@ -182,7 +182,7 @@ export interface LotOccupancyTransaction extends Record {
transactionDateString?: string; transactionDateString?: string;
transactionTime?: number; transactionTime?: number;
transactionTimeString?: string; transactionTimeString?: string;
transactionAmount?: number; transactionAmount: number;
externalReceiptNumber?: string; externalReceiptNumber?: string;
transactionNote?: string; transactionNote?: string;
} }
@ -265,8 +265,8 @@ export interface WorkOrderType extends Record {
} }
export interface WorkOrderMilestoneType extends Record { export interface WorkOrderMilestoneType extends Record {
workOrderMilestoneTypeId?: number; workOrderMilestoneTypeId: number;
workOrderMilestoneType?: string; workOrderMilestoneType: string;
orderNumber?: number; orderNumber?: number;
} }