From c9375218075b95301ec32a6103cdf181d4bd3bbd Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Thu, 12 Jan 2023 10:19:58 -0500 Subject: [PATCH] linting --- handlers/api-get/milestoneICS.ts | 4 +- helpers/lotOccupancyDB/addWorkOrder.js | 10 +- helpers/lotOccupancyDB/addWorkOrder.ts | 10 +- helpers/lotOccupancyDB/addWorkOrderLot.js | 22 +- helpers/lotOccupancyDB/addWorkOrderLot.ts | 22 +- helpers/lotOccupancyDB/closeWorkOrder.js | 8 +- helpers/lotOccupancyDB/closeWorkOrder.ts | 8 +- .../completeWorkOrderMilestone.js | 10 +- .../completeWorkOrderMilestone.ts | 10 +- .../deleteWorkOrderLotOccupancy.js | 8 +- .../deleteWorkOrderLotOccupancy.ts | 8 +- helpers/lotOccupancyDB/getFee.d.ts | 4 +- helpers/lotOccupancyDB/getFee.js | 34 +- helpers/lotOccupancyDB/getFee.ts | 68 +- helpers/lotOccupancyDB/getFeeCategories.d.ts | 2 +- helpers/lotOccupancyDB/getFeeCategories.js | 37 +- helpers/lotOccupancyDB/getFeeCategories.ts | 122 +- helpers/lotOccupancyDB/getFees.d.ts | 4 +- helpers/lotOccupancyDB/getFees.js | 39 +- helpers/lotOccupancyDB/getFees.ts | 121 +- helpers/lotOccupancyDB/getLotComments.d.ts | 4 +- helpers/lotOccupancyDB/getLotComments.js | 28 +- helpers/lotOccupancyDB/getLotComments.ts | 66 +- helpers/lotOccupancyDB/getLotFields.d.ts | 4 +- helpers/lotOccupancyDB/getLotFields.js | 56 +- helpers/lotOccupancyDB/getLotFields.ts | 90 +- helpers/lotOccupancyDB/getLotOccupancy.js | 24 +- helpers/lotOccupancyDB/getLotOccupancy.ts | 24 +- .../lotOccupancyDB/getLotOccupancyFees.d.ts | 4 +- helpers/lotOccupancyDB/getLotOccupancyFees.js | 22 +- helpers/lotOccupancyDB/getLotOccupancyFees.ts | 56 +- .../lotOccupancyDB/getLotOccupancyFields.d.ts | 4 +- .../lotOccupancyDB/getLotOccupancyFields.js | 50 +- .../lotOccupancyDB/getLotOccupancyFields.ts | 84 +- .../getLotOccupancyOccupants.d.ts | 4 +- .../getLotOccupancyOccupants.js | 6 +- .../getLotOccupancyOccupants.ts | 40 +- .../getLotOccupancyTransactions.d.ts | 4 +- .../getLotOccupancyTransactions.js | 26 +- .../getLotOccupancyTransactions.ts | 65 +- .../lotOccupancyDB/getLotOccupantTypes.d.ts | 2 +- helpers/lotOccupancyDB/getLotOccupantTypes.js | 14 +- helpers/lotOccupancyDB/getLotOccupantTypes.ts | 58 +- .../lotOccupancyDB/getLotStatusSummary.d.ts | 2 +- helpers/lotOccupancyDB/getLotStatusSummary.js | 20 +- helpers/lotOccupancyDB/getLotStatusSummary.ts | 54 +- helpers/lotOccupancyDB/getLotStatuses.d.ts | 2 +- helpers/lotOccupancyDB/getLotStatuses.js | 14 +- helpers/lotOccupancyDB/getLotStatuses.ts | 53 +- helpers/lotOccupancyDB/getLotTypeFields.d.ts | 4 +- helpers/lotOccupancyDB/getLotTypeFields.js | 22 +- helpers/lotOccupancyDB/getLotTypeFields.ts | 72 +- helpers/lotOccupancyDB/getLotTypeSummary.d.ts | 2 +- helpers/lotOccupancyDB/getLotTypeSummary.js | 20 +- helpers/lotOccupancyDB/getLotTypeSummary.ts | 54 +- helpers/lotOccupancyDB/getLotTypes.d.ts | 2 +- helpers/lotOccupancyDB/getLotTypes.js | 16 +- helpers/lotOccupancyDB/getLotTypes.ts | 60 +- helpers/lotOccupancyDB/getMap.d.ts | 2 +- helpers/lotOccupancyDB/getMap.js | 38 +- helpers/lotOccupancyDB/getMap.ts | 62 +- helpers/lotOccupancyDB/getMaps.d.ts | 2 +- helpers/lotOccupancyDB/getMaps.js | 26 +- helpers/lotOccupancyDB/getMaps.ts | 50 +- helpers/lotOccupancyDB/getNextLotId.js | 18 +- helpers/lotOccupancyDB/getNextLotId.ts | 56 +- .../getNextWorkOrderNumber.d.ts | 2 +- .../lotOccupancyDB/getNextWorkOrderNumber.js | 24 +- .../lotOccupancyDB/getNextWorkOrderNumber.ts | 83 +- public-scss/style.scss | 1 - temp/legacy.importFromCSV.js | 688 ++-- temp/legacy.importFromCSV.ts | 3273 +++++++++-------- test/1_serverCypress.js | 4 +- test/1_serverCypress.ts | 4 +- test/_globals.d.ts | 4 +- test/_globals.js | 10 +- test/_globals.ts | 238 +- 77 files changed, 3183 insertions(+), 3085 deletions(-) diff --git a/handlers/api-get/milestoneICS.ts b/handlers/api-get/milestoneICS.ts index 5d91790f..4e78c740 100644 --- a/handlers/api-get/milestoneICS.ts +++ b/handlers/api-get/milestoneICS.ts @@ -117,7 +117,7 @@ function buildEventDescriptionHTML_occupancies( ${ occupancy.occupancyEndDate - ? occupancy.occupancyEndDateString + ? occupancy.occupancyEndDateString! : '(No End Date)' } @@ -306,7 +306,7 @@ export const handler: RequestHandler = (request, response) => { }) if (request.query.workOrderId && workOrderMilestones.length > 0) { - calendar.name(`Work Order #${workOrderMilestones[0].workOrderNumber}`) + calendar.name(`Work Order #${workOrderMilestones[0].workOrderNumber!}`) calendar.url(urlRoot + '/workOrders/' + workOrderMilestones[0].workOrderId) } diff --git a/helpers/lotOccupancyDB/addWorkOrder.js b/helpers/lotOccupancyDB/addWorkOrder.js index 28e77064..5b519093 100644 --- a/helpers/lotOccupancyDB/addWorkOrder.js +++ b/helpers/lotOccupancyDB/addWorkOrder.js @@ -12,11 +12,11 @@ export function addWorkOrder(workOrderForm, requestSession) { } const result = database .prepare(`insert into WorkOrders ( - workOrderTypeId, workOrderNumber, workOrderDescription, - workOrderOpenDate, workOrderCloseDate, - recordCreate_userName, recordCreate_timeMillis, - recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?, ?, ?)`) + workOrderTypeId, workOrderNumber, workOrderDescription, + workOrderOpenDate, workOrderCloseDate, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + values (?, ?, ?, ?, ?, ?, ?, ?, ?)`) .run(workOrderForm.workOrderTypeId, workOrderNumber, workOrderForm.workOrderDescription, workOrderForm.workOrderOpenDateString ? dateStringToInteger(workOrderForm.workOrderOpenDateString) : dateToInteger(rightNow), workOrderForm.workOrderCloseDateString diff --git a/helpers/lotOccupancyDB/addWorkOrder.ts b/helpers/lotOccupancyDB/addWorkOrder.ts index 1625332c..b2b10b9f 100644 --- a/helpers/lotOccupancyDB/addWorkOrder.ts +++ b/helpers/lotOccupancyDB/addWorkOrder.ts @@ -38,11 +38,11 @@ export function addWorkOrder( const result = database .prepare( `insert into WorkOrders ( - workOrderTypeId, workOrderNumber, workOrderDescription, - workOrderOpenDate, workOrderCloseDate, - recordCreate_userName, recordCreate_timeMillis, - recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?, ?, ?)` + workOrderTypeId, workOrderNumber, workOrderDescription, + workOrderOpenDate, workOrderCloseDate, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + values (?, ?, ?, ?, ?, ?, ?, ?, ?)` ) .run( workOrderForm.workOrderTypeId, diff --git a/helpers/lotOccupancyDB/addWorkOrderLot.js b/helpers/lotOccupancyDB/addWorkOrderLot.js index 234c5ab8..341ed7ac 100644 --- a/helpers/lotOccupancyDB/addWorkOrderLot.js +++ b/helpers/lotOccupancyDB/addWorkOrderLot.js @@ -5,22 +5,22 @@ export function addWorkOrderLot(workOrderLotForm, requestSession) { const rightNowMillis = Date.now(); const row = database .prepare(`select recordDelete_timeMillis - from WorkOrderLots - where workOrderId = ? - and lotId = ?`) + from WorkOrderLots + where workOrderId = ? + and lotId = ?`) .get(workOrderLotForm.workOrderId, workOrderLotForm.lotId); if (row) { if (row.recordDelete_timeMillis) { database .prepare(`update WorkOrderLots - set recordCreate_userName = ?, - recordCreate_timeMillis = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ?, - recordDelete_userName = null, - recordDelete_timeMillis = null - where workOrderId = ? - and lotId = ?`) + set recordCreate_userName = ?, + recordCreate_timeMillis = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ?, + recordDelete_userName = null, + recordDelete_timeMillis = null + where workOrderId = ? + and lotId = ?`) .run(requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis, workOrderLotForm.workOrderId, workOrderLotForm.lotId); } } diff --git a/helpers/lotOccupancyDB/addWorkOrderLot.ts b/helpers/lotOccupancyDB/addWorkOrderLot.ts index 1073c4bf..76fe58df 100644 --- a/helpers/lotOccupancyDB/addWorkOrderLot.ts +++ b/helpers/lotOccupancyDB/addWorkOrderLot.ts @@ -20,9 +20,9 @@ export function addWorkOrderLot( const row: { recordDelete_timeMillis?: number } = database .prepare( `select recordDelete_timeMillis - from WorkOrderLots - where workOrderId = ? - and lotId = ?` + from WorkOrderLots + where workOrderId = ? + and lotId = ?` ) .get(workOrderLotForm.workOrderId, workOrderLotForm.lotId) @@ -31,14 +31,14 @@ export function addWorkOrderLot( database .prepare( `update WorkOrderLots - set recordCreate_userName = ?, - recordCreate_timeMillis = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ?, - recordDelete_userName = null, - recordDelete_timeMillis = null - where workOrderId = ? - and lotId = ?` + set recordCreate_userName = ?, + recordCreate_timeMillis = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ?, + recordDelete_userName = null, + recordDelete_timeMillis = null + where workOrderId = ? + and lotId = ?` ) .run( requestSession.user!.userName, diff --git a/helpers/lotOccupancyDB/closeWorkOrder.js b/helpers/lotOccupancyDB/closeWorkOrder.js index 4aa832c4..890b5cfa 100644 --- a/helpers/lotOccupancyDB/closeWorkOrder.js +++ b/helpers/lotOccupancyDB/closeWorkOrder.js @@ -6,10 +6,10 @@ export function closeWorkOrder(workOrderForm, requestSession) { const rightNow = new Date(); const result = database .prepare(`update WorkOrders - set workOrderCloseDate = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where workOrderId = ?`) + set workOrderCloseDate = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where workOrderId = ?`) .run(workOrderForm.workOrderCloseDateString ? dateStringToInteger(workOrderForm.workOrderCloseDateString) : dateToInteger(new Date()), requestSession.user.userName, rightNow.getTime(), workOrderForm.workOrderId); diff --git a/helpers/lotOccupancyDB/closeWorkOrder.ts b/helpers/lotOccupancyDB/closeWorkOrder.ts index 0f31c2c9..2b31ae2f 100644 --- a/helpers/lotOccupancyDB/closeWorkOrder.ts +++ b/helpers/lotOccupancyDB/closeWorkOrder.ts @@ -25,10 +25,10 @@ export function closeWorkOrder( const result = database .prepare( `update WorkOrders - set workOrderCloseDate = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where workOrderId = ?` + set workOrderCloseDate = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where workOrderId = ?` ) .run( workOrderForm.workOrderCloseDateString diff --git a/helpers/lotOccupancyDB/completeWorkOrderMilestone.js b/helpers/lotOccupancyDB/completeWorkOrderMilestone.js index ab5013f8..7adfd616 100644 --- a/helpers/lotOccupancyDB/completeWorkOrderMilestone.js +++ b/helpers/lotOccupancyDB/completeWorkOrderMilestone.js @@ -6,11 +6,11 @@ export function completeWorkOrderMilestone(milestoneForm, requestSession) { const database = sqlite(databasePath); const result = database .prepare(`update WorkOrderMilestones - set workOrderMilestoneCompletionDate = ?, - workOrderMilestoneCompletionTime = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where workOrderMilestoneId = ?`) + set workOrderMilestoneCompletionDate = ?, + workOrderMilestoneCompletionTime = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where workOrderMilestoneId = ?`) .run(milestoneForm.workOrderMilestoneCompletionDateString ? dateStringToInteger(milestoneForm.workOrderMilestoneCompletionDateString) : dateToInteger(rightNow), milestoneForm.workOrderMilestoneCompletionTimeString diff --git a/helpers/lotOccupancyDB/completeWorkOrderMilestone.ts b/helpers/lotOccupancyDB/completeWorkOrderMilestone.ts index 0f081de8..b9579cc2 100644 --- a/helpers/lotOccupancyDB/completeWorkOrderMilestone.ts +++ b/helpers/lotOccupancyDB/completeWorkOrderMilestone.ts @@ -30,11 +30,11 @@ export function completeWorkOrderMilestone( const result = database .prepare( `update WorkOrderMilestones - set workOrderMilestoneCompletionDate = ?, - workOrderMilestoneCompletionTime = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where workOrderMilestoneId = ?` + set workOrderMilestoneCompletionDate = ?, + workOrderMilestoneCompletionTime = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where workOrderMilestoneId = ?` ) .run( milestoneForm.workOrderMilestoneCompletionDateString diff --git a/helpers/lotOccupancyDB/deleteWorkOrderLotOccupancy.js b/helpers/lotOccupancyDB/deleteWorkOrderLotOccupancy.js index 66c1c5d4..3968c5f8 100644 --- a/helpers/lotOccupancyDB/deleteWorkOrderLotOccupancy.js +++ b/helpers/lotOccupancyDB/deleteWorkOrderLotOccupancy.js @@ -5,10 +5,10 @@ export function deleteWorkOrderLotOccupancy(workOrderId, lotOccupancyId, request const rightNowMillis = Date.now(); const result = database .prepare(`update WorkOrderLotOccupancies - set recordDelete_userName = ?, - recordDelete_timeMillis = ? - where workOrderId = ? - and lotOccupancyId = ?`) + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where workOrderId = ? + and lotOccupancyId = ?`) .run(requestSession.user.userName, rightNowMillis, workOrderId, lotOccupancyId); database.close(); return result.changes > 0; diff --git a/helpers/lotOccupancyDB/deleteWorkOrderLotOccupancy.ts b/helpers/lotOccupancyDB/deleteWorkOrderLotOccupancy.ts index 93f96e78..7906f035 100644 --- a/helpers/lotOccupancyDB/deleteWorkOrderLotOccupancy.ts +++ b/helpers/lotOccupancyDB/deleteWorkOrderLotOccupancy.ts @@ -16,10 +16,10 @@ export function deleteWorkOrderLotOccupancy( const result = database .prepare( `update WorkOrderLotOccupancies - set recordDelete_userName = ?, - recordDelete_timeMillis = ? - where workOrderId = ? - and lotOccupancyId = ?` + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where workOrderId = ? + and lotOccupancyId = ?` ) .run( requestSession.user!.userName, diff --git a/helpers/lotOccupancyDB/getFee.d.ts b/helpers/lotOccupancyDB/getFee.d.ts index efcdfd90..053951cf 100644 --- a/helpers/lotOccupancyDB/getFee.d.ts +++ b/helpers/lotOccupancyDB/getFee.d.ts @@ -1,4 +1,4 @@ -import sqlite from "better-sqlite3"; -import type * as recordTypes from "../../types/recordTypes"; +import sqlite from 'better-sqlite3'; +import type * as recordTypes from '../../types/recordTypes'; export declare function getFee(feeId: number | string, connectedDatabase?: sqlite.Database): recordTypes.Fee; export default getFee; diff --git a/helpers/lotOccupancyDB/getFee.js b/helpers/lotOccupancyDB/getFee.js index 38339c4f..a334a5ab 100644 --- a/helpers/lotOccupancyDB/getFee.js +++ b/helpers/lotOccupancyDB/getFee.js @@ -1,26 +1,26 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; export function getFee(feeId, connectedDatabase) { - const database = connectedDatabase || + const database = connectedDatabase ?? sqlite(databasePath, { readonly: true }); const fee = database .prepare(`select f.feeId, - f.feeCategoryId, c.feeCategory, - f.feeName, f.feeDescription, - f.occupancyTypeId, o.occupancyType, - f.lotTypeId, l.lotType, - ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction, - f.taxAmount, f.taxPercentage, - f.includeQuantity, f.quantityUnit, - f.isRequired, f.orderNumber - from Fees f - left join FeeCategories c on f.feeCategoryId = c.feeCategoryId - left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId - left join LotTypes l on f.lotTypeId = l.lotTypeId - where f.recordDelete_timeMillis is null - and f.feeId = ?`) + f.feeCategoryId, c.feeCategory, + f.feeName, f.feeDescription, + f.occupancyTypeId, o.occupancyType, + f.lotTypeId, l.lotType, + ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction, + f.taxAmount, f.taxPercentage, + f.includeQuantity, f.quantityUnit, + f.isRequired, f.orderNumber + from Fees f + left join FeeCategories c on f.feeCategoryId = c.feeCategoryId + left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId + left join LotTypes l on f.lotTypeId = l.lotTypeId + where f.recordDelete_timeMillis is null + and f.feeId = ?`) .get(feeId); if (!connectedDatabase) { database.close(); diff --git a/helpers/lotOccupancyDB/getFee.ts b/helpers/lotOccupancyDB/getFee.ts index a1893aae..34e19667 100644 --- a/helpers/lotOccupancyDB/getFee.ts +++ b/helpers/lotOccupancyDB/getFee.ts @@ -1,44 +1,44 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' export function getFee( - feeId: number | string, - connectedDatabase?: sqlite.Database + feeId: number | string, + connectedDatabase?: sqlite.Database ): recordTypes.Fee { - const database = - connectedDatabase || - sqlite(databasePath, { - readonly: true - }); + const database = + connectedDatabase ?? + sqlite(databasePath, { + readonly: true + }) - const fee = database - .prepare( - `select f.feeId, - f.feeCategoryId, c.feeCategory, - f.feeName, f.feeDescription, - f.occupancyTypeId, o.occupancyType, - f.lotTypeId, l.lotType, - ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction, - f.taxAmount, f.taxPercentage, - f.includeQuantity, f.quantityUnit, - f.isRequired, f.orderNumber - from Fees f - left join FeeCategories c on f.feeCategoryId = c.feeCategoryId - left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId - left join LotTypes l on f.lotTypeId = l.lotTypeId - where f.recordDelete_timeMillis is null - and f.feeId = ?` - ) - .get(feeId); + const fee = database + .prepare( + `select f.feeId, + f.feeCategoryId, c.feeCategory, + f.feeName, f.feeDescription, + f.occupancyTypeId, o.occupancyType, + f.lotTypeId, l.lotType, + ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction, + f.taxAmount, f.taxPercentage, + f.includeQuantity, f.quantityUnit, + f.isRequired, f.orderNumber + from Fees f + left join FeeCategories c on f.feeCategoryId = c.feeCategoryId + left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId + left join LotTypes l on f.lotTypeId = l.lotTypeId + where f.recordDelete_timeMillis is null + and f.feeId = ?` + ) + .get(feeId) - if (!connectedDatabase) { - database.close(); - } + if (!connectedDatabase) { + database.close() + } - return fee; + return fee } -export default getFee; +export default getFee diff --git a/helpers/lotOccupancyDB/getFeeCategories.d.ts b/helpers/lotOccupancyDB/getFeeCategories.d.ts index 3abac772..ac19a0d7 100644 --- a/helpers/lotOccupancyDB/getFeeCategories.d.ts +++ b/helpers/lotOccupancyDB/getFeeCategories.d.ts @@ -1,4 +1,4 @@ -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes'; interface GetFeeCategoriesFilters { occupancyTypeId?: number | string; lotTypeId?: number | string; diff --git a/helpers/lotOccupancyDB/getFeeCategories.js b/helpers/lotOccupancyDB/getFeeCategories.js index 89901524..83bc85a5 100644 --- a/helpers/lotOccupancyDB/getFeeCategories.js +++ b/helpers/lotOccupancyDB/getFeeCategories.js @@ -1,41 +1,42 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { getFees } from "./getFees.js"; -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; +import { getFees } from './getFees.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; export function getFeeCategories(filters, options) { const updateOrderNumbers = !(filters.lotTypeId || filters.occupancyTypeId) && options.includeFees; const database = sqlite(databasePath, { readonly: !updateOrderNumbers }); - let sqlWhereClause = " where recordDelete_timeMillis is null"; + let sqlWhereClause = ' where recordDelete_timeMillis is null'; const sqlParameters = []; if (filters.occupancyTypeId) { sqlWhereClause += - " and feeCategoryId in (" + - "select feeCategoryId from Fees" + - " where recordDelete_timeMillis is null" + - " and (occupancyTypeId is null or occupancyTypeId = ?))"; + ' and feeCategoryId in (' + + 'select feeCategoryId from Fees' + + ' where recordDelete_timeMillis is null' + + ' and (occupancyTypeId is null or occupancyTypeId = ?))'; sqlParameters.push(filters.occupancyTypeId); } if (filters.lotTypeId) { sqlWhereClause += - " and feeCategoryId in (" + - "select feeCategoryId from Fees" + - " where recordDelete_timeMillis is null" + - " and (lotTypeId is null or lotTypeId = ?))"; + ' and feeCategoryId in (' + + 'select feeCategoryId from Fees' + + ' where recordDelete_timeMillis is null' + + ' and (lotTypeId is null or lotTypeId = ?))'; sqlParameters.push(filters.lotTypeId); } const feeCategories = database - .prepare("select feeCategoryId, feeCategory, orderNumber" + - " from FeeCategories" + + .prepare('select feeCategoryId, feeCategory, orderNumber' + + ' from FeeCategories' + sqlWhereClause + - " order by orderNumber, feeCategory") + ' order by orderNumber, feeCategory') .all(sqlParameters); if (options.includeFees) { let expectedOrderNumber = 0; for (const feeCategory of feeCategories) { - if (updateOrderNumbers && feeCategory.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber("FeeCategories", feeCategory.feeCategoryId, expectedOrderNumber, database); + if (updateOrderNumbers && + feeCategory.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber('FeeCategories', feeCategory.feeCategoryId, expectedOrderNumber, database); feeCategory.orderNumber = expectedOrderNumber; } expectedOrderNumber += 1; diff --git a/helpers/lotOccupancyDB/getFeeCategories.ts b/helpers/lotOccupancyDB/getFeeCategories.ts index c02e70b0..43e27cfc 100644 --- a/helpers/lotOccupancyDB/getFeeCategories.ts +++ b/helpers/lotOccupancyDB/getFeeCategories.ts @@ -1,88 +1,92 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import { getFees } from "./getFees.js"; -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import { getFees } from './getFees.js' +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' interface GetFeeCategoriesFilters { - occupancyTypeId?: number | string; - lotTypeId?: number | string; + occupancyTypeId?: number | string + lotTypeId?: number | string } interface GetFeeCategoriesOptions { - includeFees?: boolean; + includeFees?: boolean } export function getFeeCategories( - filters: GetFeeCategoriesFilters, - options: GetFeeCategoriesOptions + filters: GetFeeCategoriesFilters, + options: GetFeeCategoriesOptions ): recordTypes.FeeCategory[] { - const updateOrderNumbers = !(filters.lotTypeId || filters.occupancyTypeId) && options.includeFees; + const updateOrderNumbers = + !(filters.lotTypeId || filters.occupancyTypeId) && options.includeFees - const database = sqlite(databasePath, { - readonly: !updateOrderNumbers - }); + const database = sqlite(databasePath, { + readonly: !updateOrderNumbers + }) - let sqlWhereClause = " where recordDelete_timeMillis is null"; + let sqlWhereClause = ' where recordDelete_timeMillis is null' - const sqlParameters: unknown[] = []; + const sqlParameters: unknown[] = [] - if (filters.occupancyTypeId) { - sqlWhereClause += - " and feeCategoryId in (" + - "select feeCategoryId from Fees" + - " where recordDelete_timeMillis is null" + - " and (occupancyTypeId is null or occupancyTypeId = ?))"; + if (filters.occupancyTypeId) { + sqlWhereClause += + ' and feeCategoryId in (' + + 'select feeCategoryId from Fees' + + ' where recordDelete_timeMillis is null' + + ' and (occupancyTypeId is null or occupancyTypeId = ?))' - sqlParameters.push(filters.occupancyTypeId); - } + sqlParameters.push(filters.occupancyTypeId) + } - if (filters.lotTypeId) { - sqlWhereClause += - " and feeCategoryId in (" + - "select feeCategoryId from Fees" + - " where recordDelete_timeMillis is null" + - " and (lotTypeId is null or lotTypeId = ?))"; + if (filters.lotTypeId) { + sqlWhereClause += + ' and feeCategoryId in (' + + 'select feeCategoryId from Fees' + + ' where recordDelete_timeMillis is null' + + ' and (lotTypeId is null or lotTypeId = ?))' - sqlParameters.push(filters.lotTypeId); - } + sqlParameters.push(filters.lotTypeId) + } - const feeCategories: recordTypes.FeeCategory[] = database - .prepare( - "select feeCategoryId, feeCategory, orderNumber" + - " from FeeCategories" + - sqlWhereClause + - " order by orderNumber, feeCategory" + const feeCategories: recordTypes.FeeCategory[] = database + .prepare( + 'select feeCategoryId, feeCategory, orderNumber' + + ' from FeeCategories' + + sqlWhereClause + + ' order by orderNumber, feeCategory' + ) + .all(sqlParameters) + + if (options.includeFees) { + let expectedOrderNumber = 0 + + for (const feeCategory of feeCategories) { + if ( + updateOrderNumbers && + feeCategory.orderNumber !== expectedOrderNumber + ) { + updateRecordOrderNumber( + 'FeeCategories', + feeCategory.feeCategoryId, + expectedOrderNumber, + database ) - .all(sqlParameters); - if (options.includeFees) { - let expectedOrderNumber = 0; + feeCategory.orderNumber = expectedOrderNumber + } - for (const feeCategory of feeCategories) { - if (updateOrderNumbers && feeCategory.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber( - "FeeCategories", - feeCategory.feeCategoryId, - expectedOrderNumber, - database - ); + expectedOrderNumber += 1 - feeCategory.orderNumber = expectedOrderNumber; - } - - expectedOrderNumber += 1; - - feeCategory.fees = getFees(feeCategory.feeCategoryId, filters, database); - } + feeCategory.fees = getFees(feeCategory.feeCategoryId, filters, database) } + } - database.close(); + database.close() - return feeCategories; + return feeCategories } -export default getFeeCategories; +export default getFeeCategories diff --git a/helpers/lotOccupancyDB/getFees.d.ts b/helpers/lotOccupancyDB/getFees.d.ts index 097831fe..e1aacd21 100644 --- a/helpers/lotOccupancyDB/getFees.d.ts +++ b/helpers/lotOccupancyDB/getFees.d.ts @@ -1,5 +1,5 @@ -import sqlite from "better-sqlite3"; -import type * as recordTypes from "../../types/recordTypes"; +import sqlite from 'better-sqlite3'; +import type * as recordTypes from '../../types/recordTypes'; interface GetFeesFilters { occupancyTypeId?: number | string; lotTypeId?: number | string; diff --git a/helpers/lotOccupancyDB/getFees.js b/helpers/lotOccupancyDB/getFees.js index 4267f142..fccd9a79 100644 --- a/helpers/lotOccupancyDB/getFees.js +++ b/helpers/lotOccupancyDB/getFees.js @@ -1,41 +1,42 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; export function getFees(feeCategoryId, additionalFilters, connectedDatabase) { const updateOrderNumbers = !(additionalFilters.lotTypeId || additionalFilters.occupancyTypeId); - const database = connectedDatabase || + const database = connectedDatabase ?? sqlite(databasePath, { readonly: !updateOrderNumbers }); - let sqlWhereClause = " where f.recordDelete_timeMillis is null and f.feeCategoryId = ?"; + let sqlWhereClause = ' where f.recordDelete_timeMillis is null and f.feeCategoryId = ?'; const sqlParameters = [feeCategoryId]; if (additionalFilters.occupancyTypeId) { - sqlWhereClause += " and (f.occupancyTypeId is null or f.occupancyTypeId = ?)"; + sqlWhereClause += + ' and (f.occupancyTypeId is null or f.occupancyTypeId = ?)'; sqlParameters.push(additionalFilters.occupancyTypeId); } if (additionalFilters.lotTypeId) { - sqlWhereClause += " and (f.lotTypeId is null or f.lotTypeId = ?)"; + sqlWhereClause += ' and (f.lotTypeId is null or f.lotTypeId = ?)'; sqlParameters.push(additionalFilters.lotTypeId); } const fees = database - .prepare("select f.feeId, f.feeName, f.feeDescription," + - " f.occupancyTypeId, o.occupancyType," + - " f.lotTypeId, l.lotType," + - " ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction," + - " f.taxAmount, f.taxPercentage," + - " f.includeQuantity, f.quantityUnit," + - " f.isRequired, f.orderNumber" + - " from Fees f" + - " left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId" + - " left join LotTypes l on f.lotTypeId = l.lotTypeId" + + .prepare('select f.feeId, f.feeName, f.feeDescription,' + + ' f.occupancyTypeId, o.occupancyType,' + + ' f.lotTypeId, l.lotType,' + + ' ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction,' + + ' f.taxAmount, f.taxPercentage,' + + ' f.includeQuantity, f.quantityUnit,' + + ' f.isRequired, f.orderNumber' + + ' from Fees f' + + ' left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId' + + ' left join LotTypes l on f.lotTypeId = l.lotTypeId' + sqlWhereClause + - " order by f.orderNumber, f.feeName") + ' order by f.orderNumber, f.feeName') .all(sqlParameters); if (updateOrderNumbers) { let expectedOrderNumber = 0; for (const fee of fees) { if (fee.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber("Fees", fee.feeId, expectedOrderNumber, database); + updateRecordOrderNumber('Fees', fee.feeId, expectedOrderNumber, database); fee.orderNumber = expectedOrderNumber; } expectedOrderNumber += 1; diff --git a/helpers/lotOccupancyDB/getFees.ts b/helpers/lotOccupancyDB/getFees.ts index 2e3d1f8e..76e29aca 100644 --- a/helpers/lotOccupancyDB/getFees.ts +++ b/helpers/lotOccupancyDB/getFees.ts @@ -1,80 +1,89 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' interface GetFeesFilters { - occupancyTypeId?: number | string; - lotTypeId?: number | string; + occupancyTypeId?: number | string + lotTypeId?: number | string } export function getFees( - feeCategoryId: number, - additionalFilters: GetFeesFilters, - connectedDatabase?: sqlite.Database + feeCategoryId: number, + additionalFilters: GetFeesFilters, + connectedDatabase?: sqlite.Database ): recordTypes.Fee[] { - const updateOrderNumbers = !(additionalFilters.lotTypeId || additionalFilters.occupancyTypeId); + const updateOrderNumbers = !( + additionalFilters.lotTypeId || additionalFilters.occupancyTypeId + ) - const database = - connectedDatabase || - sqlite(databasePath, { - readonly: !updateOrderNumbers - }); + const database = + connectedDatabase ?? + sqlite(databasePath, { + readonly: !updateOrderNumbers + }) - let sqlWhereClause = " where f.recordDelete_timeMillis is null and f.feeCategoryId = ?"; + let sqlWhereClause = + ' where f.recordDelete_timeMillis is null and f.feeCategoryId = ?' - const sqlParameters: unknown[] = [feeCategoryId]; + const sqlParameters: unknown[] = [feeCategoryId] - if (additionalFilters.occupancyTypeId) { - sqlWhereClause += " and (f.occupancyTypeId is null or f.occupancyTypeId = ?)"; + if (additionalFilters.occupancyTypeId) { + sqlWhereClause += + ' and (f.occupancyTypeId is null or f.occupancyTypeId = ?)' - sqlParameters.push(additionalFilters.occupancyTypeId); - } + sqlParameters.push(additionalFilters.occupancyTypeId) + } - if (additionalFilters.lotTypeId) { - sqlWhereClause += " and (f.lotTypeId is null or f.lotTypeId = ?)"; + if (additionalFilters.lotTypeId) { + sqlWhereClause += ' and (f.lotTypeId is null or f.lotTypeId = ?)' - sqlParameters.push(additionalFilters.lotTypeId); - } + sqlParameters.push(additionalFilters.lotTypeId) + } - const fees = database - .prepare( - "select f.feeId, f.feeName, f.feeDescription," + - " f.occupancyTypeId, o.occupancyType," + - " f.lotTypeId, l.lotType," + - " ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction," + - " f.taxAmount, f.taxPercentage," + - " f.includeQuantity, f.quantityUnit," + - " f.isRequired, f.orderNumber" + - " from Fees f" + - " left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId" + - " left join LotTypes l on f.lotTypeId = l.lotTypeId" + - sqlWhereClause + - " order by f.orderNumber, f.feeName" + const fees = database + .prepare( + 'select f.feeId, f.feeName, f.feeDescription,' + + ' f.occupancyTypeId, o.occupancyType,' + + ' f.lotTypeId, l.lotType,' + + ' ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction,' + + ' f.taxAmount, f.taxPercentage,' + + ' f.includeQuantity, f.quantityUnit,' + + ' f.isRequired, f.orderNumber' + + ' from Fees f' + + ' left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId' + + ' left join LotTypes l on f.lotTypeId = l.lotTypeId' + + sqlWhereClause + + ' order by f.orderNumber, f.feeName' + ) + .all(sqlParameters) + + if (updateOrderNumbers) { + let expectedOrderNumber = 0 + + for (const fee of fees) { + if (fee.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber( + 'Fees', + fee.feeId, + expectedOrderNumber, + database ) - .all(sqlParameters); + fee.orderNumber = expectedOrderNumber + } - if (updateOrderNumbers) { - let expectedOrderNumber = 0; - - for (const fee of fees) { - if (fee.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber("Fees", fee.feeId, expectedOrderNumber, database); - fee.orderNumber = expectedOrderNumber; - } - - expectedOrderNumber += 1; - } + expectedOrderNumber += 1 } + } - if (!connectedDatabase) { - database.close(); - } + if (!connectedDatabase) { + database.close() + } - return fees; + return fees } -export default getFees; +export default getFees diff --git a/helpers/lotOccupancyDB/getLotComments.d.ts b/helpers/lotOccupancyDB/getLotComments.d.ts index 79355f26..1a05c12b 100644 --- a/helpers/lotOccupancyDB/getLotComments.d.ts +++ b/helpers/lotOccupancyDB/getLotComments.d.ts @@ -1,4 +1,4 @@ -import sqlite from "better-sqlite3"; -import type * as recordTypes from "../../types/recordTypes"; +import sqlite from 'better-sqlite3'; +import type * as recordTypes from '../../types/recordTypes'; export declare function getLotComments(lotId: number | string, connectedDatabase?: sqlite.Database): recordTypes.LotComment[]; export default getLotComments; diff --git a/helpers/lotOccupancyDB/getLotComments.js b/helpers/lotOccupancyDB/getLotComments.js index adacba3b..a2db179a 100644 --- a/helpers/lotOccupancyDB/getLotComments.js +++ b/helpers/lotOccupancyDB/getLotComments.js @@ -1,23 +1,23 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { dateIntegerToString, timeIntegerToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; +import { dateIntegerToString, timeIntegerToString } from '@cityssm/expressjs-server-js/dateTimeFns.js'; export function getLotComments(lotId, connectedDatabase) { - const database = connectedDatabase || + const database = connectedDatabase ?? sqlite(databasePath, { readonly: true }); - database.function("userFn_dateIntegerToString", dateIntegerToString); - database.function("userFn_timeIntegerToString", timeIntegerToString); + database.function('userFn_dateIntegerToString', dateIntegerToString); + database.function('userFn_timeIntegerToString', timeIntegerToString); const lotComments = database .prepare(`select lotCommentId, - lotCommentDate, userFn_dateIntegerToString(lotCommentDate) as lotCommentDateString, - lotCommentTime, userFn_timeIntegerToString(lotCommentTime) as lotCommentTimeString, - lotComment, - recordCreate_userName, recordUpdate_userName - from LotComments - where recordDelete_timeMillis is null - and lotId = ? - order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc`) + lotCommentDate, userFn_dateIntegerToString(lotCommentDate) as lotCommentDateString, + lotCommentTime, userFn_timeIntegerToString(lotCommentTime) as lotCommentTimeString, + lotComment, + recordCreate_userName, recordUpdate_userName + from LotComments + where recordDelete_timeMillis is null + and lotId = ? + order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc`) .all(lotId); if (!connectedDatabase) { database.close(); diff --git a/helpers/lotOccupancyDB/getLotComments.ts b/helpers/lotOccupancyDB/getLotComments.ts index eecab820..db63a381 100644 --- a/helpers/lotOccupancyDB/getLotComments.ts +++ b/helpers/lotOccupancyDB/getLotComments.ts @@ -1,46 +1,46 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' import { - dateIntegerToString, - timeIntegerToString -} from "@cityssm/expressjs-server-js/dateTimeFns.js"; + dateIntegerToString, + timeIntegerToString +} from '@cityssm/expressjs-server-js/dateTimeFns.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' export function getLotComments( - lotId: number | string, - connectedDatabase?: sqlite.Database + lotId: number | string, + connectedDatabase?: sqlite.Database ): recordTypes.LotComment[] { - const database = - connectedDatabase || - sqlite(databasePath, { - readonly: true - }); + const database = + connectedDatabase ?? + sqlite(databasePath, { + readonly: true + }) - database.function("userFn_dateIntegerToString", dateIntegerToString); - database.function("userFn_timeIntegerToString", timeIntegerToString); + database.function('userFn_dateIntegerToString', dateIntegerToString) + database.function('userFn_timeIntegerToString', timeIntegerToString) - const lotComments = database - .prepare( - `select lotCommentId, - lotCommentDate, userFn_dateIntegerToString(lotCommentDate) as lotCommentDateString, - lotCommentTime, userFn_timeIntegerToString(lotCommentTime) as lotCommentTimeString, - lotComment, - recordCreate_userName, recordUpdate_userName - from LotComments - where recordDelete_timeMillis is null - and lotId = ? - order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc` - ) - .all(lotId); + const lotComments = database + .prepare( + `select lotCommentId, + lotCommentDate, userFn_dateIntegerToString(lotCommentDate) as lotCommentDateString, + lotCommentTime, userFn_timeIntegerToString(lotCommentTime) as lotCommentTimeString, + lotComment, + recordCreate_userName, recordUpdate_userName + from LotComments + where recordDelete_timeMillis is null + and lotId = ? + order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc` + ) + .all(lotId) - if (!connectedDatabase) { - database.close(); - } + if (!connectedDatabase) { + database.close() + } - return lotComments; + return lotComments } -export default getLotComments; +export default getLotComments diff --git a/helpers/lotOccupancyDB/getLotFields.d.ts b/helpers/lotOccupancyDB/getLotFields.d.ts index b6486c7d..8594eb5f 100644 --- a/helpers/lotOccupancyDB/getLotFields.d.ts +++ b/helpers/lotOccupancyDB/getLotFields.d.ts @@ -1,4 +1,4 @@ -import sqlite from "better-sqlite3"; -import type * as recordTypes from "../../types/recordTypes"; +import sqlite from 'better-sqlite3'; +import type * as recordTypes from '../../types/recordTypes'; export declare function getLotFields(lotId: number | string, connectedDatabase?: sqlite.Database): recordTypes.LotField[]; export default getLotFields; diff --git a/helpers/lotOccupancyDB/getLotFields.js b/helpers/lotOccupancyDB/getLotFields.js index 6e87598f..47f6d115 100644 --- a/helpers/lotOccupancyDB/getLotFields.js +++ b/helpers/lotOccupancyDB/getLotFields.js @@ -1,37 +1,37 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; export function getLotFields(lotId, connectedDatabase) { - const database = connectedDatabase || + const database = connectedDatabase ?? sqlite(databasePath, { readonly: true }); const lotFields = database .prepare(`select l.lotId, l.lotTypeFieldId, - l.lotFieldValue, - f.lotTypeField, f.lotTypeFieldValues, - f.isRequired, f.pattern, f.minimumLength, f.maximumLength, - f.orderNumber, t.orderNumber as lotTypeOrderNumber - from LotFields l - left join LotTypeFields f on l.lotTypeFieldId = f.lotTypeFieldId - left join LotTypes t on f.lotTypeId = t.lotTypeId - where l.recordDelete_timeMillis is null - and l.lotId = ? - - union - - select ? as lotId, f.lotTypeFieldId, - '' as lotFieldValue, - f.lotTypeField, f.lotTypeFieldValues, - f.isRequired, f.pattern, f.minimumLength, f.maximumLength, - f.orderNumber, t.orderNumber as lotTypeOrderNumber - from LotTypeFields f - left join LotTypes t on f.lotTypeId = t.lotTypeId - where f.recordDelete_timeMillis is null - and ( - f.lotTypeId is null - or f.lotTypeId in (select lotTypeId from Lots where lotId = ?)) - and f.lotTypeFieldId not in (select lotTypeFieldId from LotFields where lotId = ? and recordDelete_timeMillis is null) - order by lotTypeOrderNumber, f.orderNumber, f.lotTypeField`) + l.lotFieldValue, + f.lotTypeField, f.lotTypeFieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as lotTypeOrderNumber + from LotFields l + left join LotTypeFields f on l.lotTypeFieldId = f.lotTypeFieldId + left join LotTypes t on f.lotTypeId = t.lotTypeId + where l.recordDelete_timeMillis is null + and l.lotId = ? + + union + + select ? as lotId, f.lotTypeFieldId, + '' as lotFieldValue, + f.lotTypeField, f.lotTypeFieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as lotTypeOrderNumber + from LotTypeFields f + left join LotTypes t on f.lotTypeId = t.lotTypeId + where f.recordDelete_timeMillis is null + and ( + f.lotTypeId is null + or f.lotTypeId in (select lotTypeId from Lots where lotId = ?)) + and f.lotTypeFieldId not in (select lotTypeFieldId from LotFields where lotId = ? and recordDelete_timeMillis is null) + order by lotTypeOrderNumber, f.orderNumber, f.lotTypeField`) .all(lotId, lotId, lotId, lotId); if (!connectedDatabase) { database.close(); diff --git a/helpers/lotOccupancyDB/getLotFields.ts b/helpers/lotOccupancyDB/getLotFields.ts index c933acae..c3237007 100644 --- a/helpers/lotOccupancyDB/getLotFields.ts +++ b/helpers/lotOccupancyDB/getLotFields.ts @@ -1,55 +1,55 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' export function getLotFields( - lotId: number | string, - connectedDatabase?: sqlite.Database + lotId: number | string, + connectedDatabase?: sqlite.Database ): recordTypes.LotField[] { - const database = - connectedDatabase || - sqlite(databasePath, { - readonly: true - }); + const database = + connectedDatabase ?? + sqlite(databasePath, { + readonly: true + }) - const lotFields: recordTypes.LotField[] = database - .prepare( - `select l.lotId, l.lotTypeFieldId, - l.lotFieldValue, - f.lotTypeField, f.lotTypeFieldValues, - f.isRequired, f.pattern, f.minimumLength, f.maximumLength, - f.orderNumber, t.orderNumber as lotTypeOrderNumber - from LotFields l - left join LotTypeFields f on l.lotTypeFieldId = f.lotTypeFieldId - left join LotTypes t on f.lotTypeId = t.lotTypeId - where l.recordDelete_timeMillis is null - and l.lotId = ? - - union - - select ? as lotId, f.lotTypeFieldId, - '' as lotFieldValue, - f.lotTypeField, f.lotTypeFieldValues, - f.isRequired, f.pattern, f.minimumLength, f.maximumLength, - f.orderNumber, t.orderNumber as lotTypeOrderNumber - from LotTypeFields f - left join LotTypes t on f.lotTypeId = t.lotTypeId - where f.recordDelete_timeMillis is null - and ( - f.lotTypeId is null - or f.lotTypeId in (select lotTypeId from Lots where lotId = ?)) - and f.lotTypeFieldId not in (select lotTypeFieldId from LotFields where lotId = ? and recordDelete_timeMillis is null) - order by lotTypeOrderNumber, f.orderNumber, f.lotTypeField` - ) - .all(lotId, lotId, lotId, lotId); + const lotFields: recordTypes.LotField[] = database + .prepare( + `select l.lotId, l.lotTypeFieldId, + l.lotFieldValue, + f.lotTypeField, f.lotTypeFieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as lotTypeOrderNumber + from LotFields l + left join LotTypeFields f on l.lotTypeFieldId = f.lotTypeFieldId + left join LotTypes t on f.lotTypeId = t.lotTypeId + where l.recordDelete_timeMillis is null + and l.lotId = ? + + union + + select ? as lotId, f.lotTypeFieldId, + '' as lotFieldValue, + f.lotTypeField, f.lotTypeFieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as lotTypeOrderNumber + from LotTypeFields f + left join LotTypes t on f.lotTypeId = t.lotTypeId + where f.recordDelete_timeMillis is null + and ( + f.lotTypeId is null + or f.lotTypeId in (select lotTypeId from Lots where lotId = ?)) + and f.lotTypeFieldId not in (select lotTypeFieldId from LotFields where lotId = ? and recordDelete_timeMillis is null) + order by lotTypeOrderNumber, f.orderNumber, f.lotTypeField` + ) + .all(lotId, lotId, lotId, lotId) - if (!connectedDatabase) { - database.close(); - } + if (!connectedDatabase) { + database.close() + } - return lotFields; + return lotFields } -export default getLotFields; +export default getLotFields diff --git a/helpers/lotOccupancyDB/getLotOccupancy.js b/helpers/lotOccupancyDB/getLotOccupancy.js index 59e4f1dd..f6a30e0c 100644 --- a/helpers/lotOccupancyDB/getLotOccupancy.js +++ b/helpers/lotOccupancyDB/getLotOccupancy.js @@ -15,18 +15,18 @@ export function getLotOccupancy(lotOccupancyId, connectedDatabase) { database.function('userFn_dateIntegerToString', dateIntegerToString); const lotOccupancy = database .prepare(`select o.lotOccupancyId, - o.occupancyTypeId, t.occupancyType, - o.lotId, l.lotName, l.lotTypeId, - l.mapId, m.mapName, - o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString, - o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString, - o.recordUpdate_timeMillis - from LotOccupancies o - left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId - left join Lots l on o.lotId = l.lotId - left join Maps m on l.mapId = m.mapId - where o.recordDelete_timeMillis is null - and o.lotOccupancyId = ?`) + o.occupancyTypeId, t.occupancyType, + o.lotId, l.lotName, l.lotTypeId, + l.mapId, m.mapName, + o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString, + o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString, + o.recordUpdate_timeMillis + from LotOccupancies o + left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId + left join Lots l on o.lotId = l.lotId + left join Maps m on l.mapId = m.mapId + where o.recordDelete_timeMillis is null + and o.lotOccupancyId = ?`) .get(lotOccupancyId); if (lotOccupancy) { lotOccupancy.lotOccupancyFields = getLotOccupancyFields(lotOccupancyId, database); diff --git a/helpers/lotOccupancyDB/getLotOccupancy.ts b/helpers/lotOccupancyDB/getLotOccupancy.ts index 5f9593ed..ac6d67d5 100644 --- a/helpers/lotOccupancyDB/getLotOccupancy.ts +++ b/helpers/lotOccupancyDB/getLotOccupancy.ts @@ -28,18 +28,18 @@ export function getLotOccupancy( const lotOccupancy: recordTypes.LotOccupancy | undefined = database .prepare( `select o.lotOccupancyId, - o.occupancyTypeId, t.occupancyType, - o.lotId, l.lotName, l.lotTypeId, - l.mapId, m.mapName, - o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString, - o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString, - o.recordUpdate_timeMillis - from LotOccupancies o - left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId - left join Lots l on o.lotId = l.lotId - left join Maps m on l.mapId = m.mapId - where o.recordDelete_timeMillis is null - and o.lotOccupancyId = ?` + o.occupancyTypeId, t.occupancyType, + o.lotId, l.lotName, l.lotTypeId, + l.mapId, m.mapName, + o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString, + o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString, + o.recordUpdate_timeMillis + from LotOccupancies o + left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId + left join Lots l on o.lotId = l.lotId + left join Maps m on l.mapId = m.mapId + where o.recordDelete_timeMillis is null + and o.lotOccupancyId = ?` ) .get(lotOccupancyId) diff --git a/helpers/lotOccupancyDB/getLotOccupancyFees.d.ts b/helpers/lotOccupancyDB/getLotOccupancyFees.d.ts index 7ce8e6ec..65d68961 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFees.d.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyFees.d.ts @@ -1,4 +1,4 @@ -import sqlite from "better-sqlite3"; -import type * as recordTypes from "../../types/recordTypes"; +import sqlite from 'better-sqlite3'; +import type * as recordTypes from '../../types/recordTypes'; export declare function getLotOccupancyFees(lotOccupancyId: number | string, connectedDatabase?: sqlite.Database): recordTypes.LotOccupancyFee[]; export default getLotOccupancyFees; diff --git a/helpers/lotOccupancyDB/getLotOccupancyFees.js b/helpers/lotOccupancyDB/getLotOccupancyFees.js index 4484f9bb..e732c006 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFees.js +++ b/helpers/lotOccupancyDB/getLotOccupancyFees.js @@ -1,20 +1,20 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; export function getLotOccupancyFees(lotOccupancyId, connectedDatabase) { - const database = connectedDatabase || + const database = connectedDatabase ?? sqlite(databasePath, { readonly: true }); const lotOccupancyFees = database .prepare(`select o.lotOccupancyId, o.feeId, - c.feeCategory, f.feeName, - f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity - from LotOccupancyFees o - left join Fees f on o.feeId = f.feeId - left join FeeCategories c on f.feeCategoryId = c.feeCategoryId - where o.recordDelete_timeMillis is null - and o.lotOccupancyId = ? - order by o.recordCreate_timeMillis`) + c.feeCategory, f.feeName, + f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity + from LotOccupancyFees o + left join Fees f on o.feeId = f.feeId + left join FeeCategories c on f.feeCategoryId = c.feeCategoryId + where o.recordDelete_timeMillis is null + and o.lotOccupancyId = ? + order by o.recordCreate_timeMillis`) .all(lotOccupancyId); if (!connectedDatabase) { database.close(); diff --git a/helpers/lotOccupancyDB/getLotOccupancyFees.ts b/helpers/lotOccupancyDB/getLotOccupancyFees.ts index 4ba7ebc2..5e6ff2f6 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFees.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyFees.ts @@ -1,38 +1,38 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' export function getLotOccupancyFees( - lotOccupancyId: number | string, - connectedDatabase?: sqlite.Database + lotOccupancyId: number | string, + connectedDatabase?: sqlite.Database ): recordTypes.LotOccupancyFee[] { - const database = - connectedDatabase || - sqlite(databasePath, { - readonly: true - }); + const database = + connectedDatabase ?? + sqlite(databasePath, { + readonly: true + }) - const lotOccupancyFees: recordTypes.LotOccupancyFee[] = database - .prepare( - `select o.lotOccupancyId, o.feeId, - c.feeCategory, f.feeName, - f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity - from LotOccupancyFees o - left join Fees f on o.feeId = f.feeId - left join FeeCategories c on f.feeCategoryId = c.feeCategoryId - where o.recordDelete_timeMillis is null - and o.lotOccupancyId = ? - order by o.recordCreate_timeMillis` - ) - .all(lotOccupancyId); + const lotOccupancyFees: recordTypes.LotOccupancyFee[] = database + .prepare( + `select o.lotOccupancyId, o.feeId, + c.feeCategory, f.feeName, + f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity + from LotOccupancyFees o + left join Fees f on o.feeId = f.feeId + left join FeeCategories c on f.feeCategoryId = c.feeCategoryId + where o.recordDelete_timeMillis is null + and o.lotOccupancyId = ? + order by o.recordCreate_timeMillis` + ) + .all(lotOccupancyId) - if (!connectedDatabase) { - database.close(); - } + if (!connectedDatabase) { + database.close() + } - return lotOccupancyFees; + return lotOccupancyFees } -export default getLotOccupancyFees; +export default getLotOccupancyFees diff --git a/helpers/lotOccupancyDB/getLotOccupancyFields.d.ts b/helpers/lotOccupancyDB/getLotOccupancyFields.d.ts index fdb3db50..c851c93e 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFields.d.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyFields.d.ts @@ -1,4 +1,4 @@ -import sqlite from "better-sqlite3"; -import type * as recordTypes from "../../types/recordTypes"; +import sqlite from 'better-sqlite3'; +import type * as recordTypes from '../../types/recordTypes'; export declare function getLotOccupancyFields(lotOccupancyId: number | string, connectedDatabase?: sqlite.Database): recordTypes.LotOccupancyField[]; export default getLotOccupancyFields; diff --git a/helpers/lotOccupancyDB/getLotOccupancyFields.js b/helpers/lotOccupancyDB/getLotOccupancyFields.js index 164e6cb0..ebcee94d 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFields.js +++ b/helpers/lotOccupancyDB/getLotOccupancyFields.js @@ -1,34 +1,34 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; export function getLotOccupancyFields(lotOccupancyId, connectedDatabase) { - const database = connectedDatabase || + const database = connectedDatabase ?? sqlite(databasePath, { readonly: true }); const lotOccupancyFields = database .prepare(`select o.lotOccupancyId, o.occupancyTypeFieldId, - o.lotOccupancyFieldValue, f.occupancyTypeField, f.occupancyTypeFieldValues, - f.isRequired, f.pattern, f.minimumLength, f.maximumLength, - f.orderNumber, t.orderNumber as occupancyTypeOrderNumber - from LotOccupancyFields o - left join OccupancyTypeFields f on o.occupancyTypeFieldId = f.occupancyTypeFieldId - left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId - where o.recordDelete_timeMillis is null - and o.lotOccupancyId = ? - - union - - select ? as lotOccupancyId, f.occupancyTypeFieldId, - '' as lotOccupancyFieldValue, f.occupancyTypeField, f.occupancyTypeFieldValues, - f.isRequired, f.pattern, f.minimumLength, f.maximumLength, - f.orderNumber, t.orderNumber as occupancyTypeOrderNumber - from OccupancyTypeFields f - left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId - where f.recordDelete_timeMillis is null and ( - f.occupancyTypeId is null - or f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?)) - and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null) - order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField`) + o.lotOccupancyFieldValue, f.occupancyTypeField, f.occupancyTypeFieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as occupancyTypeOrderNumber + from LotOccupancyFields o + left join OccupancyTypeFields f on o.occupancyTypeFieldId = f.occupancyTypeFieldId + left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId + where o.recordDelete_timeMillis is null + and o.lotOccupancyId = ? + + union + + select ? as lotOccupancyId, f.occupancyTypeFieldId, + '' as lotOccupancyFieldValue, f.occupancyTypeField, f.occupancyTypeFieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as occupancyTypeOrderNumber + from OccupancyTypeFields f + left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId + where f.recordDelete_timeMillis is null and ( + f.occupancyTypeId is null + or f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?)) + and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null) + order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField`) .all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId); if (!connectedDatabase) { database.close(); diff --git a/helpers/lotOccupancyDB/getLotOccupancyFields.ts b/helpers/lotOccupancyDB/getLotOccupancyFields.ts index a0e8279b..88245173 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFields.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyFields.ts @@ -1,52 +1,52 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' export function getLotOccupancyFields( - lotOccupancyId: number | string, - connectedDatabase?: sqlite.Database + lotOccupancyId: number | string, + connectedDatabase?: sqlite.Database ): recordTypes.LotOccupancyField[] { - const database = - connectedDatabase || - sqlite(databasePath, { - readonly: true - }); + const database = + connectedDatabase ?? + sqlite(databasePath, { + readonly: true + }) - const lotOccupancyFields: recordTypes.LotOccupancyField[] = database - .prepare( - `select o.lotOccupancyId, o.occupancyTypeFieldId, - o.lotOccupancyFieldValue, f.occupancyTypeField, f.occupancyTypeFieldValues, - f.isRequired, f.pattern, f.minimumLength, f.maximumLength, - f.orderNumber, t.orderNumber as occupancyTypeOrderNumber - from LotOccupancyFields o - left join OccupancyTypeFields f on o.occupancyTypeFieldId = f.occupancyTypeFieldId - left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId - where o.recordDelete_timeMillis is null - and o.lotOccupancyId = ? - - union - - select ? as lotOccupancyId, f.occupancyTypeFieldId, - '' as lotOccupancyFieldValue, f.occupancyTypeField, f.occupancyTypeFieldValues, - f.isRequired, f.pattern, f.minimumLength, f.maximumLength, - f.orderNumber, t.orderNumber as occupancyTypeOrderNumber - from OccupancyTypeFields f - left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId - where f.recordDelete_timeMillis is null and ( - f.occupancyTypeId is null - or f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?)) - and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null) - order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField` - ) - .all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId); + const lotOccupancyFields: recordTypes.LotOccupancyField[] = database + .prepare( + `select o.lotOccupancyId, o.occupancyTypeFieldId, + o.lotOccupancyFieldValue, f.occupancyTypeField, f.occupancyTypeFieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as occupancyTypeOrderNumber + from LotOccupancyFields o + left join OccupancyTypeFields f on o.occupancyTypeFieldId = f.occupancyTypeFieldId + left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId + where o.recordDelete_timeMillis is null + and o.lotOccupancyId = ? + + union + + select ? as lotOccupancyId, f.occupancyTypeFieldId, + '' as lotOccupancyFieldValue, f.occupancyTypeField, f.occupancyTypeFieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as occupancyTypeOrderNumber + from OccupancyTypeFields f + left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId + where f.recordDelete_timeMillis is null and ( + f.occupancyTypeId is null + or f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?)) + and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null) + order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField` + ) + .all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId) - if (!connectedDatabase) { - database.close(); - } + if (!connectedDatabase) { + database.close() + } - return lotOccupancyFields; + return lotOccupancyFields } -export default getLotOccupancyFields; +export default getLotOccupancyFields diff --git a/helpers/lotOccupancyDB/getLotOccupancyOccupants.d.ts b/helpers/lotOccupancyDB/getLotOccupancyOccupants.d.ts index d323eed1..400f67f7 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyOccupants.d.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyOccupants.d.ts @@ -1,4 +1,4 @@ -import sqlite from "better-sqlite3"; -import type * as recordTypes from "../../types/recordTypes"; +import sqlite from 'better-sqlite3'; +import type * as recordTypes from '../../types/recordTypes'; export declare function getLotOccupancyOccupants(lotOccupancyId: number | string, connectedDatabase?: sqlite.Database): recordTypes.LotOccupancyOccupant[]; export default getLotOccupancyOccupants; diff --git a/helpers/lotOccupancyDB/getLotOccupancyOccupants.js b/helpers/lotOccupancyDB/getLotOccupancyOccupants.js index 562cfddf..18df6656 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyOccupants.js +++ b/helpers/lotOccupancyDB/getLotOccupancyOccupants.js @@ -1,7 +1,7 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; export function getLotOccupancyOccupants(lotOccupancyId, connectedDatabase) { - const database = connectedDatabase || + const database = connectedDatabase ?? sqlite(databasePath, { readonly: true }); diff --git a/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts b/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts index 23854a14..60e8d2de 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts @@ -1,22 +1,22 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' export function getLotOccupancyOccupants( - lotOccupancyId: number | string, - connectedDatabase?: sqlite.Database + lotOccupancyId: number | string, + connectedDatabase?: sqlite.Database ): recordTypes.LotOccupancyOccupant[] { - const database = - connectedDatabase || - sqlite(databasePath, { - readonly: true - }); + const database = + connectedDatabase ?? + sqlite(databasePath, { + readonly: true + }) - const lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[] = database - .prepare( - `select o.lotOccupancyId, o.lotOccupantIndex, + const lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[] = database + .prepare( + `select o.lotOccupancyId, o.lotOccupantIndex, o.occupantName, o.occupantAddress1, o.occupantAddress2, o.occupantCity, o.occupantProvince, o.occupantPostalCode, @@ -29,14 +29,14 @@ export function getLotOccupancyOccupants( where o.recordDelete_timeMillis is null and o.lotOccupancyId = ? order by t.orderNumber, t.lotOccupantType, o.occupantName, o.lotOccupantIndex` - ) - .all(lotOccupancyId); + ) + .all(lotOccupancyId) - if (!connectedDatabase) { - database.close(); - } + if (!connectedDatabase) { + database.close() + } - return lotOccupancyOccupants; + return lotOccupancyOccupants } -export default getLotOccupancyOccupants; +export default getLotOccupancyOccupants diff --git a/helpers/lotOccupancyDB/getLotOccupancyTransactions.d.ts b/helpers/lotOccupancyDB/getLotOccupancyTransactions.d.ts index 8400438f..e17952ce 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyTransactions.d.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyTransactions.d.ts @@ -1,4 +1,4 @@ -import sqlite from "better-sqlite3"; -import type * as recordTypes from "../../types/recordTypes"; +import sqlite from 'better-sqlite3'; +import type * as recordTypes from '../../types/recordTypes'; export declare function getLotOccupancyTransactions(lotOccupancyId: number | string, connectedDatabase?: sqlite.Database): recordTypes.LotOccupancyTransaction[]; export default getLotOccupancyTransactions; diff --git a/helpers/lotOccupancyDB/getLotOccupancyTransactions.js b/helpers/lotOccupancyDB/getLotOccupancyTransactions.js index 39f49398..7df89029 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyTransactions.js +++ b/helpers/lotOccupancyDB/getLotOccupancyTransactions.js @@ -1,22 +1,22 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { dateIntegerToString, timeIntegerToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; +import { dateIntegerToString, timeIntegerToString } from '@cityssm/expressjs-server-js/dateTimeFns.js'; export function getLotOccupancyTransactions(lotOccupancyId, connectedDatabase) { - const database = connectedDatabase || + const database = connectedDatabase ?? sqlite(databasePath, { readonly: true }); - database.function("userFn_dateIntegerToString", dateIntegerToString); - database.function("userFn_timeIntegerToString", timeIntegerToString); + database.function('userFn_dateIntegerToString', dateIntegerToString); + database.function('userFn_timeIntegerToString', timeIntegerToString); const lotOccupancyTransactions = database .prepare(`select lotOccupancyId, transactionIndex, - transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString, - transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString, - transactionAmount, externalReceiptNumber, transactionNote - from LotOccupancyTransactions - where recordDelete_timeMillis is null - and lotOccupancyId = ? - order by transactionDate, transactionTime, transactionIndex`) + transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString, + transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString, + transactionAmount, externalReceiptNumber, transactionNote + from LotOccupancyTransactions + where recordDelete_timeMillis is null + and lotOccupancyId = ? + order by transactionDate, transactionTime, transactionIndex`) .all(lotOccupancyId); if (!connectedDatabase) { database.close(); diff --git a/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts b/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts index 1216e335..7765bd6b 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts @@ -1,45 +1,46 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' import { - dateIntegerToString, - timeIntegerToString -} from "@cityssm/expressjs-server-js/dateTimeFns.js"; + dateIntegerToString, + timeIntegerToString +} from '@cityssm/expressjs-server-js/dateTimeFns.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' export function getLotOccupancyTransactions( - lotOccupancyId: number | string, - connectedDatabase?: sqlite.Database + lotOccupancyId: number | string, + connectedDatabase?: sqlite.Database ): recordTypes.LotOccupancyTransaction[] { - const database = - connectedDatabase || - sqlite(databasePath, { - readonly: true - }); + const database = + connectedDatabase ?? + sqlite(databasePath, { + readonly: true + }) - database.function("userFn_dateIntegerToString", dateIntegerToString); - database.function("userFn_timeIntegerToString", timeIntegerToString); + database.function('userFn_dateIntegerToString', dateIntegerToString) + database.function('userFn_timeIntegerToString', timeIntegerToString) - const lotOccupancyTransactions: recordTypes.LotOccupancyTransaction[] = database - .prepare( - `select lotOccupancyId, transactionIndex, - transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString, - transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString, - transactionAmount, externalReceiptNumber, transactionNote - from LotOccupancyTransactions - where recordDelete_timeMillis is null - and lotOccupancyId = ? - order by transactionDate, transactionTime, transactionIndex` - ) - .all(lotOccupancyId); + const lotOccupancyTransactions: recordTypes.LotOccupancyTransaction[] = + database + .prepare( + `select lotOccupancyId, transactionIndex, + transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString, + transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString, + transactionAmount, externalReceiptNumber, transactionNote + from LotOccupancyTransactions + where recordDelete_timeMillis is null + and lotOccupancyId = ? + order by transactionDate, transactionTime, transactionIndex` + ) + .all(lotOccupancyId) - if (!connectedDatabase) { - database.close(); - } + if (!connectedDatabase) { + database.close() + } - return lotOccupancyTransactions; + return lotOccupancyTransactions } -export default getLotOccupancyTransactions; +export default getLotOccupancyTransactions diff --git a/helpers/lotOccupancyDB/getLotOccupantTypes.d.ts b/helpers/lotOccupancyDB/getLotOccupantTypes.d.ts index 03bf3225..20fcd570 100644 --- a/helpers/lotOccupancyDB/getLotOccupantTypes.d.ts +++ b/helpers/lotOccupancyDB/getLotOccupantTypes.d.ts @@ -1,3 +1,3 @@ -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes'; export declare function getLotOccupantTypes(): recordTypes.LotOccupantType[]; export default getLotOccupantTypes; diff --git a/helpers/lotOccupancyDB/getLotOccupantTypes.js b/helpers/lotOccupancyDB/getLotOccupantTypes.js index 0fb66ff3..d405d938 100644 --- a/helpers/lotOccupancyDB/getLotOccupantTypes.js +++ b/helpers/lotOccupancyDB/getLotOccupantTypes.js @@ -1,18 +1,18 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; export function getLotOccupantTypes() { const database = sqlite(databasePath); const lotOccupantTypes = database .prepare(`select lotOccupantTypeId, lotOccupantType, fontAwesomeIconClass, orderNumber - from LotOccupantTypes - where recordDelete_timeMillis is null - order by orderNumber, lotOccupantType`) + from LotOccupantTypes + where recordDelete_timeMillis is null + order by orderNumber, lotOccupantType`) .all(); let expectedOrderNumber = 0; for (const lotOccupantType of lotOccupantTypes) { if (lotOccupantType.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber("LotOccupantTypes", lotOccupantType.lotOccupantTypeId, expectedOrderNumber, database); + updateRecordOrderNumber('LotOccupantTypes', lotOccupantType.lotOccupantTypeId, expectedOrderNumber, database); lotOccupantType.orderNumber = expectedOrderNumber; } expectedOrderNumber += 1; diff --git a/helpers/lotOccupancyDB/getLotOccupantTypes.ts b/helpers/lotOccupancyDB/getLotOccupantTypes.ts index ebefa9f5..1b9d200d 100644 --- a/helpers/lotOccupancyDB/getLotOccupantTypes.ts +++ b/helpers/lotOccupancyDB/getLotOccupantTypes.ts @@ -1,43 +1,43 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' export function getLotOccupantTypes(): recordTypes.LotOccupantType[] { - const database = sqlite(databasePath); + const database = sqlite(databasePath) - const lotOccupantTypes: recordTypes.LotOccupantType[] = database - .prepare( - `select lotOccupantTypeId, lotOccupantType, fontAwesomeIconClass, orderNumber - from LotOccupantTypes - where recordDelete_timeMillis is null - order by orderNumber, lotOccupantType` - ) - .all(); + const lotOccupantTypes: recordTypes.LotOccupantType[] = database + .prepare( + `select lotOccupantTypeId, lotOccupantType, fontAwesomeIconClass, orderNumber + from LotOccupantTypes + where recordDelete_timeMillis is null + order by orderNumber, lotOccupantType` + ) + .all() - let expectedOrderNumber = 0; + let expectedOrderNumber = 0 - for (const lotOccupantType of lotOccupantTypes) { - if (lotOccupantType.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber( - "LotOccupantTypes", - lotOccupantType.lotOccupantTypeId, - expectedOrderNumber, - database - ); + for (const lotOccupantType of lotOccupantTypes) { + if (lotOccupantType.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber( + 'LotOccupantTypes', + lotOccupantType.lotOccupantTypeId, + expectedOrderNumber, + database + ) - lotOccupantType.orderNumber = expectedOrderNumber; - } - - expectedOrderNumber += 1; + lotOccupantType.orderNumber = expectedOrderNumber } - database.close(); + expectedOrderNumber += 1 + } - return lotOccupantTypes; + database.close() + + return lotOccupantTypes } -export default getLotOccupantTypes; +export default getLotOccupantTypes diff --git a/helpers/lotOccupancyDB/getLotStatusSummary.d.ts b/helpers/lotOccupancyDB/getLotStatusSummary.d.ts index e5c1a797..f1c69902 100644 --- a/helpers/lotOccupancyDB/getLotStatusSummary.d.ts +++ b/helpers/lotOccupancyDB/getLotStatusSummary.d.ts @@ -1,4 +1,4 @@ -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes'; interface GetFilters { mapId?: number | string; } diff --git a/helpers/lotOccupancyDB/getLotStatusSummary.js b/helpers/lotOccupancyDB/getLotStatusSummary.js index 582ceff4..143ccdfa 100644 --- a/helpers/lotOccupancyDB/getLotStatusSummary.js +++ b/helpers/lotOccupancyDB/getLotStatusSummary.js @@ -1,22 +1,22 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; export function getLotStatusSummary(filters) { const database = sqlite(databasePath, { readonly: true }); - let sqlWhereClause = " where l.recordDelete_timeMillis is null"; + let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; const sqlParameters = []; - if (filters && filters.mapId) { - sqlWhereClause += " and l.mapId = ?"; + if (filters?.mapId) { + sqlWhereClause += ' and l.mapId = ?'; sqlParameters.push(filters.mapId); } const lotStatuses = database - .prepare("select s.lotStatusId, s.lotStatus, count(l.lotId) as lotCount" + - " from Lots l" + - " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + + .prepare('select s.lotStatusId, s.lotStatus, count(l.lotId) as lotCount' + + ' from Lots l' + + ' left join LotStatuses s on l.lotStatusId = s.lotStatusId' + sqlWhereClause + - " group by s.lotStatusId, s.lotStatus, s.orderNumber" + - " order by s.orderNumber") + ' group by s.lotStatusId, s.lotStatus, s.orderNumber' + + ' order by s.orderNumber') .all(sqlParameters); database.close(); return lotStatuses; diff --git a/helpers/lotOccupancyDB/getLotStatusSummary.ts b/helpers/lotOccupancyDB/getLotStatusSummary.ts index 7f223e34..fb94e1f1 100644 --- a/helpers/lotOccupancyDB/getLotStatusSummary.ts +++ b/helpers/lotOccupancyDB/getLotStatusSummary.ts @@ -1,44 +1,44 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' interface GetFilters { - mapId?: number | string; + mapId?: number | string } interface LotStatusSummary extends recordTypes.LotStatus { - lotCount: number; + lotCount: number } export function getLotStatusSummary(filters?: GetFilters): LotStatusSummary[] { - const database = sqlite(databasePath, { - readonly: true - }); + const database = sqlite(databasePath, { + readonly: true + }) - let sqlWhereClause = " where l.recordDelete_timeMillis is null"; - const sqlParameters: unknown[] = []; + let sqlWhereClause = ' where l.recordDelete_timeMillis is null' + const sqlParameters: unknown[] = [] - if (filters && filters.mapId) { - sqlWhereClause += " and l.mapId = ?"; - sqlParameters.push(filters.mapId); - } + if (filters?.mapId) { + sqlWhereClause += ' and l.mapId = ?' + sqlParameters.push(filters.mapId) + } - const lotStatuses: LotStatusSummary[] = database - .prepare( - "select s.lotStatusId, s.lotStatus, count(l.lotId) as lotCount" + - " from Lots l" + - " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + - sqlWhereClause + - " group by s.lotStatusId, s.lotStatus, s.orderNumber" + - " order by s.orderNumber" - ) - .all(sqlParameters); + const lotStatuses: LotStatusSummary[] = database + .prepare( + 'select s.lotStatusId, s.lotStatus, count(l.lotId) as lotCount' + + ' from Lots l' + + ' left join LotStatuses s on l.lotStatusId = s.lotStatusId' + + sqlWhereClause + + ' group by s.lotStatusId, s.lotStatus, s.orderNumber' + + ' order by s.orderNumber' + ) + .all(sqlParameters) - database.close(); + database.close() - return lotStatuses; + return lotStatuses } -export default getLotStatusSummary; +export default getLotStatusSummary diff --git a/helpers/lotOccupancyDB/getLotStatuses.d.ts b/helpers/lotOccupancyDB/getLotStatuses.d.ts index d756cbf9..10d7d209 100644 --- a/helpers/lotOccupancyDB/getLotStatuses.d.ts +++ b/helpers/lotOccupancyDB/getLotStatuses.d.ts @@ -1,3 +1,3 @@ -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes'; export declare function getLotStatuses(): recordTypes.LotStatus[]; export default getLotStatuses; diff --git a/helpers/lotOccupancyDB/getLotStatuses.js b/helpers/lotOccupancyDB/getLotStatuses.js index 2088ef88..72d3ed2f 100644 --- a/helpers/lotOccupancyDB/getLotStatuses.js +++ b/helpers/lotOccupancyDB/getLotStatuses.js @@ -1,18 +1,18 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; export function getLotStatuses() { const database = sqlite(databasePath); const lotStatuses = database .prepare(`select lotStatusId, lotStatus, orderNumber - from LotStatuses - where recordDelete_timeMillis is null - order by orderNumber, lotStatus`) + from LotStatuses + where recordDelete_timeMillis is null + order by orderNumber, lotStatus`) .all(); let expectedOrderNumber = 0; for (const lotStatus of lotStatuses) { if (lotStatus.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber("LotStatuses", lotStatus.lotStatusId, expectedOrderNumber, database); + updateRecordOrderNumber('LotStatuses', lotStatus.lotStatusId, expectedOrderNumber, database); lotStatus.orderNumber = expectedOrderNumber; } expectedOrderNumber += 1; diff --git a/helpers/lotOccupancyDB/getLotStatuses.ts b/helpers/lotOccupancyDB/getLotStatuses.ts index 8241ad7e..2167102b 100644 --- a/helpers/lotOccupancyDB/getLotStatuses.ts +++ b/helpers/lotOccupancyDB/getLotStatuses.ts @@ -1,37 +1,42 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' export function getLotStatuses(): recordTypes.LotStatus[] { - const database = sqlite(databasePath); + const database = sqlite(databasePath) - const lotStatuses: recordTypes.LotStatus[] = database - .prepare( - `select lotStatusId, lotStatus, orderNumber - from LotStatuses - where recordDelete_timeMillis is null - order by orderNumber, lotStatus` - ) - .all(); + const lotStatuses: recordTypes.LotStatus[] = database + .prepare( + `select lotStatusId, lotStatus, orderNumber + from LotStatuses + where recordDelete_timeMillis is null + order by orderNumber, lotStatus` + ) + .all() - let expectedOrderNumber = 0; + let expectedOrderNumber = 0 - for (const lotStatus of lotStatuses) { - if (lotStatus.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber("LotStatuses", lotStatus.lotStatusId, expectedOrderNumber, database); - lotStatus.orderNumber = expectedOrderNumber; - } - - expectedOrderNumber += 1; + for (const lotStatus of lotStatuses) { + if (lotStatus.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber( + 'LotStatuses', + lotStatus.lotStatusId, + expectedOrderNumber, + database + ) + lotStatus.orderNumber = expectedOrderNumber } - database.close(); + expectedOrderNumber += 1 + } - return lotStatuses; + database.close() + + return lotStatuses } -export default getLotStatuses; +export default getLotStatuses diff --git a/helpers/lotOccupancyDB/getLotTypeFields.d.ts b/helpers/lotOccupancyDB/getLotTypeFields.d.ts index 7dfccac7..8a8e67c4 100644 --- a/helpers/lotOccupancyDB/getLotTypeFields.d.ts +++ b/helpers/lotOccupancyDB/getLotTypeFields.d.ts @@ -1,4 +1,4 @@ -import sqlite from "better-sqlite3"; -import type * as recordTypes from "../../types/recordTypes"; +import sqlite from 'better-sqlite3'; +import type * as recordTypes from '../../types/recordTypes'; export declare function getLotTypeFields(lotTypeId: number, connectedDatabase?: sqlite.Database): recordTypes.LotTypeField[]; export default getLotTypeFields; diff --git a/helpers/lotOccupancyDB/getLotTypeFields.js b/helpers/lotOccupancyDB/getLotTypeFields.js index 7eef7a44..d6b11117 100644 --- a/helpers/lotOccupancyDB/getLotTypeFields.js +++ b/helpers/lotOccupancyDB/getLotTypeFields.js @@ -1,21 +1,21 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; export function getLotTypeFields(lotTypeId, connectedDatabase) { - const database = connectedDatabase || sqlite(databasePath); + const database = connectedDatabase ?? sqlite(databasePath); const lotTypeFields = database .prepare(`select lotTypeFieldId, - lotTypeField, lotTypeFieldValues, - isRequired, pattern, minimumLength, maximumLength, orderNumber - from LotTypeFields - where recordDelete_timeMillis is null - and lotTypeId = ? - order by orderNumber, lotTypeField`) + lotTypeField, lotTypeFieldValues, + isRequired, pattern, minimumLength, maximumLength, orderNumber + from LotTypeFields + where recordDelete_timeMillis is null + and lotTypeId = ? + order by orderNumber, lotTypeField`) .all(lotTypeId); let expectedOrderNumber = 0; for (const lotTypeField of lotTypeFields) { if (lotTypeField.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber("LotTypeFields", lotTypeField.lotTypeFieldId, expectedOrderNumber, database); + updateRecordOrderNumber('LotTypeFields', lotTypeField.lotTypeFieldId, expectedOrderNumber, database); lotTypeField.orderNumber = expectedOrderNumber; } expectedOrderNumber += 1; diff --git a/helpers/lotOccupancyDB/getLotTypeFields.ts b/helpers/lotOccupancyDB/getLotTypeFields.ts index 7243651f..6aad329c 100644 --- a/helpers/lotOccupancyDB/getLotTypeFields.ts +++ b/helpers/lotOccupancyDB/getLotTypeFields.ts @@ -1,50 +1,50 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import type * as recordTypes from "../../types/recordTypes"; -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import type * as recordTypes from '../../types/recordTypes' +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' export function getLotTypeFields( - lotTypeId: number, - connectedDatabase?: sqlite.Database + lotTypeId: number, + connectedDatabase?: sqlite.Database ): recordTypes.LotTypeField[] { - const database = connectedDatabase || sqlite(databasePath); + const database = connectedDatabase ?? sqlite(databasePath) - const lotTypeFields: recordTypes.LotTypeField[] = database - .prepare( - `select lotTypeFieldId, - lotTypeField, lotTypeFieldValues, - isRequired, pattern, minimumLength, maximumLength, orderNumber - from LotTypeFields - where recordDelete_timeMillis is null - and lotTypeId = ? - order by orderNumber, lotTypeField` - ) - .all(lotTypeId); + const lotTypeFields: recordTypes.LotTypeField[] = database + .prepare( + `select lotTypeFieldId, + lotTypeField, lotTypeFieldValues, + isRequired, pattern, minimumLength, maximumLength, orderNumber + from LotTypeFields + where recordDelete_timeMillis is null + and lotTypeId = ? + order by orderNumber, lotTypeField` + ) + .all(lotTypeId) - let expectedOrderNumber = 0; + let expectedOrderNumber = 0 - for (const lotTypeField of lotTypeFields) { - if (lotTypeField.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber( - "LotTypeFields", - lotTypeField.lotTypeFieldId, - expectedOrderNumber, - database - ); + for (const lotTypeField of lotTypeFields) { + if (lotTypeField.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber( + 'LotTypeFields', + lotTypeField.lotTypeFieldId, + expectedOrderNumber, + database + ) - lotTypeField.orderNumber = expectedOrderNumber; - } - - expectedOrderNumber += 1; + lotTypeField.orderNumber = expectedOrderNumber } - if (!connectedDatabase) { - database.close(); - } + expectedOrderNumber += 1 + } - return lotTypeFields; + if (!connectedDatabase) { + database.close() + } + + return lotTypeFields } -export default getLotTypeFields; +export default getLotTypeFields diff --git a/helpers/lotOccupancyDB/getLotTypeSummary.d.ts b/helpers/lotOccupancyDB/getLotTypeSummary.d.ts index 43e40ad7..1bbe4aac 100644 --- a/helpers/lotOccupancyDB/getLotTypeSummary.d.ts +++ b/helpers/lotOccupancyDB/getLotTypeSummary.d.ts @@ -1,4 +1,4 @@ -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes'; interface GetFilters { mapId?: number | string; } diff --git a/helpers/lotOccupancyDB/getLotTypeSummary.js b/helpers/lotOccupancyDB/getLotTypeSummary.js index fbc4f17f..8617fab6 100644 --- a/helpers/lotOccupancyDB/getLotTypeSummary.js +++ b/helpers/lotOccupancyDB/getLotTypeSummary.js @@ -1,22 +1,22 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; export function getLotTypeSummary(filters) { const database = sqlite(databasePath, { readonly: true }); - let sqlWhereClause = " where l.recordDelete_timeMillis is null"; + let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; const sqlParameters = []; - if (filters && filters.mapId) { - sqlWhereClause += " and l.mapId = ?"; + if (filters?.mapId) { + sqlWhereClause += ' and l.mapId = ?'; sqlParameters.push(filters.mapId); } const lotTypes = database - .prepare("select t.lotTypeId, t.lotType, count(l.lotId) as lotCount" + - " from Lots l" + - " left join LotTypes t on l.lotTypeId = t.lotTypeId" + + .prepare('select t.lotTypeId, t.lotType, count(l.lotId) as lotCount' + + ' from Lots l' + + ' left join LotTypes t on l.lotTypeId = t.lotTypeId' + sqlWhereClause + - " group by t.lotTypeId, t.lotType, t.orderNumber" + - " order by t.orderNumber") + ' group by t.lotTypeId, t.lotType, t.orderNumber' + + ' order by t.orderNumber') .all(sqlParameters); database.close(); return lotTypes; diff --git a/helpers/lotOccupancyDB/getLotTypeSummary.ts b/helpers/lotOccupancyDB/getLotTypeSummary.ts index 36db91bf..a4f59cf2 100644 --- a/helpers/lotOccupancyDB/getLotTypeSummary.ts +++ b/helpers/lotOccupancyDB/getLotTypeSummary.ts @@ -1,44 +1,44 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' interface GetFilters { - mapId?: number | string; + mapId?: number | string } interface LotTypeSummary extends recordTypes.LotType { - lotCount: number; + lotCount: number } export function getLotTypeSummary(filters?: GetFilters): LotTypeSummary[] { - const database = sqlite(databasePath, { - readonly: true - }); + const database = sqlite(databasePath, { + readonly: true + }) - let sqlWhereClause = " where l.recordDelete_timeMillis is null"; - const sqlParameters: unknown[] = []; + let sqlWhereClause = ' where l.recordDelete_timeMillis is null' + const sqlParameters: unknown[] = [] - if (filters && filters.mapId) { - sqlWhereClause += " and l.mapId = ?"; - sqlParameters.push(filters.mapId); - } + if (filters?.mapId) { + sqlWhereClause += ' and l.mapId = ?' + sqlParameters.push(filters.mapId) + } - const lotTypes: LotTypeSummary[] = database - .prepare( - "select t.lotTypeId, t.lotType, count(l.lotId) as lotCount" + - " from Lots l" + - " left join LotTypes t on l.lotTypeId = t.lotTypeId" + - sqlWhereClause + - " group by t.lotTypeId, t.lotType, t.orderNumber" + - " order by t.orderNumber" - ) - .all(sqlParameters); + const lotTypes: LotTypeSummary[] = database + .prepare( + 'select t.lotTypeId, t.lotType, count(l.lotId) as lotCount' + + ' from Lots l' + + ' left join LotTypes t on l.lotTypeId = t.lotTypeId' + + sqlWhereClause + + ' group by t.lotTypeId, t.lotType, t.orderNumber' + + ' order by t.orderNumber' + ) + .all(sqlParameters) - database.close(); + database.close() - return lotTypes; + return lotTypes } -export default getLotTypeSummary; +export default getLotTypeSummary diff --git a/helpers/lotOccupancyDB/getLotTypes.d.ts b/helpers/lotOccupancyDB/getLotTypes.d.ts index 76b6dbee..a319fd7c 100644 --- a/helpers/lotOccupancyDB/getLotTypes.d.ts +++ b/helpers/lotOccupancyDB/getLotTypes.d.ts @@ -1,3 +1,3 @@ -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes'; export declare function getLotTypes(): recordTypes.LotType[]; export default getLotTypes; diff --git a/helpers/lotOccupancyDB/getLotTypes.js b/helpers/lotOccupancyDB/getLotTypes.js index 2c32872d..129267e2 100644 --- a/helpers/lotOccupancyDB/getLotTypes.js +++ b/helpers/lotOccupancyDB/getLotTypes.js @@ -1,20 +1,20 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { getLotTypeFields } from "./getLotTypeFields.js"; -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; +import { getLotTypeFields } from './getLotTypeFields.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; export function getLotTypes() { const database = sqlite(databasePath); const lotTypes = database .prepare(`select lotTypeId, lotType, orderNumber - from LotTypes - where recordDelete_timeMillis is null - order by orderNumber, lotType`) + from LotTypes + where recordDelete_timeMillis is null + order by orderNumber, lotType`) .all(); let expectedTypeOrderNumber = -1; for (const lotType of lotTypes) { expectedTypeOrderNumber += 1; if (lotType.orderNumber !== expectedTypeOrderNumber) { - updateRecordOrderNumber("LotTypes", lotType.lotTypeId, expectedTypeOrderNumber, database); + updateRecordOrderNumber('LotTypes', lotType.lotTypeId, expectedTypeOrderNumber, database); lotType.orderNumber = expectedTypeOrderNumber; } lotType.lotTypeFields = getLotTypeFields(lotType.lotTypeId, database); diff --git a/helpers/lotOccupancyDB/getLotTypes.ts b/helpers/lotOccupancyDB/getLotTypes.ts index 2182e108..6b275e64 100644 --- a/helpers/lotOccupancyDB/getLotTypes.ts +++ b/helpers/lotOccupancyDB/getLotTypes.ts @@ -1,41 +1,49 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import { getLotTypeFields } from "./getLotTypeFields.js"; +import { getLotTypeFields } from './getLotTypeFields.js' -import type * as recordTypes from "../../types/recordTypes"; -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; +import type * as recordTypes from '../../types/recordTypes' +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' export function getLotTypes(): recordTypes.LotType[] { - const database = sqlite(databasePath); + const database = sqlite(databasePath) - const lotTypes: recordTypes.LotType[] = database - .prepare( - `select lotTypeId, lotType, orderNumber - from LotTypes - where recordDelete_timeMillis is null - order by orderNumber, lotType` - ) - .all(); + const lotTypes: recordTypes.LotType[] = database + .prepare( + `select lotTypeId, lotType, orderNumber + from LotTypes + where recordDelete_timeMillis is null + order by orderNumber, lotType` + ) + .all() - let expectedTypeOrderNumber = -1; + let expectedTypeOrderNumber = -1 - for (const lotType of lotTypes) { - expectedTypeOrderNumber += 1; + for (const lotType of lotTypes) { + expectedTypeOrderNumber += 1 - if (lotType.orderNumber !== expectedTypeOrderNumber) { - updateRecordOrderNumber("LotTypes", lotType.lotTypeId, expectedTypeOrderNumber, database); + if (lotType.orderNumber !== expectedTypeOrderNumber) { + updateRecordOrderNumber( + 'LotTypes', + lotType.lotTypeId, + expectedTypeOrderNumber, + database + ) - lotType.orderNumber = expectedTypeOrderNumber; - } - - lotType.lotTypeFields = getLotTypeFields(lotType.lotTypeId as number, database); + lotType.orderNumber = expectedTypeOrderNumber } - database.close(); + lotType.lotTypeFields = getLotTypeFields( + lotType.lotTypeId, + database + ) + } - return lotTypes; + database.close() + + return lotTypes } -export default getLotTypes; +export default getLotTypes diff --git a/helpers/lotOccupancyDB/getMap.d.ts b/helpers/lotOccupancyDB/getMap.d.ts index f05d64d8..27d44545 100644 --- a/helpers/lotOccupancyDB/getMap.d.ts +++ b/helpers/lotOccupancyDB/getMap.d.ts @@ -1,3 +1,3 @@ -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes'; export declare function getMap(mapId: number | string): recordTypes.Map; export default getMap; diff --git a/helpers/lotOccupancyDB/getMap.js b/helpers/lotOccupancyDB/getMap.js index 3725dade..d6d63565 100644 --- a/helpers/lotOccupancyDB/getMap.js +++ b/helpers/lotOccupancyDB/getMap.js @@ -1,28 +1,28 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; export function getMap(mapId) { const database = sqlite(databasePath, { readonly: true }); const map = database .prepare(`select m.mapId, m.mapName, m.mapDescription, - m.mapLatitude, m.mapLongitude, m.mapSVG, - m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, - m.mapPhoneNumber, - m.recordCreate_userName, m.recordCreate_timeMillis, - m.recordUpdate_userName, m.recordUpdate_timeMillis, - m.recordDelete_userName, m.recordDelete_timeMillis, - count(l.lotId) as lotCount - from Maps m - left join Lots l on m.mapId = l.mapId and l.recordDelete_timeMillis is null - where m.mapId = ? - group by m.mapId, m.mapName, m.mapDescription, - m.mapLatitude, m.mapLongitude, m.mapSVG, - m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, - m.mapPhoneNumber, - m.recordCreate_userName, m.recordCreate_timeMillis, - m.recordUpdate_userName, m.recordUpdate_timeMillis, - m.recordDelete_userName, m.recordDelete_timeMillis`) + m.mapLatitude, m.mapLongitude, m.mapSVG, + m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, + m.mapPhoneNumber, + m.recordCreate_userName, m.recordCreate_timeMillis, + m.recordUpdate_userName, m.recordUpdate_timeMillis, + m.recordDelete_userName, m.recordDelete_timeMillis, + count(l.lotId) as lotCount + from Maps m + left join Lots l on m.mapId = l.mapId and l.recordDelete_timeMillis is null + where m.mapId = ? + group by m.mapId, m.mapName, m.mapDescription, + m.mapLatitude, m.mapLongitude, m.mapSVG, + m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, + m.mapPhoneNumber, + m.recordCreate_userName, m.recordCreate_timeMillis, + m.recordUpdate_userName, m.recordUpdate_timeMillis, + m.recordDelete_userName, m.recordDelete_timeMillis`) .get(mapId); database.close(); return map; diff --git a/helpers/lotOccupancyDB/getMap.ts b/helpers/lotOccupancyDB/getMap.ts index 4c4a7bba..ece0cfcf 100644 --- a/helpers/lotOccupancyDB/getMap.ts +++ b/helpers/lotOccupancyDB/getMap.ts @@ -1,40 +1,40 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' export function getMap(mapId: number | string): recordTypes.Map { - const database = sqlite(databasePath, { - readonly: true - }); + const database = sqlite(databasePath, { + readonly: true + }) - const map: recordTypes.Map = database - .prepare( - `select m.mapId, m.mapName, m.mapDescription, - m.mapLatitude, m.mapLongitude, m.mapSVG, - m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, - m.mapPhoneNumber, - m.recordCreate_userName, m.recordCreate_timeMillis, - m.recordUpdate_userName, m.recordUpdate_timeMillis, - m.recordDelete_userName, m.recordDelete_timeMillis, - count(l.lotId) as lotCount - from Maps m - left join Lots l on m.mapId = l.mapId and l.recordDelete_timeMillis is null - where m.mapId = ? - group by m.mapId, m.mapName, m.mapDescription, - m.mapLatitude, m.mapLongitude, m.mapSVG, - m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, - m.mapPhoneNumber, - m.recordCreate_userName, m.recordCreate_timeMillis, - m.recordUpdate_userName, m.recordUpdate_timeMillis, - m.recordDelete_userName, m.recordDelete_timeMillis` - ) - .get(mapId); + const map: recordTypes.Map = database + .prepare( + `select m.mapId, m.mapName, m.mapDescription, + m.mapLatitude, m.mapLongitude, m.mapSVG, + m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, + m.mapPhoneNumber, + m.recordCreate_userName, m.recordCreate_timeMillis, + m.recordUpdate_userName, m.recordUpdate_timeMillis, + m.recordDelete_userName, m.recordDelete_timeMillis, + count(l.lotId) as lotCount + from Maps m + left join Lots l on m.mapId = l.mapId and l.recordDelete_timeMillis is null + where m.mapId = ? + group by m.mapId, m.mapName, m.mapDescription, + m.mapLatitude, m.mapLongitude, m.mapSVG, + m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, + m.mapPhoneNumber, + m.recordCreate_userName, m.recordCreate_timeMillis, + m.recordUpdate_userName, m.recordUpdate_timeMillis, + m.recordDelete_userName, m.recordDelete_timeMillis` + ) + .get(mapId) - database.close(); + database.close() - return map; + return map } -export default getMap; +export default getMap diff --git a/helpers/lotOccupancyDB/getMaps.d.ts b/helpers/lotOccupancyDB/getMaps.d.ts index b5381f8e..552eebea 100644 --- a/helpers/lotOccupancyDB/getMaps.d.ts +++ b/helpers/lotOccupancyDB/getMaps.d.ts @@ -1,3 +1,3 @@ -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes'; export declare function getMaps(): recordTypes.Map[]; export default getMaps; diff --git a/helpers/lotOccupancyDB/getMaps.js b/helpers/lotOccupancyDB/getMaps.js index b9cf1c24..18b2a8b2 100644 --- a/helpers/lotOccupancyDB/getMaps.js +++ b/helpers/lotOccupancyDB/getMaps.js @@ -1,22 +1,22 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; export function getMaps() { const database = sqlite(databasePath, { readonly: true }); const maps = database .prepare(`select m.mapId, m.mapName, m.mapDescription, - m.mapLatitude, m.mapLongitude, m.mapSVG, - m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, - m.mapPhoneNumber, - ifnull(l.lotCount,0) as lotCount - from Maps m - left join ( - select mapId, count(lotId) as lotCount - from Lots - where recordDelete_timeMillis is null group by mapId - ) l on m.mapId = l.mapId - where m.recordDelete_timeMillis is null order by m.mapName, m.mapId`) + m.mapLatitude, m.mapLongitude, m.mapSVG, + m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, + m.mapPhoneNumber, + ifnull(l.lotCount,0) as lotCount + from Maps m + left join ( + select mapId, count(lotId) as lotCount + from Lots + where recordDelete_timeMillis is null group by mapId + ) l on m.mapId = l.mapId + where m.recordDelete_timeMillis is null order by m.mapName, m.mapId`) .all(); database.close(); return maps; diff --git a/helpers/lotOccupancyDB/getMaps.ts b/helpers/lotOccupancyDB/getMaps.ts index 249052b4..afb10f4f 100644 --- a/helpers/lotOccupancyDB/getMaps.ts +++ b/helpers/lotOccupancyDB/getMaps.ts @@ -1,34 +1,34 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import type * as recordTypes from "../../types/recordTypes"; +import type * as recordTypes from '../../types/recordTypes' export function getMaps(): recordTypes.Map[] { - const database = sqlite(databasePath, { - readonly: true - }); + const database = sqlite(databasePath, { + readonly: true + }) - const maps: recordTypes.Map[] = database - .prepare( - `select m.mapId, m.mapName, m.mapDescription, - m.mapLatitude, m.mapLongitude, m.mapSVG, - m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, - m.mapPhoneNumber, - ifnull(l.lotCount,0) as lotCount - from Maps m - left join ( - select mapId, count(lotId) as lotCount - from Lots - where recordDelete_timeMillis is null group by mapId - ) l on m.mapId = l.mapId - where m.recordDelete_timeMillis is null order by m.mapName, m.mapId` - ) - .all(); + const maps: recordTypes.Map[] = database + .prepare( + `select m.mapId, m.mapName, m.mapDescription, + m.mapLatitude, m.mapLongitude, m.mapSVG, + m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, + m.mapPhoneNumber, + ifnull(l.lotCount,0) as lotCount + from Maps m + left join ( + select mapId, count(lotId) as lotCount + from Lots + where recordDelete_timeMillis is null group by mapId + ) l on m.mapId = l.mapId + where m.recordDelete_timeMillis is null order by m.mapName, m.mapId` + ) + .all() - database.close(); + database.close() - return maps; + return maps } -export default getMaps; +export default getMaps diff --git a/helpers/lotOccupancyDB/getNextLotId.js b/helpers/lotOccupancyDB/getNextLotId.js index 74d7ca13..9727dc47 100644 --- a/helpers/lotOccupancyDB/getNextLotId.js +++ b/helpers/lotOccupancyDB/getNextLotId.js @@ -1,18 +1,18 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import * as configFunctions from "../functions.config.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; +import * as configFunctions from '../functions.config.js'; export function getNextLotId(lotId) { const database = sqlite(databasePath, { readonly: true }); - database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction")); + database.function('userFn_lotNameSortName', configFunctions.getProperty('settings.lot.lotNameSortNameFunction')); const result = database .prepare(`select lotId - from Lots - where recordDelete_timeMillis is null - and userFn_lotNameSortName(lotName) > (select userFn_lotNameSortName(lotName) from Lots where lotId = ?) - order by userFn_lotNameSortName(lotName) - limit 1`) + from Lots + where recordDelete_timeMillis is null + and userFn_lotNameSortName(lotName) > (select userFn_lotNameSortName(lotName) from Lots where lotId = ?) + order by userFn_lotNameSortName(lotName) + limit 1`) .get(lotId); database.close(); if (result) { diff --git a/helpers/lotOccupancyDB/getNextLotId.ts b/helpers/lotOccupancyDB/getNextLotId.ts index 01ed8ce3..622343ec 100644 --- a/helpers/lotOccupancyDB/getNextLotId.ts +++ b/helpers/lotOccupancyDB/getNextLotId.ts @@ -1,39 +1,39 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import * as configFunctions from "../functions.config.js"; +import * as configFunctions from '../functions.config.js' export function getNextLotId(lotId: number | string): number | undefined { - const database = sqlite(databasePath, { - readonly: true - }); + const database = sqlite(databasePath, { + readonly: true + }) - database.function( - "userFn_lotNameSortName", - configFunctions.getProperty("settings.lot.lotNameSortNameFunction") - ); + database.function( + 'userFn_lotNameSortName', + configFunctions.getProperty('settings.lot.lotNameSortNameFunction') + ) - const result: { - lotId: number; - } = database - .prepare( - `select lotId - from Lots - where recordDelete_timeMillis is null - and userFn_lotNameSortName(lotName) > (select userFn_lotNameSortName(lotName) from Lots where lotId = ?) - order by userFn_lotNameSortName(lotName) - limit 1` - ) - .get(lotId); + const result: { + lotId: number + } = database + .prepare( + `select lotId + from Lots + where recordDelete_timeMillis is null + and userFn_lotNameSortName(lotName) > (select userFn_lotNameSortName(lotName) from Lots where lotId = ?) + order by userFn_lotNameSortName(lotName) + limit 1` + ) + .get(lotId) - database.close(); + database.close() - if (result) { - return result.lotId; - } + if (result) { + return result.lotId + } - return undefined; + return undefined } -export default getNextLotId; +export default getNextLotId diff --git a/helpers/lotOccupancyDB/getNextWorkOrderNumber.d.ts b/helpers/lotOccupancyDB/getNextWorkOrderNumber.d.ts index 6934f4c5..6d56294f 100644 --- a/helpers/lotOccupancyDB/getNextWorkOrderNumber.d.ts +++ b/helpers/lotOccupancyDB/getNextWorkOrderNumber.d.ts @@ -1,3 +1,3 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3'; export declare function getNextWorkOrderNumber(connectedDatabase?: sqlite.Database): string; export default getNextWorkOrderNumber; diff --git a/helpers/lotOccupancyDB/getNextWorkOrderNumber.js b/helpers/lotOccupancyDB/getNextWorkOrderNumber.js index a2eb38de..a3e3c102 100644 --- a/helpers/lotOccupancyDB/getNextWorkOrderNumber.js +++ b/helpers/lotOccupancyDB/getNextWorkOrderNumber.js @@ -1,20 +1,20 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import * as configFunctions from "../functions.config.js"; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'; +import * as configFunctions from '../functions.config.js'; export function getNextWorkOrderNumber(connectedDatabase) { - const database = connectedDatabase || + const database = connectedDatabase ?? sqlite(databasePath, { readonly: true }); - const paddingLength = configFunctions.getProperty("settings.workOrders.workOrderNumberLength"); + const paddingLength = configFunctions.getProperty('settings.workOrders.workOrderNumberLength'); const currentYearString = new Date().getFullYear().toString(); - const regex = new RegExp("^" + currentYearString + "-\\d+$"); - database.function("userFn_matchesWorkOrderNumberSyntax", (workOrderNumber) => { + const regex = new RegExp('^' + currentYearString + '-\\d+$'); + database.function('userFn_matchesWorkOrderNumberSyntax', (workOrderNumber) => { return regex.test(workOrderNumber) ? 1 : 0; }); const workOrderNumberRecord = database - .prepare("select workOrderNumber from WorkOrders" + - " where userFn_matchesWorkOrderNumberSyntax(workOrderNumber) = 1" + + .prepare('select workOrderNumber from WorkOrders' + + ' where userFn_matchesWorkOrderNumberSyntax(workOrderNumber) = 1' + " order by cast(substr(workOrderNumber, instr(workOrderNumber, '-') + 1) as integer) desc") .get(); if (!connectedDatabase) { @@ -22,9 +22,11 @@ export function getNextWorkOrderNumber(connectedDatabase) { } let workOrderNumberIndex = 0; if (workOrderNumberRecord) { - workOrderNumberIndex = Number.parseInt(workOrderNumberRecord.workOrderNumber.split("-")[1], 10); + workOrderNumberIndex = Number.parseInt(workOrderNumberRecord.workOrderNumber.split('-')[1], 10); } workOrderNumberIndex += 1; - return currentYearString + "-" + workOrderNumberIndex.toString().padStart(paddingLength, "0"); + return (currentYearString + + '-' + + workOrderNumberIndex.toString().padStart(paddingLength, '0')); } export default getNextWorkOrderNumber; diff --git a/helpers/lotOccupancyDB/getNextWorkOrderNumber.ts b/helpers/lotOccupancyDB/getNextWorkOrderNumber.ts index 7d36f52f..47d2f2dc 100644 --- a/helpers/lotOccupancyDB/getNextWorkOrderNumber.ts +++ b/helpers/lotOccupancyDB/getNextWorkOrderNumber.ts @@ -1,49 +1,60 @@ -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js' -import * as configFunctions from "../functions.config.js"; +import * as configFunctions from '../functions.config.js' -export function getNextWorkOrderNumber(connectedDatabase?: sqlite.Database): string { - const database = - connectedDatabase || - sqlite(databasePath, { - readonly: true - }); +export function getNextWorkOrderNumber( + connectedDatabase?: sqlite.Database +): string { + const database = + connectedDatabase ?? + sqlite(databasePath, { + readonly: true + }) - const paddingLength = configFunctions.getProperty("settings.workOrders.workOrderNumberLength"); - const currentYearString = new Date().getFullYear().toString(); + const paddingLength = configFunctions.getProperty( + 'settings.workOrders.workOrderNumberLength' + ) + const currentYearString = new Date().getFullYear().toString() - const regex = new RegExp("^" + currentYearString + "-\\d+$"); + const regex = new RegExp('^' + currentYearString + '-\\d+$') - database.function("userFn_matchesWorkOrderNumberSyntax", (workOrderNumber: string) => { - return regex.test(workOrderNumber) ? 1 : 0; - }); - - const workOrderNumberRecord = database - .prepare( - "select workOrderNumber from WorkOrders" + - " where userFn_matchesWorkOrderNumberSyntax(workOrderNumber) = 1" + - " order by cast(substr(workOrderNumber, instr(workOrderNumber, '-') + 1) as integer) desc" - ) - .get(); - - if (!connectedDatabase) { - database.close(); + database.function( + 'userFn_matchesWorkOrderNumberSyntax', + (workOrderNumber: string) => { + return regex.test(workOrderNumber) ? 1 : 0 } + ) - let workOrderNumberIndex = 0; + const workOrderNumberRecord = database + .prepare( + 'select workOrderNumber from WorkOrders' + + ' where userFn_matchesWorkOrderNumberSyntax(workOrderNumber) = 1' + + " order by cast(substr(workOrderNumber, instr(workOrderNumber, '-') + 1) as integer) desc" + ) + .get() - if (workOrderNumberRecord) { - workOrderNumberIndex = Number.parseInt( - workOrderNumberRecord.workOrderNumber.split("-")[1], - 10 - ); - } + if (!connectedDatabase) { + database.close() + } - workOrderNumberIndex += 1; + let workOrderNumberIndex = 0 - return currentYearString + "-" + workOrderNumberIndex.toString().padStart(paddingLength, "0"); + if (workOrderNumberRecord) { + workOrderNumberIndex = Number.parseInt( + workOrderNumberRecord.workOrderNumber.split('-')[1], + 10 + ) + } + + workOrderNumberIndex += 1 + + return ( + currentYearString + + '-' + + workOrderNumberIndex.toString().padStart(paddingLength, '0') + ) } -export default getNextWorkOrderNumber; +export default getNextWorkOrderNumber diff --git a/public-scss/style.scss b/public-scss/style.scss index 0313b1d5..8157f2c4 100644 --- a/public-scss/style.scss +++ b/public-scss/style.scss @@ -215,5 +215,4 @@ span.button.is-static { box-shadow: 0 -2px 0 0 #f5f5f5; } } - } diff --git a/temp/legacy.importFromCSV.js b/temp/legacy.importFromCSV.js index 531988c2..6da37de6 100644 --- a/temp/legacy.importFromCSV.js +++ b/temp/legacy.importFromCSV.js @@ -1,97 +1,101 @@ -import fs from "node:fs"; -import papa from "papaparse"; -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../data/databasePaths.js"; -import * as cacheFunctions from "../helpers/functions.cache.js"; -import { addMap } from "../helpers/lotOccupancyDB/addMap.js"; -import { getMap as getMapFromDatabase } from "../helpers/lotOccupancyDB/getMap.js"; -import { addLot } from "../helpers/lotOccupancyDB/addLot.js"; -import { updateLotStatus } from "../helpers/lotOccupancyDB/updateLot.js"; -import { addLotOccupancy } from "../helpers/lotOccupancyDB/addLotOccupancy.js"; -import { addLotOccupancyOccupant } from "../helpers/lotOccupancyDB/addLotOccupancyOccupant.js"; -import { addLotOccupancyComment } from "../helpers/lotOccupancyDB/addLotOccupancyComment.js"; -import { addOrUpdateLotOccupancyField } from "../helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.js"; -import { getLot, getLotByLotName } from "../helpers/lotOccupancyDB/getLot.js"; -import { getLotOccupancies } from "../helpers/lotOccupancyDB/getLotOccupancies.js"; -import { addLotOccupancyFee } from "../helpers/lotOccupancyDB/addLotOccupancyFee.js"; -import { addLotOccupancyTransaction } from "../helpers/lotOccupancyDB/addLotOccupancyTransaction.js"; -import { addWorkOrder } from "../helpers/lotOccupancyDB/addWorkOrder.js"; -import { addWorkOrderLot } from "../helpers/lotOccupancyDB/addWorkOrderLot.js"; -import { addWorkOrderLotOccupancy } from "../helpers/lotOccupancyDB/addWorkOrderLotOccupancy.js"; -import { getWorkOrder, getWorkOrderByWorkOrderNumber } from "../helpers/lotOccupancyDB/getWorkOrder.js"; -import { reopenWorkOrder } from "../helpers/lotOccupancyDB/reopenWorkOrder.js"; -import { addWorkOrderMilestone } from "../helpers/lotOccupancyDB/addWorkOrderMilestone.js"; -import { closeWorkOrder } from "../helpers/lotOccupancyDB/closeWorkOrder.js"; -import { dateIntegerToString, dateToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import fs from 'node:fs'; +import papa from 'papaparse'; +import sqlite from 'better-sqlite3'; +import { lotOccupancyDB as databasePath } from '../data/databasePaths.js'; +import * as cacheFunctions from '../helpers/functions.cache.js'; +import { addMap } from '../helpers/lotOccupancyDB/addMap.js'; +import { getMap as getMapFromDatabase } from '../helpers/lotOccupancyDB/getMap.js'; +import { addLot } from '../helpers/lotOccupancyDB/addLot.js'; +import { updateLotStatus } from '../helpers/lotOccupancyDB/updateLot.js'; +import { addLotOccupancy } from '../helpers/lotOccupancyDB/addLotOccupancy.js'; +import { addLotOccupancyOccupant } from '../helpers/lotOccupancyDB/addLotOccupancyOccupant.js'; +import { addLotOccupancyComment } from '../helpers/lotOccupancyDB/addLotOccupancyComment.js'; +import { addOrUpdateLotOccupancyField } from '../helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.js'; +import { getLot, getLotByLotName } from '../helpers/lotOccupancyDB/getLot.js'; +import { getLotOccupancies } from '../helpers/lotOccupancyDB/getLotOccupancies.js'; +import { addLotOccupancyFee } from '../helpers/lotOccupancyDB/addLotOccupancyFee.js'; +import { addLotOccupancyTransaction } from '../helpers/lotOccupancyDB/addLotOccupancyTransaction.js'; +import { addWorkOrder } from '../helpers/lotOccupancyDB/addWorkOrder.js'; +import { addWorkOrderLot } from '../helpers/lotOccupancyDB/addWorkOrderLot.js'; +import { addWorkOrderLotOccupancy } from '../helpers/lotOccupancyDB/addWorkOrderLotOccupancy.js'; +import { getWorkOrder, getWorkOrderByWorkOrderNumber } from '../helpers/lotOccupancyDB/getWorkOrder.js'; +import { reopenWorkOrder } from '../helpers/lotOccupancyDB/reopenWorkOrder.js'; +import { addWorkOrderMilestone } from '../helpers/lotOccupancyDB/addWorkOrderMilestone.js'; +import { closeWorkOrder } from '../helpers/lotOccupancyDB/closeWorkOrder.js'; +import { dateIntegerToString, dateToString } from '@cityssm/expressjs-server-js/dateTimeFns.js'; const user = { user: { - userName: "import.unix", + userName: 'import.unix', userProperties: { canUpdate: true, isAdmin: false, - apiKey: "" + apiKey: '' } } }; function purgeTables() { - console.time("purgeTables"); + console.time('purgeTables'); const database = sqlite(databasePath); - database.prepare("delete from WorkOrderMilestones").run(); - database.prepare("delete from WorkOrderComments").run(); - database.prepare("delete from WorkOrderLots").run(); - database.prepare("delete from WorkOrderLotOccupancies").run(); - database.prepare("delete from WorkOrders").run(); - database.prepare("delete from LotOccupancyTransactions").run(); - database.prepare("delete from LotOccupancyFees").run(); - database.prepare("delete from LotOccupancyFields").run(); - database.prepare("delete from LotOccupancyComments").run(); - database.prepare("delete from LotOccupancyOccupants").run(); - database.prepare("delete from LotOccupancies").run(); - database.prepare("delete from LotFields").run(); - database.prepare("delete from LotComments").run(); - database.prepare("delete from Lots").run(); + database.prepare('delete from WorkOrderMilestones').run(); + database.prepare('delete from WorkOrderComments').run(); + database.prepare('delete from WorkOrderLots').run(); + database.prepare('delete from WorkOrderLotOccupancies').run(); + database.prepare('delete from WorkOrders').run(); + database.prepare('delete from LotOccupancyTransactions').run(); + database.prepare('delete from LotOccupancyFees').run(); + database.prepare('delete from LotOccupancyFields').run(); + database.prepare('delete from LotOccupancyComments').run(); + database.prepare('delete from LotOccupancyOccupants').run(); + database.prepare('delete from LotOccupancies').run(); + database.prepare('delete from LotFields').run(); + database.prepare('delete from LotComments').run(); + database.prepare('delete from Lots').run(); database .prepare("delete from sqlite_sequence where name in ('Lots', 'LotComments', 'LotOccupancies', 'LotOccupancyComments', 'WorkOrders', 'WorkOrderComments', 'WorkOrderMilestones')") .run(); database.close(); - console.timeEnd("purgeTables"); + console.timeEnd('purgeTables'); } function purgeConfigTables() { - console.time("purgeConfigTables"); + console.time('purgeConfigTables'); const database = sqlite(databasePath); - database.prepare("delete from Maps").run(); + database.prepare('delete from Maps').run(); database.prepare("delete from sqlite_sequence where name in ('Maps')").run(); database.close(); - console.timeEnd("purgeConfigTables"); + console.timeEnd('purgeConfigTables'); } function getMapByMapDescription(mapDescription) { const database = sqlite(databasePath, { readonly: true }); const map = database - .prepare("select * from Maps" + " where mapDescription = ?") + .prepare('select * from Maps' + ' where mapDescription = ?') .get(mapDescription); database.close(); return map; } function formatDateString(year, month, day) { - return (("0000" + year).slice(-4) + "-" + ("00" + month).slice(-2) + "-" + ("00" + day).slice(-2)); + return (('0000' + year).slice(-4) + + '-' + + ('00' + month).slice(-2) + + '-' + + ('00' + day).slice(-2)); } function formatTimeString(hour, minute) { - return ("00" + hour).slice(-2) + ":" + ("00" + minute).slice(-2); + return ('00' + hour).slice(-2) + ':' + ('00' + minute).slice(-2); } const cemeteryToMapName = { - "00": "Crematorium", - GC: "New Greenwood - Columbarium", - HC: "Holy Sepulchre - Columbarium", - HS: "Holy Sepulchre", - MA: "Holy Sepulchre - Mausoleum", - NG: "New Greenwood", - NW: "Niche Wall", - OG: "Old Greenwood", - PG: "Pine Grove", - UG: "New Greenwood - Urn Garden", - WK: "West Korah" + '00': 'Crematorium', + GC: 'New Greenwood - Columbarium', + HC: 'Holy Sepulchre - Columbarium', + HS: 'Holy Sepulchre', + MA: 'Holy Sepulchre - Mausoleum', + NG: 'New Greenwood', + NW: 'Niche Wall', + OG: 'Old Greenwood', + PG: 'Pine Grove', + UG: 'New Greenwood - Urn Garden', + WK: 'West Korah' }; const mapCache = new Map(); function getMap(dataRow) { @@ -101,19 +105,19 @@ function getMap(dataRow) { } let map = getMapByMapDescription(mapCacheKey); if (!map) { - console.log("Creating map: " + dataRow.cemetery); + console.log('Creating map: ' + dataRow.cemetery); const mapId = addMap({ mapName: cemeteryToMapName[dataRow.cemetery] || dataRow.cemetery, mapDescription: dataRow.cemetery, - mapSVG: "", - mapLatitude: "", - mapLongitude: "", - mapAddress1: "", - mapAddress2: "", - mapCity: "Sault Ste. Marie", - mapProvince: "ON", - mapPostalCode: "", - mapPhoneNumber: "" + mapSVG: '', + mapLatitude: '', + mapLongitude: '', + mapAddress1: '', + mapAddress2: '', + mapCity: 'Sault Ste. Marie', + mapProvince: 'ON', + mapPostalCode: '', + mapPhoneNumber: '' }, user); map = getMapFromDatabase(mapId); } @@ -138,171 +142,171 @@ function getFeeIdByFeeDescription(feeDescription) { } function buildLotName(lotNamePieces) { return (lotNamePieces.cemetery + - "-" + - (lotNamePieces.block === "" ? "" : "B" + lotNamePieces.block + "-") + - (lotNamePieces.range1 === "0" && lotNamePieces.range2 === "" - ? "" - : "R" + - (lotNamePieces.range1 === "0" ? "" : lotNamePieces.range1) + + '-' + + (lotNamePieces.block === '' ? '' : 'B' + lotNamePieces.block + '-') + + (lotNamePieces.range1 === '0' && lotNamePieces.range2 === '' + ? '' + : 'R' + + (lotNamePieces.range1 === '0' ? '' : lotNamePieces.range1) + lotNamePieces.range2 + - "-") + - (lotNamePieces.lot1 === "0" && lotNamePieces.lot2 === "" - ? "" - : "L" + lotNamePieces.lot1 + lotNamePieces.lot2 + "-") + - ("G" + lotNamePieces.grave1 + lotNamePieces.grave2) + - ", " + - ("Interment " + lotNamePieces.interment)); + '-') + + (lotNamePieces.lot1 === '0' && lotNamePieces.lot2 === '' + ? '' + : 'L' + lotNamePieces.lot1 + lotNamePieces.lot2 + '-') + + ('G' + lotNamePieces.grave1 + lotNamePieces.grave2) + + ', ' + + ('Interment ' + lotNamePieces.interment)); } -const casketLotType = cacheFunctions.getLotTypesByLotType("Casket Grave"); -const columbariumLotType = cacheFunctions.getLotTypesByLotType("Columbarium"); -const crematoriumLotType = cacheFunctions.getLotTypesByLotType("Crematorium"); -const mausoleumLotType = cacheFunctions.getLotTypesByLotType("Mausoleum"); -const nicheWallLotType = cacheFunctions.getLotTypesByLotType("Niche Wall"); -const urnGardenLotType = cacheFunctions.getLotTypesByLotType("Urn Garden"); +const casketLotType = cacheFunctions.getLotTypesByLotType('Casket Grave'); +const columbariumLotType = cacheFunctions.getLotTypesByLotType('Columbarium'); +const crematoriumLotType = cacheFunctions.getLotTypesByLotType('Crematorium'); +const mausoleumLotType = cacheFunctions.getLotTypesByLotType('Mausoleum'); +const nicheWallLotType = cacheFunctions.getLotTypesByLotType('Niche Wall'); +const urnGardenLotType = cacheFunctions.getLotTypesByLotType('Urn Garden'); function getLotType(dataRow) { switch (dataRow.cemetery) { - case "00": { + case '00': { return crematoriumLotType; } - case "GC": - case "HC": { + case 'GC': + case 'HC': { return columbariumLotType; } - case "MA": { + case 'MA': { return mausoleumLotType; } - case "MN": - case "NW": { + case 'MN': + case 'NW': { return nicheWallLotType; } - case "UG": { + case 'UG': { return urnGardenLotType; } } return casketLotType; } -const availableLotStatus = cacheFunctions.getLotStatusByLotStatus("Available"); -const reservedLotStatus = cacheFunctions.getLotStatusByLotStatus("Reserved"); -const takenLotStatus = cacheFunctions.getLotStatusByLotStatus("Taken"); -const preneedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Preneed"); -const deceasedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Interment"); -const cremationOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Cremation"); -const preneedOwnerLotOccupantType = cacheFunctions.getLotOccupantTypeByLotOccupantType("Preneed Owner"); -const funeralDirectorLotOccupantType = cacheFunctions.getLotOccupantTypeByLotOccupantType("Funeral Director"); -const deceasedLotOccupantType = cacheFunctions.getLotOccupantTypeByLotOccupantType("Deceased"); -const purchaserLotOccupantType = cacheFunctions.getLotOccupantTypeByLotOccupantType("Purchaser"); -const acknowledgedWorkOrderMilestoneType = cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType("Acknowledged"); -const deathWorkOrderMilestoneType = cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType("Death"); -const funeralWorkOrderMilestoneType = cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType("Funeral"); -const cremationWorkOrderMilestoneType = cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType("Cremation"); -const intermentWorkOrderMilestoneType = cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType("Interment"); +const availableLotStatus = cacheFunctions.getLotStatusByLotStatus('Available'); +const reservedLotStatus = cacheFunctions.getLotStatusByLotStatus('Reserved'); +const takenLotStatus = cacheFunctions.getLotStatusByLotStatus('Taken'); +const preneedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType('Preneed'); +const deceasedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType('Interment'); +const cremationOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType('Cremation'); +const preneedOwnerLotOccupantType = cacheFunctions.getLotOccupantTypeByLotOccupantType('Preneed Owner'); +const funeralDirectorLotOccupantType = cacheFunctions.getLotOccupantTypeByLotOccupantType('Funeral Director'); +const deceasedLotOccupantType = cacheFunctions.getLotOccupantTypeByLotOccupantType('Deceased'); +const purchaserLotOccupantType = cacheFunctions.getLotOccupantTypeByLotOccupantType('Purchaser'); +const acknowledgedWorkOrderMilestoneType = cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Acknowledged'); +const deathWorkOrderMilestoneType = cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Death'); +const funeralWorkOrderMilestoneType = cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Funeral'); +const cremationWorkOrderMilestoneType = cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Cremation'); +const intermentWorkOrderMilestoneType = cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Interment'); function getFuneralHome(funeralHomeKey) { switch (funeralHomeKey) { - case "AR": { + case 'AR': { return { lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Arthur Funeral Home", - occupantAddress1: "492 Wellington Street East", - occupantAddress2: "", - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON", - occupantPostalCode: "P6A 2L9", - occupantPhoneNumber: "705-759-2522", - occupantEmailAddress: "" + occupantName: 'Arthur Funeral Home', + occupantAddress1: '492 Wellington Street East', + occupantAddress2: '', + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON', + occupantPostalCode: 'P6A 2L9', + occupantPhoneNumber: '705-759-2522', + occupantEmailAddress: '' }; } - case "BG": { + case 'BG': { return { lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Beggs Funeral Home", - occupantAddress1: "175 Main Street", - occupantAddress2: "P.O. Box 280", - occupantCity: "Thessalon", - occupantProvince: "ON", - occupantPostalCode: "P0R 1L0", - occupantPhoneNumber: "705-842-2520", - occupantEmailAddress: "bfh@beggsfh.ca" + occupantName: 'Beggs Funeral Home', + occupantAddress1: '175 Main Street', + occupantAddress2: 'P.O. Box 280', + occupantCity: 'Thessalon', + occupantProvince: 'ON', + occupantPostalCode: 'P0R 1L0', + occupantPhoneNumber: '705-842-2520', + occupantEmailAddress: 'bfh@beggsfh.ca' }; } - case "BK": { + case 'BK': { return { lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Barton and Kiteley", - occupantAddress1: "", - occupantAddress2: "", - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON", - occupantPostalCode: "", - occupantPhoneNumber: "", - occupantEmailAddress: "" + occupantName: 'Barton and Kiteley', + occupantAddress1: '', + occupantAddress2: '', + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON', + occupantPostalCode: '', + occupantPhoneNumber: '', + occupantEmailAddress: '' }; } - case "DA": { + case 'DA': { return { lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Damignani Burial, Cremation and Transfer Service", - occupantAddress1: "215 St. James Street", - occupantAddress2: "", - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON", - occupantPostalCode: "P6A 1P7", - occupantPhoneNumber: "705-759-8456", - occupantEmailAddress: "" + occupantName: 'Damignani Burial, Cremation and Transfer Service', + occupantAddress1: '215 St. James Street', + occupantAddress2: '', + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON', + occupantPostalCode: 'P6A 1P7', + occupantPhoneNumber: '705-759-8456', + occupantEmailAddress: '' }; } - case "GL": { + case 'GL': { return { lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Gilmartin P.M. Funeral Home", - occupantAddress1: "140 Churchill Avenue", - occupantAddress2: "", - occupantCity: "Wawa", - occupantProvince: "ON", - occupantPostalCode: "P0S 1K0", - occupantPhoneNumber: "705-856-7340", - occupantEmailAddress: "" + occupantName: 'Gilmartin P.M. Funeral Home', + occupantAddress1: '140 Churchill Avenue', + occupantAddress2: '', + occupantCity: 'Wawa', + occupantProvince: 'ON', + occupantPostalCode: 'P0S 1K0', + occupantPhoneNumber: '705-856-7340', + occupantEmailAddress: '' }; } - case "NO": { + case 'NO': { return { lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Northwood Funeral Home", - occupantAddress1: "942 Great Northern Road", - occupantAddress2: "", - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON", - occupantPostalCode: "P6B 0B6", - occupantPhoneNumber: "705-945-7758", - occupantEmailAddress: "" + occupantName: 'Northwood Funeral Home', + occupantAddress1: '942 Great Northern Road', + occupantAddress2: '', + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON', + occupantPostalCode: 'P6B 0B6', + occupantPhoneNumber: '705-945-7758', + occupantEmailAddress: '' }; } - case "OS": { + case 'OS': { return { lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, occupantName: "O'Sullivan Funeral Home", - occupantAddress1: "215 St. James Street", - occupantAddress2: "", - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON", - occupantPostalCode: "P6A 1P7", - occupantPhoneNumber: "705-759-8456", - occupantEmailAddress: "" + occupantAddress1: '215 St. James Street', + occupantAddress2: '', + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON', + occupantPostalCode: 'P6A 1P7', + occupantPhoneNumber: '705-759-8456', + occupantEmailAddress: '' }; } } return { lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, occupantName: funeralHomeKey, - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON" + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON' }; } function importFromMasterCSV() { - console.time("importFromMasterCSV"); + console.time('importFromMasterCSV'); let masterRow; - const rawData = fs.readFileSync("./temp/CMMASTER.csv").toString(); + const rawData = fs.readFileSync('./temp/CMMASTER.csv').toString(); const cmmaster = papa.parse(rawData, { - delimiter: ",", + delimiter: ',', header: true, skipEmptyLines: true }); @@ -329,80 +333,82 @@ function importFromMasterCSV() { cemetery: masterRow.CM_CEMETERY }); let lotId; - if (masterRow.CM_CEMETERY !== "00") { + if (masterRow.CM_CEMETERY !== '00') { lotId = addLot({ lotName: lotName, lotTypeId: lotType.lotTypeId, lotStatusId: availableLotStatus.lotStatusId, mapId: map.mapId, - mapKey: lotName.includes(",") ? lotName.split(",")[0] : lotName, - lotLatitude: "", - lotLongitude: "" + mapKey: lotName.includes(',') ? lotName.split(',')[0] : lotName, + lotLatitude: '', + lotLongitude: '' }, user); } let preneedOccupancyStartDateString; let preneedLotOccupancyId; - if (masterRow.CM_PRENEED_OWNER || masterRow.CM_STATUS === "P") { + if (masterRow.CM_PRENEED_OWNER || masterRow.CM_STATUS === 'P') { preneedOccupancyStartDateString = formatDateString(masterRow.CM_PURCHASE_YR, masterRow.CM_PURCHASE_MON, masterRow.CM_PURCHASE_DAY); - let occupancyEndDateString = ""; - if (masterRow.CM_INTERMENT_YR !== "" && masterRow.CM_INTERMENT_YR !== "0") { + let occupancyEndDateString = ''; + if (masterRow.CM_INTERMENT_YR !== '' && + masterRow.CM_INTERMENT_YR !== '0') { occupancyEndDateString = formatDateString(masterRow.CM_INTERMENT_YR, masterRow.CM_INTERMENT_MON, masterRow.CM_INTERMENT_DAY); } - if (preneedOccupancyStartDateString === "0000-00-00" && - occupancyEndDateString !== "") { + if (preneedOccupancyStartDateString === '0000-00-00' && + occupancyEndDateString !== '') { preneedOccupancyStartDateString = occupancyEndDateString; } - if (preneedOccupancyStartDateString === "0000-00-00" && - masterRow.CM_DEATH_YR !== "" && - masterRow.CM_DEATH_YR !== "0") { + if (preneedOccupancyStartDateString === '0000-00-00' && + masterRow.CM_DEATH_YR !== '' && + masterRow.CM_DEATH_YR !== '0') { preneedOccupancyStartDateString = formatDateString(masterRow.CM_DEATH_YR, masterRow.CM_DEATH_MON, masterRow.CM_DEATH_DAY); - if (occupancyEndDateString === "0000-00-00" || occupancyEndDateString === "") { + if (occupancyEndDateString === '0000-00-00' || + occupancyEndDateString === '') { occupancyEndDateString = preneedOccupancyStartDateString; } } - if (preneedOccupancyStartDateString === "" || - preneedOccupancyStartDateString === "0000-00-00") { - preneedOccupancyStartDateString = "0001-01-01"; + if (preneedOccupancyStartDateString === '' || + preneedOccupancyStartDateString === '0000-00-00') { + preneedOccupancyStartDateString = '0001-01-01'; } preneedLotOccupancyId = addLotOccupancy({ occupancyTypeId: preneedOccupancyType.occupancyTypeId, lotId, occupancyStartDateString: preneedOccupancyStartDateString, occupancyEndDateString, - occupancyTypeFieldIds: "" + occupancyTypeFieldIds: '' }, user); - const occupantPostalCode = ((masterRow.CM_POST1 || "") + - " " + - (masterRow.CM_POST2 || "")).trim(); + const occupantPostalCode = ((masterRow.CM_POST1 || '') + + ' ' + + (masterRow.CM_POST2 || '')).trim(); addLotOccupancyOccupant({ lotOccupancyId: preneedLotOccupancyId, lotOccupantTypeId: preneedOwnerLotOccupantType.lotOccupantTypeId, occupantName: masterRow.CM_PRENEED_OWNER, occupantAddress1: masterRow.CM_ADDRESS, - occupantAddress2: "", + occupantAddress2: '', occupantCity: masterRow.CM_CITY, occupantProvince: masterRow.CM_PROV, occupantPostalCode, - occupantPhoneNumber: "", - occupantEmailAddress: "" + occupantPhoneNumber: '', + occupantEmailAddress: '' }, user); - if (masterRow.CM_REMARK1 !== "") { + if (masterRow.CM_REMARK1 !== '') { addLotOccupancyComment({ lotOccupancyId: preneedLotOccupancyId, lotOccupancyCommentDateString: preneedOccupancyStartDateString, - lotOccupancyCommentTimeString: "00:00", + lotOccupancyCommentTimeString: '00:00', lotOccupancyComment: masterRow.CM_REMARK1 }, user); } - if (masterRow.CM_REMARK2 !== "") { + if (masterRow.CM_REMARK2 !== '') { addLotOccupancyComment({ lotOccupancyId: preneedLotOccupancyId, lotOccupancyCommentDateString: preneedOccupancyStartDateString, - lotOccupancyCommentTimeString: "00:00", + lotOccupancyCommentTimeString: '00:00', lotOccupancyComment: masterRow.CM_REMARK2 }, user); } - if (occupancyEndDateString === "") { + if (occupancyEndDateString === '') { updateLotStatus(lotId, reservedLotStatus.lotStatusId, user); } } @@ -410,17 +416,17 @@ function importFromMasterCSV() { let deceasedLotOccupancyId; if (masterRow.CM_DECEASED_NAME) { deceasedOccupancyStartDateString = formatDateString(masterRow.CM_INTERMENT_YR, masterRow.CM_INTERMENT_MON, masterRow.CM_INTERMENT_DAY); - if (deceasedOccupancyStartDateString === "0000-00-00" && - masterRow.CM_DEATH_YR !== "" && - masterRow.CM_DEATH_YR !== "0") { + if (deceasedOccupancyStartDateString === '0000-00-00' && + masterRow.CM_DEATH_YR !== '' && + masterRow.CM_DEATH_YR !== '0') { deceasedOccupancyStartDateString = formatDateString(masterRow.CM_DEATH_YR, masterRow.CM_DEATH_MON, masterRow.CM_DEATH_DAY); } - if (deceasedOccupancyStartDateString === "" || - deceasedOccupancyStartDateString === "0000-00-00") { - deceasedOccupancyStartDateString = "0001-01-01"; + if (deceasedOccupancyStartDateString === '' || + deceasedOccupancyStartDateString === '0000-00-00') { + deceasedOccupancyStartDateString = '0001-01-01'; } const deceasedOccupancyEndDateString = lotId - ? "" + ? '' : deceasedOccupancyStartDateString; deceasedLotOccupancyId = addLotOccupancy({ occupancyTypeId: lotId @@ -429,58 +435,58 @@ function importFromMasterCSV() { lotId, occupancyStartDateString: deceasedOccupancyStartDateString, occupancyEndDateString: deceasedOccupancyEndDateString, - occupancyTypeFieldIds: "" + occupancyTypeFieldIds: '' }, user); - const deceasedPostalCode = ((masterRow.CM_POST1 || "") + - " " + - (masterRow.CM_POST2 || "")).trim(); + const deceasedPostalCode = ((masterRow.CM_POST1 || '') + + ' ' + + (masterRow.CM_POST2 || '')).trim(); addLotOccupancyOccupant({ lotOccupancyId: deceasedLotOccupancyId, lotOccupantTypeId: deceasedLotOccupantType.lotOccupantTypeId, occupantName: masterRow.CM_DECEASED_NAME, occupantAddress1: masterRow.CM_ADDRESS, - occupantAddress2: "", + occupantAddress2: '', occupantCity: masterRow.CM_CITY, occupantProvince: masterRow.CM_PROV, occupantPostalCode: deceasedPostalCode, - occupantPhoneNumber: "", - occupantEmailAddress: "" + occupantPhoneNumber: '', + occupantEmailAddress: '' }, user); - if (masterRow.CM_DEATH_YR !== "") { + if (masterRow.CM_DEATH_YR !== '') { const lotOccupancyFieldValue = formatDateString(masterRow.CM_DEATH_YR, masterRow.CM_DEATH_MON, masterRow.CM_DEATH_DAY); addOrUpdateLotOccupancyField({ lotOccupancyId: deceasedLotOccupancyId, occupancyTypeFieldId: (lotId ? deceasedOccupancyType : cremationOccupancyType).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Date"; + return occupancyTypeField.occupancyTypeField === 'Death Date'; }).occupancyTypeFieldId, lotOccupancyFieldValue }, user); } - if (masterRow.CM_AGE !== "") { + if (masterRow.CM_AGE !== '') { addOrUpdateLotOccupancyField({ lotOccupancyId: deceasedLotOccupancyId, occupancyTypeFieldId: (lotId ? deceasedOccupancyType : cremationOccupancyType).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Age"; + return occupancyTypeField.occupancyTypeField === 'Death Age'; }).occupancyTypeFieldId, lotOccupancyFieldValue: masterRow.CM_AGE }, user); } - if (masterRow.CM_PERIOD !== "") { + if (masterRow.CM_PERIOD !== '') { addOrUpdateLotOccupancyField({ lotOccupancyId: deceasedLotOccupancyId, occupancyTypeFieldId: (lotId ? deceasedOccupancyType : cremationOccupancyType).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Age Period"; + return (occupancyTypeField.occupancyTypeField === 'Death Age Period'); }).occupancyTypeFieldId, lotOccupancyFieldValue: masterRow.CM_PERIOD }, user); } - if (masterRow.CM_FUNERAL_HOME !== "") { + if (masterRow.CM_FUNERAL_HOME !== '') { const funeralHomeOccupant = getFuneralHome(masterRow.CM_FUNERAL_HOME); addLotOccupancyOccupant({ lotOccupancyId: deceasedLotOccupancyId, @@ -495,57 +501,57 @@ function importFromMasterCSV() { occupantEmailAddress: funeralHomeOccupant.occupantEmailAddress }, user); } - if (masterRow.CM_FUNERAL_YR !== "") { + if (masterRow.CM_FUNERAL_YR !== '') { const lotOccupancyFieldValue = formatDateString(masterRow.CM_FUNERAL_YR, masterRow.CM_FUNERAL_MON, masterRow.CM_FUNERAL_DAY); addOrUpdateLotOccupancyField({ lotOccupancyId: deceasedLotOccupancyId, occupancyTypeFieldId: (lotId ? deceasedOccupancyType : cremationOccupancyType).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Funeral Date"; + return occupancyTypeField.occupancyTypeField === 'Funeral Date'; }).occupancyTypeFieldId, lotOccupancyFieldValue }, user); } - if (masterRow.CM_CONTAINER_TYPE !== "") { + if (masterRow.CM_CONTAINER_TYPE !== '') { addOrUpdateLotOccupancyField({ lotOccupancyId: deceasedLotOccupancyId, occupancyTypeFieldId: (lotId ? deceasedOccupancyType : cremationOccupancyType).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Container Type"; + return (occupancyTypeField.occupancyTypeField === 'Container Type'); }).occupancyTypeFieldId, lotOccupancyFieldValue: masterRow.CM_CONTAINER_TYPE }, user); } - if (masterRow.CM_COMMITTAL_TYPE !== "") { + if (masterRow.CM_COMMITTAL_TYPE !== '') { let commitalType = masterRow.CM_COMMITTAL_TYPE; - if (commitalType === "GS") { - commitalType = "Graveside"; + if (commitalType === 'GS') { + commitalType = 'Graveside'; } addOrUpdateLotOccupancyField({ lotOccupancyId: deceasedLotOccupancyId, occupancyTypeFieldId: (lotId ? deceasedOccupancyType : cremationOccupancyType).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Committal Type"; + return (occupancyTypeField.occupancyTypeField === 'Committal Type'); }).occupancyTypeFieldId, lotOccupancyFieldValue: commitalType }, user); } - if (masterRow.CM_REMARK1 !== "") { + if (masterRow.CM_REMARK1 !== '') { addLotOccupancyComment({ lotOccupancyId: deceasedLotOccupancyId, lotOccupancyCommentDateString: deceasedOccupancyStartDateString, - lotOccupancyCommentTimeString: "00:00", + lotOccupancyCommentTimeString: '00:00', lotOccupancyComment: masterRow.CM_REMARK1 }, user); } - if (masterRow.CM_REMARK2 !== "") { + if (masterRow.CM_REMARK2 !== '') { addLotOccupancyComment({ lotOccupancyId: deceasedLotOccupancyId, lotOccupancyCommentDateString: deceasedOccupancyStartDateString, - lotOccupancyCommentTimeString: "00:00", + lotOccupancyCommentTimeString: '00:00', lotOccupancyComment: masterRow.CM_REMARK2 }, user); } @@ -555,13 +561,13 @@ function importFromMasterCSV() { lotOccupancyId: deceasedLotOccupancyId, lotOccupantTypeId: preneedOwnerLotOccupantType.lotOccupantTypeId, occupantName: masterRow.CM_PRENEED_OWNER, - occupantAddress1: "", - occupantAddress2: "", - occupantCity: "", - occupantProvince: "", - occupantPostalCode: "", - occupantPhoneNumber: "", - occupantEmailAddress: "" + occupantAddress1: '', + occupantAddress2: '', + occupantCity: '', + occupantProvince: '', + occupantPostalCode: '', + occupantPhoneNumber: '', + occupantEmailAddress: '' }, user); } } @@ -571,14 +577,14 @@ function importFromMasterCSV() { console.error(error); console.log(masterRow); } - console.timeEnd("importFromMasterCSV"); + console.timeEnd('importFromMasterCSV'); } function importFromPrepaidCSV() { - console.time("importFromPrepaidCSV"); + console.time('importFromPrepaidCSV'); let prepaidRow; - const rawData = fs.readFileSync("./temp/CMPRPAID.csv").toString(); + const rawData = fs.readFileSync('./temp/CMPRPAID.csv').toString(); const cmprpaid = papa.parse(rawData, { - delimiter: ",", + delimiter: ',', header: true, skipEmptyLines: true }); @@ -591,8 +597,8 @@ function importFromPrepaidCSV() { continue; } let cemetery = prepaidRow.CMPP_CEMETERY; - if (cemetery && cemetery === ".m") { - cemetery = "HC"; + if (cemetery && cemetery === '.m') { + cemetery = 'HC'; } let lot; if (cemetery) { @@ -620,9 +626,9 @@ function importFromPrepaidCSV() { lotTypeId: lotType.lotTypeId, lotStatusId: reservedLotStatus.lotStatusId, mapId: map.mapId, - mapKey: lotName.includes(",") ? lotName.split(",")[0] : lotName, - lotLatitude: "", - lotLongitude: "" + mapKey: lotName.includes(',') ? lotName.split(',')[0] : lotName, + lotLatitude: '', + lotLongitude: '' }, user); lot = getLot(lotId); } @@ -644,15 +650,16 @@ function importFromPrepaidCSV() { offset: 0 }); if (possibleLotOccupancies.lotOccupancies.length > 0) { - lotOccupancyId = possibleLotOccupancies.lotOccupancies[0].lotOccupancyId; + lotOccupancyId = + possibleLotOccupancies.lotOccupancies[0].lotOccupancyId; } } if (!lotOccupancyId) { lotOccupancyId = addLotOccupancy({ - lotId: lot ? lot.lotId : "", + lotId: lot ? lot.lotId : '', occupancyTypeId: preneedOccupancyType.occupancyTypeId, occupancyStartDateString, - occupancyEndDateString: "" + occupancyEndDateString: '' }, user); } addLotOccupancyOccupant({ @@ -660,95 +667,95 @@ function importFromPrepaidCSV() { lotOccupantTypeId: preneedOwnerLotOccupantType.lotOccupantTypeId, occupantName: prepaidRow.CMPP_PREPAID_FOR_NAME, occupantAddress1: prepaidRow.CMPP_ADDRESS, - occupantAddress2: "", + occupantAddress2: '', occupantCity: prepaidRow.CMPP_CITY, occupantProvince: prepaidRow.CMPP_PROV.slice(0, 2), - occupantPostalCode: prepaidRow.CMPP_POSTAL1 + " " + prepaidRow.CMPP_POSTAL2, - occupantPhoneNumber: "", - occupantEmailAddress: "" + occupantPostalCode: prepaidRow.CMPP_POSTAL1 + ' ' + prepaidRow.CMPP_POSTAL2, + occupantPhoneNumber: '', + occupantEmailAddress: '' }, user); if (prepaidRow.CMPP_ARRANGED_BY_NAME) { addLotOccupancyOccupant({ lotOccupancyId, lotOccupantTypeId: purchaserLotOccupantType.lotOccupantTypeId, occupantName: prepaidRow.CMPP_ARRANGED_BY_NAME, - occupantAddress1: "", - occupantAddress2: "", - occupantCity: "", - occupantProvince: "", - occupantPostalCode: "", - occupantPhoneNumber: "", - occupantEmailAddress: "" + occupantAddress1: '', + occupantAddress2: '', + occupantCity: '', + occupantProvince: '', + occupantPostalCode: '', + occupantPhoneNumber: '', + occupantEmailAddress: '' }, user); } - if (prepaidRow.CMPP_FEE_GRAV_SD !== "0.0") { + if (prepaidRow.CMPP_FEE_GRAV_SD !== '0.0') { addLotOccupancyFee({ lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_GRAV_SD"), + feeId: getFeeIdByFeeDescription('CMPP_FEE_GRAV_SD'), quantity: 1, feeAmount: prepaidRow.CMPP_FEE_GRAV_SD, taxAmount: prepaidRow.CMPP_GST_GRAV_SD }, user); } - if (prepaidRow.CMPP_FEE_GRAV_DD !== "0.0") { + if (prepaidRow.CMPP_FEE_GRAV_DD !== '0.0') { addLotOccupancyFee({ lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_GRAV_DD"), + feeId: getFeeIdByFeeDescription('CMPP_FEE_GRAV_DD'), quantity: 1, feeAmount: prepaidRow.CMPP_FEE_GRAV_DD, taxAmount: prepaidRow.CMPP_GST_GRAV_DD }, user); } - if (prepaidRow.CMPP_FEE_CHAP_SD !== "0.0") { + if (prepaidRow.CMPP_FEE_CHAP_SD !== '0.0') { addLotOccupancyFee({ lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_CHAP_SD"), + feeId: getFeeIdByFeeDescription('CMPP_FEE_CHAP_SD'), quantity: 1, feeAmount: prepaidRow.CMPP_FEE_CHAP_SD, taxAmount: prepaidRow.CMPP_GST_CHAP_SD }, user); } - if (prepaidRow.CMPP_FEE_CHAP_DD !== "0.0") { + if (prepaidRow.CMPP_FEE_CHAP_DD !== '0.0') { addLotOccupancyFee({ lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_CHAP_DD"), + feeId: getFeeIdByFeeDescription('CMPP_FEE_CHAP_DD'), quantity: 1, feeAmount: prepaidRow.CMPP_FEE_CHAP_DD, taxAmount: prepaidRow.CMPP_GST_CHAP_DD }, user); } - if (prepaidRow.CMPP_FEE_ENTOMBMENT !== "0.0") { + if (prepaidRow.CMPP_FEE_ENTOMBMENT !== '0.0') { addLotOccupancyFee({ lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_ENTOMBMENT"), + feeId: getFeeIdByFeeDescription('CMPP_FEE_ENTOMBMENT'), quantity: 1, feeAmount: prepaidRow.CMPP_FEE_ENTOMBMENT, taxAmount: prepaidRow.CMPP_GST_ENTOMBMENT }, user); } - if (prepaidRow.CMPP_FEE_CREM !== "0.0") { + if (prepaidRow.CMPP_FEE_CREM !== '0.0') { addLotOccupancyFee({ lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_CREM"), + feeId: getFeeIdByFeeDescription('CMPP_FEE_CREM'), quantity: 1, feeAmount: prepaidRow.CMPP_FEE_CREM, taxAmount: prepaidRow.CMPP_GST_CREM }, user); } - if (prepaidRow.CMPP_FEE_NICHE !== "0.0") { + if (prepaidRow.CMPP_FEE_NICHE !== '0.0') { addLotOccupancyFee({ lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_NICHE"), + feeId: getFeeIdByFeeDescription('CMPP_FEE_NICHE'), quantity: 1, feeAmount: prepaidRow.CMPP_FEE_NICHE, taxAmount: prepaidRow.CMPP_GST_NICHE }, user); } - if (prepaidRow.CMPP_FEE_DISINTERMENT !== "0.0" && - prepaidRow.CMPP_FEE_DISINTERMENT !== "20202.02") { + if (prepaidRow.CMPP_FEE_DISINTERMENT !== '0.0' && + prepaidRow.CMPP_FEE_DISINTERMENT !== '20202.02') { addLotOccupancyFee({ lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_DISINTERMENT"), + feeId: getFeeIdByFeeDescription('CMPP_FEE_DISINTERMENT'), quantity: 1, feeAmount: prepaidRow.CMPP_FEE_DISINTERMENT, taxAmount: prepaidRow.CMPP_GST_DISINTERMENT @@ -768,18 +775,18 @@ function importFromPrepaidCSV() { Number.parseFloat(prepaidRow.CMPP_GST_CREM) + Number.parseFloat(prepaidRow.CMPP_FEE_NICHE) + Number.parseFloat(prepaidRow.CMPP_GST_NICHE) + - Number.parseFloat(prepaidRow.CMPP_FEE_DISINTERMENT === "20202.02" - ? "0" + Number.parseFloat(prepaidRow.CMPP_FEE_DISINTERMENT === '20202.02' + ? '0' : prepaidRow.CMPP_FEE_DISINTERMENT) + - Number.parseFloat(prepaidRow.CMPP_GST_DISINTERMENT === "20202.02" - ? "0" + Number.parseFloat(prepaidRow.CMPP_GST_DISINTERMENT === '20202.02' + ? '0' : prepaidRow.CMPP_GST_DISINTERMENT); addLotOccupancyTransaction({ lotOccupancyId, - externalReceiptNumber: "", + externalReceiptNumber: '', transactionAmount, transactionDateString: occupancyStartDateString, - transactionNote: "Order Number: " + prepaidRow.CMPP_ORDER_NO + transactionNote: 'Order Number: ' + prepaidRow.CMPP_ORDER_NO }, user); if (prepaidRow.CMPP_REMARK1) { addLotOccupancyComment({ @@ -801,14 +808,14 @@ function importFromPrepaidCSV() { console.error(error); console.log(prepaidRow); } - console.timeEnd("importFromPrepaidCSV"); + console.timeEnd('importFromPrepaidCSV'); } function importFromWorkOrderCSV() { - console.time("importFromWorkOrderCSV"); + console.time('importFromWorkOrderCSV'); let workOrderRow; - const rawData = fs.readFileSync("./temp/CMWKORDR.csv").toString(); + const rawData = fs.readFileSync('./temp/CMWKORDR.csv').toString(); const cmwkordr = papa.parse(rawData, { - delimiter: ",", + delimiter: ',', header: true, skipEmptyLines: true }); @@ -818,7 +825,7 @@ function importFromWorkOrderCSV() { const currentDateString = dateToString(new Date()); try { for (workOrderRow of cmwkordr.data) { - const workOrderNumber = ("000000" + workOrderRow.WO_WORK_ORDER).slice(-6); + const workOrderNumber = ('000000' + workOrderRow.WO_WORK_ORDER).slice(-6); let workOrder = getWorkOrderByWorkOrderNumber(workOrderNumber); const workOrderOpenDateString = dateIntegerToString(Number.parseInt(workOrderRow.WO_INITIATION_DATE, 10)); if (workOrder) { @@ -833,9 +840,9 @@ function importFromWorkOrderCSV() { workOrderNumber, workOrderTypeId: 1, workOrderDescription: (workOrderRow.WO_REMARK1 + - " " + + ' ' + workOrderRow.WO_REMARK2 + - " " + + ' ' + workOrderRow.WO_REMARK3).trim(), workOrderOpenDateString }, user); @@ -846,7 +853,7 @@ function importFromWorkOrderCSV() { }); } let lot; - if (workOrderRow.WO_CEMETERY !== "00") { + if (workOrderRow.WO_CEMETERY !== '00') { const lotName = buildLotName({ cemetery: workOrderRow.WO_CEMETERY, block: workOrderRow.WO_BLOCK, @@ -867,11 +874,11 @@ function importFromWorkOrderCSV() { const lotId = addLot({ mapId: map.mapId, lotName, - mapKey: lotName.includes(",") ? lotName.split(",")[0] : lotName, + mapKey: lotName.includes(',') ? lotName.split(',')[0] : lotName, lotStatusId: takenLotStatus.lotStatusId, lotTypeId: lotType.lotTypeId, - lotLatitude: "", - lotLongitude: "" + lotLatitude: '', + lotLongitude: '' }, user); lot = getLot(lotId); } @@ -894,61 +901,61 @@ function importFromWorkOrderCSV() { occupancyStartDateString = formatDateString(workOrderRow.WO_INTERMENT_YR, workOrderRow.WO_INTERMENT_MON, workOrderRow.WO_INTERMENT_DAY); } const lotOccupancyId = addLotOccupancy({ - lotId: lot ? lot.lotId : "", + lotId: lot ? lot.lotId : '', occupancyTypeId: deceasedOccupancyType.occupancyTypeId, occupancyStartDateString, - occupancyEndDateString: "" + occupancyEndDateString: '' }, user); addLotOccupancyOccupant({ lotOccupancyId, lotOccupantTypeId: deceasedLotOccupantType.lotOccupantTypeId, occupantName: workOrderRow.WO_DECEASED_NAME, occupantAddress1: workOrderRow.WO_ADDRESS, - occupantAddress2: "", + occupantAddress2: '', occupantCity: workOrderRow.WO_CITY, occupantProvince: workOrderRow.WO_PROV.slice(0, 2), - occupantPostalCode: workOrderRow.WO_POST1 + " " + workOrderRow.WO_POST2, - occupantPhoneNumber: "", - occupantEmailAddress: "" + occupantPostalCode: workOrderRow.WO_POST1 + ' ' + workOrderRow.WO_POST2, + occupantPhoneNumber: '', + occupantEmailAddress: '' }, user); - if (workOrderRow.WO_DEATH_YR !== "") { + if (workOrderRow.WO_DEATH_YR !== '') { const lotOccupancyFieldValue = formatDateString(workOrderRow.WO_DEATH_YR, workOrderRow.WO_DEATH_MON, workOrderRow.WO_DEATH_DAY); addOrUpdateLotOccupancyField({ lotOccupancyId: lotOccupancyId, occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Date"; + return occupancyTypeField.occupancyTypeField === 'Death Date'; }).occupancyTypeFieldId, lotOccupancyFieldValue }, user); } - if (workOrderRow.WO_DEATH_PLACE !== "") { + if (workOrderRow.WO_DEATH_PLACE !== '') { addOrUpdateLotOccupancyField({ lotOccupancyId: lotOccupancyId, occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Place"; + return occupancyTypeField.occupancyTypeField === 'Death Place'; }).occupancyTypeFieldId, lotOccupancyFieldValue: workOrderRow.WO_DEATH_PLACE }, user); } - if (workOrderRow.WO_AGE !== "") { + if (workOrderRow.WO_AGE !== '') { addOrUpdateLotOccupancyField({ lotOccupancyId: lotOccupancyId, occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Age"; + return occupancyTypeField.occupancyTypeField === 'Death Age'; }).occupancyTypeFieldId, lotOccupancyFieldValue: workOrderRow.WO_AGE }, user); } - if (workOrderRow.WO_PERIOD !== "") { + if (workOrderRow.WO_PERIOD !== '') { addOrUpdateLotOccupancyField({ lotOccupancyId: lotOccupancyId, occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Age Period"; + return (occupancyTypeField.occupancyTypeField === 'Death Age Period'); }).occupancyTypeFieldId, lotOccupancyFieldValue: workOrderRow.WO_PERIOD }, user); } - if (workOrderRow.WO_FUNERAL_HOME !== "") { + if (workOrderRow.WO_FUNERAL_HOME !== '') { const funeralHomeOccupant = getFuneralHome(workOrderRow.WO_FUNERAL_HOME); addLotOccupancyOccupant({ lotOccupancyId: lotOccupancyId, @@ -963,34 +970,34 @@ function importFromWorkOrderCSV() { occupantEmailAddress: funeralHomeOccupant.occupantEmailAddress }, user); } - if (workOrderRow.WO_FUNERAL_YR !== "") { + if (workOrderRow.WO_FUNERAL_YR !== '') { const lotOccupancyFieldValue = formatDateString(workOrderRow.WO_FUNERAL_YR, workOrderRow.WO_FUNERAL_MON, workOrderRow.WO_FUNERAL_DAY); addOrUpdateLotOccupancyField({ lotOccupancyId: lotOccupancyId, occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Funeral Date"; + return (occupancyTypeField.occupancyTypeField === 'Funeral Date'); }).occupancyTypeFieldId, lotOccupancyFieldValue }, user); } - if (workOrderRow.WO_CONTAINER_TYPE !== "") { + if (workOrderRow.WO_CONTAINER_TYPE !== '') { addOrUpdateLotOccupancyField({ lotOccupancyId: lotOccupancyId, occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Container Type"; + return (occupancyTypeField.occupancyTypeField === 'Container Type'); }).occupancyTypeFieldId, lotOccupancyFieldValue: workOrderRow.WO_CONTAINER_TYPE }, user); } - if (workOrderRow.WO_COMMITTAL_TYPE !== "") { + if (workOrderRow.WO_COMMITTAL_TYPE !== '') { let commitalType = workOrderRow.WO_COMMITTAL_TYPE; - if (commitalType === "GS") { - commitalType = "Graveside"; + if (commitalType === 'GS') { + commitalType = 'Graveside'; } addOrUpdateLotOccupancyField({ lotOccupancyId: lotOccupancyId, occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Committal Type"; + return (occupancyTypeField.occupancyTypeField === 'Committal Type'); }).occupancyTypeFieldId, lotOccupancyFieldValue: commitalType }, user); @@ -1006,13 +1013,11 @@ function importFromWorkOrderCSV() { workOrderId: workOrder.workOrderId, workOrderMilestoneTypeId: acknowledgedWorkOrderMilestoneType.workOrderMilestoneTypeId, workOrderMilestoneDateString: workOrderOpenDateString, - workOrderMilestoneDescription: "", + workOrderMilestoneDescription: '', workOrderMilestoneCompletionDateString: workOrderRow.WO_CONFIRMATION_IN ? workOrderOpenDateString : undefined, - workOrderMilestoneCompletionTimeString: workOrderRow.WO_CONFIRMATION_IN - ? "00:00" - : undefined + workOrderMilestoneCompletionTimeString: workOrderRow.WO_CONFIRMATION_IN ? '00:00' : undefined }, user); } if (workOrderRow.WO_DEATH_YR) { @@ -1022,12 +1027,12 @@ function importFromWorkOrderCSV() { workOrderId: workOrder.workOrderId, workOrderMilestoneTypeId: deathWorkOrderMilestoneType.workOrderMilestoneTypeId, workOrderMilestoneDateString, - workOrderMilestoneDescription: "Death Place: " + workOrderRow.WO_DEATH_PLACE, + workOrderMilestoneDescription: 'Death Place: ' + workOrderRow.WO_DEATH_PLACE, workOrderMilestoneCompletionDateString: workOrderMilestoneDateString < currentDateString ? workOrderMilestoneDateString : undefined, workOrderMilestoneCompletionTimeString: workOrderMilestoneDateString < currentDateString - ? "00:00" + ? '00:00' : undefined }, user); } @@ -1051,7 +1056,7 @@ function importFromWorkOrderCSV() { workOrderMilestoneTypeId: funeralWorkOrderMilestoneType.workOrderMilestoneTypeId, workOrderMilestoneDateString, workOrderMilestoneTimeString, - workOrderMilestoneDescription: "Funeral Home: " + workOrderRow.WO_FUNERAL_HOME, + workOrderMilestoneDescription: 'Funeral Home: ' + workOrderRow.WO_FUNERAL_HOME, workOrderMilestoneCompletionDateString: workOrderMilestoneDateString < currentDateString ? workOrderMilestoneDateString : undefined, @@ -1067,17 +1072,18 @@ function importFromWorkOrderCSV() { hasIncompleteMilestones = true; } } - if (workOrderRow.WO_CREMATION === "Y" && cremationWorkOrderMilestoneType) { + if (workOrderRow.WO_CREMATION === 'Y' && + cremationWorkOrderMilestoneType) { addWorkOrderMilestone({ workOrderId: workOrder.workOrderId, workOrderMilestoneTypeId: cremationWorkOrderMilestoneType.workOrderMilestoneTypeId, workOrderMilestoneDateString: maxMilestoneCompletionDateString, - workOrderMilestoneDescription: "", + workOrderMilestoneDescription: '', workOrderMilestoneCompletionDateString: maxMilestoneCompletionDateString < currentDateString ? maxMilestoneCompletionDateString : undefined, workOrderMilestoneCompletionTimeString: maxMilestoneCompletionDateString < currentDateString - ? "00:00" + ? '00:00' : undefined }, user); } @@ -1088,12 +1094,12 @@ function importFromWorkOrderCSV() { workOrderId: workOrder.workOrderId, workOrderMilestoneTypeId: intermentWorkOrderMilestoneType.workOrderMilestoneTypeId, workOrderMilestoneDateString, - workOrderMilestoneDescription: "Depth: " + workOrderRow.WO_DEPTH, + workOrderMilestoneDescription: 'Depth: ' + workOrderRow.WO_DEPTH, workOrderMilestoneCompletionDateString: workOrderMilestoneDateString < currentDateString ? workOrderMilestoneDateString : undefined, workOrderMilestoneCompletionTimeString: workOrderMilestoneDateString < currentDateString - ? "23:59" + ? '23:59' : undefined }, user); } @@ -1116,11 +1122,11 @@ function importFromWorkOrderCSV() { console.error(error); console.log(workOrderRow); } - console.timeEnd("importFromWorkOrderCSV"); + console.timeEnd('importFromWorkOrderCSV'); } -console.time("importFromCsv"); +console.time('importFromCsv'); purgeTables(); importFromMasterCSV(); importFromPrepaidCSV(); importFromWorkOrderCSV(); -console.timeEnd("importFromCsv"); +console.timeEnd('importFromCsv'); diff --git a/temp/legacy.importFromCSV.ts b/temp/legacy.importFromCSV.ts index e95b5d9a..040af887 100644 --- a/temp/legacy.importFromCSV.ts +++ b/temp/legacy.importFromCSV.ts @@ -1,865 +1,889 @@ /* eslint-disable node/no-extraneous-import, node/no-unpublished-import */ -import fs from "node:fs"; -import papa from "papaparse"; +import fs from 'node:fs' +import papa from 'papaparse' -import sqlite from "better-sqlite3"; +import sqlite from 'better-sqlite3' -import { lotOccupancyDB as databasePath } from "../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from '../data/databasePaths.js' -import * as cacheFunctions from "../helpers/functions.cache.js"; +import * as cacheFunctions from '../helpers/functions.cache.js' -import { addMap } from "../helpers/lotOccupancyDB/addMap.js"; -import { getMap as getMapFromDatabase } from "../helpers/lotOccupancyDB/getMap.js"; +import { addMap } from '../helpers/lotOccupancyDB/addMap.js' +import { getMap as getMapFromDatabase } from '../helpers/lotOccupancyDB/getMap.js' -import { addLot } from "../helpers/lotOccupancyDB/addLot.js"; -import { updateLotStatus } from "../helpers/lotOccupancyDB/updateLot.js"; +import { addLot } from '../helpers/lotOccupancyDB/addLot.js' +import { updateLotStatus } from '../helpers/lotOccupancyDB/updateLot.js' -import { addLotOccupancy } from "../helpers/lotOccupancyDB/addLotOccupancy.js"; +import { addLotOccupancy } from '../helpers/lotOccupancyDB/addLotOccupancy.js' -import { addLotOccupancyOccupant } from "../helpers/lotOccupancyDB/addLotOccupancyOccupant.js"; +import { addLotOccupancyOccupant } from '../helpers/lotOccupancyDB/addLotOccupancyOccupant.js' -import { addLotOccupancyComment } from "../helpers/lotOccupancyDB/addLotOccupancyComment.js"; +import { addLotOccupancyComment } from '../helpers/lotOccupancyDB/addLotOccupancyComment.js' -import { addOrUpdateLotOccupancyField } from "../helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.js"; +import { addOrUpdateLotOccupancyField } from '../helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.js' -import { getLot, getLotByLotName } from "../helpers/lotOccupancyDB/getLot.js"; +import { getLot, getLotByLotName } from '../helpers/lotOccupancyDB/getLot.js' -import { getLotOccupancies } from "../helpers/lotOccupancyDB/getLotOccupancies.js"; +import { getLotOccupancies } from '../helpers/lotOccupancyDB/getLotOccupancies.js' -import { addLotOccupancyFee } from "../helpers/lotOccupancyDB/addLotOccupancyFee.js"; +import { addLotOccupancyFee } from '../helpers/lotOccupancyDB/addLotOccupancyFee.js' -import { addLotOccupancyTransaction } from "../helpers/lotOccupancyDB/addLotOccupancyTransaction.js"; +import { addLotOccupancyTransaction } from '../helpers/lotOccupancyDB/addLotOccupancyTransaction.js' -import { addWorkOrder } from "../helpers/lotOccupancyDB/addWorkOrder.js"; +import { addWorkOrder } from '../helpers/lotOccupancyDB/addWorkOrder.js' -import { addWorkOrderLot } from "../helpers/lotOccupancyDB/addWorkOrderLot.js"; +import { addWorkOrderLot } from '../helpers/lotOccupancyDB/addWorkOrderLot.js' -import { addWorkOrderLotOccupancy } from "../helpers/lotOccupancyDB/addWorkOrderLotOccupancy.js"; +import { addWorkOrderLotOccupancy } from '../helpers/lotOccupancyDB/addWorkOrderLotOccupancy.js' import { - getWorkOrder, - getWorkOrderByWorkOrderNumber -} from "../helpers/lotOccupancyDB/getWorkOrder.js"; + getWorkOrder, + getWorkOrderByWorkOrderNumber +} from '../helpers/lotOccupancyDB/getWorkOrder.js' -import { reopenWorkOrder } from "../helpers/lotOccupancyDB/reopenWorkOrder.js"; +import { reopenWorkOrder } from '../helpers/lotOccupancyDB/reopenWorkOrder.js' -import { addWorkOrderMilestone } from "../helpers/lotOccupancyDB/addWorkOrderMilestone.js"; +import { addWorkOrderMilestone } from '../helpers/lotOccupancyDB/addWorkOrderMilestone.js' -import { closeWorkOrder } from "../helpers/lotOccupancyDB/closeWorkOrder.js"; +import { closeWorkOrder } from '../helpers/lotOccupancyDB/closeWorkOrder.js' -import { dateIntegerToString, dateToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import { + dateIntegerToString, + dateToString +} from '@cityssm/expressjs-server-js/dateTimeFns.js' -import type * as recordTypes from "../types/recordTypes"; +import type * as recordTypes from '../types/recordTypes' interface MasterRecord { - CM_SYSREC: string; - CM_CEMETERY: string; - CM_BLOCK: string; - CM_RANGE1: string; - CM_RANGE2: string; - CM_LOT1: string; - CM_LOT2: string; - CM_GRAVE1: string; - CM_GRAVE2: string; - CM_INTERMENT: string; - CM_PRENEED_OWNER: string; - CM_PRENEED_OWNER_SEQ: string; - CM_DECEASED_NAME: string; - CM_DECEASED_NAME_SEQ: string; - CM_ADDRESS: string; - CM_CITY: string; - CM_PROV: string; - CM_POST1: string; - CM_POST2: string; - CM_PRENEED_ORDER: string; - CM_PURCHASE_YR: string; - CM_PURCHASE_MON: string; - CM_PURCHASE_DAY: string; - CM_NO_GRAVES: string; - CM_DEATH_YR: string; - CM_DEATH_MON: string; - CM_DEATH_DAY: string; - CM_WORK_ORDER: string; - CM_INTERMENT_YR: string; - CM_INTERMENT_MON: string; - CM_INTERMENT_DAY: string; - CM_AGE: string; - CM_CONTAINER_TYPE: string; - CM_COMMITTAL_TYPE: string; - CM_CREMATION: string; - CM_FUNERAL_HOME: string; - CM_FUNERAL_YR: string; - CM_FUNERAL_MON: string; - CM_FUNERAL_DAY: string; - CM_RESIDENT_TYPE: string; - CM_REMARK1: string; - CM_REMARK2: string; - CM_STATUS: string; - CM_PERIOD: string; - CM_LAST_CHG_DATE: string; - CM_DEPTH: string; + CM_SYSREC: string + CM_CEMETERY: string + CM_BLOCK: string + CM_RANGE1: string + CM_RANGE2: string + CM_LOT1: string + CM_LOT2: string + CM_GRAVE1: string + CM_GRAVE2: string + CM_INTERMENT: string + CM_PRENEED_OWNER: string + CM_PRENEED_OWNER_SEQ: string + CM_DECEASED_NAME: string + CM_DECEASED_NAME_SEQ: string + CM_ADDRESS: string + CM_CITY: string + CM_PROV: string + CM_POST1: string + CM_POST2: string + CM_PRENEED_ORDER: string + CM_PURCHASE_YR: string + CM_PURCHASE_MON: string + CM_PURCHASE_DAY: string + CM_NO_GRAVES: string + CM_DEATH_YR: string + CM_DEATH_MON: string + CM_DEATH_DAY: string + CM_WORK_ORDER: string + CM_INTERMENT_YR: string + CM_INTERMENT_MON: string + CM_INTERMENT_DAY: string + CM_AGE: string + CM_CONTAINER_TYPE: string + CM_COMMITTAL_TYPE: string + CM_CREMATION: string + CM_FUNERAL_HOME: string + CM_FUNERAL_YR: string + CM_FUNERAL_MON: string + CM_FUNERAL_DAY: string + CM_RESIDENT_TYPE: string + CM_REMARK1: string + CM_REMARK2: string + CM_STATUS: string + CM_PERIOD: string + CM_LAST_CHG_DATE: string + CM_DEPTH: string } interface PrepaidRecord { - CMPP_SYSREC: string; - CMPP_PREPAID_FOR_NAME: string; - CMPP_PREPAID_FOR_SEQ: string; - CMPP_ADDRESS: string; - CMPP_CITY: string; - CMPP_PROV: string; - CMPP_POSTAL1: string; - CMPP_POSTAL2: string; - CMPP_ARRANGED_BY_NAME: string; - CMPP_ARRANGED_BY_SEQ: string; - CMPP_CEMETERY: string; - CMPP_BLOCK: string; - CMPP_RANGE1: string; - CMPP_RANGE2: string; - CMPP_LOT1: string; - CMPP_LOT2: string; - CMPP_GRAVE1: string; - CMPP_GRAVE2: string; - CMPP_INTERMENT: string; - CMPP_ORDER_NO: string; - CMPP_PURCH_YR: string; - CMPP_PURCH_MON: string; - CMPP_PURCH_DAY: string; - CMPP_FEE_GRAV_SD: string; - CMPP_GST_GRAV_SD: string; - CMPP_FEE_GRAV_DD: string; - CMPP_GST_GRAV_DD: string; - CMPP_FEE_CHAP_SD: string; - CMPP_GST_CHAP_SD: string; - CMPP_FEE_CHAP_DD: string; - CMPP_GST_CHAP_DD: string; - CMPP_FEE_ENTOMBMENT: string; - CMPP_GST_ENTOMBMENT: string; - CMPP_FEE_CREM: string; - CMPP_GST_CREM: string; - CMPP_FEE_NICHE: string; - CMPP_GST_NICHE: string; - CMPP_FEE_DISINTERMENT: string; - CMPP_GST_DISINTERMENT: string; - CMPP_REMARK1: string; - CMPP_REMARK2: string; + CMPP_SYSREC: string + CMPP_PREPAID_FOR_NAME: string + CMPP_PREPAID_FOR_SEQ: string + CMPP_ADDRESS: string + CMPP_CITY: string + CMPP_PROV: string + CMPP_POSTAL1: string + CMPP_POSTAL2: string + CMPP_ARRANGED_BY_NAME: string + CMPP_ARRANGED_BY_SEQ: string + CMPP_CEMETERY: string + CMPP_BLOCK: string + CMPP_RANGE1: string + CMPP_RANGE2: string + CMPP_LOT1: string + CMPP_LOT2: string + CMPP_GRAVE1: string + CMPP_GRAVE2: string + CMPP_INTERMENT: string + CMPP_ORDER_NO: string + CMPP_PURCH_YR: string + CMPP_PURCH_MON: string + CMPP_PURCH_DAY: string + CMPP_FEE_GRAV_SD: string + CMPP_GST_GRAV_SD: string + CMPP_FEE_GRAV_DD: string + CMPP_GST_GRAV_DD: string + CMPP_FEE_CHAP_SD: string + CMPP_GST_CHAP_SD: string + CMPP_FEE_CHAP_DD: string + CMPP_GST_CHAP_DD: string + CMPP_FEE_ENTOMBMENT: string + CMPP_GST_ENTOMBMENT: string + CMPP_FEE_CREM: string + CMPP_GST_CREM: string + CMPP_FEE_NICHE: string + CMPP_GST_NICHE: string + CMPP_FEE_DISINTERMENT: string + CMPP_GST_DISINTERMENT: string + CMPP_REMARK1: string + CMPP_REMARK2: string } interface WorkOrderRecord { - WO_SYSREC: string; - WO_DECEASED_NAME: string; - WO_DECEASED_SEQ: string; - WO_CEMETERY: string; - WO_BLOCK: string; - WO_RANGE1: string; - WO_RANGE2: string; - WO_LOT1: string; - WO_LOT2: string; - WO_GRAVE1: string; - WO_GRAVE2: string; - WO_INTERMENT: string; - WO_ADDRESS: string; - WO_CITY: string; - WO_PROV: string; - WO_POST1: string; - WO_POST2: string; - WO_DEATH_YR: string; - WO_DEATH_MON: string; - WO_DEATH_DAY: string; - WO_AGE: string; - WO_FUNERAL_HOME: string; - WO_FUNERAL_YR: string; - WO_FUNERAL_MON: string; - WO_FUNERAL_DAY: string; - WO_FUNERAL_HR: string; - WO_FUNERAL_MIN: string; - WO_INTERMENT_YR: string; - WO_INTERMENT_MON: string; - WO_INTERMENT_DAY: string; - WO_COST: string; - WO_COMMITTAL_TYPE: string; - WO_CONTAINER_TYPE: string; - WO_CREMATION: string; - WO_CONFIRMATION_IN: string; - WO_COMPLETION_YR: string; - WO_COMPLETION_MON: string; - WO_COMPLETION_DAY: string; - WO_INITIATION_DATE: string; - WO_WORK_ORDER: string; - WO_REMARK1: string; - WO_REMARK2: string; - WO_REMARK3: string; - WO_PERIOD: string; - WO_RESIDENT_TYPE: string; - WO_DEPTH: string; - WO_DEATH_PLACE: string; + WO_SYSREC: string + WO_DECEASED_NAME: string + WO_DECEASED_SEQ: string + WO_CEMETERY: string + WO_BLOCK: string + WO_RANGE1: string + WO_RANGE2: string + WO_LOT1: string + WO_LOT2: string + WO_GRAVE1: string + WO_GRAVE2: string + WO_INTERMENT: string + WO_ADDRESS: string + WO_CITY: string + WO_PROV: string + WO_POST1: string + WO_POST2: string + WO_DEATH_YR: string + WO_DEATH_MON: string + WO_DEATH_DAY: string + WO_AGE: string + WO_FUNERAL_HOME: string + WO_FUNERAL_YR: string + WO_FUNERAL_MON: string + WO_FUNERAL_DAY: string + WO_FUNERAL_HR: string + WO_FUNERAL_MIN: string + WO_INTERMENT_YR: string + WO_INTERMENT_MON: string + WO_INTERMENT_DAY: string + WO_COST: string + WO_COMMITTAL_TYPE: string + WO_CONTAINER_TYPE: string + WO_CREMATION: string + WO_CONFIRMATION_IN: string + WO_COMPLETION_YR: string + WO_COMPLETION_MON: string + WO_COMPLETION_DAY: string + WO_INITIATION_DATE: string + WO_WORK_ORDER: string + WO_REMARK1: string + WO_REMARK2: string + WO_REMARK3: string + WO_PERIOD: string + WO_RESIDENT_TYPE: string + WO_DEPTH: string + WO_DEATH_PLACE: string } const user: recordTypes.PartialSession = { - user: { - userName: "import.unix", - userProperties: { - canUpdate: true, - isAdmin: false, - apiKey: "" - } + user: { + userName: 'import.unix', + userProperties: { + canUpdate: true, + isAdmin: false, + apiKey: '' } -}; - -function purgeTables() { - console.time("purgeTables"); - - const database = sqlite(databasePath); - database.prepare("delete from WorkOrderMilestones").run(); - database.prepare("delete from WorkOrderComments").run(); - database.prepare("delete from WorkOrderLots").run(); - database.prepare("delete from WorkOrderLotOccupancies").run(); - database.prepare("delete from WorkOrders").run(); - database.prepare("delete from LotOccupancyTransactions").run(); - database.prepare("delete from LotOccupancyFees").run(); - database.prepare("delete from LotOccupancyFields").run(); - database.prepare("delete from LotOccupancyComments").run(); - database.prepare("delete from LotOccupancyOccupants").run(); - database.prepare("delete from LotOccupancies").run(); - database.prepare("delete from LotFields").run(); - database.prepare("delete from LotComments").run(); - database.prepare("delete from Lots").run(); - database - .prepare( - "delete from sqlite_sequence where name in ('Lots', 'LotComments', 'LotOccupancies', 'LotOccupancyComments', 'WorkOrders', 'WorkOrderComments', 'WorkOrderMilestones')" - ) - .run(); - database.close(); - - console.timeEnd("purgeTables"); + } } -function purgeConfigTables() { - console.time("purgeConfigTables"); +function purgeTables(): void { + console.time('purgeTables') - const database = sqlite(databasePath); - database.prepare("delete from Maps").run(); - database.prepare("delete from sqlite_sequence where name in ('Maps')").run(); - database.close(); + const database = sqlite(databasePath) + database.prepare('delete from WorkOrderMilestones').run() + database.prepare('delete from WorkOrderComments').run() + database.prepare('delete from WorkOrderLots').run() + database.prepare('delete from WorkOrderLotOccupancies').run() + database.prepare('delete from WorkOrders').run() + database.prepare('delete from LotOccupancyTransactions').run() + database.prepare('delete from LotOccupancyFees').run() + database.prepare('delete from LotOccupancyFields').run() + database.prepare('delete from LotOccupancyComments').run() + database.prepare('delete from LotOccupancyOccupants').run() + database.prepare('delete from LotOccupancies').run() + database.prepare('delete from LotFields').run() + database.prepare('delete from LotComments').run() + database.prepare('delete from Lots').run() + database + .prepare( + "delete from sqlite_sequence where name in ('Lots', 'LotComments', 'LotOccupancies', 'LotOccupancyComments', 'WorkOrders', 'WorkOrderComments', 'WorkOrderMilestones')" + ) + .run() + database.close() - console.timeEnd("purgeConfigTables"); + console.timeEnd('purgeTables') } -function getMapByMapDescription(mapDescription: string) { - const database = sqlite(databasePath, { - readonly: true - }); +function purgeConfigTables(): void { + console.time('purgeConfigTables') - const map: recordTypes.Map = database - .prepare("select * from Maps" + " where mapDescription = ?") - .get(mapDescription); + const database = sqlite(databasePath) + database.prepare('delete from Maps').run() + database.prepare("delete from sqlite_sequence where name in ('Maps')").run() + database.close() - database.close(); - - return map; + console.timeEnd('purgeConfigTables') } -function formatDateString(year: string, month: string, day: string) { - return ( - ("0000" + year).slice(-4) + "-" + ("00" + month).slice(-2) + "-" + ("00" + day).slice(-2) - ); +function getMapByMapDescription(mapDescription: string): recordTypes.Map { + const database = sqlite(databasePath, { + readonly: true + }) + + const map: recordTypes.Map = database + .prepare('select * from Maps' + ' where mapDescription = ?') + .get(mapDescription) + + database.close() + + return map } -function formatTimeString(hour: string, minute: string) { - return ("00" + hour).slice(-2) + ":" + ("00" + minute).slice(-2); +function formatDateString(year: string, month: string, day: string): string { + return ( + ('0000' + year).slice(-4) + + '-' + + ('00' + month).slice(-2) + + '-' + + ('00' + day).slice(-2) + ) +} + +function formatTimeString(hour: string, minute: string): string { + return ('00' + hour).slice(-2) + ':' + ('00' + minute).slice(-2) } const cemeteryToMapName = { - "00": "Crematorium", - GC: "New Greenwood - Columbarium", - HC: "Holy Sepulchre - Columbarium", - HS: "Holy Sepulchre", - MA: "Holy Sepulchre - Mausoleum", - NG: "New Greenwood", - NW: "Niche Wall", - OG: "Old Greenwood", - PG: "Pine Grove", - UG: "New Greenwood - Urn Garden", - WK: "West Korah" -}; + '00': 'Crematorium', + GC: 'New Greenwood - Columbarium', + HC: 'Holy Sepulchre - Columbarium', + HS: 'Holy Sepulchre', + MA: 'Holy Sepulchre - Mausoleum', + NG: 'New Greenwood', + NW: 'Niche Wall', + OG: 'Old Greenwood', + PG: 'Pine Grove', + UG: 'New Greenwood - Urn Garden', + WK: 'West Korah' +} -const mapCache: Map = new Map(); +const mapCache: Map = new Map() function getMap(dataRow: { cemetery: string }): recordTypes.Map { - const mapCacheKey = dataRow.cemetery; + const mapCacheKey = dataRow.cemetery - /* + /* if (masterRow.CM_CEMETERY === "HS" && (masterRow.CM_BLOCK === "F" || masterRow.CM_BLOCK === "G" || masterRow.CM_BLOCK === "H" || masterRow.CM_BLOCK === "J")) { mapCacheKey += "-" + masterRow.CM_BLOCK; } */ - if (mapCache.has(mapCacheKey)) { - return mapCache.get(mapCacheKey); - } + if (mapCache.has(mapCacheKey)) { + return mapCache.get(mapCacheKey) + } - let map = getMapByMapDescription(mapCacheKey); + let map = getMapByMapDescription(mapCacheKey) - if (!map) { - console.log("Creating map: " + dataRow.cemetery); + if (!map) { + console.log('Creating map: ' + dataRow.cemetery) - const mapId = addMap( - { - mapName: cemeteryToMapName[dataRow.cemetery] || dataRow.cemetery, - mapDescription: dataRow.cemetery, - mapSVG: "", - mapLatitude: "", - mapLongitude: "", - mapAddress1: "", - mapAddress2: "", - mapCity: "Sault Ste. Marie", - mapProvince: "ON", - mapPostalCode: "", - mapPhoneNumber: "" - }, - user - ); + const mapId = addMap( + { + mapName: cemeteryToMapName[dataRow.cemetery] || dataRow.cemetery, + mapDescription: dataRow.cemetery, + mapSVG: '', + mapLatitude: '', + mapLongitude: '', + mapAddress1: '', + mapAddress2: '', + mapCity: 'Sault Ste. Marie', + mapProvince: 'ON', + mapPostalCode: '', + mapPhoneNumber: '' + }, + user + ) - map = getMapFromDatabase(mapId); - } + map = getMapFromDatabase(mapId) + } - mapCache.set(mapCacheKey, map); + mapCache.set(mapCacheKey, map) - return map; + return map } -const feeCache: Map = new Map(); +const feeCache: Map = new Map() -function getFeeIdByFeeDescription(feeDescription: string) { - if (feeCache.keys.length === 0) { - const database = sqlite(databasePath, { - readonly: true - }); +function getFeeIdByFeeDescription(feeDescription: string): number | undefined { + if (feeCache.keys.length === 0) { + const database = sqlite(databasePath, { + readonly: true + }) - const records: { - feeId: number; - feeDescription: string; - }[] = database - .prepare( - "select feeId, feeDescription from Fees where feeDescription like 'CMPP_FEE_%'" - ) - .all(); + const records: Array<{ + feeId: number + feeDescription: string + }> = database + .prepare( + "select feeId, feeDescription from Fees where feeDescription like 'CMPP_FEE_%'" + ) + .all() - for (const record of records) { - feeCache.set(record.feeDescription, record.feeId); - } - - database.close(); + for (const record of records) { + feeCache.set(record.feeDescription, record.feeId) } - return feeCache.get(feeDescription); + database.close() + } + + return feeCache.get(feeDescription) } function buildLotName(lotNamePieces: { - cemetery: string; - block: string; - range1: string; - range2: string; - lot1: string; - lot2: string; - grave1: string; - grave2: string; - interment: string; -}) { - return ( - lotNamePieces.cemetery + - "-" + - (lotNamePieces.block === "" ? "" : "B" + lotNamePieces.block + "-") + - (lotNamePieces.range1 === "0" && lotNamePieces.range2 === "" - ? "" - : "R" + - (lotNamePieces.range1 === "0" ? "" : lotNamePieces.range1) + - lotNamePieces.range2 + - "-") + - (lotNamePieces.lot1 === "0" && lotNamePieces.lot2 === "" - ? "" - : "L" + lotNamePieces.lot1 + lotNamePieces.lot2 + "-") + - ("G" + lotNamePieces.grave1 + lotNamePieces.grave2) + - ", " + - ("Interment " + lotNamePieces.interment) - ); + cemetery: string + block: string + range1: string + range2: string + lot1: string + lot2: string + grave1: string + grave2: string + interment: string +}): string { + return ( + lotNamePieces.cemetery + + '-' + + (lotNamePieces.block === '' ? '' : 'B' + lotNamePieces.block + '-') + + (lotNamePieces.range1 === '0' && lotNamePieces.range2 === '' + ? '' + : 'R' + + (lotNamePieces.range1 === '0' ? '' : lotNamePieces.range1) + + lotNamePieces.range2 + + '-') + + (lotNamePieces.lot1 === '0' && lotNamePieces.lot2 === '' + ? '' + : 'L' + lotNamePieces.lot1 + lotNamePieces.lot2 + '-') + + ('G' + lotNamePieces.grave1 + lotNamePieces.grave2) + + ', ' + + ('Interment ' + lotNamePieces.interment) + ) } -const casketLotType = cacheFunctions.getLotTypesByLotType("Casket Grave"); -const columbariumLotType = cacheFunctions.getLotTypesByLotType("Columbarium"); -const crematoriumLotType = cacheFunctions.getLotTypesByLotType("Crematorium"); -const mausoleumLotType = cacheFunctions.getLotTypesByLotType("Mausoleum"); -const nicheWallLotType = cacheFunctions.getLotTypesByLotType("Niche Wall"); -const urnGardenLotType = cacheFunctions.getLotTypesByLotType("Urn Garden"); +const casketLotType = cacheFunctions.getLotTypesByLotType('Casket Grave') +const columbariumLotType = cacheFunctions.getLotTypesByLotType('Columbarium') +const crematoriumLotType = cacheFunctions.getLotTypesByLotType('Crematorium') +const mausoleumLotType = cacheFunctions.getLotTypesByLotType('Mausoleum') +const nicheWallLotType = cacheFunctions.getLotTypesByLotType('Niche Wall') +const urnGardenLotType = cacheFunctions.getLotTypesByLotType('Urn Garden') -function getLotType(dataRow: { cemetery: string }) { - switch (dataRow.cemetery) { - case "00": { - return crematoriumLotType; - } - case "GC": - case "HC": { - return columbariumLotType; - } - case "MA": { - return mausoleumLotType; - } - case "MN": - case "NW": { - return nicheWallLotType; - } - case "UG": { - return urnGardenLotType; - } +function getLotType(dataRow: { cemetery: string }): recordTypes.LotType | undefined { + switch (dataRow.cemetery) { + case '00': { + return crematoriumLotType } + case 'GC': + case 'HC': { + return columbariumLotType + } + case 'MA': { + return mausoleumLotType + } + case 'MN': + case 'NW': { + return nicheWallLotType + } + case 'UG': { + return urnGardenLotType + } + } - return casketLotType; + return casketLotType } -const availableLotStatus = cacheFunctions.getLotStatusByLotStatus("Available"); -const reservedLotStatus = cacheFunctions.getLotStatusByLotStatus("Reserved"); -const takenLotStatus = cacheFunctions.getLotStatusByLotStatus("Taken"); +const availableLotStatus = cacheFunctions.getLotStatusByLotStatus('Available') +const reservedLotStatus = cacheFunctions.getLotStatusByLotStatus('Reserved') +const takenLotStatus = cacheFunctions.getLotStatusByLotStatus('Taken') -const preneedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Preneed"); -const deceasedOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Interment"); -const cremationOccupancyType = cacheFunctions.getOccupancyTypeByOccupancyType("Cremation"); +const preneedOccupancyType = + cacheFunctions.getOccupancyTypeByOccupancyType('Preneed') +const deceasedOccupancyType = + cacheFunctions.getOccupancyTypeByOccupancyType('Interment') +const cremationOccupancyType = + cacheFunctions.getOccupancyTypeByOccupancyType('Cremation') const preneedOwnerLotOccupantType = - cacheFunctions.getLotOccupantTypeByLotOccupantType("Preneed Owner"); + cacheFunctions.getLotOccupantTypeByLotOccupantType('Preneed Owner') const funeralDirectorLotOccupantType = - cacheFunctions.getLotOccupantTypeByLotOccupantType("Funeral Director"); -const deceasedLotOccupantType = cacheFunctions.getLotOccupantTypeByLotOccupantType("Deceased"); -const purchaserLotOccupantType = cacheFunctions.getLotOccupantTypeByLotOccupantType("Purchaser"); + cacheFunctions.getLotOccupantTypeByLotOccupantType('Funeral Director') +const deceasedLotOccupantType = + cacheFunctions.getLotOccupantTypeByLotOccupantType('Deceased') +const purchaserLotOccupantType = + cacheFunctions.getLotOccupantTypeByLotOccupantType('Purchaser') const acknowledgedWorkOrderMilestoneType = - cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType("Acknowledged"); + cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType( + 'Acknowledged' + ) const deathWorkOrderMilestoneType = - cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType("Death"); + cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Death') const funeralWorkOrderMilestoneType = - cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType("Funeral"); + cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Funeral') const cremationWorkOrderMilestoneType = - cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType("Cremation"); + cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Cremation') const intermentWorkOrderMilestoneType = - cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType("Interment"); + cacheFunctions.getWorkOrderMilestoneTypeByWorkOrderMilestoneType('Interment') -function getFuneralHome(funeralHomeKey: string): recordTypes.LotOccupancyOccupant { - switch (funeralHomeKey) { - case "AR": { - return { - lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Arthur Funeral Home", - occupantAddress1: "492 Wellington Street East", - occupantAddress2: "", - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON", - occupantPostalCode: "P6A 2L9", - occupantPhoneNumber: "705-759-2522", - occupantEmailAddress: "" - }; - } - case "BG": { - return { - lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Beggs Funeral Home", - occupantAddress1: "175 Main Street", - occupantAddress2: "P.O. Box 280", - occupantCity: "Thessalon", - occupantProvince: "ON", - occupantPostalCode: "P0R 1L0", - occupantPhoneNumber: "705-842-2520", - occupantEmailAddress: "bfh@beggsfh.ca" - }; - } - case "BK": { - return { - lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Barton and Kiteley", - occupantAddress1: "", - occupantAddress2: "", - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON", - occupantPostalCode: "", - occupantPhoneNumber: "", - occupantEmailAddress: "" - }; - } - case "DA": { - return { - lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Damignani Burial, Cremation and Transfer Service", - occupantAddress1: "215 St. James Street", - occupantAddress2: "", - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON", - occupantPostalCode: "P6A 1P7", - occupantPhoneNumber: "705-759-8456", - occupantEmailAddress: "" - }; - } - case "GL": { - return { - lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Gilmartin P.M. Funeral Home", - occupantAddress1: "140 Churchill Avenue", - occupantAddress2: "", - occupantCity: "Wawa", - occupantProvince: "ON", - occupantPostalCode: "P0S 1K0", - occupantPhoneNumber: "705-856-7340", - occupantEmailAddress: "" - }; - } - case "NO": { - return { - lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "Northwood Funeral Home", - occupantAddress1: "942 Great Northern Road", - occupantAddress2: "", - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON", - occupantPostalCode: "P6B 0B6", - occupantPhoneNumber: "705-945-7758", - occupantEmailAddress: "" - }; - } - case "OS": { - return { - lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: "O'Sullivan Funeral Home", - occupantAddress1: "215 St. James Street", - occupantAddress2: "", - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON", - occupantPostalCode: "P6A 1P7", - occupantPhoneNumber: "705-759-8456", - occupantEmailAddress: "" - }; - } - } - - return { +function getFuneralHome( + funeralHomeKey: string +): recordTypes.LotOccupancyOccupant { + switch (funeralHomeKey) { + case 'AR': { + return { lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, - occupantName: funeralHomeKey, - occupantCity: "Sault Ste. Marie", - occupantProvince: "ON" - }; + occupantName: 'Arthur Funeral Home', + occupantAddress1: '492 Wellington Street East', + occupantAddress2: '', + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON', + occupantPostalCode: 'P6A 2L9', + occupantPhoneNumber: '705-759-2522', + occupantEmailAddress: '' + } + } + case 'BG': { + return { + lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, + occupantName: 'Beggs Funeral Home', + occupantAddress1: '175 Main Street', + occupantAddress2: 'P.O. Box 280', + occupantCity: 'Thessalon', + occupantProvince: 'ON', + occupantPostalCode: 'P0R 1L0', + occupantPhoneNumber: '705-842-2520', + occupantEmailAddress: 'bfh@beggsfh.ca' + } + } + case 'BK': { + return { + lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, + occupantName: 'Barton and Kiteley', + occupantAddress1: '', + occupantAddress2: '', + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON', + occupantPostalCode: '', + occupantPhoneNumber: '', + occupantEmailAddress: '' + } + } + case 'DA': { + return { + lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, + occupantName: 'Damignani Burial, Cremation and Transfer Service', + occupantAddress1: '215 St. James Street', + occupantAddress2: '', + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON', + occupantPostalCode: 'P6A 1P7', + occupantPhoneNumber: '705-759-8456', + occupantEmailAddress: '' + } + } + case 'GL': { + return { + lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, + occupantName: 'Gilmartin P.M. Funeral Home', + occupantAddress1: '140 Churchill Avenue', + occupantAddress2: '', + occupantCity: 'Wawa', + occupantProvince: 'ON', + occupantPostalCode: 'P0S 1K0', + occupantPhoneNumber: '705-856-7340', + occupantEmailAddress: '' + } + } + case 'NO': { + return { + lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, + occupantName: 'Northwood Funeral Home', + occupantAddress1: '942 Great Northern Road', + occupantAddress2: '', + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON', + occupantPostalCode: 'P6B 0B6', + occupantPhoneNumber: '705-945-7758', + occupantEmailAddress: '' + } + } + case 'OS': { + return { + lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, + occupantName: "O'Sullivan Funeral Home", + occupantAddress1: '215 St. James Street', + occupantAddress2: '', + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON', + occupantPostalCode: 'P6A 1P7', + occupantPhoneNumber: '705-759-8456', + occupantEmailAddress: '' + } + } + } + + return { + lotOccupantTypeId: funeralDirectorLotOccupantType.lotOccupantTypeId, + occupantName: funeralHomeKey, + occupantCity: 'Sault Ste. Marie', + occupantProvince: 'ON' + } } -function importFromMasterCSV() { - console.time("importFromMasterCSV"); +function importFromMasterCSV(): void { + console.time('importFromMasterCSV') - let masterRow: MasterRecord; + let masterRow: MasterRecord - const rawData = fs.readFileSync("./temp/CMMASTER.csv").toString(); + const rawData = fs.readFileSync('./temp/CMMASTER.csv').toString() - const cmmaster: papa.ParseResult = papa.parse(rawData, { - delimiter: ",", - header: true, - skipEmptyLines: true - }); + const cmmaster: papa.ParseResult = papa.parse(rawData, { + delimiter: ',', + header: true, + skipEmptyLines: true + }) - for (const parseError of cmmaster.errors) { - console.log(parseError); - } + for (const parseError of cmmaster.errors) { + console.log(parseError) + } - try { - for (masterRow of cmmaster.data) { - const map = getMap({ - cemetery: masterRow.CM_CEMETERY - }); + try { + for (masterRow of cmmaster.data) { + const map = getMap({ + cemetery: masterRow.CM_CEMETERY + }) - const lotName = buildLotName({ - cemetery: masterRow.CM_CEMETERY, - block: masterRow.CM_BLOCK, - range1: masterRow.CM_RANGE1, - range2: masterRow.CM_RANGE2, - lot1: masterRow.CM_LOT1, - lot2: masterRow.CM_LOT2, - grave1: masterRow.CM_GRAVE1, - grave2: masterRow.CM_GRAVE2, - interment: masterRow.CM_INTERMENT - }); + const lotName = buildLotName({ + cemetery: masterRow.CM_CEMETERY, + block: masterRow.CM_BLOCK, + range1: masterRow.CM_RANGE1, + range2: masterRow.CM_RANGE2, + lot1: masterRow.CM_LOT1, + lot2: masterRow.CM_LOT2, + grave1: masterRow.CM_GRAVE1, + grave2: masterRow.CM_GRAVE2, + interment: masterRow.CM_INTERMENT + }) - const lotType = getLotType({ - cemetery: masterRow.CM_CEMETERY - }); + const lotType = getLotType({ + cemetery: masterRow.CM_CEMETERY + }) - let lotId: number; + let lotId: number - if (masterRow.CM_CEMETERY !== "00") { - lotId = addLot( - { - lotName: lotName, - lotTypeId: lotType.lotTypeId, - lotStatusId: availableLotStatus.lotStatusId, - mapId: map.mapId, - mapKey: lotName.includes(",") ? lotName.split(",")[0] : lotName, - lotLatitude: "", - lotLongitude: "" - }, - user - ); - } + if (masterRow.CM_CEMETERY !== '00') { + lotId = addLot( + { + lotName: lotName, + lotTypeId: lotType.lotTypeId, + lotStatusId: availableLotStatus.lotStatusId, + mapId: map.mapId, + mapKey: lotName.includes(',') ? lotName.split(',')[0] : lotName, + lotLatitude: '', + lotLongitude: '' + }, + user + ) + } - let preneedOccupancyStartDateString: string; - let preneedLotOccupancyId: number; + let preneedOccupancyStartDateString: string + let preneedLotOccupancyId: number - if (masterRow.CM_PRENEED_OWNER || masterRow.CM_STATUS === "P") { - preneedOccupancyStartDateString = formatDateString( - masterRow.CM_PURCHASE_YR, - masterRow.CM_PURCHASE_MON, - masterRow.CM_PURCHASE_DAY - ); + if (masterRow.CM_PRENEED_OWNER || masterRow.CM_STATUS === 'P') { + preneedOccupancyStartDateString = formatDateString( + masterRow.CM_PURCHASE_YR, + masterRow.CM_PURCHASE_MON, + masterRow.CM_PURCHASE_DAY + ) - let occupancyEndDateString = ""; + let occupancyEndDateString = '' - if (masterRow.CM_INTERMENT_YR !== "" && masterRow.CM_INTERMENT_YR !== "0") { - occupancyEndDateString = formatDateString( - masterRow.CM_INTERMENT_YR, - masterRow.CM_INTERMENT_MON, - masterRow.CM_INTERMENT_DAY - ); - } + if ( + masterRow.CM_INTERMENT_YR !== '' && + masterRow.CM_INTERMENT_YR !== '0' + ) { + occupancyEndDateString = formatDateString( + masterRow.CM_INTERMENT_YR, + masterRow.CM_INTERMENT_MON, + masterRow.CM_INTERMENT_DAY + ) + } - // if purchase date unavailable - if ( - preneedOccupancyStartDateString === "0000-00-00" && - occupancyEndDateString !== "" - ) { - preneedOccupancyStartDateString = occupancyEndDateString; - } + // if purchase date unavailable + if ( + preneedOccupancyStartDateString === '0000-00-00' && + occupancyEndDateString !== '' + ) { + preneedOccupancyStartDateString = occupancyEndDateString + } - // if end date unavailable - if ( - preneedOccupancyStartDateString === "0000-00-00" && - masterRow.CM_DEATH_YR !== "" && - masterRow.CM_DEATH_YR !== "0" - ) { - preneedOccupancyStartDateString = formatDateString( - masterRow.CM_DEATH_YR, - masterRow.CM_DEATH_MON, - masterRow.CM_DEATH_DAY - ); + // if end date unavailable + if ( + preneedOccupancyStartDateString === '0000-00-00' && + masterRow.CM_DEATH_YR !== '' && + masterRow.CM_DEATH_YR !== '0' + ) { + preneedOccupancyStartDateString = formatDateString( + masterRow.CM_DEATH_YR, + masterRow.CM_DEATH_MON, + masterRow.CM_DEATH_DAY + ) - // if death took place, and there's no preneed end date - if (occupancyEndDateString === "0000-00-00" || occupancyEndDateString === "") { - occupancyEndDateString = preneedOccupancyStartDateString; - } - } + // if death took place, and there's no preneed end date + if ( + occupancyEndDateString === '0000-00-00' || + occupancyEndDateString === '' + ) { + occupancyEndDateString = preneedOccupancyStartDateString + } + } - if ( - preneedOccupancyStartDateString === "" || - preneedOccupancyStartDateString === "0000-00-00" - ) { - preneedOccupancyStartDateString = "0001-01-01"; - } + if ( + preneedOccupancyStartDateString === '' || + preneedOccupancyStartDateString === '0000-00-00' + ) { + preneedOccupancyStartDateString = '0001-01-01' + } - preneedLotOccupancyId = addLotOccupancy( - { - occupancyTypeId: preneedOccupancyType.occupancyTypeId, - lotId, - occupancyStartDateString: preneedOccupancyStartDateString, - occupancyEndDateString, - occupancyTypeFieldIds: "" - }, - user - ); + preneedLotOccupancyId = addLotOccupancy( + { + occupancyTypeId: preneedOccupancyType.occupancyTypeId, + lotId, + occupancyStartDateString: preneedOccupancyStartDateString, + occupancyEndDateString, + occupancyTypeFieldIds: '' + }, + user + ) - const occupantPostalCode = ( - (masterRow.CM_POST1 || "") + - " " + - (masterRow.CM_POST2 || "") - ).trim(); + const occupantPostalCode = ( + (masterRow.CM_POST1 || '') + + ' ' + + (masterRow.CM_POST2 || '') + ).trim() - addLotOccupancyOccupant( - { - lotOccupancyId: preneedLotOccupancyId, - lotOccupantTypeId: preneedOwnerLotOccupantType.lotOccupantTypeId, - occupantName: masterRow.CM_PRENEED_OWNER, - occupantAddress1: masterRow.CM_ADDRESS, - occupantAddress2: "", - occupantCity: masterRow.CM_CITY, - occupantProvince: masterRow.CM_PROV, - occupantPostalCode, - occupantPhoneNumber: "", - occupantEmailAddress: "" - }, - user - ); + addLotOccupancyOccupant( + { + lotOccupancyId: preneedLotOccupancyId, + lotOccupantTypeId: preneedOwnerLotOccupantType.lotOccupantTypeId, + occupantName: masterRow.CM_PRENEED_OWNER, + occupantAddress1: masterRow.CM_ADDRESS, + occupantAddress2: '', + occupantCity: masterRow.CM_CITY, + occupantProvince: masterRow.CM_PROV, + occupantPostalCode, + occupantPhoneNumber: '', + occupantEmailAddress: '' + }, + user + ) - if (masterRow.CM_REMARK1 !== "") { - addLotOccupancyComment( - { - lotOccupancyId: preneedLotOccupancyId, - lotOccupancyCommentDateString: preneedOccupancyStartDateString, - lotOccupancyCommentTimeString: "00:00", - lotOccupancyComment: masterRow.CM_REMARK1 - }, - user - ); - } + if (masterRow.CM_REMARK1 !== '') { + addLotOccupancyComment( + { + lotOccupancyId: preneedLotOccupancyId, + lotOccupancyCommentDateString: preneedOccupancyStartDateString, + lotOccupancyCommentTimeString: '00:00', + lotOccupancyComment: masterRow.CM_REMARK1 + }, + user + ) + } - if (masterRow.CM_REMARK2 !== "") { - addLotOccupancyComment( - { - lotOccupancyId: preneedLotOccupancyId, - lotOccupancyCommentDateString: preneedOccupancyStartDateString, - lotOccupancyCommentTimeString: "00:00", - lotOccupancyComment: masterRow.CM_REMARK2 - }, - user - ); - } + if (masterRow.CM_REMARK2 !== '') { + addLotOccupancyComment( + { + lotOccupancyId: preneedLotOccupancyId, + lotOccupancyCommentDateString: preneedOccupancyStartDateString, + lotOccupancyCommentTimeString: '00:00', + lotOccupancyComment: masterRow.CM_REMARK2 + }, + user + ) + } - if (occupancyEndDateString === "") { - updateLotStatus(lotId, reservedLotStatus.lotStatusId, user); - } - } + if (occupancyEndDateString === '') { + updateLotStatus(lotId, reservedLotStatus.lotStatusId, user) + } + } - let deceasedOccupancyStartDateString: string; - let deceasedLotOccupancyId: number; + let deceasedOccupancyStartDateString: string + let deceasedLotOccupancyId: number - if (masterRow.CM_DECEASED_NAME) { - deceasedOccupancyStartDateString = formatDateString( - masterRow.CM_INTERMENT_YR, - masterRow.CM_INTERMENT_MON, - masterRow.CM_INTERMENT_DAY - ); + if (masterRow.CM_DECEASED_NAME) { + deceasedOccupancyStartDateString = formatDateString( + masterRow.CM_INTERMENT_YR, + masterRow.CM_INTERMENT_MON, + masterRow.CM_INTERMENT_DAY + ) - // if interment date unavailable - if ( - deceasedOccupancyStartDateString === "0000-00-00" && - masterRow.CM_DEATH_YR !== "" && - masterRow.CM_DEATH_YR !== "0" - ) { - deceasedOccupancyStartDateString = formatDateString( - masterRow.CM_DEATH_YR, - masterRow.CM_DEATH_MON, - masterRow.CM_DEATH_DAY - ); - } + // if interment date unavailable + if ( + deceasedOccupancyStartDateString === '0000-00-00' && + masterRow.CM_DEATH_YR !== '' && + masterRow.CM_DEATH_YR !== '0' + ) { + deceasedOccupancyStartDateString = formatDateString( + masterRow.CM_DEATH_YR, + masterRow.CM_DEATH_MON, + masterRow.CM_DEATH_DAY + ) + } - if ( - deceasedOccupancyStartDateString === "" || - deceasedOccupancyStartDateString === "0000-00-00" - ) { - deceasedOccupancyStartDateString = "0001-01-01"; - } + if ( + deceasedOccupancyStartDateString === '' || + deceasedOccupancyStartDateString === '0000-00-00' + ) { + deceasedOccupancyStartDateString = '0001-01-01' + } - const deceasedOccupancyEndDateString = lotId - ? "" - : deceasedOccupancyStartDateString; + const deceasedOccupancyEndDateString = lotId + ? '' + : deceasedOccupancyStartDateString - deceasedLotOccupancyId = addLotOccupancy( - { - occupancyTypeId: lotId - ? deceasedOccupancyType.occupancyTypeId - : cremationOccupancyType.occupancyTypeId, - lotId, - occupancyStartDateString: deceasedOccupancyStartDateString, - occupancyEndDateString: deceasedOccupancyEndDateString, - occupancyTypeFieldIds: "" - }, - user - ); + deceasedLotOccupancyId = addLotOccupancy( + { + occupancyTypeId: lotId + ? deceasedOccupancyType.occupancyTypeId + : cremationOccupancyType.occupancyTypeId, + lotId, + occupancyStartDateString: deceasedOccupancyStartDateString, + occupancyEndDateString: deceasedOccupancyEndDateString, + occupancyTypeFieldIds: '' + }, + user + ) - const deceasedPostalCode = ( - (masterRow.CM_POST1 || "") + - " " + - (masterRow.CM_POST2 || "") - ).trim(); + const deceasedPostalCode = ( + (masterRow.CM_POST1 || '') + + ' ' + + (masterRow.CM_POST2 || '') + ).trim() - addLotOccupancyOccupant( - { - lotOccupancyId: deceasedLotOccupancyId, - lotOccupantTypeId: deceasedLotOccupantType.lotOccupantTypeId, - occupantName: masterRow.CM_DECEASED_NAME, - occupantAddress1: masterRow.CM_ADDRESS, - occupantAddress2: "", - occupantCity: masterRow.CM_CITY, - occupantProvince: masterRow.CM_PROV, - occupantPostalCode: deceasedPostalCode, - occupantPhoneNumber: "", - occupantEmailAddress: "" - }, - user - ); + addLotOccupancyOccupant( + { + lotOccupancyId: deceasedLotOccupancyId, + lotOccupantTypeId: deceasedLotOccupantType.lotOccupantTypeId, + occupantName: masterRow.CM_DECEASED_NAME, + occupantAddress1: masterRow.CM_ADDRESS, + occupantAddress2: '', + occupantCity: masterRow.CM_CITY, + occupantProvince: masterRow.CM_PROV, + occupantPostalCode: deceasedPostalCode, + occupantPhoneNumber: '', + occupantEmailAddress: '' + }, + user + ) - if (masterRow.CM_DEATH_YR !== "") { - const lotOccupancyFieldValue = formatDateString( - masterRow.CM_DEATH_YR, - masterRow.CM_DEATH_MON, - masterRow.CM_DEATH_DAY - ); + if (masterRow.CM_DEATH_YR !== '') { + const lotOccupancyFieldValue = formatDateString( + masterRow.CM_DEATH_YR, + masterRow.CM_DEATH_MON, + masterRow.CM_DEATH_DAY + ) - addOrUpdateLotOccupancyField( - { - lotOccupancyId: deceasedLotOccupancyId, - occupancyTypeFieldId: (lotId - ? deceasedOccupancyType - : cremationOccupancyType - ).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Date"; - }).occupancyTypeFieldId, - lotOccupancyFieldValue - }, - user - ); - } + addOrUpdateLotOccupancyField( + { + lotOccupancyId: deceasedLotOccupancyId, + occupancyTypeFieldId: (lotId + ? deceasedOccupancyType + : cremationOccupancyType + ).occupancyTypeFields.find((occupancyTypeField) => { + return occupancyTypeField.occupancyTypeField === 'Death Date' + }).occupancyTypeFieldId, + lotOccupancyFieldValue + }, + user + ) + } - if (masterRow.CM_AGE !== "") { - addOrUpdateLotOccupancyField( - { - lotOccupancyId: deceasedLotOccupancyId, - occupancyTypeFieldId: (lotId - ? deceasedOccupancyType - : cremationOccupancyType - ).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Age"; - }).occupancyTypeFieldId, - lotOccupancyFieldValue: masterRow.CM_AGE - }, - user - ); - } + if (masterRow.CM_AGE !== '') { + addOrUpdateLotOccupancyField( + { + lotOccupancyId: deceasedLotOccupancyId, + occupancyTypeFieldId: (lotId + ? deceasedOccupancyType + : cremationOccupancyType + ).occupancyTypeFields.find((occupancyTypeField) => { + return occupancyTypeField.occupancyTypeField === 'Death Age' + }).occupancyTypeFieldId, + lotOccupancyFieldValue: masterRow.CM_AGE + }, + user + ) + } - if (masterRow.CM_PERIOD !== "") { - addOrUpdateLotOccupancyField( - { - lotOccupancyId: deceasedLotOccupancyId, - occupancyTypeFieldId: (lotId - ? deceasedOccupancyType - : cremationOccupancyType - ).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Age Period"; - }).occupancyTypeFieldId, - lotOccupancyFieldValue: masterRow.CM_PERIOD - }, - user - ); - } + if (masterRow.CM_PERIOD !== '') { + addOrUpdateLotOccupancyField( + { + lotOccupancyId: deceasedLotOccupancyId, + occupancyTypeFieldId: (lotId + ? deceasedOccupancyType + : cremationOccupancyType + ).occupancyTypeFields.find((occupancyTypeField) => { + return ( + occupancyTypeField.occupancyTypeField === 'Death Age Period' + ) + }).occupancyTypeFieldId, + lotOccupancyFieldValue: masterRow.CM_PERIOD + }, + user + ) + } - if (masterRow.CM_FUNERAL_HOME !== "") { - const funeralHomeOccupant = getFuneralHome(masterRow.CM_FUNERAL_HOME); + if (masterRow.CM_FUNERAL_HOME !== '') { + const funeralHomeOccupant = getFuneralHome(masterRow.CM_FUNERAL_HOME) - addLotOccupancyOccupant( - { - lotOccupancyId: deceasedLotOccupancyId, - lotOccupantTypeId: funeralHomeOccupant.lotOccupantTypeId, - occupantName: funeralHomeOccupant.occupantName, - occupantAddress1: funeralHomeOccupant.occupantAddress1, - occupantAddress2: funeralHomeOccupant.occupantAddress2, - occupantCity: funeralHomeOccupant.occupantCity, - occupantProvince: funeralHomeOccupant.occupantProvince, - occupantPostalCode: funeralHomeOccupant.occupantPostalCode, - occupantPhoneNumber: funeralHomeOccupant.occupantPhoneNumber, - occupantEmailAddress: funeralHomeOccupant.occupantEmailAddress - }, - user - ); + addLotOccupancyOccupant( + { + lotOccupancyId: deceasedLotOccupancyId, + lotOccupantTypeId: funeralHomeOccupant.lotOccupantTypeId, + occupantName: funeralHomeOccupant.occupantName, + occupantAddress1: funeralHomeOccupant.occupantAddress1, + occupantAddress2: funeralHomeOccupant.occupantAddress2, + occupantCity: funeralHomeOccupant.occupantCity, + occupantProvince: funeralHomeOccupant.occupantProvince, + occupantPostalCode: funeralHomeOccupant.occupantPostalCode, + occupantPhoneNumber: funeralHomeOccupant.occupantPhoneNumber, + occupantEmailAddress: funeralHomeOccupant.occupantEmailAddress + }, + user + ) - /* + /* addOrUpdateLotOccupancyField( { lotOccupancyId: deceasedLotOccupancyId, @@ -873,685 +897,700 @@ function importFromMasterCSV() { user ); */ - } - - if (masterRow.CM_FUNERAL_YR !== "") { - const lotOccupancyFieldValue = formatDateString( - masterRow.CM_FUNERAL_YR, - masterRow.CM_FUNERAL_MON, - masterRow.CM_FUNERAL_DAY - ); - - addOrUpdateLotOccupancyField( - { - lotOccupancyId: deceasedLotOccupancyId, - occupancyTypeFieldId: (lotId - ? deceasedOccupancyType - : cremationOccupancyType - ).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Funeral Date"; - }).occupancyTypeFieldId, - lotOccupancyFieldValue - }, - user - ); - } - - if (masterRow.CM_CONTAINER_TYPE !== "") { - addOrUpdateLotOccupancyField( - { - lotOccupancyId: deceasedLotOccupancyId, - occupancyTypeFieldId: (lotId - ? deceasedOccupancyType - : cremationOccupancyType - ).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Container Type"; - }).occupancyTypeFieldId, - lotOccupancyFieldValue: masterRow.CM_CONTAINER_TYPE - }, - user - ); - } - - if (masterRow.CM_COMMITTAL_TYPE !== "") { - let commitalType = masterRow.CM_COMMITTAL_TYPE; - - if (commitalType === "GS") { - commitalType = "Graveside"; - } - - addOrUpdateLotOccupancyField( - { - lotOccupancyId: deceasedLotOccupancyId, - occupancyTypeFieldId: (lotId - ? deceasedOccupancyType - : cremationOccupancyType - ).occupancyTypeFields.find((occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Committal Type"; - }).occupancyTypeFieldId, - lotOccupancyFieldValue: commitalType - }, - user - ); - } - - if (masterRow.CM_REMARK1 !== "") { - addLotOccupancyComment( - { - lotOccupancyId: deceasedLotOccupancyId, - lotOccupancyCommentDateString: deceasedOccupancyStartDateString, - lotOccupancyCommentTimeString: "00:00", - lotOccupancyComment: masterRow.CM_REMARK1 - }, - user - ); - } - - if (masterRow.CM_REMARK2 !== "") { - addLotOccupancyComment( - { - lotOccupancyId: deceasedLotOccupancyId, - lotOccupancyCommentDateString: deceasedOccupancyStartDateString, - lotOccupancyCommentTimeString: "00:00", - lotOccupancyComment: masterRow.CM_REMARK2 - }, - user - ); - } - - updateLotStatus(lotId, takenLotStatus.lotStatusId, user); - - if (masterRow.CM_PRENEED_OWNER) { - addLotOccupancyOccupant( - { - lotOccupancyId: deceasedLotOccupancyId, - lotOccupantTypeId: preneedOwnerLotOccupantType.lotOccupantTypeId, - occupantName: masterRow.CM_PRENEED_OWNER, - occupantAddress1: "", - occupantAddress2: "", - occupantCity: "", - occupantProvince: "", - occupantPostalCode: "", - occupantPhoneNumber: "", - occupantEmailAddress: "" - }, - user - ); - } - } } - } catch (error) { - console.error(error); - console.log(masterRow); - } - console.timeEnd("importFromMasterCSV"); + if (masterRow.CM_FUNERAL_YR !== '') { + const lotOccupancyFieldValue = formatDateString( + masterRow.CM_FUNERAL_YR, + masterRow.CM_FUNERAL_MON, + masterRow.CM_FUNERAL_DAY + ) + + addOrUpdateLotOccupancyField( + { + lotOccupancyId: deceasedLotOccupancyId, + occupancyTypeFieldId: (lotId + ? deceasedOccupancyType + : cremationOccupancyType + ).occupancyTypeFields.find((occupancyTypeField) => { + return occupancyTypeField.occupancyTypeField === 'Funeral Date' + }).occupancyTypeFieldId, + lotOccupancyFieldValue + }, + user + ) + } + + if (masterRow.CM_CONTAINER_TYPE !== '') { + addOrUpdateLotOccupancyField( + { + lotOccupancyId: deceasedLotOccupancyId, + occupancyTypeFieldId: (lotId + ? deceasedOccupancyType + : cremationOccupancyType + ).occupancyTypeFields.find((occupancyTypeField) => { + return ( + occupancyTypeField.occupancyTypeField === 'Container Type' + ) + }).occupancyTypeFieldId, + lotOccupancyFieldValue: masterRow.CM_CONTAINER_TYPE + }, + user + ) + } + + if (masterRow.CM_COMMITTAL_TYPE !== '') { + let commitalType = masterRow.CM_COMMITTAL_TYPE + + if (commitalType === 'GS') { + commitalType = 'Graveside' + } + + addOrUpdateLotOccupancyField( + { + lotOccupancyId: deceasedLotOccupancyId, + occupancyTypeFieldId: (lotId + ? deceasedOccupancyType + : cremationOccupancyType + ).occupancyTypeFields.find((occupancyTypeField) => { + return ( + occupancyTypeField.occupancyTypeField === 'Committal Type' + ) + }).occupancyTypeFieldId, + lotOccupancyFieldValue: commitalType + }, + user + ) + } + + if (masterRow.CM_REMARK1 !== '') { + addLotOccupancyComment( + { + lotOccupancyId: deceasedLotOccupancyId, + lotOccupancyCommentDateString: deceasedOccupancyStartDateString, + lotOccupancyCommentTimeString: '00:00', + lotOccupancyComment: masterRow.CM_REMARK1 + }, + user + ) + } + + if (masterRow.CM_REMARK2 !== '') { + addLotOccupancyComment( + { + lotOccupancyId: deceasedLotOccupancyId, + lotOccupancyCommentDateString: deceasedOccupancyStartDateString, + lotOccupancyCommentTimeString: '00:00', + lotOccupancyComment: masterRow.CM_REMARK2 + }, + user + ) + } + + updateLotStatus(lotId, takenLotStatus.lotStatusId, user) + + if (masterRow.CM_PRENEED_OWNER) { + addLotOccupancyOccupant( + { + lotOccupancyId: deceasedLotOccupancyId, + lotOccupantTypeId: preneedOwnerLotOccupantType.lotOccupantTypeId, + occupantName: masterRow.CM_PRENEED_OWNER, + occupantAddress1: '', + occupantAddress2: '', + occupantCity: '', + occupantProvince: '', + occupantPostalCode: '', + occupantPhoneNumber: '', + occupantEmailAddress: '' + }, + user + ) + } + } + } + } catch (error) { + console.error(error) + console.log(masterRow) + } + + console.timeEnd('importFromMasterCSV') } function importFromPrepaidCSV() { - console.time("importFromPrepaidCSV"); + console.time('importFromPrepaidCSV') - let prepaidRow: PrepaidRecord; + let prepaidRow: PrepaidRecord - const rawData = fs.readFileSync("./temp/CMPRPAID.csv").toString(); + const rawData = fs.readFileSync('./temp/CMPRPAID.csv').toString() - const cmprpaid: papa.ParseResult = papa.parse(rawData, { - delimiter: ",", - header: true, - skipEmptyLines: true - }); + const cmprpaid: papa.ParseResult = papa.parse(rawData, { + delimiter: ',', + header: true, + skipEmptyLines: true + }) - for (const parseError of cmprpaid.errors) { - console.log(parseError); - } + for (const parseError of cmprpaid.errors) { + console.log(parseError) + } - try { - for (prepaidRow of cmprpaid.data) { - if (!prepaidRow.CMPP_PREPAID_FOR_NAME) { - continue; - } + try { + for (prepaidRow of cmprpaid.data) { + if (!prepaidRow.CMPP_PREPAID_FOR_NAME) { + continue + } - let cemetery = prepaidRow.CMPP_CEMETERY; + let cemetery = prepaidRow.CMPP_CEMETERY - if (cemetery && cemetery === ".m") { - cemetery = "HC"; - } + if (cemetery && cemetery === '.m') { + cemetery = 'HC' + } - let lot: recordTypes.Lot; + let lot: recordTypes.Lot - if (cemetery) { - const map = getMap({ - cemetery - }); + if (cemetery) { + const map = getMap({ + cemetery + }) - const lotName = buildLotName({ - cemetery, - block: prepaidRow.CMPP_BLOCK, - range1: prepaidRow.CMPP_RANGE1, - range2: prepaidRow.CMPP_RANGE2, - lot1: prepaidRow.CMPP_LOT1, - lot2: prepaidRow.CMPP_LOT2, - grave1: prepaidRow.CMPP_GRAVE1, - grave2: prepaidRow.CMPP_GRAVE2, - interment: prepaidRow.CMPP_INTERMENT - }); + const lotName = buildLotName({ + cemetery, + block: prepaidRow.CMPP_BLOCK, + range1: prepaidRow.CMPP_RANGE1, + range2: prepaidRow.CMPP_RANGE2, + lot1: prepaidRow.CMPP_LOT1, + lot2: prepaidRow.CMPP_LOT2, + grave1: prepaidRow.CMPP_GRAVE1, + grave2: prepaidRow.CMPP_GRAVE2, + interment: prepaidRow.CMPP_INTERMENT + }) - lot = getLotByLotName(lotName); + lot = getLotByLotName(lotName) - if (!lot) { - const lotType = getLotType({ - cemetery - }); + if (!lot) { + const lotType = getLotType({ + cemetery + }) - const lotId = addLot( - { - lotName: lotName, - lotTypeId: lotType.lotTypeId, - lotStatusId: reservedLotStatus.lotStatusId, - mapId: map.mapId, - mapKey: lotName.includes(",") ? lotName.split(",")[0] : lotName, - lotLatitude: "", - lotLongitude: "" - }, - user - ); + const lotId = addLot( + { + lotName: lotName, + lotTypeId: lotType.lotTypeId, + lotStatusId: reservedLotStatus.lotStatusId, + mapId: map.mapId, + mapKey: lotName.includes(',') ? lotName.split(',')[0] : lotName, + lotLatitude: '', + lotLongitude: '' + }, + user + ) - lot = getLot(lotId); - } - } - - if (lot && lot.lotStatusId === availableLotStatus.lotStatusId) { - updateLotStatus(lot.lotId, reservedLotStatus.lotStatusId, user); - } - - const occupancyStartDateString = formatDateString( - prepaidRow.CMPP_PURCH_YR, - prepaidRow.CMPP_PURCH_MON, - prepaidRow.CMPP_PURCH_DAY - ); - - let lotOccupancyId: number; - - if (lot) { - const possibleLotOccupancies = getLotOccupancies( - { - lotId: lot.lotId, - occupancyTypeId: preneedOccupancyType.occupancyTypeId, - occupantName: prepaidRow.CMPP_PREPAID_FOR_NAME, - occupancyStartDateString - }, - { - includeOccupants: false, - limit: -1, - offset: 0 - } - ); - - if (possibleLotOccupancies.lotOccupancies.length > 0) { - lotOccupancyId = possibleLotOccupancies.lotOccupancies[0].lotOccupancyId; - } - } - - if (!lotOccupancyId) { - lotOccupancyId = addLotOccupancy( - { - lotId: lot ? lot.lotId : "", - occupancyTypeId: preneedOccupancyType.occupancyTypeId, - occupancyStartDateString, - occupancyEndDateString: "" - }, - user - ); - } - - addLotOccupancyOccupant( - { - lotOccupancyId, - lotOccupantTypeId: preneedOwnerLotOccupantType.lotOccupantTypeId, - occupantName: prepaidRow.CMPP_PREPAID_FOR_NAME, - occupantAddress1: prepaidRow.CMPP_ADDRESS, - occupantAddress2: "", - occupantCity: prepaidRow.CMPP_CITY, - occupantProvince: prepaidRow.CMPP_PROV.slice(0, 2), - occupantPostalCode: prepaidRow.CMPP_POSTAL1 + " " + prepaidRow.CMPP_POSTAL2, - occupantPhoneNumber: "", - occupantEmailAddress: "" - }, - user - ); - - if (prepaidRow.CMPP_ARRANGED_BY_NAME) { - addLotOccupancyOccupant( - { - lotOccupancyId, - lotOccupantTypeId: purchaserLotOccupantType.lotOccupantTypeId, - occupantName: prepaidRow.CMPP_ARRANGED_BY_NAME, - occupantAddress1: "", - occupantAddress2: "", - occupantCity: "", - occupantProvince: "", - occupantPostalCode: "", - occupantPhoneNumber: "", - occupantEmailAddress: "" - }, - user - ); - } - - if (prepaidRow.CMPP_FEE_GRAV_SD !== "0.0") { - addLotOccupancyFee( - { - lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_GRAV_SD"), - quantity: 1, - feeAmount: prepaidRow.CMPP_FEE_GRAV_SD, - taxAmount: prepaidRow.CMPP_GST_GRAV_SD - }, - user - ); - } - - if (prepaidRow.CMPP_FEE_GRAV_DD !== "0.0") { - addLotOccupancyFee( - { - lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_GRAV_DD"), - quantity: 1, - feeAmount: prepaidRow.CMPP_FEE_GRAV_DD, - taxAmount: prepaidRow.CMPP_GST_GRAV_DD - }, - user - ); - } - - if (prepaidRow.CMPP_FEE_CHAP_SD !== "0.0") { - addLotOccupancyFee( - { - lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_CHAP_SD"), - quantity: 1, - feeAmount: prepaidRow.CMPP_FEE_CHAP_SD, - taxAmount: prepaidRow.CMPP_GST_CHAP_SD - }, - user - ); - } - - if (prepaidRow.CMPP_FEE_CHAP_DD !== "0.0") { - addLotOccupancyFee( - { - lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_CHAP_DD"), - quantity: 1, - feeAmount: prepaidRow.CMPP_FEE_CHAP_DD, - taxAmount: prepaidRow.CMPP_GST_CHAP_DD - }, - user - ); - } - - if (prepaidRow.CMPP_FEE_ENTOMBMENT !== "0.0") { - addLotOccupancyFee( - { - lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_ENTOMBMENT"), - quantity: 1, - feeAmount: prepaidRow.CMPP_FEE_ENTOMBMENT, - taxAmount: prepaidRow.CMPP_GST_ENTOMBMENT - }, - user - ); - } - - if (prepaidRow.CMPP_FEE_CREM !== "0.0") { - addLotOccupancyFee( - { - lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_CREM"), - quantity: 1, - feeAmount: prepaidRow.CMPP_FEE_CREM, - taxAmount: prepaidRow.CMPP_GST_CREM - }, - user - ); - } - - if (prepaidRow.CMPP_FEE_NICHE !== "0.0") { - addLotOccupancyFee( - { - lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_NICHE"), - quantity: 1, - feeAmount: prepaidRow.CMPP_FEE_NICHE, - taxAmount: prepaidRow.CMPP_GST_NICHE - }, - user - ); - } - - if ( - prepaidRow.CMPP_FEE_DISINTERMENT !== "0.0" && - prepaidRow.CMPP_FEE_DISINTERMENT !== "20202.02" - ) { - addLotOccupancyFee( - { - lotOccupancyId, - feeId: getFeeIdByFeeDescription("CMPP_FEE_DISINTERMENT"), - quantity: 1, - feeAmount: prepaidRow.CMPP_FEE_DISINTERMENT, - taxAmount: prepaidRow.CMPP_GST_DISINTERMENT - }, - user - ); - } - - const transactionAmount = - Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_SD) + - Number.parseFloat(prepaidRow.CMPP_GST_GRAV_SD) + - Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_DD) + - Number.parseFloat(prepaidRow.CMPP_GST_GRAV_DD) + - Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_SD) + - Number.parseFloat(prepaidRow.CMPP_GST_CHAP_SD) + - Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_DD) + - Number.parseFloat(prepaidRow.CMPP_GST_CHAP_DD) + - Number.parseFloat(prepaidRow.CMPP_FEE_ENTOMBMENT) + - Number.parseFloat(prepaidRow.CMPP_GST_ENTOMBMENT) + - Number.parseFloat(prepaidRow.CMPP_FEE_CREM) + - Number.parseFloat(prepaidRow.CMPP_GST_CREM) + - Number.parseFloat(prepaidRow.CMPP_FEE_NICHE) + - Number.parseFloat(prepaidRow.CMPP_GST_NICHE) + - Number.parseFloat( - prepaidRow.CMPP_FEE_DISINTERMENT === "20202.02" - ? "0" - : prepaidRow.CMPP_FEE_DISINTERMENT - ) + - Number.parseFloat( - prepaidRow.CMPP_GST_DISINTERMENT === "20202.02" - ? "0" - : prepaidRow.CMPP_GST_DISINTERMENT - ); - - addLotOccupancyTransaction( - { - lotOccupancyId, - externalReceiptNumber: "", - transactionAmount, - transactionDateString: occupancyStartDateString, - transactionNote: "Order Number: " + prepaidRow.CMPP_ORDER_NO - }, - user - ); - - if (prepaidRow.CMPP_REMARK1) { - addLotOccupancyComment( - { - lotOccupancyId, - lotOccupancyCommentDateString: occupancyStartDateString, - lotOccupancyComment: prepaidRow.CMPP_REMARK1 - }, - user - ); - } - - if (prepaidRow.CMPP_REMARK2) { - addLotOccupancyComment( - { - lotOccupancyId, - lotOccupancyCommentDateString: occupancyStartDateString, - lotOccupancyComment: prepaidRow.CMPP_REMARK2 - }, - user - ); - } + lot = getLot(lotId) } - } catch (error) { - console.error(error); - console.log(prepaidRow); - } + } - console.timeEnd("importFromPrepaidCSV"); + if (lot && lot.lotStatusId === availableLotStatus.lotStatusId) { + updateLotStatus(lot.lotId, reservedLotStatus.lotStatusId, user) + } + + const occupancyStartDateString = formatDateString( + prepaidRow.CMPP_PURCH_YR, + prepaidRow.CMPP_PURCH_MON, + prepaidRow.CMPP_PURCH_DAY + ) + + let lotOccupancyId: number + + if (lot) { + const possibleLotOccupancies = getLotOccupancies( + { + lotId: lot.lotId, + occupancyTypeId: preneedOccupancyType.occupancyTypeId, + occupantName: prepaidRow.CMPP_PREPAID_FOR_NAME, + occupancyStartDateString + }, + { + includeOccupants: false, + limit: -1, + offset: 0 + } + ) + + if (possibleLotOccupancies.lotOccupancies.length > 0) { + lotOccupancyId = + possibleLotOccupancies.lotOccupancies[0].lotOccupancyId + } + } + + if (!lotOccupancyId) { + lotOccupancyId = addLotOccupancy( + { + lotId: lot ? lot.lotId : '', + occupancyTypeId: preneedOccupancyType.occupancyTypeId, + occupancyStartDateString, + occupancyEndDateString: '' + }, + user + ) + } + + addLotOccupancyOccupant( + { + lotOccupancyId, + lotOccupantTypeId: preneedOwnerLotOccupantType.lotOccupantTypeId, + occupantName: prepaidRow.CMPP_PREPAID_FOR_NAME, + occupantAddress1: prepaidRow.CMPP_ADDRESS, + occupantAddress2: '', + occupantCity: prepaidRow.CMPP_CITY, + occupantProvince: prepaidRow.CMPP_PROV.slice(0, 2), + occupantPostalCode: + prepaidRow.CMPP_POSTAL1 + ' ' + prepaidRow.CMPP_POSTAL2, + occupantPhoneNumber: '', + occupantEmailAddress: '' + }, + user + ) + + if (prepaidRow.CMPP_ARRANGED_BY_NAME) { + addLotOccupancyOccupant( + { + lotOccupancyId, + lotOccupantTypeId: purchaserLotOccupantType.lotOccupantTypeId, + occupantName: prepaidRow.CMPP_ARRANGED_BY_NAME, + occupantAddress1: '', + occupantAddress2: '', + occupantCity: '', + occupantProvince: '', + occupantPostalCode: '', + occupantPhoneNumber: '', + occupantEmailAddress: '' + }, + user + ) + } + + if (prepaidRow.CMPP_FEE_GRAV_SD !== '0.0') { + addLotOccupancyFee( + { + lotOccupancyId, + feeId: getFeeIdByFeeDescription('CMPP_FEE_GRAV_SD'), + quantity: 1, + feeAmount: prepaidRow.CMPP_FEE_GRAV_SD, + taxAmount: prepaidRow.CMPP_GST_GRAV_SD + }, + user + ) + } + + if (prepaidRow.CMPP_FEE_GRAV_DD !== '0.0') { + addLotOccupancyFee( + { + lotOccupancyId, + feeId: getFeeIdByFeeDescription('CMPP_FEE_GRAV_DD'), + quantity: 1, + feeAmount: prepaidRow.CMPP_FEE_GRAV_DD, + taxAmount: prepaidRow.CMPP_GST_GRAV_DD + }, + user + ) + } + + if (prepaidRow.CMPP_FEE_CHAP_SD !== '0.0') { + addLotOccupancyFee( + { + lotOccupancyId, + feeId: getFeeIdByFeeDescription('CMPP_FEE_CHAP_SD'), + quantity: 1, + feeAmount: prepaidRow.CMPP_FEE_CHAP_SD, + taxAmount: prepaidRow.CMPP_GST_CHAP_SD + }, + user + ) + } + + if (prepaidRow.CMPP_FEE_CHAP_DD !== '0.0') { + addLotOccupancyFee( + { + lotOccupancyId, + feeId: getFeeIdByFeeDescription('CMPP_FEE_CHAP_DD'), + quantity: 1, + feeAmount: prepaidRow.CMPP_FEE_CHAP_DD, + taxAmount: prepaidRow.CMPP_GST_CHAP_DD + }, + user + ) + } + + if (prepaidRow.CMPP_FEE_ENTOMBMENT !== '0.0') { + addLotOccupancyFee( + { + lotOccupancyId, + feeId: getFeeIdByFeeDescription('CMPP_FEE_ENTOMBMENT'), + quantity: 1, + feeAmount: prepaidRow.CMPP_FEE_ENTOMBMENT, + taxAmount: prepaidRow.CMPP_GST_ENTOMBMENT + }, + user + ) + } + + if (prepaidRow.CMPP_FEE_CREM !== '0.0') { + addLotOccupancyFee( + { + lotOccupancyId, + feeId: getFeeIdByFeeDescription('CMPP_FEE_CREM'), + quantity: 1, + feeAmount: prepaidRow.CMPP_FEE_CREM, + taxAmount: prepaidRow.CMPP_GST_CREM + }, + user + ) + } + + if (prepaidRow.CMPP_FEE_NICHE !== '0.0') { + addLotOccupancyFee( + { + lotOccupancyId, + feeId: getFeeIdByFeeDescription('CMPP_FEE_NICHE'), + quantity: 1, + feeAmount: prepaidRow.CMPP_FEE_NICHE, + taxAmount: prepaidRow.CMPP_GST_NICHE + }, + user + ) + } + + if ( + prepaidRow.CMPP_FEE_DISINTERMENT !== '0.0' && + prepaidRow.CMPP_FEE_DISINTERMENT !== '20202.02' + ) { + addLotOccupancyFee( + { + lotOccupancyId, + feeId: getFeeIdByFeeDescription('CMPP_FEE_DISINTERMENT'), + quantity: 1, + feeAmount: prepaidRow.CMPP_FEE_DISINTERMENT, + taxAmount: prepaidRow.CMPP_GST_DISINTERMENT + }, + user + ) + } + + const transactionAmount = + Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_SD) + + Number.parseFloat(prepaidRow.CMPP_GST_GRAV_SD) + + Number.parseFloat(prepaidRow.CMPP_FEE_GRAV_DD) + + Number.parseFloat(prepaidRow.CMPP_GST_GRAV_DD) + + Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_SD) + + Number.parseFloat(prepaidRow.CMPP_GST_CHAP_SD) + + Number.parseFloat(prepaidRow.CMPP_FEE_CHAP_DD) + + Number.parseFloat(prepaidRow.CMPP_GST_CHAP_DD) + + Number.parseFloat(prepaidRow.CMPP_FEE_ENTOMBMENT) + + Number.parseFloat(prepaidRow.CMPP_GST_ENTOMBMENT) + + Number.parseFloat(prepaidRow.CMPP_FEE_CREM) + + Number.parseFloat(prepaidRow.CMPP_GST_CREM) + + Number.parseFloat(prepaidRow.CMPP_FEE_NICHE) + + Number.parseFloat(prepaidRow.CMPP_GST_NICHE) + + Number.parseFloat( + prepaidRow.CMPP_FEE_DISINTERMENT === '20202.02' + ? '0' + : prepaidRow.CMPP_FEE_DISINTERMENT + ) + + Number.parseFloat( + prepaidRow.CMPP_GST_DISINTERMENT === '20202.02' + ? '0' + : prepaidRow.CMPP_GST_DISINTERMENT + ) + + addLotOccupancyTransaction( + { + lotOccupancyId, + externalReceiptNumber: '', + transactionAmount, + transactionDateString: occupancyStartDateString, + transactionNote: 'Order Number: ' + prepaidRow.CMPP_ORDER_NO + }, + user + ) + + if (prepaidRow.CMPP_REMARK1) { + addLotOccupancyComment( + { + lotOccupancyId, + lotOccupancyCommentDateString: occupancyStartDateString, + lotOccupancyComment: prepaidRow.CMPP_REMARK1 + }, + user + ) + } + + if (prepaidRow.CMPP_REMARK2) { + addLotOccupancyComment( + { + lotOccupancyId, + lotOccupancyCommentDateString: occupancyStartDateString, + lotOccupancyComment: prepaidRow.CMPP_REMARK2 + }, + user + ) + } + } + } catch (error) { + console.error(error) + console.log(prepaidRow) + } + + console.timeEnd('importFromPrepaidCSV') } function importFromWorkOrderCSV() { - console.time("importFromWorkOrderCSV"); + console.time('importFromWorkOrderCSV') - let workOrderRow: WorkOrderRecord; + let workOrderRow: WorkOrderRecord - const rawData = fs.readFileSync("./temp/CMWKORDR.csv").toString(); + const rawData = fs.readFileSync('./temp/CMWKORDR.csv').toString() - const cmwkordr: papa.ParseResult = papa.parse(rawData, { - delimiter: ",", - header: true, - skipEmptyLines: true - }); + const cmwkordr: papa.ParseResult = papa.parse(rawData, { + delimiter: ',', + header: true, + skipEmptyLines: true + }) - for (const parseError of cmwkordr.errors) { - console.log(parseError); - } + for (const parseError of cmwkordr.errors) { + console.log(parseError) + } - const currentDateString = dateToString(new Date()); + const currentDateString = dateToString(new Date()) - try { - for (workOrderRow of cmwkordr.data) { - const workOrderNumber = ("000000" + workOrderRow.WO_WORK_ORDER).slice(-6); + try { + for (workOrderRow of cmwkordr.data) { + const workOrderNumber = ('000000' + workOrderRow.WO_WORK_ORDER).slice(-6) - let workOrder = getWorkOrderByWorkOrderNumber(workOrderNumber); + let workOrder = getWorkOrderByWorkOrderNumber(workOrderNumber) - const workOrderOpenDateString = dateIntegerToString( - Number.parseInt(workOrderRow.WO_INITIATION_DATE, 10) - ); + const workOrderOpenDateString = dateIntegerToString( + Number.parseInt(workOrderRow.WO_INITIATION_DATE, 10) + ) - if (workOrder) { - if (workOrder.workOrderCloseDate) { - reopenWorkOrder(workOrder.workOrderId, user); - delete workOrder.workOrderCloseDate; - delete workOrder.workOrderCloseDateString; + if (workOrder) { + if (workOrder.workOrderCloseDate) { + reopenWorkOrder(workOrder.workOrderId, user) + delete workOrder.workOrderCloseDate + delete workOrder.workOrderCloseDateString + } + } else { + const workOrderId = addWorkOrder( + { + workOrderNumber, + workOrderTypeId: 1, + workOrderDescription: ( + workOrderRow.WO_REMARK1 + + ' ' + + workOrderRow.WO_REMARK2 + + ' ' + + workOrderRow.WO_REMARK3 + ).trim(), + workOrderOpenDateString + }, + user + ) + + workOrder = getWorkOrder(workOrderId, { + includeLotsAndLotOccupancies: true, + includeComments: true, + includeMilestones: true + }) + } + + let lot: recordTypes.Lot + + if (workOrderRow.WO_CEMETERY !== '00') { + const lotName = buildLotName({ + cemetery: workOrderRow.WO_CEMETERY, + block: workOrderRow.WO_BLOCK, + range1: workOrderRow.WO_RANGE1, + range2: workOrderRow.WO_RANGE2, + lot1: workOrderRow.WO_LOT1, + lot2: workOrderRow.WO_LOT2, + grave1: workOrderRow.WO_GRAVE1, + grave2: workOrderRow.WO_GRAVE2, + interment: workOrderRow.WO_INTERMENT + }) + + lot = getLotByLotName(lotName) + + if (!lot) { + const map = getMap({ cemetery: workOrderRow.WO_CEMETERY }) + + const lotType = getLotType({ + cemetery: workOrderRow.WO_CEMETERY + }) + + const lotId = addLot( + { + mapId: map.mapId, + lotName, + mapKey: lotName.includes(',') ? lotName.split(',')[0] : lotName, + lotStatusId: takenLotStatus.lotStatusId, + lotTypeId: lotType.lotTypeId, + lotLatitude: '', + lotLongitude: '' + }, + user + ) + + lot = getLot(lotId) + } else { + updateLotStatus(lot.lotId, takenLotStatus.lotStatusId, user) + } + + const workOrderContainsLot = workOrder.workOrderLots.find( + (possibleLot) => { + return (possibleLot.lotId = lot.lotId) + } + ) + + if (!workOrderContainsLot) { + addWorkOrderLot( + { + workOrderId: workOrder.workOrderId, + lotId: lot.lotId + }, + user + ) + + workOrder.workOrderLots.push(lot) + } + } + + let occupancyStartDateString = workOrderOpenDateString + + if (workOrderRow.WO_INTERMENT_YR) { + occupancyStartDateString = formatDateString( + workOrderRow.WO_INTERMENT_YR, + workOrderRow.WO_INTERMENT_MON, + workOrderRow.WO_INTERMENT_DAY + ) + } + + const lotOccupancyId = addLotOccupancy( + { + lotId: lot ? lot.lotId : '', + occupancyTypeId: deceasedOccupancyType.occupancyTypeId, + occupancyStartDateString, + occupancyEndDateString: '' + }, + user + ) + + addLotOccupancyOccupant( + { + lotOccupancyId, + lotOccupantTypeId: deceasedLotOccupantType.lotOccupantTypeId, + occupantName: workOrderRow.WO_DECEASED_NAME, + occupantAddress1: workOrderRow.WO_ADDRESS, + occupantAddress2: '', + occupantCity: workOrderRow.WO_CITY, + occupantProvince: workOrderRow.WO_PROV.slice(0, 2), + occupantPostalCode: + workOrderRow.WO_POST1 + ' ' + workOrderRow.WO_POST2, + occupantPhoneNumber: '', + occupantEmailAddress: '' + }, + user + ) + + if (workOrderRow.WO_DEATH_YR !== '') { + const lotOccupancyFieldValue = formatDateString( + workOrderRow.WO_DEATH_YR, + workOrderRow.WO_DEATH_MON, + workOrderRow.WO_DEATH_DAY + ) + + addOrUpdateLotOccupancyField( + { + lotOccupancyId: lotOccupancyId, + occupancyTypeFieldId: + deceasedOccupancyType.occupancyTypeFields.find( + (occupancyTypeField) => { + return occupancyTypeField.occupancyTypeField === 'Death Date' } - } else { - const workOrderId = addWorkOrder( - { - workOrderNumber, - workOrderTypeId: 1, - workOrderDescription: ( - workOrderRow.WO_REMARK1 + - " " + - workOrderRow.WO_REMARK2 + - " " + - workOrderRow.WO_REMARK3 - ).trim(), - workOrderOpenDateString - }, - user - ); + ).occupancyTypeFieldId, + lotOccupancyFieldValue + }, + user + ) + } - workOrder = getWorkOrder(workOrderId, { - includeLotsAndLotOccupancies: true, - includeComments: true, - includeMilestones: true - }); - } - - let lot: recordTypes.Lot; - - if (workOrderRow.WO_CEMETERY !== "00") { - const lotName = buildLotName({ - cemetery: workOrderRow.WO_CEMETERY, - block: workOrderRow.WO_BLOCK, - range1: workOrderRow.WO_RANGE1, - range2: workOrderRow.WO_RANGE2, - lot1: workOrderRow.WO_LOT1, - lot2: workOrderRow.WO_LOT2, - grave1: workOrderRow.WO_GRAVE1, - grave2: workOrderRow.WO_GRAVE2, - interment: workOrderRow.WO_INTERMENT - }); - - lot = getLotByLotName(lotName); - - if (!lot) { - const map = getMap({ cemetery: workOrderRow.WO_CEMETERY }); - - const lotType = getLotType({ - cemetery: workOrderRow.WO_CEMETERY - }); - - const lotId = addLot( - { - mapId: map.mapId, - lotName, - mapKey: lotName.includes(",") ? lotName.split(",")[0] : lotName, - lotStatusId: takenLotStatus.lotStatusId, - lotTypeId: lotType.lotTypeId, - lotLatitude: "", - lotLongitude: "" - }, - user - ); - - lot = getLot(lotId); - } else { - updateLotStatus(lot.lotId, takenLotStatus.lotStatusId, user); + if (workOrderRow.WO_DEATH_PLACE !== '') { + addOrUpdateLotOccupancyField( + { + lotOccupancyId: lotOccupancyId, + occupancyTypeFieldId: + deceasedOccupancyType.occupancyTypeFields.find( + (occupancyTypeField) => { + return occupancyTypeField.occupancyTypeField === 'Death Place' } + ).occupancyTypeFieldId, + lotOccupancyFieldValue: workOrderRow.WO_DEATH_PLACE + }, + user + ) + } - const workOrderContainsLot = workOrder.workOrderLots.find((possibleLot) => { - return (possibleLot.lotId = lot.lotId); - }); - - if (!workOrderContainsLot) { - addWorkOrderLot( - { - workOrderId: workOrder.workOrderId, - lotId: lot.lotId - }, - user - ); - - workOrder.workOrderLots.push(lot); + if (workOrderRow.WO_AGE !== '') { + addOrUpdateLotOccupancyField( + { + lotOccupancyId: lotOccupancyId, + occupancyTypeFieldId: + deceasedOccupancyType.occupancyTypeFields.find( + (occupancyTypeField) => { + return occupancyTypeField.occupancyTypeField === 'Death Age' } - } + ).occupancyTypeFieldId, + lotOccupancyFieldValue: workOrderRow.WO_AGE + }, + user + ) + } - let occupancyStartDateString = workOrderOpenDateString; + if (workOrderRow.WO_PERIOD !== '') { + addOrUpdateLotOccupancyField( + { + lotOccupancyId: lotOccupancyId, + occupancyTypeFieldId: + deceasedOccupancyType.occupancyTypeFields.find( + (occupancyTypeField) => { + return ( + occupancyTypeField.occupancyTypeField === 'Death Age Period' + ) + } + ).occupancyTypeFieldId, + lotOccupancyFieldValue: workOrderRow.WO_PERIOD + }, + user + ) + } - if (workOrderRow.WO_INTERMENT_YR) { - occupancyStartDateString = formatDateString( - workOrderRow.WO_INTERMENT_YR, - workOrderRow.WO_INTERMENT_MON, - workOrderRow.WO_INTERMENT_DAY - ); - } + if (workOrderRow.WO_FUNERAL_HOME !== '') { + const funeralHomeOccupant = getFuneralHome(workOrderRow.WO_FUNERAL_HOME) - const lotOccupancyId = addLotOccupancy( - { - lotId: lot ? lot.lotId : "", - occupancyTypeId: deceasedOccupancyType.occupancyTypeId, - occupancyStartDateString, - occupancyEndDateString: "" - }, - user - ); + addLotOccupancyOccupant( + { + lotOccupancyId: lotOccupancyId, + lotOccupantTypeId: funeralHomeOccupant.lotOccupantTypeId, + occupantName: funeralHomeOccupant.occupantName, + occupantAddress1: funeralHomeOccupant.occupantAddress1, + occupantAddress2: funeralHomeOccupant.occupantAddress2, + occupantCity: funeralHomeOccupant.occupantCity, + occupantProvince: funeralHomeOccupant.occupantProvince, + occupantPostalCode: funeralHomeOccupant.occupantPostalCode, + occupantPhoneNumber: funeralHomeOccupant.occupantPhoneNumber, + occupantEmailAddress: funeralHomeOccupant.occupantEmailAddress + }, + user + ) - addLotOccupancyOccupant( - { - lotOccupancyId, - lotOccupantTypeId: deceasedLotOccupantType.lotOccupantTypeId, - occupantName: workOrderRow.WO_DECEASED_NAME, - occupantAddress1: workOrderRow.WO_ADDRESS, - occupantAddress2: "", - occupantCity: workOrderRow.WO_CITY, - occupantProvince: workOrderRow.WO_PROV.slice(0, 2), - occupantPostalCode: workOrderRow.WO_POST1 + " " + workOrderRow.WO_POST2, - occupantPhoneNumber: "", - occupantEmailAddress: "" - }, - user - ); - - if (workOrderRow.WO_DEATH_YR !== "") { - const lotOccupancyFieldValue = formatDateString( - workOrderRow.WO_DEATH_YR, - workOrderRow.WO_DEATH_MON, - workOrderRow.WO_DEATH_DAY - ); - - addOrUpdateLotOccupancyField( - { - lotOccupancyId: lotOccupancyId, - occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find( - (occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Date"; - } - ).occupancyTypeFieldId, - lotOccupancyFieldValue - }, - user - ); - } - - if (workOrderRow.WO_DEATH_PLACE !== "") { - addOrUpdateLotOccupancyField( - { - lotOccupancyId: lotOccupancyId, - occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find( - (occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Place"; - } - ).occupancyTypeFieldId, - lotOccupancyFieldValue: workOrderRow.WO_DEATH_PLACE - }, - user - ); - } - - if (workOrderRow.WO_AGE !== "") { - addOrUpdateLotOccupancyField( - { - lotOccupancyId: lotOccupancyId, - occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find( - (occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Age"; - } - ).occupancyTypeFieldId, - lotOccupancyFieldValue: workOrderRow.WO_AGE - }, - user - ); - } - - if (workOrderRow.WO_PERIOD !== "") { - addOrUpdateLotOccupancyField( - { - lotOccupancyId: lotOccupancyId, - occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find( - (occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Death Age Period"; - } - ).occupancyTypeFieldId, - lotOccupancyFieldValue: workOrderRow.WO_PERIOD - }, - user - ); - } - - if (workOrderRow.WO_FUNERAL_HOME !== "") { - const funeralHomeOccupant = getFuneralHome(workOrderRow.WO_FUNERAL_HOME); - - addLotOccupancyOccupant( - { - lotOccupancyId: lotOccupancyId, - lotOccupantTypeId: funeralHomeOccupant.lotOccupantTypeId, - occupantName: funeralHomeOccupant.occupantName, - occupantAddress1: funeralHomeOccupant.occupantAddress1, - occupantAddress2: funeralHomeOccupant.occupantAddress2, - occupantCity: funeralHomeOccupant.occupantCity, - occupantProvince: funeralHomeOccupant.occupantProvince, - occupantPostalCode: funeralHomeOccupant.occupantPostalCode, - occupantPhoneNumber: funeralHomeOccupant.occupantPhoneNumber, - occupantEmailAddress: funeralHomeOccupant.occupantEmailAddress - }, - user - ); - - /* + /* addOrUpdateLotOccupancyField( { lotOccupancyId: lotOccupancyId, @@ -1563,266 +1602,278 @@ function importFromWorkOrderCSV() { user ); */ - } + } - if (workOrderRow.WO_FUNERAL_YR !== "") { - const lotOccupancyFieldValue = formatDateString( - workOrderRow.WO_FUNERAL_YR, - workOrderRow.WO_FUNERAL_MON, - workOrderRow.WO_FUNERAL_DAY - ); + if (workOrderRow.WO_FUNERAL_YR !== '') { + const lotOccupancyFieldValue = formatDateString( + workOrderRow.WO_FUNERAL_YR, + workOrderRow.WO_FUNERAL_MON, + workOrderRow.WO_FUNERAL_DAY + ) - addOrUpdateLotOccupancyField( - { - lotOccupancyId: lotOccupancyId, - occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find( - (occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Funeral Date"; - } - ).occupancyTypeFieldId, - lotOccupancyFieldValue - }, - user - ); - } - - if (workOrderRow.WO_CONTAINER_TYPE !== "") { - addOrUpdateLotOccupancyField( - { - lotOccupancyId: lotOccupancyId, - occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find( - (occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Container Type"; - } - ).occupancyTypeFieldId, - lotOccupancyFieldValue: workOrderRow.WO_CONTAINER_TYPE - }, - user - ); - } - - if (workOrderRow.WO_COMMITTAL_TYPE !== "") { - let commitalType = workOrderRow.WO_COMMITTAL_TYPE; - - if (commitalType === "GS") { - commitalType = "Graveside"; + addOrUpdateLotOccupancyField( + { + lotOccupancyId: lotOccupancyId, + occupancyTypeFieldId: + deceasedOccupancyType.occupancyTypeFields.find( + (occupancyTypeField) => { + return ( + occupancyTypeField.occupancyTypeField === 'Funeral Date' + ) } + ).occupancyTypeFieldId, + lotOccupancyFieldValue + }, + user + ) + } - addOrUpdateLotOccupancyField( - { - lotOccupancyId: lotOccupancyId, - occupancyTypeFieldId: deceasedOccupancyType.occupancyTypeFields.find( - (occupancyTypeField) => { - return occupancyTypeField.occupancyTypeField === "Committal Type"; - } - ).occupancyTypeFieldId, - lotOccupancyFieldValue: commitalType - }, - user - ); - } - - addWorkOrderLotOccupancy( - { - workOrderId: workOrder.workOrderId, - lotOccupancyId - }, - user - ); - - // Milestones - - let hasIncompleteMilestones = !workOrderRow.WO_CONFIRMATION_IN; - let maxMilestoneCompletionDateString = workOrderOpenDateString; - - if (acknowledgedWorkOrderMilestoneType) { - addWorkOrderMilestone( - { - workOrderId: workOrder.workOrderId, - workOrderMilestoneTypeId: - acknowledgedWorkOrderMilestoneType.workOrderMilestoneTypeId, - workOrderMilestoneDateString: workOrderOpenDateString, - workOrderMilestoneDescription: "", - workOrderMilestoneCompletionDateString: workOrderRow.WO_CONFIRMATION_IN - ? workOrderOpenDateString - : undefined, - workOrderMilestoneCompletionTimeString: workOrderRow.WO_CONFIRMATION_IN - ? "00:00" - : undefined - }, - user - ); - } - - if (workOrderRow.WO_DEATH_YR) { - const workOrderMilestoneDateString = formatDateString( - workOrderRow.WO_DEATH_YR, - workOrderRow.WO_DEATH_MON, - workOrderRow.WO_DEATH_DAY - ); - - if (deathWorkOrderMilestoneType) { - addWorkOrderMilestone( - { - workOrderId: workOrder.workOrderId, - workOrderMilestoneTypeId: - deathWorkOrderMilestoneType.workOrderMilestoneTypeId, - workOrderMilestoneDateString, - workOrderMilestoneDescription: - "Death Place: " + workOrderRow.WO_DEATH_PLACE, - workOrderMilestoneCompletionDateString: - workOrderMilestoneDateString < currentDateString - ? workOrderMilestoneDateString - : undefined, - workOrderMilestoneCompletionTimeString: - workOrderMilestoneDateString < currentDateString - ? "00:00" - : undefined - }, - user - ); + if (workOrderRow.WO_CONTAINER_TYPE !== '') { + addOrUpdateLotOccupancyField( + { + lotOccupancyId: lotOccupancyId, + occupancyTypeFieldId: + deceasedOccupancyType.occupancyTypeFields.find( + (occupancyTypeField) => { + return ( + occupancyTypeField.occupancyTypeField === 'Container Type' + ) } + ).occupancyTypeFieldId, + lotOccupancyFieldValue: workOrderRow.WO_CONTAINER_TYPE + }, + user + ) + } - if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) { - maxMilestoneCompletionDateString = workOrderMilestoneDateString; - } + if (workOrderRow.WO_COMMITTAL_TYPE !== '') { + let commitalType = workOrderRow.WO_COMMITTAL_TYPE - if (workOrderMilestoneDateString >= currentDateString) { - hasIncompleteMilestones = true; - } - } - - if (workOrderRow.WO_FUNERAL_YR) { - const workOrderMilestoneDateString = formatDateString( - workOrderRow.WO_FUNERAL_YR, - workOrderRow.WO_FUNERAL_MON, - workOrderRow.WO_FUNERAL_DAY - ); - - let funeralHour = Number.parseInt(workOrderRow.WO_FUNERAL_HR, 10); - if (funeralHour <= 6) { - funeralHour += 12; - } - - const workOrderMilestoneTimeString = formatTimeString( - funeralHour.toString(), - workOrderRow.WO_FUNERAL_MIN - ); - - if (funeralWorkOrderMilestoneType) { - addWorkOrderMilestone( - { - workOrderId: workOrder.workOrderId, - workOrderMilestoneTypeId: - funeralWorkOrderMilestoneType.workOrderMilestoneTypeId, - workOrderMilestoneDateString, - workOrderMilestoneTimeString, - workOrderMilestoneDescription: - "Funeral Home: " + workOrderRow.WO_FUNERAL_HOME, - workOrderMilestoneCompletionDateString: - workOrderMilestoneDateString < currentDateString - ? workOrderMilestoneDateString - : undefined, - workOrderMilestoneCompletionTimeString: - workOrderMilestoneDateString < currentDateString - ? workOrderMilestoneTimeString - : undefined - }, - user - ); - } - - if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) { - maxMilestoneCompletionDateString = workOrderMilestoneDateString; - } - - if (workOrderMilestoneDateString >= currentDateString) { - hasIncompleteMilestones = true; - } - } - - if (workOrderRow.WO_CREMATION === "Y" && cremationWorkOrderMilestoneType) { - addWorkOrderMilestone( - { - workOrderId: workOrder.workOrderId, - workOrderMilestoneTypeId: - cremationWorkOrderMilestoneType.workOrderMilestoneTypeId, - workOrderMilestoneDateString: maxMilestoneCompletionDateString, - workOrderMilestoneDescription: "", - workOrderMilestoneCompletionDateString: - maxMilestoneCompletionDateString < currentDateString - ? maxMilestoneCompletionDateString - : undefined, - workOrderMilestoneCompletionTimeString: - maxMilestoneCompletionDateString < currentDateString - ? "00:00" - : undefined - }, - user - ); - } - - if (workOrderRow.WO_INTERMENT_YR) { - const workOrderMilestoneDateString = formatDateString( - workOrderRow.WO_INTERMENT_YR, - workOrderRow.WO_INTERMENT_MON, - workOrderRow.WO_INTERMENT_DAY - ); - - if (intermentWorkOrderMilestoneType) { - addWorkOrderMilestone( - { - workOrderId: workOrder.workOrderId, - workOrderMilestoneTypeId: - intermentWorkOrderMilestoneType.workOrderMilestoneTypeId, - workOrderMilestoneDateString, - workOrderMilestoneDescription: "Depth: " + workOrderRow.WO_DEPTH, - workOrderMilestoneCompletionDateString: - workOrderMilestoneDateString < currentDateString - ? workOrderMilestoneDateString - : undefined, - workOrderMilestoneCompletionTimeString: - workOrderMilestoneDateString < currentDateString - ? "23:59" - : undefined - }, - user - ); - } - - if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) { - maxMilestoneCompletionDateString = workOrderMilestoneDateString; - } - - if (workOrderMilestoneDateString >= currentDateString) { - hasIncompleteMilestones = true; - } - } - - if (!hasIncompleteMilestones) { - closeWorkOrder( - { - workOrderId: workOrder.workOrderId, - workOrderCloseDateString: maxMilestoneCompletionDateString - }, - user - ); - } + if (commitalType === 'GS') { + commitalType = 'Graveside' } - } catch (error) { - console.error(error); - console.log(workOrderRow); - } - console.timeEnd("importFromWorkOrderCSV"); + addOrUpdateLotOccupancyField( + { + lotOccupancyId: lotOccupancyId, + occupancyTypeFieldId: + deceasedOccupancyType.occupancyTypeFields.find( + (occupancyTypeField) => { + return ( + occupancyTypeField.occupancyTypeField === 'Committal Type' + ) + } + ).occupancyTypeFieldId, + lotOccupancyFieldValue: commitalType + }, + user + ) + } + + addWorkOrderLotOccupancy( + { + workOrderId: workOrder.workOrderId, + lotOccupancyId + }, + user + ) + + // Milestones + + let hasIncompleteMilestones = !workOrderRow.WO_CONFIRMATION_IN + let maxMilestoneCompletionDateString = workOrderOpenDateString + + if (acknowledgedWorkOrderMilestoneType) { + addWorkOrderMilestone( + { + workOrderId: workOrder.workOrderId, + workOrderMilestoneTypeId: + acknowledgedWorkOrderMilestoneType.workOrderMilestoneTypeId, + workOrderMilestoneDateString: workOrderOpenDateString, + workOrderMilestoneDescription: '', + workOrderMilestoneCompletionDateString: + workOrderRow.WO_CONFIRMATION_IN + ? workOrderOpenDateString + : undefined, + workOrderMilestoneCompletionTimeString: + workOrderRow.WO_CONFIRMATION_IN ? '00:00' : undefined + }, + user + ) + } + + if (workOrderRow.WO_DEATH_YR) { + const workOrderMilestoneDateString = formatDateString( + workOrderRow.WO_DEATH_YR, + workOrderRow.WO_DEATH_MON, + workOrderRow.WO_DEATH_DAY + ) + + if (deathWorkOrderMilestoneType) { + addWorkOrderMilestone( + { + workOrderId: workOrder.workOrderId, + workOrderMilestoneTypeId: + deathWorkOrderMilestoneType.workOrderMilestoneTypeId, + workOrderMilestoneDateString, + workOrderMilestoneDescription: + 'Death Place: ' + workOrderRow.WO_DEATH_PLACE, + workOrderMilestoneCompletionDateString: + workOrderMilestoneDateString < currentDateString + ? workOrderMilestoneDateString + : undefined, + workOrderMilestoneCompletionTimeString: + workOrderMilestoneDateString < currentDateString + ? '00:00' + : undefined + }, + user + ) + } + + if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) { + maxMilestoneCompletionDateString = workOrderMilestoneDateString + } + + if (workOrderMilestoneDateString >= currentDateString) { + hasIncompleteMilestones = true + } + } + + if (workOrderRow.WO_FUNERAL_YR) { + const workOrderMilestoneDateString = formatDateString( + workOrderRow.WO_FUNERAL_YR, + workOrderRow.WO_FUNERAL_MON, + workOrderRow.WO_FUNERAL_DAY + ) + + let funeralHour = Number.parseInt(workOrderRow.WO_FUNERAL_HR, 10) + if (funeralHour <= 6) { + funeralHour += 12 + } + + const workOrderMilestoneTimeString = formatTimeString( + funeralHour.toString(), + workOrderRow.WO_FUNERAL_MIN + ) + + if (funeralWorkOrderMilestoneType) { + addWorkOrderMilestone( + { + workOrderId: workOrder.workOrderId, + workOrderMilestoneTypeId: + funeralWorkOrderMilestoneType.workOrderMilestoneTypeId, + workOrderMilestoneDateString, + workOrderMilestoneTimeString, + workOrderMilestoneDescription: + 'Funeral Home: ' + workOrderRow.WO_FUNERAL_HOME, + workOrderMilestoneCompletionDateString: + workOrderMilestoneDateString < currentDateString + ? workOrderMilestoneDateString + : undefined, + workOrderMilestoneCompletionTimeString: + workOrderMilestoneDateString < currentDateString + ? workOrderMilestoneTimeString + : undefined + }, + user + ) + } + + if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) { + maxMilestoneCompletionDateString = workOrderMilestoneDateString + } + + if (workOrderMilestoneDateString >= currentDateString) { + hasIncompleteMilestones = true + } + } + + if ( + workOrderRow.WO_CREMATION === 'Y' && + cremationWorkOrderMilestoneType + ) { + addWorkOrderMilestone( + { + workOrderId: workOrder.workOrderId, + workOrderMilestoneTypeId: + cremationWorkOrderMilestoneType.workOrderMilestoneTypeId, + workOrderMilestoneDateString: maxMilestoneCompletionDateString, + workOrderMilestoneDescription: '', + workOrderMilestoneCompletionDateString: + maxMilestoneCompletionDateString < currentDateString + ? maxMilestoneCompletionDateString + : undefined, + workOrderMilestoneCompletionTimeString: + maxMilestoneCompletionDateString < currentDateString + ? '00:00' + : undefined + }, + user + ) + } + + if (workOrderRow.WO_INTERMENT_YR) { + const workOrderMilestoneDateString = formatDateString( + workOrderRow.WO_INTERMENT_YR, + workOrderRow.WO_INTERMENT_MON, + workOrderRow.WO_INTERMENT_DAY + ) + + if (intermentWorkOrderMilestoneType) { + addWorkOrderMilestone( + { + workOrderId: workOrder.workOrderId, + workOrderMilestoneTypeId: + intermentWorkOrderMilestoneType.workOrderMilestoneTypeId, + workOrderMilestoneDateString, + workOrderMilestoneDescription: 'Depth: ' + workOrderRow.WO_DEPTH, + workOrderMilestoneCompletionDateString: + workOrderMilestoneDateString < currentDateString + ? workOrderMilestoneDateString + : undefined, + workOrderMilestoneCompletionTimeString: + workOrderMilestoneDateString < currentDateString + ? '23:59' + : undefined + }, + user + ) + } + + if (workOrderMilestoneDateString > maxMilestoneCompletionDateString) { + maxMilestoneCompletionDateString = workOrderMilestoneDateString + } + + if (workOrderMilestoneDateString >= currentDateString) { + hasIncompleteMilestones = true + } + } + + if (!hasIncompleteMilestones) { + closeWorkOrder( + { + workOrderId: workOrder.workOrderId, + workOrderCloseDateString: maxMilestoneCompletionDateString + }, + user + ) + } + } + } catch (error) { + console.error(error) + console.log(workOrderRow) + } + + console.timeEnd('importFromWorkOrderCSV') } -console.time("importFromCsv"); +console.time('importFromCsv') -purgeTables(); +purgeTables() // purgeConfigTables(); -importFromMasterCSV(); -importFromPrepaidCSV(); -importFromWorkOrderCSV(); +importFromMasterCSV() +importFromPrepaidCSV() +importFromWorkOrderCSV() -console.timeEnd("importFromCsv"); +console.timeEnd('importFromCsv') diff --git a/test/1_serverCypress.js b/test/1_serverCypress.js index f0063366..bff0164f 100644 --- a/test/1_serverCypress.js +++ b/test/1_serverCypress.js @@ -30,10 +30,10 @@ describe('lot-occupancy-system', () => { cypressCommand += ' --record'; } const childProcess = exec(cypressCommand); - childProcess.stdout.on('data', (data) => { + childProcess.stdout?.on('data', (data) => { console.log(data); }); - childProcess.stderr.on('data', (data) => { + childProcess.stderr?.on('data', (data) => { console.error(data); }); childProcess.on('exit', (code) => { diff --git a/test/1_serverCypress.ts b/test/1_serverCypress.ts index 75140a14..6c286f51 100644 --- a/test/1_serverCypress.ts +++ b/test/1_serverCypress.ts @@ -48,11 +48,11 @@ describe('lot-occupancy-system', () => { const childProcess = exec(cypressCommand) - childProcess.stdout.on('data', (data) => { + childProcess.stdout?.on('data', (data) => { console.log(data) }) - childProcess.stderr.on('data', (data) => { + childProcess.stderr?.on('data', (data) => { console.error(data) }) diff --git a/test/_globals.d.ts b/test/_globals.d.ts index 1ffe21f8..3d01e418 100644 --- a/test/_globals.d.ts +++ b/test/_globals.d.ts @@ -1,6 +1,6 @@ /// -import type { Request } from "express"; -import type { Session } from "express-session"; +import type { Request } from 'express'; +import type { Session } from 'express-session'; export declare const testView = "*testView"; export declare const testUpdate = "*testUpdate"; export declare const testAdmin = "*testAdmin"; diff --git a/test/_globals.js b/test/_globals.js index a2fc0a8e..016152b0 100644 --- a/test/_globals.js +++ b/test/_globals.js @@ -1,9 +1,9 @@ -export const testView = "*testView"; -export const testUpdate = "*testUpdate"; -export const testAdmin = "*testAdmin"; +export const testView = '*testView'; +export const testUpdate = '*testUpdate'; +export const testAdmin = '*testAdmin'; export const portNumber = 7000; export const fakeViewOnlySession = { - id: "", + id: '', cookie: undefined, destroy: undefined, regenerate: undefined, @@ -14,7 +14,7 @@ export const fakeViewOnlySession = { user: undefined }; export const fakeAdminSession = { - id: "", + id: '', cookie: undefined, destroy: undefined, regenerate: undefined, diff --git a/test/_globals.ts b/test/_globals.ts index 2e05c828..586663fe 100644 --- a/test/_globals.ts +++ b/test/_globals.ts @@ -1,132 +1,132 @@ -import type { Request } from "express"; +import type { Request } from 'express' -import type { Session } from "express-session"; +import type { Session } from 'express-session' -export const testView = "*testView"; -export const testUpdate = "*testUpdate"; -export const testAdmin = "*testAdmin"; +export const testView = '*testView' +export const testUpdate = '*testUpdate' +export const testAdmin = '*testAdmin' -export const portNumber = 7000; +export const portNumber = 7000 export const fakeViewOnlySession: Session = { - id: "", - cookie: undefined, - destroy: undefined, - regenerate: undefined, - reload: undefined, - resetMaxAge: undefined, - save: undefined, - touch: undefined, - user: undefined -}; + id: '', + cookie: undefined, + destroy: undefined, + regenerate: undefined, + reload: undefined, + resetMaxAge: undefined, + save: undefined, + touch: undefined, + user: undefined +} export const fakeAdminSession: Session = { - id: "", - cookie: undefined, - destroy: undefined, - regenerate: undefined, - reload: undefined, - resetMaxAge: undefined, - save: undefined, - touch: undefined, - user: undefined -}; + id: '', + cookie: undefined, + destroy: undefined, + regenerate: undefined, + reload: undefined, + resetMaxAge: undefined, + save: undefined, + touch: undefined, + user: undefined +} export const fakeRequest: Request = { - // eslint-disable-next-line @typescript-eslint/no-empty-function - async *[Symbol.asyncIterator]() {}, - _destroy: undefined, - _read: undefined, - aborted: undefined, - accepted: undefined, - accepts: undefined, - acceptsCharsets: undefined, - acceptsEncodings: undefined, - acceptsLanguages: undefined, - addListener: undefined, - app: undefined, - baseUrl: undefined, - body: undefined, - cookies: undefined, - complete: undefined, - connection: undefined, - csrfToken: undefined, - destroy: undefined, - destroyed: undefined, - emit: undefined, - eventNames: undefined, - fresh: undefined, - get: undefined, - getMaxListeners: undefined, - header: undefined, - headers: undefined, - host: undefined, - hostname: undefined, - httpVersion: undefined, - httpVersionMajor: undefined, - httpVersionMinor: undefined, - ip: undefined, - ips: undefined, - is: undefined, - isPaused: undefined, - listenerCount: undefined, - listeners: undefined, - method: undefined, - off: undefined, - on: undefined, - once: undefined, - originalUrl: undefined, - param: undefined, - params: undefined, - path: undefined, - pause: undefined, - pipe: undefined, - prependListener: undefined, - prependOnceListener: undefined, - protocol: undefined, - push: undefined, - query: undefined, - range: undefined, - rawHeaders: undefined, - rawListeners: undefined, - rawTrailers: undefined, - read: undefined, - readable: undefined, - readableAborted: undefined, - readableDidRead: undefined, - readableEncoding: undefined, - readableEnded: undefined, - readableFlowing: undefined, - readableLength: undefined, - readableHighWaterMark: undefined, - readableObjectMode: undefined, - removeAllListeners: undefined, - removeListener: undefined, - resume: undefined, - route: undefined, - secure: undefined, - session: undefined, - sessionID: undefined, - sessionStore: undefined, - setEncoding: undefined, - setMaxListeners: undefined, - setTimeout: undefined, - signedCookies: undefined, - socket: undefined, - stale: undefined, - subdomains: undefined, - trailers: undefined, - unpipe: undefined, - unshift: undefined, - url: undefined, - wrap: undefined, - xhr: undefined -}; + // eslint-disable-next-line @typescript-eslint/no-empty-function + async *[Symbol.asyncIterator]() {}, + _destroy: undefined, + _read: undefined, + aborted: undefined, + accepted: undefined, + accepts: undefined, + acceptsCharsets: undefined, + acceptsEncodings: undefined, + acceptsLanguages: undefined, + addListener: undefined, + app: undefined, + baseUrl: undefined, + body: undefined, + cookies: undefined, + complete: undefined, + connection: undefined, + csrfToken: undefined, + destroy: undefined, + destroyed: undefined, + emit: undefined, + eventNames: undefined, + fresh: undefined, + get: undefined, + getMaxListeners: undefined, + header: undefined, + headers: undefined, + host: undefined, + hostname: undefined, + httpVersion: undefined, + httpVersionMajor: undefined, + httpVersionMinor: undefined, + ip: undefined, + ips: undefined, + is: undefined, + isPaused: undefined, + listenerCount: undefined, + listeners: undefined, + method: undefined, + off: undefined, + on: undefined, + once: undefined, + originalUrl: undefined, + param: undefined, + params: undefined, + path: undefined, + pause: undefined, + pipe: undefined, + prependListener: undefined, + prependOnceListener: undefined, + protocol: undefined, + push: undefined, + query: undefined, + range: undefined, + rawHeaders: undefined, + rawListeners: undefined, + rawTrailers: undefined, + read: undefined, + readable: undefined, + readableAborted: undefined, + readableDidRead: undefined, + readableEncoding: undefined, + readableEnded: undefined, + readableFlowing: undefined, + readableLength: undefined, + readableHighWaterMark: undefined, + readableObjectMode: undefined, + removeAllListeners: undefined, + removeListener: undefined, + resume: undefined, + route: undefined, + secure: undefined, + session: undefined, + sessionID: undefined, + sessionStore: undefined, + setEncoding: undefined, + setMaxListeners: undefined, + setTimeout: undefined, + signedCookies: undefined, + socket: undefined, + stale: undefined, + subdomains: undefined, + trailers: undefined, + unpipe: undefined, + unshift: undefined, + url: undefined, + wrap: undefined, + xhr: undefined +} export const fakeViewOnlyRequest = Object.assign({}, fakeRequest, { - session: fakeViewOnlySession -}); + session: fakeViewOnlySession +}) export const fakeAdminRequest = Object.assign({}, fakeRequest, { - session: fakeAdminSession -}); + session: fakeAdminSession +})