From 547c2e224f6064c7ae375d47c8bb9d4610a7499b Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Mon, 24 Feb 2025 15:02:30 -0500 Subject: [PATCH] major refactoring --- app.js | 18 +- app.ts | 18 +- .../{maps.cy.d.ts => cemeteries.cy.d.ts} | 0 cypress/e2e/02-update/cemeteries.cy.js | 69 ++++ cypress/e2e/02-update/cemeteries.cy.ts | 138 ++++++++ cypress/e2e/02-update/maps.cy.js | 71 ---- cypress/e2e/02-update/maps.cy.ts | 127 ------- cypress/fixtures/cemetery.json | 10 + cypress/fixtures/map.json | 10 - data/config.defaultValues.d.ts | 15 +- data/config.defaultValues.js | 16 +- data/config.defaultValues.ts | 16 +- database/addBurialSite.d.ts | 26 +- database/addBurialSite.js | 44 ++- database/addBurialSite.ts | 85 +++-- database/addBurialSiteContract.d.ts | 21 ++ database/addBurialSiteContract.js | 54 +++ database/addBurialSiteContract.ts | 122 +++++++ database/addBurialSiteContractFee.d.ts | 9 + ...ancyFee.js => addBurialSiteContractFee.js} | 54 +-- ...ancyFee.ts => addBurialSiteContractFee.ts} | 76 ++-- .../addBurialSiteContractFeeCategory.d.ts | 5 + ...js => addBurialSiteContractFeeCategory.js} | 10 +- ...ts => addBurialSiteContractFeeCategory.ts} | 14 +- database/addContractTypeField.js | 2 +- database/addContractTypeField.ts | 2 +- database/addLotOccupancy.d.ts | 21 -- database/addLotOccupancy.js | 54 --- database/addLotOccupancy.ts | 122 ------- database/addLotOccupancyFee.d.ts | 9 - database/addLotOccupancyFeeCategory.d.ts | 5 - database/addLotOccupancyTransaction.d.ts | 2 +- database/addLotOccupancyTransaction.js | 8 +- database/addLotOccupancyTransaction.ts | 10 +- database/copyBurialSiteContract.d.ts | 1 + database/copyBurialSiteContract.js | 62 ++++ database/copyBurialSiteContract.ts | 94 +++++ database/copyLotOccupancy.d.ts | 1 - database/copyLotOccupancy.js | 56 --- database/copyLotOccupancy.ts | 92 ----- database/deleteRecord.js | 2 +- database/deleteRecord.ts | 2 +- database/getBurialSite.d.ts | 1 - database/getBurialSite.js | 16 +- database/getBurialSite.ts | 22 +- database/getBurialSiteComments.d.ts | 3 + ...otComments.js => getBurialSiteComments.js} | 26 +- ...otComments.ts => getBurialSiteComments.ts} | 32 +- database/getBurialSiteContract.d.ts | 3 + database/getBurialSiteContract.js | 56 +++ database/getBurialSiteContract.ts | 90 +++++ database/getBurialSiteContractComments.d.ts | 3 + database/getBurialSiteContractComments.js | 25 ++ database/getBurialSiteContractComments.ts | 46 +++ database/getBurialSiteContractFees.d.ts | 3 + ...cyFees.js => getBurialSiteContractFees.js} | 14 +- ...cyFees.ts => getBurialSiteContractFees.ts} | 20 +- database/getBurialSiteContractFields.d.ts | 3 + database/getBurialSiteContractFields.js | 33 ++ database/getBurialSiteContractFields.ts | 51 +++ database/getBurialSiteContractInterments.d.ts | 3 + database/getBurialSiteContractInterments.js | 34 ++ database/getBurialSiteContractInterments.ts | 51 +++ .../getBurialSiteContractTransactions.d.ts | 5 + ...s => getBurialSiteContractTransactions.js} | 12 +- ...s => getBurialSiteContractTransactions.ts} | 18 +- database/getBurialSiteContracts.d.ts | 30 ++ database/getBurialSiteContracts.js | 150 ++++++++ database/getBurialSiteContracts.ts | 262 ++++++++++++++ database/getBurialSiteFields.d.ts | 3 + database/getBurialSiteFields.js | 36 ++ database/getBurialSiteFields.ts | 54 +++ database/getBurialSiteStatusSummary.d.ts | 9 + database/getBurialSiteStatusSummary.js | 21 ++ database/getBurialSiteStatusSummary.ts | 41 +++ database/getBurialSiteStatuses.d.ts | 2 + database/getBurialSiteStatuses.js | 21 ++ database/getBurialSiteStatuses.ts | 37 ++ database/getBurialSiteTypeFields.d.ts | 3 + database/getBurialSiteTypeFields.js | 26 ++ database/getBurialSiteTypeFields.ts | 48 +++ database/getBurialSiteTypeSummary.d.ts | 9 + database/getBurialSiteTypeSummary.js | 21 ++ database/getBurialSiteTypeSummary.ts | 41 +++ database/getBurialSiteTypes.d.ts | 2 + database/getBurialSiteTypes.js | 23 ++ database/getBurialSiteTypes.ts | 44 +++ database/getBurialSites.d.ts | 22 ++ database/getBurialSites.js | 114 ++++++ database/getBurialSites.ts | 177 ++++++++++ database/getCemeteries.d.ts | 2 + database/getCemeteries.js | 22 ++ database/getCemeteries.ts | 30 ++ database/getCemetery.d.ts | 2 + database/getCemetery.js | 27 ++ database/getCemetery.ts | 37 ++ database/getContractTypeFields.d.ts | 3 + database/getContractTypeFields.js | 31 ++ database/getContractTypeFields.ts | 57 +++ database/getContractTypePrints.d.ts | 2 + ...TypePrints.js => getContractTypePrints.js} | 16 +- ...TypePrints.ts => getContractTypePrints.ts} | 18 +- database/getContractTypes.d.ts | 2 + database/getContractTypes.js | 25 ++ database/getContractTypes.ts | 51 +++ database/getLotComments.d.ts | 3 - database/getLotFields.d.ts | 3 - database/getLotFields.js | 36 -- database/getLotFields.ts | 49 --- database/getLotOccupancies.d.ts | 29 -- database/getLotOccupancies.js | 133 ------- database/getLotOccupancies.ts | 247 ------------- database/getLotOccupancy.d.ts | 3 - database/getLotOccupancy.js | 45 --- database/getLotOccupancy.ts | 82 ----- database/getLotOccupancyComments.d.ts | 3 - database/getLotOccupancyComments.js | 27 -- database/getLotOccupancyComments.ts | 47 --- database/getLotOccupancyFees.d.ts | 3 - database/getLotOccupancyFields.d.ts | 3 - database/getLotOccupancyFields.js | 33 -- database/getLotOccupancyFields.ts | 51 --- database/getLotOccupancyOccupants.d.ts | 3 - database/getLotOccupancyOccupants.js | 23 -- database/getLotOccupancyOccupants.ts | 36 -- database/getLotOccupancyTransactions.d.ts | 5 - database/getLotOccupantTypes.d.ts | 2 - database/getLotOccupantTypes.js | 22 -- database/getLotOccupantTypes.ts | 41 --- database/getLotStatusSummary.d.ts | 9 - database/getLotStatusSummary.js | 20 -- database/getLotStatusSummary.ts | 40 --- database/getLotStatuses.d.ts | 2 - database/getLotStatuses.js | 21 -- database/getLotStatuses.ts | 37 -- database/getLotTypeFields.d.ts | 3 - database/getLotTypeFields.js | 26 -- database/getLotTypeFields.ts | 48 --- database/getLotTypeSummary.d.ts | 9 - database/getLotTypeSummary.js | 20 -- database/getLotTypeSummary.ts | 40 --- database/getLotTypes.d.ts | 2 - database/getLotTypes.js | 23 -- database/getLotTypes.ts | 41 --- database/getLots.d.ts | 21 -- database/getLots.js | 106 ------ database/getLots.ts | 172 ---------- database/getMap.d.ts | 2 - database/getMap.js | 27 -- database/getMap.ts | 37 -- database/getMaps.d.ts | 2 - database/getMaps.js | 20 -- database/getMaps.ts | 28 -- database/getNextCemeteryId.d.ts | 1 + database/getNextCemeteryId.js | 15 + database/getNextCemeteryId.ts | 23 ++ database/getNextMapId.d.ts | 1 - database/getNextMapId.js | 17 - database/getNextMapId.ts | 30 -- database/getOccupancyTypeFields.d.ts | 3 - database/getOccupancyTypeFields.js | 31 -- database/getOccupancyTypeFields.ts | 57 --- database/getOccupancyTypePrints.d.ts | 2 - database/getOccupancyTypes.d.ts | 2 - database/getOccupancyTypes.js | 25 -- database/getOccupancyTypes.ts | 51 --- database/getPastLotOccupancyOccupants.js | 6 +- database/getPastLotOccupancyOccupants.ts | 6 +- database/getPreviousCemeteryId.d.ts | 1 + database/getPreviousCemeteryId.js | 14 + database/getPreviousCemeteryId.ts | 22 ++ database/getPreviousMapId.d.ts | 1 - database/getPreviousMapId.js | 16 - database/getPreviousMapId.ts | 29 -- database/getWorkOrder.d.ts | 2 +- database/getWorkOrder.js | 18 +- database/getWorkOrder.ts | 20 +- database/getWorkOrderMilestones.js | 6 +- database/getWorkOrderMilestones.ts | 6 +- database/getWorkOrders.d.ts | 4 +- database/getWorkOrders.js | 22 +- database/getWorkOrders.ts | 26 +- database/moveBurialSiteTypeField.d.ts | 4 + database/moveBurialSiteTypeField.js | 81 +++++ database/moveBurialSiteTypeField.ts | 163 +++++++++ database/moveContractTypeField.d.ts | 4 + database/moveContractTypeField.js | 102 ++++++ ...yTypeField.ts => moveContractTypeField.ts} | 110 +++--- database/moveLotTypeField.d.ts | 4 - database/moveLotTypeField.js | 81 ----- database/moveLotTypeField.ts | 155 --------- database/moveOccupancyTypeField.d.ts | 4 - database/moveOccupancyTypeField.js | 102 ------ database/moveOccupancyTypePrintDown.d.ts | 4 +- database/moveOccupancyTypePrintDown.js | 44 +-- database/moveOccupancyTypePrintDown.ts | 44 +-- database/moveOccupancyTypePrintUp.d.ts | 4 +- database/moveOccupancyTypePrintUp.js | 38 +- database/moveOccupancyTypePrintUp.ts | 38 +- database/moveRecord.d.ts | 2 +- database/moveRecord.js | 7 +- database/moveRecord.ts | 14 +- database/updateBurialSite.d.ts | 18 + database/updateBurialSite.js | 59 ++++ database/updateBurialSite.ts | 137 ++++++++ database/updateBurialSiteComment.d.ts | 8 + database/updateBurialSiteComment.js | 17 + database/updateBurialSiteComment.ts | 46 +++ database/updateBurialSiteContract.d.ts | 11 + database/updateBurialSiteContract.js | 36 ++ database/updateBurialSiteContract.ts | 82 +++++ database/updateBurialSiteContractComment.d.ts | 8 + database/updateBurialSiteContractComment.js | 17 + database/updateBurialSiteContractComment.ts | 46 +++ .../updateBurialSiteContractFeeQuantity.d.ts | 6 + ...=> updateBurialSiteContractFeeQuantity.js} | 8 +- ...=> updateBurialSiteContractFeeQuantity.ts} | 14 +- ... updateBurialSiteContractTransaction.d.ts} | 6 +- .../updateBurialSiteContractTransaction.js | 20 ++ ...=> updateBurialSiteContractTransaction.ts} | 26 +- database/updateBurialSiteTypeField.d.ts | 11 + database/updateBurialSiteTypeField.js | 22 ++ database/updateBurialSiteTypeField.ts | 55 +++ database/updateCemetery.d.ts | 15 + database/updateCemetery.js | 24 ++ database/updateCemetery.ts | 63 ++++ database/updateContractTypeField.d.ts | 11 + database/updateContractTypeField.js | 22 ++ database/updateContractTypeField.ts | 55 +++ database/updateFee.d.ts | 4 +- database/updateFee.js | 6 +- database/updateFee.ts | 12 +- database/updateLot.d.ts | 14 - database/updateLot.js | 49 --- database/updateLot.ts | 110 ------ database/updateLotComment.d.ts | 8 - database/updateLotComment.js | 17 - database/updateLotComment.ts | 46 --- database/updateLotOccupancy.d.ts | 11 - database/updateLotOccupancy.js | 35 -- database/updateLotOccupancy.ts | 81 ----- database/updateLotOccupancyComment.d.ts | 8 - database/updateLotOccupancyComment.js | 17 - database/updateLotOccupancyComment.ts | 46 --- database/updateLotOccupancyFeeQuantity.d.ts | 6 - database/updateLotOccupancyOccupant.d.ts | 2 +- database/updateLotOccupancyOccupant.js | 4 +- database/updateLotOccupancyOccupant.ts | 6 +- database/updateLotOccupancyTransaction.js | 20 -- database/updateLotOccupantType.d.ts | 7 - database/updateLotOccupantType.js | 18 - database/updateLotOccupantType.ts | 43 --- database/updateLotTypeField.d.ts | 11 - database/updateLotTypeField.js | 22 -- database/updateLotTypeField.ts | 55 --- database/updateMap.d.ts | 15 - database/updateMap.js | 24 -- database/updateMap.ts | 63 ---- database/updateOccupancyTypeField.d.ts | 11 - database/updateOccupancyTypeField.js | 22 -- database/updateOccupancyTypeField.ts | 55 --- database/updateRecord.d.ts | 2 +- database/updateRecord.js | 6 +- database/updateRecord.ts | 12 +- database/updateRecordOrderNumber.d.ts | 2 +- database/updateRecordOrderNumber.js | 11 +- database/updateRecordOrderNumber.ts | 24 +- handlers/admin-get/burialSiteTypes.js | 4 +- handlers/admin-get/burialSiteTypes.ts | 4 +- handlers/admin-get/fees.js | 6 +- handlers/admin-get/fees.ts | 8 +- handlers/admin-get/occupancyTypes.js | 12 +- handlers/admin-get/occupancyTypes.ts | 14 +- handlers/admin-post/doAddLotStatus.js | 4 +- handlers/admin-post/doAddLotStatus.ts | 4 +- handlers/admin-post/doAddLotType.js | 8 +- handlers/admin-post/doAddLotType.ts | 8 +- handlers/admin-post/doAddLotTypeField.js | 4 +- handlers/admin-post/doAddLotTypeField.ts | 4 +- handlers/admin-post/doAddOccupancyType.js | 12 +- handlers/admin-post/doAddOccupancyType.ts | 14 +- .../admin-post/doAddOccupancyTypeField.js | 12 +- .../admin-post/doAddOccupancyTypeField.ts | 14 +- .../admin-post/doAddOccupancyTypePrint.js | 8 +- .../admin-post/doAddOccupancyTypePrint.ts | 10 +- handlers/admin-post/doDeleteLotStatus.d.ts | 2 +- handlers/admin-post/doDeleteLotStatus.js | 2 +- handlers/admin-post/doDeleteLotStatus.ts | 4 +- handlers/admin-post/doDeleteLotType.d.ts | 2 +- handlers/admin-post/doDeleteLotType.js | 6 +- handlers/admin-post/doDeleteLotType.ts | 8 +- handlers/admin-post/doDeleteLotTypeField.js | 6 +- handlers/admin-post/doDeleteLotTypeField.ts | 6 +- .../admin-post/doDeleteOccupancyType.d.ts | 2 +- handlers/admin-post/doDeleteOccupancyType.js | 10 +- handlers/admin-post/doDeleteOccupancyType.ts | 14 +- .../doDeleteOccupancyTypeField.d.ts | 2 +- .../admin-post/doDeleteOccupancyTypeField.js | 10 +- .../admin-post/doDeleteOccupancyTypeField.ts | 16 +- .../doDeleteOccupancyTypePrint.d.ts | 2 +- .../admin-post/doDeleteOccupancyTypePrint.js | 10 +- .../admin-post/doDeleteOccupancyTypePrint.ts | 14 +- handlers/admin-post/doMoveLotStatusDown.d.ts | 2 +- handlers/admin-post/doMoveLotStatusDown.js | 4 +- handlers/admin-post/doMoveLotStatusDown.ts | 6 +- handlers/admin-post/doMoveLotStatusUp.d.ts | 2 +- handlers/admin-post/doMoveLotStatusUp.js | 4 +- handlers/admin-post/doMoveLotStatusUp.ts | 6 +- handlers/admin-post/doMoveLotTypeDown.d.ts | 2 +- handlers/admin-post/doMoveLotTypeDown.js | 8 +- handlers/admin-post/doMoveLotTypeDown.ts | 10 +- handlers/admin-post/doMoveLotTypeFieldDown.js | 4 +- handlers/admin-post/doMoveLotTypeFieldDown.ts | 4 +- handlers/admin-post/doMoveLotTypeFieldUp.js | 4 +- handlers/admin-post/doMoveLotTypeFieldUp.ts | 4 +- handlers/admin-post/doMoveLotTypeUp.d.ts | 2 +- handlers/admin-post/doMoveLotTypeUp.js | 8 +- handlers/admin-post/doMoveLotTypeUp.ts | 10 +- .../admin-post/doMoveOccupancyTypeDown.d.ts | 2 +- .../admin-post/doMoveOccupancyTypeDown.js | 12 +- .../admin-post/doMoveOccupancyTypeDown.ts | 16 +- .../doMoveOccupancyTypeFieldDown.d.ts | 2 +- .../doMoveOccupancyTypeFieldDown.js | 12 +- .../doMoveOccupancyTypeFieldDown.ts | 16 +- .../doMoveOccupancyTypeFieldUp.d.ts | 2 +- .../admin-post/doMoveOccupancyTypeFieldUp.js | 12 +- .../admin-post/doMoveOccupancyTypeFieldUp.ts | 16 +- .../doMoveOccupancyTypePrintDown.d.ts | 2 +- .../doMoveOccupancyTypePrintDown.js | 12 +- .../doMoveOccupancyTypePrintDown.ts | 16 +- .../doMoveOccupancyTypePrintUp.d.ts | 2 +- .../admin-post/doMoveOccupancyTypePrintUp.js | 12 +- .../admin-post/doMoveOccupancyTypePrintUp.ts | 16 +- .../admin-post/doMoveOccupancyTypeUp.d.ts | 2 +- handlers/admin-post/doMoveOccupancyTypeUp.js | 12 +- handlers/admin-post/doMoveOccupancyTypeUp.ts | 16 +- handlers/admin-post/doUpdateLotStatus.d.ts | 2 +- handlers/admin-post/doUpdateLotStatus.js | 2 +- handlers/admin-post/doUpdateLotStatus.ts | 4 +- handlers/admin-post/doUpdateLotType.d.ts | 2 +- handlers/admin-post/doUpdateLotType.js | 6 +- handlers/admin-post/doUpdateLotType.ts | 8 +- handlers/admin-post/doUpdateLotTypeField.js | 8 +- handlers/admin-post/doUpdateLotTypeField.ts | 14 +- .../admin-post/doUpdateOccupancyType.d.ts | 2 +- handlers/admin-post/doUpdateOccupancyType.js | 10 +- handlers/admin-post/doUpdateOccupancyType.ts | 14 +- .../admin-post/doUpdateOccupancyTypeField.js | 8 +- .../admin-post/doUpdateOccupancyTypeField.ts | 10 +- handlers/api-get/milestoneICS.js | 12 +- handlers/api-get/milestoneICS.ts | 12 +- handlers/burialSites-get/edit.js | 4 +- handlers/burialSites-get/edit.ts | 4 +- handlers/burialSites-get/new.js | 14 +- handlers/burialSites-get/new.ts | 14 +- handlers/burialSites-get/search.js | 10 +- handlers/burialSites-get/search.ts | 10 +- .../burialSites-post/doGetLotTypeFields.js | 4 +- .../burialSites-post/doGetLotTypeFields.ts | 4 +- handlers/cemeteries-get/edit.js | 34 +- handlers/cemeteries-get/edit.ts | 34 +- handlers/cemeteries-get/new.js | 16 +- handlers/cemeteries-get/new.ts | 18 +- handlers/cemeteries-get/next.js | 12 +- handlers/cemeteries-get/next.ts | 12 +- handlers/cemeteries-get/previous.js | 12 +- handlers/cemeteries-get/previous.ts | 12 +- handlers/cemeteries-get/search.js | 11 +- handlers/cemeteries-get/search.ts | 11 +- handlers/cemeteries-get/view.js | 10 +- handlers/cemeteries-get/view.ts | 10 +- handlers/cemeteries-post/doCreateCemetery.js | 4 +- handlers/cemeteries-post/doCreateCemetery.ts | 4 +- handlers/cemeteries-post/doDeleteCemetery.js | 6 +- handlers/cemeteries-post/doDeleteCemetery.ts | 6 +- handlers/cemeteries-post/doUpdateMap.js | 2 +- handlers/cemeteries-post/doUpdateMap.ts | 2 +- handlers/contracts-get/edit.js | 14 +- handlers/contracts-get/edit.ts | 20 +- handlers/contracts-get/new.js | 14 +- handlers/contracts-get/new.ts | 16 +- handlers/contracts-get/search.js | 8 +- handlers/contracts-get/search.ts | 10 +- handlers/contracts-get/view.js | 10 +- handlers/contracts-get/view.ts | 12 +- .../doAddLotOccupancyComment.js | 2 +- .../doAddLotOccupancyComment.ts | 2 +- .../contracts-post/doAddLotOccupancyFee.js | 2 +- .../contracts-post/doAddLotOccupancyFee.ts | 2 +- .../doAddLotOccupancyFeeCategory.js | 2 +- .../doAddLotOccupancyFeeCategory.ts | 2 +- .../doAddLotOccupancyOccupant.js | 2 +- .../doAddLotOccupancyOccupant.ts | 2 +- .../doAddLotOccupancyTransaction.js | 2 +- .../doAddLotOccupancyTransaction.ts | 2 +- handlers/contracts-post/doCopyLotOccupancy.js | 4 +- handlers/contracts-post/doCopyLotOccupancy.ts | 6 +- .../contracts-post/doCreateLotOccupancy.js | 4 +- .../contracts-post/doCreateLotOccupancy.ts | 4 +- .../contracts-post/doDeleteLotOccupancy.js | 2 +- .../contracts-post/doDeleteLotOccupancy.ts | 2 +- .../doDeleteLotOccupancyComment.js | 4 +- .../doDeleteLotOccupancyComment.ts | 4 +- .../contracts-post/doDeleteLotOccupancyFee.js | 4 +- .../contracts-post/doDeleteLotOccupancyFee.ts | 4 +- .../doDeleteLotOccupancyOccupant.js | 4 +- .../doDeleteLotOccupancyOccupant.ts | 4 +- .../doDeleteLotOccupancyTransaction.js | 4 +- .../doDeleteLotOccupancyTransaction.ts | 4 +- handlers/contracts-post/doGetFees.js | 8 +- handlers/contracts-post/doGetFees.ts | 8 +- .../doGetOccupancyTypeFields.js | 12 +- .../doGetOccupancyTypeFields.ts | 16 +- .../contracts-post/doSearchLotOccupancies.js | 4 +- .../contracts-post/doSearchLotOccupancies.ts | 4 +- .../contracts-post/doUpdateLotOccupancy.js | 2 +- .../contracts-post/doUpdateLotOccupancy.ts | 2 +- .../doUpdateLotOccupancyComment.js | 2 +- .../doUpdateLotOccupancyComment.ts | 2 +- .../doUpdateLotOccupancyFeeQuantity.js | 2 +- .../doUpdateLotOccupancyFeeQuantity.ts | 2 +- .../doUpdateLotOccupancyOccupant.js | 2 +- .../doUpdateLotOccupancyOccupant.ts | 2 +- .../doUpdateLotOccupancyTransaction.js | 2 +- .../doUpdateLotOccupancyTransaction.ts | 2 +- handlers/dashboard-get/dashboard.js | 8 +- handlers/dashboard-get/dashboard.ts | 8 +- handlers/reports-get/search.js | 4 +- handlers/reports-get/search.ts | 4 +- .../doAddWorkOrderLotOccupancy.js | 6 +- .../doAddWorkOrderLotOccupancy.ts | 6 +- .../doDeleteWorkOrderLotOccupancy.js | 6 +- .../doDeleteWorkOrderLotOccupancy.ts | 6 +- handlers/workOrders-post/doUpdateLotStatus.js | 2 +- handlers/workOrders-post/doUpdateLotStatus.ts | 2 +- helpers/functions.cache.d.ts | 27 +- helpers/functions.cache.js | 185 +++++----- helpers/functions.cache.ts | 260 ++++++-------- helpers/functions.print.js | 12 +- helpers/functions.print.ts | 12 +- helpers/functions.sqlFilters.js | 8 +- helpers/functions.sqlFilters.ts | 8 +- public/html/adminFees-addFee.html | 4 +- public/html/adminFees-editFee.html | 4 +- .../html/adminLotTypes-addLotTypeField.html | 4 +- public/html/adminLotTypes-editLotType.html | 4 +- public/html/lot-editLotStatus.html | 4 +- public/html/lotOccupancy-selectLot.html | 10 +- public/html/workOrder-addLot.html | 4 +- public/javascripts/adminFees.js | 14 +- public/javascripts/adminFees.ts | 28 +- public/javascripts/adminLotTypes.js | 54 +-- public/javascripts/adminLotTypes.ts | 92 ++--- public/javascripts/adminOccupancyTypes.js | 16 +- public/javascripts/adminOccupancyTypes.ts | 196 +++++------ public/javascripts/adminTables.js | 12 +- public/javascripts/adminTables.ts | 12 +- public/javascripts/lotEdit.js | 16 +- public/javascripts/lotEdit.ts | 26 +- public/javascripts/lotOccupancyEdit.js | 8 +- public/javascripts/lotOccupancyEdit.ts | 146 ++++---- public/javascripts/lotOccupancySearch.ts | 24 +- public/javascripts/lotSearch.js | 2 +- public/javascripts/lotSearch.ts | 8 +- public/javascripts/main.ts | 14 +- public/javascripts/mapEdit.ts | 10 +- public/javascripts/mapSearch.ts | 8 +- public/javascripts/workOrderEdit.js | 22 +- public/javascripts/workOrderEdit.ts | 72 ++-- .../javascripts/workOrderMilestoneCalendar.ts | 2 +- public/javascripts/workOrderSearch.ts | 2 +- routes/burialSites.js | 30 +- routes/burialSites.ts | 32 +- routes/cemeteries.js | 2 +- routes/cemeteries.ts | 4 +- routes/contracts.js | 58 ++-- routes/contracts.ts | 60 ++-- temp/legacy.importFromCSV.js | 298 ++++++++-------- temp/legacy.importFromCSV.ts | 324 +++++++++--------- temp/legacy.importFromCsv.ids.d.ts | 22 +- temp/legacy.importFromCsv.ids.js | 38 +- temp/legacy.importFromCsv.ids.ts | 56 +-- temp/so.exportMaps.js | 4 +- temp/so.exportMaps.ts | 8 +- test/0_initializeDatabase.js | 8 +- test/0_initializeDatabase.ts | 10 +- test/functions.js | 53 +-- test/functions.ts | 73 +--- types/globalTypes.d.ts | 24 +- types/globalTypes.ts | 24 +- types/recordTypes.d.ts | 190 +++++----- types/recordTypes.ts | 197 ++++++----- ...lotTypes.ejs => admin-burialSiteTypes.ejs} | 0 ...pancyTypes.ejs => admin-contractTypes.ejs} | 6 +- views/{lot-edit.ejs => burialSite-edit.ejs} | 30 +- .../{lot-search.ejs => burialSite-search.ejs} | 12 +- views/{lot-view.ejs => burialSite-view.ejs} | 0 ...y-edit.ejs => burialSiteContract-edit.ejs} | 8 +- ...arch.ejs => burialSiteContract-search.ejs} | 6 +- ...y-view.ejs => burialSiteContract-view.ejs} | 8 +- views/{map-edit.ejs => cemetery-edit.ejs} | 4 +- views/{map-search.ejs => cemetery-search.ejs} | 0 views/{map-view.ejs => cemetery-view.ejs} | 4 +- .../screen/{lotOccupancy.ejs => contract.ejs} | 0 views/report-search.ejs | 16 +- 505 files changed, 6296 insertions(+), 6424 deletions(-) rename cypress/e2e/02-update/{maps.cy.d.ts => cemeteries.cy.d.ts} (100%) create mode 100644 cypress/e2e/02-update/cemeteries.cy.js create mode 100644 cypress/e2e/02-update/cemeteries.cy.ts delete mode 100644 cypress/e2e/02-update/maps.cy.js delete mode 100644 cypress/e2e/02-update/maps.cy.ts create mode 100644 cypress/fixtures/cemetery.json delete mode 100644 cypress/fixtures/map.json create mode 100644 database/addBurialSiteContract.d.ts create mode 100644 database/addBurialSiteContract.js create mode 100644 database/addBurialSiteContract.ts create mode 100644 database/addBurialSiteContractFee.d.ts rename database/{addLotOccupancyFee.js => addBurialSiteContractFee.js} (53%) rename database/{addLotOccupancyFee.ts => addBurialSiteContractFee.ts} (61%) create mode 100644 database/addBurialSiteContractFeeCategory.d.ts rename database/{addLotOccupancyFeeCategory.js => addBurialSiteContractFeeCategory.js} (53%) rename database/{addLotOccupancyFeeCategory.ts => addBurialSiteContractFeeCategory.ts} (61%) delete mode 100644 database/addLotOccupancy.d.ts delete mode 100644 database/addLotOccupancy.js delete mode 100644 database/addLotOccupancy.ts delete mode 100644 database/addLotOccupancyFee.d.ts delete mode 100644 database/addLotOccupancyFeeCategory.d.ts create mode 100644 database/copyBurialSiteContract.d.ts create mode 100644 database/copyBurialSiteContract.js create mode 100644 database/copyBurialSiteContract.ts delete mode 100644 database/copyLotOccupancy.d.ts delete mode 100644 database/copyLotOccupancy.js delete mode 100644 database/copyLotOccupancy.ts create mode 100644 database/getBurialSiteComments.d.ts rename database/{getLotComments.js => getBurialSiteComments.js} (50%) rename database/{getLotComments.ts => getBurialSiteComments.ts} (51%) create mode 100644 database/getBurialSiteContract.d.ts create mode 100644 database/getBurialSiteContract.js create mode 100644 database/getBurialSiteContract.ts create mode 100644 database/getBurialSiteContractComments.d.ts create mode 100644 database/getBurialSiteContractComments.js create mode 100644 database/getBurialSiteContractComments.ts create mode 100644 database/getBurialSiteContractFees.d.ts rename database/{getLotOccupancyFees.js => getBurialSiteContractFees.js} (62%) rename database/{getLotOccupancyFees.ts => getBurialSiteContractFees.ts} (59%) create mode 100644 database/getBurialSiteContractFields.d.ts create mode 100644 database/getBurialSiteContractFields.js create mode 100644 database/getBurialSiteContractFields.ts create mode 100644 database/getBurialSiteContractInterments.d.ts create mode 100644 database/getBurialSiteContractInterments.js create mode 100644 database/getBurialSiteContractInterments.ts create mode 100644 database/getBurialSiteContractTransactions.d.ts rename database/{getLotOccupancyTransactions.js => getBurialSiteContractTransactions.js} (81%) rename database/{getLotOccupancyTransactions.ts => getBurialSiteContractTransactions.ts} (77%) create mode 100644 database/getBurialSiteContracts.d.ts create mode 100644 database/getBurialSiteContracts.js create mode 100644 database/getBurialSiteContracts.ts create mode 100644 database/getBurialSiteFields.d.ts create mode 100644 database/getBurialSiteFields.js create mode 100644 database/getBurialSiteFields.ts create mode 100644 database/getBurialSiteStatusSummary.d.ts create mode 100644 database/getBurialSiteStatusSummary.js create mode 100644 database/getBurialSiteStatusSummary.ts create mode 100644 database/getBurialSiteStatuses.d.ts create mode 100644 database/getBurialSiteStatuses.js create mode 100644 database/getBurialSiteStatuses.ts create mode 100644 database/getBurialSiteTypeFields.d.ts create mode 100644 database/getBurialSiteTypeFields.js create mode 100644 database/getBurialSiteTypeFields.ts create mode 100644 database/getBurialSiteTypeSummary.d.ts create mode 100644 database/getBurialSiteTypeSummary.js create mode 100644 database/getBurialSiteTypeSummary.ts create mode 100644 database/getBurialSiteTypes.d.ts create mode 100644 database/getBurialSiteTypes.js create mode 100644 database/getBurialSiteTypes.ts create mode 100644 database/getBurialSites.d.ts create mode 100644 database/getBurialSites.js create mode 100644 database/getBurialSites.ts create mode 100644 database/getCemeteries.d.ts create mode 100644 database/getCemeteries.js create mode 100644 database/getCemeteries.ts create mode 100644 database/getCemetery.d.ts create mode 100644 database/getCemetery.js create mode 100644 database/getCemetery.ts create mode 100644 database/getContractTypeFields.d.ts create mode 100644 database/getContractTypeFields.js create mode 100644 database/getContractTypeFields.ts create mode 100644 database/getContractTypePrints.d.ts rename database/{getOccupancyTypePrints.js => getContractTypePrints.js} (73%) rename database/{getOccupancyTypePrints.ts => getContractTypePrints.ts} (75%) create mode 100644 database/getContractTypes.d.ts create mode 100644 database/getContractTypes.js create mode 100644 database/getContractTypes.ts delete mode 100644 database/getLotComments.d.ts delete mode 100644 database/getLotFields.d.ts delete mode 100644 database/getLotFields.js delete mode 100644 database/getLotFields.ts delete mode 100644 database/getLotOccupancies.d.ts delete mode 100644 database/getLotOccupancies.js delete mode 100644 database/getLotOccupancies.ts delete mode 100644 database/getLotOccupancy.d.ts delete mode 100644 database/getLotOccupancy.js delete mode 100644 database/getLotOccupancy.ts delete mode 100644 database/getLotOccupancyComments.d.ts delete mode 100644 database/getLotOccupancyComments.js delete mode 100644 database/getLotOccupancyComments.ts delete mode 100644 database/getLotOccupancyFees.d.ts delete mode 100644 database/getLotOccupancyFields.d.ts delete mode 100644 database/getLotOccupancyFields.js delete mode 100644 database/getLotOccupancyFields.ts delete mode 100644 database/getLotOccupancyOccupants.d.ts delete mode 100644 database/getLotOccupancyOccupants.js delete mode 100644 database/getLotOccupancyOccupants.ts delete mode 100644 database/getLotOccupancyTransactions.d.ts delete mode 100644 database/getLotOccupantTypes.d.ts delete mode 100644 database/getLotOccupantTypes.js delete mode 100644 database/getLotOccupantTypes.ts delete mode 100644 database/getLotStatusSummary.d.ts delete mode 100644 database/getLotStatusSummary.js delete mode 100644 database/getLotStatusSummary.ts delete mode 100644 database/getLotStatuses.d.ts delete mode 100644 database/getLotStatuses.js delete mode 100644 database/getLotStatuses.ts delete mode 100644 database/getLotTypeFields.d.ts delete mode 100644 database/getLotTypeFields.js delete mode 100644 database/getLotTypeFields.ts delete mode 100644 database/getLotTypeSummary.d.ts delete mode 100644 database/getLotTypeSummary.js delete mode 100644 database/getLotTypeSummary.ts delete mode 100644 database/getLotTypes.d.ts delete mode 100644 database/getLotTypes.js delete mode 100644 database/getLotTypes.ts delete mode 100644 database/getLots.d.ts delete mode 100644 database/getLots.js delete mode 100644 database/getLots.ts delete mode 100644 database/getMap.d.ts delete mode 100644 database/getMap.js delete mode 100644 database/getMap.ts delete mode 100644 database/getMaps.d.ts delete mode 100644 database/getMaps.js delete mode 100644 database/getMaps.ts create mode 100644 database/getNextCemeteryId.d.ts create mode 100644 database/getNextCemeteryId.js create mode 100644 database/getNextCemeteryId.ts delete mode 100644 database/getNextMapId.d.ts delete mode 100644 database/getNextMapId.js delete mode 100644 database/getNextMapId.ts delete mode 100644 database/getOccupancyTypeFields.d.ts delete mode 100644 database/getOccupancyTypeFields.js delete mode 100644 database/getOccupancyTypeFields.ts delete mode 100644 database/getOccupancyTypePrints.d.ts delete mode 100644 database/getOccupancyTypes.d.ts delete mode 100644 database/getOccupancyTypes.js delete mode 100644 database/getOccupancyTypes.ts create mode 100644 database/getPreviousCemeteryId.d.ts create mode 100644 database/getPreviousCemeteryId.js create mode 100644 database/getPreviousCemeteryId.ts delete mode 100644 database/getPreviousMapId.d.ts delete mode 100644 database/getPreviousMapId.js delete mode 100644 database/getPreviousMapId.ts create mode 100644 database/moveBurialSiteTypeField.d.ts create mode 100644 database/moveBurialSiteTypeField.js create mode 100644 database/moveBurialSiteTypeField.ts create mode 100644 database/moveContractTypeField.d.ts create mode 100644 database/moveContractTypeField.js rename database/{moveOccupancyTypeField.ts => moveContractTypeField.ts} (51%) delete mode 100644 database/moveLotTypeField.d.ts delete mode 100644 database/moveLotTypeField.js delete mode 100644 database/moveLotTypeField.ts delete mode 100644 database/moveOccupancyTypeField.d.ts delete mode 100644 database/moveOccupancyTypeField.js create mode 100644 database/updateBurialSite.d.ts create mode 100644 database/updateBurialSite.js create mode 100644 database/updateBurialSite.ts create mode 100644 database/updateBurialSiteComment.d.ts create mode 100644 database/updateBurialSiteComment.js create mode 100644 database/updateBurialSiteComment.ts create mode 100644 database/updateBurialSiteContract.d.ts create mode 100644 database/updateBurialSiteContract.js create mode 100644 database/updateBurialSiteContract.ts create mode 100644 database/updateBurialSiteContractComment.d.ts create mode 100644 database/updateBurialSiteContractComment.js create mode 100644 database/updateBurialSiteContractComment.ts create mode 100644 database/updateBurialSiteContractFeeQuantity.d.ts rename database/{updateLotOccupancyFeeQuantity.js => updateBurialSiteContractFeeQuantity.js} (63%) rename database/{updateLotOccupancyFeeQuantity.ts => updateBurialSiteContractFeeQuantity.ts} (64%) rename database/{updateLotOccupancyTransaction.d.ts => updateBurialSiteContractTransaction.d.ts} (54%) create mode 100644 database/updateBurialSiteContractTransaction.js rename database/{updateLotOccupancyTransaction.ts => updateBurialSiteContractTransaction.ts} (56%) create mode 100644 database/updateBurialSiteTypeField.d.ts create mode 100644 database/updateBurialSiteTypeField.js create mode 100644 database/updateBurialSiteTypeField.ts create mode 100644 database/updateCemetery.d.ts create mode 100644 database/updateCemetery.js create mode 100644 database/updateCemetery.ts create mode 100644 database/updateContractTypeField.d.ts create mode 100644 database/updateContractTypeField.js create mode 100644 database/updateContractTypeField.ts delete mode 100644 database/updateLot.d.ts delete mode 100644 database/updateLot.js delete mode 100644 database/updateLot.ts delete mode 100644 database/updateLotComment.d.ts delete mode 100644 database/updateLotComment.js delete mode 100644 database/updateLotComment.ts delete mode 100644 database/updateLotOccupancy.d.ts delete mode 100644 database/updateLotOccupancy.js delete mode 100644 database/updateLotOccupancy.ts delete mode 100644 database/updateLotOccupancyComment.d.ts delete mode 100644 database/updateLotOccupancyComment.js delete mode 100644 database/updateLotOccupancyComment.ts delete mode 100644 database/updateLotOccupancyFeeQuantity.d.ts delete mode 100644 database/updateLotOccupancyTransaction.js delete mode 100644 database/updateLotOccupantType.d.ts delete mode 100644 database/updateLotOccupantType.js delete mode 100644 database/updateLotOccupantType.ts delete mode 100644 database/updateLotTypeField.d.ts delete mode 100644 database/updateLotTypeField.js delete mode 100644 database/updateLotTypeField.ts delete mode 100644 database/updateMap.d.ts delete mode 100644 database/updateMap.js delete mode 100644 database/updateMap.ts delete mode 100644 database/updateOccupancyTypeField.d.ts delete mode 100644 database/updateOccupancyTypeField.js delete mode 100644 database/updateOccupancyTypeField.ts rename views/{admin-lotTypes.ejs => admin-burialSiteTypes.ejs} (100%) rename views/{admin-occupancyTypes.ejs => admin-contractTypes.ejs} (94%) rename views/{lot-edit.ejs => burialSite-edit.ejs} (93%) rename views/{lot-search.ejs => burialSite-search.ejs} (86%) rename views/{lot-view.ejs => burialSite-view.ejs} (100%) rename views/{lotOccupancy-edit.ejs => burialSiteContract-edit.ejs} (98%) rename views/{lotOccupancy-search.ejs => burialSiteContract-search.ejs} (95%) rename views/{lotOccupancy-view.ejs => burialSiteContract-view.ejs} (98%) rename views/{map-edit.ejs => cemetery-edit.ejs} (98%) rename views/{map-search.ejs => cemetery-search.ejs} (100%) rename views/{map-view.ejs => cemetery-view.ejs} (97%) rename views/print/screen/{lotOccupancy.ejs => contract.ejs} (100%) diff --git a/app.js b/app.js index 3e8d577c..831a95e3 100644 --- a/app.js +++ b/app.js @@ -9,20 +9,20 @@ import rateLimit from 'express-rate-limit'; import session from 'express-session'; import createError from 'http-errors'; import FileStore from 'session-file-store'; -import { useTestDatabases } from './data/databasePaths.js'; +import { initializeDatabase } from './database/initializeDatabase.js'; import { DEBUG_NAMESPACE } from './debug.config.js'; import * as permissionHandlers from './handlers/permissions.js'; -import { getSafeRedirectURL } from './helpers/functions.authentication.js'; import * as configFunctions from './helpers/config.helpers.js'; +import { useTestDatabases } from './helpers/database.helpers.js'; +import { getSafeRedirectURL } from './helpers/functions.authentication.js'; import * as printFunctions from './helpers/functions.print.js'; -import { initializeDatabase } from './helpers/helpers.database.js'; import routerAdmin from './routes/admin.js'; import routerApi from './routes/api.js'; +import routerBurialSites from './routes/burialSites.js'; +import routerCemeteries from './routes/cemeteries.js'; +import routerContracts from './routes/contracts.js'; import routerDashboard from './routes/dashboard.js'; import routerLogin from './routes/login.js'; -import routerLotOccupancies from './routes/lotOccupancies.js'; -import routerLots from './routes/lots.js'; -import routerMaps from './routes/maps.js'; import routerPrint from './routes/print.js'; import routerReports from './routes/reports.js'; import routerWorkOrders from './routes/workOrders.js'; @@ -140,9 +140,9 @@ app.get(`${urlPrefix}/`, sessionChecker, (_request, response) => { app.use(`${urlPrefix}/dashboard`, sessionChecker, routerDashboard); app.use(`${urlPrefix}/api/:apiKey`, permissionHandlers.apiGetHandler, routerApi); app.use(`${urlPrefix}/print`, sessionChecker, routerPrint); -app.use(`${urlPrefix}/maps`, sessionChecker, routerMaps); -app.use(`${urlPrefix}/lots`, sessionChecker, routerLots); -app.use(`${urlPrefix}/lotOccupancies`, sessionChecker, routerLotOccupancies); +app.use(`${urlPrefix}/cemeteries`, sessionChecker, routerCemeteries); +app.use(`${urlPrefix}/burialSites`, sessionChecker, routerBurialSites); +app.use(`${urlPrefix}/contracts`, sessionChecker, routerContracts); app.use(`${urlPrefix}/workOrders`, sessionChecker, routerWorkOrders); app.use(`${urlPrefix}/reports`, sessionChecker, routerReports); app.use(`${urlPrefix}/admin`, sessionChecker, permissionHandlers.adminGetHandler, routerAdmin); diff --git a/app.ts b/app.ts index 91831643..5e2f85df 100644 --- a/app.ts +++ b/app.ts @@ -11,20 +11,20 @@ import session from 'express-session' import createError from 'http-errors' import FileStore from 'session-file-store' -import { useTestDatabases } from './data/databasePaths.js' +import { initializeDatabase } from './database/initializeDatabase.js' import { DEBUG_NAMESPACE } from './debug.config.js' import * as permissionHandlers from './handlers/permissions.js' -import { getSafeRedirectURL } from './helpers/functions.authentication.js' import * as configFunctions from './helpers/config.helpers.js' +import { useTestDatabases } from './helpers/database.helpers.js' +import { getSafeRedirectURL } from './helpers/functions.authentication.js' import * as printFunctions from './helpers/functions.print.js' -import { initializeDatabase } from './helpers/helpers.database.js' import routerAdmin from './routes/admin.js' import routerApi from './routes/api.js' +import routerBurialSites from './routes/burialSites.js' +import routerCemeteries from './routes/cemeteries.js' +import routerContracts from './routes/contracts.js' import routerDashboard from './routes/dashboard.js' import routerLogin from './routes/login.js' -import routerLotOccupancies from './routes/lotOccupancies.js' -import routerLots from './routes/lots.js' -import routerMaps from './routes/maps.js' import routerPrint from './routes/print.js' import routerReports from './routes/reports.js' import routerWorkOrders from './routes/workOrders.js' @@ -231,9 +231,9 @@ app.use(`${urlPrefix}/dashboard`, sessionChecker, routerDashboard) app.use(`${urlPrefix}/api/:apiKey`, permissionHandlers.apiGetHandler, routerApi) app.use(`${urlPrefix}/print`, sessionChecker, routerPrint) -app.use(`${urlPrefix}/maps`, sessionChecker, routerMaps) -app.use(`${urlPrefix}/lots`, sessionChecker, routerLots) -app.use(`${urlPrefix}/lotOccupancies`, sessionChecker, routerLotOccupancies) +app.use(`${urlPrefix}/cemeteries`, sessionChecker, routerCemeteries) +app.use(`${urlPrefix}/burialSites`, sessionChecker, routerBurialSites) +app.use(`${urlPrefix}/contracts`, sessionChecker, routerContracts) app.use(`${urlPrefix}/workOrders`, sessionChecker, routerWorkOrders) app.use(`${urlPrefix}/reports`, sessionChecker, routerReports) diff --git a/cypress/e2e/02-update/maps.cy.d.ts b/cypress/e2e/02-update/cemeteries.cy.d.ts similarity index 100% rename from cypress/e2e/02-update/maps.cy.d.ts rename to cypress/e2e/02-update/cemeteries.cy.d.ts diff --git a/cypress/e2e/02-update/cemeteries.cy.js b/cypress/e2e/02-update/cemeteries.cy.js new file mode 100644 index 00000000..f45c7f6a --- /dev/null +++ b/cypress/e2e/02-update/cemeteries.cy.js @@ -0,0 +1,69 @@ +import { getConfigProperty } from '../../../helpers/config.helpers.js'; +import { testUpdate } from '../../../test/_globals.js'; +import { login, logout } from '../../support/index.js'; +describe('Update - Cemeteries', () => { + beforeEach('Loads page', () => { + logout(); + login(testUpdate); + }); + afterEach(logout); + it('Has a "Create" link on the Cemetery Search', () => { + cy.visit('/cemeteries'); + cy.location('pathname').should('equal', '/cemeteries'); + cy.get("a[href$='/cemeteries/new']").should('exist'); + }); + it('Creates a new cemetery', () => { + cy.visit('/cemeteries/new'); + cy.log('Check the accessibility'); + cy.injectAxe(); + cy.checkA11y(); + cy.log('Populate the fields'); + cy.fixture('cemetery.json').then((cemeteryData) => { + cy.get("input[name='cemeteryName']") + .clear() + .type(cemeteryData.cemeteryName ?? ''); + cy.get("textarea[name='cemeteryDescription']") + .clear() + .type(cemeteryData.cemeteryDescription ?? ''); + cy.get("input[name='cemeteryAddress1']") + .clear() + .type(cemeteryData.cemeteryAddress1 ?? ''); + cy.get("input[name='cemeteryAddress2']") + .clear() + .type(cemeteryData.cemeteryAddress2 ?? ''); + cy.get("input[name='cemeteryPostalCode']") + .clear() + .type(cemeteryData.cemeteryPostalCode ?? ''); + cy.get("input[name='cemeteryPhoneNumber']") + .clear() + .type(cemeteryData.cemeteryPhoneNumber ?? ''); + cy.get("input[name='cemeteryLatitude']") + .clear() + .type(cemeteryData.cemeteryLatitude?.toString() ?? ''); + cy.get("input[name='cemeteryLongitude']") + .clear() + .type(cemeteryData.cemeteryLongitude?.toString() ?? ''); + }); + cy.log('Ensure the default city and province are used'); + cy.get("input[name='cemeteryCity']").should('have.value', getConfigProperty('settings.cemeteries.cityDefault')); + cy.get("input[name='cemeteryProvince']").should('have.value', getConfigProperty('settings.cemeteries.provinceDefault')); + cy.log('Submit the form'); + cy.get('#form--cemetery').submit(); + cy.wait(1000); + cy.location('pathname') + .should('not.contain', '/new') + .should('contain', '/edit'); + cy.fixture('cemetery.json').then((cemeteryData) => { + cy.get("input[name='cemeteryName']").should('have.value', cemeteryData.cemeteryName); + cy.get("textarea[name='cemeteryDescription']").should('have.value', cemeteryData.cemeteryDescription); + cy.get("input[name='cemeteryAddress1']").should('have.value', cemeteryData.cemeteryAddress1); + cy.get("input[name='cemeteryAddress2']").should('have.value', cemeteryData.cemeteryAddress2); + cy.get("input[name='cemeteryCity']").should('have.value', getConfigProperty('settings.cemeteries.cityDefault')); + cy.get("input[name='cemeteryProvince']").should('have.value', getConfigProperty('settings.cemeteries.provinceDefault')); + cy.get("input[name='cemeteryPostalCode']").should('have.value', cemeteryData.cemeteryPostalCode); + cy.get("input[name='cemeteryPhoneNumber']").should('have.value', cemeteryData.cemeteryPhoneNumber); + cy.get("input[name='cemeteryLatitude']").should('have.value', cemeteryData.cemeteryLatitude?.toString()); + cy.get("input[name='cemeteryLongitude']").should('have.value', cemeteryData.cemeteryLongitude?.toString()); + }); + }); +}); diff --git a/cypress/e2e/02-update/cemeteries.cy.ts b/cypress/e2e/02-update/cemeteries.cy.ts new file mode 100644 index 00000000..9c89de78 --- /dev/null +++ b/cypress/e2e/02-update/cemeteries.cy.ts @@ -0,0 +1,138 @@ +import { getConfigProperty } from '../../../helpers/config.helpers.js' +import { testUpdate } from '../../../test/_globals.js' +import type { Cemetery } from '../../../types/recordTypes.js' +import { login, logout } from '../../support/index.js' + +describe('Update - Cemeteries', () => { + beforeEach('Loads page', () => { + logout() + login(testUpdate) + }) + + afterEach(logout) + + it('Has a "Create" link on the Cemetery Search', () => { + cy.visit('/cemeteries') + cy.location('pathname').should('equal', '/cemeteries') + cy.get("a[href$='/cemeteries/new']").should('exist') + }) + + it('Creates a new cemetery', () => { + cy.visit('/cemeteries/new') + + cy.log('Check the accessibility') + + cy.injectAxe() + cy.checkA11y() + + cy.log('Populate the fields') + + cy.fixture('cemetery.json').then((cemeteryData: Cemetery) => { + cy.get("input[name='cemeteryName']") + .clear() + .type(cemeteryData.cemeteryName ?? '') + + cy.get("textarea[name='cemeteryDescription']") + .clear() + .type(cemeteryData.cemeteryDescription ?? '') + + cy.get("input[name='cemeteryAddress1']") + .clear() + .type(cemeteryData.cemeteryAddress1 ?? '') + + cy.get("input[name='cemeteryAddress2']") + .clear() + .type(cemeteryData.cemeteryAddress2 ?? '') + + cy.get("input[name='cemeteryPostalCode']") + .clear() + .type(cemeteryData.cemeteryPostalCode ?? '') + + cy.get("input[name='cemeteryPhoneNumber']") + .clear() + .type(cemeteryData.cemeteryPhoneNumber ?? '') + + cy.get("input[name='cemeteryLatitude']") + .clear() + .type(cemeteryData.cemeteryLatitude?.toString() ?? '') + + cy.get("input[name='cemeteryLongitude']") + .clear() + .type(cemeteryData.cemeteryLongitude?.toString() ?? '') + }) + + cy.log('Ensure the default city and province are used') + + cy.get("input[name='cemeteryCity']").should( + 'have.value', + getConfigProperty('settings.cemeteries.cityDefault') + ) + + cy.get("input[name='cemeteryProvince']").should( + 'have.value', + getConfigProperty('settings.cemeteries.provinceDefault') + ) + + cy.log('Submit the form') + + cy.get('#form--cemetery').submit() + + cy.wait(1000) + + cy.location('pathname') + .should('not.contain', '/new') + .should('contain', '/edit') + + cy.fixture('cemetery.json').then((cemeteryData: Cemetery) => { + cy.get("input[name='cemeteryName']").should( + 'have.value', + cemeteryData.cemeteryName + ) + + cy.get("textarea[name='cemeteryDescription']").should( + 'have.value', + cemeteryData.cemeteryDescription + ) + + cy.get("input[name='cemeteryAddress1']").should( + 'have.value', + cemeteryData.cemeteryAddress1 + ) + + cy.get("input[name='cemeteryAddress2']").should( + 'have.value', + cemeteryData.cemeteryAddress2 + ) + + cy.get("input[name='cemeteryCity']").should( + 'have.value', + getConfigProperty('settings.cemeteries.cityDefault') + ) + + cy.get("input[name='cemeteryProvince']").should( + 'have.value', + getConfigProperty('settings.cemeteries.provinceDefault') + ) + + cy.get("input[name='cemeteryPostalCode']").should( + 'have.value', + cemeteryData.cemeteryPostalCode + ) + + cy.get("input[name='cemeteryPhoneNumber']").should( + 'have.value', + cemeteryData.cemeteryPhoneNumber + ) + + cy.get("input[name='cemeteryLatitude']").should( + 'have.value', + cemeteryData.cemeteryLatitude?.toString() + ) + + cy.get("input[name='cemeteryLongitude']").should( + 'have.value', + cemeteryData.cemeteryLongitude?.toString() + ) + }) + }) +}) diff --git a/cypress/e2e/02-update/maps.cy.js b/cypress/e2e/02-update/maps.cy.js deleted file mode 100644 index f8c424d9..00000000 --- a/cypress/e2e/02-update/maps.cy.js +++ /dev/null @@ -1,71 +0,0 @@ -import { getConfigProperty } from '../../../helpers/config.helpers.js'; -import { testUpdate } from '../../../test/_globals.js'; -import { login, logout } from '../../support/index.js'; -describe('Update - Maps', () => { - beforeEach('Loads page', () => { - logout(); - login(testUpdate); - }); - afterEach(logout); - it('Has a "Create" link on the Map Search', () => { - cy.visit('/maps'); - cy.location('pathname').should('equal', '/maps'); - cy.get("a[href$='/maps/new']").should('exist'); - }); - it('Creates a new map', () => { - cy.visit('/maps/new'); - cy.log('Check the accessibility'); - cy.injectAxe(); - cy.checkA11y(); - cy.log('Populate the fields'); - // eslint-disable-next-line promise/catch-or-return, promise/always-return - cy.fixture('map.json').then((mapJSON) => { - cy.get("input[name='mapName']") - .clear() - .type(mapJSON.mapName ?? ''); - cy.get("textarea[name='mapDescription']") - .clear() - .type(mapJSON.mapDescription ?? ''); - cy.get("input[name='mapAddress1']") - .clear() - .type(mapJSON.mapAddress1 ?? ''); - cy.get("input[name='mapAddress2']") - .clear() - .type(mapJSON.mapAddress2 ?? ''); - cy.get("input[name='mapPostalCode']") - .clear() - .type(mapJSON.mapPostalCode ?? ''); - cy.get("input[name='mapPhoneNumber']") - .clear() - .type(mapJSON.mapPhoneNumber ?? ''); - cy.get("input[name='mapLatitude']") - .clear() - .type(mapJSON.mapLatitude?.toString() ?? ''); - cy.get("input[name='mapLongitude']") - .clear() - .type(mapJSON.mapLongitude?.toString() ?? ''); - }); - cy.log('Ensure the default city and province are used'); - cy.get("input[name='mapCity']").should('have.value', getConfigProperty('settings.map.mapCityDefault')); - cy.get("input[name='mapProvince']").should('have.value', getConfigProperty('settings.map.mapProvinceDefault')); - cy.log('Submit the form'); - cy.get('#form--map').submit(); - cy.wait(1000); - cy.location('pathname') - .should('not.contain', '/new') - .should('contain', '/edit'); - // eslint-disable-next-line promise/catch-or-return, promise/always-return - cy.fixture('map.json').then((mapJSON) => { - cy.get("input[name='mapName']").should('have.value', mapJSON.mapName); - cy.get("textarea[name='mapDescription']").should('have.value', mapJSON.mapDescription); - cy.get("input[name='mapAddress1']").should('have.value', mapJSON.mapAddress1); - cy.get("input[name='mapAddress2']").should('have.value', mapJSON.mapAddress2); - cy.get("input[name='mapCity']").should('have.value', getConfigProperty('settings.map.mapCityDefault')); - cy.get("input[name='mapProvince']").should('have.value', getConfigProperty('settings.map.mapProvinceDefault')); - cy.get("input[name='mapPostalCode']").should('have.value', mapJSON.mapPostalCode); - cy.get("input[name='mapPhoneNumber']").should('have.value', mapJSON.mapPhoneNumber); - cy.get("input[name='mapLatitude']").should('have.value', mapJSON.mapLatitude?.toString()); - cy.get("input[name='mapLongitude']").should('have.value', mapJSON.mapLongitude?.toString()); - }); - }); -}); diff --git a/cypress/e2e/02-update/maps.cy.ts b/cypress/e2e/02-update/maps.cy.ts deleted file mode 100644 index 903b1a35..00000000 --- a/cypress/e2e/02-update/maps.cy.ts +++ /dev/null @@ -1,127 +0,0 @@ -import { getConfigProperty } from '../../../helpers/config.helpers.js' -import { testUpdate } from '../../../test/_globals.js' -import type { MapRecord } from '../../../types/recordTypes.js' -import { login, logout } from '../../support/index.js' - -describe('Update - Maps', () => { - beforeEach('Loads page', () => { - logout() - login(testUpdate) - }) - - afterEach(logout) - - it('Has a "Create" link on the Map Search', () => { - cy.visit('/maps') - cy.location('pathname').should('equal', '/maps') - cy.get("a[href$='/maps/new']").should('exist') - }) - - it('Creates a new map', () => { - cy.visit('/maps/new') - - cy.log('Check the accessibility') - - cy.injectAxe() - cy.checkA11y() - - cy.log('Populate the fields') - - // eslint-disable-next-line promise/catch-or-return, promise/always-return - cy.fixture('map.json').then((mapJSON: MapRecord) => { - cy.get("input[name='mapName']") - .clear() - .type(mapJSON.mapName ?? '') - cy.get("textarea[name='mapDescription']") - .clear() - .type(mapJSON.mapDescription ?? '') - - cy.get("input[name='mapAddress1']") - .clear() - .type(mapJSON.mapAddress1 ?? '') - cy.get("input[name='mapAddress2']") - .clear() - .type(mapJSON.mapAddress2 ?? '') - cy.get("input[name='mapPostalCode']") - .clear() - .type(mapJSON.mapPostalCode ?? '') - cy.get("input[name='mapPhoneNumber']") - .clear() - .type(mapJSON.mapPhoneNumber ?? '') - - cy.get("input[name='mapLatitude']") - .clear() - .type(mapJSON.mapLatitude?.toString() ?? '') - cy.get("input[name='mapLongitude']") - .clear() - .type(mapJSON.mapLongitude?.toString() ?? '') - }) - - cy.log('Ensure the default city and province are used') - - cy.get("input[name='mapCity']").should( - 'have.value', - getConfigProperty('settings.map.mapCityDefault') - ) - - cy.get("input[name='mapProvince']").should( - 'have.value', - getConfigProperty('settings.map.mapProvinceDefault') - ) - - cy.log('Submit the form') - - cy.get('#form--map').submit() - - cy.wait(1000) - - cy.location('pathname') - .should('not.contain', '/new') - .should('contain', '/edit') - - // eslint-disable-next-line promise/catch-or-return, promise/always-return - cy.fixture('map.json').then((mapJSON: MapRecord) => { - cy.get("input[name='mapName']").should('have.value', mapJSON.mapName) - cy.get("textarea[name='mapDescription']").should( - 'have.value', - mapJSON.mapDescription - ) - - cy.get("input[name='mapAddress1']").should( - 'have.value', - mapJSON.mapAddress1 - ) - cy.get("input[name='mapAddress2']").should( - 'have.value', - mapJSON.mapAddress2 - ) - - cy.get("input[name='mapCity']").should( - 'have.value', - getConfigProperty('settings.map.mapCityDefault') - ) - cy.get("input[name='mapProvince']").should( - 'have.value', - getConfigProperty('settings.map.mapProvinceDefault') - ) - - cy.get("input[name='mapPostalCode']").should( - 'have.value', - mapJSON.mapPostalCode - ) - cy.get("input[name='mapPhoneNumber']").should( - 'have.value', - mapJSON.mapPhoneNumber - ) - - cy.get("input[name='mapLatitude']").should( - 'have.value', - mapJSON.mapLatitude?.toString() - ) - cy.get("input[name='mapLongitude']").should( - 'have.value', - mapJSON.mapLongitude?.toString() - ) - }) - }) -}) diff --git a/cypress/fixtures/cemetery.json b/cypress/fixtures/cemetery.json new file mode 100644 index 00000000..559eb735 --- /dev/null +++ b/cypress/fixtures/cemetery.json @@ -0,0 +1,10 @@ +{ + "cemeteryName": "Cypress Test - Holy Sepulchre", + "cemeteryDescription": "Operated by the City of Sault Ste. Marie", + "cemeteryAddress1": "Fourth Line and Peoples Road", + "cemeteryAddress2": "27 Fourth Line East", + "cemeteryPostalCode": "P6A 5K8", + "cemeteryPhoneNumber": "705-759-5336", + "cemeteryLatitude": 46.56874795, + "cemeteryLongitude": -84.34842824 +} diff --git a/cypress/fixtures/map.json b/cypress/fixtures/map.json deleted file mode 100644 index e14b5e8a..00000000 --- a/cypress/fixtures/map.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "mapName": "Cypress Test - Holy Sepulchre", - "mapDescription": "Operated by the City of Sault Ste. Marie", - "mapAddress1": "Fourth Line and Peoples Road", - "mapAddress2": "27 Fourth Line East", - "mapPostalCode": "P6A 5K8", - "mapPhoneNumber": "705-759-5336", - "mapLatitude": 46.56874795, - "mapLongitude": -84.34842824 -} diff --git a/data/config.defaultValues.d.ts b/data/config.defaultValues.d.ts index df329499..57144314 100644 --- a/data/config.defaultValues.d.ts +++ b/data/config.defaultValues.d.ts @@ -24,15 +24,12 @@ export declare const configDefaultValues: { 'aliases.externalReceiptNumber': string; 'aliases.workOrderOpenDate': string; 'aliases.workOrderCloseDate': string; - 'settings.map.mapCityDefault': string; - 'settings.map.mapProvinceDefault': string; - 'settings.lot.lotNamePattern': RegExp | undefined; - 'settings.lot.lotNameHelpText': string; - 'settings.lot.lotNameSortNameFunction': (lotName: string) => string; - 'settings.lotOccupancy.occupancyEndDateIsRequired': boolean; - 'settings.lotOccupancy.occupantCityDefault': string; - 'settings.lotOccupancy.occupantProvinceDefault': string; - 'settings.lotOccupancy.prints': string[]; + 'settings.cemeteries.cityDefault': string; + 'settings.cemeteries.provinceDefault': string; + 'settings.contracts.burialSiteIdIsRequired': boolean; + 'settings.contracts.cityDefault': string; + 'settings.contracts.provinceDefault': string; + 'settings.contracts.prints': string[]; 'settings.fees.taxPercentageDefault': number; 'settings.workOrders.workOrderNumberLength': number; 'settings.workOrders.workOrderMilestoneDateRecentBeforeDays': number; diff --git a/data/config.defaultValues.js b/data/config.defaultValues.js index 1ab54e3d..a629f823 100644 --- a/data/config.defaultValues.js +++ b/data/config.defaultValues.js @@ -23,16 +23,12 @@ export const configDefaultValues = { 'aliases.externalReceiptNumber': 'External Receipt Number', 'aliases.workOrderOpenDate': 'Order Date', 'aliases.workOrderCloseDate': 'Completion Date', - 'settings.map.mapCityDefault': '', - 'settings.map.mapProvinceDefault': '', - 'settings.lot.lotNamePattern': undefined, - 'settings.lot.lotNameHelpText': '', - 'settings.lot.lotNameSortNameFunction': (lotName) => lotName, - // eslint-disable-next-line no-secrets/no-secrets - 'settings.lotOccupancy.occupancyEndDateIsRequired': true, - 'settings.lotOccupancy.occupantCityDefault': '', - 'settings.lotOccupancy.occupantProvinceDefault': '', - 'settings.lotOccupancy.prints': ['screen/lotOccupancy'], + 'settings.cemeteries.cityDefault': '', + 'settings.cemeteries.provinceDefault': '', + 'settings.contracts.burialSiteIdIsRequired': true, + 'settings.contracts.cityDefault': '', + 'settings.contracts.provinceDefault': '', + 'settings.contracts.prints': ['screen/contract'], 'settings.fees.taxPercentageDefault': 0, 'settings.workOrders.workOrderNumberLength': 6, 'settings.workOrders.workOrderMilestoneDateRecentBeforeDays': 5, diff --git a/data/config.defaultValues.ts b/data/config.defaultValues.ts index ebeb330d..2912809f 100644 --- a/data/config.defaultValues.ts +++ b/data/config.defaultValues.ts @@ -38,17 +38,13 @@ export const configDefaultValues = { 'aliases.workOrderOpenDate': 'Order Date', 'aliases.workOrderCloseDate': 'Completion Date', - 'settings.map.mapCityDefault': '', - 'settings.map.mapProvinceDefault': '', + 'settings.cemeteries.cityDefault': '', + 'settings.cemeteries.provinceDefault': '', - 'settings.lot.lotNamePattern': undefined as RegExp | undefined, - 'settings.lot.lotNameHelpText': '', - 'settings.lot.lotNameSortNameFunction': (lotName: string) => lotName, - // eslint-disable-next-line no-secrets/no-secrets - 'settings.lotOccupancy.occupancyEndDateIsRequired': true, - 'settings.lotOccupancy.occupantCityDefault': '', - 'settings.lotOccupancy.occupantProvinceDefault': '', - 'settings.lotOccupancy.prints': ['screen/lotOccupancy'], + 'settings.contracts.burialSiteIdIsRequired': true, + 'settings.contracts.cityDefault': '', + 'settings.contracts.provinceDefault': '', + 'settings.contracts.prints': ['screen/contract'], 'settings.fees.taxPercentageDefault': 0, diff --git a/database/addBurialSite.d.ts b/database/addBurialSite.d.ts index 3594fb49..e01f6910 100644 --- a/database/addBurialSite.d.ts +++ b/database/addBurialSite.d.ts @@ -1,12 +1,16 @@ -export interface AddLotForm { - lotName: string; - lotTypeId: string | number; - lotStatusId: string | number; - mapId: string | number; - mapKey: string; - lotLatitude: string; - lotLongitude: string; - lotTypeFieldIds?: string; - [lotFieldValue_lotTypeFieldId: string]: unknown; +export interface AddBurialSiteForm { + burialSiteNameSegment1: string; + burialSiteNameSegment2?: string; + burialSiteNameSegment3?: string; + burialSiteNameSegment4?: string; + burialSiteNameSegment5?: string; + burialSiteTypeId: string | number; + burialSiteStatusId: string | number; + cemeteryId: string | number; + cemeterySvgId: string; + burialSiteLatitude: string; + burialSiteLongitude: string; + burialSiteTypeFieldIds?: string; + [fieldValue_burialSiteTypeFieldId: string]: unknown; } -export default function addLot(lotForm: AddLotForm, user: User): Promise; +export default function addLot(burialSiteForm: AddBurialSiteForm, user: User): Promise; diff --git a/database/addBurialSite.js b/database/addBurialSite.js index 571c6a50..db2724a4 100644 --- a/database/addBurialSite.js +++ b/database/addBurialSite.js @@ -1,29 +1,37 @@ -import addOrUpdateLotField from './addOrUpdateLotField.js'; +import addOrUpdateBurialSiteField from './addOrUpdateBurialSiteField.js'; import { acquireConnection } from './pool.js'; -export default async function addLot(lotForm, user) { +export default async function addLot(burialSiteForm, user) { const database = await acquireConnection(); const rightNowMillis = Date.now(); const result = database - .prepare(`insert into Lots ( - lotName, lotTypeId, lotStatusId, - mapId, mapKey, - lotLatitude, lotLongitude, + .prepare(`insert into BurialSites ( + burialSiteNameSegment1, + burialSiteNameSegment2, + burialSiteNameSegment3, + burialSiteNameSegment4, + burialSiteNameSegment5, + burialSiteTypeId, burialSiteStatusId, + cemeteryId, cemeterySvgId, + burialSiteLatitude, burialSiteLongitude, + recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) - .run(lotForm.lotName, lotForm.lotTypeId, lotForm.lotStatusId === '' ? undefined : lotForm.lotStatusId, lotForm.mapId === '' ? undefined : lotForm.mapId, lotForm.mapKey, lotForm.lotLatitude === '' ? undefined : lotForm.lotLatitude, lotForm.lotLongitude === '' ? undefined : lotForm.lotLongitude, user.userName, rightNowMillis, user.userName, rightNowMillis); - const lotId = result.lastInsertRowid; - const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(','); - for (const lotTypeFieldId of lotTypeFieldIds) { - const lotFieldValue = lotForm[`lotFieldValue_${lotTypeFieldId}`]; - if ((lotFieldValue ?? '') !== '') { - await addOrUpdateLotField({ - lotId, - lotTypeFieldId, - lotFieldValue: lotFieldValue ?? '' + values (?, + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?)`) + .run(burialSiteForm.burialSiteNameSegment1, burialSiteForm.burialSiteNameSegment2 ?? '', burialSiteForm.burialSiteNameSegment3 ?? '', burialSiteForm.burialSiteNameSegment4 ?? '', burialSiteForm.burialSiteNameSegment5 ?? '', burialSiteForm.burialSiteTypeId, burialSiteForm.burialSiteStatusId === '' ? undefined : burialSiteForm.burialSiteStatusId, burialSiteForm.cemeteryId === '' ? undefined : burialSiteForm.cemeteryId, burialSiteForm.cemeterySvgId, burialSiteForm.burialSiteLatitude === '' ? undefined : burialSiteForm.burialSiteLatitude, burialSiteForm.burialSiteLongitude === '' ? undefined : burialSiteForm.burialSiteLongitude, user.userName, rightNowMillis, user.userName, rightNowMillis); + const burialSiteId = result.lastInsertRowid; + const burialSiteTypeFieldIds = (burialSiteForm.burialSiteTypeFieldIds ?? '').split(','); + for (const burialSiteTypeFieldId of burialSiteTypeFieldIds) { + const fieldValue = burialSiteForm[`burialSiteFieldValue_${burialSiteTypeFieldId}`]; + if ((fieldValue ?? '') !== '') { + await addOrUpdateBurialSiteField({ + burialSiteId, + burialSiteTypeFieldId, + fieldValue: fieldValue ?? '' }, user, database); } } database.release(); - return lotId; + return burialSiteId; } diff --git a/database/addBurialSite.ts b/database/addBurialSite.ts index 3230a03f..eb5305ef 100644 --- a/database/addBurialSite.ts +++ b/database/addBurialSite.ts @@ -1,23 +1,28 @@ -import addOrUpdateLotField from './addOrUpdateLotField.js' +import addOrUpdateBurialSiteField from './addOrUpdateBurialSiteField.js' import { acquireConnection } from './pool.js' -export interface AddLotForm { - lotName: string - lotTypeId: string | number - lotStatusId: string | number +export interface AddBurialSiteForm { + burialSiteNameSegment1: string + burialSiteNameSegment2?: string + burialSiteNameSegment3?: string + burialSiteNameSegment4?: string + burialSiteNameSegment5?: string - mapId: string | number - mapKey: string + burialSiteTypeId: string | number + burialSiteStatusId: string | number - lotLatitude: string - lotLongitude: string + cemeteryId: string | number + cemeterySvgId: string - lotTypeFieldIds?: string - [lotFieldValue_lotTypeFieldId: string]: unknown + burialSiteLatitude: string + burialSiteLongitude: string + + burialSiteTypeFieldIds?: string + [fieldValue_burialSiteTypeFieldId: string]: unknown } export default async function addLot( - lotForm: AddLotForm, + burialSiteForm: AddBurialSiteForm, user: User ): Promise { const database = await acquireConnection() @@ -26,41 +31,53 @@ export default async function addLot( const result = database .prepare( - `insert into Lots ( - lotName, lotTypeId, lotStatusId, - mapId, mapKey, - lotLatitude, lotLongitude, + `insert into BurialSites ( + burialSiteNameSegment1, + burialSiteNameSegment2, + burialSiteNameSegment3, + burialSiteNameSegment4, + burialSiteNameSegment5, + burialSiteTypeId, burialSiteStatusId, + cemeteryId, cemeterySvgId, + burialSiteLatitude, burialSiteLongitude, + recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` + values (?, + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?)` ) .run( - lotForm.lotName, - lotForm.lotTypeId, - lotForm.lotStatusId === '' ? undefined : lotForm.lotStatusId, - lotForm.mapId === '' ? undefined : lotForm.mapId, - lotForm.mapKey, - lotForm.lotLatitude === '' ? undefined : lotForm.lotLatitude, - lotForm.lotLongitude === '' ? undefined : lotForm.lotLongitude, + burialSiteForm.burialSiteNameSegment1, + burialSiteForm.burialSiteNameSegment2 ?? '', + burialSiteForm.burialSiteNameSegment3 ?? '', + burialSiteForm.burialSiteNameSegment4 ?? '', + burialSiteForm.burialSiteNameSegment5 ?? '', + burialSiteForm.burialSiteTypeId, + burialSiteForm.burialSiteStatusId === '' ? undefined : burialSiteForm.burialSiteStatusId, + burialSiteForm.cemeteryId === '' ? undefined : burialSiteForm.cemeteryId, + burialSiteForm.cemeterySvgId, + burialSiteForm.burialSiteLatitude === '' ? undefined : burialSiteForm.burialSiteLatitude, + burialSiteForm.burialSiteLongitude === '' ? undefined : burialSiteForm.burialSiteLongitude, user.userName, rightNowMillis, user.userName, rightNowMillis ) - const lotId = result.lastInsertRowid as number + const burialSiteId = result.lastInsertRowid as number - const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(',') + const burialSiteTypeFieldIds = (burialSiteForm.burialSiteTypeFieldIds ?? '').split(',') - for (const lotTypeFieldId of lotTypeFieldIds) { - const lotFieldValue = lotForm[`lotFieldValue_${lotTypeFieldId}`] as string | undefined + for (const burialSiteTypeFieldId of burialSiteTypeFieldIds) { + const fieldValue = burialSiteForm[`burialSiteFieldValue_${burialSiteTypeFieldId}`] as string | undefined - if ((lotFieldValue ?? '') !== '') { - await addOrUpdateLotField( + if ((fieldValue ?? '') !== '') { + await addOrUpdateBurialSiteField( { - lotId, - lotTypeFieldId, - lotFieldValue: lotFieldValue ?? '' + burialSiteId, + burialSiteTypeFieldId, + fieldValue: fieldValue ?? '' }, user, database @@ -70,5 +87,5 @@ export default async function addLot( database.release() - return lotId + return burialSiteId } diff --git a/database/addBurialSiteContract.d.ts b/database/addBurialSiteContract.d.ts new file mode 100644 index 00000000..eb88ac67 --- /dev/null +++ b/database/addBurialSiteContract.d.ts @@ -0,0 +1,21 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +export interface AddBurialSiteContractForm { + contractTypeId: string | number; + burialSiteId: string | number; + contractStartDateString: string; + contractEndDateString: string; + contractTypeFieldIds?: string; + [fieldValue_contractTypeFieldId: string]: unknown; + lotOccupantTypeId?: string; + occupantName?: string; + occupantFamilyName?: string; + occupantAddress1?: string; + occupantAddress2?: string; + occupantCity?: string; + occupantProvince?: string; + occupantPostalCode?: string; + occupantPhoneNumber?: string; + occupantEmailAddress?: string; + occupantComment?: string; +} +export default function addLotOccupancy(addForm: AddBurialSiteContractForm, user: User, connectedDatabase?: PoolConnection): Promise; diff --git a/database/addBurialSiteContract.js b/database/addBurialSiteContract.js new file mode 100644 index 00000000..c215e262 --- /dev/null +++ b/database/addBurialSiteContract.js @@ -0,0 +1,54 @@ +import { dateStringToInteger } from '@cityssm/utils-datetime'; +import addLotOccupancyOccupant from './addLotOccupancyOccupant.js'; +import addOrUpdateBurialSiteContractField from './addOrUpdateBurialSiteContractField.js'; +import { acquireConnection } from './pool.js'; +export default async function addLotOccupancy(addForm, user, connectedDatabase) { + const database = connectedDatabase ?? (await acquireConnection()); + const rightNowMillis = Date.now(); + const contractStartDate = dateStringToInteger(addForm.contractStartDateString); + if (contractStartDate <= 0) { + console.error(addForm); + } + const result = database + .prepare(`insert into BurialSiteContracts ( + contractTypeId, lotId, + contractStartDate, contractEndDate, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + values (?, ?, ?, ?, ?, ?, ?, ?)`) + .run(addForm.contractTypeId, addForm.burialSiteId === '' ? undefined : addForm.burialSiteId, contractStartDate, addForm.contractEndDateString === '' + ? undefined + : dateStringToInteger(addForm.contractEndDateString), user.userName, rightNowMillis, user.userName, rightNowMillis); + const burialSiteContractId = result.lastInsertRowid; + const contractTypeFieldIds = (addForm.contractTypeFieldIds ?? '').split(','); + for (const contractTypeFieldId of contractTypeFieldIds) { + const lotOccupancyFieldValue = addForm[`lotOccupancyFieldValue_${contractTypeFieldId}`]; + if ((lotOccupancyFieldValue ?? '') !== '') { + await addOrUpdateBurialSiteContractField({ + burialSiteContractId, + contractTypeFieldId, + lotOccupancyFieldValue: lotOccupancyFieldValue ?? '' + }, user, database); + } + } + if ((addForm.lotOccupantTypeId ?? '') !== '') { + await addLotOccupancyOccupant({ + burialSiteContractId, + lotOccupantTypeId: addForm.lotOccupantTypeId ?? '', + occupantName: addForm.occupantName ?? '', + occupantFamilyName: addForm.occupantFamilyName ?? '', + occupantAddress1: addForm.occupantAddress1 ?? '', + occupantAddress2: addForm.occupantAddress2 ?? '', + occupantCity: addForm.occupantCity ?? '', + occupantProvince: addForm.occupantProvince ?? '', + occupantPostalCode: addForm.occupantPostalCode ?? '', + occupantPhoneNumber: addForm.occupantPhoneNumber ?? '', + occupantEmailAddress: addForm.occupantEmailAddress ?? '', + occupantComment: addForm.occupantComment ?? '' + }, user, database); + } + if (connectedDatabase === undefined) { + database.release(); + } + return burialSiteContractId; +} diff --git a/database/addBurialSiteContract.ts b/database/addBurialSiteContract.ts new file mode 100644 index 00000000..0d12dd38 --- /dev/null +++ b/database/addBurialSiteContract.ts @@ -0,0 +1,122 @@ +import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime' +import type { PoolConnection } from 'better-sqlite-pool' + +import addLotOccupancyOccupant from './addLotOccupancyOccupant.js' +import addOrUpdateBurialSiteContractField from './addOrUpdateBurialSiteContractField.js' +import { acquireConnection } from './pool.js' + +export interface AddBurialSiteContractForm { + contractTypeId: string | number + burialSiteId: string | number + + contractStartDateString: string + contractEndDateString: string + + contractTypeFieldIds?: string + [fieldValue_contractTypeFieldId: string]: unknown + + lotOccupantTypeId?: string + occupantName?: string + occupantFamilyName?: string + occupantAddress1?: string + occupantAddress2?: string + occupantCity?: string + occupantProvince?: string + occupantPostalCode?: string + occupantPhoneNumber?: string + occupantEmailAddress?: string + occupantComment?: string +} + +export default async function addLotOccupancy( + addForm: AddBurialSiteContractForm, + user: User, + connectedDatabase?: PoolConnection +): Promise { + const database = connectedDatabase ?? (await acquireConnection()) + + const rightNowMillis = Date.now() + + const contractStartDate = dateStringToInteger( + addForm.contractStartDateString as DateString + ) + + if (contractStartDate <= 0) { + console.error(addForm) + } + + const result = database + .prepare( + `insert into BurialSiteContracts ( + contractTypeId, lotId, + contractStartDate, contractEndDate, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + values (?, ?, ?, ?, ?, ?, ?, ?)` + ) + .run( + addForm.contractTypeId, + addForm.burialSiteId === '' ? undefined : addForm.burialSiteId, + contractStartDate, + addForm.contractEndDateString === '' + ? undefined + : dateStringToInteger( + addForm.contractEndDateString as DateString + ), + user.userName, + rightNowMillis, + user.userName, + rightNowMillis + ) + + const burialSiteContractId = result.lastInsertRowid as number + + const contractTypeFieldIds = ( + addForm.contractTypeFieldIds ?? '' + ).split(',') + + for (const contractTypeFieldId of contractTypeFieldIds) { + const lotOccupancyFieldValue = addForm[ + `lotOccupancyFieldValue_${contractTypeFieldId}` + ] as string | undefined + + if ((lotOccupancyFieldValue ?? '') !== '') { + await addOrUpdateBurialSiteContractField( + { + burialSiteContractId, + contractTypeFieldId, + lotOccupancyFieldValue: lotOccupancyFieldValue ?? '' + }, + user, + database + ) + } + } + + if ((addForm.lotOccupantTypeId ?? '') !== '') { + await addLotOccupancyOccupant( + { + burialSiteContractId, + lotOccupantTypeId: addForm.lotOccupantTypeId ?? '', + occupantName: addForm.occupantName ?? '', + occupantFamilyName: addForm.occupantFamilyName ?? '', + occupantAddress1: addForm.occupantAddress1 ?? '', + occupantAddress2: addForm.occupantAddress2 ?? '', + occupantCity: addForm.occupantCity ?? '', + occupantProvince: addForm.occupantProvince ?? '', + occupantPostalCode: addForm.occupantPostalCode ?? '', + occupantPhoneNumber: addForm.occupantPhoneNumber ?? '', + occupantEmailAddress: addForm.occupantEmailAddress ?? '', + occupantComment: addForm.occupantComment ?? '' + }, + user, + database + ) + } + + if (connectedDatabase === undefined) { + database.release() + } + + return burialSiteContractId +} diff --git a/database/addBurialSiteContractFee.d.ts b/database/addBurialSiteContractFee.d.ts new file mode 100644 index 00000000..6a265d65 --- /dev/null +++ b/database/addBurialSiteContractFee.d.ts @@ -0,0 +1,9 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +export interface AddBurialSiteContractFeeForm { + burialSiteContractId: number | string; + feeId: number | string; + quantity: number | string; + feeAmount?: number | string; + taxAmount?: number | string; +} +export default function addBurialSiteContractFee(addFeeForm: AddBurialSiteContractFeeForm, user: User, connectedDatabase?: PoolConnection): Promise; diff --git a/database/addLotOccupancyFee.js b/database/addBurialSiteContractFee.js similarity index 53% rename from database/addLotOccupancyFee.js rename to database/addBurialSiteContractFee.js index a4bc9a40..9d438a53 100644 --- a/database/addLotOccupancyFee.js +++ b/database/addBurialSiteContractFee.js @@ -1,84 +1,84 @@ import { calculateFeeAmount, calculateTaxAmount } from '../helpers/functions.fee.js'; +import getBurialSiteContract from './getBurialSiteContract.js'; import getFee from './getFee.js'; -import getLotOccupancy from './getLotOccupancy.js'; import { acquireConnection } from './pool.js'; -export default async function addLotOccupancyFee(lotOccupancyFeeForm, user, connectedDatabase) { +export default async function addBurialSiteContractFee(addFeeForm, user, connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); const rightNowMillis = Date.now(); // Calculate fee and tax (if not set) let feeAmount; let taxAmount; - if ((lotOccupancyFeeForm.feeAmount ?? '') === '') { - const lotOccupancy = (await getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId)); - const fee = (await getFee(lotOccupancyFeeForm.feeId)); + if ((addFeeForm.feeAmount ?? '') === '') { + const lotOccupancy = (await getBurialSiteContract(addFeeForm.burialSiteContractId)); + const fee = (await getFee(addFeeForm.feeId)); feeAmount = calculateFeeAmount(fee, lotOccupancy); taxAmount = calculateTaxAmount(fee, feeAmount); } else { feeAmount = - typeof lotOccupancyFeeForm.feeAmount === 'string' - ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) + typeof addFeeForm.feeAmount === 'string' + ? Number.parseFloat(addFeeForm.feeAmount) : 0; taxAmount = - typeof lotOccupancyFeeForm.taxAmount === 'string' - ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) + typeof addFeeForm.taxAmount === 'string' + ? Number.parseFloat(addFeeForm.taxAmount) : 0; } try { // Check if record already exists const record = database .prepare(`select feeAmount, taxAmount, recordDelete_timeMillis - from LotOccupancyFees - where lotOccupancyId = ? + from BurialSiteContractFees + where burialSiteContractId = ? and feeId = ?`) - .get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId); + .get(addFeeForm.burialSiteContractId, addFeeForm.feeId); if (record !== undefined) { if (record.recordDelete_timeMillis !== null) { database - .prepare(`delete from LotOccupancyFees + .prepare(`delete from BurialSiteContractFees where recordDelete_timeMillis is not null - and lotOccupancyId = ? + and burialSiteContractId = ? and feeId = ?`) - .run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId); + .run(addFeeForm.burialSiteContractId, addFeeForm.feeId); } else if (record.feeAmount === feeAmount && record.taxAmount === taxAmount) { database - .prepare(`update LotOccupancyFees + .prepare(`update BurialSiteContractFees set quantity = quantity + ?, recordUpdate_userName = ?, recordUpdate_timeMillis = ? - where lotOccupancyId = ? + where burialSiteContractId = ? and feeId = ?`) - .run(lotOccupancyFeeForm.quantity, user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId); + .run(addFeeForm.quantity, user.userName, rightNowMillis, addFeeForm.burialSiteContractId, addFeeForm.feeId); return true; } else { - const quantity = typeof lotOccupancyFeeForm.quantity === 'string' - ? Number.parseFloat(lotOccupancyFeeForm.quantity) - : lotOccupancyFeeForm.quantity; + const quantity = typeof addFeeForm.quantity === 'string' + ? Number.parseFloat(addFeeForm.quantity) + : addFeeForm.quantity; database - .prepare(`update LotOccupancyFees + .prepare(`update BurialSiteContractFees set feeAmount = (feeAmount * quantity) + ?, taxAmount = (taxAmount * quantity) + ?, quantity = 1, recordUpdate_userName = ?, recordUpdate_timeMillis = ? - where lotOccupancyId = ? + where burialSiteContractId = ? and feeId = ?`) - .run(feeAmount * quantity, taxAmount * quantity, user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId); + .run(feeAmount * quantity, taxAmount * quantity, user.userName, rightNowMillis, addFeeForm.burialSiteContractId, addFeeForm.feeId); return true; } } // Create new record const result = database - .prepare(`insert into LotOccupancyFees ( - lotOccupancyId, feeId, + .prepare(`insert into BurialSiteContractFees ( + burialSiteContractId, feeId, quantity, feeAmount, taxAmount, recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) values (?, ?, ?, ?, ?, ?, ?, ?, ?)`) - .run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId, lotOccupancyFeeForm.quantity, feeAmount, taxAmount, user.userName, rightNowMillis, user.userName, rightNowMillis); + .run(addFeeForm.burialSiteContractId, addFeeForm.feeId, addFeeForm.quantity, feeAmount, taxAmount, user.userName, rightNowMillis, user.userName, rightNowMillis); return result.changes > 0; } finally { diff --git a/database/addLotOccupancyFee.ts b/database/addBurialSiteContractFee.ts similarity index 61% rename from database/addLotOccupancyFee.ts rename to database/addBurialSiteContractFee.ts index 301c1e51..582a7081 100644 --- a/database/addLotOccupancyFee.ts +++ b/database/addBurialSiteContractFee.ts @@ -4,22 +4,22 @@ import { calculateFeeAmount, calculateTaxAmount } from '../helpers/functions.fee.js' -import type { Fee, LotOccupancy } from '../types/recordTypes.js' +import type { BurialSiteContract, Fee } from '../types/recordTypes.js' +import getBurialSiteContract from './getBurialSiteContract.js' import getFee from './getFee.js' -import getLotOccupancy from './getLotOccupancy.js' import { acquireConnection } from './pool.js' -export interface AddLotOccupancyFeeForm { - lotOccupancyId: number | string +export interface AddBurialSiteContractFeeForm { + burialSiteContractId: number | string feeId: number | string quantity: number | string feeAmount?: number | string taxAmount?: number | string } -export default async function addLotOccupancyFee( - lotOccupancyFeeForm: AddLotOccupancyFeeForm, +export default async function addBurialSiteContractFee( + addFeeForm: AddBurialSiteContractFeeForm, user: User, connectedDatabase?: PoolConnection ): Promise { @@ -31,23 +31,23 @@ export default async function addLotOccupancyFee( let feeAmount: number let taxAmount: number - if ((lotOccupancyFeeForm.feeAmount ?? '') === '') { - const lotOccupancy = (await getLotOccupancy( - lotOccupancyFeeForm.lotOccupancyId - )) as LotOccupancy + if ((addFeeForm.feeAmount ?? '') === '') { + const lotOccupancy = (await getBurialSiteContract( + addFeeForm.burialSiteContractId + )) as BurialSiteContract - const fee = (await getFee(lotOccupancyFeeForm.feeId)) as Fee + const fee = (await getFee(addFeeForm.feeId)) as Fee feeAmount = calculateFeeAmount(fee, lotOccupancy) taxAmount = calculateTaxAmount(fee, feeAmount) } else { feeAmount = - typeof lotOccupancyFeeForm.feeAmount === 'string' - ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) + typeof addFeeForm.feeAmount === 'string' + ? Number.parseFloat(addFeeForm.feeAmount) : 0 taxAmount = - typeof lotOccupancyFeeForm.taxAmount === 'string' - ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) + typeof addFeeForm.taxAmount === 'string' + ? Number.parseFloat(addFeeForm.taxAmount) : 0 } @@ -56,11 +56,11 @@ export default async function addLotOccupancyFee( const record = database .prepare( `select feeAmount, taxAmount, recordDelete_timeMillis - from LotOccupancyFees - where lotOccupancyId = ? + from BurialSiteContractFees + where burialSiteContractId = ? and feeId = ?` ) - .get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId) as + .get(addFeeForm.burialSiteContractId, addFeeForm.feeId) as | { feeAmount: number | null taxAmount: number | null @@ -72,49 +72,49 @@ export default async function addLotOccupancyFee( if (record.recordDelete_timeMillis !== null) { database .prepare( - `delete from LotOccupancyFees + `delete from BurialSiteContractFees where recordDelete_timeMillis is not null - and lotOccupancyId = ? + and burialSiteContractId = ? and feeId = ?` ) - .run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId) + .run(addFeeForm.burialSiteContractId, addFeeForm.feeId) } else if ( record.feeAmount === feeAmount && record.taxAmount === taxAmount ) { database .prepare( - `update LotOccupancyFees + `update BurialSiteContractFees set quantity = quantity + ?, recordUpdate_userName = ?, recordUpdate_timeMillis = ? - where lotOccupancyId = ? + where burialSiteContractId = ? and feeId = ?` ) .run( - lotOccupancyFeeForm.quantity, + addFeeForm.quantity, user.userName, rightNowMillis, - lotOccupancyFeeForm.lotOccupancyId, - lotOccupancyFeeForm.feeId + addFeeForm.burialSiteContractId, + addFeeForm.feeId ) return true } else { const quantity = - typeof lotOccupancyFeeForm.quantity === 'string' - ? Number.parseFloat(lotOccupancyFeeForm.quantity) - : lotOccupancyFeeForm.quantity + typeof addFeeForm.quantity === 'string' + ? Number.parseFloat(addFeeForm.quantity) + : addFeeForm.quantity database .prepare( - `update LotOccupancyFees + `update BurialSiteContractFees set feeAmount = (feeAmount * quantity) + ?, taxAmount = (taxAmount * quantity) + ?, quantity = 1, recordUpdate_userName = ?, recordUpdate_timeMillis = ? - where lotOccupancyId = ? + where burialSiteContractId = ? and feeId = ?` ) .run( @@ -122,8 +122,8 @@ export default async function addLotOccupancyFee( taxAmount * quantity, user.userName, rightNowMillis, - lotOccupancyFeeForm.lotOccupancyId, - lotOccupancyFeeForm.feeId + addFeeForm.burialSiteContractId, + addFeeForm.feeId ) return true @@ -133,17 +133,17 @@ export default async function addLotOccupancyFee( // Create new record const result = database .prepare( - `insert into LotOccupancyFees ( - lotOccupancyId, feeId, + `insert into BurialSiteContractFees ( + burialSiteContractId, feeId, quantity, feeAmount, taxAmount, recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) values (?, ?, ?, ?, ?, ?, ?, ?, ?)` ) .run( - lotOccupancyFeeForm.lotOccupancyId, - lotOccupancyFeeForm.feeId, - lotOccupancyFeeForm.quantity, + addFeeForm.burialSiteContractId, + addFeeForm.feeId, + addFeeForm.quantity, feeAmount, taxAmount, user.userName, diff --git a/database/addBurialSiteContractFeeCategory.d.ts b/database/addBurialSiteContractFeeCategory.d.ts new file mode 100644 index 00000000..007e8fe0 --- /dev/null +++ b/database/addBurialSiteContractFeeCategory.d.ts @@ -0,0 +1,5 @@ +export interface AddBurialSiteContractCategoryForm { + burialSiteContractId: number | string; + feeCategoryId: number | string; +} +export default function addLotOccupancyFeeCategory(addFeeCategoryForm: AddBurialSiteContractCategoryForm, user: User): Promise; diff --git a/database/addLotOccupancyFeeCategory.js b/database/addBurialSiteContractFeeCategory.js similarity index 53% rename from database/addLotOccupancyFeeCategory.js rename to database/addBurialSiteContractFeeCategory.js index 8f01321f..9f6b50ab 100644 --- a/database/addLotOccupancyFeeCategory.js +++ b/database/addBurialSiteContractFeeCategory.js @@ -1,13 +1,13 @@ -import addLotOccupancyFee from './addLotOccupancyFee.js'; +import addBurialSiteContractFee from './addBurialSiteContractFee.js'; import { getFeeCategory } from './getFeeCategories.js'; import { acquireConnection } from './pool.js'; -export default async function addLotOccupancyFeeCategory(lotOccupancyFeeCategoryForm, user) { +export default async function addLotOccupancyFeeCategory(addFeeCategoryForm, user) { const database = await acquireConnection(); - const feeCategory = await getFeeCategory(lotOccupancyFeeCategoryForm.feeCategoryId, database); + const feeCategory = await getFeeCategory(addFeeCategoryForm.feeCategoryId, database); let addedFeeCount = 0; for (const fee of feeCategory?.fees ?? []) { - const success = await addLotOccupancyFee({ - lotOccupancyId: lotOccupancyFeeCategoryForm.lotOccupancyId, + const success = await addBurialSiteContractFee({ + burialSiteContractId: addFeeCategoryForm.burialSiteContractId, feeId: fee.feeId, quantity: 1 }, user, database); diff --git a/database/addLotOccupancyFeeCategory.ts b/database/addBurialSiteContractFeeCategory.ts similarity index 61% rename from database/addLotOccupancyFeeCategory.ts rename to database/addBurialSiteContractFeeCategory.ts index 78e7f2c5..c795e020 100644 --- a/database/addLotOccupancyFeeCategory.ts +++ b/database/addBurialSiteContractFeeCategory.ts @@ -1,29 +1,29 @@ -import addLotOccupancyFee from './addLotOccupancyFee.js' +import addBurialSiteContractFee from './addBurialSiteContractFee.js' import { getFeeCategory } from './getFeeCategories.js' import { acquireConnection } from './pool.js' -export interface AddLotOccupancyFeeCategoryForm { - lotOccupancyId: number | string +export interface AddBurialSiteContractCategoryForm { + burialSiteContractId: number | string feeCategoryId: number | string } export default async function addLotOccupancyFeeCategory( - lotOccupancyFeeCategoryForm: AddLotOccupancyFeeCategoryForm, + addFeeCategoryForm: AddBurialSiteContractCategoryForm, user: User ): Promise { const database = await acquireConnection() const feeCategory = await getFeeCategory( - lotOccupancyFeeCategoryForm.feeCategoryId, + addFeeCategoryForm.feeCategoryId, database ) let addedFeeCount = 0 for (const fee of feeCategory?.fees ?? []) { - const success = await addLotOccupancyFee( + const success = await addBurialSiteContractFee( { - lotOccupancyId: lotOccupancyFeeCategoryForm.lotOccupancyId, + burialSiteContractId: addFeeCategoryForm.burialSiteContractId, feeId: fee.feeId, quantity: 1 }, diff --git a/database/addContractTypeField.js b/database/addContractTypeField.js index 525fd210..aea9de8c 100644 --- a/database/addContractTypeField.js +++ b/database/addContractTypeField.js @@ -14,6 +14,6 @@ export default async function addContractTypeField(addForm, user) { values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) .run(addForm.contractTypeId ?? undefined, addForm.contractTypeField, addForm.fieldType ?? 'text', addForm.fieldValues ?? '', addForm.isRequired === '' ? 0 : 1, addForm.pattern ?? '', addForm.minimumLength ?? 0, addForm.maximumLength ?? 100, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis); database.release(); - clearCacheByTableName('OccupancyTypeFields'); + clearCacheByTableName('ContractTypeFields'); return result.lastInsertRowid; } diff --git a/database/addContractTypeField.ts b/database/addContractTypeField.ts index eefc7a94..718b523e 100644 --- a/database/addContractTypeField.ts +++ b/database/addContractTypeField.ts @@ -51,7 +51,7 @@ export default async function addContractTypeField( database.release() - clearCacheByTableName('OccupancyTypeFields') + clearCacheByTableName('ContractTypeFields') return result.lastInsertRowid as number } diff --git a/database/addLotOccupancy.d.ts b/database/addLotOccupancy.d.ts deleted file mode 100644 index 55a6160f..00000000 --- a/database/addLotOccupancy.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -export interface AddLotOccupancyForm { - occupancyTypeId: string | number; - lotId: string | number; - occupancyStartDateString: string; - occupancyEndDateString: string; - occupancyTypeFieldIds?: string; - [lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown; - lotOccupantTypeId?: string; - occupantName?: string; - occupantFamilyName?: string; - occupantAddress1?: string; - occupantAddress2?: string; - occupantCity?: string; - occupantProvince?: string; - occupantPostalCode?: string; - occupantPhoneNumber?: string; - occupantEmailAddress?: string; - occupantComment?: string; -} -export default function addLotOccupancy(lotOccupancyForm: AddLotOccupancyForm, user: User, connectedDatabase?: PoolConnection): Promise; diff --git a/database/addLotOccupancy.js b/database/addLotOccupancy.js deleted file mode 100644 index 03f8afc1..00000000 --- a/database/addLotOccupancy.js +++ /dev/null @@ -1,54 +0,0 @@ -import { dateStringToInteger } from '@cityssm/utils-datetime'; -import addLotOccupancyOccupant from './addLotOccupancyOccupant.js'; -import addOrUpdateLotOccupancyField from './addOrUpdateLotOccupancyField.js'; -import { acquireConnection } from './pool.js'; -export default async function addLotOccupancy(lotOccupancyForm, user, connectedDatabase) { - const database = connectedDatabase ?? (await acquireConnection()); - const rightNowMillis = Date.now(); - const occupancyStartDate = dateStringToInteger(lotOccupancyForm.occupancyStartDateString); - if (occupancyStartDate <= 0) { - console.error(lotOccupancyForm); - } - const result = database - .prepare(`insert into LotOccupancies ( - occupancyTypeId, lotId, - occupancyStartDate, occupancyEndDate, - recordCreate_userName, recordCreate_timeMillis, - recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?, ?)`) - .run(lotOccupancyForm.occupancyTypeId, lotOccupancyForm.lotId === '' ? undefined : lotOccupancyForm.lotId, occupancyStartDate, lotOccupancyForm.occupancyEndDateString === '' - ? undefined - : dateStringToInteger(lotOccupancyForm.occupancyEndDateString), user.userName, rightNowMillis, user.userName, rightNowMillis); - const lotOccupancyId = result.lastInsertRowid; - const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds ?? '').split(','); - for (const occupancyTypeFieldId of occupancyTypeFieldIds) { - const lotOccupancyFieldValue = lotOccupancyForm[`lotOccupancyFieldValue_${occupancyTypeFieldId}`]; - if ((lotOccupancyFieldValue ?? '') !== '') { - await addOrUpdateLotOccupancyField({ - lotOccupancyId, - occupancyTypeFieldId, - lotOccupancyFieldValue: lotOccupancyFieldValue ?? '' - }, user, database); - } - } - if ((lotOccupancyForm.lotOccupantTypeId ?? '') !== '') { - await addLotOccupancyOccupant({ - lotOccupancyId, - lotOccupantTypeId: lotOccupancyForm.lotOccupantTypeId ?? '', - occupantName: lotOccupancyForm.occupantName ?? '', - occupantFamilyName: lotOccupancyForm.occupantFamilyName ?? '', - occupantAddress1: lotOccupancyForm.occupantAddress1 ?? '', - occupantAddress2: lotOccupancyForm.occupantAddress2 ?? '', - occupantCity: lotOccupancyForm.occupantCity ?? '', - occupantProvince: lotOccupancyForm.occupantProvince ?? '', - occupantPostalCode: lotOccupancyForm.occupantPostalCode ?? '', - occupantPhoneNumber: lotOccupancyForm.occupantPhoneNumber ?? '', - occupantEmailAddress: lotOccupancyForm.occupantEmailAddress ?? '', - occupantComment: lotOccupancyForm.occupantComment ?? '' - }, user, database); - } - if (connectedDatabase === undefined) { - database.release(); - } - return lotOccupancyId; -} diff --git a/database/addLotOccupancy.ts b/database/addLotOccupancy.ts deleted file mode 100644 index 8e031045..00000000 --- a/database/addLotOccupancy.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime' -import type { PoolConnection } from 'better-sqlite-pool' - -import addLotOccupancyOccupant from './addLotOccupancyOccupant.js' -import addOrUpdateLotOccupancyField from './addOrUpdateLotOccupancyField.js' -import { acquireConnection } from './pool.js' - -export interface AddLotOccupancyForm { - occupancyTypeId: string | number - lotId: string | number - - occupancyStartDateString: string - occupancyEndDateString: string - - occupancyTypeFieldIds?: string - [lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown - - lotOccupantTypeId?: string - occupantName?: string - occupantFamilyName?: string - occupantAddress1?: string - occupantAddress2?: string - occupantCity?: string - occupantProvince?: string - occupantPostalCode?: string - occupantPhoneNumber?: string - occupantEmailAddress?: string - occupantComment?: string -} - -export default async function addLotOccupancy( - lotOccupancyForm: AddLotOccupancyForm, - user: User, - connectedDatabase?: PoolConnection -): Promise { - const database = connectedDatabase ?? (await acquireConnection()) - - const rightNowMillis = Date.now() - - const occupancyStartDate = dateStringToInteger( - lotOccupancyForm.occupancyStartDateString as DateString - ) - - if (occupancyStartDate <= 0) { - console.error(lotOccupancyForm) - } - - const result = database - .prepare( - `insert into LotOccupancies ( - occupancyTypeId, lotId, - occupancyStartDate, occupancyEndDate, - recordCreate_userName, recordCreate_timeMillis, - recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?, ?)` - ) - .run( - lotOccupancyForm.occupancyTypeId, - lotOccupancyForm.lotId === '' ? undefined : lotOccupancyForm.lotId, - occupancyStartDate, - lotOccupancyForm.occupancyEndDateString === '' - ? undefined - : dateStringToInteger( - lotOccupancyForm.occupancyEndDateString as DateString - ), - user.userName, - rightNowMillis, - user.userName, - rightNowMillis - ) - - const lotOccupancyId = result.lastInsertRowid as number - - const occupancyTypeFieldIds = ( - lotOccupancyForm.occupancyTypeFieldIds ?? '' - ).split(',') - - for (const occupancyTypeFieldId of occupancyTypeFieldIds) { - const lotOccupancyFieldValue = lotOccupancyForm[ - `lotOccupancyFieldValue_${occupancyTypeFieldId}` - ] as string | undefined - - if ((lotOccupancyFieldValue ?? '') !== '') { - await addOrUpdateLotOccupancyField( - { - lotOccupancyId, - occupancyTypeFieldId, - lotOccupancyFieldValue: lotOccupancyFieldValue ?? '' - }, - user, - database - ) - } - } - - if ((lotOccupancyForm.lotOccupantTypeId ?? '') !== '') { - await addLotOccupancyOccupant( - { - lotOccupancyId, - lotOccupantTypeId: lotOccupancyForm.lotOccupantTypeId ?? '', - occupantName: lotOccupancyForm.occupantName ?? '', - occupantFamilyName: lotOccupancyForm.occupantFamilyName ?? '', - occupantAddress1: lotOccupancyForm.occupantAddress1 ?? '', - occupantAddress2: lotOccupancyForm.occupantAddress2 ?? '', - occupantCity: lotOccupancyForm.occupantCity ?? '', - occupantProvince: lotOccupancyForm.occupantProvince ?? '', - occupantPostalCode: lotOccupancyForm.occupantPostalCode ?? '', - occupantPhoneNumber: lotOccupancyForm.occupantPhoneNumber ?? '', - occupantEmailAddress: lotOccupancyForm.occupantEmailAddress ?? '', - occupantComment: lotOccupancyForm.occupantComment ?? '' - }, - user, - database - ) - } - - if (connectedDatabase === undefined) { - database.release() - } - - return lotOccupancyId -} diff --git a/database/addLotOccupancyFee.d.ts b/database/addLotOccupancyFee.d.ts deleted file mode 100644 index 11b3130d..00000000 --- a/database/addLotOccupancyFee.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -export interface AddLotOccupancyFeeForm { - lotOccupancyId: number | string; - feeId: number | string; - quantity: number | string; - feeAmount?: number | string; - taxAmount?: number | string; -} -export default function addLotOccupancyFee(lotOccupancyFeeForm: AddLotOccupancyFeeForm, user: User, connectedDatabase?: PoolConnection): Promise; diff --git a/database/addLotOccupancyFeeCategory.d.ts b/database/addLotOccupancyFeeCategory.d.ts deleted file mode 100644 index d4eabba2..00000000 --- a/database/addLotOccupancyFeeCategory.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface AddLotOccupancyFeeCategoryForm { - lotOccupancyId: number | string; - feeCategoryId: number | string; -} -export default function addLotOccupancyFeeCategory(lotOccupancyFeeCategoryForm: AddLotOccupancyFeeCategoryForm, user: User): Promise; diff --git a/database/addLotOccupancyTransaction.d.ts b/database/addLotOccupancyTransaction.d.ts index f990abb5..efbc616e 100644 --- a/database/addLotOccupancyTransaction.d.ts +++ b/database/addLotOccupancyTransaction.d.ts @@ -1,5 +1,5 @@ export interface AddLotOccupancyTransactionForm { - lotOccupancyId: string | number; + burialSiteContractId: string | number; transactionDateString?: string; transactionTimeString?: string; transactionAmount: string | number; diff --git a/database/addLotOccupancyTransaction.js b/database/addLotOccupancyTransaction.js index 0bed2c53..559a4754 100644 --- a/database/addLotOccupancyTransaction.js +++ b/database/addLotOccupancyTransaction.js @@ -6,10 +6,10 @@ export default async function addLotOccupancyTransaction(lotOccupancyTransaction const maxIndexResult = database .prepare(`select transactionIndex from LotOccupancyTransactions - where lotOccupancyId = ? + where burialSiteContractId = ? order by transactionIndex desc limit 1`) - .get(lotOccupancyTransactionForm.lotOccupancyId); + .get(lotOccupancyTransactionForm.burialSiteContractId); if (maxIndexResult !== undefined) { transactionIndex = maxIndexResult.transactionIndex + 1; } @@ -22,13 +22,13 @@ export default async function addLotOccupancyTransaction(lotOccupancyTransaction : dateToTimeInteger(rightNow); database .prepare(`insert into LotOccupancyTransactions ( - lotOccupancyId, transactionIndex, + burialSiteContractId, transactionIndex, transactionDate, transactionTime, transactionAmount, externalReceiptNumber, transactionNote, recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) - .run(lotOccupancyTransactionForm.lotOccupancyId, transactionIndex, transactionDate, transactionTime, lotOccupancyTransactionForm.transactionAmount, lotOccupancyTransactionForm.externalReceiptNumber, lotOccupancyTransactionForm.transactionNote, user.userName, rightNow.getTime(), user.userName, rightNow.getTime()); + .run(lotOccupancyTransactionForm.burialSiteContractId, transactionIndex, transactionDate, transactionTime, lotOccupancyTransactionForm.transactionAmount, lotOccupancyTransactionForm.externalReceiptNumber, lotOccupancyTransactionForm.transactionNote, user.userName, rightNow.getTime(), user.userName, rightNow.getTime()); database.release(); return transactionIndex; } diff --git a/database/addLotOccupancyTransaction.ts b/database/addLotOccupancyTransaction.ts index 99b2a02a..c3b689fb 100644 --- a/database/addLotOccupancyTransaction.ts +++ b/database/addLotOccupancyTransaction.ts @@ -8,7 +8,7 @@ import { import { acquireConnection } from './pool.js' export interface AddLotOccupancyTransactionForm { - lotOccupancyId: string | number + burialSiteContractId: string | number transactionDateString?: string transactionTimeString?: string transactionAmount: string | number @@ -28,11 +28,11 @@ export default async function addLotOccupancyTransaction( .prepare( `select transactionIndex from LotOccupancyTransactions - where lotOccupancyId = ? + where burialSiteContractId = ? order by transactionIndex desc limit 1` ) - .get(lotOccupancyTransactionForm.lotOccupancyId) as + .get(lotOccupancyTransactionForm.burialSiteContractId) as | { transactionIndex: number } | undefined @@ -53,7 +53,7 @@ export default async function addLotOccupancyTransaction( database .prepare( `insert into LotOccupancyTransactions ( - lotOccupancyId, transactionIndex, + burialSiteContractId, transactionIndex, transactionDate, transactionTime, transactionAmount, externalReceiptNumber, transactionNote, recordCreate_userName, recordCreate_timeMillis, @@ -61,7 +61,7 @@ export default async function addLotOccupancyTransaction( values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` ) .run( - lotOccupancyTransactionForm.lotOccupancyId, + lotOccupancyTransactionForm.burialSiteContractId, transactionIndex, transactionDate, transactionTime, diff --git a/database/copyBurialSiteContract.d.ts b/database/copyBurialSiteContract.d.ts new file mode 100644 index 00000000..63d08900 --- /dev/null +++ b/database/copyBurialSiteContract.d.ts @@ -0,0 +1 @@ +export default function copyBurialSiteContract(oldBurialSiteContractId: number | string, user: User): Promise; diff --git a/database/copyBurialSiteContract.js b/database/copyBurialSiteContract.js new file mode 100644 index 00000000..8f5fa336 --- /dev/null +++ b/database/copyBurialSiteContract.js @@ -0,0 +1,62 @@ +import { dateToString } from '@cityssm/utils-datetime'; +import addBurialSiteContract from './addBurialSiteContract.js'; +import addBurialSiteContractComment from './addBurialSiteContractComment.js'; +// import addLotOccupancyOccupant from './addLotOccupancyOccupant.js' +import getBurialSiteContract from './getBurialSiteContract.js'; +import { acquireConnection } from './pool.js'; +export default async function copyBurialSiteContract(oldBurialSiteContractId, user) { + const database = await acquireConnection(); + const oldBurialSiteContract = await getBurialSiteContract(oldBurialSiteContractId, database); + const newBurialSiteContractId = await addBurialSiteContract({ + burialSiteId: oldBurialSiteContract.burialSiteId ?? '', + contractTypeId: oldBurialSiteContract.contractTypeId, + contractStartDateString: dateToString(new Date()), + contractEndDateString: '' + }, user, database); + /* + * Copy Fields + */ + const rightNowMillis = Date.now(); + for (const field of oldBurialSiteContract.burialSiteContractFields ?? []) { + database + .prepare(`insert into BurialSiteContractFields ( + burialSiteContractId, contractTypeFieldId, fieldValue, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + values (?, ?, ?, ?, ?, ?, ?)`) + .run(newBurialSiteContractId, field.contractTypeFieldId, field.fieldValue, user.userName, rightNowMillis, user.userName, rightNowMillis); + } + /* + * Copy Occupants + */ + /* + for (const occupant of oldBurialSiteContract.lotOccupancyOccupants ?? []) { + await addLotOccupancyOccupant( + { + burialSiteContractId: newBurialSiteContractId, + lotOccupantTypeId: occupant.lotOccupantTypeId!, + occupantName: occupant.occupantName!, + occupantFamilyName: occupant.occupantFamilyName!, + occupantAddress1: occupant.occupantAddress1!, + occupantAddress2: occupant.occupantAddress2!, + occupantCity: occupant.occupantCity!, + occupantProvince: occupant.occupantProvince!, + occupantPostalCode: occupant.occupantPostalCode!, + occupantPhoneNumber: occupant.occupantPhoneNumber!, + occupantEmailAddress: occupant.occupantEmailAddress! + }, + user, + database + ) + } + */ + /* + * Add Comment + */ + await addBurialSiteContractComment({ + burialSiteContractId: newBurialSiteContractId, + comment: `New record copied from #${oldBurialSiteContractId}.` + }, user); + database.release(); + return newBurialSiteContractId; +} diff --git a/database/copyBurialSiteContract.ts b/database/copyBurialSiteContract.ts new file mode 100644 index 00000000..7f0cb579 --- /dev/null +++ b/database/copyBurialSiteContract.ts @@ -0,0 +1,94 @@ +import { dateToString } from '@cityssm/utils-datetime' + +import type { BurialSiteContract } from '../types/recordTypes.js' + +import addBurialSiteContract from './addBurialSiteContract.js' +import addBurialSiteContractComment from './addBurialSiteContractComment.js' +// import addLotOccupancyOccupant from './addLotOccupancyOccupant.js' +import getBurialSiteContract from './getBurialSiteContract.js' +import { acquireConnection } from './pool.js' + +export default async function copyBurialSiteContract( + oldBurialSiteContractId: number | string, + user: User +): Promise { + const database = await acquireConnection() + + const oldBurialSiteContract = await getBurialSiteContract(oldBurialSiteContractId, database) as BurialSiteContract + + const newBurialSiteContractId = await addBurialSiteContract( + { + burialSiteId: oldBurialSiteContract.burialSiteId ?? '', + contractTypeId: oldBurialSiteContract.contractTypeId, + contractStartDateString: dateToString(new Date()), + contractEndDateString: '' + }, + user, + database + ) + + /* + * Copy Fields + */ + + const rightNowMillis = Date.now() + + for (const field of oldBurialSiteContract.burialSiteContractFields ?? []) { + database + .prepare( + `insert into BurialSiteContractFields ( + burialSiteContractId, contractTypeFieldId, fieldValue, + recordCreate_userName, recordCreate_timeMillis, + recordUpdate_userName, recordUpdate_timeMillis) + values (?, ?, ?, ?, ?, ?, ?)` + ) + .run( + newBurialSiteContractId, + field.contractTypeFieldId, + field.fieldValue, + user.userName, + rightNowMillis, + user.userName, + rightNowMillis + ) + } + + /* + * Copy Occupants + */ + + /* + for (const occupant of oldBurialSiteContract.lotOccupancyOccupants ?? []) { + await addLotOccupancyOccupant( + { + burialSiteContractId: newBurialSiteContractId, + lotOccupantTypeId: occupant.lotOccupantTypeId!, + occupantName: occupant.occupantName!, + occupantFamilyName: occupant.occupantFamilyName!, + occupantAddress1: occupant.occupantAddress1!, + occupantAddress2: occupant.occupantAddress2!, + occupantCity: occupant.occupantCity!, + occupantProvince: occupant.occupantProvince!, + occupantPostalCode: occupant.occupantPostalCode!, + occupantPhoneNumber: occupant.occupantPhoneNumber!, + occupantEmailAddress: occupant.occupantEmailAddress! + }, + user, + database + ) + } + */ + + /* + * Add Comment + */ + + await addBurialSiteContractComment({ + burialSiteContractId: newBurialSiteContractId, + comment: `New record copied from #${oldBurialSiteContractId}.` + }, user) + + database.release() + + return newBurialSiteContractId +} diff --git a/database/copyLotOccupancy.d.ts b/database/copyLotOccupancy.d.ts deleted file mode 100644 index 814c2c40..00000000 --- a/database/copyLotOccupancy.d.ts +++ /dev/null @@ -1 +0,0 @@ -export default function copyLotOccupancy(oldLotOccupancyId: number | string, user: User): Promise; diff --git a/database/copyLotOccupancy.js b/database/copyLotOccupancy.js deleted file mode 100644 index 11e073af..00000000 --- a/database/copyLotOccupancy.js +++ /dev/null @@ -1,56 +0,0 @@ -import { dateToString } from '@cityssm/utils-datetime'; -import addLotOccupancy from './addLotOccupancy.js'; -import addLotOccupancyComment from './addLotOccupancyComment.js'; -import addLotOccupancyOccupant from './addLotOccupancyOccupant.js'; -import getLotOccupancy from './getLotOccupancy.js'; -import { acquireConnection } from './pool.js'; -export default async function copyLotOccupancy(oldLotOccupancyId, user) { - const database = await acquireConnection(); - const oldLotOccupancy = await getLotOccupancy(oldLotOccupancyId, database); - const newLotOccupancyId = await addLotOccupancy({ - lotId: oldLotOccupancy.lotId ?? '', - occupancyTypeId: oldLotOccupancy.occupancyTypeId, - occupancyStartDateString: dateToString(new Date()), - occupancyEndDateString: '' - }, user, database); - /* - * Copy Fields - */ - const rightNowMillis = Date.now(); - for (const occupancyField of oldLotOccupancy.lotOccupancyFields ?? []) { - database - .prepare(`insert into LotOccupancyFields ( - lotOccupancyId, occupancyTypeFieldId, lotOccupancyFieldValue, - recordCreate_userName, recordCreate_timeMillis, - recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?)`) - .run(newLotOccupancyId, occupancyField.occupancyTypeFieldId, occupancyField.lotOccupancyFieldValue, user.userName, rightNowMillis, user.userName, rightNowMillis); - } - /* - * Copy Occupants - */ - for (const occupant of oldLotOccupancy.lotOccupancyOccupants ?? []) { - await addLotOccupancyOccupant({ - lotOccupancyId: newLotOccupancyId, - lotOccupantTypeId: occupant.lotOccupantTypeId, - occupantName: occupant.occupantName, - occupantFamilyName: occupant.occupantFamilyName, - occupantAddress1: occupant.occupantAddress1, - occupantAddress2: occupant.occupantAddress2, - occupantCity: occupant.occupantCity, - occupantProvince: occupant.occupantProvince, - occupantPostalCode: occupant.occupantPostalCode, - occupantPhoneNumber: occupant.occupantPhoneNumber, - occupantEmailAddress: occupant.occupantEmailAddress - }, user, database); - } - /* - * Add Comment - */ - await addLotOccupancyComment({ - lotOccupancyId: newLotOccupancyId, - lotOccupancyComment: `New record copied from #${oldLotOccupancyId}.` - }, user); - database.release(); - return newLotOccupancyId; -} diff --git a/database/copyLotOccupancy.ts b/database/copyLotOccupancy.ts deleted file mode 100644 index 4dbc0530..00000000 --- a/database/copyLotOccupancy.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { dateToString } from '@cityssm/utils-datetime' - -import type { LotOccupancy } from '../types/recordTypes.js' - -import addLotOccupancy from './addLotOccupancy.js' -import addLotOccupancyComment from './addLotOccupancyComment.js' -import addLotOccupancyOccupant from './addLotOccupancyOccupant.js' -import getLotOccupancy from './getLotOccupancy.js' -import { acquireConnection } from './pool.js' - -export default async function copyLotOccupancy( - oldLotOccupancyId: number | string, - user: User -): Promise { - const database = await acquireConnection() - - const oldLotOccupancy = await getLotOccupancy(oldLotOccupancyId, database) as LotOccupancy - - const newLotOccupancyId = await addLotOccupancy( - { - lotId: oldLotOccupancy.lotId ?? '', - occupancyTypeId: oldLotOccupancy.occupancyTypeId, - occupancyStartDateString: dateToString(new Date()), - occupancyEndDateString: '' - }, - user, - database - ) - - /* - * Copy Fields - */ - - const rightNowMillis = Date.now() - - for (const occupancyField of oldLotOccupancy.lotOccupancyFields ?? []) { - database - .prepare( - `insert into LotOccupancyFields ( - lotOccupancyId, occupancyTypeFieldId, lotOccupancyFieldValue, - recordCreate_userName, recordCreate_timeMillis, - recordUpdate_userName, recordUpdate_timeMillis) - values (?, ?, ?, ?, ?, ?, ?)` - ) - .run( - newLotOccupancyId, - occupancyField.occupancyTypeFieldId, - occupancyField.lotOccupancyFieldValue, - user.userName, - rightNowMillis, - user.userName, - rightNowMillis - ) - } - - /* - * Copy Occupants - */ - - for (const occupant of oldLotOccupancy.lotOccupancyOccupants ?? []) { - await addLotOccupancyOccupant( - { - lotOccupancyId: newLotOccupancyId, - lotOccupantTypeId: occupant.lotOccupantTypeId!, - occupantName: occupant.occupantName!, - occupantFamilyName: occupant.occupantFamilyName!, - occupantAddress1: occupant.occupantAddress1!, - occupantAddress2: occupant.occupantAddress2!, - occupantCity: occupant.occupantCity!, - occupantProvince: occupant.occupantProvince!, - occupantPostalCode: occupant.occupantPostalCode!, - occupantPhoneNumber: occupant.occupantPhoneNumber!, - occupantEmailAddress: occupant.occupantEmailAddress! - }, - user, - database - ) - } - - /* - * Add Comment - */ - - await addLotOccupancyComment({ - lotOccupancyId: newLotOccupancyId, - lotOccupancyComment: `New record copied from #${oldLotOccupancyId}.` - }, user) - - database.release() - - return newLotOccupancyId -} diff --git a/database/deleteRecord.js b/database/deleteRecord.js index 5356517f..b747a46b 100644 --- a/database/deleteRecord.js +++ b/database/deleteRecord.js @@ -31,7 +31,7 @@ relatedTables.set('ContractTypes', ['ContractTypePrints', 'ContractTypeFields']) relatedTables.set('WorkOrders', [ 'WorkOrderMilestones', 'WorkOrderLots', - 'WorkOrderLotOccupancies', + 'WorkOrderBurialSiteContracts', 'WorkOrderComments' ]); export async function deleteRecord(recordTable, recordId, user) { diff --git a/database/deleteRecord.ts b/database/deleteRecord.ts index 7e3d364e..8a42a353 100644 --- a/database/deleteRecord.ts +++ b/database/deleteRecord.ts @@ -53,7 +53,7 @@ relatedTables.set('ContractTypes', ['ContractTypePrints', 'ContractTypeFields']) relatedTables.set('WorkOrders', [ 'WorkOrderMilestones', 'WorkOrderLots', - 'WorkOrderLotOccupancies', + 'WorkOrderBurialSiteContracts', 'WorkOrderComments' ]) diff --git a/database/getBurialSite.d.ts b/database/getBurialSite.d.ts index d5f2d2fd..af9a1aa9 100644 --- a/database/getBurialSite.d.ts +++ b/database/getBurialSite.d.ts @@ -1,3 +1,2 @@ -import type { Lot } from '../types/recordTypes.js'; export declare function getLotByLotName(lotName: string): Promise; export default function getLot(burialSiteId: number | string): Promise; diff --git a/database/getBurialSite.js b/database/getBurialSite.js index 25c12557..1f7d8ee6 100644 --- a/database/getBurialSite.js +++ b/database/getBurialSite.js @@ -1,6 +1,6 @@ -import getLotComments from './getLotComments.js'; -import getLotFields from './getLotFields.js'; -import getBurialSiteInterments from './getLotOccupancies.js'; +import getBurialSiteComments from './getBurialSiteComments.js'; +import getBurialSiteInterments from './getBurialSiteContracts.js'; +import getBurialSiteFields from './getBurialSiteFields.js'; import { acquireConnection } from './pool.js'; const baseSQL = `select l.burialSiteId, l.burialSiteTypeId, t.burialSiteType, @@ -23,8 +23,8 @@ async function _getBurialSite(sql, burialSiteIdOrLotName) { const database = await acquireConnection(); const burialSite = database.prepare(sql).get(burialSiteIdOrLotName); if (burialSite !== undefined) { - const lotOccupancies = await getBurialSiteInterments({ - lotId: burialSite.lotId + const BurialSiteContracts = await getBurialSiteInterments({ + burialSiteId: burialSite.burialSiteId }, { includeOccupants: true, includeFees: false, @@ -32,9 +32,9 @@ async function _getBurialSite(sql, burialSiteIdOrLotName) { limit: -1, offset: 0 }, database); - burialSite.lotOccupancies = lotOccupancies.lotOccupancies; - burialSite.lotFields = await getLotFields(burialSite.lotId, database); - burialSite.lotComments = await getLotComments(burialSite.lotId, database); + burialSite.burialSiteContracts = BurialSiteContracts.BurialSiteContracts; + burialSite.burialSiteFields = await getBurialSiteFields(burialSite.burialSiteId, database); + burialSite.burialSiteComments = await getBurialSiteComments(burialSite.burialSiteId, database); } database.release(); return burialSite; diff --git a/database/getBurialSite.ts b/database/getBurialSite.ts index dd8affa9..d8c76915 100644 --- a/database/getBurialSite.ts +++ b/database/getBurialSite.ts @@ -1,8 +1,8 @@ -import type { Lot } from '../types/recordTypes.js' +import type { BurialSite } from '../types/recordTypes.js' -import getLotComments from './getLotComments.js' -import getLotFields from './getLotFields.js' -import getBurialSiteInterments from './getLotOccupancies.js' +import getBurialSiteComments from './getBurialSiteComments.js' +import getBurialSiteInterments from './getBurialSiteContracts.js' +import getBurialSiteFields from './getBurialSiteFields.js' import { acquireConnection } from './pool.js' const baseSQL = `select l.burialSiteId, @@ -26,15 +26,15 @@ const baseSQL = `select l.burialSiteId, async function _getBurialSite( sql: string, burialSiteIdOrLotName: number | string -): Promise { +): Promise { const database = await acquireConnection() - const burialSite = database.prepare(sql).get(burialSiteIdOrLotName) as Lot | undefined + const burialSite = database.prepare(sql).get(burialSiteIdOrLotName) as BurialSite | undefined if (burialSite !== undefined) { - const lotOccupancies = await getBurialSiteInterments( + const BurialSiteContracts = await getBurialSiteInterments( { - lotId: burialSite.lotId + burialSiteId: burialSite.burialSiteId }, { includeOccupants: true, @@ -46,11 +46,11 @@ async function _getBurialSite( database ) - burialSite.lotOccupancies = lotOccupancies.lotOccupancies + burialSite.burialSiteContracts = BurialSiteContracts.BurialSiteContracts - burialSite.lotFields = await getLotFields(burialSite.lotId, database) + burialSite.burialSiteFields = await getBurialSiteFields(burialSite.burialSiteId, database) - burialSite.lotComments = await getLotComments(burialSite.lotId, database) + burialSite.burialSiteComments = await getBurialSiteComments(burialSite.burialSiteId, database) } database.release() diff --git a/database/getBurialSiteComments.d.ts b/database/getBurialSiteComments.d.ts new file mode 100644 index 00000000..b0dbe7bc --- /dev/null +++ b/database/getBurialSiteComments.d.ts @@ -0,0 +1,3 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +import type { BurialSiteComment } from '../types/recordTypes.js'; +export default function getBurialSiteComments(burialSiteId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotComments.js b/database/getBurialSiteComments.js similarity index 50% rename from database/getLotComments.js rename to database/getBurialSiteComments.js index b52f9f28..1fb507bc 100644 --- a/database/getLotComments.js +++ b/database/getBurialSiteComments.js @@ -1,25 +1,25 @@ import { dateIntegerToString, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime'; import { acquireConnection } from './pool.js'; -export default async function getLotComments(lotId, connectedDatabase) { +export default async function getBurialSiteComments(burialSiteId, connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); database.function('userFn_dateIntegerToString', dateIntegerToString); database.function('userFn_timeIntegerToString', timeIntegerToString); database.function('userFn_timeIntegerToPeriodString', timeIntegerToPeriodString); - const lotComments = database - .prepare(`select lotCommentId, - lotCommentDate, userFn_dateIntegerToString(lotCommentDate) as lotCommentDateString, - lotCommentTime, - userFn_timeIntegerToString(lotCommentTime) as lotCommentTimeString, - userFn_timeIntegerToPeriodString(lotCommentTime) as lotCommentTimePeriodString, - lotComment, + const comments = database + .prepare(`select burialSiteCommentId, + commentDate, userFn_dateIntegerToString(commentDate) as commentDateString, + commentTime, + userFn_timeIntegerToString(commentTime) as commentTimeString, + userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString, + comment, recordCreate_userName, recordUpdate_userName - from LotComments + from BurialSiteComments where recordDelete_timeMillis is null - and lotId = ? - order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc`) - .all(lotId); + and burialSiteId = ? + order by commentDate desc, commentTime desc, burialSiteCommentId desc`) + .all(burialSiteId); if (connectedDatabase === undefined) { database.release(); } - return lotComments; + return comments; } diff --git a/database/getLotComments.ts b/database/getBurialSiteComments.ts similarity index 51% rename from database/getLotComments.ts rename to database/getBurialSiteComments.ts index e3127439..4bfcd14d 100644 --- a/database/getLotComments.ts +++ b/database/getBurialSiteComments.ts @@ -5,14 +5,14 @@ import { } from '@cityssm/utils-datetime' import type { PoolConnection } from 'better-sqlite-pool' -import type { LotComment } from '../types/recordTypes.js' +import type { BurialSiteComment } from '../types/recordTypes.js' import { acquireConnection } from './pool.js' -export default async function getLotComments( - lotId: number | string, +export default async function getBurialSiteComments( + burialSiteId: number | string, connectedDatabase?: PoolConnection -): Promise { +): Promise { const database = connectedDatabase ?? (await acquireConnection()) database.function('userFn_dateIntegerToString', dateIntegerToString) @@ -22,25 +22,25 @@ export default async function getLotComments( timeIntegerToPeriodString ) - const lotComments = database + const comments = database .prepare( - `select lotCommentId, - lotCommentDate, userFn_dateIntegerToString(lotCommentDate) as lotCommentDateString, - lotCommentTime, - userFn_timeIntegerToString(lotCommentTime) as lotCommentTimeString, - userFn_timeIntegerToPeriodString(lotCommentTime) as lotCommentTimePeriodString, - lotComment, + `select burialSiteCommentId, + commentDate, userFn_dateIntegerToString(commentDate) as commentDateString, + commentTime, + userFn_timeIntegerToString(commentTime) as commentTimeString, + userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString, + comment, recordCreate_userName, recordUpdate_userName - from LotComments + from BurialSiteComments where recordDelete_timeMillis is null - and lotId = ? - order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc` + and burialSiteId = ? + order by commentDate desc, commentTime desc, burialSiteCommentId desc` ) - .all(lotId) as LotComment[] + .all(burialSiteId) as BurialSiteComment[] if (connectedDatabase === undefined) { database.release() } - return lotComments + return comments } diff --git a/database/getBurialSiteContract.d.ts b/database/getBurialSiteContract.d.ts new file mode 100644 index 00000000..c6e91bd4 --- /dev/null +++ b/database/getBurialSiteContract.d.ts @@ -0,0 +1,3 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +import type { BurialSiteContract } from '../types/recordTypes.js'; +export default function getLotOccupancy(burialSiteContractId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getBurialSiteContract.js b/database/getBurialSiteContract.js new file mode 100644 index 00000000..65d6d822 --- /dev/null +++ b/database/getBurialSiteContract.js @@ -0,0 +1,56 @@ +import { dateIntegerToString } from '@cityssm/utils-datetime'; +import getBurialSiteContractComments from './getBurialSiteContractComments.js'; +import getBurialSiteContractFees from './getBurialSiteContractFees.js'; +import getBurialSiteContractFields from './getBurialSiteContractFields.js'; +// import getLotOccupancyOccupants from './getLotOccupancyOccupants.js' +import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js'; +import { getWorkOrders } from './getWorkOrders.js'; +import { acquireConnection } from './pool.js'; +export default async function getLotOccupancy(burialSiteContractId, connectedDatabase) { + const database = connectedDatabase ?? (await acquireConnection()); + database.function('userFn_dateIntegerToString', dateIntegerToString); + const contract = database + .prepare(`select o.burialSiteContractId, + o.contractTypeId, t.contractType, + o.burialSiteId, + l.burialSiteNameSegment1, + l.burialSiteNameSegment2, + l.burialSiteNameSegment3, + l.burialSiteNameSegment4, + l.burialSiteNameSegment5, + l.burialSiteTypeId, + l.cemeteryId, m.cemeteryName, + o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, + o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString, + o.recordUpdate_timeMillis + from BurialSiteContracts o + left join ContractTypes t on o.contractTypeId = t.contractTypeId + left join BurialSites l on o.burialSiteId = l.burialSiteId + left join Maps m on l.cemeteryId = m.cemeteryId + where o.recordDelete_timeMillis is null + and o.burialSiteContractId = ?`) + .get(burialSiteContractId); + if (contract !== undefined) { + contract.burialSiteContractFields = await getBurialSiteContractFields(burialSiteContractId, database); + /* + contract.burialSiteContractInterments = await getLotOccupancyOccupants( + burialSiteContractId, + database + ) + */ + contract.burialSiteContractComments = await getBurialSiteContractComments(burialSiteContractId, database); + contract.burialSiteContractFees = await getBurialSiteContractFees(burialSiteContractId, database); + contract.burialSiteContractTransactions = await getBurialSiteContractTransactions(burialSiteContractId, { includeIntegrations: true }, database); + const workOrdersResults = await getWorkOrders({ + burialSiteContractId + }, { + limit: -1, + offset: 0 + }, database); + contract.workOrders = workOrdersResults.workOrders; + } + if (connectedDatabase === undefined) { + database.release(); + } + return contract; +} diff --git a/database/getBurialSiteContract.ts b/database/getBurialSiteContract.ts new file mode 100644 index 00000000..a1b6ed94 --- /dev/null +++ b/database/getBurialSiteContract.ts @@ -0,0 +1,90 @@ +import { dateIntegerToString } from '@cityssm/utils-datetime' +import type { PoolConnection } from 'better-sqlite-pool' + +import type { BurialSiteContract } from '../types/recordTypes.js' + +import getBurialSiteContractComments from './getBurialSiteContractComments.js' +import getBurialSiteContractFees from './getBurialSiteContractFees.js' +import getBurialSiteContractFields from './getBurialSiteContractFields.js' +// import getLotOccupancyOccupants from './getLotOccupancyOccupants.js' +import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js' +import { getWorkOrders } from './getWorkOrders.js' +import { acquireConnection } from './pool.js' + +export default async function getLotOccupancy( + burialSiteContractId: number | string, + connectedDatabase?: PoolConnection +): Promise { + const database = connectedDatabase ?? (await acquireConnection()) + + database.function('userFn_dateIntegerToString', dateIntegerToString) + + const contract = database + .prepare( + `select o.burialSiteContractId, + o.contractTypeId, t.contractType, + o.burialSiteId, + l.burialSiteNameSegment1, + l.burialSiteNameSegment2, + l.burialSiteNameSegment3, + l.burialSiteNameSegment4, + l.burialSiteNameSegment5, + l.burialSiteTypeId, + l.cemeteryId, m.cemeteryName, + o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, + o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString, + o.recordUpdate_timeMillis + from BurialSiteContracts o + left join ContractTypes t on o.contractTypeId = t.contractTypeId + left join BurialSites l on o.burialSiteId = l.burialSiteId + left join Maps m on l.cemeteryId = m.cemeteryId + where o.recordDelete_timeMillis is null + and o.burialSiteContractId = ?` + ) + .get(burialSiteContractId) as BurialSiteContract | undefined + + if (contract !== undefined) { + contract.burialSiteContractFields = await getBurialSiteContractFields( + burialSiteContractId, + database + ) + /* + contract.burialSiteContractInterments = await getLotOccupancyOccupants( + burialSiteContractId, + database + ) + */ + contract.burialSiteContractComments = await getBurialSiteContractComments( + burialSiteContractId, + database + ) + contract.burialSiteContractFees = await getBurialSiteContractFees( + burialSiteContractId, + database + ) + contract.burialSiteContractTransactions = await getBurialSiteContractTransactions( + burialSiteContractId, + { includeIntegrations: true }, + database + ) + + const workOrdersResults = await getWorkOrders( + { + burialSiteContractId + }, + { + limit: -1, + offset: 0 + }, + database + ) + + contract.workOrders = workOrdersResults.workOrders + } + + if (connectedDatabase === undefined) { + database.release() + } + + return contract +} diff --git a/database/getBurialSiteContractComments.d.ts b/database/getBurialSiteContractComments.d.ts new file mode 100644 index 00000000..54837098 --- /dev/null +++ b/database/getBurialSiteContractComments.d.ts @@ -0,0 +1,3 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +import type { BurialSiteContractComment } from '../types/recordTypes.js'; +export default function getBurialSiteContractComments(burialSiteContractId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getBurialSiteContractComments.js b/database/getBurialSiteContractComments.js new file mode 100644 index 00000000..d545c9fd --- /dev/null +++ b/database/getBurialSiteContractComments.js @@ -0,0 +1,25 @@ +import { dateIntegerToString, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime'; +import { acquireConnection } from './pool.js'; +export default async function getBurialSiteContractComments(burialSiteContractId, connectedDatabase) { + const database = connectedDatabase ?? (await acquireConnection()); + database.function('userFn_dateIntegerToString', dateIntegerToString); + database.function('userFn_timeIntegerToString', timeIntegerToString); + database.function('userFn_timeIntegerToPeriodString', timeIntegerToPeriodString); + const comments = database + .prepare(`select burialSiteContractCommentId, + commentDate, userFn_dateIntegerToString(commentDate) as commentDateString, + commentTime, + userFn_timeIntegerToString(commentTime) as commentTimeString, + userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString, + comment, + recordCreate_userName, recordUpdate_userName + from BurialSiteContractComments + where recordDelete_timeMillis is null + and burialSiteContractId = ? + order by commentDate desc, commentTime desc, burialSiteContractCommentId desc`) + .all(burialSiteContractId); + if (connectedDatabase === undefined) { + database.release(); + } + return comments; +} diff --git a/database/getBurialSiteContractComments.ts b/database/getBurialSiteContractComments.ts new file mode 100644 index 00000000..8cdec0a0 --- /dev/null +++ b/database/getBurialSiteContractComments.ts @@ -0,0 +1,46 @@ +import { + dateIntegerToString, + timeIntegerToPeriodString, + timeIntegerToString +} from '@cityssm/utils-datetime' +import type { PoolConnection } from 'better-sqlite-pool' + +import type { BurialSiteContractComment } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' + +export default async function getBurialSiteContractComments( + burialSiteContractId: number | string, + connectedDatabase?: PoolConnection +): Promise { + const database = connectedDatabase ?? (await acquireConnection()) + + database.function('userFn_dateIntegerToString', dateIntegerToString) + database.function('userFn_timeIntegerToString', timeIntegerToString) + database.function( + 'userFn_timeIntegerToPeriodString', + timeIntegerToPeriodString + ) + + const comments = database + .prepare( + `select burialSiteContractCommentId, + commentDate, userFn_dateIntegerToString(commentDate) as commentDateString, + commentTime, + userFn_timeIntegerToString(commentTime) as commentTimeString, + userFn_timeIntegerToPeriodString(commentTime) as commentTimePeriodString, + comment, + recordCreate_userName, recordUpdate_userName + from BurialSiteContractComments + where recordDelete_timeMillis is null + and burialSiteContractId = ? + order by commentDate desc, commentTime desc, burialSiteContractCommentId desc` + ) + .all(burialSiteContractId) as BurialSiteContractComment[] + + if (connectedDatabase === undefined) { + database.release() + } + + return comments +} diff --git a/database/getBurialSiteContractFees.d.ts b/database/getBurialSiteContractFees.d.ts new file mode 100644 index 00000000..d1635bae --- /dev/null +++ b/database/getBurialSiteContractFees.d.ts @@ -0,0 +1,3 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +import type { BurialSiteContractFee } from '../types/recordTypes.js'; +export default function getBurialSiteContractFees(burialSiteContractId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotOccupancyFees.js b/database/getBurialSiteContractFees.js similarity index 62% rename from database/getLotOccupancyFees.js rename to database/getBurialSiteContractFees.js index 1aa4051d..886dd761 100644 --- a/database/getLotOccupancyFees.js +++ b/database/getBurialSiteContractFees.js @@ -1,19 +1,19 @@ import { acquireConnection } from './pool.js'; -export default async function getLotOccupancyFees(lotOccupancyId, connectedDatabase) { +export default async function getBurialSiteContractFees(burialSiteContractId, connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); - const lotOccupancyFees = database - .prepare(`select o.lotOccupancyId, o.feeId, + const fees = database + .prepare(`select o.burialSiteContractId, o.feeId, c.feeCategory, f.feeName, f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity, f.quantityUnit - from LotOccupancyFees o + from BurialSiteContractFees 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 = ? + and o.burialSiteContractId = ? order by o.recordCreate_timeMillis`) - .all(lotOccupancyId); + .all(burialSiteContractId); if (connectedDatabase === undefined) { database.release(); } - return lotOccupancyFees; + return fees; } diff --git a/database/getLotOccupancyFees.ts b/database/getBurialSiteContractFees.ts similarity index 59% rename from database/getLotOccupancyFees.ts rename to database/getBurialSiteContractFees.ts index 41832fe7..733142fa 100644 --- a/database/getLotOccupancyFees.ts +++ b/database/getBurialSiteContractFees.ts @@ -1,32 +1,32 @@ import type { PoolConnection } from 'better-sqlite-pool' -import type { LotOccupancyFee } from '../types/recordTypes.js' +import type { BurialSiteContractFee } from '../types/recordTypes.js' import { acquireConnection } from './pool.js' -export default async function getLotOccupancyFees( - lotOccupancyId: number | string, +export default async function getBurialSiteContractFees( + burialSiteContractId: number | string, connectedDatabase?: PoolConnection -): Promise { +): Promise { const database = connectedDatabase ?? (await acquireConnection()) - const lotOccupancyFees = database + const fees = database .prepare( - `select o.lotOccupancyId, o.feeId, + `select o.burialSiteContractId, o.feeId, c.feeCategory, f.feeName, f.includeQuantity, o.feeAmount, o.taxAmount, o.quantity, f.quantityUnit - from LotOccupancyFees o + from BurialSiteContractFees 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 = ? + and o.burialSiteContractId = ? order by o.recordCreate_timeMillis` ) - .all(lotOccupancyId) as LotOccupancyFee[] + .all(burialSiteContractId) as BurialSiteContractFee[] if (connectedDatabase === undefined) { database.release() } - return lotOccupancyFees + return fees } diff --git a/database/getBurialSiteContractFields.d.ts b/database/getBurialSiteContractFields.d.ts new file mode 100644 index 00000000..51e39733 --- /dev/null +++ b/database/getBurialSiteContractFields.d.ts @@ -0,0 +1,3 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +import type { BurialSiteContractField } from '../types/recordTypes.js'; +export default function getBurialSiteContractField(burialSiteContractId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getBurialSiteContractFields.js b/database/getBurialSiteContractFields.js new file mode 100644 index 00000000..9e4e82e8 --- /dev/null +++ b/database/getBurialSiteContractFields.js @@ -0,0 +1,33 @@ +import { acquireConnection } from './pool.js'; +export default async function getBurialSiteContractField(burialSiteContractId, connectedDatabase) { + const database = connectedDatabase ?? (await acquireConnection()); + const fields = database + .prepare(`select o.burialSiteContractId, o.contractTypeFieldId, + o.fieldValue, f.contractTypeField, f.fieldType, f.fieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as contractTypeOrderNumber + from BurialSiteContractFields o + left join ContractTypeFields f on o.contractTypeFieldId = f.contractTypeFieldId + left join ContractTypes t on f.contractTypeId = t.contractTypeId + where o.recordDelete_timeMillis is null + and o.burialSiteContractId = ? + + union + + select ? as burialSiteContractId, f.contractTypeFieldId, + '' as fieldValue, f.contractTypeField, f.fieldType, f.fieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as contractTypeOrderNumber + from ContractTypeFields f + left join ContractTypes t on f.contractTypeId = t.contractTypeId + where f.recordDelete_timeMillis is null and ( + f.contractTypeId is null + or f.contractTypeId in (select contractTypeId from BurialSiteContracts where burialSiteContractId = ?)) + and f.contractTypeFieldId not in (select contractTypeFieldId from BurialSiteContractFields where burialSiteContractId = ? and recordDelete_timeMillis is null) + order by contractTypeOrderNumber, f.orderNumber, f.contractTypeField`) + .all(burialSiteContractId, burialSiteContractId, burialSiteContractId, burialSiteContractId); + if (connectedDatabase === undefined) { + database.release(); + } + return fields; +} diff --git a/database/getBurialSiteContractFields.ts b/database/getBurialSiteContractFields.ts new file mode 100644 index 00000000..be7f85a3 --- /dev/null +++ b/database/getBurialSiteContractFields.ts @@ -0,0 +1,51 @@ +import type { PoolConnection } from 'better-sqlite-pool' + +import type { BurialSiteContractField } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' + +export default async function getBurialSiteContractField( + burialSiteContractId: number | string, + connectedDatabase?: PoolConnection +): Promise { + const database = connectedDatabase ?? (await acquireConnection()) + + const fields = database + .prepare( + `select o.burialSiteContractId, o.contractTypeFieldId, + o.fieldValue, f.contractTypeField, f.fieldType, f.fieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as contractTypeOrderNumber + from BurialSiteContractFields o + left join ContractTypeFields f on o.contractTypeFieldId = f.contractTypeFieldId + left join ContractTypes t on f.contractTypeId = t.contractTypeId + where o.recordDelete_timeMillis is null + and o.burialSiteContractId = ? + + union + + select ? as burialSiteContractId, f.contractTypeFieldId, + '' as fieldValue, f.contractTypeField, f.fieldType, f.fieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as contractTypeOrderNumber + from ContractTypeFields f + left join ContractTypes t on f.contractTypeId = t.contractTypeId + where f.recordDelete_timeMillis is null and ( + f.contractTypeId is null + or f.contractTypeId in (select contractTypeId from BurialSiteContracts where burialSiteContractId = ?)) + and f.contractTypeFieldId not in (select contractTypeFieldId from BurialSiteContractFields where burialSiteContractId = ? and recordDelete_timeMillis is null) + order by contractTypeOrderNumber, f.orderNumber, f.contractTypeField` + ) + .all( + burialSiteContractId, + burialSiteContractId, + burialSiteContractId, + burialSiteContractId + ) as BurialSiteContractField[] + + if (connectedDatabase === undefined) { + database.release() + } + + return fields +} diff --git a/database/getBurialSiteContractInterments.d.ts b/database/getBurialSiteContractInterments.d.ts new file mode 100644 index 00000000..0a65ceca --- /dev/null +++ b/database/getBurialSiteContractInterments.d.ts @@ -0,0 +1,3 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +import type { BurialSiteContractInterment } from '../types/recordTypes.js'; +export default function getBurialSiteContractInterments(burialSiteContractId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getBurialSiteContractInterments.js b/database/getBurialSiteContractInterments.js new file mode 100644 index 00000000..efc4e755 --- /dev/null +++ b/database/getBurialSiteContractInterments.js @@ -0,0 +1,34 @@ +import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetime'; +import { acquireConnection } from './pool.js'; +export default async function getBurialSiteContractInterments(burialSiteContractId, connectedDatabase) { + const database = connectedDatabase ?? (await acquireConnection()); + database.function('userFn_dateIntegerToString', dateIntegerToString); + database.function('userFn_timeIntegerToString', timeIntegerToString); + const interments = database + .prepare(`select o.burialSiteContractId, o.intermentNumber, + o.isCremated, + o.deceasedName, + birthDate, userFn_dateIntegerToString(birthDate) as birthDateString, + birthPlace, + deathDate, userFn_dateIntegerToString(deathDate) as deathDateString, + deathPlace, + + intermentDate, userFn_dateIntegerToString(intermentDate) as intermentDateString, + intermentTime, userFn_timeIntegerToString(intermentTime) as intermentTimeString, + + intermentContainerTypeId, t.intermentContainerType, + intermentCommittalTypeId, c.intermentCommittalType + + from BurialSiteContractInterments o + left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId + left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId + + where o.recordDelete_timeMillis is null + and o.burialSiteContractId = ? + order by t.orderNumber, o.deceasedName, o.intermentNumber`) + .all(burialSiteContractId); + if (connectedDatabase === undefined) { + database.release(); + } + return interments; +} diff --git a/database/getBurialSiteContractInterments.ts b/database/getBurialSiteContractInterments.ts new file mode 100644 index 00000000..6534db8f --- /dev/null +++ b/database/getBurialSiteContractInterments.ts @@ -0,0 +1,51 @@ +import { + dateIntegerToString, + timeIntegerToString +} from '@cityssm/utils-datetime' +import type { PoolConnection } from 'better-sqlite-pool' + +import type { BurialSiteContractInterment } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' + +export default async function getBurialSiteContractInterments( + burialSiteContractId: number | string, + connectedDatabase?: PoolConnection +): Promise { + const database = connectedDatabase ?? (await acquireConnection()) + + database.function('userFn_dateIntegerToString', dateIntegerToString) + database.function('userFn_timeIntegerToString', timeIntegerToString) + + const interments = database + .prepare( + `select o.burialSiteContractId, o.intermentNumber, + o.isCremated, + o.deceasedName, + birthDate, userFn_dateIntegerToString(birthDate) as birthDateString, + birthPlace, + deathDate, userFn_dateIntegerToString(deathDate) as deathDateString, + deathPlace, + + intermentDate, userFn_dateIntegerToString(intermentDate) as intermentDateString, + intermentTime, userFn_timeIntegerToString(intermentTime) as intermentTimeString, + + intermentContainerTypeId, t.intermentContainerType, + intermentCommittalTypeId, c.intermentCommittalType + + from BurialSiteContractInterments o + left join IntermentContainerTypes t on o.intermentContainerTypeId = t.intermentContainerTypeId + left join IntermentCommittalTypes c on o.intermentCommittalTypeId = c.intermentCommittalTypeId + + where o.recordDelete_timeMillis is null + and o.burialSiteContractId = ? + order by t.orderNumber, o.deceasedName, o.intermentNumber` + ) + .all(burialSiteContractId) as BurialSiteContractInterment[] + + if (connectedDatabase === undefined) { + database.release() + } + + return interments +} diff --git a/database/getBurialSiteContractTransactions.d.ts b/database/getBurialSiteContractTransactions.d.ts new file mode 100644 index 00000000..3204286e --- /dev/null +++ b/database/getBurialSiteContractTransactions.d.ts @@ -0,0 +1,5 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +import type { BurialSiteContractTransaction } from '../types/recordTypes.js'; +export default function GetBurialSiteContractTransactions(burialSiteContractId: number | string, options: { + includeIntegrations: boolean; +}, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotOccupancyTransactions.js b/database/getBurialSiteContractTransactions.js similarity index 81% rename from database/getLotOccupancyTransactions.js rename to database/getBurialSiteContractTransactions.js index 4ba45b62..4c36858c 100644 --- a/database/getLotOccupancyTransactions.js +++ b/database/getBurialSiteContractTransactions.js @@ -2,24 +2,24 @@ import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetim import { getConfigProperty } from '../helpers/config.helpers.js'; import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.js'; import { acquireConnection } from './pool.js'; -export default async function getLotOccupancyTransactions(lotOccupancyId, options, connectedDatabase) { +export default async function GetBurialSiteContractTransactions(burialSiteContractId, options, connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); database.function('userFn_dateIntegerToString', dateIntegerToString); database.function('userFn_timeIntegerToString', timeIntegerToString); const lotOccupancyTransactions = database - .prepare(`select lotOccupancyId, transactionIndex, + .prepare(`select burialSiteContractId, transactionIndex, transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString, transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString, transactionAmount, externalReceiptNumber, transactionNote - from LotOccupancyTransactions + from BurialSiteContractTransactions where recordDelete_timeMillis is null - and lotOccupancyId = ? + and burialSiteContractId = ? order by transactionDate, transactionTime, transactionIndex`) - .all(lotOccupancyId); + .all(burialSiteContractId); if (connectedDatabase === undefined) { database.release(); } - if ((options?.includeIntegrations ?? false) && + if (options.includeIntegrations && getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { for (const transaction of lotOccupancyTransactions) { if ((transaction.externalReceiptNumber ?? '') !== '') { diff --git a/database/getLotOccupancyTransactions.ts b/database/getBurialSiteContractTransactions.ts similarity index 77% rename from database/getLotOccupancyTransactions.ts rename to database/getBurialSiteContractTransactions.ts index 66ed93f3..d49eab0c 100644 --- a/database/getLotOccupancyTransactions.ts +++ b/database/getBurialSiteContractTransactions.ts @@ -6,17 +6,17 @@ import type { PoolConnection } from 'better-sqlite-pool' import { getConfigProperty } from '../helpers/config.helpers.js' import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.js' -import type { LotOccupancyTransaction } from '../types/recordTypes.js' +import type { BurialSiteContractTransaction } from '../types/recordTypes.js' import { acquireConnection } from './pool.js' -export default async function getLotOccupancyTransactions( - lotOccupancyId: number | string, +export default async function GetBurialSiteContractTransactions( + burialSiteContractId: number | string, options: { includeIntegrations: boolean }, connectedDatabase?: PoolConnection -): Promise { +): Promise { const database = connectedDatabase ?? (await acquireConnection()) database.function('userFn_dateIntegerToString', dateIntegerToString) @@ -24,23 +24,23 @@ export default async function getLotOccupancyTransactions( const lotOccupancyTransactions = database .prepare( - `select lotOccupancyId, transactionIndex, + `select burialSiteContractId, transactionIndex, transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString, transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString, transactionAmount, externalReceiptNumber, transactionNote - from LotOccupancyTransactions + from BurialSiteContractTransactions where recordDelete_timeMillis is null - and lotOccupancyId = ? + and burialSiteContractId = ? order by transactionDate, transactionTime, transactionIndex` ) - .all(lotOccupancyId) as LotOccupancyTransaction[] + .all(burialSiteContractId) as BurialSiteContractTransaction[] if (connectedDatabase === undefined) { database.release() } if ( - (options?.includeIntegrations ?? false) && + options.includeIntegrations && getConfigProperty('settings.dynamicsGP.integrationIsEnabled') ) { for (const transaction of lotOccupancyTransactions) { diff --git a/database/getBurialSiteContracts.d.ts b/database/getBurialSiteContracts.d.ts new file mode 100644 index 00000000..067a45b3 --- /dev/null +++ b/database/getBurialSiteContracts.d.ts @@ -0,0 +1,30 @@ +import { type DateString } from '@cityssm/utils-datetime'; +import type { PoolConnection } from 'better-sqlite-pool'; +import type { BurialSiteContract } from '../types/recordTypes.js'; +interface GetBurialSiteContractsFilters { + burialSiteId?: number | string; + occupancyTime?: '' | 'past' | 'current' | 'future'; + contractStartDateString?: DateString; + occupancyEffectiveDateString?: string; + occupantName?: string; + contractTypeId?: number | string; + cemeteryId?: number | string; + burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith'; + burialSiteName?: string; + burialSiteTypeId?: number | string; + workOrderId?: number | string; + notWorkOrderId?: number | string; +} +interface GetBurialSiteContractsOptions { + /** -1 for no limit */ + limit: number; + offset: number; + includeInterments: boolean; + includeFees: boolean; + includeTransactions: boolean; +} +export default function getBurialSiteContracts(filters: GetBurialSiteContractsFilters, options: GetBurialSiteContractsOptions, connectedDatabase?: PoolConnection): Promise<{ + count: number; + burialSiteContracts: BurialSiteContract[]; +}>; +export {}; diff --git a/database/getBurialSiteContracts.js b/database/getBurialSiteContracts.js new file mode 100644 index 00000000..eecb2b73 --- /dev/null +++ b/database/getBurialSiteContracts.js @@ -0,0 +1,150 @@ +import { dateIntegerToString, dateStringToInteger } from '@cityssm/utils-datetime'; +import { getConfigProperty } from '../helpers/config.helpers.js'; +import { getContractTypeById } from '../helpers/functions.cache.js'; +import { getLotNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWhereClause } from '../helpers/functions.sqlFilters.js'; +import getBurialSiteContractFees from './getBurialSiteContractFees.js'; +// import getLotOccupancyOccupants from './getLotOccupancyOccupants.js' +import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js'; +import { acquireConnection } from './pool.js'; +function buildWhereClause(filters) { + let sqlWhereClause = ' where o.recordDelete_timeMillis is null'; + const sqlParameters = []; + if ((filters.burialSiteId ?? '') !== '') { + sqlWhereClause += ' and o.lotId = ?'; + sqlParameters.push(filters.burialSiteId); + } + const lotNameFilters = getLotNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l'); + sqlWhereClause += lotNameFilters.sqlWhereClause; + sqlParameters.push(...lotNameFilters.sqlParameters); + const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, 'o'); + if (occupantNameFilters.sqlParameters.length > 0) { + sqlWhereClause += ` and o.burialSiteContractId in ( + select burialSiteContractId from LotOccupancyOccupants o + where recordDelete_timeMillis is null + ${occupantNameFilters.sqlWhereClause})`; + sqlParameters.push(...occupantNameFilters.sqlParameters); + } + if ((filters.contractTypeId ?? '') !== '') { + sqlWhereClause += ' and o.contractTypeId = ?'; + sqlParameters.push(filters.contractTypeId); + } + const occupancyTimeFilters = getOccupancyTimeWhereClause(filters.occupancyTime ?? '', 'o'); + sqlWhereClause += occupancyTimeFilters.sqlWhereClause; + sqlParameters.push(...occupancyTimeFilters.sqlParameters); + if ((filters.contractStartDateString ?? '') !== '') { + sqlWhereClause += ' and o.contractStartDate = ?'; + sqlParameters.push(dateStringToInteger(filters.contractStartDateString)); + } + if ((filters.occupancyEffectiveDateString ?? '') !== '') { + sqlWhereClause += ` and ( + o.contractEndDate is null + or (o.contractStartDate <= ? and o.contractEndDate >= ?) + )`; + sqlParameters.push(dateStringToInteger(filters.occupancyEffectiveDateString), dateStringToInteger(filters.occupancyEffectiveDateString)); + } + if ((filters.cemeteryId ?? '') !== '') { + sqlWhereClause += ' and l.cemeteryId = ?'; + sqlParameters.push(filters.cemeteryId); + } + if ((filters.burialSiteTypeId ?? '') !== '') { + sqlWhereClause += ' and l.burialSiteTypeId = ?'; + sqlParameters.push(filters.burialSiteTypeId); + } + if ((filters.workOrderId ?? '') !== '') { + sqlWhereClause += + ' and o.burialSiteContractId in (select burialSiteContractId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and workOrderId = ?)'; + sqlParameters.push(filters.workOrderId); + } + if ((filters.notWorkOrderId ?? '') !== '') { + sqlWhereClause += + ' and o.burialSiteContractId not in (select burialSiteContractId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and workOrderId = ?)'; + sqlParameters.push(filters.notWorkOrderId); + } + return { + sqlWhereClause, + sqlParameters + }; +} +async function addInclusions(burialSiteContract, options, database) { + if (options.includeFees) { + burialSiteContract.burialSiteContractFees = await getBurialSiteContractFees(burialSiteContract.burialSiteContractId, database); + } + if (options.includeTransactions) { + burialSiteContract.burialSiteContractTransactions = + await getBurialSiteContractTransactions(burialSiteContract.burialSiteContractId, { includeIntegrations: false }, database); + } + /* + if (options.includeInterments) { + burialSiteContract.burialSiteContractInterments = + await getLotOccupancyOccupants( + burialSiteContract.burialSiteContractId, + database + ) + } + */ + return burialSiteContract; +} +export default async function getBurialSiteContracts(filters, options, connectedDatabase) { + const database = connectedDatabase ?? (await acquireConnection()); + database.function('userFn_dateIntegerToString', dateIntegerToString); + const { sqlWhereClause, sqlParameters } = buildWhereClause(filters); + let count = options.limit; + const isLimited = options.limit !== -1; + if (isLimited) { + count = database + .prepare(`select count(*) as recordCount + from BurialSiteContracts o + left join BurialSites l on o.burialSiteId = l.burialSiteId + ${sqlWhereClause}`) + .get(sqlParameters).recordCount; + } + let burialSiteContracts = []; + if (count !== 0) { + burialSiteContracts = database + .prepare(`select o.burialSiteContractId, + o.contractTypeId, t.contractType, + o.burialSiteId, lt.burialSiteType, + l.burialSiteNameSegment1, + l.burialSiteNameSegment2, + l.burialSiteNameSegment3, + l.burialSiteNameSegment4, + l.burialSiteNameSegment5, + l.cemeteryId, m.cemeteryName, + o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, + o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString + from BurialSiteContracts o + left join ContractTypes t on o.contractTypeId = t.contractTypeId + left join BurialSites l on o.burialSiteId = l.burialSiteId + left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId + left join Cemeteries m on l.cemeteryId = m.cemeteryId + ${sqlWhereClause} + order by o.contractStartDate desc, ifnull(o.contractEndDate, 99999999) desc, + l.burialSiteNameSegment1, + l.burialSiteNameSegment2, + l.burialSiteNameSegment3, + l.burialSiteNameSegment4, + l.burialSiteNameSegment5, + o.burialSiteId, o.burialSiteContractId desc + ${isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''}`) + .all(sqlParameters); + if (!isLimited) { + count = burialSiteContracts.length; + } + for (const burialSiteContract of burialSiteContracts) { + const contractType = await getContractTypeById(burialSiteContract.contractTypeId); + if (contractType !== undefined) { + burialSiteContract.printEJS = (contractType.contractTypePrints ?? []).includes('*') + ? getConfigProperty('settings.contracts.prints')[0] + : (contractType.contractTypePrints ?? [])[0]; + } + await addInclusions(burialSiteContract, options, database); + } + } + if (connectedDatabase === undefined) { + database.release(); + } + return { + count, + burialSiteContracts + }; +} diff --git a/database/getBurialSiteContracts.ts b/database/getBurialSiteContracts.ts new file mode 100644 index 00000000..310bed1b --- /dev/null +++ b/database/getBurialSiteContracts.ts @@ -0,0 +1,262 @@ +import { + type DateString, + dateIntegerToString, + dateStringToInteger +} from '@cityssm/utils-datetime' +import type { PoolConnection } from 'better-sqlite-pool' + +import { getConfigProperty } from '../helpers/config.helpers.js' +import { getContractTypeById } from '../helpers/functions.cache.js' +import { + getLotNameWhereClause, + getOccupancyTimeWhereClause, + getOccupantNameWhereClause +} from '../helpers/functions.sqlFilters.js' +import type { BurialSiteContract } from '../types/recordTypes.js' + +import getBurialSiteContractFees from './getBurialSiteContractFees.js' +// import getLotOccupancyOccupants from './getLotOccupancyOccupants.js' +import getBurialSiteContractTransactions from './getBurialSiteContractTransactions.js' +import { acquireConnection } from './pool.js' + +interface GetBurialSiteContractsFilters { + burialSiteId?: number | string + occupancyTime?: '' | 'past' | 'current' | 'future' + contractStartDateString?: DateString + occupancyEffectiveDateString?: string + occupantName?: string + contractTypeId?: number | string + cemeteryId?: number | string + burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith' + burialSiteName?: string + burialSiteTypeId?: number | string + workOrderId?: number | string + notWorkOrderId?: number | string +} + +interface GetBurialSiteContractsOptions { + /** -1 for no limit */ + limit: number + offset: number + includeInterments: boolean + includeFees: boolean + includeTransactions: boolean +} + +function buildWhereClause(filters: GetBurialSiteContractsFilters): { + sqlWhereClause: string + sqlParameters: unknown[] +} { + let sqlWhereClause = ' where o.recordDelete_timeMillis is null' + const sqlParameters: unknown[] = [] + + if ((filters.burialSiteId ?? '') !== '') { + sqlWhereClause += ' and o.lotId = ?' + sqlParameters.push(filters.burialSiteId) + } + + const lotNameFilters = getLotNameWhereClause( + filters.burialSiteName, + filters.burialSiteNameSearchType ?? '', + 'l' + ) + sqlWhereClause += lotNameFilters.sqlWhereClause + sqlParameters.push(...lotNameFilters.sqlParameters) + + const occupantNameFilters = getOccupantNameWhereClause( + filters.occupantName, + 'o' + ) + if (occupantNameFilters.sqlParameters.length > 0) { + sqlWhereClause += ` and o.burialSiteContractId in ( + select burialSiteContractId from LotOccupancyOccupants o + where recordDelete_timeMillis is null + ${occupantNameFilters.sqlWhereClause})` + sqlParameters.push(...occupantNameFilters.sqlParameters) + } + + if ((filters.contractTypeId ?? '') !== '') { + sqlWhereClause += ' and o.contractTypeId = ?' + sqlParameters.push(filters.contractTypeId) + } + + const occupancyTimeFilters = getOccupancyTimeWhereClause( + filters.occupancyTime ?? '', + 'o' + ) + sqlWhereClause += occupancyTimeFilters.sqlWhereClause + sqlParameters.push(...occupancyTimeFilters.sqlParameters) + + if ((filters.contractStartDateString ?? '') !== '') { + sqlWhereClause += ' and o.contractStartDate = ?' + sqlParameters.push( + dateStringToInteger(filters.contractStartDateString as DateString) + ) + } + + if ((filters.occupancyEffectiveDateString ?? '') !== '') { + sqlWhereClause += ` and ( + o.contractEndDate is null + or (o.contractStartDate <= ? and o.contractEndDate >= ?) + )` + sqlParameters.push( + dateStringToInteger(filters.occupancyEffectiveDateString as DateString), + dateStringToInteger(filters.occupancyEffectiveDateString as DateString) + ) + } + + if ((filters.cemeteryId ?? '') !== '') { + sqlWhereClause += ' and l.cemeteryId = ?' + sqlParameters.push(filters.cemeteryId) + } + + if ((filters.burialSiteTypeId ?? '') !== '') { + sqlWhereClause += ' and l.burialSiteTypeId = ?' + sqlParameters.push(filters.burialSiteTypeId) + } + + if ((filters.workOrderId ?? '') !== '') { + sqlWhereClause += + ' and o.burialSiteContractId in (select burialSiteContractId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and workOrderId = ?)' + sqlParameters.push(filters.workOrderId) + } + + if ((filters.notWorkOrderId ?? '') !== '') { + sqlWhereClause += + ' and o.burialSiteContractId not in (select burialSiteContractId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and workOrderId = ?)' + sqlParameters.push(filters.notWorkOrderId) + } + + return { + sqlWhereClause, + sqlParameters + } +} + +async function addInclusions( + burialSiteContract: BurialSiteContract, + options: GetBurialSiteContractsOptions, + database: PoolConnection +): Promise { + if (options.includeFees) { + burialSiteContract.burialSiteContractFees = await getBurialSiteContractFees( + burialSiteContract.burialSiteContractId, + database + ) + } + + if (options.includeTransactions) { + burialSiteContract.burialSiteContractTransactions = + await getBurialSiteContractTransactions( + burialSiteContract.burialSiteContractId, + { includeIntegrations: false }, + database + ) + } + + /* + if (options.includeInterments) { + burialSiteContract.burialSiteContractInterments = + await getLotOccupancyOccupants( + burialSiteContract.burialSiteContractId, + database + ) + } + */ + + return burialSiteContract +} + +export default async function getBurialSiteContracts( + filters: GetBurialSiteContractsFilters, + options: GetBurialSiteContractsOptions, + connectedDatabase?: PoolConnection +): Promise<{ count: number; burialSiteContracts: BurialSiteContract[] }> { + const database = connectedDatabase ?? (await acquireConnection()) + + database.function('userFn_dateIntegerToString', dateIntegerToString) + + const { sqlWhereClause, sqlParameters } = buildWhereClause(filters) + + let count = options.limit + + const isLimited = options.limit !== -1 + + if (isLimited) { + count = ( + database + .prepare( + `select count(*) as recordCount + from BurialSiteContracts o + left join BurialSites l on o.burialSiteId = l.burialSiteId + ${sqlWhereClause}` + ) + .get(sqlParameters) as { recordCount: number } + ).recordCount + } + + let burialSiteContracts: BurialSiteContract[] = [] + + if (count !== 0) { + burialSiteContracts = database + .prepare( + `select o.burialSiteContractId, + o.contractTypeId, t.contractType, + o.burialSiteId, lt.burialSiteType, + l.burialSiteNameSegment1, + l.burialSiteNameSegment2, + l.burialSiteNameSegment3, + l.burialSiteNameSegment4, + l.burialSiteNameSegment5, + l.cemeteryId, m.cemeteryName, + o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, + o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString + from BurialSiteContracts o + left join ContractTypes t on o.contractTypeId = t.contractTypeId + left join BurialSites l on o.burialSiteId = l.burialSiteId + left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId + left join Cemeteries m on l.cemeteryId = m.cemeteryId + ${sqlWhereClause} + order by o.contractStartDate desc, ifnull(o.contractEndDate, 99999999) desc, + l.burialSiteNameSegment1, + l.burialSiteNameSegment2, + l.burialSiteNameSegment3, + l.burialSiteNameSegment4, + l.burialSiteNameSegment5, + o.burialSiteId, o.burialSiteContractId desc + ${ + isLimited ? ` limit ${options.limit} offset ${options.offset}` : '' + }` + ) + .all(sqlParameters) as BurialSiteContract[] + + if (!isLimited) { + count = burialSiteContracts.length + } + + for (const burialSiteContract of burialSiteContracts) { + const contractType = await getContractTypeById( + burialSiteContract.contractTypeId! + ) + + if (contractType !== undefined) { + burialSiteContract.printEJS = ( + contractType.contractTypePrints ?? [] + ).includes('*') + ? getConfigProperty('settings.contracts.prints')[0] + : (contractType.contractTypePrints ?? [])[0] + } + + await addInclusions(burialSiteContract, options, database) + } + } + + if (connectedDatabase === undefined) { + database.release() + } + + return { + count, + burialSiteContracts + } +} diff --git a/database/getBurialSiteFields.d.ts b/database/getBurialSiteFields.d.ts new file mode 100644 index 00000000..1532b6a9 --- /dev/null +++ b/database/getBurialSiteFields.d.ts @@ -0,0 +1,3 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +import type { BurialSiteField } from '../types/recordTypes.js'; +export default function getBurialSiteFields(burialSiteId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getBurialSiteFields.js b/database/getBurialSiteFields.js new file mode 100644 index 00000000..052854e4 --- /dev/null +++ b/database/getBurialSiteFields.js @@ -0,0 +1,36 @@ +import { acquireConnection } from './pool.js'; +export default async function getBurialSiteFields(burialSiteId, connectedDatabase) { + const database = connectedDatabase ?? (await acquireConnection()); + const burialSiteFields = database + .prepare(`select l.burialSiteId, l.burialSiteTypeFieldId, + l.fieldValue, + f.burialSiteTypeField, f.fieldType, f.fieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as burialSiteTypeOrderNumber + from BurialSiteFields l + left join BurialSiteTypeFields f on l.burialSiteTypeFieldId = f.burialSiteTypeFieldId + left join BurialSiteTypes t on f.burialSiteTypeId = t.burialSiteTypeId + where l.recordDelete_timeMillis is null + and l.burialSiteId = ? + + union + + select ? as burialSiteId, f.burialSiteTypeFieldId, + '' as fieldValue, + f.burialSiteTypeField, f.fieldType, f.fieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as burialSiteTypeOrderNumber + from BurialSiteTypeFields f + left join BurialSiteTypes t on f.burialSiteTypeId = t.burialSiteTypeId + where f.recordDelete_timeMillis is null + and ( + f.burialSiteTypeId is null + or f.burialSiteTypeId in (select burialSiteTypeId from BurialSites where burialSiteId = ?)) + and f.burialSiteTypeFieldId not in (select burialSiteTypeFieldId from BurialSiteFields where burialSiteId = ? and recordDelete_timeMillis is null) + order by burialSiteTypeOrderNumber, f.orderNumber, f.burialSiteTypeField`) + .all(burialSiteId, burialSiteId, burialSiteId, burialSiteId); + if (connectedDatabase === undefined) { + database.release(); + } + return burialSiteFields; +} diff --git a/database/getBurialSiteFields.ts b/database/getBurialSiteFields.ts new file mode 100644 index 00000000..cf0bdea3 --- /dev/null +++ b/database/getBurialSiteFields.ts @@ -0,0 +1,54 @@ +import type { PoolConnection } from 'better-sqlite-pool' + +import type { BurialSiteField } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' + +export default async function getBurialSiteFields( + burialSiteId: number | string, + connectedDatabase?: PoolConnection +): Promise { + const database = connectedDatabase ?? (await acquireConnection()) + + const burialSiteFields = database + .prepare( + `select l.burialSiteId, l.burialSiteTypeFieldId, + l.fieldValue, + f.burialSiteTypeField, f.fieldType, f.fieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as burialSiteTypeOrderNumber + from BurialSiteFields l + left join BurialSiteTypeFields f on l.burialSiteTypeFieldId = f.burialSiteTypeFieldId + left join BurialSiteTypes t on f.burialSiteTypeId = t.burialSiteTypeId + where l.recordDelete_timeMillis is null + and l.burialSiteId = ? + + union + + select ? as burialSiteId, f.burialSiteTypeFieldId, + '' as fieldValue, + f.burialSiteTypeField, f.fieldType, f.fieldValues, + f.isRequired, f.pattern, f.minimumLength, f.maximumLength, + f.orderNumber, t.orderNumber as burialSiteTypeOrderNumber + from BurialSiteTypeFields f + left join BurialSiteTypes t on f.burialSiteTypeId = t.burialSiteTypeId + where f.recordDelete_timeMillis is null + and ( + f.burialSiteTypeId is null + or f.burialSiteTypeId in (select burialSiteTypeId from BurialSites where burialSiteId = ?)) + and f.burialSiteTypeFieldId not in (select burialSiteTypeFieldId from BurialSiteFields where burialSiteId = ? and recordDelete_timeMillis is null) + order by burialSiteTypeOrderNumber, f.orderNumber, f.burialSiteTypeField` + ) + .all( + burialSiteId, + burialSiteId, + burialSiteId, + burialSiteId + ) as BurialSiteField[] + + if (connectedDatabase === undefined) { + database.release() + } + + return burialSiteFields +} diff --git a/database/getBurialSiteStatusSummary.d.ts b/database/getBurialSiteStatusSummary.d.ts new file mode 100644 index 00000000..f6792d2d --- /dev/null +++ b/database/getBurialSiteStatusSummary.d.ts @@ -0,0 +1,9 @@ +import type { BurialSiteStatus } from '../types/recordTypes.js'; +interface GetFilters { + cemeteryId?: number | string; +} +interface BurialSiteStatusSummary extends BurialSiteStatus { + burialSiteCount: number; +} +export default function getBurialSiteStatusSummary(filters: GetFilters): Promise; +export {}; diff --git a/database/getBurialSiteStatusSummary.js b/database/getBurialSiteStatusSummary.js new file mode 100644 index 00000000..490627fa --- /dev/null +++ b/database/getBurialSiteStatusSummary.js @@ -0,0 +1,21 @@ +import { acquireConnection } from './pool.js'; +export default async function getBurialSiteStatusSummary(filters) { + const database = await acquireConnection(); + let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; + const sqlParameters = []; + if ((filters.cemeteryId ?? '') !== '') { + sqlWhereClause += ' and l.cemeteryId = ?'; + sqlParameters.push(filters.cemeteryId); + } + const statuses = database + .prepare(`select s.burialSiteStatusId, s.burialSiteStatus, + count(l.burialSiteId) as burialSiteCount + from BurialSites l + left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId + ${sqlWhereClause} + group by s.burialSiteStatusId, s.burialSiteStatus, s.orderNumber + order by s.orderNumber`) + .all(sqlParameters); + database.release(); + return statuses; +} diff --git a/database/getBurialSiteStatusSummary.ts b/database/getBurialSiteStatusSummary.ts new file mode 100644 index 00000000..fbe8dc0b --- /dev/null +++ b/database/getBurialSiteStatusSummary.ts @@ -0,0 +1,41 @@ +import type { BurialSiteStatus } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' + +interface GetFilters { + cemeteryId?: number | string +} + +interface BurialSiteStatusSummary extends BurialSiteStatus { + burialSiteCount: number +} + +export default async function getBurialSiteStatusSummary( + filters: GetFilters +): Promise { + const database = await acquireConnection() + + let sqlWhereClause = ' where l.recordDelete_timeMillis is null' + const sqlParameters: unknown[] = [] + + if ((filters.cemeteryId ?? '') !== '') { + sqlWhereClause += ' and l.cemeteryId = ?' + sqlParameters.push(filters.cemeteryId) + } + + const statuses = database + .prepare( + `select s.burialSiteStatusId, s.burialSiteStatus, + count(l.burialSiteId) as burialSiteCount + from BurialSites l + left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId + ${sqlWhereClause} + group by s.burialSiteStatusId, s.burialSiteStatus, s.orderNumber + order by s.orderNumber` + ) + .all(sqlParameters) as BurialSiteStatusSummary[] + + database.release() + + return statuses +} diff --git a/database/getBurialSiteStatuses.d.ts b/database/getBurialSiteStatuses.d.ts new file mode 100644 index 00000000..96222547 --- /dev/null +++ b/database/getBurialSiteStatuses.d.ts @@ -0,0 +1,2 @@ +import type { BurialSiteStatus } from '../types/recordTypes.js'; +export default function getBurialSiteStatuses(): Promise; diff --git a/database/getBurialSiteStatuses.js b/database/getBurialSiteStatuses.js new file mode 100644 index 00000000..7188b915 --- /dev/null +++ b/database/getBurialSiteStatuses.js @@ -0,0 +1,21 @@ +import { acquireConnection } from './pool.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; +export default async function getBurialSiteStatuses() { + const database = await acquireConnection(); + const statuses = database + .prepare(`select burialSiteStatusId, burialSiteStatus, orderNumber + from BurialSiteStatuses + where recordDelete_timeMillis is null + order by orderNumber, burialSiteStatus`) + .all(); + let expectedOrderNumber = 0; + for (const status of statuses) { + if (status.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber('BurialSiteStatuses', status.burialSiteStatusId, expectedOrderNumber, database); + status.orderNumber = expectedOrderNumber; + } + expectedOrderNumber += 1; + } + database.release(); + return statuses; +} diff --git a/database/getBurialSiteStatuses.ts b/database/getBurialSiteStatuses.ts new file mode 100644 index 00000000..b18be3a6 --- /dev/null +++ b/database/getBurialSiteStatuses.ts @@ -0,0 +1,37 @@ +import type { BurialSiteStatus } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' + +export default async function getBurialSiteStatuses(): Promise { + const database = await acquireConnection() + + const statuses = database + .prepare( + `select burialSiteStatusId, burialSiteStatus, orderNumber + from BurialSiteStatuses + where recordDelete_timeMillis is null + order by orderNumber, burialSiteStatus` + ) + .all() as BurialSiteStatus[] + + let expectedOrderNumber = 0 + + for (const status of statuses) { + if (status.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber( + 'BurialSiteStatuses', + status.burialSiteStatusId, + expectedOrderNumber, + database + ) + status.orderNumber = expectedOrderNumber + } + + expectedOrderNumber += 1 + } + + database.release() + + return statuses +} diff --git a/database/getBurialSiteTypeFields.d.ts b/database/getBurialSiteTypeFields.d.ts new file mode 100644 index 00000000..4e879874 --- /dev/null +++ b/database/getBurialSiteTypeFields.d.ts @@ -0,0 +1,3 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +import type { BurialSiteTypeField } from '../types/recordTypes.js'; +export default function getBurialSiteTypeFields(burialSiteTypeId: number, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getBurialSiteTypeFields.js b/database/getBurialSiteTypeFields.js new file mode 100644 index 00000000..1a3068e0 --- /dev/null +++ b/database/getBurialSiteTypeFields.js @@ -0,0 +1,26 @@ +import { acquireConnection } from './pool.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; +export default async function getBurialSiteTypeFields(burialSiteTypeId, connectedDatabase) { + const database = connectedDatabase ?? (await acquireConnection()); + const typeFields = database + .prepare(`select burialSiteTypeFieldId, + burialSiteTypeField, fieldType, fieldValues, + isRequired, pattern, minimumLength, maximumLength, orderNumber + from BurialSiteTypeFields + where recordDelete_timeMillis is null + and burialSiteTypeId = ? + order by orderNumber, burialSiteTypeField`) + .all(burialSiteTypeId); + let expectedOrderNumber = 0; + for (const typeField of typeFields) { + if (typeField.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber('BurialSiteTypeFields', typeField.burialSiteTypeFieldId, expectedOrderNumber, database); + typeField.orderNumber = expectedOrderNumber; + } + expectedOrderNumber += 1; + } + if (connectedDatabase === undefined) { + database.release(); + } + return typeFields; +} diff --git a/database/getBurialSiteTypeFields.ts b/database/getBurialSiteTypeFields.ts new file mode 100644 index 00000000..dae08858 --- /dev/null +++ b/database/getBurialSiteTypeFields.ts @@ -0,0 +1,48 @@ +import type { PoolConnection } from 'better-sqlite-pool' + +import type { BurialSiteTypeField } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' + +export default async function getBurialSiteTypeFields( + burialSiteTypeId: number, + connectedDatabase?: PoolConnection +): Promise { + const database = connectedDatabase ?? (await acquireConnection()) + + const typeFields = database + .prepare( + `select burialSiteTypeFieldId, + burialSiteTypeField, fieldType, fieldValues, + isRequired, pattern, minimumLength, maximumLength, orderNumber + from BurialSiteTypeFields + where recordDelete_timeMillis is null + and burialSiteTypeId = ? + order by orderNumber, burialSiteTypeField` + ) + .all(burialSiteTypeId) as BurialSiteTypeField[] + + let expectedOrderNumber = 0 + + for (const typeField of typeFields) { + if (typeField.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber( + 'BurialSiteTypeFields', + typeField.burialSiteTypeFieldId, + expectedOrderNumber, + database + ) + + typeField.orderNumber = expectedOrderNumber + } + + expectedOrderNumber += 1 + } + + if (connectedDatabase === undefined) { + database.release() + } + + return typeFields +} diff --git a/database/getBurialSiteTypeSummary.d.ts b/database/getBurialSiteTypeSummary.d.ts new file mode 100644 index 00000000..c7bc1a32 --- /dev/null +++ b/database/getBurialSiteTypeSummary.d.ts @@ -0,0 +1,9 @@ +import type { BurialSiteType } from '../types/recordTypes.js'; +interface GetFilters { + cemeteryId?: number | string; +} +interface BurialSiteTypeSummary extends BurialSiteType { + lotCount: number; +} +export default function getBurialSiteTypeSummary(filters: GetFilters): Promise; +export {}; diff --git a/database/getBurialSiteTypeSummary.js b/database/getBurialSiteTypeSummary.js new file mode 100644 index 00000000..a06ffbb3 --- /dev/null +++ b/database/getBurialSiteTypeSummary.js @@ -0,0 +1,21 @@ +import { acquireConnection } from './pool.js'; +export default async function getBurialSiteTypeSummary(filters) { + const database = await acquireConnection(); + let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; + const sqlParameters = []; + if ((filters.cemeteryId ?? '') !== '') { + sqlWhereClause += ' and l.cemeteryId = ?'; + sqlParameters.push(filters.cemeteryId); + } + const burialSiteTypes = database + .prepare(`select t.burialSiteTypeId, t.burialSiteType, + count(l.burialSiteId) as burialSiteCount + from BurialSites l + left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId + ${sqlWhereClause} + group by t.burialSiteTypeId, t.burialSiteType, t.orderNumber + order by t.orderNumber`) + .all(sqlParameters); + database.release(); + return burialSiteTypes; +} diff --git a/database/getBurialSiteTypeSummary.ts b/database/getBurialSiteTypeSummary.ts new file mode 100644 index 00000000..047fa50e --- /dev/null +++ b/database/getBurialSiteTypeSummary.ts @@ -0,0 +1,41 @@ +import type { BurialSiteType } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' + +interface GetFilters { + cemeteryId?: number | string +} + +interface BurialSiteTypeSummary extends BurialSiteType { + lotCount: number +} + +export default async function getBurialSiteTypeSummary( + filters: GetFilters +): Promise { + const database = await acquireConnection() + + let sqlWhereClause = ' where l.recordDelete_timeMillis is null' + const sqlParameters: unknown[] = [] + + if ((filters.cemeteryId ?? '') !== '') { + sqlWhereClause += ' and l.cemeteryId = ?' + sqlParameters.push(filters.cemeteryId) + } + + const burialSiteTypes = database + .prepare( + `select t.burialSiteTypeId, t.burialSiteType, + count(l.burialSiteId) as burialSiteCount + from BurialSites l + left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId + ${sqlWhereClause} + group by t.burialSiteTypeId, t.burialSiteType, t.orderNumber + order by t.orderNumber` + ) + .all(sqlParameters) as BurialSiteTypeSummary[] + + database.release() + + return burialSiteTypes +} diff --git a/database/getBurialSiteTypes.d.ts b/database/getBurialSiteTypes.d.ts new file mode 100644 index 00000000..b02e4720 --- /dev/null +++ b/database/getBurialSiteTypes.d.ts @@ -0,0 +1,2 @@ +import type { BurialSiteType } from '../types/recordTypes.js'; +export default function getBurialSiteTypes(): Promise; diff --git a/database/getBurialSiteTypes.js b/database/getBurialSiteTypes.js new file mode 100644 index 00000000..bdf8dd8b --- /dev/null +++ b/database/getBurialSiteTypes.js @@ -0,0 +1,23 @@ +import getBurialSiteTypeFields from './getBurialSiteTypeFields.js'; +import { acquireConnection } from './pool.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; +export default async function getBurialSiteTypes() { + const database = await acquireConnection(); + const burialSiteTypes = database + .prepare(`select burialSiteTypeId, burialSiteType, orderNumber + from BurialSiteTypes + where recordDelete_timeMillis is null + order by orderNumber, burialSiteType`) + .all(); + let expectedOrderNumber = -1; + for (const burialSiteType of burialSiteTypes) { + expectedOrderNumber += 1; + if (burialSiteType.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber('BurialSiteTypes', burialSiteType.burialSiteTypeId, expectedOrderNumber, database); + burialSiteType.orderNumber = expectedOrderNumber; + } + burialSiteType.burialSiteTypeFields = await getBurialSiteTypeFields(burialSiteType.burialSiteTypeId, database); + } + database.release(); + return burialSiteTypes; +} diff --git a/database/getBurialSiteTypes.ts b/database/getBurialSiteTypes.ts new file mode 100644 index 00000000..065d0008 --- /dev/null +++ b/database/getBurialSiteTypes.ts @@ -0,0 +1,44 @@ +import type { BurialSiteType } from '../types/recordTypes.js' + +import getBurialSiteTypeFields from './getBurialSiteTypeFields.js' +import { acquireConnection } from './pool.js' +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' + +export default async function getBurialSiteTypes(): Promise { + const database = await acquireConnection() + + const burialSiteTypes = database + .prepare( + `select burialSiteTypeId, burialSiteType, orderNumber + from BurialSiteTypes + where recordDelete_timeMillis is null + order by orderNumber, burialSiteType` + ) + .all() as BurialSiteType[] + + let expectedOrderNumber = -1 + + for (const burialSiteType of burialSiteTypes) { + expectedOrderNumber += 1 + + if (burialSiteType.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber( + 'BurialSiteTypes', + burialSiteType.burialSiteTypeId, + expectedOrderNumber, + database + ) + + burialSiteType.orderNumber = expectedOrderNumber + } + + burialSiteType.burialSiteTypeFields = await getBurialSiteTypeFields( + burialSiteType.burialSiteTypeId, + database + ) + } + + database.release() + + return burialSiteTypes +} diff --git a/database/getBurialSites.d.ts b/database/getBurialSites.d.ts new file mode 100644 index 00000000..8edc358a --- /dev/null +++ b/database/getBurialSites.d.ts @@ -0,0 +1,22 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +import type { BurialSite } from '../types/recordTypes.js'; +interface GetBurialSitesFilters { + burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith'; + burialSiteName?: string; + cemeteryId?: number | string; + burialSiteTypeId?: number | string; + burialSiteStatusId?: number | string; + contractStatus?: '' | 'occupied' | 'unoccupied'; + workOrderId?: number | string; +} +interface GetBurialSitesOptions { + /** -1 for no limit */ + limit: number; + offset: number; + includeBurialSiteContractCount?: boolean; +} +export default function getBurialSites(filters: GetBurialSitesFilters, options: GetBurialSitesOptions, connectedDatabase?: PoolConnection): Promise<{ + count: number; + burialSites: BurialSite[]; +}>; +export {}; diff --git a/database/getBurialSites.js b/database/getBurialSites.js new file mode 100644 index 00000000..a9f66877 --- /dev/null +++ b/database/getBurialSites.js @@ -0,0 +1,114 @@ +import { dateToInteger } from '@cityssm/utils-datetime'; +import { getLotNameWhereClause } from '../helpers/functions.sqlFilters.js'; +import { acquireConnection } from './pool.js'; +function buildWhereClause(filters) { + let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; + const sqlParameters = []; + const lotNameFilters = getLotNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l'); + sqlWhereClause += lotNameFilters.sqlWhereClause; + sqlParameters.push(...lotNameFilters.sqlParameters); + if ((filters.cemeteryId ?? '') !== '') { + sqlWhereClause += ' and l.cemeteryId = ?'; + sqlParameters.push(filters.cemeteryId); + } + if ((filters.burialSiteTypeId ?? '') !== '') { + sqlWhereClause += ' and l.burialSiteTypeId = ?'; + sqlParameters.push(filters.burialSiteTypeId); + } + if ((filters.burialSiteStatusId ?? '') !== '') { + sqlWhereClause += ' and l.burialSiteStatusId = ?'; + sqlParameters.push(filters.burialSiteStatusId); + } + if ((filters.contractStatus ?? '') !== '') { + if (filters.contractStatus === 'occupied') { + sqlWhereClause += ' and lotOccupancyCount > 0'; + } + else if (filters.contractStatus === 'unoccupied') { + sqlWhereClause += + ' and (lotOccupancyCount is null or lotOccupancyCount = 0)'; + } + } + if ((filters.workOrderId ?? '') !== '') { + sqlWhereClause += + ' and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)'; + sqlParameters.push(filters.workOrderId); + } + return { + sqlWhereClause, + sqlParameters + }; +} +export default async function getBurialSites(filters, options, connectedDatabase) { + const database = connectedDatabase ?? (await acquireConnection()); + const { sqlWhereClause, sqlParameters } = buildWhereClause(filters); + const currentDate = dateToInteger(new Date()); + let count = 0; + if (options.limit !== -1) { + count = database + .prepare(`select count(*) as recordCount + from BurialSites l + left join ( + select burialSiteId, count(burialSiteContractId) as burialSiteContractCount from BurialSiteContracts + where recordDelete_timeMillis is null + and contractStartDate <= ${currentDate.toString()} + and (contractEndDate is null or contractEndDate >= ${currentDate.toString()}) + group by burialSiteId + ) o on l.burialSiteId = o.burialSiteId + ${sqlWhereClause}`) + .get(sqlParameters).recordCount; + } + let burialSites = []; + if (options.limit === -1 || count > 0) { + const includeBurialSiteContractCount = options.includeBurialSiteContractCount ?? true; + if (includeBurialSiteContractCount) { + sqlParameters.unshift(currentDate, currentDate); + } + burialSites = database + .prepare(`select l.burialSiteId, + l.burialSiteNameSegment1, + l.burialSiteNameSegment2, + l.burialSiteNameSegment3, + l.burialSiteNameSegment4, + l.burialSiteNameSegment5, + t.burialSiteType, + l.cemeteryId, m.cemeteryName, l.cemeterySvgId, + l.burialSiteStatusId, s.burialSiteStatus + ${includeBurialSiteContractCount + ? ', ifnull(o.burialSiteContractCount, 0) as burialSiteContractCount' + : ''} + from BurialSites l + left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId + left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId + left join Cemeteries m on l.cemeteryId = m.cemeteryId + ${includeBurialSiteContractCount + ? `left join ( + select burialSiteId, count(burialSiteContractId) as burialSiteContractCount + from BurialSiteContracts + where recordDelete_timeMillis is null + and contractStartDate <= ? + and (contractEndDate is null or contractEndDate >= ?) + group by burialSiteId) o on l.burialSiteId = o.burialSiteId` + : ''} + ${sqlWhereClause} + order by l.burialSiteNameSegment1, + l.burialSiteNameSegment2, + l.burialSiteNameSegment3, + l.burialSiteNameSegment4, + l.burialSiteNameSegment5, + l.burialSiteId + ${options.limit === -1 + ? '' + : ` limit ${options.limit.toString()} offset ${options.offset.toString()}`}`) + .all(sqlParameters); + if (options.limit === -1) { + count = burialSites.length; + } + } + if (connectedDatabase === undefined) { + database.release(); + } + return { + count, + burialSites + }; +} diff --git a/database/getBurialSites.ts b/database/getBurialSites.ts new file mode 100644 index 00000000..17ffdf35 --- /dev/null +++ b/database/getBurialSites.ts @@ -0,0 +1,177 @@ +import { dateToInteger } from '@cityssm/utils-datetime' +import type { PoolConnection } from 'better-sqlite-pool' + +import { getLotNameWhereClause } from '../helpers/functions.sqlFilters.js' +import type { BurialSite } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' + +interface GetBurialSitesFilters { + burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith' + burialSiteName?: string + cemeteryId?: number | string + burialSiteTypeId?: number | string + burialSiteStatusId?: number | string + contractStatus?: '' | 'occupied' | 'unoccupied' + workOrderId?: number | string +} + +interface GetBurialSitesOptions { + /** -1 for no limit */ + limit: number + offset: number + includeBurialSiteContractCount?: boolean +} + +function buildWhereClause(filters: GetBurialSitesFilters): { + sqlWhereClause: string + sqlParameters: unknown[] +} { + let sqlWhereClause = ' where l.recordDelete_timeMillis is null' + const sqlParameters: unknown[] = [] + + const lotNameFilters = getLotNameWhereClause( + filters.burialSiteName, + filters.burialSiteNameSearchType ?? '', + 'l' + ) + sqlWhereClause += lotNameFilters.sqlWhereClause + sqlParameters.push(...lotNameFilters.sqlParameters) + + if ((filters.cemeteryId ?? '') !== '') { + sqlWhereClause += ' and l.cemeteryId = ?' + sqlParameters.push(filters.cemeteryId) + } + + if ((filters.burialSiteTypeId ?? '') !== '') { + sqlWhereClause += ' and l.burialSiteTypeId = ?' + sqlParameters.push(filters.burialSiteTypeId) + } + + if ((filters.burialSiteStatusId ?? '') !== '') { + sqlWhereClause += ' and l.burialSiteStatusId = ?' + sqlParameters.push(filters.burialSiteStatusId) + } + + if ((filters.contractStatus ?? '') !== '') { + if (filters.contractStatus === 'occupied') { + sqlWhereClause += ' and lotOccupancyCount > 0' + } else if (filters.contractStatus === 'unoccupied') { + sqlWhereClause += + ' and (lotOccupancyCount is null or lotOccupancyCount = 0)' + } + } + + if ((filters.workOrderId ?? '') !== '') { + sqlWhereClause += + ' and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)' + sqlParameters.push(filters.workOrderId) + } + + return { + sqlWhereClause, + sqlParameters + } +} + +export default async function getBurialSites( + filters: GetBurialSitesFilters, + options: GetBurialSitesOptions, + connectedDatabase?: PoolConnection +): Promise<{ count: number; burialSites: BurialSite[] }> { + const database = connectedDatabase ?? (await acquireConnection()) + + const { sqlWhereClause, sqlParameters } = buildWhereClause(filters) + + const currentDate = dateToInteger(new Date()) + + let count = 0 + + if (options.limit !== -1) { + count = ( + database + .prepare( + `select count(*) as recordCount + from BurialSites l + left join ( + select burialSiteId, count(burialSiteContractId) as burialSiteContractCount from BurialSiteContracts + where recordDelete_timeMillis is null + and contractStartDate <= ${currentDate.toString()} + and (contractEndDate is null or contractEndDate >= ${currentDate.toString()}) + group by burialSiteId + ) o on l.burialSiteId = o.burialSiteId + ${sqlWhereClause}` + ) + .get(sqlParameters) as { recordCount: number } + ).recordCount + } + + let burialSites: BurialSite[] = [] + + if (options.limit === -1 || count > 0) { + const includeBurialSiteContractCount = options.includeBurialSiteContractCount ?? true + + if (includeBurialSiteContractCount) { + sqlParameters.unshift(currentDate, currentDate) + } + + burialSites = database + .prepare( + `select l.burialSiteId, + l.burialSiteNameSegment1, + l.burialSiteNameSegment2, + l.burialSiteNameSegment3, + l.burialSiteNameSegment4, + l.burialSiteNameSegment5, + t.burialSiteType, + l.cemeteryId, m.cemeteryName, l.cemeterySvgId, + l.burialSiteStatusId, s.burialSiteStatus + ${ + includeBurialSiteContractCount + ? ', ifnull(o.burialSiteContractCount, 0) as burialSiteContractCount' + : '' + } + from BurialSites l + left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId + left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId + left join Cemeteries m on l.cemeteryId = m.cemeteryId + ${ + includeBurialSiteContractCount + ? `left join ( + select burialSiteId, count(burialSiteContractId) as burialSiteContractCount + from BurialSiteContracts + where recordDelete_timeMillis is null + and contractStartDate <= ? + and (contractEndDate is null or contractEndDate >= ?) + group by burialSiteId) o on l.burialSiteId = o.burialSiteId` + : '' + } + ${sqlWhereClause} + order by l.burialSiteNameSegment1, + l.burialSiteNameSegment2, + l.burialSiteNameSegment3, + l.burialSiteNameSegment4, + l.burialSiteNameSegment5, + l.burialSiteId + ${ + options.limit === -1 + ? '' + : ` limit ${options.limit.toString()} offset ${options.offset.toString()}` + }` + ) + .all(sqlParameters) as BurialSite[] + + if (options.limit === -1) { + count = burialSites.length + } + } + + if (connectedDatabase === undefined) { + database.release() + } + + return { + count, + burialSites + } +} diff --git a/database/getCemeteries.d.ts b/database/getCemeteries.d.ts new file mode 100644 index 00000000..d027c01e --- /dev/null +++ b/database/getCemeteries.d.ts @@ -0,0 +1,2 @@ +import type { Cemetery } from '../types/recordTypes.js'; +export default function getCemeteries(): Promise; diff --git a/database/getCemeteries.js b/database/getCemeteries.js new file mode 100644 index 00000000..0ea947f1 --- /dev/null +++ b/database/getCemeteries.js @@ -0,0 +1,22 @@ +import { acquireConnection } from './pool.js'; +export default async function getCemeteries() { + const database = await acquireConnection(); + const cemeteries = database + .prepare(`select m.cemeteryId, m.cemeteryName, m.cemeteryDescription, + m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, + m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, + m.cemeteryPhoneNumber, + ifnull(l.burialSiteCount, 0) as burialSiteCount + from Cemeteries m + left join ( + select cemeteryId, count(burialSiteId) as burialSiteCount + from BurialSites + where recordDelete_timeMillis is null + group by cemeteryId + ) l on m.cemeteryId = l.cemeteryId + where m.recordDelete_timeMillis is null + order by m.cemeteryName, m.cemeteryId`) + .all(); + database.release(); + return cemeteries; +} diff --git a/database/getCemeteries.ts b/database/getCemeteries.ts new file mode 100644 index 00000000..cb4615eb --- /dev/null +++ b/database/getCemeteries.ts @@ -0,0 +1,30 @@ +import type { Cemetery } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' + +export default async function getCemeteries(): Promise { + const database = await acquireConnection() + + const cemeteries = database + .prepare( + `select m.cemeteryId, m.cemeteryName, m.cemeteryDescription, + m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, + m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, + m.cemeteryPhoneNumber, + ifnull(l.burialSiteCount, 0) as burialSiteCount + from Cemeteries m + left join ( + select cemeteryId, count(burialSiteId) as burialSiteCount + from BurialSites + where recordDelete_timeMillis is null + group by cemeteryId + ) l on m.cemeteryId = l.cemeteryId + where m.recordDelete_timeMillis is null + order by m.cemeteryName, m.cemeteryId` + ) + .all() as Cemetery[] + + database.release() + + return cemeteries +} diff --git a/database/getCemetery.d.ts b/database/getCemetery.d.ts new file mode 100644 index 00000000..91c36727 --- /dev/null +++ b/database/getCemetery.d.ts @@ -0,0 +1,2 @@ +import type { Cemetery } from '../types/recordTypes.js'; +export default function getMap(cemeteryId: number | string): Promise; diff --git a/database/getCemetery.js b/database/getCemetery.js new file mode 100644 index 00000000..41c556b1 --- /dev/null +++ b/database/getCemetery.js @@ -0,0 +1,27 @@ +import { acquireConnection } from './pool.js'; +export default async function getMap(cemeteryId) { + const database = await acquireConnection(); + const map = database + .prepare(`select m.cemeteryId, m.cemeteryName, m.cemeteryDescription, + m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, + m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, + m.cemeteryPhoneNumber, + m.recordCreate_userName, m.recordCreate_timeMillis, + m.recordUpdate_userName, m.recordUpdate_timeMillis, + m.recordDelete_userName, m.recordDelete_timeMillis, + count(l.burialSiteId) as burialSiteCount + from Cemeteries m + left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null + where m.cemeteryId = ? + and m.recordDelete_timeMillis is null + group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription, + m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, + m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, + m.cemeteryPhoneNumber, + m.recordCreate_userName, m.recordCreate_timeMillis, + m.recordUpdate_userName, m.recordUpdate_timeMillis, + m.recordDelete_userName, m.recordDelete_timeMillis`) + .get(cemeteryId); + database.release(); + return map; +} diff --git a/database/getCemetery.ts b/database/getCemetery.ts new file mode 100644 index 00000000..8790abec --- /dev/null +++ b/database/getCemetery.ts @@ -0,0 +1,37 @@ +import type { Cemetery } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' + +export default async function getMap( + cemeteryId: number | string +): Promise { + const database = await acquireConnection() + + const map = database + .prepare( + `select m.cemeteryId, m.cemeteryName, m.cemeteryDescription, + m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, + m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, + m.cemeteryPhoneNumber, + m.recordCreate_userName, m.recordCreate_timeMillis, + m.recordUpdate_userName, m.recordUpdate_timeMillis, + m.recordDelete_userName, m.recordDelete_timeMillis, + count(l.burialSiteId) as burialSiteCount + from Cemeteries m + left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null + where m.cemeteryId = ? + and m.recordDelete_timeMillis is null + group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription, + m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, + m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, + m.cemeteryPhoneNumber, + m.recordCreate_userName, m.recordCreate_timeMillis, + m.recordUpdate_userName, m.recordUpdate_timeMillis, + m.recordDelete_userName, m.recordDelete_timeMillis` + ) + .get(cemeteryId) as Cemetery | undefined + + database.release() + + return map +} diff --git a/database/getContractTypeFields.d.ts b/database/getContractTypeFields.d.ts new file mode 100644 index 00000000..9978475a --- /dev/null +++ b/database/getContractTypeFields.d.ts @@ -0,0 +1,3 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +import type { ContractTypeField } from '../types/recordTypes.js'; +export default function getContractTypeFields(contractTypeId?: number, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getContractTypeFields.js b/database/getContractTypeFields.js new file mode 100644 index 00000000..636b4724 --- /dev/null +++ b/database/getContractTypeFields.js @@ -0,0 +1,31 @@ +import { acquireConnection } from './pool.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; +export default async function getContractTypeFields(contractTypeId, connectedDatabase) { + const database = connectedDatabase ?? (await acquireConnection()); + const sqlParameters = []; + if ((contractTypeId ?? -1) !== -1) { + sqlParameters.push(contractTypeId); + } + const contractTypeFields = database + .prepare(`select contractTypeFieldId, contractTypeField, fieldType, + fieldValues, isRequired, pattern, minimumLength, maximumLength, orderNumber + from ContractTypeFields + where recordDelete_timeMillis is null + ${(contractTypeId ?? -1) === -1 + ? ' and contractTypeId is null' + : ' and contractTypeId = ?'} + order by orderNumber, contractTypeField`) + .all(sqlParameters); + let expectedOrderNumber = 0; + for (const contractTypeField of contractTypeFields) { + if (contractTypeField.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber('ContractTypeFields', contractTypeField.contractTypeFieldId, expectedOrderNumber, database); + contractTypeField.orderNumber = expectedOrderNumber; + } + expectedOrderNumber += 1; + } + if (connectedDatabase === undefined) { + database.release(); + } + return contractTypeFields; +} diff --git a/database/getContractTypeFields.ts b/database/getContractTypeFields.ts new file mode 100644 index 00000000..a867ebf4 --- /dev/null +++ b/database/getContractTypeFields.ts @@ -0,0 +1,57 @@ +import type { PoolConnection } from 'better-sqlite-pool' + +import type { ContractTypeField } from '../types/recordTypes.js' + +import { acquireConnection } from './pool.js' +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' + +export default async function getContractTypeFields( + contractTypeId?: number, + connectedDatabase?: PoolConnection +): Promise { + const database = connectedDatabase ?? (await acquireConnection()) + + const sqlParameters: unknown[] = [] + + if ((contractTypeId ?? -1) !== -1) { + sqlParameters.push(contractTypeId) + } + + const contractTypeFields = database + .prepare( + `select contractTypeFieldId, contractTypeField, fieldType, + fieldValues, isRequired, pattern, minimumLength, maximumLength, orderNumber + from ContractTypeFields + where recordDelete_timeMillis is null + ${ + (contractTypeId ?? -1) === -1 + ? ' and contractTypeId is null' + : ' and contractTypeId = ?' + } + order by orderNumber, contractTypeField` + ) + .all(sqlParameters) as ContractTypeField[] + + let expectedOrderNumber = 0 + + for (const contractTypeField of contractTypeFields) { + if (contractTypeField.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber( + 'ContractTypeFields', + contractTypeField.contractTypeFieldId, + expectedOrderNumber, + database + ) + + contractTypeField.orderNumber = expectedOrderNumber + } + + expectedOrderNumber += 1 + } + + if (connectedDatabase === undefined) { + database.release() + } + + return contractTypeFields +} diff --git a/database/getContractTypePrints.d.ts b/database/getContractTypePrints.d.ts new file mode 100644 index 00000000..f50f446f --- /dev/null +++ b/database/getContractTypePrints.d.ts @@ -0,0 +1,2 @@ +import type { PoolConnection } from 'better-sqlite-pool'; +export default function getContractTypePrints(contractTypeId: number, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getOccupancyTypePrints.js b/database/getContractTypePrints.js similarity index 73% rename from database/getOccupancyTypePrints.js rename to database/getContractTypePrints.js index 6eb16583..4b3f227f 100644 --- a/database/getOccupancyTypePrints.js +++ b/database/getContractTypePrints.js @@ -1,6 +1,6 @@ import { getConfigProperty } from '../helpers/config.helpers.js'; import { acquireConnection } from './pool.js'; -const availablePrints = getConfigProperty('settings.lotOccupancy.prints'); +const availablePrints = getConfigProperty('settings.contracts.prints'); // eslint-disable-next-line @typescript-eslint/naming-convention const userFunction_configContainsPrintEJS = (printEJS) => { if (printEJS === '*' || availablePrints.includes(printEJS)) { @@ -8,30 +8,30 @@ const userFunction_configContainsPrintEJS = (printEJS) => { } return 0; }; -export default async function getOccupancyTypePrints(occupancyTypeId, connectedDatabase) { +export default async function getContractTypePrints(contractTypeId, connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); database.function( // eslint-disable-next-line no-secrets/no-secrets 'userFn_configContainsPrintEJS', userFunction_configContainsPrintEJS); const results = database .prepare(`select printEJS, orderNumber - from OccupancyTypePrints + from ContractTypePrints where recordDelete_timeMillis is null - and occupancyTypeId = ? + and contractTypeId = ? and userFn_configContainsPrintEJS(printEJS) = 1 order by orderNumber, printEJS`) - .all(occupancyTypeId); + .all(contractTypeId); let expectedOrderNumber = -1; const prints = []; for (const result of results) { expectedOrderNumber += 1; if (result.orderNumber !== expectedOrderNumber) { database - .prepare(`update OccupancyTypePrints + .prepare(`update ContractTypePrints set orderNumber = ? - where occupancyTypeId = ? + where contractTypeId = ? and printEJS = ?`) - .run(expectedOrderNumber, occupancyTypeId, result.printEJS); + .run(expectedOrderNumber, contractTypeId, result.printEJS); } prints.push(result.printEJS); } diff --git a/database/getOccupancyTypePrints.ts b/database/getContractTypePrints.ts similarity index 75% rename from database/getOccupancyTypePrints.ts rename to database/getContractTypePrints.ts index 38ec2dc3..a96061cf 100644 --- a/database/getOccupancyTypePrints.ts +++ b/database/getContractTypePrints.ts @@ -4,7 +4,7 @@ import { getConfigProperty } from '../helpers/config.helpers.js' import { acquireConnection } from './pool.js' -const availablePrints = getConfigProperty('settings.lotOccupancy.prints') +const availablePrints = getConfigProperty('settings.contracts.prints') // eslint-disable-next-line @typescript-eslint/naming-convention const userFunction_configContainsPrintEJS = (printEJS: string): number => { @@ -15,8 +15,8 @@ const userFunction_configContainsPrintEJS = (printEJS: string): number => { return 0 } -export default async function getOccupancyTypePrints( - occupancyTypeId: number, +export default async function getContractTypePrints( + contractTypeId: number, connectedDatabase?: PoolConnection ): Promise { const database = connectedDatabase ?? (await acquireConnection()) @@ -30,13 +30,13 @@ export default async function getOccupancyTypePrints( const results = database .prepare( `select printEJS, orderNumber - from OccupancyTypePrints + from ContractTypePrints where recordDelete_timeMillis is null - and occupancyTypeId = ? + and contractTypeId = ? and userFn_configContainsPrintEJS(printEJS) = 1 order by orderNumber, printEJS` ) - .all(occupancyTypeId) as Array<{ printEJS: string; orderNumber: number }> + .all(contractTypeId) as Array<{ printEJS: string; orderNumber: number }> let expectedOrderNumber = -1 @@ -48,12 +48,12 @@ export default async function getOccupancyTypePrints( if (result.orderNumber !== expectedOrderNumber) { database .prepare( - `update OccupancyTypePrints + `update ContractTypePrints set orderNumber = ? - where occupancyTypeId = ? + where contractTypeId = ? and printEJS = ?` ) - .run(expectedOrderNumber, occupancyTypeId, result.printEJS) + .run(expectedOrderNumber, contractTypeId, result.printEJS) } prints.push(result.printEJS) diff --git a/database/getContractTypes.d.ts b/database/getContractTypes.d.ts new file mode 100644 index 00000000..3e8cab74 --- /dev/null +++ b/database/getContractTypes.d.ts @@ -0,0 +1,2 @@ +import type { ContractType } from '../types/recordTypes.js'; +export default function getContractTypes(): Promise; diff --git a/database/getContractTypes.js b/database/getContractTypes.js new file mode 100644 index 00000000..e45d9875 --- /dev/null +++ b/database/getContractTypes.js @@ -0,0 +1,25 @@ +import getContractTypeFields from './getContractTypeFields.js'; +import getContractTypePrints from './getContractTypePrints.js'; +import { acquireConnection } from './pool.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; +export default async function getContractTypes() { + const database = await acquireConnection(); + const contractTypes = database + .prepare(`select contractTypeId, contractType, orderNumber + from ContractTypes + where recordDelete_timeMillis is null + order by orderNumber, contractType`) + .all(); + let expectedOrderNumber = -1; + for (const contractType of contractTypes) { + expectedOrderNumber += 1; + if (contractType.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber('ContractTypes', contractType.contractTypeId, expectedOrderNumber, database); + contractType.orderNumber = expectedOrderNumber; + } + contractType.contractTypeFields = await getContractTypeFields(contractType.contractTypeId, database); + contractType.contractTypePrints = await getContractTypePrints(contractType.contractTypeId, database); + } + database.release(); + return contractTypes; +} diff --git a/database/getContractTypes.ts b/database/getContractTypes.ts new file mode 100644 index 00000000..f7d99214 --- /dev/null +++ b/database/getContractTypes.ts @@ -0,0 +1,51 @@ +import type { ContractType } from '../types/recordTypes.js' + +import getContractTypeFields from './getContractTypeFields.js' +import getContractTypePrints from './getContractTypePrints.js' +import { acquireConnection } from './pool.js' +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' + +export default async function getContractTypes(): Promise { + const database = await acquireConnection() + + const contractTypes = database + .prepare( + `select contractTypeId, contractType, orderNumber + from ContractTypes + where recordDelete_timeMillis is null + order by orderNumber, contractType` + ) + .all() as ContractType[] + + let expectedOrderNumber = -1 + + for (const contractType of contractTypes) { + expectedOrderNumber += 1 + + if (contractType.orderNumber !== expectedOrderNumber) { + updateRecordOrderNumber( + 'ContractTypes', + contractType.contractTypeId, + expectedOrderNumber, + database + ) + + contractType.orderNumber = expectedOrderNumber + } + + contractType.contractTypeFields = await getContractTypeFields( + contractType.contractTypeId, + database + ) + + contractType.contractTypePrints = await getContractTypePrints( + contractType.contractTypeId, + database + ) + } + + database.release() + + return contractTypes +} + diff --git a/database/getLotComments.d.ts b/database/getLotComments.d.ts deleted file mode 100644 index e9645dd8..00000000 --- a/database/getLotComments.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -import type { LotComment } from '../types/recordTypes.js'; -export default function getLotComments(lotId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotFields.d.ts b/database/getLotFields.d.ts deleted file mode 100644 index 78b021fa..00000000 --- a/database/getLotFields.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -import type { LotField } from '../types/recordTypes.js'; -export default function getLotFields(lotId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotFields.js b/database/getLotFields.js deleted file mode 100644 index 5bbe3b06..00000000 --- a/database/getLotFields.js +++ /dev/null @@ -1,36 +0,0 @@ -import { acquireConnection } from './pool.js'; -export default async function getLotFields(lotId, connectedDatabase) { - const database = connectedDatabase ?? (await acquireConnection()); - const lotFields = database - .prepare(`select l.lotId, l.lotTypeFieldId, - l.lotFieldValue, - f.lotTypeField, f.fieldType, 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.fieldType, 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 === undefined) { - database.release(); - } - return lotFields; -} diff --git a/database/getLotFields.ts b/database/getLotFields.ts deleted file mode 100644 index 584ed37e..00000000 --- a/database/getLotFields.ts +++ /dev/null @@ -1,49 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool' - -import type { LotField } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' - -export default async function getLotFields( - lotId: number | string, - connectedDatabase?: PoolConnection -): Promise { - const database = connectedDatabase ?? (await acquireConnection()) - - const lotFields = database - .prepare( - `select l.lotId, l.lotTypeFieldId, - l.lotFieldValue, - f.lotTypeField, f.fieldType, 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.fieldType, 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) as LotField[] - - if (connectedDatabase === undefined) { - database.release() - } - - return lotFields -} diff --git a/database/getLotOccupancies.d.ts b/database/getLotOccupancies.d.ts deleted file mode 100644 index 0fa4579b..00000000 --- a/database/getLotOccupancies.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { type DateString } from '@cityssm/utils-datetime'; -import type { PoolConnection } from 'better-sqlite-pool'; -import type { LotOccupancy } from '../types/recordTypes.js'; -interface GetLotOccupanciesFilters { - lotId?: number | string; - occupancyTime?: '' | 'past' | 'current' | 'future'; - occupancyStartDateString?: DateString; - occupancyEffectiveDateString?: string; - occupantName?: string; - occupancyTypeId?: number | string; - mapId?: number | string; - lotNameSearchType?: '' | 'startsWith' | 'endsWith'; - lotName?: string; - lotTypeId?: number | string; - workOrderId?: number | string; - notWorkOrderId?: number | string; -} -interface GetLotOccupanciesOptions { - limit: -1 | number; - offset: number; - includeOccupants: boolean; - includeFees: boolean; - includeTransactions: boolean; -} -export default function getLotOccupancies(filters: GetLotOccupanciesFilters, options: GetLotOccupanciesOptions, connectedDatabase?: PoolConnection): Promise<{ - count: number; - lotOccupancies: LotOccupancy[]; -}>; -export {}; diff --git a/database/getLotOccupancies.js b/database/getLotOccupancies.js deleted file mode 100644 index 04556fe0..00000000 --- a/database/getLotOccupancies.js +++ /dev/null @@ -1,133 +0,0 @@ -import { dateIntegerToString, dateStringToInteger } from '@cityssm/utils-datetime'; -import { getOccupancyTypeById } from '../helpers/functions.cache.js'; -import { getConfigProperty } from '../helpers/config.helpers.js'; -import { getLotNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWhereClause } from '../helpers/functions.sqlFilters.js'; -import getLotOccupancyFees from './getLotOccupancyFees.js'; -import getLotOccupancyOccupants from './getLotOccupancyOccupants.js'; -import getLotOccupancyTransactions from './getLotOccupancyTransactions.js'; -import { acquireConnection } from './pool.js'; -function buildWhereClause(filters) { - let sqlWhereClause = ' where o.recordDelete_timeMillis is null'; - const sqlParameters = []; - if ((filters.lotId ?? '') !== '') { - sqlWhereClause += ' and o.lotId = ?'; - sqlParameters.push(filters.lotId); - } - const lotNameFilters = getLotNameWhereClause(filters.lotName, filters.lotNameSearchType ?? '', 'l'); - sqlWhereClause += lotNameFilters.sqlWhereClause; - sqlParameters.push(...lotNameFilters.sqlParameters); - const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, 'o'); - if (occupantNameFilters.sqlParameters.length > 0) { - sqlWhereClause += - ` and o.lotOccupancyId in ( - select lotOccupancyId from LotOccupancyOccupants o - where recordDelete_timeMillis is null - ${occupantNameFilters.sqlWhereClause})`; - sqlParameters.push(...occupantNameFilters.sqlParameters); - } - if ((filters.occupancyTypeId ?? '') !== '') { - sqlWhereClause += ' and o.occupancyTypeId = ?'; - sqlParameters.push(filters.occupancyTypeId); - } - const occupancyTimeFilters = getOccupancyTimeWhereClause(filters.occupancyTime ?? '', 'o'); - sqlWhereClause += occupancyTimeFilters.sqlWhereClause; - sqlParameters.push(...occupancyTimeFilters.sqlParameters); - if ((filters.occupancyStartDateString ?? '') !== '') { - sqlWhereClause += ' and o.occupancyStartDate = ?'; - sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString)); - } - if ((filters.occupancyEffectiveDateString ?? '') !== '') { - sqlWhereClause += ` and ( - o.occupancyEndDate is null - or (o.occupancyStartDate <= ? and o.occupancyEndDate >= ?) - )`; - sqlParameters.push(dateStringToInteger(filters.occupancyEffectiveDateString), dateStringToInteger(filters.occupancyEffectiveDateString)); - } - if ((filters.mapId ?? '') !== '') { - sqlWhereClause += ' and l.mapId = ?'; - sqlParameters.push(filters.mapId); - } - if ((filters.lotTypeId ?? '') !== '') { - sqlWhereClause += ' and l.lotTypeId = ?'; - sqlParameters.push(filters.lotTypeId); - } - if ((filters.workOrderId ?? '') !== '') { - sqlWhereClause += - ' and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)'; - sqlParameters.push(filters.workOrderId); - } - if ((filters.notWorkOrderId ?? '') !== '') { - sqlWhereClause += - ' and o.lotOccupancyId not in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)'; - sqlParameters.push(filters.notWorkOrderId); - } - return { - sqlWhereClause, - sqlParameters - }; -} -async function addInclusions(lotOccupancy, options, database) { - if (options.includeFees) { - lotOccupancy.lotOccupancyFees = await getLotOccupancyFees(lotOccupancy.lotOccupancyId, database); - } - if (options.includeTransactions) { - lotOccupancy.lotOccupancyTransactions = await getLotOccupancyTransactions(lotOccupancy.lotOccupancyId, { includeIntegrations: false }, database); - } - if (options.includeOccupants) { - lotOccupancy.lotOccupancyOccupants = await getLotOccupancyOccupants(lotOccupancy.lotOccupancyId, database); - } - return lotOccupancy; -} -export default async function getLotOccupancies(filters, options, connectedDatabase) { - const database = connectedDatabase ?? (await acquireConnection()); - database.function('userFn_dateIntegerToString', dateIntegerToString); - const { sqlWhereClause, sqlParameters } = buildWhereClause(filters); - let count = options.limit; - const isLimited = options.limit !== -1; - if (isLimited) { - count = database - .prepare(`select count(*) as recordCount - from LotOccupancies o - left join Lots l on o.lotId = l.lotId - ${sqlWhereClause}`) - .get(sqlParameters).recordCount; - } - let lotOccupancies = []; - if (count !== 0) { - lotOccupancies = database - .prepare(`select o.lotOccupancyId, - o.occupancyTypeId, t.occupancyType, - o.lotId, lt.lotType, l.lotName, - l.mapId, m.mapName, - o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString, - o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString - from LotOccupancies o - left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId - left join Lots l on o.lotId = l.lotId - left join LotTypes lt on l.lotTypeId = lt.lotTypeId - left join Maps m on l.mapId = m.mapId - ${sqlWhereClause} - order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc - ${isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''}`) - .all(sqlParameters); - if (!isLimited) { - count = lotOccupancies.length; - } - for (const lotOccupancy of lotOccupancies) { - const occupancyType = await getOccupancyTypeById(lotOccupancy.occupancyTypeId); - if (occupancyType !== undefined) { - lotOccupancy.printEJS = (occupancyType.occupancyTypePrints ?? []).includes('*') - ? getConfigProperty('settings.lotOccupancy.prints')[0] - : occupancyType.occupancyTypePrints[0]; - } - await addInclusions(lotOccupancy, options, database); - } - } - if (connectedDatabase === undefined) { - database.release(); - } - return { - count, - lotOccupancies - }; -} diff --git a/database/getLotOccupancies.ts b/database/getLotOccupancies.ts deleted file mode 100644 index 41df0061..00000000 --- a/database/getLotOccupancies.ts +++ /dev/null @@ -1,247 +0,0 @@ -import { - type DateString, - dateIntegerToString, - dateStringToInteger -} from '@cityssm/utils-datetime' -import type { PoolConnection } from 'better-sqlite-pool' - -import { getOccupancyTypeById } from '../helpers/functions.cache.js' -import { getConfigProperty } from '../helpers/config.helpers.js' -import { - getLotNameWhereClause, - getOccupancyTimeWhereClause, - getOccupantNameWhereClause -} from '../helpers/functions.sqlFilters.js' -import type { LotOccupancy } from '../types/recordTypes.js' - -import getLotOccupancyFees from './getLotOccupancyFees.js' -import getLotOccupancyOccupants from './getLotOccupancyOccupants.js' -import getLotOccupancyTransactions from './getLotOccupancyTransactions.js' -import { acquireConnection } from './pool.js' - -interface GetLotOccupanciesFilters { - lotId?: number | string - occupancyTime?: '' | 'past' | 'current' | 'future' - occupancyStartDateString?: DateString - occupancyEffectiveDateString?: string - occupantName?: string - occupancyTypeId?: number | string - mapId?: number | string - lotNameSearchType?: '' | 'startsWith' | 'endsWith' - lotName?: string - lotTypeId?: number | string - workOrderId?: number | string - notWorkOrderId?: number | string -} - -interface GetLotOccupanciesOptions { - limit: -1 | number - offset: number - includeOccupants: boolean - includeFees: boolean - includeTransactions: boolean -} - -function buildWhereClause(filters: GetLotOccupanciesFilters): { - sqlWhereClause: string - sqlParameters: unknown[] -} { - let sqlWhereClause = ' where o.recordDelete_timeMillis is null' - const sqlParameters: unknown[] = [] - - if ((filters.lotId ?? '') !== '') { - sqlWhereClause += ' and o.lotId = ?' - sqlParameters.push(filters.lotId) - } - - const lotNameFilters = getLotNameWhereClause( - filters.lotName, - filters.lotNameSearchType ?? '', - 'l' - ) - sqlWhereClause += lotNameFilters.sqlWhereClause - sqlParameters.push(...lotNameFilters.sqlParameters) - - const occupantNameFilters = getOccupantNameWhereClause( - filters.occupantName, - 'o' - ) - if (occupantNameFilters.sqlParameters.length > 0) { - sqlWhereClause += - ` and o.lotOccupancyId in ( - select lotOccupancyId from LotOccupancyOccupants o - where recordDelete_timeMillis is null - ${occupantNameFilters.sqlWhereClause})` - sqlParameters.push(...occupantNameFilters.sqlParameters) - } - - if ((filters.occupancyTypeId ?? '') !== '') { - sqlWhereClause += ' and o.occupancyTypeId = ?' - sqlParameters.push(filters.occupancyTypeId) - } - - const occupancyTimeFilters = getOccupancyTimeWhereClause( - filters.occupancyTime ?? '', - 'o' - ) - sqlWhereClause += occupancyTimeFilters.sqlWhereClause - sqlParameters.push(...occupancyTimeFilters.sqlParameters) - - if ((filters.occupancyStartDateString ?? '') !== '') { - sqlWhereClause += ' and o.occupancyStartDate = ?' - sqlParameters.push( - dateStringToInteger(filters.occupancyStartDateString as DateString) - ) - } - - if ((filters.occupancyEffectiveDateString ?? '') !== '') { - sqlWhereClause += ` and ( - o.occupancyEndDate is null - or (o.occupancyStartDate <= ? and o.occupancyEndDate >= ?) - )` - sqlParameters.push( - dateStringToInteger(filters.occupancyEffectiveDateString as DateString), - dateStringToInteger(filters.occupancyEffectiveDateString as DateString) - ) - } - - if ((filters.mapId ?? '') !== '') { - sqlWhereClause += ' and l.mapId = ?' - sqlParameters.push(filters.mapId) - } - - if ((filters.lotTypeId ?? '') !== '') { - sqlWhereClause += ' and l.lotTypeId = ?' - sqlParameters.push(filters.lotTypeId) - } - - if ((filters.workOrderId ?? '') !== '') { - sqlWhereClause += - ' and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)' - sqlParameters.push(filters.workOrderId) - } - - if ((filters.notWorkOrderId ?? '') !== '') { - sqlWhereClause += - ' and o.lotOccupancyId not in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)' - sqlParameters.push(filters.notWorkOrderId) - } - - return { - sqlWhereClause, - sqlParameters - } -} - -async function addInclusions( - lotOccupancy: LotOccupancy, - options: GetLotOccupanciesOptions, - database: PoolConnection -): Promise { - if (options.includeFees) { - lotOccupancy.lotOccupancyFees = await getLotOccupancyFees( - lotOccupancy.lotOccupancyId, - database - ) - } - - if (options.includeTransactions) { - lotOccupancy.lotOccupancyTransactions = await getLotOccupancyTransactions( - lotOccupancy.lotOccupancyId, - { includeIntegrations: false }, - database - ) - } - - if (options.includeOccupants) { - lotOccupancy.lotOccupancyOccupants = await getLotOccupancyOccupants( - lotOccupancy.lotOccupancyId, - database - ) - } - - return lotOccupancy -} - -export default async function getLotOccupancies( - filters: GetLotOccupanciesFilters, - options: GetLotOccupanciesOptions, - connectedDatabase?: PoolConnection -): Promise<{ count: number; lotOccupancies: LotOccupancy[] }> { - const database = connectedDatabase ?? (await acquireConnection()) - - database.function('userFn_dateIntegerToString', dateIntegerToString) - - const { sqlWhereClause, sqlParameters } = buildWhereClause(filters) - - let count = options.limit - - const isLimited = options.limit !== -1 - - if (isLimited) { - count = ( - database - .prepare( - `select count(*) as recordCount - from LotOccupancies o - left join Lots l on o.lotId = l.lotId - ${sqlWhereClause}` - ) - .get(sqlParameters) as { recordCount: number } - ).recordCount - } - - let lotOccupancies: LotOccupancy[] = [] - - if (count !== 0) { - lotOccupancies = database - .prepare( - `select o.lotOccupancyId, - o.occupancyTypeId, t.occupancyType, - o.lotId, lt.lotType, l.lotName, - l.mapId, m.mapName, - o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString, - o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString - from LotOccupancies o - left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId - left join Lots l on o.lotId = l.lotId - left join LotTypes lt on l.lotTypeId = lt.lotTypeId - left join Maps m on l.mapId = m.mapId - ${sqlWhereClause} - order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc - ${ - isLimited ? ` limit ${options.limit} offset ${options.offset}` : '' - }` - ) - .all(sqlParameters) as LotOccupancy[] - - if (!isLimited) { - count = lotOccupancies.length - } - - for (const lotOccupancy of lotOccupancies) { - const occupancyType = await getOccupancyTypeById( - lotOccupancy.occupancyTypeId! - ) - - if (occupancyType !== undefined) { - lotOccupancy.printEJS = ( - occupancyType.occupancyTypePrints ?? [] - ).includes('*') - ? getConfigProperty('settings.lotOccupancy.prints')[0] - : occupancyType.occupancyTypePrints![0] - } - - await addInclusions(lotOccupancy, options, database) - } - } - - if (connectedDatabase === undefined) { - database.release() - } - - return { - count, - lotOccupancies - } -} diff --git a/database/getLotOccupancy.d.ts b/database/getLotOccupancy.d.ts deleted file mode 100644 index a776e85f..00000000 --- a/database/getLotOccupancy.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -import type { LotOccupancy } from '../types/recordTypes.js'; -export default function getLotOccupancy(lotOccupancyId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotOccupancy.js b/database/getLotOccupancy.js deleted file mode 100644 index e3f3f475..00000000 --- a/database/getLotOccupancy.js +++ /dev/null @@ -1,45 +0,0 @@ -import { dateIntegerToString } from '@cityssm/utils-datetime'; -import getLotOccupancyComments from './getLotOccupancyComments.js'; -import getLotOccupancyFees from './getLotOccupancyFees.js'; -import getLotOccupancyFields from './getLotOccupancyFields.js'; -import getLotOccupancyOccupants from './getLotOccupancyOccupants.js'; -import getLotOccupancyTransactions from './getLotOccupancyTransactions.js'; -import { getWorkOrders } from './getWorkOrders.js'; -import { acquireConnection } from './pool.js'; -export default async function getLotOccupancy(lotOccupancyId, connectedDatabase) { - const database = connectedDatabase ?? (await acquireConnection()); - 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 = ?`) - .get(lotOccupancyId); - if (lotOccupancy !== undefined) { - lotOccupancy.lotOccupancyFields = await getLotOccupancyFields(lotOccupancyId, database); - lotOccupancy.lotOccupancyOccupants = await getLotOccupancyOccupants(lotOccupancyId, database); - lotOccupancy.lotOccupancyComments = await getLotOccupancyComments(lotOccupancyId, database); - lotOccupancy.lotOccupancyFees = await getLotOccupancyFees(lotOccupancyId, database); - lotOccupancy.lotOccupancyTransactions = await getLotOccupancyTransactions(lotOccupancyId, { includeIntegrations: true }, database); - const workOrdersResults = await getWorkOrders({ - lotOccupancyId - }, { - limit: -1, - offset: 0 - }, database); - lotOccupancy.workOrders = workOrdersResults.workOrders; - } - if (connectedDatabase === undefined) { - database.release(); - } - return lotOccupancy; -} diff --git a/database/getLotOccupancy.ts b/database/getLotOccupancy.ts deleted file mode 100644 index 03b30b00..00000000 --- a/database/getLotOccupancy.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { dateIntegerToString } from '@cityssm/utils-datetime' -import type { PoolConnection } from 'better-sqlite-pool' - -import type { LotOccupancy } from '../types/recordTypes.js' - -import getLotOccupancyComments from './getLotOccupancyComments.js' -import getLotOccupancyFees from './getLotOccupancyFees.js' -import getLotOccupancyFields from './getLotOccupancyFields.js' -import getLotOccupancyOccupants from './getLotOccupancyOccupants.js' -import getLotOccupancyTransactions from './getLotOccupancyTransactions.js' -import { getWorkOrders } from './getWorkOrders.js' -import { acquireConnection } from './pool.js' - -export default async function getLotOccupancy( - lotOccupancyId: number | string, - connectedDatabase?: PoolConnection -): Promise { - const database = connectedDatabase ?? (await acquireConnection()) - - 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 = ?` - ) - .get(lotOccupancyId) as LotOccupancy | undefined - - if (lotOccupancy !== undefined) { - lotOccupancy.lotOccupancyFields = await getLotOccupancyFields( - lotOccupancyId, - database - ) - lotOccupancy.lotOccupancyOccupants = await getLotOccupancyOccupants( - lotOccupancyId, - database - ) - lotOccupancy.lotOccupancyComments = await getLotOccupancyComments( - lotOccupancyId, - database - ) - lotOccupancy.lotOccupancyFees = await getLotOccupancyFees( - lotOccupancyId, - database - ) - lotOccupancy.lotOccupancyTransactions = await getLotOccupancyTransactions( - lotOccupancyId, - { includeIntegrations: true }, - database - ) - - const workOrdersResults = await getWorkOrders( - { - lotOccupancyId - }, - { - limit: -1, - offset: 0 - }, - database - ) - - lotOccupancy.workOrders = workOrdersResults.workOrders - } - - if (connectedDatabase === undefined) { - database.release() - } - - return lotOccupancy -} diff --git a/database/getLotOccupancyComments.d.ts b/database/getLotOccupancyComments.d.ts deleted file mode 100644 index e273573c..00000000 --- a/database/getLotOccupancyComments.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -import type { LotOccupancyComment } from '../types/recordTypes.js'; -export default function getLotOccupancyComments(lotOccupancyId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotOccupancyComments.js b/database/getLotOccupancyComments.js deleted file mode 100644 index 11c50c9e..00000000 --- a/database/getLotOccupancyComments.js +++ /dev/null @@ -1,27 +0,0 @@ -import { dateIntegerToString, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime'; -import { acquireConnection } from './pool.js'; -export default async function getLotOccupancyComments(lotOccupancyId, connectedDatabase) { - const database = connectedDatabase ?? (await acquireConnection()); - database.function('userFn_dateIntegerToString', dateIntegerToString); - database.function('userFn_timeIntegerToString', timeIntegerToString); - database.function('userFn_timeIntegerToPeriodString', timeIntegerToPeriodString); - const lotComments = database - .prepare( - // eslint-disable-next-line no-secrets/no-secrets - `select lotOccupancyCommentId, - lotOccupancyCommentDate, userFn_dateIntegerToString(lotOccupancyCommentDate) as lotOccupancyCommentDateString, - lotOccupancyCommentTime, - userFn_timeIntegerToString(lotOccupancyCommentTime) as lotOccupancyCommentTimeString, - userFn_timeIntegerToPeriodString(lotOccupancyCommentTime) as lotOccupancyCommentTimePeriodString, - lotOccupancyComment, - recordCreate_userName, recordUpdate_userName - from LotOccupancyComments - where recordDelete_timeMillis is null - and lotOccupancyId = ? - order by lotOccupancyCommentDate desc, lotOccupancyCommentTime desc, lotOccupancyCommentId desc`) - .all(lotOccupancyId); - if (connectedDatabase === undefined) { - database.release(); - } - return lotComments; -} diff --git a/database/getLotOccupancyComments.ts b/database/getLotOccupancyComments.ts deleted file mode 100644 index c2022dbb..00000000 --- a/database/getLotOccupancyComments.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { - dateIntegerToString, - timeIntegerToPeriodString, - timeIntegerToString -} from '@cityssm/utils-datetime' -import type { PoolConnection } from 'better-sqlite-pool' - -import type { LotOccupancyComment } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' - -export default async function getLotOccupancyComments( - lotOccupancyId: number | string, - connectedDatabase?: PoolConnection -): Promise { - const database = connectedDatabase ?? (await acquireConnection()) - - database.function('userFn_dateIntegerToString', dateIntegerToString) - database.function('userFn_timeIntegerToString', timeIntegerToString) - database.function( - 'userFn_timeIntegerToPeriodString', - timeIntegerToPeriodString - ) - - const lotComments = database - .prepare( - // eslint-disable-next-line no-secrets/no-secrets - `select lotOccupancyCommentId, - lotOccupancyCommentDate, userFn_dateIntegerToString(lotOccupancyCommentDate) as lotOccupancyCommentDateString, - lotOccupancyCommentTime, - userFn_timeIntegerToString(lotOccupancyCommentTime) as lotOccupancyCommentTimeString, - userFn_timeIntegerToPeriodString(lotOccupancyCommentTime) as lotOccupancyCommentTimePeriodString, - lotOccupancyComment, - recordCreate_userName, recordUpdate_userName - from LotOccupancyComments - where recordDelete_timeMillis is null - and lotOccupancyId = ? - order by lotOccupancyCommentDate desc, lotOccupancyCommentTime desc, lotOccupancyCommentId desc` - ) - .all(lotOccupancyId) as LotOccupancyComment[] - - if (connectedDatabase === undefined) { - database.release() - } - - return lotComments -} diff --git a/database/getLotOccupancyFees.d.ts b/database/getLotOccupancyFees.d.ts deleted file mode 100644 index 90d813b3..00000000 --- a/database/getLotOccupancyFees.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -import type { LotOccupancyFee } from '../types/recordTypes.js'; -export default function getLotOccupancyFees(lotOccupancyId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotOccupancyFields.d.ts b/database/getLotOccupancyFields.d.ts deleted file mode 100644 index 33efacb2..00000000 --- a/database/getLotOccupancyFields.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -import type { LotOccupancyField } from '../types/recordTypes.js'; -export default function getLotOccupancyFields(lotOccupancyId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotOccupancyFields.js b/database/getLotOccupancyFields.js deleted file mode 100644 index 0ade2ce2..00000000 --- a/database/getLotOccupancyFields.js +++ /dev/null @@ -1,33 +0,0 @@ -import { acquireConnection } from './pool.js'; -export default async function getLotOccupancyFields(lotOccupancyId, connectedDatabase) { - const database = connectedDatabase ?? (await acquireConnection()); - const lotOccupancyFields = database - .prepare(`select o.lotOccupancyId, o.occupancyTypeFieldId, - o.lotOccupancyFieldValue, f.occupancyTypeField, f.fieldType, 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.fieldType, 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 === undefined) { - database.release(); - } - return lotOccupancyFields; -} diff --git a/database/getLotOccupancyFields.ts b/database/getLotOccupancyFields.ts deleted file mode 100644 index 2685d615..00000000 --- a/database/getLotOccupancyFields.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool' - -import type { LotOccupancyField } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' - -export default async function getLotOccupancyFields( - lotOccupancyId: number | string, - connectedDatabase?: PoolConnection -): Promise { - const database = connectedDatabase ?? (await acquireConnection()) - - const lotOccupancyFields = database - .prepare( - `select o.lotOccupancyId, o.occupancyTypeFieldId, - o.lotOccupancyFieldValue, f.occupancyTypeField, f.fieldType, 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.fieldType, 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 - ) as LotOccupancyField[] - - if (connectedDatabase === undefined) { - database.release() - } - - return lotOccupancyFields -} diff --git a/database/getLotOccupancyOccupants.d.ts b/database/getLotOccupancyOccupants.d.ts deleted file mode 100644 index de560baa..00000000 --- a/database/getLotOccupancyOccupants.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -import type { LotOccupancyOccupant } from '../types/recordTypes.js'; -export default function getLotOccupancyOccupants(lotOccupancyId: number | string, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotOccupancyOccupants.js b/database/getLotOccupancyOccupants.js deleted file mode 100644 index 43526dec..00000000 --- a/database/getLotOccupancyOccupants.js +++ /dev/null @@ -1,23 +0,0 @@ -import { acquireConnection } from './pool.js'; -export default async function getLotOccupancyOccupants(lotOccupancyId, connectedDatabase) { - const database = connectedDatabase ?? (await acquireConnection()); - const lotOccupancyOccupants = database - .prepare(`select o.lotOccupancyId, o.lotOccupantIndex, - o.occupantName, o.occupantFamilyName, - o.occupantAddress1, o.occupantAddress2, - o.occupantCity, o.occupantProvince, o.occupantPostalCode, - o.occupantPhoneNumber, o.occupantEmailAddress, - o.occupantComment, - o.lotOccupantTypeId, t.lotOccupantType, - t.fontAwesomeIconClass, t.occupantCommentTitle - from LotOccupancyOccupants o - left join LotOccupantTypes t on o.lotOccupantTypeId = t.lotOccupantTypeId - where o.recordDelete_timeMillis is null - and o.lotOccupancyId = ? - order by t.orderNumber, t.lotOccupantType, o.occupantName, o.lotOccupantIndex`) - .all(lotOccupancyId); - if (connectedDatabase === undefined) { - database.release(); - } - return lotOccupancyOccupants; -} diff --git a/database/getLotOccupancyOccupants.ts b/database/getLotOccupancyOccupants.ts deleted file mode 100644 index 94c24d52..00000000 --- a/database/getLotOccupancyOccupants.ts +++ /dev/null @@ -1,36 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool' - -import type { LotOccupancyOccupant } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' - -export default async function getLotOccupancyOccupants( - lotOccupancyId: number | string, - connectedDatabase?: PoolConnection -): Promise { - const database = connectedDatabase ?? (await acquireConnection()) - - const lotOccupancyOccupants = database - .prepare( - `select o.lotOccupancyId, o.lotOccupantIndex, - o.occupantName, o.occupantFamilyName, - o.occupantAddress1, o.occupantAddress2, - o.occupantCity, o.occupantProvince, o.occupantPostalCode, - o.occupantPhoneNumber, o.occupantEmailAddress, - o.occupantComment, - o.lotOccupantTypeId, t.lotOccupantType, - t.fontAwesomeIconClass, t.occupantCommentTitle - from LotOccupancyOccupants o - left join LotOccupantTypes t on o.lotOccupantTypeId = t.lotOccupantTypeId - where o.recordDelete_timeMillis is null - and o.lotOccupancyId = ? - order by t.orderNumber, t.lotOccupantType, o.occupantName, o.lotOccupantIndex` - ) - .all(lotOccupancyId) as LotOccupancyOccupant[] - - if (connectedDatabase === undefined) { - database.release() - } - - return lotOccupancyOccupants -} diff --git a/database/getLotOccupancyTransactions.d.ts b/database/getLotOccupancyTransactions.d.ts deleted file mode 100644 index aede8712..00000000 --- a/database/getLotOccupancyTransactions.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -import type { LotOccupancyTransaction } from '../types/recordTypes.js'; -export default function getLotOccupancyTransactions(lotOccupancyId: number | string, options: { - includeIntegrations: boolean; -}, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotOccupantTypes.d.ts b/database/getLotOccupantTypes.d.ts deleted file mode 100644 index bfa475d7..00000000 --- a/database/getLotOccupantTypes.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { LotOccupantType } from '../types/recordTypes.js'; -export default function getLotOccupantTypes(): Promise; diff --git a/database/getLotOccupantTypes.js b/database/getLotOccupantTypes.js deleted file mode 100644 index e270a5e7..00000000 --- a/database/getLotOccupantTypes.js +++ /dev/null @@ -1,22 +0,0 @@ -import { acquireConnection } from './pool.js'; -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; -export default async function getLotOccupantTypes() { - const database = await acquireConnection(); - const lotOccupantTypes = database - .prepare(`select lotOccupantTypeId, lotOccupantType, fontAwesomeIconClass, occupantCommentTitle, - orderNumber - 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); - lotOccupantType.orderNumber = expectedOrderNumber; - } - expectedOrderNumber += 1; - } - database.release(); - return lotOccupantTypes; -} diff --git a/database/getLotOccupantTypes.ts b/database/getLotOccupantTypes.ts deleted file mode 100644 index f49ef5a0..00000000 --- a/database/getLotOccupantTypes.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type { LotOccupantType } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' - -export default async function getLotOccupantTypes(): Promise< - LotOccupantType[] -> { - const database = await acquireConnection() - - const lotOccupantTypes = database - .prepare( - `select lotOccupantTypeId, lotOccupantType, fontAwesomeIconClass, occupantCommentTitle, - orderNumber - from LotOccupantTypes - where recordDelete_timeMillis is null - order by orderNumber, lotOccupantType` - ) - .all() as LotOccupantType[] - - let expectedOrderNumber = 0 - - for (const lotOccupantType of lotOccupantTypes) { - if (lotOccupantType.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber( - 'LotOccupantTypes', - lotOccupantType.lotOccupantTypeId, - expectedOrderNumber, - database - ) - - lotOccupantType.orderNumber = expectedOrderNumber - } - - expectedOrderNumber += 1 - } - - database.release() - - return lotOccupantTypes -} diff --git a/database/getLotStatusSummary.d.ts b/database/getLotStatusSummary.d.ts deleted file mode 100644 index 00b5becc..00000000 --- a/database/getLotStatusSummary.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { LotStatus } from '../types/recordTypes.js'; -interface GetFilters { - mapId?: number | string; -} -interface LotStatusSummary extends LotStatus { - lotCount: number; -} -export default function getLotStatusSummary(filters: GetFilters): Promise; -export {}; diff --git a/database/getLotStatusSummary.js b/database/getLotStatusSummary.js deleted file mode 100644 index 4fe4ad7f..00000000 --- a/database/getLotStatusSummary.js +++ /dev/null @@ -1,20 +0,0 @@ -import { acquireConnection } from './pool.js'; -export default async function getLotStatusSummary(filters) { - const database = await acquireConnection(); - let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; - const sqlParameters = []; - 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 - ${sqlWhereClause} - group by s.lotStatusId, s.lotStatus, s.orderNumber - order by s.orderNumber`) - .all(sqlParameters); - database.release(); - return lotStatuses; -} diff --git a/database/getLotStatusSummary.ts b/database/getLotStatusSummary.ts deleted file mode 100644 index ccbbc26c..00000000 --- a/database/getLotStatusSummary.ts +++ /dev/null @@ -1,40 +0,0 @@ -import type { LotStatus } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' - -interface GetFilters { - mapId?: number | string -} - -interface LotStatusSummary extends LotStatus { - lotCount: number -} - -export default async function getLotStatusSummary( - filters: GetFilters -): Promise { - const database = await acquireConnection() - - let sqlWhereClause = ' where l.recordDelete_timeMillis is null' - const sqlParameters: unknown[] = [] - - 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 - ${sqlWhereClause} - group by s.lotStatusId, s.lotStatus, s.orderNumber - order by s.orderNumber` - ) - .all(sqlParameters) as LotStatusSummary[] - - database.release() - - return lotStatuses -} diff --git a/database/getLotStatuses.d.ts b/database/getLotStatuses.d.ts deleted file mode 100644 index 58bafad8..00000000 --- a/database/getLotStatuses.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { LotStatus } from '../types/recordTypes.js'; -export default function getLotStatuses(): Promise; diff --git a/database/getLotStatuses.js b/database/getLotStatuses.js deleted file mode 100644 index 9426c206..00000000 --- a/database/getLotStatuses.js +++ /dev/null @@ -1,21 +0,0 @@ -import { acquireConnection } from './pool.js'; -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; -export default async function getLotStatuses() { - const database = await acquireConnection(); - const lotStatuses = database - .prepare(`select lotStatusId, lotStatus, orderNumber - 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); - lotStatus.orderNumber = expectedOrderNumber; - } - expectedOrderNumber += 1; - } - database.release(); - return lotStatuses; -} diff --git a/database/getLotStatuses.ts b/database/getLotStatuses.ts deleted file mode 100644 index f81a5e89..00000000 --- a/database/getLotStatuses.ts +++ /dev/null @@ -1,37 +0,0 @@ -import type { LotStatus } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' - -export default async function getLotStatuses(): Promise { - const database = await acquireConnection() - - const lotStatuses = database - .prepare( - `select lotStatusId, lotStatus, orderNumber - from LotStatuses - where recordDelete_timeMillis is null - order by orderNumber, lotStatus` - ) - .all() as LotStatus[] - - let expectedOrderNumber = 0 - - for (const lotStatus of lotStatuses) { - if (lotStatus.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber( - 'LotStatuses', - lotStatus.lotStatusId, - expectedOrderNumber, - database - ) - lotStatus.orderNumber = expectedOrderNumber - } - - expectedOrderNumber += 1 - } - - database.release() - - return lotStatuses -} diff --git a/database/getLotTypeFields.d.ts b/database/getLotTypeFields.d.ts deleted file mode 100644 index aa98b0a0..00000000 --- a/database/getLotTypeFields.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -import type { LotTypeField } from '../types/recordTypes.js'; -export default function getLotTypeFields(lotTypeId: number, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getLotTypeFields.js b/database/getLotTypeFields.js deleted file mode 100644 index f47d0751..00000000 --- a/database/getLotTypeFields.js +++ /dev/null @@ -1,26 +0,0 @@ -import { acquireConnection } from './pool.js'; -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; -export default async function getLotTypeFields(lotTypeId, connectedDatabase) { - const database = connectedDatabase ?? (await acquireConnection()); - const lotTypeFields = database - .prepare(`select lotTypeFieldId, - lotTypeField, fieldType, 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); - lotTypeField.orderNumber = expectedOrderNumber; - } - expectedOrderNumber += 1; - } - if (connectedDatabase === undefined) { - database.release(); - } - return lotTypeFields; -} diff --git a/database/getLotTypeFields.ts b/database/getLotTypeFields.ts deleted file mode 100644 index 3794721b..00000000 --- a/database/getLotTypeFields.ts +++ /dev/null @@ -1,48 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool' - -import type { LotTypeField } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' - -export default async function getLotTypeFields( - lotTypeId: number, - connectedDatabase?: PoolConnection -): Promise { - const database = connectedDatabase ?? (await acquireConnection()) - - const lotTypeFields = database - .prepare( - `select lotTypeFieldId, - lotTypeField, fieldType, lotTypeFieldValues, - isRequired, pattern, minimumLength, maximumLength, orderNumber - from LotTypeFields - where recordDelete_timeMillis is null - and lotTypeId = ? - order by orderNumber, lotTypeField` - ) - .all(lotTypeId) as LotTypeField[] - - let expectedOrderNumber = 0 - - for (const lotTypeField of lotTypeFields) { - if (lotTypeField.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber( - 'LotTypeFields', - lotTypeField.lotTypeFieldId, - expectedOrderNumber, - database - ) - - lotTypeField.orderNumber = expectedOrderNumber - } - - expectedOrderNumber += 1 - } - - if (connectedDatabase === undefined) { - database.release() - } - - return lotTypeFields -} diff --git a/database/getLotTypeSummary.d.ts b/database/getLotTypeSummary.d.ts deleted file mode 100644 index aed6af2c..00000000 --- a/database/getLotTypeSummary.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { LotType } from '../types/recordTypes.js'; -interface GetFilters { - mapId?: number | string; -} -interface LotTypeSummary extends LotType { - lotCount: number; -} -export default function getLotTypeSummary(filters: GetFilters): Promise; -export {}; diff --git a/database/getLotTypeSummary.js b/database/getLotTypeSummary.js deleted file mode 100644 index 14cd7a9a..00000000 --- a/database/getLotTypeSummary.js +++ /dev/null @@ -1,20 +0,0 @@ -import { acquireConnection } from './pool.js'; -export default async function getLotTypeSummary(filters) { - const database = await acquireConnection(); - let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; - const sqlParameters = []; - 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 - ${sqlWhereClause} - group by t.lotTypeId, t.lotType, t.orderNumber - order by t.orderNumber`) - .all(sqlParameters); - database.release(); - return lotTypes; -} diff --git a/database/getLotTypeSummary.ts b/database/getLotTypeSummary.ts deleted file mode 100644 index dfe6ae4e..00000000 --- a/database/getLotTypeSummary.ts +++ /dev/null @@ -1,40 +0,0 @@ -import type { LotType } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' - -interface GetFilters { - mapId?: number | string -} - -interface LotTypeSummary extends LotType { - lotCount: number -} - -export default async function getLotTypeSummary( - filters: GetFilters -): Promise { - const database = await acquireConnection() - - let sqlWhereClause = ' where l.recordDelete_timeMillis is null' - const sqlParameters: unknown[] = [] - - 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 - ${sqlWhereClause} - group by t.lotTypeId, t.lotType, t.orderNumber - order by t.orderNumber` - ) - .all(sqlParameters) as LotTypeSummary[] - - database.release() - - return lotTypes -} diff --git a/database/getLotTypes.d.ts b/database/getLotTypes.d.ts deleted file mode 100644 index f101e1c9..00000000 --- a/database/getLotTypes.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { LotType } from '../types/recordTypes.js'; -export default function getLotTypes(): Promise; diff --git a/database/getLotTypes.js b/database/getLotTypes.js deleted file mode 100644 index e7ac3426..00000000 --- a/database/getLotTypes.js +++ /dev/null @@ -1,23 +0,0 @@ -import getLotTypeFields from './getLotTypeFields.js'; -import { acquireConnection } from './pool.js'; -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; -export default async function getLotTypes() { - const database = await acquireConnection(); - const lotTypes = database - .prepare(`select lotTypeId, lotType, orderNumber - 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); - lotType.orderNumber = expectedTypeOrderNumber; - } - lotType.lotTypeFields = await getLotTypeFields(lotType.lotTypeId, database); - } - database.release(); - return lotTypes; -} diff --git a/database/getLotTypes.ts b/database/getLotTypes.ts deleted file mode 100644 index 395bfe31..00000000 --- a/database/getLotTypes.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type { LotType } from '../types/recordTypes.js' - -import getLotTypeFields from './getLotTypeFields.js' -import { acquireConnection } from './pool.js' -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' - -export default async function getLotTypes(): Promise { - const database = await acquireConnection() - - const lotTypes = database - .prepare( - `select lotTypeId, lotType, orderNumber - from LotTypes - where recordDelete_timeMillis is null - order by orderNumber, lotType` - ) - .all() as LotType[] - - let expectedTypeOrderNumber = -1 - - for (const lotType of lotTypes) { - expectedTypeOrderNumber += 1 - - if (lotType.orderNumber !== expectedTypeOrderNumber) { - updateRecordOrderNumber( - 'LotTypes', - lotType.lotTypeId, - expectedTypeOrderNumber, - database - ) - - lotType.orderNumber = expectedTypeOrderNumber - } - - lotType.lotTypeFields = await getLotTypeFields(lotType.lotTypeId, database) - } - - database.release() - - return lotTypes -} diff --git a/database/getLots.d.ts b/database/getLots.d.ts deleted file mode 100644 index 4911c0b8..00000000 --- a/database/getLots.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -import type { Lot } from '../types/recordTypes.js'; -interface GetLotsFilters { - lotNameSearchType?: '' | 'startsWith' | 'endsWith'; - lotName?: string; - mapId?: number | string; - lotTypeId?: number | string; - lotStatusId?: number | string; - occupancyStatus?: '' | 'occupied' | 'unoccupied'; - workOrderId?: number | string; -} -interface GetLotsOptions { - limit: -1 | number; - offset: number; - includeLotOccupancyCount?: boolean; -} -export default function getLots(filters: GetLotsFilters, options: GetLotsOptions, connectedDatabase?: PoolConnection): Promise<{ - count: number; - lots: Lot[]; -}>; -export {}; diff --git a/database/getLots.js b/database/getLots.js deleted file mode 100644 index 5b8c22c2..00000000 --- a/database/getLots.js +++ /dev/null @@ -1,106 +0,0 @@ -import { dateToInteger } from '@cityssm/utils-datetime'; -import { getConfigProperty } from '../helpers/config.helpers.js'; -import { getLotNameWhereClause } from '../helpers/functions.sqlFilters.js'; -import { acquireConnection } from './pool.js'; -function buildWhereClause(filters) { - let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; - const sqlParameters = []; - const lotNameFilters = getLotNameWhereClause(filters.lotName, filters.lotNameSearchType ?? '', 'l'); - sqlWhereClause += lotNameFilters.sqlWhereClause; - sqlParameters.push(...lotNameFilters.sqlParameters); - if ((filters.mapId ?? '') !== '') { - sqlWhereClause += ' and l.mapId = ?'; - sqlParameters.push(filters.mapId); - } - if ((filters.lotTypeId ?? '') !== '') { - sqlWhereClause += ' and l.lotTypeId = ?'; - sqlParameters.push(filters.lotTypeId); - } - if ((filters.lotStatusId ?? '') !== '') { - sqlWhereClause += ' and l.lotStatusId = ?'; - sqlParameters.push(filters.lotStatusId); - } - if ((filters.occupancyStatus ?? '') !== '') { - if (filters.occupancyStatus === 'occupied') { - sqlWhereClause += ' and lotOccupancyCount > 0'; - } - else if (filters.occupancyStatus === 'unoccupied') { - sqlWhereClause += - ' and (lotOccupancyCount is null or lotOccupancyCount = 0)'; - } - } - if ((filters.workOrderId ?? '') !== '') { - sqlWhereClause += - ' and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)'; - sqlParameters.push(filters.workOrderId); - } - return { - sqlWhereClause, - sqlParameters - }; -} -export default async function getLots(filters, options, connectedDatabase) { - const database = connectedDatabase ?? (await acquireConnection()); - const { sqlWhereClause, sqlParameters } = buildWhereClause(filters); - const currentDate = dateToInteger(new Date()); - let count = 0; - if (options.limit !== -1) { - count = database - .prepare(`select count(*) as recordCount - from Lots l - left join ( - select lotId, count(lotOccupancyId) as lotOccupancyCount from LotOccupancies - where recordDelete_timeMillis is null - and occupancyStartDate <= ${currentDate.toString()} - and (occupancyEndDate is null or occupancyEndDate >= ${currentDate.toString()}) - group by lotId - ) o on l.lotId = o.lotId - ${sqlWhereClause}`) - .get(sqlParameters).recordCount; - } - let lots = []; - if (options.limit === -1 || count > 0) { - const includeLotOccupancyCount = options.includeLotOccupancyCount ?? true; - database.function('userFn_lotNameSortName', getConfigProperty('settings.lot.lotNameSortNameFunction')); - if (includeLotOccupancyCount) { - sqlParameters.unshift(currentDate, currentDate); - } - lots = database - .prepare(`select l.lotId, l.lotName, - t.lotType, - l.mapId, m.mapName, l.mapKey, - l.lotStatusId, s.lotStatus - ${includeLotOccupancyCount - ? ', ifnull(o.lotOccupancyCount, 0) as lotOccupancyCount' - : ''} - from Lots l - left join LotTypes t on l.lotTypeId = t.lotTypeId - left join LotStatuses s on l.lotStatusId = s.lotStatusId - left join Maps m on l.mapId = m.mapId - ${includeLotOccupancyCount - ? `left join ( - select lotId, count(lotOccupancyId) as lotOccupancyCount - from LotOccupancies - where recordDelete_timeMillis is null - and occupancyStartDate <= ? - and (occupancyEndDate is null or occupancyEndDate >= ?) - group by lotId) o on l.lotId = o.lotId` - : ''} - ${sqlWhereClause} - order by userFn_lotNameSortName(l.lotName), l.lotId - ${options.limit === -1 - ? '' - : ` limit ${options.limit.toString()} offset ${options.offset.toString()}`}`) - .all(sqlParameters); - if (options.limit === -1) { - count = lots.length; - } - } - if (connectedDatabase === undefined) { - database.release(); - } - return { - count, - lots - }; -} diff --git a/database/getLots.ts b/database/getLots.ts deleted file mode 100644 index 74b53ed3..00000000 --- a/database/getLots.ts +++ /dev/null @@ -1,172 +0,0 @@ -import { dateToInteger } from '@cityssm/utils-datetime' -import type { PoolConnection } from 'better-sqlite-pool' - -import { getConfigProperty } from '../helpers/config.helpers.js' -import { getLotNameWhereClause } from '../helpers/functions.sqlFilters.js' -import type { Lot } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' - -interface GetLotsFilters { - lotNameSearchType?: '' | 'startsWith' | 'endsWith' - lotName?: string - mapId?: number | string - lotTypeId?: number | string - lotStatusId?: number | string - occupancyStatus?: '' | 'occupied' | 'unoccupied' - workOrderId?: number | string -} - -interface GetLotsOptions { - limit: -1 | number - offset: number - includeLotOccupancyCount?: boolean -} - -function buildWhereClause(filters: GetLotsFilters): { - sqlWhereClause: string - sqlParameters: unknown[] -} { - let sqlWhereClause = ' where l.recordDelete_timeMillis is null' - const sqlParameters: unknown[] = [] - - const lotNameFilters = getLotNameWhereClause( - filters.lotName, - filters.lotNameSearchType ?? '', - 'l' - ) - sqlWhereClause += lotNameFilters.sqlWhereClause - sqlParameters.push(...lotNameFilters.sqlParameters) - - if ((filters.mapId ?? '') !== '') { - sqlWhereClause += ' and l.mapId = ?' - sqlParameters.push(filters.mapId) - } - - if ((filters.lotTypeId ?? '') !== '') { - sqlWhereClause += ' and l.lotTypeId = ?' - sqlParameters.push(filters.lotTypeId) - } - - if ((filters.lotStatusId ?? '') !== '') { - sqlWhereClause += ' and l.lotStatusId = ?' - sqlParameters.push(filters.lotStatusId) - } - - if ((filters.occupancyStatus ?? '') !== '') { - if (filters.occupancyStatus === 'occupied') { - sqlWhereClause += ' and lotOccupancyCount > 0' - } else if (filters.occupancyStatus === 'unoccupied') { - sqlWhereClause += - ' and (lotOccupancyCount is null or lotOccupancyCount = 0)' - } - } - - if ((filters.workOrderId ?? '') !== '') { - sqlWhereClause += - ' and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)' - sqlParameters.push(filters.workOrderId) - } - - return { - sqlWhereClause, - sqlParameters - } -} - -export default async function getLots( - filters: GetLotsFilters, - options: GetLotsOptions, - connectedDatabase?: PoolConnection -): Promise<{ count: number; lots: Lot[] }> { - const database = connectedDatabase ?? (await acquireConnection()) - - const { sqlWhereClause, sqlParameters } = buildWhereClause(filters) - - const currentDate = dateToInteger(new Date()) - - let count = 0 - - if (options.limit !== -1) { - count = ( - database - .prepare( - `select count(*) as recordCount - from Lots l - left join ( - select lotId, count(lotOccupancyId) as lotOccupancyCount from LotOccupancies - where recordDelete_timeMillis is null - and occupancyStartDate <= ${currentDate.toString()} - and (occupancyEndDate is null or occupancyEndDate >= ${currentDate.toString()}) - group by lotId - ) o on l.lotId = o.lotId - ${sqlWhereClause}` - ) - .get(sqlParameters) as { recordCount: number } - ).recordCount - } - - let lots: Lot[] = [] - - if (options.limit === -1 || count > 0) { - const includeLotOccupancyCount = options.includeLotOccupancyCount ?? true - - database.function( - 'userFn_lotNameSortName', - getConfigProperty('settings.lot.lotNameSortNameFunction') - ) - - if (includeLotOccupancyCount) { - sqlParameters.unshift(currentDate, currentDate) - } - - lots = database - .prepare( - `select l.lotId, l.lotName, - t.lotType, - l.mapId, m.mapName, l.mapKey, - l.lotStatusId, s.lotStatus - ${ - includeLotOccupancyCount - ? ', ifnull(o.lotOccupancyCount, 0) as lotOccupancyCount' - : '' - } - from Lots l - left join LotTypes t on l.lotTypeId = t.lotTypeId - left join LotStatuses s on l.lotStatusId = s.lotStatusId - left join Maps m on l.mapId = m.mapId - ${ - includeLotOccupancyCount - ? `left join ( - select lotId, count(lotOccupancyId) as lotOccupancyCount - from LotOccupancies - where recordDelete_timeMillis is null - and occupancyStartDate <= ? - and (occupancyEndDate is null or occupancyEndDate >= ?) - group by lotId) o on l.lotId = o.lotId` - : '' - } - ${sqlWhereClause} - order by userFn_lotNameSortName(l.lotName), l.lotId - ${ - options.limit === -1 - ? '' - : ` limit ${options.limit.toString()} offset ${options.offset.toString()}` - }` - ) - .all(sqlParameters) as Lot[] - - if (options.limit === -1) { - count = lots.length - } - } - - if (connectedDatabase === undefined) { - database.release() - } - - return { - count, - lots - } -} diff --git a/database/getMap.d.ts b/database/getMap.d.ts deleted file mode 100644 index 3b362972..00000000 --- a/database/getMap.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { MapRecord } from '../types/recordTypes.js'; -export default function getMap(mapId: number | string): Promise; diff --git a/database/getMap.js b/database/getMap.js deleted file mode 100644 index 3a03ce0a..00000000 --- a/database/getMap.js +++ /dev/null @@ -1,27 +0,0 @@ -import { acquireConnection } from './pool.js'; -export default async function getMap(mapId) { - const database = await acquireConnection(); - 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 = ? - and m.recordDelete_timeMillis is null - 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.release(); - return map; -} diff --git a/database/getMap.ts b/database/getMap.ts deleted file mode 100644 index 92678c50..00000000 --- a/database/getMap.ts +++ /dev/null @@ -1,37 +0,0 @@ -import type { MapRecord } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' - -export default async function getMap( - mapId: number | string -): Promise { - const database = await acquireConnection() - - 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 = ? - and m.recordDelete_timeMillis is null - 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) as MapRecord | undefined - - database.release() - - return map -} diff --git a/database/getMaps.d.ts b/database/getMaps.d.ts deleted file mode 100644 index a0a37884..00000000 --- a/database/getMaps.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { MapRecord } from '../types/recordTypes.js'; -export default function getMaps(): Promise; diff --git a/database/getMaps.js b/database/getMaps.js deleted file mode 100644 index 54fde7fd..00000000 --- a/database/getMaps.js +++ /dev/null @@ -1,20 +0,0 @@ -import { acquireConnection } from './pool.js'; -export default async function getMaps() { - const database = await acquireConnection(); - 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`) - .all(); - database.release(); - return maps; -} diff --git a/database/getMaps.ts b/database/getMaps.ts deleted file mode 100644 index ab169916..00000000 --- a/database/getMaps.ts +++ /dev/null @@ -1,28 +0,0 @@ -import type { MapRecord } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' - -export default async function getMaps(): Promise { - const database = await acquireConnection() - - 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` - ) - .all() as MapRecord[] - - database.release() - - return maps -} diff --git a/database/getNextCemeteryId.d.ts b/database/getNextCemeteryId.d.ts new file mode 100644 index 00000000..4d366a88 --- /dev/null +++ b/database/getNextCemeteryId.d.ts @@ -0,0 +1 @@ +export default function getNextCemeteryId(cemeteryId: number | string): Promise; diff --git a/database/getNextCemeteryId.js b/database/getNextCemeteryId.js new file mode 100644 index 00000000..9379e06a --- /dev/null +++ b/database/getNextCemeteryId.js @@ -0,0 +1,15 @@ +import { acquireConnection } from './pool.js'; +export default async function getNextCemeteryId(cemeteryId) { + const database = await acquireConnection(); + const result = database + .prepare(`select cemeteryId + from Cemeteries + where recordDelete_timeMillis is null + and cemeteryName > (select cemeteryName from Cemeteries where cemeteryId = ?) + order by cemeteryName + limit 1`) + .pluck() + .get(cemeteryId); + database.release(); + return result; +} diff --git a/database/getNextCemeteryId.ts b/database/getNextCemeteryId.ts new file mode 100644 index 00000000..8706f188 --- /dev/null +++ b/database/getNextCemeteryId.ts @@ -0,0 +1,23 @@ +import { acquireConnection } from './pool.js' + +export default async function getNextCemeteryId( + cemeteryId: number | string +): Promise { + const database = await acquireConnection() + + const result = database + .prepare( + `select cemeteryId + from Cemeteries + where recordDelete_timeMillis is null + and cemeteryName > (select cemeteryName from Cemeteries where cemeteryId = ?) + order by cemeteryName + limit 1` + ) + .pluck() + .get(cemeteryId) as number | undefined + + database.release() + + return result +} diff --git a/database/getNextMapId.d.ts b/database/getNextMapId.d.ts deleted file mode 100644 index 9ea3eff7..00000000 --- a/database/getNextMapId.d.ts +++ /dev/null @@ -1 +0,0 @@ -export default function getNextMapId(mapId: number | string): Promise; diff --git a/database/getNextMapId.js b/database/getNextMapId.js deleted file mode 100644 index a720f01b..00000000 --- a/database/getNextMapId.js +++ /dev/null @@ -1,17 +0,0 @@ -import { acquireConnection } from './pool.js'; -export default async function getNextMapId(mapId) { - const database = await acquireConnection(); - const result = database - .prepare(`select mapId - from Maps - where recordDelete_timeMillis is null - and mapName > (select mapName from Maps where mapId = ?) - order by mapName - limit 1`) - .get(mapId); - database.release(); - if (result === undefined) { - return undefined; - } - return result.mapId; -} diff --git a/database/getNextMapId.ts b/database/getNextMapId.ts deleted file mode 100644 index 6fd8c536..00000000 --- a/database/getNextMapId.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { acquireConnection } from './pool.js' - -export default async function getNextMapId( - mapId: number | string -): Promise { - const database = await acquireConnection() - - const result = database - .prepare( - `select mapId - from Maps - where recordDelete_timeMillis is null - and mapName > (select mapName from Maps where mapId = ?) - order by mapName - limit 1` - ) - .get(mapId) as - | { - mapId: number - } - | undefined - - database.release() - - if (result === undefined) { - return undefined - } - - return result.mapId -} diff --git a/database/getOccupancyTypeFields.d.ts b/database/getOccupancyTypeFields.d.ts deleted file mode 100644 index 96d5a924..00000000 --- a/database/getOccupancyTypeFields.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -import type { OccupancyTypeField } from '../types/recordTypes.js'; -export default function getOccupancyTypeFields(occupancyTypeId?: number, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getOccupancyTypeFields.js b/database/getOccupancyTypeFields.js deleted file mode 100644 index 84bac38a..00000000 --- a/database/getOccupancyTypeFields.js +++ /dev/null @@ -1,31 +0,0 @@ -import { acquireConnection } from './pool.js'; -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; -export default async function getOccupancyTypeFields(occupancyTypeId, connectedDatabase) { - const database = connectedDatabase ?? (await acquireConnection()); - const sqlParameters = []; - if ((occupancyTypeId ?? -1) !== -1) { - sqlParameters.push(occupancyTypeId); - } - const occupancyTypeFields = database - .prepare(`select occupancyTypeFieldId, occupancyTypeField, fieldType, - occupancyTypeFieldValues, isRequired, pattern, minimumLength, maximumLength, orderNumber - from OccupancyTypeFields - where recordDelete_timeMillis is null - ${(occupancyTypeId ?? -1) === -1 - ? ' and occupancyTypeId is null' - : ' and occupancyTypeId = ?'} - order by orderNumber, occupancyTypeField`) - .all(sqlParameters); - let expectedOrderNumber = 0; - for (const occupancyTypeField of occupancyTypeFields) { - if (occupancyTypeField.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber('OccupancyTypeFields', occupancyTypeField.occupancyTypeFieldId, expectedOrderNumber, database); - occupancyTypeField.orderNumber = expectedOrderNumber; - } - expectedOrderNumber += 1; - } - if (connectedDatabase === undefined) { - database.release(); - } - return occupancyTypeFields; -} diff --git a/database/getOccupancyTypeFields.ts b/database/getOccupancyTypeFields.ts deleted file mode 100644 index 4a03a54d..00000000 --- a/database/getOccupancyTypeFields.ts +++ /dev/null @@ -1,57 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool' - -import type { OccupancyTypeField } from '../types/recordTypes.js' - -import { acquireConnection } from './pool.js' -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' - -export default async function getOccupancyTypeFields( - occupancyTypeId?: number, - connectedDatabase?: PoolConnection -): Promise { - const database = connectedDatabase ?? (await acquireConnection()) - - const sqlParameters: unknown[] = [] - - if ((occupancyTypeId ?? -1) !== -1) { - sqlParameters.push(occupancyTypeId) - } - - const occupancyTypeFields = database - .prepare( - `select occupancyTypeFieldId, occupancyTypeField, fieldType, - occupancyTypeFieldValues, isRequired, pattern, minimumLength, maximumLength, orderNumber - from OccupancyTypeFields - where recordDelete_timeMillis is null - ${ - (occupancyTypeId ?? -1) === -1 - ? ' and occupancyTypeId is null' - : ' and occupancyTypeId = ?' - } - order by orderNumber, occupancyTypeField` - ) - .all(sqlParameters) as OccupancyTypeField[] - - let expectedOrderNumber = 0 - - for (const occupancyTypeField of occupancyTypeFields) { - if (occupancyTypeField.orderNumber !== expectedOrderNumber) { - updateRecordOrderNumber( - 'OccupancyTypeFields', - occupancyTypeField.occupancyTypeFieldId, - expectedOrderNumber, - database - ) - - occupancyTypeField.orderNumber = expectedOrderNumber - } - - expectedOrderNumber += 1 - } - - if (connectedDatabase === undefined) { - database.release() - } - - return occupancyTypeFields -} diff --git a/database/getOccupancyTypePrints.d.ts b/database/getOccupancyTypePrints.d.ts deleted file mode 100644 index e503d6ff..00000000 --- a/database/getOccupancyTypePrints.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool'; -export default function getOccupancyTypePrints(occupancyTypeId: number, connectedDatabase?: PoolConnection): Promise; diff --git a/database/getOccupancyTypes.d.ts b/database/getOccupancyTypes.d.ts deleted file mode 100644 index b1003087..00000000 --- a/database/getOccupancyTypes.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { OccupancyType } from '../types/recordTypes.js'; -export default function getOccupancyTypes(): Promise; diff --git a/database/getOccupancyTypes.js b/database/getOccupancyTypes.js deleted file mode 100644 index 0827c68e..00000000 --- a/database/getOccupancyTypes.js +++ /dev/null @@ -1,25 +0,0 @@ -import getOccupancyTypeFields from './getOccupancyTypeFields.js'; -import getOccupancyTypePrints from './getOccupancyTypePrints.js'; -import { acquireConnection } from './pool.js'; -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; -export default async function getOccupancyTypes() { - const database = await acquireConnection(); - const occupancyTypes = database - .prepare(`select occupancyTypeId, occupancyType, orderNumber - from OccupancyTypes - where recordDelete_timeMillis is null - order by orderNumber, occupancyType`) - .all(); - let expectedTypeOrderNumber = -1; - for (const occupancyType of occupancyTypes) { - expectedTypeOrderNumber += 1; - if (occupancyType.orderNumber !== expectedTypeOrderNumber) { - updateRecordOrderNumber('OccupancyTypes', occupancyType.occupancyTypeId, expectedTypeOrderNumber, database); - occupancyType.orderNumber = expectedTypeOrderNumber; - } - occupancyType.occupancyTypeFields = await getOccupancyTypeFields(occupancyType.occupancyTypeId, database); - occupancyType.occupancyTypePrints = await getOccupancyTypePrints(occupancyType.occupancyTypeId, database); - } - database.release(); - return occupancyTypes; -} diff --git a/database/getOccupancyTypes.ts b/database/getOccupancyTypes.ts deleted file mode 100644 index 66b7b7b2..00000000 --- a/database/getOccupancyTypes.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { OccupancyType } from '../types/recordTypes.js' - -import getOccupancyTypeFields from './getOccupancyTypeFields.js' -import getOccupancyTypePrints from './getOccupancyTypePrints.js' -import { acquireConnection } from './pool.js' -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' - -export default async function getOccupancyTypes(): Promise { - const database = await acquireConnection() - - const occupancyTypes = database - .prepare( - `select occupancyTypeId, occupancyType, orderNumber - from OccupancyTypes - where recordDelete_timeMillis is null - order by orderNumber, occupancyType` - ) - .all() as OccupancyType[] - - let expectedTypeOrderNumber = -1 - - for (const occupancyType of occupancyTypes) { - expectedTypeOrderNumber += 1 - - if (occupancyType.orderNumber !== expectedTypeOrderNumber) { - updateRecordOrderNumber( - 'OccupancyTypes', - occupancyType.occupancyTypeId, - expectedTypeOrderNumber, - database - ) - - occupancyType.orderNumber = expectedTypeOrderNumber - } - - occupancyType.occupancyTypeFields = await getOccupancyTypeFields( - occupancyType.occupancyTypeId, - database - ) - - occupancyType.occupancyTypePrints = await getOccupancyTypePrints( - occupancyType.occupancyTypeId, - database - ) - } - - database.release() - - return occupancyTypes -} - diff --git a/database/getPastLotOccupancyOccupants.js b/database/getPastLotOccupancyOccupants.js index cbc92d4a..7beab54f 100644 --- a/database/getPastLotOccupancyOccupants.js +++ b/database/getPastLotOccupancyOccupants.js @@ -21,15 +21,15 @@ export default async function getPastLotOccupancyOccupants(filters, options) { o.occupantAddress1, o.occupantAddress2, o.occupantCity, o.occupantProvince, o.occupantPostalCode, o.occupantPhoneNumber, o.occupantEmailAddress, - count(*) as lotOccupancyIdCount, + count(*) as burialSiteContractIdCount, max(o.recordUpdate_timeMillis) as recordUpdate_timeMillisMax from LotOccupancyOccupants o - left join LotOccupancies l on o.lotOccupancyId = l.lotOccupancyId + left join BurialSiteContracts l on o.burialSiteContractId = l.burialSiteContractId ${sqlWhereClause} group by occupantName, occupantAddress1, occupantAddress2, occupantCity, occupantProvince, occupantPostalCode, occupantPhoneNumber, occupantEmailAddress - order by lotOccupancyIdCount desc, recordUpdate_timeMillisMax desc + order by burialSiteContractIdCount desc, recordUpdate_timeMillisMax desc limit ${options.limit}`; const lotOccupancyOccupants = database .prepare(sql) diff --git a/database/getPastLotOccupancyOccupants.ts b/database/getPastLotOccupancyOccupants.ts index fcd4b785..c1c14b1e 100644 --- a/database/getPastLotOccupancyOccupants.ts +++ b/database/getPastLotOccupancyOccupants.ts @@ -49,15 +49,15 @@ export default async function getPastLotOccupancyOccupants( o.occupantAddress1, o.occupantAddress2, o.occupantCity, o.occupantProvince, o.occupantPostalCode, o.occupantPhoneNumber, o.occupantEmailAddress, - count(*) as lotOccupancyIdCount, + count(*) as burialSiteContractIdCount, max(o.recordUpdate_timeMillis) as recordUpdate_timeMillisMax from LotOccupancyOccupants o - left join LotOccupancies l on o.lotOccupancyId = l.lotOccupancyId + left join BurialSiteContracts l on o.burialSiteContractId = l.burialSiteContractId ${sqlWhereClause} group by occupantName, occupantAddress1, occupantAddress2, occupantCity, occupantProvince, occupantPostalCode, occupantPhoneNumber, occupantEmailAddress - order by lotOccupancyIdCount desc, recordUpdate_timeMillisMax desc + order by burialSiteContractIdCount desc, recordUpdate_timeMillisMax desc limit ${options.limit}` const lotOccupancyOccupants = database diff --git a/database/getPreviousCemeteryId.d.ts b/database/getPreviousCemeteryId.d.ts new file mode 100644 index 00000000..c5dd1acf --- /dev/null +++ b/database/getPreviousCemeteryId.d.ts @@ -0,0 +1 @@ +export default function getPreviousCemeteryId(cemeteryId: number | string): Promise; diff --git a/database/getPreviousCemeteryId.js b/database/getPreviousCemeteryId.js new file mode 100644 index 00000000..f4bd8f8f --- /dev/null +++ b/database/getPreviousCemeteryId.js @@ -0,0 +1,14 @@ +import { acquireConnection } from './pool.js'; +export default async function getPreviousCemeteryId(cemeteryId) { + const database = await acquireConnection(); + const result = database + .prepare(`select cemeteryId from Cemeteries + where recordDelete_timeMillis is null + and cemeteryName < (select cemeteryName from Cemeteries where cemeteryId = ?) + order by cemeteryName desc + limit 1`) + .pluck() + .get(cemeteryId); + database.release(); + return result; +} diff --git a/database/getPreviousCemeteryId.ts b/database/getPreviousCemeteryId.ts new file mode 100644 index 00000000..bd5ffcca --- /dev/null +++ b/database/getPreviousCemeteryId.ts @@ -0,0 +1,22 @@ +import { acquireConnection } from './pool.js' + +export default async function getPreviousCemeteryId( + cemeteryId: number | string +): Promise { + const database = await acquireConnection() + + const result = database + .prepare( + `select cemeteryId from Cemeteries + where recordDelete_timeMillis is null + and cemeteryName < (select cemeteryName from Cemeteries where cemeteryId = ?) + order by cemeteryName desc + limit 1` + ) + .pluck() + .get(cemeteryId) as number | undefined + + database.release() + + return result +} diff --git a/database/getPreviousMapId.d.ts b/database/getPreviousMapId.d.ts deleted file mode 100644 index eb611968..00000000 --- a/database/getPreviousMapId.d.ts +++ /dev/null @@ -1 +0,0 @@ -export default function getPreviousMapId(mapId: number | string): Promise; diff --git a/database/getPreviousMapId.js b/database/getPreviousMapId.js deleted file mode 100644 index c716652e..00000000 --- a/database/getPreviousMapId.js +++ /dev/null @@ -1,16 +0,0 @@ -import { acquireConnection } from './pool.js'; -export default async function getPreviousMapId(mapId) { - const database = await acquireConnection(); - const result = database - .prepare(`select mapId from Maps - where recordDelete_timeMillis is null - and mapName < (select mapName from Maps where mapId = ?) - order by mapName desc - limit 1`) - .get(mapId); - database.release(); - if (result === undefined) { - return undefined; - } - return result.mapId; -} diff --git a/database/getPreviousMapId.ts b/database/getPreviousMapId.ts deleted file mode 100644 index f1118808..00000000 --- a/database/getPreviousMapId.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { acquireConnection } from './pool.js' - -export default async function getPreviousMapId( - mapId: number | string -): Promise { - const database = await acquireConnection() - - const result = database - .prepare( - `select mapId from Maps - where recordDelete_timeMillis is null - and mapName < (select mapName from Maps where mapId = ?) - order by mapName desc - limit 1` - ) - .get(mapId) as - | { - mapId: number - } - | undefined - - database.release() - - if (result === undefined) { - return undefined - } - - return result.mapId -} diff --git a/database/getWorkOrder.d.ts b/database/getWorkOrder.d.ts index fc428f62..cc22d0e9 100644 --- a/database/getWorkOrder.d.ts +++ b/database/getWorkOrder.d.ts @@ -1,7 +1,7 @@ import type { PoolConnection } from 'better-sqlite-pool'; import type { WorkOrder } from '../types/recordTypes.js'; interface WorkOrderOptions { - includeLotsAndLotOccupancies: boolean; + includeBurialSites: boolean; includeComments: boolean; includeMilestones: boolean; } diff --git a/database/getWorkOrder.js b/database/getWorkOrder.js index 12d45022..909cf767 100644 --- a/database/getWorkOrder.js +++ b/database/getWorkOrder.js @@ -1,6 +1,6 @@ import { dateIntegerToString } from '@cityssm/utils-datetime'; -import getLotOccupancies from './getLotOccupancies.js'; -import getLots from './getLots.js'; +import getBurialSiteContracts from './getBurialSiteContracts.js'; +import getBurialSites from './getBurialSites.js'; import getWorkOrderComments from './getWorkOrderComments.js'; import getWorkOrderMilestones from './getWorkOrderMilestones.js'; import { acquireConnection } from './pool.js'; @@ -18,16 +18,16 @@ async function _getWorkOrder(sql, workOrderIdOrWorkOrderNumber, options, connect database.function('userFn_dateIntegerToString', dateIntegerToString); const workOrder = database.prepare(sql).get(workOrderIdOrWorkOrderNumber); if (workOrder !== undefined) { - if (options.includeLotsAndLotOccupancies) { - const workOrderLotsResults = await getLots({ + if (options.includeBurialSites) { + const burialSiteResults = await getBurialSites({ workOrderId: workOrder.workOrderId }, { limit: -1, offset: 0, includeLotOccupancyCount: false }, database); - workOrder.workOrderLots = workOrderLotsResults.lots; - const workOrderLotOccupanciesResults = await getLotOccupancies({ + workOrder.workOrderBurialSites = burialSiteResults.lots; + const workOrderBurialSiteContractsResults = await getBurialSiteContracts({ workOrderId: workOrder.workOrderId }, { limit: -1, @@ -36,8 +36,8 @@ async function _getWorkOrder(sql, workOrderIdOrWorkOrderNumber, options, connect includeFees: false, includeTransactions: false }, database); - workOrder.workOrderLotOccupancies = - workOrderLotOccupanciesResults.lotOccupancies; + workOrder.workOrderBurialSiteContracts = + workOrderBurialSiteContractsResults.BurialSiteContracts; } if (options.includeComments) { workOrder.workOrderComments = await getWorkOrderComments(workOrder.workOrderId, database); @@ -58,7 +58,7 @@ async function _getWorkOrder(sql, workOrderIdOrWorkOrderNumber, options, connect } export async function getWorkOrderByWorkOrderNumber(workOrderNumber) { return await _getWorkOrder(`${baseSQL} and w.workOrderNumber = ?`, workOrderNumber, { - includeLotsAndLotOccupancies: true, + includeBurialSites: true, includeComments: true, includeMilestones: true }); diff --git a/database/getWorkOrder.ts b/database/getWorkOrder.ts index 75f948a0..fba5100d 100644 --- a/database/getWorkOrder.ts +++ b/database/getWorkOrder.ts @@ -3,14 +3,14 @@ import type { PoolConnection } from 'better-sqlite-pool' import type { WorkOrder } from '../types/recordTypes.js' -import getLotOccupancies from './getLotOccupancies.js' -import getLots from './getLots.js' +import getBurialSiteContracts from './getBurialSiteContracts.js' +import getBurialSites from './getBurialSites.js' import getWorkOrderComments from './getWorkOrderComments.js' import getWorkOrderMilestones from './getWorkOrderMilestones.js' import { acquireConnection } from './pool.js' interface WorkOrderOptions { - includeLotsAndLotOccupancies: boolean + includeBurialSites: boolean includeComments: boolean includeMilestones: boolean } @@ -40,8 +40,8 @@ async function _getWorkOrder( | undefined if (workOrder !== undefined) { - if (options.includeLotsAndLotOccupancies) { - const workOrderLotsResults = await getLots( + if (options.includeBurialSites) { + const burialSiteResults = await getBurialSites( { workOrderId: workOrder.workOrderId }, @@ -53,9 +53,9 @@ async function _getWorkOrder( database ) - workOrder.workOrderLots = workOrderLotsResults.lots + workOrder.workOrderBurialSites = burialSiteResults.lots - const workOrderLotOccupanciesResults = await getLotOccupancies( + const workOrderBurialSiteContractsResults = await getBurialSiteContracts( { workOrderId: workOrder.workOrderId }, @@ -69,8 +69,8 @@ async function _getWorkOrder( database ) - workOrder.workOrderLotOccupancies = - workOrderLotOccupanciesResults.lotOccupancies + workOrder.workOrderBurialSiteContracts = + workOrderBurialSiteContractsResults.BurialSiteContracts } if (options.includeComments) { @@ -108,7 +108,7 @@ export async function getWorkOrderByWorkOrderNumber( `${baseSQL} and w.workOrderNumber = ?`, workOrderNumber, { - includeLotsAndLotOccupancies: true, + includeBurialSites: true, includeComments: true, includeMilestones: true } diff --git a/database/getWorkOrderMilestones.js b/database/getWorkOrderMilestones.js index 4dabecda..3930c44e 100644 --- a/database/getWorkOrderMilestones.js +++ b/database/getWorkOrderMilestones.js @@ -1,6 +1,6 @@ import { dateIntegerToString, dateStringToInteger, dateToInteger, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime'; import { getConfigProperty } from '../helpers/config.helpers.js'; -import getLotOccupancies from './getLotOccupancies.js'; +import getBurialSiteContracts from './getBurialSiteContracts.js'; import getLots from './getLots.js'; import { acquireConnection } from './pool.js'; // eslint-disable-next-line security/detect-unsafe-regex @@ -129,7 +129,7 @@ export default async function getWorkOrderMilestones(filters, options, connected includeLotOccupancyCount: false }, database); workOrderMilestone.workOrderLots = workOrderLotsResults.lots; - const lotOccupancies = await getLotOccupancies({ + const BurialSiteContracts = await getBurialSiteContracts({ workOrderId: workOrderMilestone.workOrderId }, { limit: -1, @@ -138,7 +138,7 @@ export default async function getWorkOrderMilestones(filters, options, connected includeFees: false, includeTransactions: false }, database); - workOrderMilestone.workOrderLotOccupancies = lotOccupancies.lotOccupancies; + workOrderMilestone.workOrderBurialSiteContracts = BurialSiteContracts.BurialSiteContracts; } } if (connectedDatabase === undefined) { diff --git a/database/getWorkOrderMilestones.ts b/database/getWorkOrderMilestones.ts index f7189a48..7dfe659a 100644 --- a/database/getWorkOrderMilestones.ts +++ b/database/getWorkOrderMilestones.ts @@ -11,7 +11,7 @@ import type { PoolConnection } from 'better-sqlite-pool' import { getConfigProperty } from '../helpers/config.helpers.js' import type { WorkOrderMilestone } from '../types/recordTypes.js' -import getLotOccupancies from './getLotOccupancies.js' +import getBurialSiteContracts from './getBurialSiteContracts.js' import getLots from './getLots.js' import { acquireConnection } from './pool.js' @@ -218,7 +218,7 @@ export default async function getWorkOrderMilestones( workOrderMilestone.workOrderLots = workOrderLotsResults.lots - const lotOccupancies = await getLotOccupancies( + const BurialSiteContracts = await getBurialSiteContracts( { workOrderId: workOrderMilestone.workOrderId }, @@ -232,7 +232,7 @@ export default async function getWorkOrderMilestones( database ) - workOrderMilestone.workOrderLotOccupancies = lotOccupancies.lotOccupancies + workOrderMilestone.workOrderBurialSiteContracts = BurialSiteContracts.BurialSiteContracts } } diff --git a/database/getWorkOrders.d.ts b/database/getWorkOrders.d.ts index 7fa3a46c..5f367ba2 100644 --- a/database/getWorkOrders.d.ts +++ b/database/getWorkOrders.d.ts @@ -6,12 +6,12 @@ export interface GetWorkOrdersFilters { workOrderOpenDateString?: string; occupantName?: string; lotName?: string; - lotOccupancyId?: number | string; + burialSiteContractId?: number | string; } interface GetWorkOrdersOptions { limit: number; offset: number; - includeLotsAndLotOccupancies?: boolean; + includeLotsAndBurialSiteContracts?: boolean; includeComments?: boolean; includeMilestones?: boolean; } diff --git a/database/getWorkOrders.js b/database/getWorkOrders.js index 3b2bfeb1..0d907be2 100644 --- a/database/getWorkOrders.js +++ b/database/getWorkOrders.js @@ -1,6 +1,6 @@ import { dateIntegerToString, dateStringToInteger } from '@cityssm/utils-datetime'; import { getLotNameWhereClause, getOccupantNameWhereClause } from '../helpers/functions.sqlFilters.js'; -import getLotOccupancies from './getLotOccupancies.js'; +import getBurialSiteContracts from './getBurialSiteContracts.js'; import getLots from './getLots.js'; import getWorkOrderComments from './getWorkOrderComments.js'; import getWorkOrderMilestones from './getWorkOrderMilestones.js'; @@ -28,10 +28,10 @@ function buildWhereClause(filters) { if (occupantNameFilters.sqlParameters.length > 0) { sqlWhereClause += ` and w.workOrderId in ( - select workOrderId from WorkOrderLotOccupancies o + select workOrderId from WorkOrderBurialSiteContracts o where recordDelete_timeMillis is null - and o.lotOccupancyId in ( - select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null + and o.burialSiteContractId in ( + select burialSiteContractId from LotOccupancyOccupants o where recordDelete_timeMillis is null ${occupantNameFilters.sqlWhereClause} ))`; sqlParameters.push(...occupantNameFilters.sqlParameters); @@ -49,10 +49,10 @@ function buildWhereClause(filters) { ))`; sqlParameters.push(...lotNameFilters.sqlParameters); } - if ((filters.lotOccupancyId ?? '') !== '') { + if ((filters.burialSiteContractId ?? '') !== '') { sqlWhereClause += - ' and w.workOrderId in (select workOrderId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and lotOccupancyId = ?)'; - sqlParameters.push(filters.lotOccupancyId); + ' and w.workOrderId in (select workOrderId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and burialSiteContractId = ?)'; + sqlParameters.push(filters.burialSiteContractId); } return { sqlWhereClause, @@ -63,7 +63,7 @@ async function addInclusions(workOrder, options, database) { if (options.includeComments ?? false) { workOrder.workOrderComments = await getWorkOrderComments(workOrder.workOrderId, database); } - if (options.includeLotsAndLotOccupancies ?? false) { + if (options.includeLotsAndBurialSiteContracts ?? false) { if (workOrder.workOrderLotCount === 0) { workOrder.workOrderLots = []; } @@ -77,7 +77,7 @@ async function addInclusions(workOrder, options, database) { }, database); workOrder.workOrderLots = workOrderLotsResults.lots; } - const lotOccupancies = await getLotOccupancies({ + const BurialSiteContracts = await getBurialSiteContracts({ workOrderId: workOrder.workOrderId }, { limit: -1, @@ -86,7 +86,7 @@ async function addInclusions(workOrder, options, database) { includeFees: false, includeTransactions: false }, database); - workOrder.workOrderLotOccupancies = lotOccupancies.lotOccupancies; + workOrder.workOrderBurialSiteContracts = BurialSiteContracts.BurialSiteContracts; } if (options.includeMilestones ?? false) { workOrder.workOrderMilestones = @@ -142,7 +142,7 @@ export async function getWorkOrders(filters, options, connectedDatabase) { .all(sqlParameters); } const hasInclusions = (options.includeComments ?? false) || - (options.includeLotsAndLotOccupancies ?? false) || + (options.includeLotsAndBurialSiteContracts ?? false) || (options.includeMilestones ?? false); if (hasInclusions) { for (const workOrder of workOrders) { diff --git a/database/getWorkOrders.ts b/database/getWorkOrders.ts index 9f9a1420..f32ec856 100644 --- a/database/getWorkOrders.ts +++ b/database/getWorkOrders.ts @@ -11,7 +11,7 @@ import { } from '../helpers/functions.sqlFilters.js' import type { WorkOrder } from '../types/recordTypes.js' -import getLotOccupancies from './getLotOccupancies.js' +import getBurialSiteContracts from './getBurialSiteContracts.js' import getLots from './getLots.js' import getWorkOrderComments from './getWorkOrderComments.js' import getWorkOrderMilestones from './getWorkOrderMilestones.js' @@ -23,13 +23,13 @@ export interface GetWorkOrdersFilters { workOrderOpenDateString?: string occupantName?: string lotName?: string - lotOccupancyId?: number | string + burialSiteContractId?: number | string } interface GetWorkOrdersOptions { limit: number offset: number - includeLotsAndLotOccupancies?: boolean + includeLotsAndBurialSiteContracts?: boolean includeComments?: boolean includeMilestones?: boolean } @@ -68,10 +68,10 @@ function buildWhereClause(filters: GetWorkOrdersFilters): { if (occupantNameFilters.sqlParameters.length > 0) { sqlWhereClause += ` and w.workOrderId in ( - select workOrderId from WorkOrderLotOccupancies o + select workOrderId from WorkOrderBurialSiteContracts o where recordDelete_timeMillis is null - and o.lotOccupancyId in ( - select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null + and o.burialSiteContractId in ( + select burialSiteContractId from LotOccupancyOccupants o where recordDelete_timeMillis is null ${occupantNameFilters.sqlWhereClause} ))` sqlParameters.push(...occupantNameFilters.sqlParameters) @@ -91,10 +91,10 @@ function buildWhereClause(filters: GetWorkOrdersFilters): { sqlParameters.push(...lotNameFilters.sqlParameters) } - if ((filters.lotOccupancyId ?? '') !== '') { + if ((filters.burialSiteContractId ?? '') !== '') { sqlWhereClause += - ' and w.workOrderId in (select workOrderId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and lotOccupancyId = ?)' - sqlParameters.push(filters.lotOccupancyId) + ' and w.workOrderId in (select workOrderId from WorkOrderBurialSiteContracts where recordDelete_timeMillis is null and burialSiteContractId = ?)' + sqlParameters.push(filters.burialSiteContractId) } return { @@ -115,7 +115,7 @@ async function addInclusions( ) } - if (options.includeLotsAndLotOccupancies ?? false) { + if (options.includeLotsAndBurialSiteContracts ?? false) { if (workOrder.workOrderLotCount === 0) { workOrder.workOrderLots = [] } else { @@ -134,7 +134,7 @@ async function addInclusions( workOrder.workOrderLots = workOrderLotsResults.lots } - const lotOccupancies = await getLotOccupancies( + const BurialSiteContracts = await getBurialSiteContracts( { workOrderId: workOrder.workOrderId }, @@ -148,7 +148,7 @@ async function addInclusions( database ) - workOrder.workOrderLotOccupancies = lotOccupancies.lotOccupancies + workOrder.workOrderBurialSiteContracts = BurialSiteContracts.BurialSiteContracts } if (options.includeMilestones ?? false) { @@ -230,7 +230,7 @@ export async function getWorkOrders( const hasInclusions = (options.includeComments ?? false) || - (options.includeLotsAndLotOccupancies ?? false) || + (options.includeLotsAndBurialSiteContracts ?? false) || (options.includeMilestones ?? false) if (hasInclusions) { diff --git a/database/moveBurialSiteTypeField.d.ts b/database/moveBurialSiteTypeField.d.ts new file mode 100644 index 00000000..8a503006 --- /dev/null +++ b/database/moveBurialSiteTypeField.d.ts @@ -0,0 +1,4 @@ +export declare function moveBurialSiteTypeFieldDown(burialSiteTypeFieldId: number | string): Promise; +export declare function moveBurialSiteTypeFieldDownToBottom(burialSiteTypeFieldId: number | string): Promise; +export declare function moveBurialSiteTypeFieldUp(burialSiteTypeFieldId: number | string): Promise; +export declare function moveBurialSiteTypeFieldUpToTop(burialSiteTypeFieldId: number | string): Promise; diff --git a/database/moveBurialSiteTypeField.js b/database/moveBurialSiteTypeField.js new file mode 100644 index 00000000..2c048831 --- /dev/null +++ b/database/moveBurialSiteTypeField.js @@ -0,0 +1,81 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js'; +import { acquireConnection } from './pool.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; +function getCurrentField(burialSiteTypeFieldId, connectedDatabase) { + return connectedDatabase + .prepare('select burialSiteTypeId, orderNumber from BurialSiteTypeFields where burialSiteTypeFieldId = ?') + .get(burialSiteTypeFieldId); +} +export async function moveBurialSiteTypeFieldDown(burialSiteTypeFieldId) { + const database = await acquireConnection(); + const currentField = getCurrentField(burialSiteTypeFieldId, database); + database + .prepare(`update BurialSiteTypeFields + set orderNumber = orderNumber - 1 + where recordDelete_timeMillis is null + and burialSiteTypeId = ? and orderNumber = ? + 1`) + .run(currentField.burialSiteTypeId, currentField.orderNumber); + const success = updateRecordOrderNumber('BurialSiteTypeFields', burialSiteTypeFieldId, currentField.orderNumber + 1, database); + database.release(); + clearCacheByTableName('BurialSiteTypeFields'); + return success; +} +export async function moveBurialSiteTypeFieldDownToBottom(burialSiteTypeFieldId) { + const database = await acquireConnection(); + const currentField = getCurrentField(burialSiteTypeFieldId, database); + const maxOrderNumber = database + .prepare(`select max(orderNumber) as maxOrderNumber + from BurialSiteTypeFields + where recordDelete_timeMillis is null + and burialSiteTypeId = ?`) + .get(currentField.burialSiteTypeId).maxOrderNumber; + if (currentField.orderNumber !== maxOrderNumber) { + updateRecordOrderNumber('BurialSiteTypeFields', burialSiteTypeFieldId, maxOrderNumber + 1, database); + database + .prepare(`update BurialSiteTypeFields + set orderNumber = orderNumber - 1 + where recordDelete_timeMillis is null + and burialSiteTypeId = ? + and orderNumber > ?`) + .run(currentField.burialSiteTypeId, currentField.orderNumber); + } + database.release(); + clearCacheByTableName('BurialSiteTypeFields'); + return true; +} +export async function moveBurialSiteTypeFieldUp(burialSiteTypeFieldId) { + const database = await acquireConnection(); + const currentField = getCurrentField(burialSiteTypeFieldId, database); + if (currentField.orderNumber <= 0) { + database.release(); + return true; + } + database + .prepare(`update BurialSiteTypeFields + set orderNumber = orderNumber + 1 + where recordDelete_timeMillis is null + and burialSiteTypeId = ? + and orderNumber = ? - 1`) + .run(currentField.burialSiteTypeId, currentField.orderNumber); + const success = updateRecordOrderNumber('BurialSiteTypeFields', burialSiteTypeFieldId, currentField.orderNumber - 1, database); + database.release(); + clearCacheByTableName('BurialSiteTypeFields'); + return success; +} +export async function moveBurialSiteTypeFieldUpToTop(burialSiteTypeFieldId) { + const database = await acquireConnection(); + const currentField = getCurrentField(burialSiteTypeFieldId, database); + if (currentField.orderNumber > 0) { + updateRecordOrderNumber('BurialSiteTypeFields', burialSiteTypeFieldId, -1, database); + database + .prepare(`update BurialSiteTypeFields + set orderNumber = orderNumber + 1 + where recordDelete_timeMillis is null + and burialSiteTypeId = ? + and orderNumber < ?`) + .run(currentField.burialSiteTypeId, currentField.orderNumber); + } + database.release(); + clearCacheByTableName('BurialSiteTypeFields'); + return true; +} diff --git a/database/moveBurialSiteTypeField.ts b/database/moveBurialSiteTypeField.ts new file mode 100644 index 00000000..a2bf93e9 --- /dev/null +++ b/database/moveBurialSiteTypeField.ts @@ -0,0 +1,163 @@ +import type { PoolConnection } from 'better-sqlite-pool' + +import { clearCacheByTableName } from '../helpers/functions.cache.js' + +import { acquireConnection } from './pool.js' +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' + +function getCurrentField( + burialSiteTypeFieldId: number | string, + connectedDatabase: PoolConnection +): { burialSiteTypeId?: number; orderNumber: number } { + return connectedDatabase + .prepare( + 'select burialSiteTypeId, orderNumber from BurialSiteTypeFields where burialSiteTypeFieldId = ?' + ) + .get(burialSiteTypeFieldId) as { + burialSiteTypeId?: number + orderNumber: number + } +} + +export async function moveBurialSiteTypeFieldDown( + burialSiteTypeFieldId: number | string +): Promise { + const database = await acquireConnection() + + const currentField = getCurrentField(burialSiteTypeFieldId, database) + + database + .prepare( + `update BurialSiteTypeFields + set orderNumber = orderNumber - 1 + where recordDelete_timeMillis is null + and burialSiteTypeId = ? and orderNumber = ? + 1` + ) + .run(currentField.burialSiteTypeId, currentField.orderNumber) + + const success = updateRecordOrderNumber( + 'BurialSiteTypeFields', + burialSiteTypeFieldId, + currentField.orderNumber + 1, + database + ) + + database.release() + + clearCacheByTableName('BurialSiteTypeFields') + + return success +} + +export async function moveBurialSiteTypeFieldDownToBottom( + burialSiteTypeFieldId: number | string +): Promise { + const database = await acquireConnection() + + const currentField = getCurrentField(burialSiteTypeFieldId, database) + + const maxOrderNumber = ( + database + .prepare( + `select max(orderNumber) as maxOrderNumber + from BurialSiteTypeFields + where recordDelete_timeMillis is null + and burialSiteTypeId = ?` + ) + .get(currentField.burialSiteTypeId) as { maxOrderNumber: number } + ).maxOrderNumber + + if (currentField.orderNumber !== maxOrderNumber) { + updateRecordOrderNumber( + 'BurialSiteTypeFields', + burialSiteTypeFieldId, + maxOrderNumber + 1, + database + ) + + database + .prepare( + `update BurialSiteTypeFields + set orderNumber = orderNumber - 1 + where recordDelete_timeMillis is null + and burialSiteTypeId = ? + and orderNumber > ?` + ) + .run(currentField.burialSiteTypeId, currentField.orderNumber) + } + + database.release() + + clearCacheByTableName('BurialSiteTypeFields') + + return true +} + +export async function moveBurialSiteTypeFieldUp( + burialSiteTypeFieldId: number | string +): Promise { + const database = await acquireConnection() + + const currentField = getCurrentField(burialSiteTypeFieldId, database) + + if (currentField.orderNumber <= 0) { + database.release() + return true + } + + database + .prepare( + `update BurialSiteTypeFields + set orderNumber = orderNumber + 1 + where recordDelete_timeMillis is null + and burialSiteTypeId = ? + and orderNumber = ? - 1` + ) + .run(currentField.burialSiteTypeId, currentField.orderNumber) + + const success = updateRecordOrderNumber( + 'BurialSiteTypeFields', + burialSiteTypeFieldId, + currentField.orderNumber - 1, + database + ) + + database.release() + + clearCacheByTableName('BurialSiteTypeFields') + + return success +} + +export async function moveBurialSiteTypeFieldUpToTop( + burialSiteTypeFieldId: number | string +): Promise { + const database = await acquireConnection() + + const currentField = getCurrentField(burialSiteTypeFieldId, database) + + if (currentField.orderNumber > 0) { + updateRecordOrderNumber( + 'BurialSiteTypeFields', + burialSiteTypeFieldId, + -1, + database + ) + + database + .prepare( + `update BurialSiteTypeFields + set orderNumber = orderNumber + 1 + where recordDelete_timeMillis is null + and burialSiteTypeId = ? + and orderNumber < ?` + ) + .run(currentField.burialSiteTypeId, currentField.orderNumber) + } + + database.release() + + clearCacheByTableName('BurialSiteTypeFields') + + return true +} diff --git a/database/moveContractTypeField.d.ts b/database/moveContractTypeField.d.ts new file mode 100644 index 00000000..8c12b2a7 --- /dev/null +++ b/database/moveContractTypeField.d.ts @@ -0,0 +1,4 @@ +export declare function moveContractTypeFieldDown(contractTypeFieldId: number | string): Promise; +export declare function moveContractTypeFieldDownToBottom(contractTypeFieldId: number | string): Promise; +export declare function moveContractTypeFieldUp(contractTypeFieldId: number | string): Promise; +export declare function moveContractTypeFieldUpToTop(contractTypeFieldId: number | string): Promise; diff --git a/database/moveContractTypeField.js b/database/moveContractTypeField.js new file mode 100644 index 00000000..f07b28f3 --- /dev/null +++ b/database/moveContractTypeField.js @@ -0,0 +1,102 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js'; +import { acquireConnection } from './pool.js'; +import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; +function getCurrentField(contractTypeFieldId, connectedDatabase) { + return connectedDatabase + .prepare(`select contractTypeId, orderNumber + from ContractTypeFields + where contractTypeFieldId = ?`) + .get(contractTypeFieldId); +} +export async function moveContractTypeFieldDown(contractTypeFieldId) { + const database = await acquireConnection(); + const currentField = getCurrentField(contractTypeFieldId, database); + database + .prepare(`update ContractTypeFields + set orderNumber = orderNumber - 1 + where recordDelete_timeMillis is null + ${currentField.contractTypeId === undefined + ? ' and contractTypeId is null' + : ` and contractTypeId = '${currentField.contractTypeId.toString()}'`} + and orderNumber = ? + 1`) + .run(currentField.orderNumber); + const success = updateRecordOrderNumber('ContractTypeFields', contractTypeFieldId, currentField.orderNumber + 1, database); + database.release(); + clearCacheByTableName('ContractTypeFields'); + return success; +} +export async function moveContractTypeFieldDownToBottom(contractTypeFieldId) { + const database = await acquireConnection(); + const currentField = getCurrentField(contractTypeFieldId, database); + const occupancyTypeParameters = []; + if (currentField.contractTypeId) { + occupancyTypeParameters.push(currentField.contractTypeId); + } + const maxOrderNumber = database + .prepare(`select max(orderNumber) as maxOrderNumber + from ContractTypeFields + where recordDelete_timeMillis is null + ${currentField.contractTypeId === undefined + ? ' and contractTypeId is null' + : ' and contractTypeId = ?'}`) + .get(occupancyTypeParameters).maxOrderNumber; + if (currentField.orderNumber !== maxOrderNumber) { + updateRecordOrderNumber('ContractTypeFields', contractTypeFieldId, maxOrderNumber + 1, database); + occupancyTypeParameters.push(currentField.orderNumber); + database + .prepare(`update ContractTypeFields set orderNumber = orderNumber - 1 + where recordDelete_timeMillis is null + ${currentField.contractTypeId === undefined + ? ' and contractTypeId is null' + : ' and contractTypeId = ?'} + and orderNumber > ?`) + .run(occupancyTypeParameters); + } + database.release(); + clearCacheByTableName('ContractTypeFields'); + return true; +} +export async function moveContractTypeFieldUp(contractTypeFieldId) { + const database = await acquireConnection(); + const currentField = getCurrentField(contractTypeFieldId, database); + if (currentField.orderNumber <= 0) { + database.release(); + return true; + } + database + .prepare(`update ContractTypeFields + set orderNumber = orderNumber + 1 + where recordDelete_timeMillis is null + ${currentField.contractTypeId === undefined + ? ' and contractTypeId is null' + : ` and contractTypeId = '${currentField.contractTypeId.toString()}'`} + and orderNumber = ? - 1`) + .run(currentField.orderNumber); + const success = updateRecordOrderNumber('ContractTypeFields', contractTypeFieldId, currentField.orderNumber - 1, database); + database.release(); + clearCacheByTableName('ContractTypeFields'); + return success; +} +export async function moveContractTypeFieldUpToTop(contractTypeFieldId) { + const database = await acquireConnection(); + const currentField = getCurrentField(contractTypeFieldId, database); + if (currentField.orderNumber > 0) { + updateRecordOrderNumber('ContractTypeFields', contractTypeFieldId, -1, database); + const occupancyTypeParameters = []; + if (currentField.contractTypeId) { + occupancyTypeParameters.push(currentField.contractTypeId); + } + occupancyTypeParameters.push(currentField.orderNumber); + database + .prepare(`update ContractTypeFields + set orderNumber = orderNumber + 1 + where recordDelete_timeMillis is null + ${currentField.contractTypeId + ? ' and contractTypeId = ?' + : ' and contractTypeId is null'} and orderNumber < ?`) + .run(occupancyTypeParameters); + } + database.release(); + clearCacheByTableName('ContractTypeFields'); + return true; +} diff --git a/database/moveOccupancyTypeField.ts b/database/moveContractTypeField.ts similarity index 51% rename from database/moveOccupancyTypeField.ts rename to database/moveContractTypeField.ts index 38027d74..b9a86010 100644 --- a/database/moveOccupancyTypeField.ts +++ b/database/moveContractTypeField.ts @@ -6,79 +6,79 @@ import { acquireConnection } from './pool.js' import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' function getCurrentField( - occupancyTypeFieldId: number | string, + contractTypeFieldId: number | string, connectedDatabase: PoolConnection -): { occupancyTypeId?: number; orderNumber: number } { +): { contractTypeId?: number; orderNumber: number } { return connectedDatabase .prepare( - `select occupancyTypeId, orderNumber - from OccupancyTypeFields - where occupancyTypeFieldId = ?` + `select contractTypeId, orderNumber + from ContractTypeFields + where contractTypeFieldId = ?` ) - .get(occupancyTypeFieldId) as { - occupancyTypeId?: number + .get(contractTypeFieldId) as { + contractTypeId?: number orderNumber: number } } -export async function moveOccupancyTypeFieldDown( - occupancyTypeFieldId: number | string +export async function moveContractTypeFieldDown( + contractTypeFieldId: number | string ): Promise { const database = await acquireConnection() - const currentField = getCurrentField(occupancyTypeFieldId, database) + const currentField = getCurrentField(contractTypeFieldId, database) database .prepare( - `update OccupancyTypeFields + `update ContractTypeFields set orderNumber = orderNumber - 1 where recordDelete_timeMillis is null ${ - currentField.occupancyTypeId === undefined - ? ' and occupancyTypeId is null' - : ` and occupancyTypeId = '${currentField.occupancyTypeId.toString()}'` + currentField.contractTypeId === undefined + ? ' and contractTypeId is null' + : ` and contractTypeId = '${currentField.contractTypeId.toString()}'` } and orderNumber = ? + 1` ) .run(currentField.orderNumber) const success = updateRecordOrderNumber( - 'OccupancyTypeFields', - occupancyTypeFieldId, + 'ContractTypeFields', + contractTypeFieldId, currentField.orderNumber + 1, database ) database.release() - clearCacheByTableName('OccupancyTypeFields') + clearCacheByTableName('ContractTypeFields') return success } -export async function moveOccupancyTypeFieldDownToBottom( - occupancyTypeFieldId: number | string +export async function moveContractTypeFieldDownToBottom( + contractTypeFieldId: number | string ): Promise { const database = await acquireConnection() - const currentField = getCurrentField(occupancyTypeFieldId, database) + const currentField = getCurrentField(contractTypeFieldId, database) const occupancyTypeParameters: unknown[] = [] - if (currentField.occupancyTypeId) { - occupancyTypeParameters.push(currentField.occupancyTypeId) + if (currentField.contractTypeId) { + occupancyTypeParameters.push(currentField.contractTypeId) } const maxOrderNumber: number = ( database .prepare( `select max(orderNumber) as maxOrderNumber - from OccupancyTypeFields + from ContractTypeFields where recordDelete_timeMillis is null ${ - currentField.occupancyTypeId === undefined - ? ' and occupancyTypeId is null' - : ' and occupancyTypeId = ?' + currentField.contractTypeId === undefined + ? ' and contractTypeId is null' + : ' and contractTypeId = ?' }` ) .get(occupancyTypeParameters) as { maxOrderNumber: number } @@ -86,8 +86,8 @@ export async function moveOccupancyTypeFieldDownToBottom( if (currentField.orderNumber !== maxOrderNumber) { updateRecordOrderNumber( - 'OccupancyTypeFields', - occupancyTypeFieldId, + 'ContractTypeFields', + contractTypeFieldId, maxOrderNumber + 1, database ) @@ -96,12 +96,12 @@ export async function moveOccupancyTypeFieldDownToBottom( database .prepare( - `update OccupancyTypeFields set orderNumber = orderNumber - 1 + `update ContractTypeFields set orderNumber = orderNumber - 1 where recordDelete_timeMillis is null ${ - currentField.occupancyTypeId === undefined - ? ' and occupancyTypeId is null' - : ' and occupancyTypeId = ?' + currentField.contractTypeId === undefined + ? ' and contractTypeId is null' + : ' and contractTypeId = ?' } and orderNumber > ?` ) @@ -110,17 +110,17 @@ export async function moveOccupancyTypeFieldDownToBottom( database.release() - clearCacheByTableName('OccupancyTypeFields') + clearCacheByTableName('ContractTypeFields') return true } -export async function moveOccupancyTypeFieldUp( - occupancyTypeFieldId: number | string +export async function moveContractTypeFieldUp( + contractTypeFieldId: number | string ): Promise { const database = await acquireConnection() - const currentField = getCurrentField(occupancyTypeFieldId, database) + const currentField = getCurrentField(contractTypeFieldId, database) if (currentField.orderNumber <= 0) { database.release() @@ -129,64 +129,64 @@ export async function moveOccupancyTypeFieldUp( database .prepare( - `update OccupancyTypeFields + `update ContractTypeFields set orderNumber = orderNumber + 1 where recordDelete_timeMillis is null ${ - currentField.occupancyTypeId === undefined - ? ' and occupancyTypeId is null' - : ` and occupancyTypeId = '${currentField.occupancyTypeId.toString()}'` + currentField.contractTypeId === undefined + ? ' and contractTypeId is null' + : ` and contractTypeId = '${currentField.contractTypeId.toString()}'` } and orderNumber = ? - 1` ) .run(currentField.orderNumber) const success = updateRecordOrderNumber( - 'OccupancyTypeFields', - occupancyTypeFieldId, + 'ContractTypeFields', + contractTypeFieldId, currentField.orderNumber - 1, database ) database.release() - clearCacheByTableName('OccupancyTypeFields') + clearCacheByTableName('ContractTypeFields') return success } -export async function moveOccupancyTypeFieldUpToTop( - occupancyTypeFieldId: number | string +export async function moveContractTypeFieldUpToTop( + contractTypeFieldId: number | string ): Promise { const database = await acquireConnection() - const currentField = getCurrentField(occupancyTypeFieldId, database) + const currentField = getCurrentField(contractTypeFieldId, database) if (currentField.orderNumber > 0) { updateRecordOrderNumber( - 'OccupancyTypeFields', - occupancyTypeFieldId, + 'ContractTypeFields', + contractTypeFieldId, -1, database ) const occupancyTypeParameters: unknown[] = [] - if (currentField.occupancyTypeId) { - occupancyTypeParameters.push(currentField.occupancyTypeId) + if (currentField.contractTypeId) { + occupancyTypeParameters.push(currentField.contractTypeId) } occupancyTypeParameters.push(currentField.orderNumber) database .prepare( - `update OccupancyTypeFields + `update ContractTypeFields set orderNumber = orderNumber + 1 where recordDelete_timeMillis is null ${ - currentField.occupancyTypeId - ? ' and occupancyTypeId = ?' - : ' and occupancyTypeId is null' + currentField.contractTypeId + ? ' and contractTypeId = ?' + : ' and contractTypeId is null' } and orderNumber < ?` ) .run(occupancyTypeParameters) @@ -194,7 +194,7 @@ export async function moveOccupancyTypeFieldUpToTop( database.release() - clearCacheByTableName('OccupancyTypeFields') + clearCacheByTableName('ContractTypeFields') return true } diff --git a/database/moveLotTypeField.d.ts b/database/moveLotTypeField.d.ts deleted file mode 100644 index 42c06734..00000000 --- a/database/moveLotTypeField.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export declare function moveLotTypeFieldDown(lotTypeFieldId: number | string): Promise; -export declare function moveLotTypeFieldDownToBottom(lotTypeFieldId: number | string): Promise; -export declare function moveLotTypeFieldUp(lotTypeFieldId: number | string): Promise; -export declare function moveLotTypeFieldUpToTop(lotTypeFieldId: number | string): Promise; diff --git a/database/moveLotTypeField.js b/database/moveLotTypeField.js deleted file mode 100644 index 3faab9e8..00000000 --- a/database/moveLotTypeField.js +++ /dev/null @@ -1,81 +0,0 @@ -import { clearCacheByTableName } from '../helpers/functions.cache.js'; -import { acquireConnection } from './pool.js'; -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; -function getCurrentField(lotTypeFieldId, connectedDatabase) { - return connectedDatabase - .prepare('select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?') - .get(lotTypeFieldId); -} -export async function moveLotTypeFieldDown(lotTypeFieldId) { - const database = await acquireConnection(); - const currentField = getCurrentField(lotTypeFieldId, database); - database - .prepare(`update LotTypeFields - set orderNumber = orderNumber - 1 - where recordDelete_timeMillis is null - and lotTypeId = ? and orderNumber = ? + 1`) - .run(currentField.lotTypeId, currentField.orderNumber); - const success = updateRecordOrderNumber('LotTypeFields', lotTypeFieldId, currentField.orderNumber + 1, database); - database.release(); - clearCacheByTableName('LotTypeFields'); - return success; -} -export async function moveLotTypeFieldDownToBottom(lotTypeFieldId) { - const database = await acquireConnection(); - const currentField = getCurrentField(lotTypeFieldId, database); - const maxOrderNumber = database - .prepare(`select max(orderNumber) as maxOrderNumber - from LotTypeFields - where recordDelete_timeMillis is null - and lotTypeId = ?`) - .get(currentField.lotTypeId).maxOrderNumber; - if (currentField.orderNumber !== maxOrderNumber) { - updateRecordOrderNumber('LotTypeFields', lotTypeFieldId, maxOrderNumber + 1, database); - database - .prepare(`update LotTypeFields - set orderNumber = orderNumber - 1 - where recordDelete_timeMillis is null - and lotTypeId = ? - and orderNumber > ?`) - .run(currentField.lotTypeId, currentField.orderNumber); - } - database.release(); - clearCacheByTableName('LotTypeFields'); - return true; -} -export async function moveLotTypeFieldUp(lotTypeFieldId) { - const database = await acquireConnection(); - const currentField = getCurrentField(lotTypeFieldId, database); - if (currentField.orderNumber <= 0) { - database.release(); - return true; - } - database - .prepare(`update LotTypeFields - set orderNumber = orderNumber + 1 - where recordDelete_timeMillis is null - and lotTypeId = ? - and orderNumber = ? - 1`) - .run(currentField.lotTypeId, currentField.orderNumber); - const success = updateRecordOrderNumber('LotTypeFields', lotTypeFieldId, currentField.orderNumber - 1, database); - database.release(); - clearCacheByTableName('LotTypeFields'); - return success; -} -export async function moveLotTypeFieldUpToTop(lotTypeFieldId) { - const database = await acquireConnection(); - const currentField = getCurrentField(lotTypeFieldId, database); - if (currentField.orderNumber > 0) { - updateRecordOrderNumber('LotTypeFields', lotTypeFieldId, -1, database); - database - .prepare(`update LotTypeFields - set orderNumber = orderNumber + 1 - where recordDelete_timeMillis is null - and lotTypeId = ? - and orderNumber < ?`) - .run(currentField.lotTypeId, currentField.orderNumber); - } - database.release(); - clearCacheByTableName('LotTypeFields'); - return true; -} diff --git a/database/moveLotTypeField.ts b/database/moveLotTypeField.ts deleted file mode 100644 index a98dcfaa..00000000 --- a/database/moveLotTypeField.ts +++ /dev/null @@ -1,155 +0,0 @@ -import type { PoolConnection } from 'better-sqlite-pool' - -import { clearCacheByTableName } from '../helpers/functions.cache.js' - -import { acquireConnection } from './pool.js' -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' - -function getCurrentField( - lotTypeFieldId: number | string, - connectedDatabase: PoolConnection -): { lotTypeId?: number; orderNumber: number } { - return connectedDatabase - .prepare( - 'select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?' - ) - .get(lotTypeFieldId) as { lotTypeId?: number; orderNumber: number } -} - -export async function moveLotTypeFieldDown( - lotTypeFieldId: number | string -): Promise { - const database = await acquireConnection() - - const currentField = getCurrentField(lotTypeFieldId, database) - - database - .prepare( - `update LotTypeFields - set orderNumber = orderNumber - 1 - where recordDelete_timeMillis is null - and lotTypeId = ? and orderNumber = ? + 1` - ) - .run(currentField.lotTypeId, currentField.orderNumber) - - const success = updateRecordOrderNumber( - 'LotTypeFields', - lotTypeFieldId, - currentField.orderNumber + 1, - database - ) - - database.release() - - clearCacheByTableName('LotTypeFields') - - return success -} - -export async function moveLotTypeFieldDownToBottom( - lotTypeFieldId: number | string -): Promise { - const database = await acquireConnection() - - const currentField = getCurrentField(lotTypeFieldId, database) - - const maxOrderNumber = ( - database - .prepare( - `select max(orderNumber) as maxOrderNumber - from LotTypeFields - where recordDelete_timeMillis is null - and lotTypeId = ?` - ) - .get(currentField.lotTypeId) as { maxOrderNumber: number } - ).maxOrderNumber - - if (currentField.orderNumber !== maxOrderNumber) { - updateRecordOrderNumber( - 'LotTypeFields', - lotTypeFieldId, - maxOrderNumber + 1, - database - ) - - database - .prepare( - `update LotTypeFields - set orderNumber = orderNumber - 1 - where recordDelete_timeMillis is null - and lotTypeId = ? - and orderNumber > ?` - ) - .run(currentField.lotTypeId, currentField.orderNumber) - } - - database.release() - - clearCacheByTableName('LotTypeFields') - - return true -} - -export async function moveLotTypeFieldUp( - lotTypeFieldId: number | string -): Promise { - const database = await acquireConnection() - - const currentField = getCurrentField(lotTypeFieldId, database) - - if (currentField.orderNumber <= 0) { - database.release() - return true - } - - database - .prepare( - `update LotTypeFields - set orderNumber = orderNumber + 1 - where recordDelete_timeMillis is null - and lotTypeId = ? - and orderNumber = ? - 1` - ) - .run(currentField.lotTypeId, currentField.orderNumber) - - const success = updateRecordOrderNumber( - 'LotTypeFields', - lotTypeFieldId, - currentField.orderNumber - 1, - database - ) - - database.release() - - clearCacheByTableName('LotTypeFields') - - return success -} - -export async function moveLotTypeFieldUpToTop( - lotTypeFieldId: number | string -): Promise { - const database = await acquireConnection() - - const currentField = getCurrentField(lotTypeFieldId, database) - - if (currentField.orderNumber > 0) { - updateRecordOrderNumber('LotTypeFields', lotTypeFieldId, -1, database) - - database - .prepare( - `update LotTypeFields - set orderNumber = orderNumber + 1 - where recordDelete_timeMillis is null - and lotTypeId = ? - and orderNumber < ?` - ) - .run(currentField.lotTypeId, currentField.orderNumber) - } - - database.release() - - clearCacheByTableName('LotTypeFields') - - return true -} diff --git a/database/moveOccupancyTypeField.d.ts b/database/moveOccupancyTypeField.d.ts deleted file mode 100644 index 36a3b0af..00000000 --- a/database/moveOccupancyTypeField.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export declare function moveOccupancyTypeFieldDown(occupancyTypeFieldId: number | string): Promise; -export declare function moveOccupancyTypeFieldDownToBottom(occupancyTypeFieldId: number | string): Promise; -export declare function moveOccupancyTypeFieldUp(occupancyTypeFieldId: number | string): Promise; -export declare function moveOccupancyTypeFieldUpToTop(occupancyTypeFieldId: number | string): Promise; diff --git a/database/moveOccupancyTypeField.js b/database/moveOccupancyTypeField.js deleted file mode 100644 index d147817b..00000000 --- a/database/moveOccupancyTypeField.js +++ /dev/null @@ -1,102 +0,0 @@ -import { clearCacheByTableName } from '../helpers/functions.cache.js'; -import { acquireConnection } from './pool.js'; -import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; -function getCurrentField(occupancyTypeFieldId, connectedDatabase) { - return connectedDatabase - .prepare(`select occupancyTypeId, orderNumber - from OccupancyTypeFields - where occupancyTypeFieldId = ?`) - .get(occupancyTypeFieldId); -} -export async function moveOccupancyTypeFieldDown(occupancyTypeFieldId) { - const database = await acquireConnection(); - const currentField = getCurrentField(occupancyTypeFieldId, database); - database - .prepare(`update OccupancyTypeFields - set orderNumber = orderNumber - 1 - where recordDelete_timeMillis is null - ${currentField.occupancyTypeId === undefined - ? ' and occupancyTypeId is null' - : ` and occupancyTypeId = '${currentField.occupancyTypeId.toString()}'`} - and orderNumber = ? + 1`) - .run(currentField.orderNumber); - const success = updateRecordOrderNumber('OccupancyTypeFields', occupancyTypeFieldId, currentField.orderNumber + 1, database); - database.release(); - clearCacheByTableName('OccupancyTypeFields'); - return success; -} -export async function moveOccupancyTypeFieldDownToBottom(occupancyTypeFieldId) { - const database = await acquireConnection(); - const currentField = getCurrentField(occupancyTypeFieldId, database); - const occupancyTypeParameters = []; - if (currentField.occupancyTypeId) { - occupancyTypeParameters.push(currentField.occupancyTypeId); - } - const maxOrderNumber = database - .prepare(`select max(orderNumber) as maxOrderNumber - from OccupancyTypeFields - where recordDelete_timeMillis is null - ${currentField.occupancyTypeId === undefined - ? ' and occupancyTypeId is null' - : ' and occupancyTypeId = ?'}`) - .get(occupancyTypeParameters).maxOrderNumber; - if (currentField.orderNumber !== maxOrderNumber) { - updateRecordOrderNumber('OccupancyTypeFields', occupancyTypeFieldId, maxOrderNumber + 1, database); - occupancyTypeParameters.push(currentField.orderNumber); - database - .prepare(`update OccupancyTypeFields set orderNumber = orderNumber - 1 - where recordDelete_timeMillis is null - ${currentField.occupancyTypeId === undefined - ? ' and occupancyTypeId is null' - : ' and occupancyTypeId = ?'} - and orderNumber > ?`) - .run(occupancyTypeParameters); - } - database.release(); - clearCacheByTableName('OccupancyTypeFields'); - return true; -} -export async function moveOccupancyTypeFieldUp(occupancyTypeFieldId) { - const database = await acquireConnection(); - const currentField = getCurrentField(occupancyTypeFieldId, database); - if (currentField.orderNumber <= 0) { - database.release(); - return true; - } - database - .prepare(`update OccupancyTypeFields - set orderNumber = orderNumber + 1 - where recordDelete_timeMillis is null - ${currentField.occupancyTypeId === undefined - ? ' and occupancyTypeId is null' - : ` and occupancyTypeId = '${currentField.occupancyTypeId.toString()}'`} - and orderNumber = ? - 1`) - .run(currentField.orderNumber); - const success = updateRecordOrderNumber('OccupancyTypeFields', occupancyTypeFieldId, currentField.orderNumber - 1, database); - database.release(); - clearCacheByTableName('OccupancyTypeFields'); - return success; -} -export async function moveOccupancyTypeFieldUpToTop(occupancyTypeFieldId) { - const database = await acquireConnection(); - const currentField = getCurrentField(occupancyTypeFieldId, database); - if (currentField.orderNumber > 0) { - updateRecordOrderNumber('OccupancyTypeFields', occupancyTypeFieldId, -1, database); - const occupancyTypeParameters = []; - if (currentField.occupancyTypeId) { - occupancyTypeParameters.push(currentField.occupancyTypeId); - } - occupancyTypeParameters.push(currentField.orderNumber); - database - .prepare(`update OccupancyTypeFields - set orderNumber = orderNumber + 1 - where recordDelete_timeMillis is null - ${currentField.occupancyTypeId - ? ' and occupancyTypeId = ?' - : ' and occupancyTypeId is null'} and orderNumber < ?`) - .run(occupancyTypeParameters); - } - database.release(); - clearCacheByTableName('OccupancyTypeFields'); - return true; -} diff --git a/database/moveOccupancyTypePrintDown.d.ts b/database/moveOccupancyTypePrintDown.d.ts index 64d29428..1f2bbbc2 100644 --- a/database/moveOccupancyTypePrintDown.d.ts +++ b/database/moveOccupancyTypePrintDown.d.ts @@ -1,3 +1,3 @@ -export declare function moveOccupancyTypePrintDown(occupancyTypeId: number | string, printEJS: string): Promise; -export declare function moveOccupancyTypePrintDownToBottom(occupancyTypeId: number | string, printEJS: string): Promise; +export declare function moveOccupancyTypePrintDown(contractTypeId: number | string, printEJS: string): Promise; +export declare function moveOccupancyTypePrintDownToBottom(contractTypeId: number | string, printEJS: string): Promise; export default moveOccupancyTypePrintDown; diff --git a/database/moveOccupancyTypePrintDown.js b/database/moveOccupancyTypePrintDown.js index 6bac50ec..03e3109d 100644 --- a/database/moveOccupancyTypePrintDown.js +++ b/database/moveOccupancyTypePrintDown.js @@ -1,52 +1,52 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js'; import { acquireConnection } from './pool.js'; -export async function moveOccupancyTypePrintDown(occupancyTypeId, printEJS) { +export async function moveOccupancyTypePrintDown(contractTypeId, printEJS) { const database = await acquireConnection(); const currentOrderNumber = database - .prepare('select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?') - .get(occupancyTypeId, printEJS).orderNumber; + .prepare('select orderNumber from ContractTypePrints where contractTypeId = ? and printEJS = ?') + .get(contractTypeId, printEJS).orderNumber; database - .prepare(`update OccupancyTypePrints + .prepare(`update ContractTypePrints set orderNumber = orderNumber - 1 where recordDelete_timeMillis is null - and occupancyTypeId = ? + and contractTypeId = ? and orderNumber = ? + 1`) - .run(occupancyTypeId, currentOrderNumber); + .run(contractTypeId, currentOrderNumber); const result = database - .prepare('update OccupancyTypePrints set orderNumber = ? + 1 where occupancyTypeId = ? and printEJS = ?') - .run(currentOrderNumber, occupancyTypeId, printEJS); + .prepare('update ContractTypePrints set orderNumber = ? + 1 where contractTypeId = ? and printEJS = ?') + .run(currentOrderNumber, contractTypeId, printEJS); database.release(); - clearCacheByTableName('OccupancyTypePrints'); + clearCacheByTableName('ContractTypePrints'); return result.changes > 0; } -export async function moveOccupancyTypePrintDownToBottom(occupancyTypeId, printEJS) { +export async function moveOccupancyTypePrintDownToBottom(contractTypeId, printEJS) { const database = await acquireConnection(); const currentOrderNumber = database - .prepare('select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?') - .get(occupancyTypeId, printEJS).orderNumber; + .prepare('select orderNumber from ContractTypePrints where contractTypeId = ? and printEJS = ?') + .get(contractTypeId, printEJS).orderNumber; const maxOrderNumber = database .prepare(`select max(orderNumber) as maxOrderNumber - from OccupancyTypePrints + from ContractTypePrints where recordDelete_timeMillis is null - and occupancyTypeId = ?`) - .get(occupancyTypeId).maxOrderNumber; + and contractTypeId = ?`) + .get(contractTypeId).maxOrderNumber; if (currentOrderNumber !== maxOrderNumber) { database - .prepare(`update OccupancyTypePrints + .prepare(`update ContractTypePrints set orderNumber = ? + 1 - where occupancyTypeId = ? + where contractTypeId = ? and printEJS = ?`) - .run(maxOrderNumber, occupancyTypeId, printEJS); + .run(maxOrderNumber, contractTypeId, printEJS); database - .prepare(`update OccupancyTypeFields + .prepare(`update ContractTypeFields set orderNumber = orderNumber - 1 where recordDelete_timeMillis is null - and occupancyTypeId = ? + and contractTypeId = ? and orderNumber > ?`) - .run(occupancyTypeId, currentOrderNumber); + .run(contractTypeId, currentOrderNumber); } database.release(); - clearCacheByTableName('OccupancyTypePrints'); + clearCacheByTableName('ContractTypePrints'); return true; } export default moveOccupancyTypePrintDown; diff --git a/database/moveOccupancyTypePrintDown.ts b/database/moveOccupancyTypePrintDown.ts index 5dcc374f..8e1609c6 100644 --- a/database/moveOccupancyTypePrintDown.ts +++ b/database/moveOccupancyTypePrintDown.ts @@ -3,7 +3,7 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js' import { acquireConnection } from './pool.js' export async function moveOccupancyTypePrintDown( - occupancyTypeId: number | string, + contractTypeId: number | string, printEJS: string ): Promise { const database = await acquireConnection() @@ -11,36 +11,36 @@ export async function moveOccupancyTypePrintDown( const currentOrderNumber = ( database .prepare( - 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' + 'select orderNumber from ContractTypePrints where contractTypeId = ? and printEJS = ?' ) - .get(occupancyTypeId, printEJS) as { orderNumber: number } + .get(contractTypeId, printEJS) as { orderNumber: number } ).orderNumber database .prepare( - `update OccupancyTypePrints + `update ContractTypePrints set orderNumber = orderNumber - 1 where recordDelete_timeMillis is null - and occupancyTypeId = ? + and contractTypeId = ? and orderNumber = ? + 1` ) - .run(occupancyTypeId, currentOrderNumber) + .run(contractTypeId, currentOrderNumber) const result = database .prepare( - 'update OccupancyTypePrints set orderNumber = ? + 1 where occupancyTypeId = ? and printEJS = ?' + 'update ContractTypePrints set orderNumber = ? + 1 where contractTypeId = ? and printEJS = ?' ) - .run(currentOrderNumber, occupancyTypeId, printEJS) + .run(currentOrderNumber, contractTypeId, printEJS) database.release() - clearCacheByTableName('OccupancyTypePrints') + clearCacheByTableName('ContractTypePrints') return result.changes > 0 } export async function moveOccupancyTypePrintDownToBottom( - occupancyTypeId: number | string, + contractTypeId: number | string, printEJS: string ): Promise { const database = await acquireConnection() @@ -48,46 +48,46 @@ export async function moveOccupancyTypePrintDownToBottom( const currentOrderNumber = ( database .prepare( - 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' + 'select orderNumber from ContractTypePrints where contractTypeId = ? and printEJS = ?' ) - .get(occupancyTypeId, printEJS) as { orderNumber: number } + .get(contractTypeId, printEJS) as { orderNumber: number } ).orderNumber const maxOrderNumber: number = ( database .prepare( `select max(orderNumber) as maxOrderNumber - from OccupancyTypePrints + from ContractTypePrints where recordDelete_timeMillis is null - and occupancyTypeId = ?` + and contractTypeId = ?` ) - .get(occupancyTypeId) as { maxOrderNumber: number } + .get(contractTypeId) as { maxOrderNumber: number } ).maxOrderNumber if (currentOrderNumber !== maxOrderNumber) { database .prepare( - `update OccupancyTypePrints + `update ContractTypePrints set orderNumber = ? + 1 - where occupancyTypeId = ? + where contractTypeId = ? and printEJS = ?` ) - .run(maxOrderNumber, occupancyTypeId, printEJS) + .run(maxOrderNumber, contractTypeId, printEJS) database .prepare( - `update OccupancyTypeFields + `update ContractTypeFields set orderNumber = orderNumber - 1 where recordDelete_timeMillis is null - and occupancyTypeId = ? + and contractTypeId = ? and orderNumber > ?` ) - .run(occupancyTypeId, currentOrderNumber) + .run(contractTypeId, currentOrderNumber) } database.release() - clearCacheByTableName('OccupancyTypePrints') + clearCacheByTableName('ContractTypePrints') return true } diff --git a/database/moveOccupancyTypePrintUp.d.ts b/database/moveOccupancyTypePrintUp.d.ts index 49787bfc..44878f13 100644 --- a/database/moveOccupancyTypePrintUp.d.ts +++ b/database/moveOccupancyTypePrintUp.d.ts @@ -1,3 +1,3 @@ -export declare function moveOccupancyTypePrintUp(occupancyTypeId: number | string, printEJS: string): Promise; -export declare function moveOccupancyTypePrintUpToTop(occupancyTypeId: number | string, printEJS: string): Promise; +export declare function moveOccupancyTypePrintUp(contractTypeId: number | string, printEJS: string): Promise; +export declare function moveOccupancyTypePrintUpToTop(contractTypeId: number | string, printEJS: string): Promise; export default moveOccupancyTypePrintUp; diff --git a/database/moveOccupancyTypePrintUp.js b/database/moveOccupancyTypePrintUp.js index d6c6827c..98d1d17b 100644 --- a/database/moveOccupancyTypePrintUp.js +++ b/database/moveOccupancyTypePrintUp.js @@ -1,50 +1,50 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js'; import { acquireConnection } from './pool.js'; -export async function moveOccupancyTypePrintUp(occupancyTypeId, printEJS) { +export async function moveOccupancyTypePrintUp(contractTypeId, printEJS) { const database = await acquireConnection(); const currentOrderNumber = database - .prepare('select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?') - .get(occupancyTypeId, printEJS).orderNumber; + .prepare('select orderNumber from ContractTypePrints where contractTypeId = ? and printEJS = ?') + .get(contractTypeId, printEJS).orderNumber; if (currentOrderNumber <= 0) { database.release(); return true; } database - .prepare(`update OccupancyTypePrints + .prepare(`update ContractTypePrints set orderNumber = orderNumber + 1 where recordDelete_timeMillis is null - and occupancyTypeId = ? + and contractTypeId = ? and orderNumber = ? - 1`) - .run(occupancyTypeId, currentOrderNumber); + .run(contractTypeId, currentOrderNumber); const result = database - .prepare('update OccupancyTypePrints set orderNumber = ? - 1 where occupancyTypeId = ? and printEJS = ?') - .run(currentOrderNumber, occupancyTypeId, printEJS); + .prepare('update ContractTypePrints set orderNumber = ? - 1 where contractTypeId = ? and printEJS = ?') + .run(currentOrderNumber, contractTypeId, printEJS); database.release(); - clearCacheByTableName('OccupancyTypePrints'); + clearCacheByTableName('ContractTypePrints'); return result.changes > 0; } -export async function moveOccupancyTypePrintUpToTop(occupancyTypeId, printEJS) { +export async function moveOccupancyTypePrintUpToTop(contractTypeId, printEJS) { const database = await acquireConnection(); const currentOrderNumber = database - .prepare('select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?') - .get(occupancyTypeId, printEJS).orderNumber; + .prepare('select orderNumber from ContractTypePrints where contractTypeId = ? and printEJS = ?') + .get(contractTypeId, printEJS).orderNumber; if (currentOrderNumber > 0) { database - .prepare(`update OccupancyTypePrints + .prepare(`update ContractTypePrints set orderNumber = -1 - where occupancyTypeId = ? + where contractTypeId = ? and printEJS = ?`) - .run(occupancyTypeId, printEJS); + .run(contractTypeId, printEJS); database - .prepare(`update OccupancyTypePrints + .prepare(`update ContractTypePrints set orderNumber = orderNumber + 1 where recordDelete_timeMillis is null - and occupancyTypeId = ? + and contractTypeId = ? and orderNumber < ?`) - .run(occupancyTypeId, currentOrderNumber); + .run(contractTypeId, currentOrderNumber); } database.release(); - clearCacheByTableName('OccupancyTypePrints'); + clearCacheByTableName('ContractTypePrints'); return true; } export default moveOccupancyTypePrintUp; diff --git a/database/moveOccupancyTypePrintUp.ts b/database/moveOccupancyTypePrintUp.ts index a0ba9aa8..30abea1b 100644 --- a/database/moveOccupancyTypePrintUp.ts +++ b/database/moveOccupancyTypePrintUp.ts @@ -3,7 +3,7 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js' import { acquireConnection } from './pool.js' export async function moveOccupancyTypePrintUp( - occupancyTypeId: number | string, + contractTypeId: number | string, printEJS: string ): Promise { const database = await acquireConnection() @@ -11,9 +11,9 @@ export async function moveOccupancyTypePrintUp( const currentOrderNumber = ( database .prepare( - 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' + 'select orderNumber from ContractTypePrints where contractTypeId = ? and printEJS = ?' ) - .get(occupancyTypeId, printEJS) as { orderNumber: number } + .get(contractTypeId, printEJS) as { orderNumber: number } ).orderNumber if (currentOrderNumber <= 0) { @@ -23,29 +23,29 @@ export async function moveOccupancyTypePrintUp( database .prepare( - `update OccupancyTypePrints + `update ContractTypePrints set orderNumber = orderNumber + 1 where recordDelete_timeMillis is null - and occupancyTypeId = ? + and contractTypeId = ? and orderNumber = ? - 1` ) - .run(occupancyTypeId, currentOrderNumber) + .run(contractTypeId, currentOrderNumber) const result = database .prepare( - 'update OccupancyTypePrints set orderNumber = ? - 1 where occupancyTypeId = ? and printEJS = ?' + 'update ContractTypePrints set orderNumber = ? - 1 where contractTypeId = ? and printEJS = ?' ) - .run(currentOrderNumber, occupancyTypeId, printEJS) + .run(currentOrderNumber, contractTypeId, printEJS) database.release() - clearCacheByTableName('OccupancyTypePrints') + clearCacheByTableName('ContractTypePrints') return result.changes > 0 } export async function moveOccupancyTypePrintUpToTop( - occupancyTypeId: number | string, + contractTypeId: number | string, printEJS: string ): Promise { const database = await acquireConnection() @@ -53,35 +53,35 @@ export async function moveOccupancyTypePrintUpToTop( const currentOrderNumber = ( database .prepare( - 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' + 'select orderNumber from ContractTypePrints where contractTypeId = ? and printEJS = ?' ) - .get(occupancyTypeId, printEJS) as { orderNumber: number } + .get(contractTypeId, printEJS) as { orderNumber: number } ).orderNumber if (currentOrderNumber > 0) { database .prepare( - `update OccupancyTypePrints + `update ContractTypePrints set orderNumber = -1 - where occupancyTypeId = ? + where contractTypeId = ? and printEJS = ?` ) - .run(occupancyTypeId, printEJS) + .run(contractTypeId, printEJS) database .prepare( - `update OccupancyTypePrints + `update ContractTypePrints set orderNumber = orderNumber + 1 where recordDelete_timeMillis is null - and occupancyTypeId = ? + and contractTypeId = ? and orderNumber < ?` ) - .run(occupancyTypeId, currentOrderNumber) + .run(contractTypeId, currentOrderNumber) } database.release() - clearCacheByTableName('OccupancyTypePrints') + clearCacheByTableName('ContractTypePrints') return true } diff --git a/database/moveRecord.d.ts b/database/moveRecord.d.ts index a828bf37..49d35c9e 100644 --- a/database/moveRecord.d.ts +++ b/database/moveRecord.d.ts @@ -1,4 +1,4 @@ -type RecordTable = 'FeeCategories' | 'LotOccupantTypes' | 'LotStatuses' | 'LotTypes' | 'OccupancyTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; +type RecordTable = 'FeeCategories' | 'BurialSiteStatuses' | 'BurialSiteTypes' | 'ContractTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; export declare function moveRecordDown(recordTable: RecordTable, recordId: number | string): Promise; export declare function moveRecordDownToBottom(recordTable: RecordTable, recordId: number | string): Promise; export declare function moveRecordUp(recordTable: RecordTable, recordId: number | string): Promise; diff --git a/database/moveRecord.js b/database/moveRecord.js index 564d6e07..315b802c 100644 --- a/database/moveRecord.js +++ b/database/moveRecord.js @@ -3,10 +3,9 @@ import { acquireConnection } from './pool.js'; import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'; const recordIdColumns = new Map(); recordIdColumns.set('FeeCategories', 'feeCategoryId'); -recordIdColumns.set('LotOccupantTypes', 'lotOccupantTypeId'); -recordIdColumns.set('LotStatuses', 'lotStatusId'); -recordIdColumns.set('LotTypes', 'lotTypeId'); -recordIdColumns.set('OccupancyTypes', 'occupancyTypeId'); +recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId'); +recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId'); +recordIdColumns.set('ContractTypes', 'contractTypeId'); recordIdColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneTypeId'); recordIdColumns.set('WorkOrderTypes', 'workOrderTypeId'); function getCurrentOrderNumber(recordTable, recordId, database) { diff --git a/database/moveRecord.ts b/database/moveRecord.ts index ec5342c3..b294bf3c 100644 --- a/database/moveRecord.ts +++ b/database/moveRecord.ts @@ -7,19 +7,17 @@ import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' type RecordTable = | 'FeeCategories' - | 'LotOccupantTypes' - | 'LotStatuses' - | 'LotTypes' - | 'OccupancyTypes' + | 'BurialSiteStatuses' + | 'BurialSiteTypes' + | 'ContractTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes' const recordIdColumns = new Map() recordIdColumns.set('FeeCategories', 'feeCategoryId') -recordIdColumns.set('LotOccupantTypes', 'lotOccupantTypeId') -recordIdColumns.set('LotStatuses', 'lotStatusId') -recordIdColumns.set('LotTypes', 'lotTypeId') -recordIdColumns.set('OccupancyTypes', 'occupancyTypeId') +recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId') +recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId') +recordIdColumns.set('ContractTypes', 'contractTypeId') recordIdColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneTypeId') recordIdColumns.set('WorkOrderTypes', 'workOrderTypeId') diff --git a/database/updateBurialSite.d.ts b/database/updateBurialSite.d.ts new file mode 100644 index 00000000..dc598daf --- /dev/null +++ b/database/updateBurialSite.d.ts @@ -0,0 +1,18 @@ +export interface UpdateBurialSiteForm { + burialSiteId: string | number; + burialSiteNameSegment1: string; + burialSiteNameSegment2?: string; + burialSiteNameSegment3?: string; + burialSiteNameSegment4?: string; + burialSiteNameSegment5?: string; + burialSiteTypeId: string | number; + burialSiteStatusId: string | number; + cemeteryId: string | number; + cemeterySvgId: string; + burialSiteLatitude: string; + burialSiteLongitude: string; + burialSiteTypeFieldIds?: string; + [fieldValue_burialSiteTypeFieldId: string]: unknown; +} +export default function updateBurialSite(updateForm: UpdateBurialSiteForm, user: User): Promise; +export declare function updateBurialSiteStatus(burialSiteId: number | string, burialSiteStatusId: number | string, user: User): Promise; diff --git a/database/updateBurialSite.js b/database/updateBurialSite.js new file mode 100644 index 00000000..96c61c21 --- /dev/null +++ b/database/updateBurialSite.js @@ -0,0 +1,59 @@ +import addOrUpdateBurialSiteField from './addOrUpdateBurialSiteField.js'; +import deleteBurialSiteField from './deleteBurialSiteField.js'; +import { acquireConnection } from './pool.js'; +export default async function updateBurialSite(updateForm, user) { + const database = await acquireConnection(); + const result = database + .prepare(`update BurialSites + set burialSiteNameSegment1 = ?, + burialSiteNameSegment2 = ?, + burialSiteNameSegment3 = ?, + burialSiteNameSegment4 = ?, + burialSiteNameSegment5 = ?, + burialSiteTypeId = ?, + burialSiteStatusId = ?, + cemeteryId = ?, + cemeterySvgId = ?, + burialSiteLatitude = ?, + burialSiteLongitude = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where lotId = ? + and recordDelete_timeMillis is null`) + .run(updateForm.burialSiteNameSegment1, updateForm.burialSiteNameSegment2 ?? '', updateForm.burialSiteNameSegment3 ?? '', updateForm.burialSiteNameSegment4 ?? '', updateForm.burialSiteNameSegment5 ?? '', updateForm.burialSiteTypeId, updateForm.burialSiteStatusId === '' + ? undefined + : updateForm.burialSiteStatusId, updateForm.cemeteryId === '' ? undefined : updateForm.cemeteryId, updateForm.cemeterySvgId, updateForm.burialSiteLatitude === '' + ? undefined + : updateForm.burialSiteLatitude, updateForm.burialSiteLongitude === '' + ? undefined + : updateForm.burialSiteLongitude, user.userName, Date.now(), updateForm.burialSiteId); + if (result.changes > 0) { + const burialSiteTypeFieldIds = (updateForm.burialSiteTypeFieldIds ?? '').split(','); + for (const burialSiteTypeFieldId of burialSiteTypeFieldIds) { + const fieldValue = updateForm[`fieldValue_${burialSiteTypeFieldId}`]; + await ((fieldValue ?? '') === '' + ? deleteBurialSiteField(updateForm.burialSiteId, burialSiteTypeFieldId, user, database) + : addOrUpdateBurialSiteField({ + burialSiteId: updateForm.burialSiteId, + burialSiteTypeFieldId, + fieldValue: fieldValue ?? '' + }, user, database)); + } + } + database.release(); + return result.changes > 0; +} +export async function updateBurialSiteStatus(burialSiteId, burialSiteStatusId, user) { + const database = await acquireConnection(); + const rightNowMillis = Date.now(); + const result = database + .prepare(`update BurialSites + set burialSiteStatusId = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where burialSiteId = ? + and recordDelete_timeMillis is null`) + .run(burialSiteStatusId === '' ? undefined : burialSiteStatusId, user.userName, rightNowMillis, burialSiteId); + database.release(); + return result.changes > 0; +} diff --git a/database/updateBurialSite.ts b/database/updateBurialSite.ts new file mode 100644 index 00000000..e16a4d6e --- /dev/null +++ b/database/updateBurialSite.ts @@ -0,0 +1,137 @@ +import addOrUpdateBurialSiteField from './addOrUpdateBurialSiteField.js' +import deleteBurialSiteField from './deleteBurialSiteField.js' +import { acquireConnection } from './pool.js' + +export interface UpdateBurialSiteForm { + burialSiteId: string | number + + burialSiteNameSegment1: string + burialSiteNameSegment2?: string + burialSiteNameSegment3?: string + burialSiteNameSegment4?: string + burialSiteNameSegment5?: string + + burialSiteTypeId: string | number + burialSiteStatusId: string | number + + cemeteryId: string | number + cemeterySvgId: string + + burialSiteLatitude: string + burialSiteLongitude: string + + burialSiteTypeFieldIds?: string + [fieldValue_burialSiteTypeFieldId: string]: unknown +} + +export default async function updateBurialSite( + updateForm: UpdateBurialSiteForm, + user: User +): Promise { + const database = await acquireConnection() + + const result = database + .prepare( + `update BurialSites + set burialSiteNameSegment1 = ?, + burialSiteNameSegment2 = ?, + burialSiteNameSegment3 = ?, + burialSiteNameSegment4 = ?, + burialSiteNameSegment5 = ?, + burialSiteTypeId = ?, + burialSiteStatusId = ?, + cemeteryId = ?, + cemeterySvgId = ?, + burialSiteLatitude = ?, + burialSiteLongitude = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where lotId = ? + and recordDelete_timeMillis is null` + ) + .run( + updateForm.burialSiteNameSegment1, + updateForm.burialSiteNameSegment2 ?? '', + updateForm.burialSiteNameSegment3 ?? '', + updateForm.burialSiteNameSegment4 ?? '', + updateForm.burialSiteNameSegment5 ?? '', + updateForm.burialSiteTypeId, + updateForm.burialSiteStatusId === '' + ? undefined + : updateForm.burialSiteStatusId, + updateForm.cemeteryId === '' ? undefined : updateForm.cemeteryId, + updateForm.cemeterySvgId, + updateForm.burialSiteLatitude === '' + ? undefined + : updateForm.burialSiteLatitude, + updateForm.burialSiteLongitude === '' + ? undefined + : updateForm.burialSiteLongitude, + user.userName, + Date.now(), + updateForm.burialSiteId + ) + + if (result.changes > 0) { + const burialSiteTypeFieldIds = ( + updateForm.burialSiteTypeFieldIds ?? '' + ).split(',') + + for (const burialSiteTypeFieldId of burialSiteTypeFieldIds) { + const fieldValue = updateForm[`fieldValue_${burialSiteTypeFieldId}`] as + | string + | undefined + + await ((fieldValue ?? '') === '' + ? deleteBurialSiteField( + updateForm.burialSiteId, + burialSiteTypeFieldId, + user, + database + ) + : addOrUpdateBurialSiteField( + { + burialSiteId: updateForm.burialSiteId, + burialSiteTypeFieldId, + fieldValue: fieldValue ?? '' + }, + user, + database + )) + } + } + + database.release() + + return result.changes > 0 +} + +export async function updateBurialSiteStatus( + burialSiteId: number | string, + burialSiteStatusId: number | string, + user: User +): Promise { + const database = await acquireConnection() + + const rightNowMillis = Date.now() + + const result = database + .prepare( + `update BurialSites + set burialSiteStatusId = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where burialSiteId = ? + and recordDelete_timeMillis is null` + ) + .run( + burialSiteStatusId === '' ? undefined : burialSiteStatusId, + user.userName, + rightNowMillis, + burialSiteId + ) + + database.release() + + return result.changes > 0 +} diff --git a/database/updateBurialSiteComment.d.ts b/database/updateBurialSiteComment.d.ts new file mode 100644 index 00000000..8fafef92 --- /dev/null +++ b/database/updateBurialSiteComment.d.ts @@ -0,0 +1,8 @@ +import { type DateString, type TimeString } from '@cityssm/utils-datetime'; +export interface UpdateBurialSiteCommentForm { + burialSiteCommentId: string | number; + commentDateString: DateString; + commentTimeString: TimeString; + comment: string; +} +export default function updateBurialSiteComment(commentForm: UpdateBurialSiteCommentForm, user: User): Promise; diff --git a/database/updateBurialSiteComment.js b/database/updateBurialSiteComment.js new file mode 100644 index 00000000..7442bcd1 --- /dev/null +++ b/database/updateBurialSiteComment.js @@ -0,0 +1,17 @@ +import { dateStringToInteger, timeStringToInteger } from '@cityssm/utils-datetime'; +import { acquireConnection } from './pool.js'; +export default async function updateBurialSiteComment(commentForm, user) { + const database = await acquireConnection(); + const result = database + .prepare(`update BurialSiteComments + set commentDate = ?, + commentTime = ?, + comment = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where recordDelete_timeMillis is null + and burialSiteCommentId = ?`) + .run(dateStringToInteger(commentForm.commentDateString), timeStringToInteger(commentForm.commentTimeString), commentForm.comment, user.userName, Date.now(), commentForm.burialSiteCommentId); + database.release(); + return result.changes > 0; +} diff --git a/database/updateBurialSiteComment.ts b/database/updateBurialSiteComment.ts new file mode 100644 index 00000000..fdee0858 --- /dev/null +++ b/database/updateBurialSiteComment.ts @@ -0,0 +1,46 @@ +import { + type DateString, + type TimeString, + dateStringToInteger, + timeStringToInteger +} from '@cityssm/utils-datetime' + +import { acquireConnection } from './pool.js' + +export interface UpdateBurialSiteCommentForm { + burialSiteCommentId: string | number + commentDateString: DateString + commentTimeString: TimeString + comment: string +} + +export default async function updateBurialSiteComment( + commentForm: UpdateBurialSiteCommentForm, + user: User +): Promise { + const database = await acquireConnection() + + const result = database + .prepare( + `update BurialSiteComments + set commentDate = ?, + commentTime = ?, + comment = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where recordDelete_timeMillis is null + and burialSiteCommentId = ?` + ) + .run( + dateStringToInteger(commentForm.commentDateString), + timeStringToInteger(commentForm.commentTimeString), + commentForm.comment, + user.userName, + Date.now(), + commentForm.burialSiteCommentId + ) + + database.release() + + return result.changes > 0 +} diff --git a/database/updateBurialSiteContract.d.ts b/database/updateBurialSiteContract.d.ts new file mode 100644 index 00000000..dfe10e15 --- /dev/null +++ b/database/updateBurialSiteContract.d.ts @@ -0,0 +1,11 @@ +import { type DateString } from '@cityssm/utils-datetime'; +export interface UpdateBurialSiteContractForm { + burialSiteContractId: string | number; + contractTypeId: string | number; + burialSiteId: string | number; + contractStartDateString: DateString; + contractEndDateString: DateString | ''; + contractTypeFieldIds?: string; + [fieldValue_contractTypeFieldId: string]: unknown; +} +export default function updateBurialSiteContract(updateForm: UpdateBurialSiteContractForm, user: User): Promise; diff --git a/database/updateBurialSiteContract.js b/database/updateBurialSiteContract.js new file mode 100644 index 00000000..901c4d8c --- /dev/null +++ b/database/updateBurialSiteContract.js @@ -0,0 +1,36 @@ +import { dateStringToInteger } from '@cityssm/utils-datetime'; +import addOrUpdateBurialSiteContractField from './addOrUpdateBurialSiteContractField.js'; +import deleteBurialSiteContractField from './deleteBurialSiteContractField.js'; +import { acquireConnection } from './pool.js'; +export default async function updateBurialSiteContract(updateForm, user) { + const database = await acquireConnection(); + const result = database + .prepare(`update BurialSiteContracts + set contractTypeId = ?, + burialSiteId = ?, + contractStartDate = ?, + contractEndDate = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where burialSiteContractId = ? + and recordDelete_timeMillis is null`) + .run(updateForm.contractTypeId, updateForm.burialSiteId === '' ? undefined : updateForm.burialSiteId, dateStringToInteger(updateForm.contractStartDateString), updateForm.contractEndDateString === '' + ? undefined + : dateStringToInteger(updateForm.contractEndDateString), user.userName, Date.now(), updateForm.burialSiteContractId); + if (result.changes > 0) { + const contractTypeFieldIds = (updateForm.contractTypeFieldIds ?? '').split(','); + for (const contractTypeFieldId of contractTypeFieldIds) { + const fieldValue = updateForm[`fieldValue_${contractTypeFieldId}`]; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + await ((fieldValue ?? '') === '' + ? deleteBurialSiteContractField(updateForm.burialSiteContractId, contractTypeFieldId, user, database) + : addOrUpdateBurialSiteContractField({ + burialSiteContractId: updateForm.burialSiteContractId, + contractTypeFieldId, + fieldValue + }, user, database)); + } + } + database.release(); + return result.changes > 0; +} diff --git a/database/updateBurialSiteContract.ts b/database/updateBurialSiteContract.ts new file mode 100644 index 00000000..103462f6 --- /dev/null +++ b/database/updateBurialSiteContract.ts @@ -0,0 +1,82 @@ +import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime' + +import addOrUpdateBurialSiteContractField from './addOrUpdateBurialSiteContractField.js' +import deleteBurialSiteContractField from './deleteBurialSiteContractField.js' +import { acquireConnection } from './pool.js' + +export interface UpdateBurialSiteContractForm { + burialSiteContractId: string | number + contractTypeId: string | number + burialSiteId: string | number + + contractStartDateString: DateString + contractEndDateString: DateString | '' + + contractTypeFieldIds?: string + [fieldValue_contractTypeFieldId: string]: unknown +} + +export default async function updateBurialSiteContract( + updateForm: UpdateBurialSiteContractForm, + user: User +): Promise { + const database = await acquireConnection() + + const result = database + .prepare( + `update BurialSiteContracts + set contractTypeId = ?, + burialSiteId = ?, + contractStartDate = ?, + contractEndDate = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where burialSiteContractId = ? + and recordDelete_timeMillis is null` + ) + .run( + updateForm.contractTypeId, + updateForm.burialSiteId === '' ? undefined : updateForm.burialSiteId, + dateStringToInteger(updateForm.contractStartDateString), + updateForm.contractEndDateString === '' + ? undefined + : dateStringToInteger(updateForm.contractEndDateString), + user.userName, + Date.now(), + updateForm.burialSiteContractId + ) + + if (result.changes > 0) { + const contractTypeFieldIds = ( + updateForm.contractTypeFieldIds ?? '' + ).split(',') + + for (const contractTypeFieldId of contractTypeFieldIds) { + const fieldValue = updateForm[ + `fieldValue_${contractTypeFieldId}` + ] as string + + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + await ((fieldValue ?? '') === '' + ? deleteBurialSiteContractField( + updateForm.burialSiteContractId, + contractTypeFieldId, + user, + database + ) + : addOrUpdateBurialSiteContractField( + { + burialSiteContractId: updateForm.burialSiteContractId, + contractTypeFieldId, + fieldValue + }, + user, + database + )) + } + } + + database.release() + + return result.changes > 0 +} diff --git a/database/updateBurialSiteContractComment.d.ts b/database/updateBurialSiteContractComment.d.ts new file mode 100644 index 00000000..0a20be62 --- /dev/null +++ b/database/updateBurialSiteContractComment.d.ts @@ -0,0 +1,8 @@ +import { type DateString, type TimeString } from '@cityssm/utils-datetime'; +export interface BurialSiteCommentUpdateForm { + burialSiteContractCommentId: string | number; + commentDateString: DateString; + commentTimeString: TimeString; + comment: string; +} +export default function updateBurialSiteContractComment(commentForm: BurialSiteCommentUpdateForm, user: User): Promise; diff --git a/database/updateBurialSiteContractComment.js b/database/updateBurialSiteContractComment.js new file mode 100644 index 00000000..b0b3859c --- /dev/null +++ b/database/updateBurialSiteContractComment.js @@ -0,0 +1,17 @@ +import { dateStringToInteger, timeStringToInteger } from '@cityssm/utils-datetime'; +import { acquireConnection } from './pool.js'; +export default async function updateBurialSiteContractComment(commentForm, user) { + const database = await acquireConnection(); + const result = database + .prepare(`update BurialSiteContractComments + set commentDate = ?, + commentTime = ?, + comment = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where recordDelete_timeMillis is null + and burialSiteContractCommentId = ?`) + .run(dateStringToInteger(commentForm.commentDateString), timeStringToInteger(commentForm.commentTimeString), commentForm.comment, user.userName, Date.now(), commentForm.burialSiteContractCommentId); + database.release(); + return result.changes > 0; +} diff --git a/database/updateBurialSiteContractComment.ts b/database/updateBurialSiteContractComment.ts new file mode 100644 index 00000000..c66ce316 --- /dev/null +++ b/database/updateBurialSiteContractComment.ts @@ -0,0 +1,46 @@ +import { + type DateString, + type TimeString, + dateStringToInteger, + timeStringToInteger +} from '@cityssm/utils-datetime' + +import { acquireConnection } from './pool.js' + +export interface BurialSiteCommentUpdateForm { + burialSiteContractCommentId: string | number + commentDateString: DateString + commentTimeString: TimeString + comment: string +} + +export default async function updateBurialSiteContractComment( + commentForm: BurialSiteCommentUpdateForm, + user: User +): Promise { + const database = await acquireConnection() + + const result = database + .prepare( + `update BurialSiteContractComments + set commentDate = ?, + commentTime = ?, + comment = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where recordDelete_timeMillis is null + and burialSiteContractCommentId = ?` + ) + .run( + dateStringToInteger(commentForm.commentDateString), + timeStringToInteger(commentForm.commentTimeString), + commentForm.comment, + user.userName, + Date.now(), + commentForm.burialSiteContractCommentId + ) + + database.release() + + return result.changes > 0 +} diff --git a/database/updateBurialSiteContractFeeQuantity.d.ts b/database/updateBurialSiteContractFeeQuantity.d.ts new file mode 100644 index 00000000..3ea59793 --- /dev/null +++ b/database/updateBurialSiteContractFeeQuantity.d.ts @@ -0,0 +1,6 @@ +export interface UpdateBurialSiteFeeForm { + burialSiteContractId: string | number; + feeId: string | number; + quantity: string | number; +} +export default function updateBurialSiteContractFeeQuantity(feeQuantityForm: UpdateBurialSiteFeeForm, user: User): Promise; diff --git a/database/updateLotOccupancyFeeQuantity.js b/database/updateBurialSiteContractFeeQuantity.js similarity index 63% rename from database/updateLotOccupancyFeeQuantity.js rename to database/updateBurialSiteContractFeeQuantity.js index fa41c090..1d510591 100644 --- a/database/updateLotOccupancyFeeQuantity.js +++ b/database/updateBurialSiteContractFeeQuantity.js @@ -1,15 +1,15 @@ import { acquireConnection } from './pool.js'; -export default async function updateLotOccupancyFeeQuantity(feeQuantityForm, user) { +export default async function updateBurialSiteContractFeeQuantity(feeQuantityForm, user) { const database = await acquireConnection(); const result = database - .prepare(`update LotOccupancyFees + .prepare(`update BurialSiteContractFees set quantity = ?, recordUpdate_userName = ?, recordUpdate_timeMillis = ? where recordDelete_timeMillis is null - and lotOccupancyId = ? + and burialSiteContractId = ? and feeId = ?`) - .run(feeQuantityForm.quantity, user.userName, Date.now(), feeQuantityForm.lotOccupancyId, feeQuantityForm.feeId); + .run(feeQuantityForm.quantity, user.userName, Date.now(), feeQuantityForm.burialSiteContractId, feeQuantityForm.feeId); database.release(); return result.changes > 0; } diff --git a/database/updateLotOccupancyFeeQuantity.ts b/database/updateBurialSiteContractFeeQuantity.ts similarity index 64% rename from database/updateLotOccupancyFeeQuantity.ts rename to database/updateBurialSiteContractFeeQuantity.ts index 113552b5..2557a4a6 100644 --- a/database/updateLotOccupancyFeeQuantity.ts +++ b/database/updateBurialSiteContractFeeQuantity.ts @@ -1,32 +1,32 @@ import { acquireConnection } from './pool.js' -export interface UpdateLotOccupancyFeeQuantityForm { - lotOccupancyId: string | number +export interface UpdateBurialSiteFeeForm { + burialSiteContractId: string | number feeId: string | number quantity: string | number } -export default async function updateLotOccupancyFeeQuantity( - feeQuantityForm: UpdateLotOccupancyFeeQuantityForm, +export default async function updateBurialSiteContractFeeQuantity( + feeQuantityForm: UpdateBurialSiteFeeForm, user: User ): Promise { const database = await acquireConnection() const result = database .prepare( - `update LotOccupancyFees + `update BurialSiteContractFees set quantity = ?, recordUpdate_userName = ?, recordUpdate_timeMillis = ? where recordDelete_timeMillis is null - and lotOccupancyId = ? + and burialSiteContractId = ? and feeId = ?` ) .run( feeQuantityForm.quantity, user.userName, Date.now(), - feeQuantityForm.lotOccupancyId, + feeQuantityForm.burialSiteContractId, feeQuantityForm.feeId ) diff --git a/database/updateLotOccupancyTransaction.d.ts b/database/updateBurialSiteContractTransaction.d.ts similarity index 54% rename from database/updateLotOccupancyTransaction.d.ts rename to database/updateBurialSiteContractTransaction.d.ts index a9728b32..452b4709 100644 --- a/database/updateLotOccupancyTransaction.d.ts +++ b/database/updateBurialSiteContractTransaction.d.ts @@ -1,6 +1,6 @@ import { type DateString, type TimeString } from '@cityssm/utils-datetime'; -export interface UpdateLotOccupancyTransactionForm { - lotOccupancyId: string | number; +export interface BurialSiteContractTransactionUpdateForm { + burialSiteContractId: string | number; transactionIndex: string | number; transactionDateString: DateString; transactionTimeString: TimeString; @@ -8,4 +8,4 @@ export interface UpdateLotOccupancyTransactionForm { externalReceiptNumber: string; transactionNote: string; } -export default function updateLotOccupancyTransaction(lotOccupancyTransactionForm: UpdateLotOccupancyTransactionForm, user: User): Promise; +export default function updateBurialSiteContractTransaction(updateForm: BurialSiteContractTransactionUpdateForm, user: User): Promise; diff --git a/database/updateBurialSiteContractTransaction.js b/database/updateBurialSiteContractTransaction.js new file mode 100644 index 00000000..20be3501 --- /dev/null +++ b/database/updateBurialSiteContractTransaction.js @@ -0,0 +1,20 @@ +import { dateStringToInteger, timeStringToInteger } from '@cityssm/utils-datetime'; +import { acquireConnection } from './pool.js'; +export default async function updateBurialSiteContractTransaction(updateForm, user) { + const database = await acquireConnection(); + const result = database + .prepare(`update BurialSiteContractTransactions + set transactionAmount = ?, + externalReceiptNumber = ?, + transactionNote = ?, + transactionDate = ?, + transactionTime = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where recordDelete_timeMillis is null + and burialSiteContractId = ? + and transactionIndex = ?`) + .run(updateForm.transactionAmount, updateForm.externalReceiptNumber, updateForm.transactionNote, dateStringToInteger(updateForm.transactionDateString), timeStringToInteger(updateForm.transactionTimeString), user.userName, Date.now(), updateForm.burialSiteContractId, updateForm.transactionIndex); + database.release(); + return result.changes > 0; +} diff --git a/database/updateLotOccupancyTransaction.ts b/database/updateBurialSiteContractTransaction.ts similarity index 56% rename from database/updateLotOccupancyTransaction.ts rename to database/updateBurialSiteContractTransaction.ts index ca4ec1dd..71ec332f 100644 --- a/database/updateLotOccupancyTransaction.ts +++ b/database/updateBurialSiteContractTransaction.ts @@ -7,8 +7,8 @@ import { import { acquireConnection } from './pool.js' -export interface UpdateLotOccupancyTransactionForm { - lotOccupancyId: string | number +export interface BurialSiteContractTransactionUpdateForm { + burialSiteContractId: string | number transactionIndex: string | number transactionDateString: DateString transactionTimeString: TimeString @@ -17,15 +17,15 @@ export interface UpdateLotOccupancyTransactionForm { transactionNote: string } -export default async function updateLotOccupancyTransaction( - lotOccupancyTransactionForm: UpdateLotOccupancyTransactionForm, +export default async function updateBurialSiteContractTransaction( + updateForm: BurialSiteContractTransactionUpdateForm, user: User ): Promise { const database = await acquireConnection() const result = database .prepare( - `update LotOccupancyTransactions + `update BurialSiteContractTransactions set transactionAmount = ?, externalReceiptNumber = ?, transactionNote = ?, @@ -34,19 +34,19 @@ export default async function updateLotOccupancyTransaction( recordUpdate_userName = ?, recordUpdate_timeMillis = ? where recordDelete_timeMillis is null - and lotOccupancyId = ? + and burialSiteContractId = ? and transactionIndex = ?` ) .run( - lotOccupancyTransactionForm.transactionAmount, - lotOccupancyTransactionForm.externalReceiptNumber, - lotOccupancyTransactionForm.transactionNote, - dateStringToInteger(lotOccupancyTransactionForm.transactionDateString), - timeStringToInteger(lotOccupancyTransactionForm.transactionTimeString), + updateForm.transactionAmount, + updateForm.externalReceiptNumber, + updateForm.transactionNote, + dateStringToInteger(updateForm.transactionDateString), + timeStringToInteger(updateForm.transactionTimeString), user.userName, Date.now(), - lotOccupancyTransactionForm.lotOccupancyId, - lotOccupancyTransactionForm.transactionIndex + updateForm.burialSiteContractId, + updateForm.transactionIndex ) database.release() diff --git a/database/updateBurialSiteTypeField.d.ts b/database/updateBurialSiteTypeField.d.ts new file mode 100644 index 00000000..94a077b0 --- /dev/null +++ b/database/updateBurialSiteTypeField.d.ts @@ -0,0 +1,11 @@ +export interface UpdateBurialSiteTypeFieldForm { + burialSiteTypeFieldId: number | string; + burialSiteTypeField: string; + isRequired: '0' | '1'; + fieldType?: string; + minimumLength?: string; + maximumLength?: string; + pattern?: string; + fieldValues: string; +} +export default function updateBurialSiteTypeField(updateForm: UpdateBurialSiteTypeFieldForm, user: User): Promise; diff --git a/database/updateBurialSiteTypeField.js b/database/updateBurialSiteTypeField.js new file mode 100644 index 00000000..856f5b80 --- /dev/null +++ b/database/updateBurialSiteTypeField.js @@ -0,0 +1,22 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js'; +import { acquireConnection } from './pool.js'; +export default async function updateBurialSiteTypeField(updateForm, user) { + const database = await acquireConnection(); + const result = database + .prepare(`update BurialSiteTypeFields + set burialSiteTypeField = ?, + isRequired = ?, + fieldType = ?, + minimumLength = ?, + maximumLength = ?, + pattern = ?, + fieldValues = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where burialSiteTypeFieldId = ? + and recordDelete_timeMillis is null`) + .run(updateForm.burialSiteTypeField, Number.parseInt(updateForm.isRequired, 10), updateForm.fieldType ?? 'text', updateForm.minimumLength ?? 0, updateForm.maximumLength ?? 100, updateForm.pattern ?? '', updateForm.fieldValues, user.userName, Date.now(), updateForm.burialSiteTypeFieldId); + database.release(); + clearCacheByTableName('BurialSiteTypeFields'); + return result.changes > 0; +} diff --git a/database/updateBurialSiteTypeField.ts b/database/updateBurialSiteTypeField.ts new file mode 100644 index 00000000..e228695d --- /dev/null +++ b/database/updateBurialSiteTypeField.ts @@ -0,0 +1,55 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js' + +import { acquireConnection } from './pool.js' + +export interface UpdateBurialSiteTypeFieldForm { + burialSiteTypeFieldId: number | string + burialSiteTypeField: string + isRequired: '0' | '1' + fieldType?: string + minimumLength?: string + maximumLength?: string + pattern?: string + fieldValues: string +} + +export default async function updateBurialSiteTypeField( + updateForm: UpdateBurialSiteTypeFieldForm, + user: User +): Promise { + const database = await acquireConnection() + + const result = database + .prepare( + `update BurialSiteTypeFields + set burialSiteTypeField = ?, + isRequired = ?, + fieldType = ?, + minimumLength = ?, + maximumLength = ?, + pattern = ?, + fieldValues = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where burialSiteTypeFieldId = ? + and recordDelete_timeMillis is null` + ) + .run( + updateForm.burialSiteTypeField, + Number.parseInt(updateForm.isRequired, 10), + updateForm.fieldType ?? 'text', + updateForm.minimumLength ?? 0, + updateForm.maximumLength ?? 100, + updateForm.pattern ?? '', + updateForm.fieldValues, + user.userName, + Date.now(), + updateForm.burialSiteTypeFieldId + ) + + database.release() + + clearCacheByTableName('BurialSiteTypeFields') + + return result.changes > 0 +} diff --git a/database/updateCemetery.d.ts b/database/updateCemetery.d.ts new file mode 100644 index 00000000..0b67f27f --- /dev/null +++ b/database/updateCemetery.d.ts @@ -0,0 +1,15 @@ +export interface UpdateCemeteryForm { + cemeteryId: string; + cemeteryName: string; + cemeteryDescription: string; + cemeterySvg: string; + cemeteryLatitude: string; + cemeteryLongitude: string; + cemeteryAddress1: string; + cemeteryAddress2: string; + cemeteryCity: string; + cemeteryProvince: string; + cemeteryPostalCode: string; + cemeteryPhoneNumber: string; +} +export default function updateCemetery(updateForm: UpdateCemeteryForm, user: User): Promise; diff --git a/database/updateCemetery.js b/database/updateCemetery.js new file mode 100644 index 00000000..41845aec --- /dev/null +++ b/database/updateCemetery.js @@ -0,0 +1,24 @@ +import { acquireConnection } from './pool.js'; +export default async function updateCemetery(updateForm, user) { + const database = await acquireConnection(); + const result = database + .prepare(`update Maps + set cemeteryName = ?, + mapDescription = ?, + mapSVG = ?, + mapLatitude = ?, + mapLongitude = ?, + mapAddress1 = ?, + mapAddress2 = ?, + mapCity = ?, + mapProvince = ?, + mapPostalCode = ?, + mapPhoneNumber = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where cemeteryId = ? + and recordDelete_timeMillis is null`) + .run(updateForm.cemeteryName, updateForm.cemeteryDescription, updateForm.cemeterySvg, updateForm.cemeteryLatitude === '' ? undefined : updateForm.cemeteryLatitude, updateForm.cemeteryLongitude === '' ? undefined : updateForm.cemeteryLongitude, updateForm.cemeteryAddress1, updateForm.cemeteryAddress2, updateForm.cemeteryCity, updateForm.cemeteryProvince, updateForm.cemeteryPostalCode, updateForm.cemeteryPhoneNumber, user.userName, Date.now(), updateForm.cemeteryId); + database.release(); + return result.changes > 0; +} diff --git a/database/updateCemetery.ts b/database/updateCemetery.ts new file mode 100644 index 00000000..a1ca213a --- /dev/null +++ b/database/updateCemetery.ts @@ -0,0 +1,63 @@ +import { acquireConnection } from './pool.js' + +export interface UpdateCemeteryForm { + cemeteryId: string + cemeteryName: string + cemeteryDescription: string + cemeterySvg: string + cemeteryLatitude: string + cemeteryLongitude: string + cemeteryAddress1: string + cemeteryAddress2: string + cemeteryCity: string + cemeteryProvince: string + cemeteryPostalCode: string + cemeteryPhoneNumber: string +} + +export default async function updateCemetery( + updateForm: UpdateCemeteryForm, + user: User +): Promise { + const database = await acquireConnection() + + const result = database + .prepare( + `update Maps + set cemeteryName = ?, + mapDescription = ?, + mapSVG = ?, + mapLatitude = ?, + mapLongitude = ?, + mapAddress1 = ?, + mapAddress2 = ?, + mapCity = ?, + mapProvince = ?, + mapPostalCode = ?, + mapPhoneNumber = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where cemeteryId = ? + and recordDelete_timeMillis is null` + ) + .run( + updateForm.cemeteryName, + updateForm.cemeteryDescription, + updateForm.cemeterySvg, + updateForm.cemeteryLatitude === '' ? undefined : updateForm.cemeteryLatitude, + updateForm.cemeteryLongitude === '' ? undefined : updateForm.cemeteryLongitude, + updateForm.cemeteryAddress1, + updateForm.cemeteryAddress2, + updateForm.cemeteryCity, + updateForm.cemeteryProvince, + updateForm.cemeteryPostalCode, + updateForm.cemeteryPhoneNumber, + user.userName, + Date.now(), + updateForm.cemeteryId + ) + + database.release() + + return result.changes > 0 +} diff --git a/database/updateContractTypeField.d.ts b/database/updateContractTypeField.d.ts new file mode 100644 index 00000000..03b06c67 --- /dev/null +++ b/database/updateContractTypeField.d.ts @@ -0,0 +1,11 @@ +export interface UpdateContractTypeFieldForm { + contractTypeFieldId: number | string; + contractTypeField: string; + isRequired: '0' | '1'; + fieldType?: string; + minimumLength?: string; + maximumLength?: string; + pattern?: string; + fieldValues: string; +} +export default function updateContractTypeField(updateForm: UpdateContractTypeFieldForm, user: User): Promise; diff --git a/database/updateContractTypeField.js b/database/updateContractTypeField.js new file mode 100644 index 00000000..f3951349 --- /dev/null +++ b/database/updateContractTypeField.js @@ -0,0 +1,22 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js'; +import { acquireConnection } from './pool.js'; +export default async function updateContractTypeField(updateForm, user) { + const database = await acquireConnection(); + const result = database + .prepare(`update ContractTypeFields + set contractTypeField = ?, + isRequired = ?, + fieldType = ?, + minimumLength = ?, + maximumLength = ?, + pattern = ?, + fieldValues = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where contractTypeFieldId = ? + and recordDelete_timeMillis is null`) + .run(updateForm.contractTypeField, Number.parseInt(updateForm.isRequired, 10), updateForm.fieldType ?? 'text', updateForm.minimumLength ?? 0, updateForm.maximumLength ?? 100, updateForm.pattern ?? '', updateForm.fieldValues, user.userName, Date.now(), updateForm.contractTypeFieldId); + database.release(); + clearCacheByTableName('ContractTypeFields'); + return result.changes > 0; +} diff --git a/database/updateContractTypeField.ts b/database/updateContractTypeField.ts new file mode 100644 index 00000000..3c304010 --- /dev/null +++ b/database/updateContractTypeField.ts @@ -0,0 +1,55 @@ +import { clearCacheByTableName } from '../helpers/functions.cache.js' + +import { acquireConnection } from './pool.js' + +export interface UpdateContractTypeFieldForm { + contractTypeFieldId: number | string + contractTypeField: string + isRequired: '0' | '1' + fieldType?: string + minimumLength?: string + maximumLength?: string + pattern?: string + fieldValues: string +} + +export default async function updateContractTypeField( + updateForm: UpdateContractTypeFieldForm, + user: User +): Promise { + const database = await acquireConnection() + + const result = database + .prepare( + `update ContractTypeFields + set contractTypeField = ?, + isRequired = ?, + fieldType = ?, + minimumLength = ?, + maximumLength = ?, + pattern = ?, + fieldValues = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where contractTypeFieldId = ? + and recordDelete_timeMillis is null` + ) + .run( + updateForm.contractTypeField, + Number.parseInt(updateForm.isRequired, 10), + updateForm.fieldType ?? 'text', + updateForm.minimumLength ?? 0, + updateForm.maximumLength ?? 100, + updateForm.pattern ?? '', + updateForm.fieldValues, + user.userName, + Date.now(), + updateForm.contractTypeFieldId + ) + + database.release() + + clearCacheByTableName('ContractTypeFields') + + return result.changes > 0 +} diff --git a/database/updateFee.d.ts b/database/updateFee.d.ts index 7520311c..cfbe5d97 100644 --- a/database/updateFee.d.ts +++ b/database/updateFee.d.ts @@ -4,8 +4,8 @@ export interface UpdateFeeForm { feeName: string; feeDescription: string; feeAccount: string; - occupancyTypeId: string; - lotTypeId: string; + contractTypeId: string; + burialSiteTypeId: string; feeAmount?: string; feeFunction?: string; taxAmount?: string; diff --git a/database/updateFee.js b/database/updateFee.js index 7e1a2a5a..2ca39bd8 100644 --- a/database/updateFee.js +++ b/database/updateFee.js @@ -7,8 +7,8 @@ export default async function updateFee(feeForm, user) { feeName = ?, feeDescription = ?, feeAccount = ?, - occupancyTypeId = ?, - lotTypeId = ?, + contractTypeId = ?, + burialSiteTypeId = ?, feeAmount = ?, feeFunction = ?, taxAmount = ?, @@ -20,7 +20,7 @@ export default async function updateFee(feeForm, user) { recordUpdate_timeMillis = ? where recordDelete_timeMillis is null and feeId = ?`) - .run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.feeAccount, feeForm.occupancyTypeId === '' ? undefined : feeForm.occupancyTypeId, feeForm.lotTypeId === '' ? undefined : feeForm.lotTypeId, feeForm.feeAmount === undefined || feeForm.feeAmount === '' + .run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.feeAccount, feeForm.contractTypeId === '' ? undefined : feeForm.contractTypeId, feeForm.burialSiteTypeId === '' ? undefined : feeForm.burialSiteTypeId, feeForm.feeAmount === undefined || feeForm.feeAmount === '' ? 0 : feeForm.feeAmount, feeForm.feeFunction ?? undefined, feeForm.taxAmount ?? undefined, feeForm.taxPercentage ?? undefined, feeForm.includeQuantity === '' ? 0 : 1, feeForm.quantityUnit, feeForm.isRequired === '' ? 0 : 1, user.userName, Date.now(), feeForm.feeId); database.release(); diff --git a/database/updateFee.ts b/database/updateFee.ts index e4b6e3a8..d68ebfa9 100644 --- a/database/updateFee.ts +++ b/database/updateFee.ts @@ -6,8 +6,8 @@ export interface UpdateFeeForm { feeName: string feeDescription: string feeAccount: string - occupancyTypeId: string - lotTypeId: string + contractTypeId: string + burialSiteTypeId: string feeAmount?: string feeFunction?: string taxAmount?: string @@ -30,8 +30,8 @@ export default async function updateFee( feeName = ?, feeDescription = ?, feeAccount = ?, - occupancyTypeId = ?, - lotTypeId = ?, + contractTypeId = ?, + burialSiteTypeId = ?, feeAmount = ?, feeFunction = ?, taxAmount = ?, @@ -49,8 +49,8 @@ export default async function updateFee( feeForm.feeName, feeForm.feeDescription, feeForm.feeAccount, - feeForm.occupancyTypeId === '' ? undefined : feeForm.occupancyTypeId, - feeForm.lotTypeId === '' ? undefined : feeForm.lotTypeId, + feeForm.contractTypeId === '' ? undefined : feeForm.contractTypeId, + feeForm.burialSiteTypeId === '' ? undefined : feeForm.burialSiteTypeId, feeForm.feeAmount === undefined || feeForm.feeAmount === '' ? 0 : feeForm.feeAmount, diff --git a/database/updateLot.d.ts b/database/updateLot.d.ts deleted file mode 100644 index 75b80d34..00000000 --- a/database/updateLot.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -export interface UpdateLotForm { - lotId: string | number; - lotName: string; - lotTypeId: string | number; - lotStatusId: string | number; - mapId: string | number; - mapKey: string; - lotLatitude: string; - lotLongitude: string; - lotTypeFieldIds?: string; - [lotFieldValue_lotTypeFieldId: string]: unknown; -} -export default function updateLot(lotForm: UpdateLotForm, user: User): Promise; -export declare function updateLotStatus(lotId: number | string, lotStatusId: number | string, user: User): Promise; diff --git a/database/updateLot.js b/database/updateLot.js deleted file mode 100644 index 2da3f6a1..00000000 --- a/database/updateLot.js +++ /dev/null @@ -1,49 +0,0 @@ -import addOrUpdateLotField from './addOrUpdateLotField.js'; -import deleteLotField from './deleteLotField.js'; -import { acquireConnection } from './pool.js'; -export default async function updateLot(lotForm, user) { - const database = await acquireConnection(); - const result = database - .prepare(`update Lots - set lotName = ?, - lotTypeId = ?, - lotStatusId = ?, - mapId = ?, - mapKey = ?, - lotLatitude = ?, - lotLongitude = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where lotId = ? - and recordDelete_timeMillis is null`) - .run(lotForm.lotName, lotForm.lotTypeId, lotForm.lotStatusId === '' ? undefined : lotForm.lotStatusId, lotForm.mapId === '' ? undefined : lotForm.mapId, lotForm.mapKey, lotForm.lotLatitude === '' ? undefined : lotForm.lotLatitude, lotForm.lotLongitude === '' ? undefined : lotForm.lotLongitude, user.userName, Date.now(), lotForm.lotId); - if (result.changes > 0) { - const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(','); - for (const lotTypeFieldId of lotTypeFieldIds) { - const lotFieldValue = lotForm[`lotFieldValue_${lotTypeFieldId}`]; - await ((lotFieldValue ?? '') === '' - ? deleteLotField(lotForm.lotId, lotTypeFieldId, user, database) - : addOrUpdateLotField({ - lotId: lotForm.lotId, - lotTypeFieldId, - lotFieldValue: lotFieldValue ?? '' - }, user, database)); - } - } - database.release(); - return result.changes > 0; -} -export async function updateLotStatus(lotId, lotStatusId, user) { - const database = await acquireConnection(); - const rightNowMillis = Date.now(); - const result = database - .prepare(`update Lots - set lotStatusId = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where lotId = ? - and recordDelete_timeMillis is null`) - .run(lotStatusId === '' ? undefined : lotStatusId, user.userName, rightNowMillis, lotId); - database.release(); - return result.changes > 0; -} diff --git a/database/updateLot.ts b/database/updateLot.ts deleted file mode 100644 index f2df1ef3..00000000 --- a/database/updateLot.ts +++ /dev/null @@ -1,110 +0,0 @@ -import addOrUpdateLotField from './addOrUpdateLotField.js' -import deleteLotField from './deleteLotField.js' -import { acquireConnection } from './pool.js' - -export interface UpdateLotForm { - lotId: string | number - lotName: string - lotTypeId: string | number - lotStatusId: string | number - - mapId: string | number - mapKey: string - - lotLatitude: string - lotLongitude: string - - lotTypeFieldIds?: string - [lotFieldValue_lotTypeFieldId: string]: unknown -} - -export default async function updateLot( - lotForm: UpdateLotForm, - user: User -): Promise { - const database = await acquireConnection() - - const result = database - .prepare( - `update Lots - set lotName = ?, - lotTypeId = ?, - lotStatusId = ?, - mapId = ?, - mapKey = ?, - lotLatitude = ?, - lotLongitude = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where lotId = ? - and recordDelete_timeMillis is null` - ) - .run( - lotForm.lotName, - lotForm.lotTypeId, - lotForm.lotStatusId === '' ? undefined : lotForm.lotStatusId, - lotForm.mapId === '' ? undefined : lotForm.mapId, - lotForm.mapKey, - lotForm.lotLatitude === '' ? undefined : lotForm.lotLatitude, - lotForm.lotLongitude === '' ? undefined : lotForm.lotLongitude, - user.userName, - Date.now(), - lotForm.lotId - ) - - if (result.changes > 0) { - const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(',') - - for (const lotTypeFieldId of lotTypeFieldIds) { - const lotFieldValue = lotForm[`lotFieldValue_${lotTypeFieldId}`] as - | string - | undefined - - await ((lotFieldValue ?? '') === '' - ? deleteLotField(lotForm.lotId, lotTypeFieldId, user, database) - : addOrUpdateLotField( - { - lotId: lotForm.lotId, - lotTypeFieldId, - lotFieldValue: lotFieldValue ?? '' - }, - user, - database - )) - } - } - - database.release() - - return result.changes > 0 -} - -export async function updateLotStatus( - lotId: number | string, - lotStatusId: number | string, - user: User -): Promise { - const database = await acquireConnection() - - const rightNowMillis = Date.now() - - const result = database - .prepare( - `update Lots - set lotStatusId = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where lotId = ? - and recordDelete_timeMillis is null` - ) - .run( - lotStatusId === '' ? undefined : lotStatusId, - user.userName, - rightNowMillis, - lotId - ) - - database.release() - - return result.changes > 0 -} diff --git a/database/updateLotComment.d.ts b/database/updateLotComment.d.ts deleted file mode 100644 index 5d2e9e12..00000000 --- a/database/updateLotComment.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { type DateString, type TimeString } from '@cityssm/utils-datetime'; -export interface UpdateLotCommentForm { - lotCommentId: string | number; - lotCommentDateString: DateString; - lotCommentTimeString: TimeString; - lotComment: string; -} -export default function updateLotComment(commentForm: UpdateLotCommentForm, user: User): Promise; diff --git a/database/updateLotComment.js b/database/updateLotComment.js deleted file mode 100644 index 0d19eb2a..00000000 --- a/database/updateLotComment.js +++ /dev/null @@ -1,17 +0,0 @@ -import { dateStringToInteger, timeStringToInteger } from '@cityssm/utils-datetime'; -import { acquireConnection } from './pool.js'; -export default async function updateLotComment(commentForm, user) { - const database = await acquireConnection(); - const result = database - .prepare(`update LotComments - set lotCommentDate = ?, - lotCommentTime = ?, - lotComment = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where recordDelete_timeMillis is null - and lotCommentId = ?`) - .run(dateStringToInteger(commentForm.lotCommentDateString), timeStringToInteger(commentForm.lotCommentTimeString), commentForm.lotComment, user.userName, Date.now(), commentForm.lotCommentId); - database.release(); - return result.changes > 0; -} diff --git a/database/updateLotComment.ts b/database/updateLotComment.ts deleted file mode 100644 index 898f53f5..00000000 --- a/database/updateLotComment.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { - type DateString, - type TimeString, - dateStringToInteger, - timeStringToInteger -} from '@cityssm/utils-datetime' - -import { acquireConnection } from './pool.js' - -export interface UpdateLotCommentForm { - lotCommentId: string | number - lotCommentDateString: DateString - lotCommentTimeString: TimeString - lotComment: string -} - -export default async function updateLotComment( - commentForm: UpdateLotCommentForm, - user: User -): Promise { - const database = await acquireConnection() - - const result = database - .prepare( - `update LotComments - set lotCommentDate = ?, - lotCommentTime = ?, - lotComment = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where recordDelete_timeMillis is null - and lotCommentId = ?` - ) - .run( - dateStringToInteger(commentForm.lotCommentDateString), - timeStringToInteger(commentForm.lotCommentTimeString), - commentForm.lotComment, - user.userName, - Date.now(), - commentForm.lotCommentId - ) - - database.release() - - return result.changes > 0 -} diff --git a/database/updateLotOccupancy.d.ts b/database/updateLotOccupancy.d.ts deleted file mode 100644 index f714042c..00000000 --- a/database/updateLotOccupancy.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { type DateString } from '@cityssm/utils-datetime'; -export interface UpdateLotOccupancyForm { - lotOccupancyId: string | number; - occupancyTypeId: string | number; - lotId: string | number; - occupancyStartDateString: DateString; - occupancyEndDateString: DateString | ''; - occupancyTypeFieldIds?: string; - [lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown; -} -export default function updateLotOccupancy(lotOccupancyForm: UpdateLotOccupancyForm, user: User): Promise; diff --git a/database/updateLotOccupancy.js b/database/updateLotOccupancy.js deleted file mode 100644 index 11d44d1c..00000000 --- a/database/updateLotOccupancy.js +++ /dev/null @@ -1,35 +0,0 @@ -import { dateStringToInteger } from '@cityssm/utils-datetime'; -import addOrUpdateLotOccupancyField from './addOrUpdateLotOccupancyField.js'; -import deleteLotOccupancyField from './deleteLotOccupancyField.js'; -import { acquireConnection } from './pool.js'; -export default async function updateLotOccupancy(lotOccupancyForm, user) { - const database = await acquireConnection(); - const result = database - .prepare(`update LotOccupancies - set occupancyTypeId = ?, - lotId = ?, - occupancyStartDate = ?, - occupancyEndDate = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where lotOccupancyId = ? - and recordDelete_timeMillis is null`) - .run(lotOccupancyForm.occupancyTypeId, lotOccupancyForm.lotId === '' ? undefined : lotOccupancyForm.lotId, dateStringToInteger(lotOccupancyForm.occupancyStartDateString), lotOccupancyForm.occupancyEndDateString === '' - ? undefined - : dateStringToInteger(lotOccupancyForm.occupancyEndDateString), user.userName, Date.now(), lotOccupancyForm.lotOccupancyId); - if (result.changes > 0) { - const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds ?? '').split(','); - for (const occupancyTypeFieldId of occupancyTypeFieldIds) { - const lotOccupancyFieldValue = lotOccupancyForm[`lotOccupancyFieldValue_${occupancyTypeFieldId}`]; - await ((lotOccupancyFieldValue ?? '') === '' - ? deleteLotOccupancyField(lotOccupancyForm.lotOccupancyId, occupancyTypeFieldId, user, database) - : addOrUpdateLotOccupancyField({ - lotOccupancyId: lotOccupancyForm.lotOccupancyId, - occupancyTypeFieldId, - lotOccupancyFieldValue - }, user, database)); - } - } - database.release(); - return result.changes > 0; -} diff --git a/database/updateLotOccupancy.ts b/database/updateLotOccupancy.ts deleted file mode 100644 index e2b66478..00000000 --- a/database/updateLotOccupancy.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime' - -import addOrUpdateLotOccupancyField from './addOrUpdateLotOccupancyField.js' -import deleteLotOccupancyField from './deleteLotOccupancyField.js' -import { acquireConnection } from './pool.js' - -export interface UpdateLotOccupancyForm { - lotOccupancyId: string | number - occupancyTypeId: string | number - lotId: string | number - - occupancyStartDateString: DateString - occupancyEndDateString: DateString | '' - - occupancyTypeFieldIds?: string - [lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown -} - -export default async function updateLotOccupancy( - lotOccupancyForm: UpdateLotOccupancyForm, - user: User -): Promise { - const database = await acquireConnection() - - const result = database - .prepare( - `update LotOccupancies - set occupancyTypeId = ?, - lotId = ?, - occupancyStartDate = ?, - occupancyEndDate = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where lotOccupancyId = ? - and recordDelete_timeMillis is null` - ) - .run( - lotOccupancyForm.occupancyTypeId, - lotOccupancyForm.lotId === '' ? undefined : lotOccupancyForm.lotId, - dateStringToInteger(lotOccupancyForm.occupancyStartDateString), - lotOccupancyForm.occupancyEndDateString === '' - ? undefined - : dateStringToInteger(lotOccupancyForm.occupancyEndDateString), - user.userName, - Date.now(), - lotOccupancyForm.lotOccupancyId - ) - - if (result.changes > 0) { - const occupancyTypeFieldIds = ( - lotOccupancyForm.occupancyTypeFieldIds ?? '' - ).split(',') - - for (const occupancyTypeFieldId of occupancyTypeFieldIds) { - const lotOccupancyFieldValue = lotOccupancyForm[ - `lotOccupancyFieldValue_${occupancyTypeFieldId}` - ] as string - - await ((lotOccupancyFieldValue ?? '') === '' - ? deleteLotOccupancyField( - lotOccupancyForm.lotOccupancyId, - occupancyTypeFieldId, - user, - database - ) - : addOrUpdateLotOccupancyField( - { - lotOccupancyId: lotOccupancyForm.lotOccupancyId, - occupancyTypeFieldId, - lotOccupancyFieldValue - }, - user, - database - )) - } - } - - database.release() - - return result.changes > 0 -} diff --git a/database/updateLotOccupancyComment.d.ts b/database/updateLotOccupancyComment.d.ts deleted file mode 100644 index 20b8949a..00000000 --- a/database/updateLotOccupancyComment.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { type DateString, type TimeString } from '@cityssm/utils-datetime'; -export interface UpdateLotOccupancyCommentForm { - lotOccupancyCommentId: string | number; - lotOccupancyCommentDateString: DateString; - lotOccupancyCommentTimeString: TimeString; - lotOccupancyComment: string; -} -export default function updateLotOccupancyComment(commentForm: UpdateLotOccupancyCommentForm, user: User): Promise; diff --git a/database/updateLotOccupancyComment.js b/database/updateLotOccupancyComment.js deleted file mode 100644 index 2597ac7a..00000000 --- a/database/updateLotOccupancyComment.js +++ /dev/null @@ -1,17 +0,0 @@ -import { dateStringToInteger, timeStringToInteger } from '@cityssm/utils-datetime'; -import { acquireConnection } from './pool.js'; -export default async function updateLotOccupancyComment(commentForm, user) { - const database = await acquireConnection(); - const result = database - .prepare(`update LotOccupancyComments - set lotOccupancyCommentDate = ?, - lotOccupancyCommentTime = ?, - lotOccupancyComment = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where recordDelete_timeMillis is null - and lotOccupancyCommentId = ?`) - .run(dateStringToInteger(commentForm.lotOccupancyCommentDateString), timeStringToInteger(commentForm.lotOccupancyCommentTimeString), commentForm.lotOccupancyComment, user.userName, Date.now(), commentForm.lotOccupancyCommentId); - database.release(); - return result.changes > 0; -} diff --git a/database/updateLotOccupancyComment.ts b/database/updateLotOccupancyComment.ts deleted file mode 100644 index fdbe3ceb..00000000 --- a/database/updateLotOccupancyComment.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { - type DateString, - type TimeString, - dateStringToInteger, - timeStringToInteger -} from '@cityssm/utils-datetime' - -import { acquireConnection } from './pool.js' - -export interface UpdateLotOccupancyCommentForm { - lotOccupancyCommentId: string | number - lotOccupancyCommentDateString: DateString - lotOccupancyCommentTimeString: TimeString - lotOccupancyComment: string -} - -export default async function updateLotOccupancyComment( - commentForm: UpdateLotOccupancyCommentForm, - user: User -): Promise { - const database = await acquireConnection() - - const result = database - .prepare( - `update LotOccupancyComments - set lotOccupancyCommentDate = ?, - lotOccupancyCommentTime = ?, - lotOccupancyComment = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where recordDelete_timeMillis is null - and lotOccupancyCommentId = ?` - ) - .run( - dateStringToInteger(commentForm.lotOccupancyCommentDateString), - timeStringToInteger(commentForm.lotOccupancyCommentTimeString), - commentForm.lotOccupancyComment, - user.userName, - Date.now(), - commentForm.lotOccupancyCommentId - ) - - database.release() - - return result.changes > 0 -} diff --git a/database/updateLotOccupancyFeeQuantity.d.ts b/database/updateLotOccupancyFeeQuantity.d.ts deleted file mode 100644 index a43667ee..00000000 --- a/database/updateLotOccupancyFeeQuantity.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface UpdateLotOccupancyFeeQuantityForm { - lotOccupancyId: string | number; - feeId: string | number; - quantity: string | number; -} -export default function updateLotOccupancyFeeQuantity(feeQuantityForm: UpdateLotOccupancyFeeQuantityForm, user: User): Promise; diff --git a/database/updateLotOccupancyOccupant.d.ts b/database/updateLotOccupancyOccupant.d.ts index 8ba2e555..ce9c06ca 100644 --- a/database/updateLotOccupancyOccupant.d.ts +++ b/database/updateLotOccupancyOccupant.d.ts @@ -1,5 +1,5 @@ export interface UpdateLotOccupancyOccupantForm { - lotOccupancyId: string | number; + burialSiteContractId: string | number; lotOccupantIndex: string | number; lotOccupantTypeId: string | number; occupantName: string; diff --git a/database/updateLotOccupancyOccupant.js b/database/updateLotOccupancyOccupant.js index 65de0d7f..81f01128 100644 --- a/database/updateLotOccupancyOccupant.js +++ b/database/updateLotOccupancyOccupant.js @@ -17,9 +17,9 @@ export default async function updateLotOccupancyOccupant(lotOccupancyOccupantFor recordUpdate_userName = ?, recordUpdate_timeMillis = ? where recordDelete_timeMillis is null - and lotOccupancyId = ? + and burialSiteContractId = ? and lotOccupantIndex = ?`) - .run(lotOccupancyOccupantForm.occupantName, lotOccupancyOccupantForm.occupantFamilyName, lotOccupancyOccupantForm.occupantAddress1, lotOccupancyOccupantForm.occupantAddress2, lotOccupancyOccupantForm.occupantCity, lotOccupancyOccupantForm.occupantProvince, lotOccupancyOccupantForm.occupantPostalCode, lotOccupancyOccupantForm.occupantPhoneNumber, lotOccupancyOccupantForm.occupantEmailAddress, lotOccupancyOccupantForm.occupantComment, lotOccupancyOccupantForm.lotOccupantTypeId, user.userName, Date.now(), lotOccupancyOccupantForm.lotOccupancyId, lotOccupancyOccupantForm.lotOccupantIndex); + .run(lotOccupancyOccupantForm.occupantName, lotOccupancyOccupantForm.occupantFamilyName, lotOccupancyOccupantForm.occupantAddress1, lotOccupancyOccupantForm.occupantAddress2, lotOccupancyOccupantForm.occupantCity, lotOccupancyOccupantForm.occupantProvince, lotOccupancyOccupantForm.occupantPostalCode, lotOccupancyOccupantForm.occupantPhoneNumber, lotOccupancyOccupantForm.occupantEmailAddress, lotOccupancyOccupantForm.occupantComment, lotOccupancyOccupantForm.lotOccupantTypeId, user.userName, Date.now(), lotOccupancyOccupantForm.burialSiteContractId, lotOccupancyOccupantForm.lotOccupantIndex); database.release(); return results.changes > 0; } diff --git a/database/updateLotOccupancyOccupant.ts b/database/updateLotOccupancyOccupant.ts index bcdaa390..290a70af 100644 --- a/database/updateLotOccupancyOccupant.ts +++ b/database/updateLotOccupancyOccupant.ts @@ -1,7 +1,7 @@ import { acquireConnection } from './pool.js' export interface UpdateLotOccupancyOccupantForm { - lotOccupancyId: string | number + burialSiteContractId: string | number lotOccupantIndex: string | number lotOccupantTypeId: string | number occupantName: string @@ -39,7 +39,7 @@ export default async function updateLotOccupancyOccupant( recordUpdate_userName = ?, recordUpdate_timeMillis = ? where recordDelete_timeMillis is null - and lotOccupancyId = ? + and burialSiteContractId = ? and lotOccupantIndex = ?` ) .run( @@ -56,7 +56,7 @@ export default async function updateLotOccupancyOccupant( lotOccupancyOccupantForm.lotOccupantTypeId, user.userName, Date.now(), - lotOccupancyOccupantForm.lotOccupancyId, + lotOccupancyOccupantForm.burialSiteContractId, lotOccupancyOccupantForm.lotOccupantIndex ) diff --git a/database/updateLotOccupancyTransaction.js b/database/updateLotOccupancyTransaction.js deleted file mode 100644 index 8d06ec37..00000000 --- a/database/updateLotOccupancyTransaction.js +++ /dev/null @@ -1,20 +0,0 @@ -import { dateStringToInteger, timeStringToInteger } from '@cityssm/utils-datetime'; -import { acquireConnection } from './pool.js'; -export default async function updateLotOccupancyTransaction(lotOccupancyTransactionForm, user) { - const database = await acquireConnection(); - const result = database - .prepare(`update LotOccupancyTransactions - set transactionAmount = ?, - externalReceiptNumber = ?, - transactionNote = ?, - transactionDate = ?, - transactionTime = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where recordDelete_timeMillis is null - and lotOccupancyId = ? - and transactionIndex = ?`) - .run(lotOccupancyTransactionForm.transactionAmount, lotOccupancyTransactionForm.externalReceiptNumber, lotOccupancyTransactionForm.transactionNote, dateStringToInteger(lotOccupancyTransactionForm.transactionDateString), timeStringToInteger(lotOccupancyTransactionForm.transactionTimeString), user.userName, Date.now(), lotOccupancyTransactionForm.lotOccupancyId, lotOccupancyTransactionForm.transactionIndex); - database.release(); - return result.changes > 0; -} diff --git a/database/updateLotOccupantType.d.ts b/database/updateLotOccupantType.d.ts deleted file mode 100644 index 848b071f..00000000 --- a/database/updateLotOccupantType.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface UpdateLotOccupantTypeForm { - lotOccupantTypeId: number | string; - lotOccupantType: string; - fontAwesomeIconClass: string; - occupantCommentTitle: string; -} -export default function updateLotOccupantType(lotOccupantTypeForm: UpdateLotOccupantTypeForm, user: User): Promise; diff --git a/database/updateLotOccupantType.js b/database/updateLotOccupantType.js deleted file mode 100644 index e0db3e7e..00000000 --- a/database/updateLotOccupantType.js +++ /dev/null @@ -1,18 +0,0 @@ -import { clearCacheByTableName } from '../helpers/functions.cache.js'; -import { acquireConnection } from './pool.js'; -export default async function updateLotOccupantType(lotOccupantTypeForm, user) { - const database = await acquireConnection(); - const result = database - .prepare(`update LotOccupantTypes - set lotOccupantType = ?, - fontAwesomeIconClass = ?, - occupantCommentTitle = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where lotOccupantTypeId = ? - and recordDelete_timeMillis is null`) - .run(lotOccupantTypeForm.lotOccupantType, lotOccupantTypeForm.fontAwesomeIconClass, lotOccupantTypeForm.occupantCommentTitle, user.userName, Date.now(), lotOccupantTypeForm.lotOccupantTypeId); - database.release(); - clearCacheByTableName('LotOccupantTypes'); - return result.changes > 0; -} diff --git a/database/updateLotOccupantType.ts b/database/updateLotOccupantType.ts deleted file mode 100644 index 2574340e..00000000 --- a/database/updateLotOccupantType.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { clearCacheByTableName } from '../helpers/functions.cache.js' - -import { acquireConnection } from './pool.js' - -export interface UpdateLotOccupantTypeForm { - lotOccupantTypeId: number | string - lotOccupantType: string - fontAwesomeIconClass: string - occupantCommentTitle: string -} - -export default async function updateLotOccupantType( - lotOccupantTypeForm: UpdateLotOccupantTypeForm, - user: User -): Promise { - const database = await acquireConnection() - - const result = database - .prepare( - `update LotOccupantTypes - set lotOccupantType = ?, - fontAwesomeIconClass = ?, - occupantCommentTitle = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where lotOccupantTypeId = ? - and recordDelete_timeMillis is null` - ) - .run( - lotOccupantTypeForm.lotOccupantType, - lotOccupantTypeForm.fontAwesomeIconClass, - lotOccupantTypeForm.occupantCommentTitle, - user.userName, - Date.now(), - lotOccupantTypeForm.lotOccupantTypeId - ) - - database.release() - - clearCacheByTableName('LotOccupantTypes') - - return result.changes > 0 -} diff --git a/database/updateLotTypeField.d.ts b/database/updateLotTypeField.d.ts deleted file mode 100644 index 063f14b5..00000000 --- a/database/updateLotTypeField.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface UpdateLotTypeFieldForm { - lotTypeFieldId: number | string; - lotTypeField: string; - isRequired: '0' | '1'; - fieldType?: string; - minimumLength?: string; - maximumLength?: string; - pattern?: string; - lotTypeFieldValues: string; -} -export default function updateLotTypeField(lotTypeFieldForm: UpdateLotTypeFieldForm, user: User): Promise; diff --git a/database/updateLotTypeField.js b/database/updateLotTypeField.js deleted file mode 100644 index 7a14c2e6..00000000 --- a/database/updateLotTypeField.js +++ /dev/null @@ -1,22 +0,0 @@ -import { clearCacheByTableName } from '../helpers/functions.cache.js'; -import { acquireConnection } from './pool.js'; -export default async function updateLotTypeField(lotTypeFieldForm, user) { - const database = await acquireConnection(); - const result = database - .prepare(`update LotTypeFields - set lotTypeField = ?, - isRequired = ?, - fieldType = ?, - minimumLength = ?, - maximumLength = ?, - pattern = ?, - lotTypeFieldValues = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where lotTypeFieldId = ? - and recordDelete_timeMillis is null`) - .run(lotTypeFieldForm.lotTypeField, Number.parseInt(lotTypeFieldForm.isRequired, 10), lotTypeFieldForm.fieldType ?? 'text', lotTypeFieldForm.minimumLength ?? 0, lotTypeFieldForm.maximumLength ?? 100, lotTypeFieldForm.pattern ?? '', lotTypeFieldForm.lotTypeFieldValues, user.userName, Date.now(), lotTypeFieldForm.lotTypeFieldId); - database.release(); - clearCacheByTableName('LotTypeFields'); - return result.changes > 0; -} diff --git a/database/updateLotTypeField.ts b/database/updateLotTypeField.ts deleted file mode 100644 index 18ac1509..00000000 --- a/database/updateLotTypeField.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { clearCacheByTableName } from '../helpers/functions.cache.js' - -import { acquireConnection } from './pool.js' - -export interface UpdateLotTypeFieldForm { - lotTypeFieldId: number | string - lotTypeField: string - isRequired: '0' | '1' - fieldType?: string - minimumLength?: string - maximumLength?: string - pattern?: string - lotTypeFieldValues: string -} - -export default async function updateLotTypeField( - lotTypeFieldForm: UpdateLotTypeFieldForm, - user: User -): Promise { - const database = await acquireConnection() - - const result = database - .prepare( - `update LotTypeFields - set lotTypeField = ?, - isRequired = ?, - fieldType = ?, - minimumLength = ?, - maximumLength = ?, - pattern = ?, - lotTypeFieldValues = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where lotTypeFieldId = ? - and recordDelete_timeMillis is null` - ) - .run( - lotTypeFieldForm.lotTypeField, - Number.parseInt(lotTypeFieldForm.isRequired, 10), - lotTypeFieldForm.fieldType ?? 'text', - lotTypeFieldForm.minimumLength ?? 0, - lotTypeFieldForm.maximumLength ?? 100, - lotTypeFieldForm.pattern ?? '', - lotTypeFieldForm.lotTypeFieldValues, - user.userName, - Date.now(), - lotTypeFieldForm.lotTypeFieldId - ) - - database.release() - - clearCacheByTableName('LotTypeFields') - - return result.changes > 0 -} diff --git a/database/updateMap.d.ts b/database/updateMap.d.ts deleted file mode 100644 index 71ba0db8..00000000 --- a/database/updateMap.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -export interface UpdateMapForm { - mapId: string; - mapName: string; - mapDescription: string; - mapSVG: string; - mapLatitude: string; - mapLongitude: string; - mapAddress1: string; - mapAddress2: string; - mapCity: string; - mapProvince: string; - mapPostalCode: string; - mapPhoneNumber: string; -} -export default function updateMap(mapForm: UpdateMapForm, user: User): Promise; diff --git a/database/updateMap.js b/database/updateMap.js deleted file mode 100644 index de6e1939..00000000 --- a/database/updateMap.js +++ /dev/null @@ -1,24 +0,0 @@ -import { acquireConnection } from './pool.js'; -export default async function updateMap(mapForm, user) { - const database = await acquireConnection(); - const result = database - .prepare(`update Maps - set mapName = ?, - mapDescription = ?, - mapSVG = ?, - mapLatitude = ?, - mapLongitude = ?, - mapAddress1 = ?, - mapAddress2 = ?, - mapCity = ?, - mapProvince = ?, - mapPostalCode = ?, - mapPhoneNumber = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where mapId = ? - and recordDelete_timeMillis is null`) - .run(mapForm.mapName, mapForm.mapDescription, mapForm.mapSVG, mapForm.mapLatitude === '' ? undefined : mapForm.mapLatitude, mapForm.mapLongitude === '' ? undefined : mapForm.mapLongitude, mapForm.mapAddress1, mapForm.mapAddress2, mapForm.mapCity, mapForm.mapProvince, mapForm.mapPostalCode, mapForm.mapPhoneNumber, user.userName, Date.now(), mapForm.mapId); - database.release(); - return result.changes > 0; -} diff --git a/database/updateMap.ts b/database/updateMap.ts deleted file mode 100644 index c5a2db6e..00000000 --- a/database/updateMap.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { acquireConnection } from './pool.js' - -export interface UpdateMapForm { - mapId: string - mapName: string - mapDescription: string - mapSVG: string - mapLatitude: string - mapLongitude: string - mapAddress1: string - mapAddress2: string - mapCity: string - mapProvince: string - mapPostalCode: string - mapPhoneNumber: string -} - -export default async function updateMap( - mapForm: UpdateMapForm, - user: User -): Promise { - const database = await acquireConnection() - - const result = database - .prepare( - `update Maps - set mapName = ?, - mapDescription = ?, - mapSVG = ?, - mapLatitude = ?, - mapLongitude = ?, - mapAddress1 = ?, - mapAddress2 = ?, - mapCity = ?, - mapProvince = ?, - mapPostalCode = ?, - mapPhoneNumber = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where mapId = ? - and recordDelete_timeMillis is null` - ) - .run( - mapForm.mapName, - mapForm.mapDescription, - mapForm.mapSVG, - mapForm.mapLatitude === '' ? undefined : mapForm.mapLatitude, - mapForm.mapLongitude === '' ? undefined : mapForm.mapLongitude, - mapForm.mapAddress1, - mapForm.mapAddress2, - mapForm.mapCity, - mapForm.mapProvince, - mapForm.mapPostalCode, - mapForm.mapPhoneNumber, - user.userName, - Date.now(), - mapForm.mapId - ) - - database.release() - - return result.changes > 0 -} diff --git a/database/updateOccupancyTypeField.d.ts b/database/updateOccupancyTypeField.d.ts deleted file mode 100644 index 4a980626..00000000 --- a/database/updateOccupancyTypeField.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface UpdateOccupancyTypeFieldForm { - occupancyTypeFieldId: number | string; - occupancyTypeField: string; - isRequired: '0' | '1'; - fieldType?: string; - minimumLength?: string; - maximumLength?: string; - pattern?: string; - occupancyTypeFieldValues: string; -} -export default function updateOccupancyTypeField(occupancyTypeFieldForm: UpdateOccupancyTypeFieldForm, user: User): Promise; diff --git a/database/updateOccupancyTypeField.js b/database/updateOccupancyTypeField.js deleted file mode 100644 index fa46d408..00000000 --- a/database/updateOccupancyTypeField.js +++ /dev/null @@ -1,22 +0,0 @@ -import { clearCacheByTableName } from '../helpers/functions.cache.js'; -import { acquireConnection } from './pool.js'; -export default async function updateOccupancyTypeField(occupancyTypeFieldForm, user) { - const database = await acquireConnection(); - const result = database - .prepare(`update OccupancyTypeFields - set occupancyTypeField = ?, - isRequired = ?, - fieldType = ?, - minimumLength = ?, - maximumLength = ?, - pattern = ?, - occupancyTypeFieldValues = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where occupancyTypeFieldId = ? - and recordDelete_timeMillis is null`) - .run(occupancyTypeFieldForm.occupancyTypeField, Number.parseInt(occupancyTypeFieldForm.isRequired, 10), occupancyTypeFieldForm.fieldType ?? 'text', occupancyTypeFieldForm.minimumLength ?? 0, occupancyTypeFieldForm.maximumLength ?? 100, occupancyTypeFieldForm.pattern ?? '', occupancyTypeFieldForm.occupancyTypeFieldValues, user.userName, Date.now(), occupancyTypeFieldForm.occupancyTypeFieldId); - database.release(); - clearCacheByTableName('OccupancyTypeFields'); - return result.changes > 0; -} diff --git a/database/updateOccupancyTypeField.ts b/database/updateOccupancyTypeField.ts deleted file mode 100644 index 818b12a4..00000000 --- a/database/updateOccupancyTypeField.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { clearCacheByTableName } from '../helpers/functions.cache.js' - -import { acquireConnection } from './pool.js' - -export interface UpdateOccupancyTypeFieldForm { - occupancyTypeFieldId: number | string - occupancyTypeField: string - isRequired: '0' | '1' - fieldType?: string - minimumLength?: string - maximumLength?: string - pattern?: string - occupancyTypeFieldValues: string -} - -export default async function updateOccupancyTypeField( - occupancyTypeFieldForm: UpdateOccupancyTypeFieldForm, - user: User -): Promise { - const database = await acquireConnection() - - const result = database - .prepare( - `update OccupancyTypeFields - set occupancyTypeField = ?, - isRequired = ?, - fieldType = ?, - minimumLength = ?, - maximumLength = ?, - pattern = ?, - occupancyTypeFieldValues = ?, - recordUpdate_userName = ?, - recordUpdate_timeMillis = ? - where occupancyTypeFieldId = ? - and recordDelete_timeMillis is null` - ) - .run( - occupancyTypeFieldForm.occupancyTypeField, - Number.parseInt(occupancyTypeFieldForm.isRequired, 10), - occupancyTypeFieldForm.fieldType ?? 'text', - occupancyTypeFieldForm.minimumLength ?? 0, - occupancyTypeFieldForm.maximumLength ?? 100, - occupancyTypeFieldForm.pattern ?? '', - occupancyTypeFieldForm.occupancyTypeFieldValues, - user.userName, - Date.now(), - occupancyTypeFieldForm.occupancyTypeFieldId - ) - - database.release() - - clearCacheByTableName('OccupancyTypeFields') - - return result.changes > 0 -} diff --git a/database/updateRecord.d.ts b/database/updateRecord.d.ts index b70fdc17..31d33036 100644 --- a/database/updateRecord.d.ts +++ b/database/updateRecord.d.ts @@ -1,3 +1,3 @@ -type RecordTable = 'LotStatuses' | 'LotTypes' | 'OccupancyTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; +type RecordTable = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'ContractTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; export declare function updateRecord(recordTable: RecordTable, recordId: number | string, recordName: string, user: User): Promise; export {}; diff --git a/database/updateRecord.js b/database/updateRecord.js index 91f646ac..8dff0d9a 100644 --- a/database/updateRecord.js +++ b/database/updateRecord.js @@ -1,9 +1,9 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js'; import { acquireConnection } from './pool.js'; const recordNameIdColumns = new Map(); -recordNameIdColumns.set('LotStatuses', ['lotStatus', 'lotStatusId']); -recordNameIdColumns.set('LotTypes', ['lotType', 'lotTypeId']); -recordNameIdColumns.set('OccupancyTypes', ['occupancyType', 'occupancyTypeId']); +recordNameIdColumns.set('BurialSiteStatuses', ['burialSiteStatus', 'burialSiteStatusId']); +recordNameIdColumns.set('BurialSiteTypes', ['burialSiteType', 'burialSiteTypeId']); +recordNameIdColumns.set('ContractTypes', ['contractType', 'contractTypeId']); recordNameIdColumns.set('WorkOrderMilestoneTypes', [ 'workOrderMilestoneType', 'workOrderMilestoneTypeId' diff --git a/database/updateRecord.ts b/database/updateRecord.ts index 9f010d4e..653db97a 100644 --- a/database/updateRecord.ts +++ b/database/updateRecord.ts @@ -3,16 +3,16 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js' import { acquireConnection } from './pool.js' type RecordTable = - | 'LotStatuses' - | 'LotTypes' - | 'OccupancyTypes' + | 'BurialSiteStatuses' + | 'BurialSiteTypes' + | 'ContractTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes' const recordNameIdColumns = new Map() -recordNameIdColumns.set('LotStatuses', ['lotStatus', 'lotStatusId']) -recordNameIdColumns.set('LotTypes', ['lotType', 'lotTypeId']) -recordNameIdColumns.set('OccupancyTypes', ['occupancyType', 'occupancyTypeId']) +recordNameIdColumns.set('BurialSiteStatuses', ['burialSiteStatus', 'burialSiteStatusId']) +recordNameIdColumns.set('BurialSiteTypes', ['burialSiteType', 'burialSiteTypeId']) +recordNameIdColumns.set('ContractTypes', ['contractType', 'contractTypeId']) recordNameIdColumns.set('WorkOrderMilestoneTypes', [ 'workOrderMilestoneType', 'workOrderMilestoneTypeId' diff --git a/database/updateRecordOrderNumber.d.ts b/database/updateRecordOrderNumber.d.ts index 9a1f44ed..1ce0e85a 100644 --- a/database/updateRecordOrderNumber.d.ts +++ b/database/updateRecordOrderNumber.d.ts @@ -1,4 +1,4 @@ import type { PoolConnection } from 'better-sqlite-pool'; -type RecordTable = 'FeeCategories' | 'Fees' | 'LotOccupantTypes' | 'LotStatuses' | 'LotTypes' | 'LotTypeFields' | 'OccupancyTypes' | 'OccupancyTypeFields' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; +type RecordTable = 'FeeCategories' | 'Fees' | 'BurialSiteStatuses' | 'BurialSiteTypes' | 'BurialSiteTypeFields' | 'ContractTypes' | 'ContractTypeFields' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes'; export declare function updateRecordOrderNumber(recordTable: RecordTable, recordId: number | string, orderNumber: number | string, connectedDatabase: PoolConnection): boolean; export {}; diff --git a/database/updateRecordOrderNumber.js b/database/updateRecordOrderNumber.js index b321aaa6..d9a18018 100644 --- a/database/updateRecordOrderNumber.js +++ b/database/updateRecordOrderNumber.js @@ -1,12 +1,11 @@ const recordIdColumns = new Map(); recordIdColumns.set('FeeCategories', 'feeCategoryId'); recordIdColumns.set('Fees', 'feeId'); -recordIdColumns.set('LotOccupantTypes', 'lotOccupantTypeId'); -recordIdColumns.set('LotStatuses', 'lotStatusId'); -recordIdColumns.set('LotTypes', 'lotTypeId'); -recordIdColumns.set('LotTypeFields', 'lotTypeFieldId'); -recordIdColumns.set('OccupancyTypes', 'occupancyTypeId'); -recordIdColumns.set('OccupancyTypeFields', 'occupancyTypeFieldId'); +recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId'); +recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId'); +recordIdColumns.set('BurialSiteTypeFields', 'burialSiteTypeFieldId'); +recordIdColumns.set('ContractTypes', 'contractTypeId'); +recordIdColumns.set('ContractTypeFields', 'contractTypeFieldId'); recordIdColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneTypeId'); recordIdColumns.set('WorkOrderTypes', 'workOrderTypeId'); export function updateRecordOrderNumber(recordTable, recordId, orderNumber, connectedDatabase) { diff --git a/database/updateRecordOrderNumber.ts b/database/updateRecordOrderNumber.ts index 316cfa55..2757e1dd 100644 --- a/database/updateRecordOrderNumber.ts +++ b/database/updateRecordOrderNumber.ts @@ -3,24 +3,22 @@ import type { PoolConnection } from 'better-sqlite-pool' type RecordTable = | 'FeeCategories' | 'Fees' - | 'LotOccupantTypes' - | 'LotStatuses' - | 'LotTypes' - | 'LotTypeFields' - | 'OccupancyTypes' - | 'OccupancyTypeFields' + | 'BurialSiteStatuses' + | 'BurialSiteTypes' + | 'BurialSiteTypeFields' + | 'ContractTypes' + | 'ContractTypeFields' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes' const recordIdColumns = new Map() recordIdColumns.set('FeeCategories', 'feeCategoryId') recordIdColumns.set('Fees', 'feeId') -recordIdColumns.set('LotOccupantTypes', 'lotOccupantTypeId') -recordIdColumns.set('LotStatuses', 'lotStatusId') -recordIdColumns.set('LotTypes', 'lotTypeId') -recordIdColumns.set('LotTypeFields', 'lotTypeFieldId') -recordIdColumns.set('OccupancyTypes', 'occupancyTypeId') -recordIdColumns.set('OccupancyTypeFields', 'occupancyTypeFieldId') +recordIdColumns.set('BurialSiteStatuses', 'burialSiteStatusId') +recordIdColumns.set('BurialSiteTypes', 'burialSiteTypeId') +recordIdColumns.set('BurialSiteTypeFields', 'burialSiteTypeFieldId') +recordIdColumns.set('ContractTypes', 'contractTypeId') +recordIdColumns.set('ContractTypeFields', 'contractTypeFieldId') recordIdColumns.set('WorkOrderMilestoneTypes', 'workOrderMilestoneTypeId') recordIdColumns.set('WorkOrderTypes', 'workOrderTypeId') @@ -35,7 +33,7 @@ export function updateRecordOrderNumber( `update ${recordTable} set orderNumber = ? where recordDelete_timeMillis is null - and ${recordIdColumns.get(recordTable)!} = ?` + and ${recordIdColumns.get(recordTable)} = ?` ) .run(orderNumber, recordId) diff --git a/handlers/admin-get/burialSiteTypes.js b/handlers/admin-get/burialSiteTypes.js index 706f49f0..17e30b03 100644 --- a/handlers/admin-get/burialSiteTypes.js +++ b/handlers/admin-get/burialSiteTypes.js @@ -1,7 +1,7 @@ -import { getLotTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes } from '../../helpers/functions.cache.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(_request, response) { - const lotTypes = await getLotTypes(); + const lotTypes = await getBurialSiteTypes(); response.render('admin-lotTypes', { headTitle: `${getConfigProperty('aliases.lot')} Type Management`, lotTypes diff --git a/handlers/admin-get/burialSiteTypes.ts b/handlers/admin-get/burialSiteTypes.ts index 07ad006b..363f3629 100644 --- a/handlers/admin-get/burialSiteTypes.ts +++ b/handlers/admin-get/burialSiteTypes.ts @@ -1,13 +1,13 @@ import type { Request, Response } from 'express' -import { getLotTypes } from '../../helpers/functions.cache.js' +import { getBurialSiteTypes } from '../../helpers/functions.cache.js' import { getConfigProperty } from '../../helpers/config.helpers.js' export default async function handler( _request: Request, response: Response ): Promise { - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() response.render('admin-lotTypes', { headTitle: `${getConfigProperty('aliases.lot')} Type Management`, diff --git a/handlers/admin-get/fees.js b/handlers/admin-get/fees.js index f2d5ea97..77c50247 100644 --- a/handlers/admin-get/fees.js +++ b/handlers/admin-get/fees.js @@ -1,11 +1,11 @@ import getFeeCategories from '../../database/getFeeCategories.js'; -import { getLotTypes, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(_request, response) { const feeCategories = await getFeeCategories({}, { includeFees: true }); - const occupancyTypes = await getOccupancyTypes(); - const lotTypes = await getLotTypes(); + const occupancyTypes = await getContractTypes(); + const lotTypes = await getBurialSiteTypes(); response.render('admin-fees', { headTitle: 'Fee Management', feeCategories, diff --git a/handlers/admin-get/fees.ts b/handlers/admin-get/fees.ts index e058facd..f50d1dcc 100644 --- a/handlers/admin-get/fees.ts +++ b/handlers/admin-get/fees.ts @@ -2,8 +2,8 @@ import type { Request, Response } from 'express' import getFeeCategories from '../../database/getFeeCategories.js' import { - getLotTypes, - getOccupancyTypes + getBurialSiteTypes, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( @@ -17,8 +17,8 @@ export default async function handler( } ) - const occupancyTypes = await getOccupancyTypes() - const lotTypes = await getLotTypes() + const occupancyTypes = await getContractTypes() + const lotTypes = await getBurialSiteTypes() response.render('admin-fees', { headTitle: 'Fee Management', diff --git a/handlers/admin-get/occupancyTypes.js b/handlers/admin-get/occupancyTypes.js index 686813b1..369886d9 100644 --- a/handlers/admin-get/occupancyTypes.js +++ b/handlers/admin-get/occupancyTypes.js @@ -1,12 +1,12 @@ -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; import { getPrintConfig } from '../../helpers/functions.print.js'; export default async function handler(_request, response) { - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); - const occupancyTypePrints = getConfigProperty('settings.lotOccupancy.prints'); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); + const ContractTypePrints = getConfigProperty('settings.lotOccupancy.prints'); const occupancyTypePrintTitles = {}; - for (const printEJS of occupancyTypePrints) { + for (const printEJS of ContractTypePrints) { const printConfig = getPrintConfig(printEJS); if (printConfig !== undefined) { occupancyTypePrintTitles[printEJS] = printConfig.title; @@ -15,7 +15,7 @@ export default async function handler(_request, response) { response.render('admin-occupancyTypes', { headTitle: `${getConfigProperty('aliases.occupancy')} Type Management`, occupancyTypes, - allOccupancyTypeFields, + allContractTypeFields, occupancyTypePrintTitles }); } diff --git a/handlers/admin-get/occupancyTypes.ts b/handlers/admin-get/occupancyTypes.ts index b2c6a40f..185f65fa 100644 --- a/handlers/admin-get/occupancyTypes.ts +++ b/handlers/admin-get/occupancyTypes.ts @@ -1,8 +1,8 @@ import type { Request, Response } from 'express' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' import { getConfigProperty } from '../../helpers/config.helpers.js' import { getPrintConfig } from '../../helpers/functions.print.js' @@ -11,14 +11,14 @@ export default async function handler( _request: Request, response: Response ): Promise { - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() - const occupancyTypePrints = getConfigProperty('settings.lotOccupancy.prints') + const ContractTypePrints = getConfigProperty('settings.lotOccupancy.prints') const occupancyTypePrintTitles = {} - for (const printEJS of occupancyTypePrints) { + for (const printEJS of ContractTypePrints) { const printConfig = getPrintConfig(printEJS) if (printConfig !== undefined) { @@ -29,7 +29,7 @@ export default async function handler( response.render('admin-occupancyTypes', { headTitle: `${getConfigProperty('aliases.occupancy')} Type Management`, occupancyTypes, - allOccupancyTypeFields, + allContractTypeFields, occupancyTypePrintTitles }) } diff --git a/handlers/admin-post/doAddLotStatus.js b/handlers/admin-post/doAddLotStatus.js index ee6ea83b..7073f7ba 100644 --- a/handlers/admin-post/doAddLotStatus.js +++ b/handlers/admin-post/doAddLotStatus.js @@ -1,11 +1,11 @@ import { addRecord } from '../../database/addRecord.js'; import { getLotStatuses } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const lotStatusId = await addRecord('LotStatuses', request.body.lotStatus, request.body.orderNumber ?? -1, request.session.user); + const burialSiteStatusId = await addRecord('LotStatuses', request.body.lotStatus, request.body.orderNumber ?? -1, request.session.user); const lotStatuses = await getLotStatuses(); response.json({ success: true, - lotStatusId, + burialSiteStatusId, lotStatuses }); } diff --git a/handlers/admin-post/doAddLotStatus.ts b/handlers/admin-post/doAddLotStatus.ts index b43ff894..8e39ab62 100644 --- a/handlers/admin-post/doAddLotStatus.ts +++ b/handlers/admin-post/doAddLotStatus.ts @@ -7,7 +7,7 @@ export default async function handler( request: Request, response: Response ): Promise { - const lotStatusId = await addRecord( + const burialSiteStatusId = await addRecord( 'LotStatuses', request.body.lotStatus, request.body.orderNumber ?? -1, @@ -18,7 +18,7 @@ export default async function handler( response.json({ success: true, - lotStatusId, + burialSiteStatusId, lotStatuses }) } diff --git a/handlers/admin-post/doAddLotType.js b/handlers/admin-post/doAddLotType.js index 6782afe7..e5f4c48e 100644 --- a/handlers/admin-post/doAddLotType.js +++ b/handlers/admin-post/doAddLotType.js @@ -1,11 +1,11 @@ import { addRecord } from '../../database/addRecord.js'; -import { getLotTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const lotTypeId = await addRecord('LotTypes', request.body.lotType, request.body.orderNumber ?? -1, request.session.user); - const lotTypes = await getLotTypes(); + const burialSiteTypeId = await addRecord('LotTypes', request.body.lotType, request.body.orderNumber ?? -1, request.session.user); + const lotTypes = await getBurialSiteTypes(); response.json({ success: true, - lotTypeId, + burialSiteTypeId, lotTypes }); } diff --git a/handlers/admin-post/doAddLotType.ts b/handlers/admin-post/doAddLotType.ts index d31dd331..3689bc5d 100644 --- a/handlers/admin-post/doAddLotType.ts +++ b/handlers/admin-post/doAddLotType.ts @@ -1,24 +1,24 @@ import type { Request, Response } from 'express' import { addRecord } from '../../database/addRecord.js' -import { getLotTypes } from '../../helpers/functions.cache.js' +import { getBurialSiteTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request, response: Response ): Promise { - const lotTypeId = await addRecord( + const burialSiteTypeId = await addRecord( 'LotTypes', request.body.lotType, request.body.orderNumber ?? -1, request.session.user as User ) - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() response.json({ success: true, - lotTypeId, + burialSiteTypeId, lotTypes }) } diff --git a/handlers/admin-post/doAddLotTypeField.js b/handlers/admin-post/doAddLotTypeField.js index e46afbdc..50dcf0a6 100644 --- a/handlers/admin-post/doAddLotTypeField.js +++ b/handlers/admin-post/doAddLotTypeField.js @@ -1,8 +1,8 @@ import addLotTypeField from '../../database/addLotTypeField.js'; -import { getLotTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const lotTypeFieldId = await addLotTypeField(request.body, request.session.user); - const lotTypes = await getLotTypes(); + const lotTypes = await getBurialSiteTypes(); response.json({ success: true, lotTypeFieldId, diff --git a/handlers/admin-post/doAddLotTypeField.ts b/handlers/admin-post/doAddLotTypeField.ts index 541b8b89..ecd96355 100644 --- a/handlers/admin-post/doAddLotTypeField.ts +++ b/handlers/admin-post/doAddLotTypeField.ts @@ -3,7 +3,7 @@ import type { Request, Response } from 'express' import addLotTypeField, { type AddLotTypeFieldForm } from '../../database/addLotTypeField.js' -import { getLotTypes } from '../../helpers/functions.cache.js' +import { getBurialSiteTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request, @@ -14,7 +14,7 @@ export default async function handler( request.session.user as User ) - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() response.json({ success: true, diff --git a/handlers/admin-post/doAddOccupancyType.js b/handlers/admin-post/doAddOccupancyType.js index 2db4a6bd..a48b9b2f 100644 --- a/handlers/admin-post/doAddOccupancyType.js +++ b/handlers/admin-post/doAddOccupancyType.js @@ -1,13 +1,13 @@ import { addRecord } from '../../database/addRecord.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const occupancyTypeId = await addRecord('OccupancyTypes', request.body.occupancyType, request.body.orderNumber ?? -1, request.session.user); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + const contractTypeId = await addRecord('OccupancyTypes', request.body.occupancyType, request.body.orderNumber ?? -1, request.session.user); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success: true, - occupancyTypeId, + contractTypeId, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doAddOccupancyType.ts b/handlers/admin-post/doAddOccupancyType.ts index 478cf17f..f8ed46af 100644 --- a/handlers/admin-post/doAddOccupancyType.ts +++ b/handlers/admin-post/doAddOccupancyType.ts @@ -2,28 +2,28 @@ import type { Request, Response } from 'express' import { addRecord } from '../../database/addRecord.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request, response: Response ): Promise { - const occupancyTypeId = await addRecord( + const contractTypeId = await addRecord( 'OccupancyTypes', request.body.occupancyType, request.body.orderNumber ?? -1, request.session.user as User ) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success: true, - occupancyTypeId, + contractTypeId, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doAddOccupancyTypeField.js b/handlers/admin-post/doAddOccupancyTypeField.js index 1e348073..fadf8084 100644 --- a/handlers/admin-post/doAddOccupancyTypeField.js +++ b/handlers/admin-post/doAddOccupancyTypeField.js @@ -1,13 +1,13 @@ import addOccupancyTypeField from '../../database/addOccupancyTypeField.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const occupancyTypeFieldId = await addOccupancyTypeField(request.body, request.session.user); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + const contractTypeFieldId = await addOccupancyTypeField(request.body, request.session.user); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success: true, - occupancyTypeFieldId, + contractTypeFieldId, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doAddOccupancyTypeField.ts b/handlers/admin-post/doAddOccupancyTypeField.ts index bd6cac45..53c7c5ad 100644 --- a/handlers/admin-post/doAddOccupancyTypeField.ts +++ b/handlers/admin-post/doAddOccupancyTypeField.ts @@ -4,26 +4,26 @@ import addOccupancyTypeField, { type AddOccupancyTypeFieldForm } from '../../database/addOccupancyTypeField.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request, response: Response ): Promise { - const occupancyTypeFieldId = await addOccupancyTypeField( + const contractTypeFieldId = await addOccupancyTypeField( request.body as AddOccupancyTypeFieldForm, request.session.user as User ) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success: true, - occupancyTypeFieldId, + contractTypeFieldId, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doAddOccupancyTypePrint.js b/handlers/admin-post/doAddOccupancyTypePrint.js index 6d14e0fc..8b2af43f 100644 --- a/handlers/admin-post/doAddOccupancyTypePrint.js +++ b/handlers/admin-post/doAddOccupancyTypePrint.js @@ -1,12 +1,12 @@ import addOccupancyTypePrint from '../../database/addOccupancyTypePrint.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = await addOccupancyTypePrint(request.body, request.session.user); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doAddOccupancyTypePrint.ts b/handlers/admin-post/doAddOccupancyTypePrint.ts index 96875fef..1da31a34 100644 --- a/handlers/admin-post/doAddOccupancyTypePrint.ts +++ b/handlers/admin-post/doAddOccupancyTypePrint.ts @@ -4,8 +4,8 @@ import addOccupancyTypePrint, { type AddOccupancyTypePrintForm } from '../../database/addOccupancyTypePrint.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( @@ -17,12 +17,12 @@ export default async function handler( request.session.user as User ) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doDeleteLotStatus.d.ts b/handlers/admin-post/doDeleteLotStatus.d.ts index 8b6aa056..2b230d63 100644 --- a/handlers/admin-post/doDeleteLotStatus.d.ts +++ b/handlers/admin-post/doDeleteLotStatus.d.ts @@ -1,4 +1,4 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doDeleteLotStatus.js b/handlers/admin-post/doDeleteLotStatus.js index 2a1859e6..17e1c87a 100644 --- a/handlers/admin-post/doDeleteLotStatus.js +++ b/handlers/admin-post/doDeleteLotStatus.js @@ -1,7 +1,7 @@ import { deleteRecord } from '../../database/deleteRecord.js'; import { getLotStatuses } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const success = await deleteRecord('LotStatuses', request.body.lotStatusId, request.session.user); + const success = await deleteRecord('LotStatuses', request.body.burialSiteStatusId, request.session.user); const lotStatuses = await getLotStatuses(); response.json({ success, diff --git a/handlers/admin-post/doDeleteLotStatus.ts b/handlers/admin-post/doDeleteLotStatus.ts index fa984fe6..3c145548 100644 --- a/handlers/admin-post/doDeleteLotStatus.ts +++ b/handlers/admin-post/doDeleteLotStatus.ts @@ -4,12 +4,12 @@ import { deleteRecord } from '../../database/deleteRecord.js' import { getLotStatuses } from '../../helpers/functions.cache.js' export default async function handler( - request: Request, + request: Request, response: Response ): Promise { const success = await deleteRecord( 'LotStatuses', - request.body.lotStatusId, + request.body.burialSiteStatusId, request.session.user as User ) diff --git a/handlers/admin-post/doDeleteLotType.d.ts b/handlers/admin-post/doDeleteLotType.d.ts index 3f806b54..af966b40 100644 --- a/handlers/admin-post/doDeleteLotType.d.ts +++ b/handlers/admin-post/doDeleteLotType.d.ts @@ -1,4 +1,4 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doDeleteLotType.js b/handlers/admin-post/doDeleteLotType.js index c7acabc8..f1731f6a 100644 --- a/handlers/admin-post/doDeleteLotType.js +++ b/handlers/admin-post/doDeleteLotType.js @@ -1,8 +1,8 @@ import { deleteRecord } from '../../database/deleteRecord.js'; -import { getLotTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const success = await deleteRecord('LotTypes', request.body.lotTypeId, request.session.user); - const lotTypes = await getLotTypes(); + const success = await deleteRecord('LotTypes', request.body.burialSiteTypeId, request.session.user); + const lotTypes = await getBurialSiteTypes(); response.json({ success, lotTypes diff --git a/handlers/admin-post/doDeleteLotType.ts b/handlers/admin-post/doDeleteLotType.ts index 335df967..13af9ef9 100644 --- a/handlers/admin-post/doDeleteLotType.ts +++ b/handlers/admin-post/doDeleteLotType.ts @@ -1,19 +1,19 @@ import type { Request, Response } from 'express' import { deleteRecord } from '../../database/deleteRecord.js' -import { getLotTypes } from '../../helpers/functions.cache.js' +import { getBurialSiteTypes } from '../../helpers/functions.cache.js' export default async function handler( - request: Request, + request: Request, response: Response ): Promise { const success = await deleteRecord( 'LotTypes', - request.body.lotTypeId as string, + request.body.burialSiteTypeId as string, request.session.user as User ) - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() response.json({ success, diff --git a/handlers/admin-post/doDeleteLotTypeField.js b/handlers/admin-post/doDeleteLotTypeField.js index 0c03d916..f6eb1540 100644 --- a/handlers/admin-post/doDeleteLotTypeField.js +++ b/handlers/admin-post/doDeleteLotTypeField.js @@ -1,8 +1,8 @@ import { deleteRecord } from '../../database/deleteRecord.js'; -import { getLotTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const success = await deleteRecord('LotTypeFields', request.body.lotTypeFieldId, request.session.user); - const lotTypes = await getLotTypes(); + const success = await deleteRecord('BurialSiteTypeFields', request.body.lotTypeFieldId, request.session.user); + const lotTypes = await getBurialSiteTypes(); response.json({ success, lotTypes diff --git a/handlers/admin-post/doDeleteLotTypeField.ts b/handlers/admin-post/doDeleteLotTypeField.ts index 709ce2bf..cadfccff 100644 --- a/handlers/admin-post/doDeleteLotTypeField.ts +++ b/handlers/admin-post/doDeleteLotTypeField.ts @@ -1,19 +1,19 @@ import type { Request, Response } from 'express' import { deleteRecord } from '../../database/deleteRecord.js' -import { getLotTypes } from '../../helpers/functions.cache.js' +import { getBurialSiteTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request, response: Response ): Promise { const success = await deleteRecord( - 'LotTypeFields', + 'BurialSiteTypeFields', request.body.lotTypeFieldId as string, request.session.user as User ) - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() response.json({ success, diff --git a/handlers/admin-post/doDeleteOccupancyType.d.ts b/handlers/admin-post/doDeleteOccupancyType.d.ts index 24c978d9..dc1620a5 100644 --- a/handlers/admin-post/doDeleteOccupancyType.d.ts +++ b/handlers/admin-post/doDeleteOccupancyType.d.ts @@ -1,4 +1,4 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doDeleteOccupancyType.js b/handlers/admin-post/doDeleteOccupancyType.js index 2f043e68..1533719f 100644 --- a/handlers/admin-post/doDeleteOccupancyType.js +++ b/handlers/admin-post/doDeleteOccupancyType.js @@ -1,12 +1,12 @@ import { deleteRecord } from '../../database/deleteRecord.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const success = await deleteRecord('OccupancyTypes', request.body.occupancyTypeId, request.session.user); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + const success = await deleteRecord('OccupancyTypes', request.body.contractTypeId, request.session.user); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doDeleteOccupancyType.ts b/handlers/admin-post/doDeleteOccupancyType.ts index ccd0ccbd..d4249f0a 100644 --- a/handlers/admin-post/doDeleteOccupancyType.ts +++ b/handlers/admin-post/doDeleteOccupancyType.ts @@ -2,26 +2,26 @@ import type { Request, Response } from 'express' import { deleteRecord } from '../../database/deleteRecord.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( - request: Request, + request: Request, response: Response ): Promise { const success = await deleteRecord( 'OccupancyTypes', - request.body.occupancyTypeId as string, + request.body.contractTypeId as string, request.session.user as User ) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doDeleteOccupancyTypeField.d.ts b/handlers/admin-post/doDeleteOccupancyTypeField.d.ts index 5f3ebdc8..99087f64 100644 --- a/handlers/admin-post/doDeleteOccupancyTypeField.d.ts +++ b/handlers/admin-post/doDeleteOccupancyTypeField.d.ts @@ -1,4 +1,4 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doDeleteOccupancyTypeField.js b/handlers/admin-post/doDeleteOccupancyTypeField.js index 8de56a6b..05ba5d48 100644 --- a/handlers/admin-post/doDeleteOccupancyTypeField.js +++ b/handlers/admin-post/doDeleteOccupancyTypeField.js @@ -1,12 +1,12 @@ import { deleteRecord } from '../../database/deleteRecord.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const success = await deleteRecord('OccupancyTypeFields', request.body.occupancyTypeFieldId, request.session.user); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + const success = await deleteRecord('ContractTypeFields', request.body.contractTypeFieldId, request.session.user); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doDeleteOccupancyTypeField.ts b/handlers/admin-post/doDeleteOccupancyTypeField.ts index 756f44ec..11449a3e 100644 --- a/handlers/admin-post/doDeleteOccupancyTypeField.ts +++ b/handlers/admin-post/doDeleteOccupancyTypeField.ts @@ -2,26 +2,26 @@ import type { Request, Response } from 'express' import { deleteRecord } from '../../database/deleteRecord.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( - request: Request, + request: Request, response: Response ): Promise { const success = await deleteRecord( - 'OccupancyTypeFields', - request.body.occupancyTypeFieldId, + 'ContractTypeFields', + request.body.contractTypeFieldId, request.session.user as User ) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doDeleteOccupancyTypePrint.d.ts b/handlers/admin-post/doDeleteOccupancyTypePrint.d.ts index b630f44e..b4fa82af 100644 --- a/handlers/admin-post/doDeleteOccupancyTypePrint.d.ts +++ b/handlers/admin-post/doDeleteOccupancyTypePrint.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doDeleteOccupancyTypePrint.js b/handlers/admin-post/doDeleteOccupancyTypePrint.js index 716636ad..be6c1ea6 100644 --- a/handlers/admin-post/doDeleteOccupancyTypePrint.js +++ b/handlers/admin-post/doDeleteOccupancyTypePrint.js @@ -1,12 +1,12 @@ import deleteOccupancyTypePrint from '../../database/deleteOccupancyTypePrint.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const success = await deleteOccupancyTypePrint(request.body.occupancyTypeId, request.body.printEJS, request.session.user); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + const success = await deleteOccupancyTypePrint(request.body.contractTypeId, request.body.printEJS, request.session.user); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doDeleteOccupancyTypePrint.ts b/handlers/admin-post/doDeleteOccupancyTypePrint.ts index e3ef5cbf..ebd6153c 100644 --- a/handlers/admin-post/doDeleteOccupancyTypePrint.ts +++ b/handlers/admin-post/doDeleteOccupancyTypePrint.ts @@ -2,30 +2,30 @@ import type { Request, Response } from 'express' import deleteOccupancyTypePrint from '../../database/deleteOccupancyTypePrint.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< unknown, unknown, - { occupancyTypeId: string; printEJS: string } + { contractTypeId: string; printEJS: string } >, response: Response ): Promise { const success = await deleteOccupancyTypePrint( - request.body.occupancyTypeId, + request.body.contractTypeId, request.body.printEJS, request.session.user as User ) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doMoveLotStatusDown.d.ts b/handlers/admin-post/doMoveLotStatusDown.d.ts index db8bc19a..14175c98 100644 --- a/handlers/admin-post/doMoveLotStatusDown.d.ts +++ b/handlers/admin-post/doMoveLotStatusDown.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doMoveLotStatusDown.js b/handlers/admin-post/doMoveLotStatusDown.js index 185fb467..c4f75be0 100644 --- a/handlers/admin-post/doMoveLotStatusDown.js +++ b/handlers/admin-post/doMoveLotStatusDown.js @@ -2,8 +2,8 @@ import { moveRecordDown, moveRecordDownToBottom } from '../../database/moveRecor import { getLotStatuses } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' - ? await moveRecordDownToBottom('LotStatuses', request.body.lotStatusId) - : await moveRecordDown('LotStatuses', request.body.lotStatusId); + ? await moveRecordDownToBottom('LotStatuses', request.body.burialSiteStatusId) + : await moveRecordDown('LotStatuses', request.body.burialSiteStatusId); const lotStatuses = await getLotStatuses(); response.json({ success, diff --git a/handlers/admin-post/doMoveLotStatusDown.ts b/handlers/admin-post/doMoveLotStatusDown.ts index 3ce4a85c..b6601c3f 100644 --- a/handlers/admin-post/doMoveLotStatusDown.ts +++ b/handlers/admin-post/doMoveLotStatusDown.ts @@ -10,14 +10,14 @@ export default async function handler( request: Request< unknown, unknown, - { lotStatusId: string; moveToEnd: '0' | '1' } + { burialSiteStatusId: string; moveToEnd: '0' | '1' } >, response: Response ): Promise { const success = request.body.moveToEnd === '1' - ? await moveRecordDownToBottom('LotStatuses', request.body.lotStatusId) - : await moveRecordDown('LotStatuses', request.body.lotStatusId) + ? await moveRecordDownToBottom('LotStatuses', request.body.burialSiteStatusId) + : await moveRecordDown('LotStatuses', request.body.burialSiteStatusId) const lotStatuses = await getLotStatuses() diff --git a/handlers/admin-post/doMoveLotStatusUp.d.ts b/handlers/admin-post/doMoveLotStatusUp.d.ts index db8bc19a..14175c98 100644 --- a/handlers/admin-post/doMoveLotStatusUp.d.ts +++ b/handlers/admin-post/doMoveLotStatusUp.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doMoveLotStatusUp.js b/handlers/admin-post/doMoveLotStatusUp.js index c4d74fa7..4ee6b8bd 100644 --- a/handlers/admin-post/doMoveLotStatusUp.js +++ b/handlers/admin-post/doMoveLotStatusUp.js @@ -2,8 +2,8 @@ import { moveRecordUp, moveRecordUpToTop } from '../../database/moveRecord.js'; import { getLotStatuses } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' - ? await moveRecordUpToTop('LotStatuses', request.body.lotStatusId) - : await moveRecordUp('LotStatuses', request.body.lotStatusId); + ? await moveRecordUpToTop('LotStatuses', request.body.burialSiteStatusId) + : await moveRecordUp('LotStatuses', request.body.burialSiteStatusId); const lotStatuses = await getLotStatuses(); response.json({ success, diff --git a/handlers/admin-post/doMoveLotStatusUp.ts b/handlers/admin-post/doMoveLotStatusUp.ts index 129a2488..95a25a7e 100644 --- a/handlers/admin-post/doMoveLotStatusUp.ts +++ b/handlers/admin-post/doMoveLotStatusUp.ts @@ -7,14 +7,14 @@ export default async function handler( request: Request< unknown, unknown, - { lotStatusId: string; moveToEnd: '0' | '1' } + { burialSiteStatusId: string; moveToEnd: '0' | '1' } >, response: Response ): Promise { const success = request.body.moveToEnd === '1' - ? await moveRecordUpToTop('LotStatuses', request.body.lotStatusId) - : await moveRecordUp('LotStatuses', request.body.lotStatusId) + ? await moveRecordUpToTop('LotStatuses', request.body.burialSiteStatusId) + : await moveRecordUp('LotStatuses', request.body.burialSiteStatusId) const lotStatuses = await getLotStatuses() diff --git a/handlers/admin-post/doMoveLotTypeDown.d.ts b/handlers/admin-post/doMoveLotTypeDown.d.ts index ae0df006..dcbb398c 100644 --- a/handlers/admin-post/doMoveLotTypeDown.d.ts +++ b/handlers/admin-post/doMoveLotTypeDown.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doMoveLotTypeDown.js b/handlers/admin-post/doMoveLotTypeDown.js index 9d0190e2..af8cf5a3 100644 --- a/handlers/admin-post/doMoveLotTypeDown.js +++ b/handlers/admin-post/doMoveLotTypeDown.js @@ -1,10 +1,10 @@ import { moveRecordDown, moveRecordDownToBottom } from '../../database/moveRecord.js'; -import { getLotTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' - ? await moveRecordDownToBottom('LotTypes', request.body.lotTypeId) - : await moveRecordDown('LotTypes', request.body.lotTypeId); - const lotTypes = await getLotTypes(); + ? await moveRecordDownToBottom('LotTypes', request.body.burialSiteTypeId) + : await moveRecordDown('LotTypes', request.body.burialSiteTypeId); + const lotTypes = await getBurialSiteTypes(); response.json({ success, lotTypes diff --git a/handlers/admin-post/doMoveLotTypeDown.ts b/handlers/admin-post/doMoveLotTypeDown.ts index b3d5afa2..f8063e7b 100644 --- a/handlers/admin-post/doMoveLotTypeDown.ts +++ b/handlers/admin-post/doMoveLotTypeDown.ts @@ -4,22 +4,22 @@ import { moveRecordDown, moveRecordDownToBottom } from '../../database/moveRecord.js' -import { getLotTypes } from '../../helpers/functions.cache.js' +import { getBurialSiteTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< unknown, unknown, - { lotTypeId: string; moveToEnd: '0' | '1' } + { burialSiteTypeId: string; moveToEnd: '0' | '1' } >, response: Response ): Promise { const success = request.body.moveToEnd === '1' - ? await moveRecordDownToBottom('LotTypes', request.body.lotTypeId) - : await moveRecordDown('LotTypes', request.body.lotTypeId) + ? await moveRecordDownToBottom('LotTypes', request.body.burialSiteTypeId) + : await moveRecordDown('LotTypes', request.body.burialSiteTypeId) - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() response.json({ success, diff --git a/handlers/admin-post/doMoveLotTypeFieldDown.js b/handlers/admin-post/doMoveLotTypeFieldDown.js index 0bffe4e0..726835f1 100644 --- a/handlers/admin-post/doMoveLotTypeFieldDown.js +++ b/handlers/admin-post/doMoveLotTypeFieldDown.js @@ -1,10 +1,10 @@ import { moveLotTypeFieldDown, moveLotTypeFieldDownToBottom } from '../../database/moveLotTypeField.js'; -import { getLotTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' ? await moveLotTypeFieldDownToBottom(request.body.lotTypeFieldId) : await moveLotTypeFieldDown(request.body.lotTypeFieldId); - const lotTypes = await getLotTypes(); + const lotTypes = await getBurialSiteTypes(); response.json({ success, lotTypes diff --git a/handlers/admin-post/doMoveLotTypeFieldDown.ts b/handlers/admin-post/doMoveLotTypeFieldDown.ts index 48b347a9..aa44b738 100644 --- a/handlers/admin-post/doMoveLotTypeFieldDown.ts +++ b/handlers/admin-post/doMoveLotTypeFieldDown.ts @@ -4,7 +4,7 @@ import { moveLotTypeFieldDown, moveLotTypeFieldDownToBottom } from '../../database/moveLotTypeField.js' -import { getLotTypes } from '../../helpers/functions.cache.js' +import { getBurialSiteTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< @@ -19,7 +19,7 @@ export default async function handler( ? await moveLotTypeFieldDownToBottom(request.body.lotTypeFieldId) : await moveLotTypeFieldDown(request.body.lotTypeFieldId) - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() response.json({ success, diff --git a/handlers/admin-post/doMoveLotTypeFieldUp.js b/handlers/admin-post/doMoveLotTypeFieldUp.js index f6900d8c..dd786075 100644 --- a/handlers/admin-post/doMoveLotTypeFieldUp.js +++ b/handlers/admin-post/doMoveLotTypeFieldUp.js @@ -1,10 +1,10 @@ import { moveLotTypeFieldUp, moveLotTypeFieldUpToTop } from '../../database/moveLotTypeField.js'; -import { getLotTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' ? await moveLotTypeFieldUpToTop(request.body.lotTypeFieldId) : await moveLotTypeFieldUp(request.body.lotTypeFieldId); - const lotTypes = await getLotTypes(); + const lotTypes = await getBurialSiteTypes(); response.json({ success, lotTypes diff --git a/handlers/admin-post/doMoveLotTypeFieldUp.ts b/handlers/admin-post/doMoveLotTypeFieldUp.ts index a6804de2..a5410549 100644 --- a/handlers/admin-post/doMoveLotTypeFieldUp.ts +++ b/handlers/admin-post/doMoveLotTypeFieldUp.ts @@ -4,7 +4,7 @@ import { moveLotTypeFieldUp, moveLotTypeFieldUpToTop } from '../../database/moveLotTypeField.js' -import { getLotTypes } from '../../helpers/functions.cache.js' +import { getBurialSiteTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< @@ -19,7 +19,7 @@ export default async function handler( ? await moveLotTypeFieldUpToTop(request.body.lotTypeFieldId) : await moveLotTypeFieldUp(request.body.lotTypeFieldId) - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() response.json({ success, diff --git a/handlers/admin-post/doMoveLotTypeUp.d.ts b/handlers/admin-post/doMoveLotTypeUp.d.ts index ae0df006..dcbb398c 100644 --- a/handlers/admin-post/doMoveLotTypeUp.d.ts +++ b/handlers/admin-post/doMoveLotTypeUp.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doMoveLotTypeUp.js b/handlers/admin-post/doMoveLotTypeUp.js index 19fcb2a3..0fa010b2 100644 --- a/handlers/admin-post/doMoveLotTypeUp.js +++ b/handlers/admin-post/doMoveLotTypeUp.js @@ -1,10 +1,10 @@ import { moveRecordUp, moveRecordUpToTop } from '../../database/moveRecord.js'; -import { getLotTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' - ? await moveRecordUpToTop('LotTypes', request.body.lotTypeId) - : await moveRecordUp('LotTypes', request.body.lotTypeId); - const lotTypes = await getLotTypes(); + ? await moveRecordUpToTop('LotTypes', request.body.burialSiteTypeId) + : await moveRecordUp('LotTypes', request.body.burialSiteTypeId); + const lotTypes = await getBurialSiteTypes(); response.json({ success, lotTypes diff --git a/handlers/admin-post/doMoveLotTypeUp.ts b/handlers/admin-post/doMoveLotTypeUp.ts index 36321081..2fa85ba3 100644 --- a/handlers/admin-post/doMoveLotTypeUp.ts +++ b/handlers/admin-post/doMoveLotTypeUp.ts @@ -1,22 +1,22 @@ import type { Request, Response } from 'express' import { moveRecordUp, moveRecordUpToTop } from '../../database/moveRecord.js' -import { getLotTypes } from '../../helpers/functions.cache.js' +import { getBurialSiteTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< unknown, unknown, - { lotTypeId: string; moveToEnd: '0' | '1' } + { burialSiteTypeId: string; moveToEnd: '0' | '1' } >, response: Response ): Promise { const success = request.body.moveToEnd === '1' - ? await moveRecordUpToTop('LotTypes', request.body.lotTypeId) - : await moveRecordUp('LotTypes', request.body.lotTypeId) + ? await moveRecordUpToTop('LotTypes', request.body.burialSiteTypeId) + : await moveRecordUp('LotTypes', request.body.burialSiteTypeId) - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() response.json({ success, diff --git a/handlers/admin-post/doMoveOccupancyTypeDown.d.ts b/handlers/admin-post/doMoveOccupancyTypeDown.d.ts index 794a45b6..2ff5fd7b 100644 --- a/handlers/admin-post/doMoveOccupancyTypeDown.d.ts +++ b/handlers/admin-post/doMoveOccupancyTypeDown.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doMoveOccupancyTypeDown.js b/handlers/admin-post/doMoveOccupancyTypeDown.js index 47ce49ed..d8e742eb 100644 --- a/handlers/admin-post/doMoveOccupancyTypeDown.js +++ b/handlers/admin-post/doMoveOccupancyTypeDown.js @@ -1,14 +1,14 @@ import { moveRecordDown, moveRecordDownToBottom } from '../../database/moveRecord.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' - ? await moveRecordDownToBottom('OccupancyTypes', request.body.occupancyTypeId) - : await moveRecordDown('OccupancyTypes', request.body.occupancyTypeId); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + ? await moveRecordDownToBottom('OccupancyTypes', request.body.contractTypeId) + : await moveRecordDown('OccupancyTypes', request.body.contractTypeId); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doMoveOccupancyTypeDown.ts b/handlers/admin-post/doMoveOccupancyTypeDown.ts index c196537e..15e1e79e 100644 --- a/handlers/admin-post/doMoveOccupancyTypeDown.ts +++ b/handlers/admin-post/doMoveOccupancyTypeDown.ts @@ -5,15 +5,15 @@ import { moveRecordDownToBottom } from '../../database/moveRecord.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< unknown, unknown, - { occupancyTypeId: string; moveToEnd: '0' | '1' } + { contractTypeId: string; moveToEnd: '0' | '1' } >, response: Response ): Promise { @@ -21,16 +21,16 @@ export default async function handler( request.body.moveToEnd === '1' ? await moveRecordDownToBottom( 'OccupancyTypes', - request.body.occupancyTypeId + request.body.contractTypeId ) - : await moveRecordDown('OccupancyTypes', request.body.occupancyTypeId) + : await moveRecordDown('OccupancyTypes', request.body.contractTypeId) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doMoveOccupancyTypeFieldDown.d.ts b/handlers/admin-post/doMoveOccupancyTypeFieldDown.d.ts index db628aa6..44fc8cf1 100644 --- a/handlers/admin-post/doMoveOccupancyTypeFieldDown.d.ts +++ b/handlers/admin-post/doMoveOccupancyTypeFieldDown.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doMoveOccupancyTypeFieldDown.js b/handlers/admin-post/doMoveOccupancyTypeFieldDown.js index cf2caa9f..32471dee 100644 --- a/handlers/admin-post/doMoveOccupancyTypeFieldDown.js +++ b/handlers/admin-post/doMoveOccupancyTypeFieldDown.js @@ -1,14 +1,14 @@ import { moveOccupancyTypeFieldDown, moveOccupancyTypeFieldDownToBottom } from '../../database/moveOccupancyTypeField.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' - ? await moveOccupancyTypeFieldDownToBottom(request.body.occupancyTypeFieldId) - : await moveOccupancyTypeFieldDown(request.body.occupancyTypeFieldId); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + ? await moveOccupancyTypeFieldDownToBottom(request.body.contractTypeFieldId) + : await moveOccupancyTypeFieldDown(request.body.contractTypeFieldId); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doMoveOccupancyTypeFieldDown.ts b/handlers/admin-post/doMoveOccupancyTypeFieldDown.ts index dd354c28..7d4b45f2 100644 --- a/handlers/admin-post/doMoveOccupancyTypeFieldDown.ts +++ b/handlers/admin-post/doMoveOccupancyTypeFieldDown.ts @@ -5,31 +5,31 @@ import { moveOccupancyTypeFieldDownToBottom } from '../../database/moveOccupancyTypeField.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< unknown, unknown, - { occupancyTypeFieldId: string; moveToEnd: '0' | '1' } + { contractTypeFieldId: string; moveToEnd: '0' | '1' } >, response: Response ): Promise { const success = request.body.moveToEnd === '1' ? await moveOccupancyTypeFieldDownToBottom( - request.body.occupancyTypeFieldId + request.body.contractTypeFieldId ) - : await moveOccupancyTypeFieldDown(request.body.occupancyTypeFieldId) + : await moveOccupancyTypeFieldDown(request.body.contractTypeFieldId) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doMoveOccupancyTypeFieldUp.d.ts b/handlers/admin-post/doMoveOccupancyTypeFieldUp.d.ts index db628aa6..44fc8cf1 100644 --- a/handlers/admin-post/doMoveOccupancyTypeFieldUp.d.ts +++ b/handlers/admin-post/doMoveOccupancyTypeFieldUp.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doMoveOccupancyTypeFieldUp.js b/handlers/admin-post/doMoveOccupancyTypeFieldUp.js index ddfa5707..2f26afcb 100644 --- a/handlers/admin-post/doMoveOccupancyTypeFieldUp.js +++ b/handlers/admin-post/doMoveOccupancyTypeFieldUp.js @@ -1,14 +1,14 @@ import { moveOccupancyTypeFieldUp, moveOccupancyTypeFieldUpToTop } from '../../database/moveOccupancyTypeField.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' - ? await moveOccupancyTypeFieldUpToTop(request.body.occupancyTypeFieldId) - : await moveOccupancyTypeFieldUp(request.body.occupancyTypeFieldId); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + ? await moveOccupancyTypeFieldUpToTop(request.body.contractTypeFieldId) + : await moveOccupancyTypeFieldUp(request.body.contractTypeFieldId); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doMoveOccupancyTypeFieldUp.ts b/handlers/admin-post/doMoveOccupancyTypeFieldUp.ts index 975ec43d..17caf399 100644 --- a/handlers/admin-post/doMoveOccupancyTypeFieldUp.ts +++ b/handlers/admin-post/doMoveOccupancyTypeFieldUp.ts @@ -5,29 +5,29 @@ import { moveOccupancyTypeFieldUpToTop } from '../../database/moveOccupancyTypeField.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< unknown, unknown, - { occupancyTypeFieldId: string; moveToEnd: '0' | '1' } + { contractTypeFieldId: string; moveToEnd: '0' | '1' } >, response: Response ): Promise { const success = request.body.moveToEnd === '1' - ? await moveOccupancyTypeFieldUpToTop(request.body.occupancyTypeFieldId) - : await moveOccupancyTypeFieldUp(request.body.occupancyTypeFieldId) + ? await moveOccupancyTypeFieldUpToTop(request.body.contractTypeFieldId) + : await moveOccupancyTypeFieldUp(request.body.contractTypeFieldId) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doMoveOccupancyTypePrintDown.d.ts b/handlers/admin-post/doMoveOccupancyTypePrintDown.d.ts index b1afedba..e1a5dac8 100644 --- a/handlers/admin-post/doMoveOccupancyTypePrintDown.d.ts +++ b/handlers/admin-post/doMoveOccupancyTypePrintDown.d.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doMoveOccupancyTypePrintDown.js b/handlers/admin-post/doMoveOccupancyTypePrintDown.js index e9bc8173..7abdb9ea 100644 --- a/handlers/admin-post/doMoveOccupancyTypePrintDown.js +++ b/handlers/admin-post/doMoveOccupancyTypePrintDown.js @@ -1,14 +1,14 @@ import { moveOccupancyTypePrintDown, moveOccupancyTypePrintDownToBottom } from '../../database/moveOccupancyTypePrintDown.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' - ? await moveOccupancyTypePrintDownToBottom(request.body.occupancyTypeId, request.body.printEJS) - : await moveOccupancyTypePrintDown(request.body.occupancyTypeId, request.body.printEJS); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + ? await moveOccupancyTypePrintDownToBottom(request.body.contractTypeId, request.body.printEJS) + : await moveOccupancyTypePrintDown(request.body.contractTypeId, request.body.printEJS); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doMoveOccupancyTypePrintDown.ts b/handlers/admin-post/doMoveOccupancyTypePrintDown.ts index 87cba62f..56f7ef54 100644 --- a/handlers/admin-post/doMoveOccupancyTypePrintDown.ts +++ b/handlers/admin-post/doMoveOccupancyTypePrintDown.ts @@ -5,35 +5,35 @@ import { moveOccupancyTypePrintDownToBottom } from '../../database/moveOccupancyTypePrintDown.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< unknown, unknown, - { occupancyTypeId: string; printEJS: string; moveToEnd: '0' | '1' } + { contractTypeId: string; printEJS: string; moveToEnd: '0' | '1' } >, response: Response ): Promise { const success = request.body.moveToEnd === '1' ? await moveOccupancyTypePrintDownToBottom( - request.body.occupancyTypeId, + request.body.contractTypeId, request.body.printEJS ) : await moveOccupancyTypePrintDown( - request.body.occupancyTypeId, + request.body.contractTypeId, request.body.printEJS ) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doMoveOccupancyTypePrintUp.d.ts b/handlers/admin-post/doMoveOccupancyTypePrintUp.d.ts index b1afedba..e1a5dac8 100644 --- a/handlers/admin-post/doMoveOccupancyTypePrintUp.d.ts +++ b/handlers/admin-post/doMoveOccupancyTypePrintUp.d.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doMoveOccupancyTypePrintUp.js b/handlers/admin-post/doMoveOccupancyTypePrintUp.js index 0ba72a4c..fb46928e 100644 --- a/handlers/admin-post/doMoveOccupancyTypePrintUp.js +++ b/handlers/admin-post/doMoveOccupancyTypePrintUp.js @@ -1,14 +1,14 @@ import { moveOccupancyTypePrintUp, moveOccupancyTypePrintUpToTop } from '../../database/moveOccupancyTypePrintUp.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' - ? await moveOccupancyTypePrintUpToTop(request.body.occupancyTypeId, request.body.printEJS) - : await moveOccupancyTypePrintUp(request.body.occupancyTypeId, request.body.printEJS); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + ? await moveOccupancyTypePrintUpToTop(request.body.contractTypeId, request.body.printEJS) + : await moveOccupancyTypePrintUp(request.body.contractTypeId, request.body.printEJS); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doMoveOccupancyTypePrintUp.ts b/handlers/admin-post/doMoveOccupancyTypePrintUp.ts index 69bdf2a7..81cb8089 100644 --- a/handlers/admin-post/doMoveOccupancyTypePrintUp.ts +++ b/handlers/admin-post/doMoveOccupancyTypePrintUp.ts @@ -5,35 +5,35 @@ import { moveOccupancyTypePrintUpToTop } from '../../database/moveOccupancyTypePrintUp.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< unknown, unknown, - { occupancyTypeId: string; printEJS: string; moveToEnd: '0' | '1' } + { contractTypeId: string; printEJS: string; moveToEnd: '0' | '1' } >, response: Response ): Promise { const success = request.body.moveToEnd === '1' ? await moveOccupancyTypePrintUpToTop( - request.body.occupancyTypeId, + request.body.contractTypeId, request.body.printEJS ) : await moveOccupancyTypePrintUp( - request.body.occupancyTypeId, + request.body.contractTypeId, request.body.printEJS ) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doMoveOccupancyTypeUp.d.ts b/handlers/admin-post/doMoveOccupancyTypeUp.d.ts index 794a45b6..2ff5fd7b 100644 --- a/handlers/admin-post/doMoveOccupancyTypeUp.d.ts +++ b/handlers/admin-post/doMoveOccupancyTypeUp.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doMoveOccupancyTypeUp.js b/handlers/admin-post/doMoveOccupancyTypeUp.js index 5855b436..f70117b6 100644 --- a/handlers/admin-post/doMoveOccupancyTypeUp.js +++ b/handlers/admin-post/doMoveOccupancyTypeUp.js @@ -1,14 +1,14 @@ import { moveRecordUp, moveRecordUpToTop } from '../../database/moveRecord.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = request.body.moveToEnd === '1' - ? await moveRecordUpToTop('OccupancyTypes', request.body.occupancyTypeId) - : await moveRecordUp('OccupancyTypes', request.body.occupancyTypeId); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + ? await moveRecordUpToTop('OccupancyTypes', request.body.contractTypeId) + : await moveRecordUp('OccupancyTypes', request.body.contractTypeId); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doMoveOccupancyTypeUp.ts b/handlers/admin-post/doMoveOccupancyTypeUp.ts index 6d425ab6..0365bf35 100644 --- a/handlers/admin-post/doMoveOccupancyTypeUp.ts +++ b/handlers/admin-post/doMoveOccupancyTypeUp.ts @@ -2,29 +2,29 @@ import type { Request, Response } from 'express' import { moveRecordUp, moveRecordUpToTop } from '../../database/moveRecord.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< unknown, unknown, - { occupancyTypeId: string; moveToEnd: '0' | '1' } + { contractTypeId: string; moveToEnd: '0' | '1' } >, response: Response ): Promise { const success = request.body.moveToEnd === '1' - ? await moveRecordUpToTop('OccupancyTypes', request.body.occupancyTypeId) - : await moveRecordUp('OccupancyTypes', request.body.occupancyTypeId) + ? await moveRecordUpToTop('OccupancyTypes', request.body.contractTypeId) + : await moveRecordUp('OccupancyTypes', request.body.contractTypeId) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doUpdateLotStatus.d.ts b/handlers/admin-post/doUpdateLotStatus.d.ts index a6dceca9..5ffcdbf1 100644 --- a/handlers/admin-post/doUpdateLotStatus.d.ts +++ b/handlers/admin-post/doUpdateLotStatus.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doUpdateLotStatus.js b/handlers/admin-post/doUpdateLotStatus.js index 4aedd219..a31b8797 100644 --- a/handlers/admin-post/doUpdateLotStatus.js +++ b/handlers/admin-post/doUpdateLotStatus.js @@ -1,7 +1,7 @@ import { updateRecord } from '../../database/updateRecord.js'; import { getLotStatuses } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const success = await updateRecord('LotStatuses', request.body.lotStatusId, request.body.lotStatus, request.session.user); + const success = await updateRecord('LotStatuses', request.body.burialSiteStatusId, request.body.lotStatus, request.session.user); const lotStatuses = await getLotStatuses(); response.json({ success, diff --git a/handlers/admin-post/doUpdateLotStatus.ts b/handlers/admin-post/doUpdateLotStatus.ts index d7b3c0a3..d37b4c38 100644 --- a/handlers/admin-post/doUpdateLotStatus.ts +++ b/handlers/admin-post/doUpdateLotStatus.ts @@ -7,13 +7,13 @@ export default async function handler( request: Request< unknown, unknown, - { lotStatusId: string; lotStatus: string } + { burialSiteStatusId: string; lotStatus: string } >, response: Response ): Promise { const success = await updateRecord( 'LotStatuses', - request.body.lotStatusId, + request.body.burialSiteStatusId, request.body.lotStatus, request.session.user as User ) diff --git a/handlers/admin-post/doUpdateLotType.d.ts b/handlers/admin-post/doUpdateLotType.d.ts index 69d81c32..430aceb5 100644 --- a/handlers/admin-post/doUpdateLotType.d.ts +++ b/handlers/admin-post/doUpdateLotType.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doUpdateLotType.js b/handlers/admin-post/doUpdateLotType.js index 8c7d8a38..f31b440e 100644 --- a/handlers/admin-post/doUpdateLotType.js +++ b/handlers/admin-post/doUpdateLotType.js @@ -1,8 +1,8 @@ import { updateRecord } from '../../database/updateRecord.js'; -import { getLotTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const success = await updateRecord('LotTypes', request.body.lotTypeId, request.body.lotType, request.session.user); - const lotTypes = await getLotTypes(); + const success = await updateRecord('LotTypes', request.body.burialSiteTypeId, request.body.lotType, request.session.user); + const lotTypes = await getBurialSiteTypes(); response.json({ success, lotTypes diff --git a/handlers/admin-post/doUpdateLotType.ts b/handlers/admin-post/doUpdateLotType.ts index b93f86c8..8b872d71 100644 --- a/handlers/admin-post/doUpdateLotType.ts +++ b/handlers/admin-post/doUpdateLotType.ts @@ -1,20 +1,20 @@ import type { Request, Response } from 'express' import { updateRecord } from '../../database/updateRecord.js' -import { getLotTypes } from '../../helpers/functions.cache.js' +import { getBurialSiteTypes } from '../../helpers/functions.cache.js' export default async function handler( - request: Request, + request: Request, response: Response ): Promise { const success = await updateRecord( 'LotTypes', - request.body.lotTypeId, + request.body.burialSiteTypeId, request.body.lotType, request.session.user as User ) - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() response.json({ success, diff --git a/handlers/admin-post/doUpdateLotTypeField.js b/handlers/admin-post/doUpdateLotTypeField.js index 40a3dcc8..d9af6ae4 100644 --- a/handlers/admin-post/doUpdateLotTypeField.js +++ b/handlers/admin-post/doUpdateLotTypeField.js @@ -1,8 +1,8 @@ -import updateLotTypeField from '../../database/updateLotTypeField.js'; -import { getLotTypes } from '../../helpers/functions.cache.js'; +import updateBurialSiteTypeField from '../../database/updateBurialSiteTypeField.js'; +import { getBurialSiteTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const success = await updateLotTypeField(request.body, request.session.user); - const lotTypes = await getLotTypes(); + const success = await updateBurialSiteTypeField(request.body, request.session.user); + const lotTypes = await getBurialSiteTypes(); response.json({ success, lotTypes diff --git a/handlers/admin-post/doUpdateLotTypeField.ts b/handlers/admin-post/doUpdateLotTypeField.ts index f410cc49..8a591ea2 100644 --- a/handlers/admin-post/doUpdateLotTypeField.ts +++ b/handlers/admin-post/doUpdateLotTypeField.ts @@ -1,20 +1,20 @@ import type { Request, Response } from 'express' -import updateLotTypeField, { - type UpdateLotTypeFieldForm -} from '../../database/updateLotTypeField.js' -import { getLotTypes } from '../../helpers/functions.cache.js' +import updateBurialSiteTypeField, { + type UpdateBurialSiteTypeFieldForm +} from '../../database/updateBurialSiteTypeField.js' +import { getBurialSiteTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request, response: Response ): Promise { - const success = await updateLotTypeField( - request.body as UpdateLotTypeFieldForm, + const success = await updateBurialSiteTypeField( + request.body as UpdateBurialSiteTypeFieldForm, request.session.user as User ) - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() response.json({ success, diff --git a/handlers/admin-post/doUpdateOccupancyType.d.ts b/handlers/admin-post/doUpdateOccupancyType.d.ts index f79642cf..6be65985 100644 --- a/handlers/admin-post/doUpdateOccupancyType.d.ts +++ b/handlers/admin-post/doUpdateOccupancyType.d.ts @@ -1,5 +1,5 @@ import type { Request, Response } from 'express'; export default function handler(request: Request, response: Response): Promise; diff --git a/handlers/admin-post/doUpdateOccupancyType.js b/handlers/admin-post/doUpdateOccupancyType.js index 2cfe2eca..6b23682a 100644 --- a/handlers/admin-post/doUpdateOccupancyType.js +++ b/handlers/admin-post/doUpdateOccupancyType.js @@ -1,12 +1,12 @@ import { updateRecord } from '../../database/updateRecord.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const success = await updateRecord('OccupancyTypes', request.body.occupancyTypeId, request.body.occupancyType, request.session.user); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + const success = await updateRecord('OccupancyTypes', request.body.contractTypeId, request.body.occupancyType, request.session.user); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doUpdateOccupancyType.ts b/handlers/admin-post/doUpdateOccupancyType.ts index a0aa28f2..ac3dc323 100644 --- a/handlers/admin-post/doUpdateOccupancyType.ts +++ b/handlers/admin-post/doUpdateOccupancyType.ts @@ -2,31 +2,31 @@ import type { Request, Response } from 'express' import { updateRecord } from '../../database/updateRecord.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( request: Request< unknown, unknown, - { occupancyTypeId: string; occupancyType: string } + { contractTypeId: string; occupancyType: string } >, response: Response ): Promise { const success = await updateRecord( 'OccupancyTypes', - request.body.occupancyTypeId, + request.body.contractTypeId, request.body.occupancyType, request.session.user as User ) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/admin-post/doUpdateOccupancyTypeField.js b/handlers/admin-post/doUpdateOccupancyTypeField.js index 5f8cd9e4..600e6215 100644 --- a/handlers/admin-post/doUpdateOccupancyTypeField.js +++ b/handlers/admin-post/doUpdateOccupancyTypeField.js @@ -1,12 +1,12 @@ import updateOccupancyTypeField from '../../database/updateOccupancyTypeField.js'; -import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getAllContractTypeFields, getContractTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const success = await updateOccupancyTypeField(request.body, request.session.user); - const occupancyTypes = await getOccupancyTypes(); - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); + const occupancyTypes = await getContractTypes(); + const allContractTypeFields = await getAllContractTypeFields(); response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }); } diff --git a/handlers/admin-post/doUpdateOccupancyTypeField.ts b/handlers/admin-post/doUpdateOccupancyTypeField.ts index 24ac5507..02076654 100644 --- a/handlers/admin-post/doUpdateOccupancyTypeField.ts +++ b/handlers/admin-post/doUpdateOccupancyTypeField.ts @@ -4,8 +4,8 @@ import updateOccupancyTypeField, { type UpdateOccupancyTypeFieldForm } from '../../database/updateOccupancyTypeField.js' import { - getAllOccupancyTypeFields, - getOccupancyTypes + getAllContractTypeFields, + getContractTypes } from '../../helpers/functions.cache.js' export default async function handler( @@ -17,12 +17,12 @@ export default async function handler( request.session.user as User ) - const occupancyTypes = await getOccupancyTypes() - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const occupancyTypes = await getContractTypes() + const allContractTypeFields = await getAllContractTypeFields() response.json({ success, occupancyTypes, - allOccupancyTypeFields + allContractTypeFields }) } diff --git a/handlers/api-get/milestoneICS.js b/handlers/api-get/milestoneICS.js index 6644a6e3..f7c90714 100644 --- a/handlers/api-get/milestoneICS.js +++ b/handlers/api-get/milestoneICS.js @@ -59,7 +59,7 @@ function buildEventDescriptionHTML_occupancies(request, milestone) { for (const occupancy of milestone.workOrderLotOccupancies ?? []) { descriptionHTML += ` - + ${escapeHTML(occupancy.occupancyType ?? '')} @@ -67,11 +67,11 @@ function buildEventDescriptionHTML_occupancies(request, milestone) { ${occupancy.lotName ? escapeHTML(occupancy.lotName) : '(Not Set)'} - ${occupancy.occupancyStartDateString} + ${occupancy.contractStartDateString} - ${occupancy.occupancyEndDate - ? occupancy.occupancyEndDateString + ${occupancy.contractEndDate + ? occupancy.contractEndDateString : '(No End Date)'} `; @@ -112,7 +112,7 @@ function buildEventDescriptionHTML_lots(request, milestone) { ${escapeHTML(lot.lotName ?? '')} - ${escapeHTML(lot.mapName ?? '')} + ${escapeHTML(lot.cemeteryName ?? '')} ${escapeHTML(lot.lotType ?? '')} ${escapeHTML(lot.lotStatus ?? '')} `; @@ -166,7 +166,7 @@ function buildEventLocation(milestone) { const lotNames = []; if (milestone.workOrderLots.length > 0) { for (const lot of milestone.workOrderLots ?? []) { - lotNames.push(`${lot.mapName ?? ''}: ${lot.lotName ?? ''}`); + lotNames.push(`${lot.cemeteryName ?? ''}: ${lot.lotName ?? ''}`); } } return lotNames.join(', '); diff --git a/handlers/api-get/milestoneICS.ts b/handlers/api-get/milestoneICS.ts index 69ec8f2a..5a368243 100644 --- a/handlers/api-get/milestoneICS.ts +++ b/handlers/api-get/milestoneICS.ts @@ -94,7 +94,7 @@ function buildEventDescriptionHTML_occupancies( for (const occupancy of milestone.workOrderLotOccupancies ?? []) { descriptionHTML += ` - + ${escapeHTML(occupancy.occupancyType ?? '')} @@ -102,12 +102,12 @@ function buildEventDescriptionHTML_occupancies( ${occupancy.lotName ? escapeHTML(occupancy.lotName) : '(Not Set)'} - ${occupancy.occupancyStartDateString} + ${occupancy.contractStartDateString} ${ - occupancy.occupancyEndDate - ? occupancy.occupancyEndDateString + occupancy.contractEndDate + ? occupancy.contractEndDateString : '(No End Date)' } @@ -164,7 +164,7 @@ function buildEventDescriptionHTML_lots( ${escapeHTML(lot.lotName ?? '')} - ${escapeHTML(lot.mapName ?? '')} + ${escapeHTML(lot.cemeteryName ?? '')} ${escapeHTML(lot.lotType ?? '')} ${escapeHTML(lot.lotStatus ?? '')} ` @@ -246,7 +246,7 @@ function buildEventLocation(milestone: WorkOrderMilestone): string { if (milestone.workOrderLots!.length > 0) { for (const lot of milestone.workOrderLots ?? []) { - lotNames.push(`${lot.mapName ?? ''}: ${lot.lotName ?? ''}`) + lotNames.push(`${lot.cemeteryName ?? ''}: ${lot.lotName ?? ''}`) } } return lotNames.join(', ') diff --git a/handlers/burialSites-get/edit.js b/handlers/burialSites-get/edit.js index 3c2b4949..48331939 100644 --- a/handlers/burialSites-get/edit.js +++ b/handlers/burialSites-get/edit.js @@ -1,6 +1,6 @@ import getLot from '../../database/getLot.js'; import getMaps from '../../database/getMaps.js'; -import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js'; +import { getLotStatuses, getBurialSiteTypes } from '../../helpers/functions.cache.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(request, response) { const lot = await getLot(request.params.lotId); @@ -9,7 +9,7 @@ export default async function handler(request, response) { return; } const maps = await getMaps(); - const lotTypes = await getLotTypes(); + const lotTypes = await getBurialSiteTypes(); const lotStatuses = await getLotStatuses(); response.render('lot-edit', { headTitle: lot.lotName, diff --git a/handlers/burialSites-get/edit.ts b/handlers/burialSites-get/edit.ts index faedae2d..5aba7591 100644 --- a/handlers/burialSites-get/edit.ts +++ b/handlers/burialSites-get/edit.ts @@ -2,7 +2,7 @@ import type { Request, Response } from 'express' import getLot from '../../database/getLot.js' import getMaps from '../../database/getMaps.js' -import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js' +import { getLotStatuses, getBurialSiteTypes } from '../../helpers/functions.cache.js' import { getConfigProperty } from '../../helpers/config.helpers.js' export default async function handler( @@ -19,7 +19,7 @@ export default async function handler( } const maps = await getMaps() - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() const lotStatuses = await getLotStatuses() response.render('lot-edit', { diff --git a/handlers/burialSites-get/new.js b/handlers/burialSites-get/new.js index 99c88404..42f21c90 100644 --- a/handlers/burialSites-get/new.js +++ b/handlers/burialSites-get/new.js @@ -1,5 +1,5 @@ import getMaps from '../../database/getMaps.js'; -import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js'; +import { getLotStatuses, getBurialSiteTypes } from '../../helpers/functions.cache.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(request, response) { const lot = { @@ -7,17 +7,17 @@ export default async function handler(request, response) { lotOccupancies: [] }; const maps = await getMaps(); - if (request.query.mapId !== undefined) { - const mapId = Number.parseInt(request.query.mapId, 10); + if (request.query.cemeteryId !== undefined) { + const cemeteryId = Number.parseInt(request.query.cemeteryId, 10); const map = maps.find((possibleMap) => { - return mapId === possibleMap.mapId; + return cemeteryId === possibleMap.cemeteryId; }); if (map !== undefined) { - lot.mapId = map.mapId; - lot.mapName = map.mapName; + lot.cemeteryId = map.cemeteryId; + lot.cemeteryName = map.cemeteryName; } } - const lotTypes = await getLotTypes(); + const lotTypes = await getBurialSiteTypes(); const lotStatuses = await getLotStatuses(); response.render('lot-edit', { headTitle: `Create a New ${getConfigProperty('aliases.lot')}`, diff --git a/handlers/burialSites-get/new.ts b/handlers/burialSites-get/new.ts index f9fbb7ac..16b8ebd9 100644 --- a/handlers/burialSites-get/new.ts +++ b/handlers/burialSites-get/new.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express' import getMaps from '../../database/getMaps.js' -import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js' +import { getLotStatuses, getBurialSiteTypes } from '../../helpers/functions.cache.js' import { getConfigProperty } from '../../helpers/config.helpers.js' import type { Lot } from '../../types/recordTypes.js' @@ -16,20 +16,20 @@ export default async function handler( const maps = await getMaps() - if (request.query.mapId !== undefined) { - const mapId = Number.parseInt(request.query.mapId as string, 10) + if (request.query.cemeteryId !== undefined) { + const cemeteryId = Number.parseInt(request.query.cemeteryId as string, 10) const map = maps.find((possibleMap) => { - return mapId === possibleMap.mapId + return cemeteryId === possibleMap.cemeteryId }) if (map !== undefined) { - lot.mapId = map.mapId - lot.mapName = map.mapName + lot.cemeteryId = map.cemeteryId + lot.cemeteryName = map.cemeteryName } } - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() const lotStatuses = await getLotStatuses() response.render('lot-edit', { diff --git a/handlers/burialSites-get/search.js b/handlers/burialSites-get/search.js index f590ccc6..af372a7e 100644 --- a/handlers/burialSites-get/search.js +++ b/handlers/burialSites-get/search.js @@ -1,17 +1,17 @@ import getMaps from '../../database/getMaps.js'; -import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js'; +import { getLotStatuses, getBurialSiteTypes } from '../../helpers/functions.cache.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(request, response) { const maps = await getMaps(); - const lotTypes = await getLotTypes(); + const lotTypes = await getBurialSiteTypes(); const lotStatuses = await getLotStatuses(); response.render('lot-search', { headTitle: `${getConfigProperty('aliases.lot')} Search`, maps, lotTypes, lotStatuses, - mapId: request.query.mapId, - lotTypeId: request.query.lotTypeId, - lotStatusId: request.query.lotStatusId + cemeteryId: request.query.cemeteryId, + burialSiteTypeId: request.query.burialSiteTypeId, + burialSiteStatusId: request.query.burialSiteStatusId }); } diff --git a/handlers/burialSites-get/search.ts b/handlers/burialSites-get/search.ts index 5d023aed..010d3d0b 100644 --- a/handlers/burialSites-get/search.ts +++ b/handlers/burialSites-get/search.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express' import getMaps from '../../database/getMaps.js' -import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js' +import { getLotStatuses, getBurialSiteTypes } from '../../helpers/functions.cache.js' import { getConfigProperty } from '../../helpers/config.helpers.js' export default async function handler( @@ -9,7 +9,7 @@ export default async function handler( response: Response ): Promise { const maps = await getMaps() - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() const lotStatuses = await getLotStatuses() response.render('lot-search', { @@ -17,8 +17,8 @@ export default async function handler( maps, lotTypes, lotStatuses, - mapId: request.query.mapId, - lotTypeId: request.query.lotTypeId, - lotStatusId: request.query.lotStatusId + cemeteryId: request.query.cemeteryId, + burialSiteTypeId: request.query.burialSiteTypeId, + burialSiteStatusId: request.query.burialSiteStatusId }) } diff --git a/handlers/burialSites-post/doGetLotTypeFields.js b/handlers/burialSites-post/doGetLotTypeFields.js index b8f6b859..a308bf9b 100644 --- a/handlers/burialSites-post/doGetLotTypeFields.js +++ b/handlers/burialSites-post/doGetLotTypeFields.js @@ -1,7 +1,7 @@ import { getLotTypeById } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const lotType = (await getLotTypeById(Number.parseInt(request.body.lotTypeId, 10))); + const lotType = (await getLotTypeById(Number.parseInt(request.body.burialSiteTypeId, 10))); response.json({ - lotTypeFields: lotType.lotTypeFields + BurialSiteTypeFields: lotType.BurialSiteTypeFields }); } diff --git a/handlers/burialSites-post/doGetLotTypeFields.ts b/handlers/burialSites-post/doGetLotTypeFields.ts index 4ea8d33b..44245ef9 100644 --- a/handlers/burialSites-post/doGetLotTypeFields.ts +++ b/handlers/burialSites-post/doGetLotTypeFields.ts @@ -7,11 +7,11 @@ export default async function handler( response: Response ): Promise { const lotType = (await getLotTypeById( - Number.parseInt(request.body.lotTypeId, 10) + Number.parseInt(request.body.burialSiteTypeId, 10) ))! response.json({ - lotTypeFields: lotType.lotTypeFields + BurialSiteTypeFields: lotType.BurialSiteTypeFields }) } diff --git a/handlers/cemeteries-get/edit.js b/handlers/cemeteries-get/edit.js index 1862c0ed..9a35d0e1 100644 --- a/handlers/cemeteries-get/edit.js +++ b/handlers/cemeteries-get/edit.js @@ -1,27 +1,27 @@ -import getLotStatusSummary from '../../database/getLotStatusSummary.js'; -import getLotTypeSummary from '../../database/getLotTypeSummary.js'; -import getMap from '../../database/getMap.js'; +import getBurialSiteStatusSummary from '../../database/getBurialSiteStatusSummary.js'; +import getBurialSiteTypeSummary from '../../database/getBurialSiteTypeSummary.js'; +import getCemetery from '../../database/getCemetery.js'; +import { getCemeterySVGs } from '../../helpers/cemeteries.helpers.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; -import { getMapSVGs } from '../../helpers/functions.map.js'; export default async function handler(request, response) { - const map = await getMap(request.params.mapId); - if (map === undefined) { - response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=mapIdNotFound`); + const cemetery = await getCemetery(request.params.cemeteryId); + if (cemetery === undefined) { + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/cemeteries/?error=cemeteryIdNotFound`); return; } - const mapSVGs = await getMapSVGs(); - const lotTypeSummary = await getLotTypeSummary({ - mapId: map.mapId + const cemeterySVGs = await getCemeterySVGs(); + const burialSiteTypeSummary = await getBurialSiteTypeSummary({ + cemeteryId: cemetery.cemeteryId }); - const lotStatusSummary = await getLotStatusSummary({ - mapId: map.mapId + const burialSiteStatusSummary = await getBurialSiteStatusSummary({ + cemeteryId: cemetery.cemeteryId }); response.render('map-edit', { - headTitle: map.mapName, + headTitle: cemetery.cemeteryName, isCreate: false, - map, - mapSVGs, - lotTypeSummary, - lotStatusSummary + cemetery, + cemeterySVGs, + burialSiteTypeSummary, + burialSiteStatusSummary }); } diff --git a/handlers/cemeteries-get/edit.ts b/handlers/cemeteries-get/edit.ts index 7f8f7a81..c4c3e9c9 100644 --- a/handlers/cemeteries-get/edit.ts +++ b/handlers/cemeteries-get/edit.ts @@ -1,40 +1,40 @@ import type { Request, Response } from 'express' -import getLotStatusSummary from '../../database/getLotStatusSummary.js' -import getLotTypeSummary from '../../database/getLotTypeSummary.js' -import getMap from '../../database/getMap.js' +import getBurialSiteStatusSummary from '../../database/getBurialSiteStatusSummary.js' +import getBurialSiteTypeSummary from '../../database/getBurialSiteTypeSummary.js' +import getCemetery from '../../database/getCemetery.js' +import { getCemeterySVGs } from '../../helpers/cemeteries.helpers.js' import { getConfigProperty } from '../../helpers/config.helpers.js' -import { getMapSVGs } from '../../helpers/functions.map.js' export default async function handler( request: Request, response: Response ): Promise { - const map = await getMap(request.params.mapId) + const cemetery = await getCemetery(request.params.cemeteryId) - if (map === undefined) { + if (cemetery === undefined) { response.redirect( - `${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=mapIdNotFound` + `${getConfigProperty('reverseProxy.urlPrefix')}/cemeteries/?error=cemeteryIdNotFound` ) return } - const mapSVGs = await getMapSVGs() + const cemeterySVGs = await getCemeterySVGs() - const lotTypeSummary = await getLotTypeSummary({ - mapId: map.mapId + const burialSiteTypeSummary = await getBurialSiteTypeSummary({ + cemeteryId: cemetery.cemeteryId }) - const lotStatusSummary = await getLotStatusSummary({ - mapId: map.mapId + const burialSiteStatusSummary = await getBurialSiteStatusSummary({ + cemeteryId: cemetery.cemeteryId }) response.render('map-edit', { - headTitle: map.mapName, + headTitle: cemetery.cemeteryName, isCreate: false, - map, - mapSVGs, - lotTypeSummary, - lotStatusSummary + cemetery, + cemeterySVGs, + burialSiteTypeSummary, + burialSiteStatusSummary }) } diff --git a/handlers/cemeteries-get/new.js b/handlers/cemeteries-get/new.js index ff091619..fda2e6dd 100644 --- a/handlers/cemeteries-get/new.js +++ b/handlers/cemeteries-get/new.js @@ -1,15 +1,15 @@ +import { getCemeterySVGs } from '../../helpers/cemeteries.helpers.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; -import { getMapSVGs } from '../../helpers/functions.map.js'; export default async function handler(_request, response) { - const map = { - mapCity: getConfigProperty('settings.map.mapCityDefault'), - mapProvince: getConfigProperty('settings.map.mapProvinceDefault') + const cemetery = { + cemeteryCity: getConfigProperty('settings.cemeteries.cityDefault'), + cemeteryProvince: getConfigProperty('settings.cemeteries.provinceDefault') }; - const mapSVGs = await getMapSVGs(); + const cemeterySVGs = await getCemeterySVGs(); response.render('map-edit', { - headTitle: `${getConfigProperty('aliases.map')} Create`, + headTitle: `Create a Cemetery`, isCreate: true, - map, - mapSVGs + cemetery, + cemeterySVGs }); } diff --git a/handlers/cemeteries-get/new.ts b/handlers/cemeteries-get/new.ts index 6930f9d3..54fe94b2 100644 --- a/handlers/cemeteries-get/new.ts +++ b/handlers/cemeteries-get/new.ts @@ -1,24 +1,24 @@ import type { Request, Response } from 'express' +import { getCemeterySVGs } from '../../helpers/cemeteries.helpers.js' import { getConfigProperty } from '../../helpers/config.helpers.js' -import { getMapSVGs } from '../../helpers/functions.map.js' -import type { MapRecord } from '../../types/recordTypes.js' +import type { Cemetery } from '../../types/recordTypes.js' export default async function handler( _request: Request, response: Response ): Promise { - const map: MapRecord = { - mapCity: getConfigProperty('settings.map.mapCityDefault'), - mapProvince: getConfigProperty('settings.map.mapProvinceDefault') + const cemetery: Cemetery = { + cemeteryCity: getConfigProperty('settings.cemeteries.cityDefault'), + cemeteryProvince: getConfigProperty('settings.cemeteries.provinceDefault') } - const mapSVGs = await getMapSVGs() + const cemeterySVGs = await getCemeterySVGs() response.render('map-edit', { - headTitle: `${getConfigProperty('aliases.map')} Create`, + headTitle: `Create a Cemetery`, isCreate: true, - map, - mapSVGs + cemetery, + cemeterySVGs }) } diff --git a/handlers/cemeteries-get/next.js b/handlers/cemeteries-get/next.js index 1fe5922c..e8c9a0a2 100644 --- a/handlers/cemeteries-get/next.js +++ b/handlers/cemeteries-get/next.js @@ -1,11 +1,11 @@ -import getNextMapId from '../../database/getNextMapId.js'; +import getNextCemeteryId from '../../database/getNextCemeteryId.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(request, response) { - const mapId = Number.parseInt(request.params.mapId, 10); - const nextMapId = await getNextMapId(mapId); - if (nextMapId === undefined) { - response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=noNextMapIdFound`); + const cemeteryId = Number.parseInt(request.params.cemeteryId, 10); + const nextCemeteryId = await getNextCemeteryId(cemeteryId); + if (nextCemeteryId === undefined) { + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/cemeteries/?error=noNextCemeteryIdFound`); return; } - response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/${nextMapId.toString()}`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/cemeteries/${nextCemeteryId.toString()}`); } diff --git a/handlers/cemeteries-get/next.ts b/handlers/cemeteries-get/next.ts index 3e12d9be..5788c3d8 100644 --- a/handlers/cemeteries-get/next.ts +++ b/handlers/cemeteries-get/next.ts @@ -1,21 +1,21 @@ import type { Request, Response } from 'express' -import getNextMapId from '../../database/getNextMapId.js' +import getNextCemeteryId from '../../database/getNextCemeteryId.js' import { getConfigProperty } from '../../helpers/config.helpers.js' export default async function handler( request: Request, response: Response ): Promise { - const mapId = Number.parseInt(request.params.mapId, 10) + const cemeteryId = Number.parseInt(request.params.cemeteryId, 10) - const nextMapId = await getNextMapId(mapId) + const nextCemeteryId = await getNextCemeteryId(cemeteryId) - if (nextMapId === undefined) { + if (nextCemeteryId === undefined) { response.redirect( `${getConfigProperty( 'reverseProxy.urlPrefix' - )}/maps/?error=noNextMapIdFound` + )}/cemeteries/?error=noNextCemeteryIdFound` ) return } @@ -23,6 +23,6 @@ export default async function handler( response.redirect( `${getConfigProperty( 'reverseProxy.urlPrefix' - )}/maps/${nextMapId.toString()}` + )}/cemeteries/${nextCemeteryId.toString()}` ) } diff --git a/handlers/cemeteries-get/previous.js b/handlers/cemeteries-get/previous.js index 4037474f..763f8a0e 100644 --- a/handlers/cemeteries-get/previous.js +++ b/handlers/cemeteries-get/previous.js @@ -1,11 +1,11 @@ -import getPreviousMapId from '../../database/getPreviousMapId.js'; +import getPreviouscemeteryId from '../../database/getPreviouscemeteryId.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(request, response) { - const mapId = Number.parseInt(request.params.mapId, 10); - const previousMapId = await getPreviousMapId(mapId); - if (previousMapId === undefined) { - response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=noPreviousMapIdFound`); + const cemeteryId = Number.parseInt(request.params.cemeteryId, 10); + const previouscemeteryId = await getPreviouscemeteryId(cemeteryId); + if (previouscemeteryId === undefined) { + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=noPreviouscemeteryIdFound`); return; } - response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/${previousMapId.toString()}`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/${previouscemeteryId.toString()}`); } diff --git a/handlers/cemeteries-get/previous.ts b/handlers/cemeteries-get/previous.ts index ffa9de55..d5f3091b 100644 --- a/handlers/cemeteries-get/previous.ts +++ b/handlers/cemeteries-get/previous.ts @@ -1,21 +1,21 @@ import type { Request, Response } from 'express' -import getPreviousMapId from '../../database/getPreviousMapId.js' +import getPreviouscemeteryId from '../../database/getPreviouscemeteryId.js' import { getConfigProperty } from '../../helpers/config.helpers.js' export default async function handler( request: Request, response: Response ): Promise { - const mapId = Number.parseInt(request.params.mapId, 10) + const cemeteryId = Number.parseInt(request.params.cemeteryId, 10) - const previousMapId = await getPreviousMapId(mapId) + const previouscemeteryId = await getPreviouscemeteryId(cemeteryId) - if (previousMapId === undefined) { + if (previouscemeteryId === undefined) { response.redirect( `${getConfigProperty( 'reverseProxy.urlPrefix' - )}/maps/?error=noPreviousMapIdFound` + )}/maps/?error=noPreviouscemeteryIdFound` ) return } @@ -23,6 +23,6 @@ export default async function handler( response.redirect( `${getConfigProperty( 'reverseProxy.urlPrefix' - )}/maps/${previousMapId.toString()}` + )}/maps/${previouscemeteryId.toString()}` ) } diff --git a/handlers/cemeteries-get/search.js b/handlers/cemeteries-get/search.js index a1793296..99d10a35 100644 --- a/handlers/cemeteries-get/search.js +++ b/handlers/cemeteries-get/search.js @@ -1,9 +1,8 @@ -import getMaps from '../../database/getMaps.js'; -import { getConfigProperty } from '../../helpers/config.helpers.js'; +import getCemeteries from '../../database/getCemeteries.js'; export default async function handler(_request, response) { - const maps = await getMaps(); - response.render('map-search', { - headTitle: `${getConfigProperty('aliases.map')} Search`, - maps + const cemeteries = await getCemeteries(); + response.render('cemetery-search', { + headTitle: `Cemetery Search`, + cemeteries }); } diff --git a/handlers/cemeteries-get/search.ts b/handlers/cemeteries-get/search.ts index 60e3566a..dbb75a35 100644 --- a/handlers/cemeteries-get/search.ts +++ b/handlers/cemeteries-get/search.ts @@ -1,16 +1,15 @@ import type { Request, Response } from 'express' -import getMaps from '../../database/getMaps.js' -import { getConfigProperty } from '../../helpers/config.helpers.js' +import getCemeteries from '../../database/getCemeteries.js' export default async function handler( _request: Request, response: Response ): Promise { - const maps = await getMaps() + const cemeteries = await getCemeteries() - response.render('map-search', { - headTitle: `${getConfigProperty('aliases.map')} Search`, - maps + response.render('cemetery-search', { + headTitle: `Cemetery Search`, + cemeteries }) } diff --git a/handlers/cemeteries-get/view.js b/handlers/cemeteries-get/view.js index 2c2d7539..c44fec2f 100644 --- a/handlers/cemeteries-get/view.js +++ b/handlers/cemeteries-get/view.js @@ -3,19 +3,19 @@ import getLotTypeSummary from '../../database/getLotTypeSummary.js'; import getMap from '../../database/getMap.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(request, response) { - const map = await getMap(request.params.mapId); + const map = await getMap(request.params.cemeteryId); if (map === undefined) { - response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=mapIdNotFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=cemeteryIdNotFound`); return; } const lotTypeSummary = await getLotTypeSummary({ - mapId: map.mapId + cemeteryId: map.cemeteryId }); const lotStatusSummary = await getLotStatusSummary({ - mapId: map.mapId + cemeteryId: map.cemeteryId }); response.render('map-view', { - headTitle: map.mapName, + headTitle: map.cemeteryName, map, lotTypeSummary, lotStatusSummary diff --git a/handlers/cemeteries-get/view.ts b/handlers/cemeteries-get/view.ts index b44653e6..ca950958 100644 --- a/handlers/cemeteries-get/view.ts +++ b/handlers/cemeteries-get/view.ts @@ -9,25 +9,25 @@ export default async function handler( request: Request, response: Response ): Promise { - const map = await getMap(request.params.mapId) + const map = await getMap(request.params.cemeteryId) if (map === undefined) { response.redirect( - `${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=mapIdNotFound` + `${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=cemeteryIdNotFound` ) return } const lotTypeSummary = await getLotTypeSummary({ - mapId: map.mapId + cemeteryId: map.cemeteryId }) const lotStatusSummary = await getLotStatusSummary({ - mapId: map.mapId + cemeteryId: map.cemeteryId }) response.render('map-view', { - headTitle: map.mapName, + headTitle: map.cemeteryName, map, lotTypeSummary, lotStatusSummary diff --git a/handlers/cemeteries-post/doCreateCemetery.js b/handlers/cemeteries-post/doCreateCemetery.js index c0badffa..9761fc7d 100644 --- a/handlers/cemeteries-post/doCreateCemetery.js +++ b/handlers/cemeteries-post/doCreateCemetery.js @@ -1,8 +1,8 @@ import addMap from '../../database/addMap.js'; export default async function handler(request, response) { - const mapId = await addMap(request.body, request.session.user); + const cemeteryId = await addMap(request.body, request.session.user); response.json({ success: true, - mapId + cemeteryId }); } diff --git a/handlers/cemeteries-post/doCreateCemetery.ts b/handlers/cemeteries-post/doCreateCemetery.ts index 99406b77..a75cc7f9 100644 --- a/handlers/cemeteries-post/doCreateCemetery.ts +++ b/handlers/cemeteries-post/doCreateCemetery.ts @@ -6,14 +6,14 @@ export default async function handler( request: Request, response: Response ): Promise { - const mapId = await addMap( + const cemeteryId = await addMap( request.body as AddMapForm, request.session.user as User ) response.json({ success: true, - mapId + cemeteryId }) } diff --git a/handlers/cemeteries-post/doDeleteCemetery.js b/handlers/cemeteries-post/doDeleteCemetery.js index 36ddaa6a..bb3c4bea 100644 --- a/handlers/cemeteries-post/doDeleteCemetery.js +++ b/handlers/cemeteries-post/doDeleteCemetery.js @@ -1,11 +1,11 @@ -import { clearNextPreviousLotIdCache } from '../../helpers/functions.lots.js'; import { deleteRecord } from '../../database/deleteRecord.js'; +import { clearNextPreviousBurialSiteIdCache } from '../../helpers/burialSites.helpers.js'; export default async function handler(request, response) { - const success = await deleteRecord('Maps', request.body.mapId, request.session.user); + const success = await deleteRecord('Maps', request.body.cemeteryId, request.session.user); response.json({ success }); response.on('finish', () => { - clearNextPreviousLotIdCache(-1); + clearNextPreviousBurialSiteIdCache(-1); }); } diff --git a/handlers/cemeteries-post/doDeleteCemetery.ts b/handlers/cemeteries-post/doDeleteCemetery.ts index acba1a3c..610f9f1a 100644 --- a/handlers/cemeteries-post/doDeleteCemetery.ts +++ b/handlers/cemeteries-post/doDeleteCemetery.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express' -import { clearNextPreviousLotIdCache } from '../../helpers/functions.lots.js' import { deleteRecord } from '../../database/deleteRecord.js' +import { clearNextPreviousBurialSiteIdCache } from '../../helpers/burialSites.helpers.js' export default async function handler( request: Request, @@ -9,7 +9,7 @@ export default async function handler( ): Promise { const success = await deleteRecord( 'Maps', - request.body.mapId, + request.body.cemeteryId, request.session.user as User ) @@ -18,7 +18,7 @@ export default async function handler( }) response.on('finish', () => { - clearNextPreviousLotIdCache(-1) + clearNextPreviousBurialSiteIdCache(-1) }) } diff --git a/handlers/cemeteries-post/doUpdateMap.js b/handlers/cemeteries-post/doUpdateMap.js index 82329a4a..f25f92c6 100644 --- a/handlers/cemeteries-post/doUpdateMap.js +++ b/handlers/cemeteries-post/doUpdateMap.js @@ -3,6 +3,6 @@ export default async function handler(request, response) { const success = await updateMap(request.body, request.session.user); response.json({ success, - mapId: request.body.mapId + cemeteryId: request.body.cemeteryId }); } diff --git a/handlers/cemeteries-post/doUpdateMap.ts b/handlers/cemeteries-post/doUpdateMap.ts index 3c6651b3..1455be30 100644 --- a/handlers/cemeteries-post/doUpdateMap.ts +++ b/handlers/cemeteries-post/doUpdateMap.ts @@ -13,6 +13,6 @@ export default async function handler( response.json({ success, - mapId: request.body.mapId as string + cemeteryId: request.body.cemeteryId as string }) } diff --git a/handlers/contracts-get/edit.js b/handlers/contracts-get/edit.js index bee627d0..b34524b8 100644 --- a/handlers/contracts-get/edit.js +++ b/handlers/contracts-get/edit.js @@ -1,24 +1,24 @@ import getLotOccupancy from '../../database/getLotOccupancy.js'; import getMaps from '../../database/getMaps.js'; -import { getLotOccupantTypes, getLotStatuses, getLotTypes, getOccupancyTypePrintsById, getOccupancyTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js'; +import { getLotOccupantTypes, getLotStatuses, getBurialSiteTypes, getContractTypePrintsById, getContractTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(request, response) { - const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId); + const lotOccupancy = await getLotOccupancy(request.params.burialSiteContractId); if (lotOccupancy === undefined) { - response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lotOccupancies/?error=lotOccupancyIdNotFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lotOccupancies/?error=burialSiteContractIdNotFound`); return; } - const occupancyTypePrints = await getOccupancyTypePrintsById(lotOccupancy.occupancyTypeId); - const occupancyTypes = await getOccupancyTypes(); + const ContractTypePrints = await getContractTypePrintsById(lotOccupancy.contractTypeId); + const occupancyTypes = await getContractTypes(); const lotOccupantTypes = await getLotOccupantTypes(); - const lotTypes = await getLotTypes(); + const lotTypes = await getBurialSiteTypes(); const lotStatuses = await getLotStatuses(); const maps = await getMaps(); const workOrderTypes = await getWorkOrderTypes(); response.render('lotOccupancy-edit', { headTitle: `${getConfigProperty('aliases.occupancy')} Update`, lotOccupancy, - occupancyTypePrints, + ContractTypePrints, occupancyTypes, lotOccupantTypes, lotTypes, diff --git a/handlers/contracts-get/edit.ts b/handlers/contracts-get/edit.ts index 5b8830fc..eb371292 100644 --- a/handlers/contracts-get/edit.ts +++ b/handlers/contracts-get/edit.ts @@ -5,9 +5,9 @@ import getMaps from '../../database/getMaps.js' import { getLotOccupantTypes, getLotStatuses, - getLotTypes, - getOccupancyTypePrintsById, - getOccupancyTypes, + getBurialSiteTypes, + getContractTypePrintsById, + getContractTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js' import { getConfigProperty } from '../../helpers/config.helpers.js' @@ -16,24 +16,24 @@ export default async function handler( request: Request, response: Response ): Promise { - const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId) + const lotOccupancy = await getLotOccupancy(request.params.burialSiteContractId) if (lotOccupancy === undefined) { response.redirect( `${getConfigProperty( 'reverseProxy.urlPrefix' - )}/lotOccupancies/?error=lotOccupancyIdNotFound` + )}/lotOccupancies/?error=burialSiteContractIdNotFound` ) return } - const occupancyTypePrints = await getOccupancyTypePrintsById( - lotOccupancy.occupancyTypeId + const ContractTypePrints = await getContractTypePrintsById( + lotOccupancy.contractTypeId ) - const occupancyTypes = await getOccupancyTypes() + const occupancyTypes = await getContractTypes() const lotOccupantTypes = await getLotOccupantTypes() - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() const lotStatuses = await getLotStatuses() const maps = await getMaps() const workOrderTypes = await getWorkOrderTypes() @@ -41,7 +41,7 @@ export default async function handler( response.render('lotOccupancy-edit', { headTitle: `${getConfigProperty('aliases.occupancy')} Update`, lotOccupancy, - occupancyTypePrints, + ContractTypePrints, occupancyTypes, lotOccupantTypes, diff --git a/handlers/contracts-get/new.js b/handlers/contracts-get/new.js index 8f22d07a..6c58603c 100644 --- a/handlers/contracts-get/new.js +++ b/handlers/contracts-get/new.js @@ -1,26 +1,26 @@ import { dateToInteger, dateToString } from '@cityssm/utils-datetime'; import getLot from '../../database/getLot.js'; import getMaps from '../../database/getMaps.js'; -import { getLotOccupantTypes, getLotStatuses, getLotTypes, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getLotOccupantTypes, getLotStatuses, getBurialSiteTypes, getContractTypes } from '../../helpers/functions.cache.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(request, response) { const startDate = new Date(); const lotOccupancy = { - occupancyStartDate: dateToInteger(startDate), - occupancyStartDateString: dateToString(startDate) + contractStartDate: dateToInteger(startDate), + contractStartDateString: dateToString(startDate) }; if (request.query.lotId !== undefined) { const lot = await getLot(request.query.lotId); if (lot !== undefined) { lotOccupancy.lotId = lot.lotId; lotOccupancy.lotName = lot.lotName; - lotOccupancy.mapId = lot.mapId; - lotOccupancy.mapName = lot.mapName; + lotOccupancy.cemeteryId = lot.cemeteryId; + lotOccupancy.cemeteryName = lot.cemeteryName; } } - const occupancyTypes = await getOccupancyTypes(); + const occupancyTypes = await getContractTypes(); const lotOccupantTypes = await getLotOccupantTypes(); - const lotTypes = await getLotTypes(); + const lotTypes = await getBurialSiteTypes(); const lotStatuses = await getLotStatuses(); const maps = await getMaps(); response.render('lotOccupancy-edit', { diff --git a/handlers/contracts-get/new.ts b/handlers/contracts-get/new.ts index aa672696..ced7e3ac 100644 --- a/handlers/contracts-get/new.ts +++ b/handlers/contracts-get/new.ts @@ -6,8 +6,8 @@ import getMaps from '../../database/getMaps.js' import { getLotOccupantTypes, getLotStatuses, - getLotTypes, - getOccupancyTypes + getBurialSiteTypes, + getContractTypes } from '../../helpers/functions.cache.js' import { getConfigProperty } from '../../helpers/config.helpers.js' import type { LotOccupancy } from '../../types/recordTypes.js' @@ -19,8 +19,8 @@ export default async function handler( const startDate = new Date() const lotOccupancy: Partial = { - occupancyStartDate: dateToInteger(startDate), - occupancyStartDateString: dateToString(startDate) + contractStartDate: dateToInteger(startDate), + contractStartDateString: dateToString(startDate) } if (request.query.lotId !== undefined) { @@ -29,14 +29,14 @@ export default async function handler( if (lot !== undefined) { lotOccupancy.lotId = lot.lotId lotOccupancy.lotName = lot.lotName - lotOccupancy.mapId = lot.mapId - lotOccupancy.mapName = lot.mapName + lotOccupancy.cemeteryId = lot.cemeteryId + lotOccupancy.cemeteryName = lot.cemeteryName } } - const occupancyTypes = await getOccupancyTypes() + const occupancyTypes = await getContractTypes() const lotOccupantTypes = await getLotOccupantTypes() - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() const lotStatuses = await getLotStatuses() const maps = await getMaps() diff --git a/handlers/contracts-get/search.js b/handlers/contracts-get/search.js index 09a0732d..c057d8a0 100644 --- a/handlers/contracts-get/search.js +++ b/handlers/contracts-get/search.js @@ -1,15 +1,15 @@ import getMaps from '../../database/getMaps.js'; -import { getLotTypes, getOccupancyTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteTypes, getContractTypes } from '../../helpers/functions.cache.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(request, response) { const maps = await getMaps(); - const lotTypes = await getLotTypes(); - const occupancyTypes = await getOccupancyTypes(); + const lotTypes = await getBurialSiteTypes(); + const occupancyTypes = await getContractTypes(); response.render('lotOccupancy-search', { headTitle: `${getConfigProperty('aliases.occupancy')} Search`, maps, lotTypes, occupancyTypes, - mapId: request.query.mapId + cemeteryId: request.query.cemeteryId }); } diff --git a/handlers/contracts-get/search.ts b/handlers/contracts-get/search.ts index b259434b..31947652 100644 --- a/handlers/contracts-get/search.ts +++ b/handlers/contracts-get/search.ts @@ -2,8 +2,8 @@ import type { Request, Response } from 'express' import getMaps from '../../database/getMaps.js' import { - getLotTypes, - getOccupancyTypes + getBurialSiteTypes, + getContractTypes } from '../../helpers/functions.cache.js' import { getConfigProperty } from '../../helpers/config.helpers.js' @@ -12,14 +12,14 @@ export default async function handler( response: Response ): Promise { const maps = await getMaps() - const lotTypes = await getLotTypes() - const occupancyTypes = await getOccupancyTypes() + const lotTypes = await getBurialSiteTypes() + const occupancyTypes = await getContractTypes() response.render('lotOccupancy-search', { headTitle: `${getConfigProperty('aliases.occupancy')} Search`, maps, lotTypes, occupancyTypes, - mapId: request.query.mapId + cemeteryId: request.query.cemeteryId }) } diff --git a/handlers/contracts-get/view.js b/handlers/contracts-get/view.js index 7a6dd4d4..5aebc90c 100644 --- a/handlers/contracts-get/view.js +++ b/handlers/contracts-get/view.js @@ -1,16 +1,16 @@ import getLotOccupancy from '../../database/getLotOccupancy.js'; -import { getOccupancyTypePrintsById } from '../../helpers/functions.cache.js'; +import { getContractTypePrintsById } from '../../helpers/functions.cache.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(request, response) { - const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId); + const lotOccupancy = await getLotOccupancy(request.params.burialSiteContractId); if (lotOccupancy === undefined) { - response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lotOccupancies/?error=lotOccupancyIdNotFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lotOccupancies/?error=burialSiteContractIdNotFound`); return; } - const occupancyTypePrints = await getOccupancyTypePrintsById(lotOccupancy.occupancyTypeId); + const ContractTypePrints = await getContractTypePrintsById(lotOccupancy.contractTypeId); response.render('lotOccupancy-view', { headTitle: `${getConfigProperty('aliases.occupancy')} View`, lotOccupancy, - occupancyTypePrints + ContractTypePrints }); } diff --git a/handlers/contracts-get/view.ts b/handlers/contracts-get/view.ts index 5c8fe6b2..bb429d8b 100644 --- a/handlers/contracts-get/view.ts +++ b/handlers/contracts-get/view.ts @@ -1,31 +1,31 @@ import type { Request, Response } from 'express' import getLotOccupancy from '../../database/getLotOccupancy.js' -import { getOccupancyTypePrintsById } from '../../helpers/functions.cache.js' +import { getContractTypePrintsById } from '../../helpers/functions.cache.js' import { getConfigProperty } from '../../helpers/config.helpers.js' export default async function handler( request: Request, response: Response ): Promise { - const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId) + const lotOccupancy = await getLotOccupancy(request.params.burialSiteContractId) if (lotOccupancy === undefined) { response.redirect( `${getConfigProperty( 'reverseProxy.urlPrefix' - )}/lotOccupancies/?error=lotOccupancyIdNotFound` + )}/lotOccupancies/?error=burialSiteContractIdNotFound` ) return } - const occupancyTypePrints = await getOccupancyTypePrintsById( - lotOccupancy.occupancyTypeId + const ContractTypePrints = await getContractTypePrintsById( + lotOccupancy.contractTypeId ) response.render('lotOccupancy-view', { headTitle: `${getConfigProperty('aliases.occupancy')} View`, lotOccupancy, - occupancyTypePrints + ContractTypePrints }) } diff --git a/handlers/contracts-post/doAddLotOccupancyComment.js b/handlers/contracts-post/doAddLotOccupancyComment.js index c6a8d7fb..555a169d 100644 --- a/handlers/contracts-post/doAddLotOccupancyComment.js +++ b/handlers/contracts-post/doAddLotOccupancyComment.js @@ -2,7 +2,7 @@ import addLotOccupancyComment from '../../database/addLotOccupancyComment.js'; import getLotOccupancyComments from '../../database/getLotOccupancyComments.js'; export default async function handler(request, response) { await addLotOccupancyComment(request.body, request.session.user); - const lotOccupancyComments = await getLotOccupancyComments(request.body.lotOccupancyId); + const lotOccupancyComments = await getLotOccupancyComments(request.body.burialSiteContractId); response.json({ success: true, lotOccupancyComments diff --git a/handlers/contracts-post/doAddLotOccupancyComment.ts b/handlers/contracts-post/doAddLotOccupancyComment.ts index a5373a86..5250bc7f 100644 --- a/handlers/contracts-post/doAddLotOccupancyComment.ts +++ b/handlers/contracts-post/doAddLotOccupancyComment.ts @@ -15,7 +15,7 @@ export default async function handler( ) const lotOccupancyComments = await getLotOccupancyComments( - request.body.lotOccupancyId as string + request.body.burialSiteContractId as string ) response.json({ diff --git a/handlers/contracts-post/doAddLotOccupancyFee.js b/handlers/contracts-post/doAddLotOccupancyFee.js index bde811b7..d9460bfd 100644 --- a/handlers/contracts-post/doAddLotOccupancyFee.js +++ b/handlers/contracts-post/doAddLotOccupancyFee.js @@ -2,7 +2,7 @@ import addLotOccupancyFee from '../../database/addLotOccupancyFee.js'; import getLotOccupancyFees from '../../database/getLotOccupancyFees.js'; export default async function handler(request, response) { await addLotOccupancyFee(request.body, request.session.user); - const lotOccupancyFees = await getLotOccupancyFees(request.body.lotOccupancyId); + const lotOccupancyFees = await getLotOccupancyFees(request.body.burialSiteContractId); response.json({ success: true, lotOccupancyFees diff --git a/handlers/contracts-post/doAddLotOccupancyFee.ts b/handlers/contracts-post/doAddLotOccupancyFee.ts index 8c6ceb61..8c7bfecc 100644 --- a/handlers/contracts-post/doAddLotOccupancyFee.ts +++ b/handlers/contracts-post/doAddLotOccupancyFee.ts @@ -15,7 +15,7 @@ export default async function handler( ) const lotOccupancyFees = await getLotOccupancyFees( - request.body.lotOccupancyId as string + request.body.burialSiteContractId as string ) response.json({ diff --git a/handlers/contracts-post/doAddLotOccupancyFeeCategory.js b/handlers/contracts-post/doAddLotOccupancyFeeCategory.js index ea423a93..f153090f 100644 --- a/handlers/contracts-post/doAddLotOccupancyFeeCategory.js +++ b/handlers/contracts-post/doAddLotOccupancyFeeCategory.js @@ -2,7 +2,7 @@ import addLotOccupancyFeeCategory from '../../database/addLotOccupancyFeeCategor import getLotOccupancyFees from '../../database/getLotOccupancyFees.js'; export default async function handler(request, response) { await addLotOccupancyFeeCategory(request.body, request.session.user); - const lotOccupancyFees = await getLotOccupancyFees(request.body.lotOccupancyId); + const lotOccupancyFees = await getLotOccupancyFees(request.body.burialSiteContractId); response.json({ success: true, lotOccupancyFees diff --git a/handlers/contracts-post/doAddLotOccupancyFeeCategory.ts b/handlers/contracts-post/doAddLotOccupancyFeeCategory.ts index bdcf5cad..ebf8a3af 100644 --- a/handlers/contracts-post/doAddLotOccupancyFeeCategory.ts +++ b/handlers/contracts-post/doAddLotOccupancyFeeCategory.ts @@ -15,7 +15,7 @@ export default async function handler( ) const lotOccupancyFees = await getLotOccupancyFees( - request.body.lotOccupancyId as string + request.body.burialSiteContractId as string ) response.json({ diff --git a/handlers/contracts-post/doAddLotOccupancyOccupant.js b/handlers/contracts-post/doAddLotOccupancyOccupant.js index 5165f900..8c65347c 100644 --- a/handlers/contracts-post/doAddLotOccupancyOccupant.js +++ b/handlers/contracts-post/doAddLotOccupancyOccupant.js @@ -2,7 +2,7 @@ import addLotOccupancyOccupant from '../../database/addLotOccupancyOccupant.js'; import getLotOccupancyOccupants from '../../database/getLotOccupancyOccupants.js'; export default async function handler(request, response) { await addLotOccupancyOccupant(request.body, request.session.user); - const lotOccupancyOccupants = await getLotOccupancyOccupants(request.body.lotOccupancyId); + const lotOccupancyOccupants = await getLotOccupancyOccupants(request.body.burialSiteContractId); response.json({ success: true, lotOccupancyOccupants diff --git a/handlers/contracts-post/doAddLotOccupancyOccupant.ts b/handlers/contracts-post/doAddLotOccupancyOccupant.ts index a3fbc7f6..2e69a9b2 100644 --- a/handlers/contracts-post/doAddLotOccupancyOccupant.ts +++ b/handlers/contracts-post/doAddLotOccupancyOccupant.ts @@ -15,7 +15,7 @@ export default async function handler( ) const lotOccupancyOccupants = await getLotOccupancyOccupants( - request.body.lotOccupancyId + request.body.burialSiteContractId ) response.json({ diff --git a/handlers/contracts-post/doAddLotOccupancyTransaction.js b/handlers/contracts-post/doAddLotOccupancyTransaction.js index eaec4874..3cd2dd23 100644 --- a/handlers/contracts-post/doAddLotOccupancyTransaction.js +++ b/handlers/contracts-post/doAddLotOccupancyTransaction.js @@ -2,7 +2,7 @@ import addLotOccupancyTransaction from '../../database/addLotOccupancyTransactio import getLotOccupancyTransactions from '../../database/getLotOccupancyTransactions.js'; export default async function handler(request, response) { await addLotOccupancyTransaction(request.body, request.session.user); - const lotOccupancyTransactions = await getLotOccupancyTransactions(request.body.lotOccupancyId, { includeIntegrations: true }); + const lotOccupancyTransactions = await getLotOccupancyTransactions(request.body.burialSiteContractId, { includeIntegrations: true }); response.json({ success: true, lotOccupancyTransactions diff --git a/handlers/contracts-post/doAddLotOccupancyTransaction.ts b/handlers/contracts-post/doAddLotOccupancyTransaction.ts index 200d1e95..07f22669 100644 --- a/handlers/contracts-post/doAddLotOccupancyTransaction.ts +++ b/handlers/contracts-post/doAddLotOccupancyTransaction.ts @@ -15,7 +15,7 @@ export default async function handler( ) const lotOccupancyTransactions = await getLotOccupancyTransactions( - request.body.lotOccupancyId, + request.body.burialSiteContractId, { includeIntegrations: true } ) diff --git a/handlers/contracts-post/doCopyLotOccupancy.js b/handlers/contracts-post/doCopyLotOccupancy.js index 0ee4255b..e23b98e1 100644 --- a/handlers/contracts-post/doCopyLotOccupancy.js +++ b/handlers/contracts-post/doCopyLotOccupancy.js @@ -1,8 +1,8 @@ import copyLotOccupancy from '../../database/copyLotOccupancy.js'; export default async function handler(request, response) { - const lotOccupancyId = await copyLotOccupancy(request.body.lotOccupancyId, request.session.user); + const burialSiteContractId = await copyLotOccupancy(request.body.burialSiteContractId, request.session.user); response.json({ success: true, - lotOccupancyId + burialSiteContractId }); } diff --git a/handlers/contracts-post/doCopyLotOccupancy.ts b/handlers/contracts-post/doCopyLotOccupancy.ts index 03f65774..ac1b246d 100644 --- a/handlers/contracts-post/doCopyLotOccupancy.ts +++ b/handlers/contracts-post/doCopyLotOccupancy.ts @@ -6,14 +6,14 @@ export default async function handler( request: Request, response: Response ): Promise { - const lotOccupancyId = await copyLotOccupancy( - request.body.lotOccupancyId as string, + const burialSiteContractId = await copyLotOccupancy( + request.body.burialSiteContractId as string, request.session.user as User ) response.json({ success: true, - lotOccupancyId + burialSiteContractId }) } diff --git a/handlers/contracts-post/doCreateLotOccupancy.js b/handlers/contracts-post/doCreateLotOccupancy.js index a90d33f7..b5317be3 100644 --- a/handlers/contracts-post/doCreateLotOccupancy.js +++ b/handlers/contracts-post/doCreateLotOccupancy.js @@ -1,8 +1,8 @@ import addLotOccupancy from '../../database/addLotOccupancy.js'; export default async function handler(request, response) { - const lotOccupancyId = await addLotOccupancy(request.body, request.session.user); + const burialSiteContractId = await addLotOccupancy(request.body, request.session.user); response.json({ success: true, - lotOccupancyId + burialSiteContractId }); } diff --git a/handlers/contracts-post/doCreateLotOccupancy.ts b/handlers/contracts-post/doCreateLotOccupancy.ts index 0798538a..bd67e998 100644 --- a/handlers/contracts-post/doCreateLotOccupancy.ts +++ b/handlers/contracts-post/doCreateLotOccupancy.ts @@ -8,14 +8,14 @@ export default async function handler( request: Request, response: Response ): Promise { - const lotOccupancyId = await addLotOccupancy( + const burialSiteContractId = await addLotOccupancy( request.body as AddLotOccupancyForm, request.session.user as User ) response.json({ success: true, - lotOccupancyId + burialSiteContractId }) } diff --git a/handlers/contracts-post/doDeleteLotOccupancy.js b/handlers/contracts-post/doDeleteLotOccupancy.js index a493113b..043eb177 100644 --- a/handlers/contracts-post/doDeleteLotOccupancy.js +++ b/handlers/contracts-post/doDeleteLotOccupancy.js @@ -1,6 +1,6 @@ import { deleteRecord } from '../../database/deleteRecord.js'; export default async function handler(request, response) { - const success = await deleteRecord('LotOccupancies', request.body.lotOccupancyId, request.session.user); + const success = await deleteRecord('LotOccupancies', request.body.burialSiteContractId, request.session.user); response.json({ success }); diff --git a/handlers/contracts-post/doDeleteLotOccupancy.ts b/handlers/contracts-post/doDeleteLotOccupancy.ts index 202900cb..f9cc559b 100644 --- a/handlers/contracts-post/doDeleteLotOccupancy.ts +++ b/handlers/contracts-post/doDeleteLotOccupancy.ts @@ -8,7 +8,7 @@ export default async function handler( ): Promise { const success = await deleteRecord( 'LotOccupancies', - request.body.lotOccupancyId as string, + request.body.burialSiteContractId as string, request.session.user as User ) diff --git a/handlers/contracts-post/doDeleteLotOccupancyComment.js b/handlers/contracts-post/doDeleteLotOccupancyComment.js index 4bc6aa0b..fca2b3aa 100644 --- a/handlers/contracts-post/doDeleteLotOccupancyComment.js +++ b/handlers/contracts-post/doDeleteLotOccupancyComment.js @@ -1,8 +1,8 @@ import { deleteRecord } from '../../database/deleteRecord.js'; import getLotOccupancyComments from '../../database/getLotOccupancyComments.js'; export default async function handler(request, response) { - const success = await deleteRecord('LotOccupancyComments', request.body.lotOccupancyCommentId, request.session.user); - const lotOccupancyComments = await getLotOccupancyComments(request.body.lotOccupancyId); + const success = await deleteRecord('LotOccupancyComments', request.body.burialSiteContractCommentId, request.session.user); + const lotOccupancyComments = await getLotOccupancyComments(request.body.burialSiteContractId); response.json({ success, lotOccupancyComments diff --git a/handlers/contracts-post/doDeleteLotOccupancyComment.ts b/handlers/contracts-post/doDeleteLotOccupancyComment.ts index f659d774..eae11d96 100644 --- a/handlers/contracts-post/doDeleteLotOccupancyComment.ts +++ b/handlers/contracts-post/doDeleteLotOccupancyComment.ts @@ -9,12 +9,12 @@ export default async function handler( ): Promise { const success = await deleteRecord( 'LotOccupancyComments', - request.body.lotOccupancyCommentId as string, + request.body.burialSiteContractCommentId as string, request.session.user as User ) const lotOccupancyComments = await getLotOccupancyComments( - request.body.lotOccupancyId as string + request.body.burialSiteContractId as string ) response.json({ diff --git a/handlers/contracts-post/doDeleteLotOccupancyFee.js b/handlers/contracts-post/doDeleteLotOccupancyFee.js index a4ffea29..e2668451 100644 --- a/handlers/contracts-post/doDeleteLotOccupancyFee.js +++ b/handlers/contracts-post/doDeleteLotOccupancyFee.js @@ -1,8 +1,8 @@ import deleteLotOccupancyFee from '../../database/deleteLotOccupancyFee.js'; import getLotOccupancyFees from '../../database/getLotOccupancyFees.js'; export default async function handler(request, response) { - const success = await deleteLotOccupancyFee(request.body.lotOccupancyId, request.body.feeId, request.session.user); - const lotOccupancyFees = await getLotOccupancyFees(request.body.lotOccupancyId); + const success = await deleteLotOccupancyFee(request.body.burialSiteContractId, request.body.feeId, request.session.user); + const lotOccupancyFees = await getLotOccupancyFees(request.body.burialSiteContractId); response.json({ success, lotOccupancyFees diff --git a/handlers/contracts-post/doDeleteLotOccupancyFee.ts b/handlers/contracts-post/doDeleteLotOccupancyFee.ts index 2cb5b8bc..fac2b07b 100644 --- a/handlers/contracts-post/doDeleteLotOccupancyFee.ts +++ b/handlers/contracts-post/doDeleteLotOccupancyFee.ts @@ -8,13 +8,13 @@ export default async function handler( response: Response ): Promise { const success = await deleteLotOccupancyFee( - request.body.lotOccupancyId, + request.body.burialSiteContractId, request.body.feeId, request.session.user as User ) const lotOccupancyFees = await getLotOccupancyFees( - request.body.lotOccupancyId + request.body.burialSiteContractId ) response.json({ diff --git a/handlers/contracts-post/doDeleteLotOccupancyOccupant.js b/handlers/contracts-post/doDeleteLotOccupancyOccupant.js index 7650ad4f..9e0cecd4 100644 --- a/handlers/contracts-post/doDeleteLotOccupancyOccupant.js +++ b/handlers/contracts-post/doDeleteLotOccupancyOccupant.js @@ -1,8 +1,8 @@ import deleteLotOccupancyOccupant from '../../database/deleteLotOccupancyOccupant.js'; import getLotOccupancyOccupants from '../../database/getLotOccupancyOccupants.js'; export default async function handler(request, response) { - const success = await deleteLotOccupancyOccupant(request.body.lotOccupancyId, request.body.lotOccupantIndex, request.session.user); - const lotOccupancyOccupants = await getLotOccupancyOccupants(request.body.lotOccupancyId); + const success = await deleteLotOccupancyOccupant(request.body.burialSiteContractId, request.body.lotOccupantIndex, request.session.user); + const lotOccupancyOccupants = await getLotOccupancyOccupants(request.body.burialSiteContractId); response.json({ success, lotOccupancyOccupants diff --git a/handlers/contracts-post/doDeleteLotOccupancyOccupant.ts b/handlers/contracts-post/doDeleteLotOccupancyOccupant.ts index 967497f5..67321c7b 100644 --- a/handlers/contracts-post/doDeleteLotOccupancyOccupant.ts +++ b/handlers/contracts-post/doDeleteLotOccupancyOccupant.ts @@ -8,13 +8,13 @@ export default async function handler( response: Response ): Promise { const success = await deleteLotOccupancyOccupant( - request.body.lotOccupancyId, + request.body.burialSiteContractId, request.body.lotOccupantIndex, request.session.user as User ) const lotOccupancyOccupants = await getLotOccupancyOccupants( - request.body.lotOccupancyId + request.body.burialSiteContractId ) response.json({ diff --git a/handlers/contracts-post/doDeleteLotOccupancyTransaction.js b/handlers/contracts-post/doDeleteLotOccupancyTransaction.js index 2acf9bf4..7f8d2165 100644 --- a/handlers/contracts-post/doDeleteLotOccupancyTransaction.js +++ b/handlers/contracts-post/doDeleteLotOccupancyTransaction.js @@ -1,8 +1,8 @@ import deleteLotOccupancyTransaction from '../../database/deleteLotOccupancyTransaction.js'; import getLotOccupancyTransactions from '../../database/getLotOccupancyTransactions.js'; export default async function handler(request, response) { - const success = await deleteLotOccupancyTransaction(request.body.lotOccupancyId, request.body.transactionIndex, request.session.user); - const lotOccupancyTransactions = await getLotOccupancyTransactions(request.body.lotOccupancyId, { includeIntegrations: true }); + const success = await deleteLotOccupancyTransaction(request.body.burialSiteContractId, request.body.transactionIndex, request.session.user); + const lotOccupancyTransactions = await getLotOccupancyTransactions(request.body.burialSiteContractId, { includeIntegrations: true }); response.json({ success, lotOccupancyTransactions diff --git a/handlers/contracts-post/doDeleteLotOccupancyTransaction.ts b/handlers/contracts-post/doDeleteLotOccupancyTransaction.ts index 11e451ee..80870961 100644 --- a/handlers/contracts-post/doDeleteLotOccupancyTransaction.ts +++ b/handlers/contracts-post/doDeleteLotOccupancyTransaction.ts @@ -8,13 +8,13 @@ export default async function handler( response: Response ): Promise { const success = await deleteLotOccupancyTransaction( - request.body.lotOccupancyId, + request.body.burialSiteContractId, request.body.transactionIndex, request.session.user as User ) const lotOccupancyTransactions = await getLotOccupancyTransactions( - request.body.lotOccupancyId, + request.body.burialSiteContractId, { includeIntegrations: true } ) diff --git a/handlers/contracts-post/doGetFees.js b/handlers/contracts-post/doGetFees.js index dbcd85d3..ddf2ca72 100644 --- a/handlers/contracts-post/doGetFees.js +++ b/handlers/contracts-post/doGetFees.js @@ -1,11 +1,11 @@ import getFeeCategories from '../../database/getFeeCategories.js'; import getLotOccupancy from '../../database/getLotOccupancy.js'; export default async function handler(request, response) { - const lotOccupancyId = request.body.lotOccupancyId; - const lotOccupancy = (await getLotOccupancy(lotOccupancyId)); + const burialSiteContractId = request.body.burialSiteContractId; + const lotOccupancy = (await getLotOccupancy(burialSiteContractId)); const feeCategories = await getFeeCategories({ - occupancyTypeId: lotOccupancy.occupancyTypeId, - lotTypeId: lotOccupancy.lotTypeId + contractTypeId: lotOccupancy.contractTypeId, + burialSiteTypeId: lotOccupancy.burialSiteTypeId }, { includeFees: true }); diff --git a/handlers/contracts-post/doGetFees.ts b/handlers/contracts-post/doGetFees.ts index f6ee03f6..0260b31d 100644 --- a/handlers/contracts-post/doGetFees.ts +++ b/handlers/contracts-post/doGetFees.ts @@ -7,14 +7,14 @@ export default async function handler( request: Request, response: Response ): Promise { - const lotOccupancyId = request.body.lotOccupancyId + const burialSiteContractId = request.body.burialSiteContractId - const lotOccupancy = (await getLotOccupancy(lotOccupancyId))! + const lotOccupancy = (await getLotOccupancy(burialSiteContractId))! const feeCategories = await getFeeCategories( { - occupancyTypeId: lotOccupancy.occupancyTypeId, - lotTypeId: lotOccupancy.lotTypeId + contractTypeId: lotOccupancy.contractTypeId, + burialSiteTypeId: lotOccupancy.burialSiteTypeId }, { includeFees: true diff --git a/handlers/contracts-post/doGetOccupancyTypeFields.js b/handlers/contracts-post/doGetOccupancyTypeFields.js index 2813ec49..987f42eb 100644 --- a/handlers/contracts-post/doGetOccupancyTypeFields.js +++ b/handlers/contracts-post/doGetOccupancyTypeFields.js @@ -1,10 +1,10 @@ -import { getOccupancyTypeById, getAllOccupancyTypeFields } from '../../helpers/functions.cache.js'; +import { getContractTypeById, getAllContractTypeFields } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { - const allOccupancyTypeFields = await getAllOccupancyTypeFields(); - const result = (await getOccupancyTypeById(Number.parseInt(request.body.occupancyTypeId, 10))); - const occupancyTypeFields = [...allOccupancyTypeFields]; - occupancyTypeFields.push(...(result.occupancyTypeFields ?? [])); + const allContractTypeFields = await getAllContractTypeFields(); + const result = (await getContractTypeById(Number.parseInt(request.body.contractTypeId, 10))); + const ContractTypeFields = [...allContractTypeFields]; + ContractTypeFields.push(...(result.ContractTypeFields ?? [])); response.json({ - occupancyTypeFields + ContractTypeFields }); } diff --git a/handlers/contracts-post/doGetOccupancyTypeFields.ts b/handlers/contracts-post/doGetOccupancyTypeFields.ts index b85aaf57..928477fb 100644 --- a/handlers/contracts-post/doGetOccupancyTypeFields.ts +++ b/handlers/contracts-post/doGetOccupancyTypeFields.ts @@ -1,26 +1,26 @@ import type { Request, Response } from 'express' import { - getOccupancyTypeById, - getAllOccupancyTypeFields + getContractTypeById, + getAllContractTypeFields } from '../../helpers/functions.cache.js' export default async function handler( request: Request, response: Response ): Promise { - const allOccupancyTypeFields = await getAllOccupancyTypeFields() + const allContractTypeFields = await getAllContractTypeFields() - const result = (await getOccupancyTypeById( - Number.parseInt(request.body.occupancyTypeId, 10) + const result = (await getContractTypeById( + Number.parseInt(request.body.contractTypeId, 10) ))! - const occupancyTypeFields = [...allOccupancyTypeFields] + const ContractTypeFields = [...allContractTypeFields] - occupancyTypeFields.push(...(result.occupancyTypeFields ?? [])) + ContractTypeFields.push(...(result.ContractTypeFields ?? [])) response.json({ - occupancyTypeFields + ContractTypeFields }) } diff --git a/handlers/contracts-post/doSearchLotOccupancies.js b/handlers/contracts-post/doSearchLotOccupancies.js index 6ddf8460..97c2cad3 100644 --- a/handlers/contracts-post/doSearchLotOccupancies.js +++ b/handlers/contracts-post/doSearchLotOccupancies.js @@ -1,6 +1,6 @@ -import getLotOccupancies from '../../database/getLotOccupancies.js'; +import getBurialSiteContracts from '../../database/getLotOccupancies.js'; export default async function handler(request, response) { - const result = await getLotOccupancies(request.body, { + const result = await getBurialSiteContracts(request.body, { limit: request.body.limit, offset: request.body.offset, includeOccupants: true, diff --git a/handlers/contracts-post/doSearchLotOccupancies.ts b/handlers/contracts-post/doSearchLotOccupancies.ts index 06f2e44f..fcc9d503 100644 --- a/handlers/contracts-post/doSearchLotOccupancies.ts +++ b/handlers/contracts-post/doSearchLotOccupancies.ts @@ -1,12 +1,12 @@ import type { Request, Response } from 'express' -import getLotOccupancies from '../../database/getLotOccupancies.js' +import getBurialSiteContracts from '../../database/getLotOccupancies.js' export default async function handler( request: Request, response: Response ): Promise { - const result = await getLotOccupancies(request.body, { + const result = await getBurialSiteContracts(request.body, { limit: request.body.limit, offset: request.body.offset, includeOccupants: true, diff --git a/handlers/contracts-post/doUpdateLotOccupancy.js b/handlers/contracts-post/doUpdateLotOccupancy.js index db50ed17..4bee3138 100644 --- a/handlers/contracts-post/doUpdateLotOccupancy.js +++ b/handlers/contracts-post/doUpdateLotOccupancy.js @@ -3,6 +3,6 @@ export default async function handler(request, response) { const success = await updateLotOccupancy(request.body, request.session.user); response.json({ success, - lotOccupancyId: request.body.lotOccupancyId + burialSiteContractId: request.body.burialSiteContractId }); } diff --git a/handlers/contracts-post/doUpdateLotOccupancy.ts b/handlers/contracts-post/doUpdateLotOccupancy.ts index c8642c49..f534862c 100644 --- a/handlers/contracts-post/doUpdateLotOccupancy.ts +++ b/handlers/contracts-post/doUpdateLotOccupancy.ts @@ -15,6 +15,6 @@ export default async function handler( response.json({ success, - lotOccupancyId: request.body.lotOccupancyId as string + burialSiteContractId: request.body.burialSiteContractId as string }) } diff --git a/handlers/contracts-post/doUpdateLotOccupancyComment.js b/handlers/contracts-post/doUpdateLotOccupancyComment.js index 519d7f46..500b6404 100644 --- a/handlers/contracts-post/doUpdateLotOccupancyComment.js +++ b/handlers/contracts-post/doUpdateLotOccupancyComment.js @@ -2,7 +2,7 @@ import getLotOccupancyComments from '../../database/getLotOccupancyComments.js'; import updateLotOccupancyComment from '../../database/updateLotOccupancyComment.js'; export default async function handler(request, response) { const success = await updateLotOccupancyComment(request.body, request.session.user); - const lotOccupancyComments = await getLotOccupancyComments(request.body.lotOccupancyId); + const lotOccupancyComments = await getLotOccupancyComments(request.body.burialSiteContractId); response.json({ success, lotOccupancyComments diff --git a/handlers/contracts-post/doUpdateLotOccupancyComment.ts b/handlers/contracts-post/doUpdateLotOccupancyComment.ts index 3f8c6a8d..93661ae5 100644 --- a/handlers/contracts-post/doUpdateLotOccupancyComment.ts +++ b/handlers/contracts-post/doUpdateLotOccupancyComment.ts @@ -15,7 +15,7 @@ export default async function handler( ) const lotOccupancyComments = await getLotOccupancyComments( - request.body.lotOccupancyId as string + request.body.burialSiteContractId as string ) response.json({ diff --git a/handlers/contracts-post/doUpdateLotOccupancyFeeQuantity.js b/handlers/contracts-post/doUpdateLotOccupancyFeeQuantity.js index 10142361..f3f34832 100644 --- a/handlers/contracts-post/doUpdateLotOccupancyFeeQuantity.js +++ b/handlers/contracts-post/doUpdateLotOccupancyFeeQuantity.js @@ -2,7 +2,7 @@ import getLotOccupancyFees from '../../database/getLotOccupancyFees.js'; import updateLotOccupancyFeeQuantity from '../../database/updateLotOccupancyFeeQuantity.js'; export default async function handler(request, response) { const success = await updateLotOccupancyFeeQuantity(request.body, request.session.user); - const lotOccupancyFees = await getLotOccupancyFees(request.body.lotOccupancyId); + const lotOccupancyFees = await getLotOccupancyFees(request.body.burialSiteContractId); response.json({ success, lotOccupancyFees diff --git a/handlers/contracts-post/doUpdateLotOccupancyFeeQuantity.ts b/handlers/contracts-post/doUpdateLotOccupancyFeeQuantity.ts index fa4ff64f..63295481 100644 --- a/handlers/contracts-post/doUpdateLotOccupancyFeeQuantity.ts +++ b/handlers/contracts-post/doUpdateLotOccupancyFeeQuantity.ts @@ -15,7 +15,7 @@ export default async function handler( ) const lotOccupancyFees = await getLotOccupancyFees( - request.body.lotOccupancyId as string + request.body.burialSiteContractId as string ) response.json({ diff --git a/handlers/contracts-post/doUpdateLotOccupancyOccupant.js b/handlers/contracts-post/doUpdateLotOccupancyOccupant.js index d60ecc6b..9e4f0e52 100644 --- a/handlers/contracts-post/doUpdateLotOccupancyOccupant.js +++ b/handlers/contracts-post/doUpdateLotOccupancyOccupant.js @@ -2,7 +2,7 @@ import getLotOccupancyOccupants from '../../database/getLotOccupancyOccupants.js import updateLotOccupancyOccupant from '../../database/updateLotOccupancyOccupant.js'; export default async function handler(request, response) { const success = await updateLotOccupancyOccupant(request.body, request.session.user); - const lotOccupancyOccupants = await getLotOccupancyOccupants(request.body.lotOccupancyId); + const lotOccupancyOccupants = await getLotOccupancyOccupants(request.body.burialSiteContractId); response.json({ success, lotOccupancyOccupants diff --git a/handlers/contracts-post/doUpdateLotOccupancyOccupant.ts b/handlers/contracts-post/doUpdateLotOccupancyOccupant.ts index 302717eb..864d7b00 100644 --- a/handlers/contracts-post/doUpdateLotOccupancyOccupant.ts +++ b/handlers/contracts-post/doUpdateLotOccupancyOccupant.ts @@ -15,7 +15,7 @@ export default async function handler( ) const lotOccupancyOccupants = await getLotOccupancyOccupants( - request.body.lotOccupancyId as string + request.body.burialSiteContractId as string ) response.json({ diff --git a/handlers/contracts-post/doUpdateLotOccupancyTransaction.js b/handlers/contracts-post/doUpdateLotOccupancyTransaction.js index d9db05ce..2e52ee38 100644 --- a/handlers/contracts-post/doUpdateLotOccupancyTransaction.js +++ b/handlers/contracts-post/doUpdateLotOccupancyTransaction.js @@ -2,7 +2,7 @@ import getLotOccupancyTransactions from '../../database/getLotOccupancyTransacti import updateLotOccupancyTransaction from '../../database/updateLotOccupancyTransaction.js'; export default async function handler(request, response) { await updateLotOccupancyTransaction(request.body, request.session.user); - const lotOccupancyTransactions = await getLotOccupancyTransactions(request.body.lotOccupancyId, { includeIntegrations: true }); + const lotOccupancyTransactions = await getLotOccupancyTransactions(request.body.burialSiteContractId, { includeIntegrations: true }); response.json({ success: true, lotOccupancyTransactions diff --git a/handlers/contracts-post/doUpdateLotOccupancyTransaction.ts b/handlers/contracts-post/doUpdateLotOccupancyTransaction.ts index 17eb6697..b99ab78a 100644 --- a/handlers/contracts-post/doUpdateLotOccupancyTransaction.ts +++ b/handlers/contracts-post/doUpdateLotOccupancyTransaction.ts @@ -15,7 +15,7 @@ export default async function handler( ) const lotOccupancyTransactions = await getLotOccupancyTransactions( - request.body.lotOccupancyId as string, + request.body.burialSiteContractId as string, { includeIntegrations: true } ) diff --git a/handlers/dashboard-get/dashboard.js b/handlers/dashboard-get/dashboard.js index 23cf6237..620cd1aa 100644 --- a/handlers/dashboard-get/dashboard.js +++ b/handlers/dashboard-get/dashboard.js @@ -1,5 +1,5 @@ import { dateToString } from '@cityssm/utils-datetime'; -import getLotOccupancies from '../../database/getLotOccupancies.js'; +import getBurialSiteContracts from '../../database/getBurialSiteContracts.js'; import getWorkOrderMilestones from '../../database/getWorkOrderMilestones.js'; import { getWorkOrders } from '../../database/getWorkOrders.js'; export default async function handler(_request, response) { @@ -17,13 +17,13 @@ export default async function handler(_request, response) { limit: 1, // only using the count offset: 0 }); - const lotOccupancyResults = await getLotOccupancies({ - occupancyStartDateString: currentDateString + const lotOccupancyResults = await getBurialSiteContracts({ + contractStartDateString: currentDateString }, { limit: 1, // only using the count offset: 0, includeFees: false, - includeOccupants: false, + includeInterments: false, includeTransactions: false }); response.render('dashboard', { diff --git a/handlers/dashboard-get/dashboard.ts b/handlers/dashboard-get/dashboard.ts index fa90486e..0edfd447 100644 --- a/handlers/dashboard-get/dashboard.ts +++ b/handlers/dashboard-get/dashboard.ts @@ -1,7 +1,7 @@ import { dateToString } from '@cityssm/utils-datetime' import type { Request, Response } from 'express' -import getLotOccupancies from '../../database/getLotOccupancies.js' +import getBurialSiteContracts from '../../database/getBurialSiteContracts.js' import getWorkOrderMilestones from '../../database/getWorkOrderMilestones.js' import { getWorkOrders } from '../../database/getWorkOrders.js' @@ -32,15 +32,15 @@ export default async function handler( } ) - const lotOccupancyResults = await getLotOccupancies( + const lotOccupancyResults = await getBurialSiteContracts( { - occupancyStartDateString: currentDateString + contractStartDateString: currentDateString }, { limit: 1, // only using the count offset: 0, includeFees: false, - includeOccupants: false, + includeInterments: false, includeTransactions: false } ) diff --git a/handlers/reports-get/search.js b/handlers/reports-get/search.js index 09526ea5..75302174 100644 --- a/handlers/reports-get/search.js +++ b/handlers/reports-get/search.js @@ -1,10 +1,10 @@ import { dateToString } from '@cityssm/utils-datetime'; import getMaps from '../../database/getMaps.js'; -import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js'; +import { getLotStatuses, getBurialSiteTypes } from '../../helpers/functions.cache.js'; export default async function handler(_request, response) { const rightNow = new Date(); const maps = await getMaps(); - const lotTypes = await getLotTypes(); + const lotTypes = await getBurialSiteTypes(); const lotStatuses = await getLotStatuses(); response.render('report-search', { headTitle: 'Reports', diff --git a/handlers/reports-get/search.ts b/handlers/reports-get/search.ts index e22e3547..45c903ec 100644 --- a/handlers/reports-get/search.ts +++ b/handlers/reports-get/search.ts @@ -2,7 +2,7 @@ import { dateToString } from '@cityssm/utils-datetime' import type { Request, Response } from 'express' import getMaps from '../../database/getMaps.js' -import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js' +import { getLotStatuses, getBurialSiteTypes } from '../../helpers/functions.cache.js' export default async function handler( _request: Request, @@ -11,7 +11,7 @@ export default async function handler( const rightNow = new Date() const maps = await getMaps() - const lotTypes = await getLotTypes() + const lotTypes = await getBurialSiteTypes() const lotStatuses = await getLotStatuses() response.render('report-search', { diff --git a/handlers/workOrders-post/doAddWorkOrderLotOccupancy.js b/handlers/workOrders-post/doAddWorkOrderLotOccupancy.js index cb3633f6..478e0190 100644 --- a/handlers/workOrders-post/doAddWorkOrderLotOccupancy.js +++ b/handlers/workOrders-post/doAddWorkOrderLotOccupancy.js @@ -1,11 +1,11 @@ import addWorkOrderLotOccupancy from '../../database/addWorkOrderLotOccupancy.js'; -import getLotOccupancies from '../../database/getLotOccupancies.js'; +import getBurialSiteContracts from '../../database/getLotOccupancies.js'; export default async function handler(request, response) { const success = await addWorkOrderLotOccupancy({ workOrderId: request.body.workOrderId, - lotOccupancyId: request.body.lotOccupancyId + burialSiteContractId: request.body.burialSiteContractId }, request.session.user); - const workOrderLotOccupanciesResults = await getLotOccupancies({ + const workOrderLotOccupanciesResults = await getBurialSiteContracts({ workOrderId: request.body.workOrderId }, { limit: -1, diff --git a/handlers/workOrders-post/doAddWorkOrderLotOccupancy.ts b/handlers/workOrders-post/doAddWorkOrderLotOccupancy.ts index ce74552f..aa211c7d 100644 --- a/handlers/workOrders-post/doAddWorkOrderLotOccupancy.ts +++ b/handlers/workOrders-post/doAddWorkOrderLotOccupancy.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express' import addWorkOrderLotOccupancy from '../../database/addWorkOrderLotOccupancy.js' -import getLotOccupancies from '../../database/getLotOccupancies.js' +import getBurialSiteContracts from '../../database/getLotOccupancies.js' export default async function handler( request: Request, @@ -10,12 +10,12 @@ export default async function handler( const success = await addWorkOrderLotOccupancy( { workOrderId: request.body.workOrderId as string, - lotOccupancyId: request.body.lotOccupancyId as string + burialSiteContractId: request.body.burialSiteContractId as string }, request.session.user as User ) - const workOrderLotOccupanciesResults = await getLotOccupancies( + const workOrderLotOccupanciesResults = await getBurialSiteContracts( { workOrderId: request.body.workOrderId as string }, diff --git a/handlers/workOrders-post/doDeleteWorkOrderLotOccupancy.js b/handlers/workOrders-post/doDeleteWorkOrderLotOccupancy.js index a9eceede..902048e2 100644 --- a/handlers/workOrders-post/doDeleteWorkOrderLotOccupancy.js +++ b/handlers/workOrders-post/doDeleteWorkOrderLotOccupancy.js @@ -1,8 +1,8 @@ import deleteWorkOrderLotOccupancy from '../../database/deleteWorkOrderLotOccupancy.js'; -import getLotOccupancies from '../../database/getLotOccupancies.js'; +import getBurialSiteContracts from '../../database/getLotOccupancies.js'; export default async function handler(request, response) { - const success = await deleteWorkOrderLotOccupancy(request.body.workOrderId, request.body.lotOccupancyId, request.session.user); - const workOrderLotOccupancies = await getLotOccupancies({ + const success = await deleteWorkOrderLotOccupancy(request.body.workOrderId, request.body.burialSiteContractId, request.session.user); + const workOrderLotOccupancies = await getBurialSiteContracts({ workOrderId: request.body.workOrderId }, { limit: -1, diff --git a/handlers/workOrders-post/doDeleteWorkOrderLotOccupancy.ts b/handlers/workOrders-post/doDeleteWorkOrderLotOccupancy.ts index e6b82084..193a49fb 100644 --- a/handlers/workOrders-post/doDeleteWorkOrderLotOccupancy.ts +++ b/handlers/workOrders-post/doDeleteWorkOrderLotOccupancy.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express' import deleteWorkOrderLotOccupancy from '../../database/deleteWorkOrderLotOccupancy.js' -import getLotOccupancies from '../../database/getLotOccupancies.js' +import getBurialSiteContracts from '../../database/getLotOccupancies.js' export default async function handler( request: Request, @@ -9,11 +9,11 @@ export default async function handler( ): Promise { const success = await deleteWorkOrderLotOccupancy( request.body.workOrderId as string, - request.body.lotOccupancyId as string, + request.body.burialSiteContractId as string, request.session.user as User ) - const workOrderLotOccupancies = await getLotOccupancies( + const workOrderLotOccupancies = await getBurialSiteContracts( { workOrderId: request.body.workOrderId as string }, diff --git a/handlers/workOrders-post/doUpdateLotStatus.js b/handlers/workOrders-post/doUpdateLotStatus.js index f9d3570b..0dc16c1e 100644 --- a/handlers/workOrders-post/doUpdateLotStatus.js +++ b/handlers/workOrders-post/doUpdateLotStatus.js @@ -1,7 +1,7 @@ import getLots from '../../database/getLots.js'; import { updateLotStatus } from '../../database/updateLot.js'; export default async function handler(request, response) { - const success = await updateLotStatus(request.body.lotId, request.body.lotStatusId, request.session.user); + const success = await updateLotStatus(request.body.lotId, request.body.burialSiteStatusId, request.session.user); const workOrderLotsResults = await getLots({ workOrderId: request.body.workOrderId }, { diff --git a/handlers/workOrders-post/doUpdateLotStatus.ts b/handlers/workOrders-post/doUpdateLotStatus.ts index c6abf481..a3934972 100644 --- a/handlers/workOrders-post/doUpdateLotStatus.ts +++ b/handlers/workOrders-post/doUpdateLotStatus.ts @@ -9,7 +9,7 @@ export default async function handler( ): Promise { const success = await updateLotStatus( request.body.lotId as string, - request.body.lotStatusId as string, + request.body.burialSiteStatusId as string, request.session.user as User ) diff --git a/helpers/functions.cache.d.ts b/helpers/functions.cache.d.ts index dcbed2c2..9dacbfcc 100644 --- a/helpers/functions.cache.d.ts +++ b/helpers/functions.cache.d.ts @@ -1,18 +1,15 @@ -import type { LotOccupantType, LotStatus, LotType, OccupancyType, OccupancyTypeField, WorkOrderMilestoneType, WorkOrderType } from '../types/recordTypes.js'; -export declare function getLotOccupantTypes(): Promise; -export declare function getLotOccupantTypeById(lotOccupantTypeId: number): Promise; -export declare function getLotOccupantTypeByLotOccupantType(lotOccupantType: string): Promise; -export declare function getLotStatuses(): Promise; -export declare function getLotStatusById(lotStatusId: number): Promise; -export declare function getLotStatusByLotStatus(lotStatus: string): Promise; -export declare function getLotTypes(): Promise; -export declare function getLotTypeById(lotTypeId: number): Promise; -export declare function getLotTypesByLotType(lotType: string): Promise; -export declare function getOccupancyTypes(): Promise; -export declare function getAllOccupancyTypeFields(): Promise; -export declare function getOccupancyTypeById(occupancyTypeId: number): Promise; -export declare function getOccupancyTypeByOccupancyType(occupancyTypeString: string): Promise; -export declare function getOccupancyTypePrintsById(occupancyTypeId: number): Promise; +import type { BurialSiteStatus, BurialSiteType, ContractType, ContractTypeField, WorkOrderMilestoneType, WorkOrderType } from '../types/recordTypes.js'; +export declare function getBurialSiteStatuses(): Promise; +export declare function getBurialSiteStatusById(burialSiteStatusId: number): Promise; +export declare function getBurialSiteStatusByBurialSiteStatus(burialSiteStatus: string): Promise; +export declare function getBurialSiteTypes(): Promise; +export declare function getBurialSiteTypeById(burialSiteTypeId: number): Promise; +export declare function getBurialSiteTypesByBurialSiteType(burialSiteType: string): Promise; +export declare function getContractTypes(): Promise; +export declare function getAllContractTypeFields(): Promise; +export declare function getContractTypeById(contractTypeId: number): Promise; +export declare function getContractTypeByContractType(contractTypeString: string): Promise; +export declare function getContractTypePrintsById(contractTypeId: number): Promise; export declare function getWorkOrderTypes(): Promise; export declare function getWorkOrderTypeById(workOrderTypeId: number): Promise; export declare function getWorkOrderMilestoneTypes(): Promise; diff --git a/helpers/functions.cache.js b/helpers/functions.cache.js index 433fb644..bab645eb 100644 --- a/helpers/functions.cache.js +++ b/helpers/functions.cache.js @@ -2,124 +2,99 @@ /* eslint-disable @typescript-eslint/init-declarations */ import cluster from 'node:cluster'; import Debug from 'debug'; -import getLotOccupantTypesFromDatabase from '../database/getLotOccupantTypes.js'; -import getLotStatusesFromDatabase from '../database/getLotStatuses.js'; -import getLotTypesFromDatabase from '../database/getLotTypes.js'; -import getOccupancyTypeFieldsFromDatabase from '../database/getOccupancyTypeFields.js'; -import getOccupancyTypesFromDatabase from '../database/getOccupancyTypes.js'; +import getBurialSiteStatusesFromDatabase from '../database/getBurialSiteStatuses.js'; +import getBurialSiteTypesFromDatabase from '../database/getBurialSiteTypes.js'; +import getContractTypeFieldsFromDatabase from '../database/getContractTypeFields.js'; +import getContractTypesFromDatabase from '../database/getContractTypes.js'; import getWorkOrderMilestoneTypesFromDatabase from '../database/getWorkOrderMilestoneTypes.js'; import getWorkOrderTypesFromDatabase from '../database/getWorkOrderTypes.js'; import { DEBUG_NAMESPACE } from '../debug.config.js'; import { getConfigProperty } from './config.helpers.js'; const debug = Debug(`${DEBUG_NAMESPACE}:functions.cache:${process.pid}`); /* - * Lot Occupant Types + * Burial Site Statuses */ -let lotOccupantTypes; -export async function getLotOccupantTypes() { - if (lotOccupantTypes === undefined) { - lotOccupantTypes = await getLotOccupantTypesFromDatabase(); +let burialSiteStatuses; +export async function getBurialSiteStatuses() { + if (burialSiteStatuses === undefined) { + burialSiteStatuses = await getBurialSiteStatusesFromDatabase(); } - return lotOccupantTypes; + return burialSiteStatuses; } -export async function getLotOccupantTypeById(lotOccupantTypeId) { - const cachedLotOccupantTypes = await getLotOccupantTypes(); - return cachedLotOccupantTypes.find((currentLotOccupantType) => currentLotOccupantType.lotOccupantTypeId === lotOccupantTypeId); +export async function getBurialSiteStatusById(burialSiteStatusId) { + const cachedStatuses = await getBurialSiteStatuses(); + return cachedStatuses.find((currentStatus) => currentStatus.burialSiteStatusId === burialSiteStatusId); } -export async function getLotOccupantTypeByLotOccupantType(lotOccupantType) { - const cachedLotOccupantTypes = await getLotOccupantTypes(); - const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase(); - return cachedLotOccupantTypes.find((currentLotOccupantType) => currentLotOccupantType.lotOccupantType.toLowerCase() === - lotOccupantTypeLowerCase); +export async function getBurialSiteStatusByBurialSiteStatus(burialSiteStatus) { + const cachedStatuses = await getBurialSiteStatuses(); + const statusLowerCase = burialSiteStatus.toLowerCase(); + return cachedStatuses.find((currentStatus) => currentStatus.burialSiteStatus.toLowerCase() === statusLowerCase); } -function clearLotOccupantTypesCache() { - lotOccupantTypes = undefined; +function clearBurialSiteStatusesCache() { + burialSiteStatuses = undefined; } /* - * Lot Statuses + * Burial Site Types */ -let lotStatuses; -export async function getLotStatuses() { - if (lotStatuses === undefined) { - lotStatuses = await getLotStatusesFromDatabase(); +let burialSiteTypes; +export async function getBurialSiteTypes() { + if (burialSiteTypes === undefined) { + burialSiteTypes = await getBurialSiteTypesFromDatabase(); } - return lotStatuses; + return burialSiteTypes; } -export async function getLotStatusById(lotStatusId) { - const cachedLotStatuses = await getLotStatuses(); - return cachedLotStatuses.find((currentLotStatus) => currentLotStatus.lotStatusId === lotStatusId); +export async function getBurialSiteTypeById(burialSiteTypeId) { + const cachedTypes = await getBurialSiteTypes(); + return cachedTypes.find((currentType) => currentType.burialSiteTypeId === burialSiteTypeId); } -export async function getLotStatusByLotStatus(lotStatus) { - const cachedLotStatuses = await getLotStatuses(); - const lotStatusLowerCase = lotStatus.toLowerCase(); - return cachedLotStatuses.find((currentLotStatus) => currentLotStatus.lotStatus.toLowerCase() === lotStatusLowerCase); +export async function getBurialSiteTypesByBurialSiteType(burialSiteType) { + const cachedTypes = await getBurialSiteTypes(); + const typeLowerCase = burialSiteType.toLowerCase(); + return cachedTypes.find((currentType) => currentType.burialSiteType.toLowerCase() === typeLowerCase); } -function clearLotStatusesCache() { - lotStatuses = undefined; +function clearBurialSiteTypesCache() { + burialSiteTypes = undefined; } /* - * Lot Types + * Contract Types */ -let lotTypes; -export async function getLotTypes() { - if (lotTypes === undefined) { - lotTypes = await getLotTypesFromDatabase(); +let contractTypes; +let allContractTypeFields; +export async function getContractTypes() { + if (contractTypes === undefined) { + contractTypes = await getContractTypesFromDatabase(); } - return lotTypes; + return contractTypes; } -export async function getLotTypeById(lotTypeId) { - const cachedLotTypes = await getLotTypes(); - return cachedLotTypes.find((currentLotType) => currentLotType.lotTypeId === lotTypeId); -} -export async function getLotTypesByLotType(lotType) { - const cachedLotTypes = await getLotTypes(); - const lotTypeLowerCase = lotType.toLowerCase(); - return cachedLotTypes.find((currentLotType) => currentLotType.lotType.toLowerCase() === lotTypeLowerCase); -} -function clearLotTypesCache() { - lotTypes = undefined; -} -/* - * Occupancy Types - */ -let occupancyTypes; -let allOccupancyTypeFields; -export async function getOccupancyTypes() { - if (occupancyTypes === undefined) { - occupancyTypes = await getOccupancyTypesFromDatabase(); +export async function getAllContractTypeFields() { + if (allContractTypeFields === undefined) { + allContractTypeFields = await getContractTypeFieldsFromDatabase(); } - return occupancyTypes; + return allContractTypeFields; } -export async function getAllOccupancyTypeFields() { - if (allOccupancyTypeFields === undefined) { - allOccupancyTypeFields = await getOccupancyTypeFieldsFromDatabase(); - } - return allOccupancyTypeFields; +export async function getContractTypeById(contractTypeId) { + const cachedTypes = await getContractTypes(); + return cachedTypes.find((currentType) => currentType.contractTypeId === contractTypeId); } -export async function getOccupancyTypeById(occupancyTypeId) { - const cachedOccupancyTypes = await getOccupancyTypes(); - return cachedOccupancyTypes.find((currentOccupancyType) => currentOccupancyType.occupancyTypeId === occupancyTypeId); +export async function getContractTypeByContractType(contractTypeString) { + const cachedTypes = await getContractTypes(); + const typeLowerCase = contractTypeString.toLowerCase(); + return cachedTypes.find((currentType) => currentType.contractType.toLowerCase() === typeLowerCase); } -export async function getOccupancyTypeByOccupancyType(occupancyTypeString) { - const cachedOccupancyTypes = await getOccupancyTypes(); - const occupancyTypeLowerCase = occupancyTypeString.toLowerCase(); - return cachedOccupancyTypes.find((currentOccupancyType) => currentOccupancyType.occupancyType.toLowerCase() === - occupancyTypeLowerCase); -} -export async function getOccupancyTypePrintsById(occupancyTypeId) { - const occupancyType = await getOccupancyTypeById(occupancyTypeId); - if (occupancyType?.occupancyTypePrints === undefined || - occupancyType.occupancyTypePrints.length === 0) { +export async function getContractTypePrintsById(contractTypeId) { + const contractType = await getContractTypeById(contractTypeId); + if (contractType?.contractTypePrints === undefined || + contractType.contractTypePrints.length === 0) { return []; } - if (occupancyType.occupancyTypePrints.includes('*')) { - return getConfigProperty('settings.lotOccupancy.prints'); + if (contractType.contractTypePrints.includes('*')) { + return getConfigProperty('settings.contracts.prints'); } - return occupancyType.occupancyTypePrints ?? []; + return contractType.contractTypePrints ?? []; } -function clearOccupancyTypesCache() { - occupancyTypes = undefined; - allOccupancyTypeFields = undefined; +function clearContractTypesCache() { + contractTypes = undefined; + allContractTypeFields = undefined; } /* * Work Order Types @@ -161,18 +136,16 @@ export async function getWorkOrderMilestoneTypeByWorkOrderMilestoneType(workOrde } export async function preloadCaches() { debug('Preloading caches'); - await getLotOccupantTypes(); - await getLotStatuses(); - await getLotTypes(); - await getOccupancyTypes(); + await getBurialSiteStatuses(); + await getBurialSiteTypes(); + await getContractTypes(); await getWorkOrderTypes(); await getWorkOrderMilestoneTypes(); } export function clearCaches() { - clearLotOccupantTypesCache(); - clearLotStatusesCache(); - clearLotTypesCache(); - clearOccupancyTypesCache(); + clearBurialSiteStatusesCache(); + clearBurialSiteTypesCache(); + clearContractTypesCache(); clearWorkOrderTypesCache(); clearWorkOrderMilestoneTypesCache(); } @@ -181,23 +154,19 @@ function clearWorkOrderMilestoneTypesCache() { } export function clearCacheByTableName(tableName, relayMessage = true) { switch (tableName) { - case 'LotOccupantTypes': { - clearLotOccupantTypesCache(); + case 'BurialSiteStatuses': { + clearBurialSiteStatusesCache(); break; } - case 'LotStatuses': { - clearLotStatusesCache(); + case 'BurialSiteTypes': + case 'BurialSiteTypeFields': { + clearBurialSiteTypesCache(); break; } - case 'LotTypes': - case 'LotTypeFields': { - clearLotTypesCache(); - break; - } - case 'OccupancyTypes': - case 'OccupancyTypeFields': - case 'OccupancyTypePrints': { - clearOccupancyTypesCache(); + case 'ContractTypes': + case 'ContractTypeFields': + case 'ContractTypePrints': { + clearContractTypesCache(); break; } case 'WorkOrderMilestoneTypes': { diff --git a/helpers/functions.cache.ts b/helpers/functions.cache.ts index b266c27e..c6a257c6 100644 --- a/helpers/functions.cache.ts +++ b/helpers/functions.cache.ts @@ -5,11 +5,10 @@ import cluster from 'node:cluster' import Debug from 'debug' -import getLotOccupantTypesFromDatabase from '../database/getLotOccupantTypes.js' -import getLotStatusesFromDatabase from '../database/getLotStatuses.js' -import getLotTypesFromDatabase from '../database/getLotTypes.js' -import getOccupancyTypeFieldsFromDatabase from '../database/getOccupancyTypeFields.js' -import getOccupancyTypesFromDatabase from '../database/getOccupancyTypes.js' +import getBurialSiteStatusesFromDatabase from '../database/getBurialSiteStatuses.js' +import getBurialSiteTypesFromDatabase from '../database/getBurialSiteTypes.js' +import getContractTypeFieldsFromDatabase from '../database/getContractTypeFields.js' +import getContractTypesFromDatabase from '../database/getContractTypes.js' import getWorkOrderMilestoneTypesFromDatabase from '../database/getWorkOrderMilestoneTypes.js' import getWorkOrderTypesFromDatabase from '../database/getWorkOrderTypes.js' import { DEBUG_NAMESPACE } from '../debug.config.js' @@ -18,11 +17,10 @@ import type { WorkerMessage } from '../types/applicationTypes.js' import type { - LotOccupantType, - LotStatus, - LotType, - OccupancyType, - OccupancyTypeField, + BurialSiteStatus, + BurialSiteType, + ContractType, + ContractTypeField, WorkOrderMilestoneType, WorkOrderType } from '../types/recordTypes.js' @@ -32,201 +30,152 @@ import { getConfigProperty } from './config.helpers.js' const debug = Debug(`${DEBUG_NAMESPACE}:functions.cache:${process.pid}`) /* - * Lot Occupant Types + * Burial Site Statuses */ -let lotOccupantTypes: LotOccupantType[] | undefined +let burialSiteStatuses: BurialSiteStatus[] | undefined -export async function getLotOccupantTypes(): Promise { - if (lotOccupantTypes === undefined) { - lotOccupantTypes = await getLotOccupantTypesFromDatabase() +export async function getBurialSiteStatuses(): Promise { + if (burialSiteStatuses === undefined) { + burialSiteStatuses = await getBurialSiteStatusesFromDatabase() } - return lotOccupantTypes + return burialSiteStatuses } -export async function getLotOccupantTypeById( - lotOccupantTypeId: number -): Promise { - const cachedLotOccupantTypes = await getLotOccupantTypes() +export async function getBurialSiteStatusById( + burialSiteStatusId: number +): Promise { + const cachedStatuses = await getBurialSiteStatuses() - return cachedLotOccupantTypes.find( - (currentLotOccupantType) => - currentLotOccupantType.lotOccupantTypeId === lotOccupantTypeId + return cachedStatuses.find( + (currentStatus) => currentStatus.burialSiteStatusId === burialSiteStatusId ) } -export async function getLotOccupantTypeByLotOccupantType( - lotOccupantType: string -): Promise { - const cachedLotOccupantTypes = await getLotOccupantTypes() +export async function getBurialSiteStatusByBurialSiteStatus( + burialSiteStatus: string +): Promise { + const cachedStatuses = await getBurialSiteStatuses() - const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase() + const statusLowerCase = burialSiteStatus.toLowerCase() - return cachedLotOccupantTypes.find( - (currentLotOccupantType) => - currentLotOccupantType.lotOccupantType.toLowerCase() === - lotOccupantTypeLowerCase + return cachedStatuses.find( + (currentStatus) => + currentStatus.burialSiteStatus.toLowerCase() === statusLowerCase ) } -function clearLotOccupantTypesCache(): void { - lotOccupantTypes = undefined +function clearBurialSiteStatusesCache(): void { + burialSiteStatuses = undefined } /* - * Lot Statuses + * Burial Site Types */ -let lotStatuses: LotStatus[] | undefined +let burialSiteTypes: BurialSiteType[] | undefined -export async function getLotStatuses(): Promise { - if (lotStatuses === undefined) { - lotStatuses = await getLotStatusesFromDatabase() +export async function getBurialSiteTypes(): Promise { + if (burialSiteTypes === undefined) { + burialSiteTypes = await getBurialSiteTypesFromDatabase() } - return lotStatuses + return burialSiteTypes } -export async function getLotStatusById( - lotStatusId: number -): Promise { - const cachedLotStatuses = await getLotStatuses() +export async function getBurialSiteTypeById( + burialSiteTypeId: number +): Promise { + const cachedTypes = await getBurialSiteTypes() - return cachedLotStatuses.find( - (currentLotStatus) => currentLotStatus.lotStatusId === lotStatusId + return cachedTypes.find( + (currentType) => currentType.burialSiteTypeId === burialSiteTypeId ) } -export async function getLotStatusByLotStatus( - lotStatus: string -): Promise { - const cachedLotStatuses = await getLotStatuses() +export async function getBurialSiteTypesByBurialSiteType( + burialSiteType: string +): Promise { + const cachedTypes = await getBurialSiteTypes() - const lotStatusLowerCase = lotStatus.toLowerCase() + const typeLowerCase = burialSiteType.toLowerCase() - return cachedLotStatuses.find( - (currentLotStatus) => - currentLotStatus.lotStatus.toLowerCase() === lotStatusLowerCase + return cachedTypes.find( + (currentType) => currentType.burialSiteType.toLowerCase() === typeLowerCase ) } -function clearLotStatusesCache(): void { - lotStatuses = undefined +function clearBurialSiteTypesCache(): void { + burialSiteTypes = undefined } /* - * Lot Types + * Contract Types */ -let lotTypes: LotType[] | undefined +let contractTypes: ContractType[] | undefined +let allContractTypeFields: ContractTypeField[] | undefined -export async function getLotTypes(): Promise { - if (lotTypes === undefined) { - lotTypes = await getLotTypesFromDatabase() +export async function getContractTypes(): Promise { + if (contractTypes === undefined) { + contractTypes = await getContractTypesFromDatabase() } - return lotTypes + return contractTypes } -export async function getLotTypeById( - lotTypeId: number -): Promise { - const cachedLotTypes = await getLotTypes() - - return cachedLotTypes.find( - (currentLotType) => currentLotType.lotTypeId === lotTypeId - ) -} - -export async function getLotTypesByLotType( - lotType: string -): Promise { - const cachedLotTypes = await getLotTypes() - - const lotTypeLowerCase = lotType.toLowerCase() - - return cachedLotTypes.find( - (currentLotType) => - currentLotType.lotType.toLowerCase() === lotTypeLowerCase - ) -} - -function clearLotTypesCache(): void { - lotTypes = undefined -} - -/* - * Occupancy Types - */ - -let occupancyTypes: OccupancyType[] | undefined -let allOccupancyTypeFields: OccupancyTypeField[] | undefined - -export async function getOccupancyTypes(): Promise { - if (occupancyTypes === undefined) { - occupancyTypes = await getOccupancyTypesFromDatabase() +export async function getAllContractTypeFields(): Promise { + if (allContractTypeFields === undefined) { + allContractTypeFields = await getContractTypeFieldsFromDatabase() } - - return occupancyTypes + return allContractTypeFields } -export async function getAllOccupancyTypeFields(): Promise< - OccupancyTypeField[] -> { - if (allOccupancyTypeFields === undefined) { - allOccupancyTypeFields = await getOccupancyTypeFieldsFromDatabase() - } - return allOccupancyTypeFields -} +export async function getContractTypeById( + contractTypeId: number +): Promise { + const cachedTypes = await getContractTypes() -export async function getOccupancyTypeById( - occupancyTypeId: number -): Promise { - const cachedOccupancyTypes = await getOccupancyTypes() - - return cachedOccupancyTypes.find( - (currentOccupancyType) => - currentOccupancyType.occupancyTypeId === occupancyTypeId + return cachedTypes.find( + (currentType) => currentType.contractTypeId === contractTypeId ) } -export async function getOccupancyTypeByOccupancyType( - occupancyTypeString: string -): Promise { - const cachedOccupancyTypes = await getOccupancyTypes() +export async function getContractTypeByContractType( + contractTypeString: string +): Promise { + const cachedTypes = await getContractTypes() - const occupancyTypeLowerCase = occupancyTypeString.toLowerCase() + const typeLowerCase = contractTypeString.toLowerCase() - return cachedOccupancyTypes.find( - (currentOccupancyType) => - currentOccupancyType.occupancyType.toLowerCase() === - occupancyTypeLowerCase + return cachedTypes.find( + (currentType) => currentType.contractType.toLowerCase() === typeLowerCase ) } -export async function getOccupancyTypePrintsById( - occupancyTypeId: number +export async function getContractTypePrintsById( + contractTypeId: number ): Promise { - const occupancyType = await getOccupancyTypeById(occupancyTypeId) + const contractType = await getContractTypeById(contractTypeId) if ( - occupancyType?.occupancyTypePrints === undefined || - occupancyType.occupancyTypePrints.length === 0 + contractType?.contractTypePrints === undefined || + contractType.contractTypePrints.length === 0 ) { return [] } - if (occupancyType.occupancyTypePrints.includes('*')) { - return getConfigProperty('settings.lotOccupancy.prints') + if (contractType.contractTypePrints.includes('*')) { + return getConfigProperty('settings.contracts.prints') } - return occupancyType.occupancyTypePrints ?? [] + return contractType.contractTypePrints ?? [] } -function clearOccupancyTypesCache(): void { - occupancyTypes = undefined - allOccupancyTypeFields = undefined +function clearContractTypesCache(): void { + contractTypes = undefined + allContractTypeFields = undefined } /* @@ -303,19 +252,17 @@ export async function getWorkOrderMilestoneTypeByWorkOrderMilestoneType( export async function preloadCaches(): Promise { debug('Preloading caches') - await getLotOccupantTypes() - await getLotStatuses() - await getLotTypes() - await getOccupancyTypes() + await getBurialSiteStatuses() + await getBurialSiteTypes() + await getContractTypes() await getWorkOrderTypes() await getWorkOrderMilestoneTypes() } export function clearCaches(): void { - clearLotOccupantTypesCache() - clearLotStatusesCache() - clearLotTypesCache() - clearOccupancyTypesCache() + clearBurialSiteStatusesCache() + clearBurialSiteTypesCache() + clearContractTypesCache() clearWorkOrderTypesCache() clearWorkOrderMilestoneTypesCache() } @@ -329,26 +276,21 @@ export function clearCacheByTableName( relayMessage = true ): void { switch (tableName) { - case 'LotOccupantTypes': { - clearLotOccupantTypesCache() + case 'BurialSiteStatuses': { + clearBurialSiteStatusesCache() break } - case 'LotStatuses': { - clearLotStatusesCache() + case 'BurialSiteTypes': + case 'BurialSiteTypeFields': { + clearBurialSiteTypesCache() break } - case 'LotTypes': - case 'LotTypeFields': { - clearLotTypesCache() - break - } - - case 'OccupancyTypes': - case 'OccupancyTypeFields': - case 'OccupancyTypePrints': { - clearOccupancyTypesCache() + case 'ContractTypes': + case 'ContractTypeFields': + case 'ContractTypePrints': { + clearContractTypesCache() break } diff --git a/helpers/functions.print.js b/helpers/functions.print.js index 73a1d94b..c6a38192 100644 --- a/helpers/functions.print.js +++ b/helpers/functions.print.js @@ -7,7 +7,7 @@ import * as lotOccupancyFunctions from './functions.lotOccupancy.js'; const screenPrintConfigs = { lotOccupancy: { title: `${configFunctions.getConfigProperty('aliases.lot')} ${configFunctions.getConfigProperty('aliases.occupancy')} Print`, - params: ['lotOccupancyId'] + params: ['burialSiteContractId'] } }; export function getScreenPrintConfig(printName) { @@ -25,11 +25,11 @@ const pdfPrintConfigs = { // Occupancy 'ssm.cemetery.burialPermit': { title: 'Burial Permit', - params: ['lotOccupancyId'] + params: ['burialSiteContractId'] }, 'ssm.cemetery.contract': { title: 'Contract for Purchase of Interment Rights', - params: ['lotOccupancyId'] + params: ['burialSiteContractId'] } }; export function getPdfPrintConfig(printName) { @@ -54,9 +54,9 @@ export async function getReportData(printConfig, requestQuery) { dateTimeFunctions, lotOccupancyFunctions }; - if (printConfig.params.includes('lotOccupancyId') && - typeof requestQuery.lotOccupancyId === 'string') { - const lotOccupancy = await getLotOccupancy(requestQuery.lotOccupancyId); + if (printConfig.params.includes('burialSiteContractId') && + typeof requestQuery.burialSiteContractId === 'string') { + const lotOccupancy = await getLotOccupancy(requestQuery.burialSiteContractId); if (lotOccupancy !== undefined && (lotOccupancy.lotId ?? -1) !== -1) { reportData.lot = await getLot(lotOccupancy.lotId ?? -1); } diff --git a/helpers/functions.print.ts b/helpers/functions.print.ts index 020aacb3..7d3eed81 100644 --- a/helpers/functions.print.ts +++ b/helpers/functions.print.ts @@ -30,7 +30,7 @@ const screenPrintConfigs: Record = { title: `${configFunctions.getConfigProperty( 'aliases.lot' )} ${configFunctions.getConfigProperty('aliases.occupancy')} Print`, - params: ['lotOccupancyId'] + params: ['burialSiteContractId'] } } @@ -53,11 +53,11 @@ const pdfPrintConfigs: Record = { // Occupancy 'ssm.cemetery.burialPermit': { title: 'Burial Permit', - params: ['lotOccupancyId'] + params: ['burialSiteContractId'] }, 'ssm.cemetery.contract': { title: 'Contract for Purchase of Interment Rights', - params: ['lotOccupancyId'] + params: ['burialSiteContractId'] } } @@ -94,10 +94,10 @@ export async function getReportData( } if ( - printConfig.params.includes('lotOccupancyId') && - typeof requestQuery.lotOccupancyId === 'string' + printConfig.params.includes('burialSiteContractId') && + typeof requestQuery.burialSiteContractId === 'string' ) { - const lotOccupancy = await getLotOccupancy(requestQuery.lotOccupancyId) + const lotOccupancy = await getLotOccupancy(requestQuery.burialSiteContractId) if (lotOccupancy !== undefined && (lotOccupancy.lotId ?? -1) !== -1) { reportData.lot = await getLot(lotOccupancy.lotId ?? -1) diff --git a/helpers/functions.sqlFilters.js b/helpers/functions.sqlFilters.js index 64b70632..a453c20c 100644 --- a/helpers/functions.sqlFilters.js +++ b/helpers/functions.sqlFilters.js @@ -39,20 +39,20 @@ export function getOccupancyTimeWhereClause(occupancyTime, lotOccupanciesTableAl const currentDateString = dateToInteger(new Date()); switch (occupancyTime ?? '') { case 'current': { - sqlWhereClause += ` and ${lotOccupanciesTableAlias}.occupancyStartDate <= ? - and (${lotOccupanciesTableAlias}.occupancyEndDate is null or ${lotOccupanciesTableAlias}.occupancyEndDate >= ?)`; + sqlWhereClause += ` and ${lotOccupanciesTableAlias}.contractStartDate <= ? + and (${lotOccupanciesTableAlias}.contractEndDate is null or ${lotOccupanciesTableAlias}.contractEndDate >= ?)`; sqlParameters.push(currentDateString, currentDateString); break; } case 'past': { sqlWhereClause += - ` and ${lotOccupanciesTableAlias}.occupancyEndDate < ?`; + ` and ${lotOccupanciesTableAlias}.contractEndDate < ?`; sqlParameters.push(currentDateString); break; } case 'future': { sqlWhereClause += - ` and ${lotOccupanciesTableAlias}.occupancyStartDate > ?`; + ` and ${lotOccupanciesTableAlias}.contractStartDate > ?`; sqlParameters.push(currentDateString); break; } diff --git a/helpers/functions.sqlFilters.ts b/helpers/functions.sqlFilters.ts index 52f90211..164424b5 100644 --- a/helpers/functions.sqlFilters.ts +++ b/helpers/functions.sqlFilters.ts @@ -65,22 +65,22 @@ export function getOccupancyTimeWhereClause( switch (occupancyTime ?? '') { case 'current': { - sqlWhereClause += ` and ${lotOccupanciesTableAlias}.occupancyStartDate <= ? - and (${lotOccupanciesTableAlias}.occupancyEndDate is null or ${lotOccupanciesTableAlias}.occupancyEndDate >= ?)` + sqlWhereClause += ` and ${lotOccupanciesTableAlias}.contractStartDate <= ? + and (${lotOccupanciesTableAlias}.contractEndDate is null or ${lotOccupanciesTableAlias}.contractEndDate >= ?)` sqlParameters.push(currentDateString, currentDateString) break } case 'past': { sqlWhereClause += - ` and ${lotOccupanciesTableAlias}.occupancyEndDate < ?` + ` and ${lotOccupanciesTableAlias}.contractEndDate < ?` sqlParameters.push(currentDateString) break } case 'future': { sqlWhereClause += - ` and ${lotOccupanciesTableAlias}.occupancyStartDate > ?` + ` and ${lotOccupanciesTableAlias}.contractStartDate > ?` sqlParameters.push(currentDateString) break } diff --git a/public/html/adminFees-addFee.html b/public/html/adminFees-addFee.html index 1846f226..f2b4c755 100644 --- a/public/html/adminFees-addFee.html +++ b/public/html/adminFees-addFee.html @@ -93,12 +93,12 @@
-
-
diff --git a/public/html/adminFees-editFee.html b/public/html/adminFees-editFee.html index 8e0e4e12..abd3e407 100644 --- a/public/html/adminFees-editFee.html +++ b/public/html/adminFees-editFee.html @@ -94,12 +94,12 @@
-
-
diff --git a/public/html/adminLotTypes-addLotTypeField.html b/public/html/adminLotTypes-addLotTypeField.html index 0b74879b..86885c95 100644 --- a/public/html/adminLotTypes-addLotTypeField.html +++ b/public/html/adminLotTypes-addLotTypeField.html @@ -15,8 +15,8 @@
diff --git a/public/html/adminLotTypes-editLotType.html b/public/html/adminLotTypes-editLotType.html index fe397856..539bed95 100644 --- a/public/html/adminLotTypes-editLotType.html +++ b/public/html/adminLotTypes-editLotType.html @@ -15,8 +15,8 @@
diff --git a/public/html/lot-editLotStatus.html b/public/html/lot-editLotStatus.html index 03bc2e50..fbc3f270 100644 --- a/public/html/lot-editLotStatus.html +++ b/public/html/lot-editLotStatus.html @@ -28,10 +28,10 @@
- +
-
diff --git a/public/html/lotOccupancy-selectLot.html b/public/html/lotOccupancy-selectLot.html index ca5acdb4..1ba4f12a 100644 --- a/public/html/lotOccupancy-selectLot.html +++ b/public/html/lotOccupancy-selectLot.html @@ -93,14 +93,14 @@
-
+
diff --git a/public/html/workOrder-addLot.html b/public/html/workOrder-addLot.html index b64a1fcb..37c37571 100644 --- a/public/html/workOrder-addLot.html +++ b/public/html/workOrder-addLot.html @@ -45,10 +45,10 @@
- +
-
diff --git a/public/javascripts/adminFees.js b/public/javascripts/adminFees.js index 6206f7d5..cbb80585 100644 --- a/public/javascripts/adminFees.js +++ b/public/javascripts/adminFees.js @@ -85,7 +85,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); panelBlockElement.dataset.feeId = fee.feeId.toString(); const hasTagsBlock = (fee.isRequired ?? false) || fee.occupancyTypeId !== undefined || - fee.lotTypeId !== undefined; + fee.burialSiteTypeId !== undefined; // eslint-disable-next-line no-unsanitized/property panelBlockElement.innerHTML = `
@@ -110,7 +110,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); ${cityssm.escapeHTML(fee.occupancyType ?? '')} `} - ${(fee.lotTypeId ?? -1) === -1 + ${(fee.burialSiteTypeId ?? -1) === -1 ? '' : ` @@ -351,10 +351,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); optionElement.textContent = occupancyType.occupancyType; occupancyTypeElement.append(optionElement); } - const lotTypeElement = modalElement.querySelector('#feeAdd--lotTypeId'); + const lotTypeElement = modalElement.querySelector('#feeAdd--burialSiteTypeId'); for (const lotType of exports.lotTypes) { const optionElement = document.createElement('option'); - optionElement.value = lotType.lotTypeId.toString(); + optionElement.value = lotType.burialSiteTypeId.toString(); optionElement.textContent = lotType.lotType; lotTypeElement.append(optionElement); } @@ -576,12 +576,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); } occupancyTypeElement.append(optionElement); } - const lotTypeElement = modalElement.querySelector('#feeEdit--lotTypeId'); + const lotTypeElement = modalElement.querySelector('#feeEdit--burialSiteTypeId'); for (const lotType of exports.lotTypes) { const optionElement = document.createElement('option'); - optionElement.value = lotType.lotTypeId.toString(); + optionElement.value = lotType.burialSiteTypeId.toString(); optionElement.textContent = lotType.lotType; - if (lotType.lotTypeId === fee.lotTypeId) { + if (lotType.burialSiteTypeId === fee.burialSiteTypeId) { optionElement.selected = true; } lotTypeElement.append(optionElement); diff --git a/public/javascripts/adminFees.ts b/public/javascripts/adminFees.ts index f75a647b..a039527a 100644 --- a/public/javascripts/adminFees.ts +++ b/public/javascripts/adminFees.ts @@ -142,8 +142,8 @@ declare const exports: Record const hasTagsBlock = (fee.isRequired ?? false) || - fee.occupancyTypeId !== undefined || - fee.lotTypeId !== undefined + fee.contractTypeId !== undefined || + fee.burialSiteTypeId !== undefined // eslint-disable-next-line no-unsanitized/property panelBlockElement.innerHTML = `
@@ -168,7 +168,7 @@ declare const exports: Record : '' } ${ - (fee.occupancyTypeId ?? -1) === -1 + (fee.contractTypeId ?? -1) === -1 ? '' : ` @@ -176,7 +176,7 @@ declare const exports: Record ` } ${ - (fee.lotTypeId ?? -1) === -1 + (fee.burialSiteTypeId ?? -1) === -1 ? '' : ` @@ -543,23 +543,23 @@ declare const exports: Record } const occupancyTypeElement = modalElement.querySelector( - '#feeAdd--occupancyTypeId' + '#feeAdd--contractTypeId' ) as HTMLSelectElement for (const occupancyType of exports.occupancyTypes as OccupancyType[]) { const optionElement = document.createElement('option') - optionElement.value = occupancyType.occupancyTypeId.toString() + optionElement.value = occupancyType.contractTypeId.toString() optionElement.textContent = occupancyType.occupancyType occupancyTypeElement.append(optionElement) } const lotTypeElement = modalElement.querySelector( - '#feeAdd--lotTypeId' + '#feeAdd--burialSiteTypeId' ) as HTMLSelectElement for (const lotType of exports.lotTypes as LotType[]) { const optionElement = document.createElement('option') - optionElement.value = lotType.lotTypeId.toString() + optionElement.value = lotType.burialSiteTypeId.toString() optionElement.textContent = lotType.lotType lotTypeElement.append(optionElement) } @@ -907,15 +907,15 @@ declare const exports: Record ).value = fee.feeDescription ?? '' const occupancyTypeElement = modalElement.querySelector( - '#feeEdit--occupancyTypeId' + '#feeEdit--contractTypeId' ) as HTMLSelectElement for (const occupancyType of exports.occupancyTypes as OccupancyType[]) { const optionElement = document.createElement('option') - optionElement.value = occupancyType.occupancyTypeId.toString() + optionElement.value = occupancyType.contractTypeId.toString() optionElement.textContent = occupancyType.occupancyType - if (occupancyType.occupancyTypeId === fee.occupancyTypeId) { + if (occupancyType.contractTypeId === fee.contractTypeId) { optionElement.selected = true } @@ -923,15 +923,15 @@ declare const exports: Record } const lotTypeElement = modalElement.querySelector( - '#feeEdit--lotTypeId' + '#feeEdit--burialSiteTypeId' ) as HTMLSelectElement for (const lotType of exports.lotTypes as LotType[]) { const optionElement = document.createElement('option') - optionElement.value = lotType.lotTypeId.toString() + optionElement.value = lotType.burialSiteTypeId.toString() optionElement.textContent = lotType.lotType - if (lotType.lotTypeId === fee.lotTypeId) { + if (lotType.burialSiteTypeId === fee.burialSiteTypeId) { optionElement.selected = true } diff --git a/public/javascripts/adminLotTypes.js b/public/javascripts/adminLotTypes.js index 9d010815..64db0de5 100644 --- a/public/javascripts/adminLotTypes.js +++ b/public/javascripts/adminLotTypes.js @@ -9,15 +9,15 @@ Object.defineProperty(exports, "__esModule", { value: true }); function toggleLotTypeFields(clickEvent) { const toggleButtonElement = clickEvent.currentTarget; const lotTypeElement = toggleButtonElement.closest('.container--lotType'); - const lotTypeId = Number.parseInt(lotTypeElement.dataset.lotTypeId ?? '', 10); - if (expandedLotTypes.has(lotTypeId)) { - expandedLotTypes.delete(lotTypeId); + const burialSiteTypeId = Number.parseInt(lotTypeElement.dataset.burialSiteTypeId ?? '', 10); + if (expandedLotTypes.has(burialSiteTypeId)) { + expandedLotTypes.delete(burialSiteTypeId); } else { - expandedLotTypes.add(lotTypeId); + expandedLotTypes.add(burialSiteTypeId); } // eslint-disable-next-line no-unsanitized/property - toggleButtonElement.innerHTML = expandedLotTypes.has(lotTypeId) + toggleButtonElement.innerHTML = expandedLotTypes.has(burialSiteTypeId) ? '' : ''; const panelBlockElements = lotTypeElement.querySelectorAll('.panel-block'); @@ -40,10 +40,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); } } function deleteLotType(clickEvent) { - const lotTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.lotTypeId ?? '', 10); + const burialSiteTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.burialSiteTypeId ?? '', 10); function doDelete() { cityssm.postJSON(`${los.urlPrefix}/admin/doDeleteLotType`, { - lotTypeId + burialSiteTypeId }, lotTypeResponseHandler); } bulmaJS.confirm({ @@ -57,8 +57,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); }); } function openEditLotType(clickEvent) { - const lotTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.lotTypeId ?? '', 10); - const lotType = lotTypes.find((currentLotType) => lotTypeId === currentLotType.lotTypeId); + const burialSiteTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.burialSiteTypeId ?? '', 10); + const lotType = lotTypes.find((currentLotType) => burialSiteTypeId === currentLotType.burialSiteTypeId); let editCloseModalFunction; function doEdit(submitEvent) { submitEvent.preventDefault(); @@ -73,7 +73,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); cityssm.openHtmlModal('adminLotTypes-editLotType', { onshow(modalElement) { los.populateAliases(modalElement); - modalElement.querySelector('#lotTypeEdit--lotTypeId').value = lotTypeId.toString(); + modalElement.querySelector('#lotTypeEdit--burialSiteTypeId').value = burialSiteTypeId.toString(); modalElement.querySelector('#lotTypeEdit--lotType').value = lotType.lotType; }, onshown(modalElement, closeModalFunction) { @@ -88,26 +88,26 @@ Object.defineProperty(exports, "__esModule", { value: true }); }); } function openAddLotTypeField(clickEvent) { - const lotTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.lotTypeId ?? '', 10); + const burialSiteTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.burialSiteTypeId ?? '', 10); let addCloseModalFunction; function doAdd(submitEvent) { submitEvent.preventDefault(); cityssm.postJSON(`${los.urlPrefix}/admin/doAddLotTypeField`, submitEvent.currentTarget, (rawResponseJSON) => { const responseJSON = rawResponseJSON; - expandedLotTypes.add(lotTypeId); + expandedLotTypes.add(burialSiteTypeId); lotTypeResponseHandler(responseJSON); if (responseJSON.success) { addCloseModalFunction(); - openEditLotTypeField(lotTypeId, responseJSON.lotTypeFieldId); + openEditLotTypeField(burialSiteTypeId, responseJSON.lotTypeFieldId); } }); } cityssm.openHtmlModal('adminLotTypes-addLotTypeField', { onshow(modalElement) { los.populateAliases(modalElement); - if (lotTypeId) { + if (burialSiteTypeId) { ; - modalElement.querySelector('#lotTypeFieldAdd--lotTypeId').value = lotTypeId.toString(); + modalElement.querySelector('#lotTypeFieldAdd--burialSiteTypeId').value = burialSiteTypeId.toString(); } }, onshown(modalElement, closeModalFunction) { @@ -123,16 +123,16 @@ Object.defineProperty(exports, "__esModule", { value: true }); } function moveLotType(clickEvent) { const buttonElement = clickEvent.currentTarget; - const lotTypeId = buttonElement.closest('.container--lotType').dataset.lotTypeId; + const burialSiteTypeId = buttonElement.closest('.container--lotType').dataset.burialSiteTypeId; cityssm.postJSON(`${los.urlPrefix}/admin/${buttonElement.dataset.direction === 'up' ? 'doMoveLotTypeUp' : 'doMoveLotTypeDown'}`, { - lotTypeId, + burialSiteTypeId, moveToEnd: clickEvent.shiftKey ? '1' : '0' }, lotTypeResponseHandler); } - function openEditLotTypeField(lotTypeId, lotTypeFieldId) { - const lotType = lotTypes.find((currentLotType) => currentLotType.lotTypeId === lotTypeId); + function openEditLotTypeField(burialSiteTypeId, lotTypeFieldId) { + const lotType = lotTypes.find((currentLotType) => currentLotType.burialSiteTypeId === burialSiteTypeId); const lotTypeField = (lotType.lotTypeFields ?? []).find((currentLotTypeField) => currentLotTypeField.lotTypeFieldId === lotTypeFieldId); let fieldTypeElement; let minimumLengthElement; @@ -242,8 +242,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); function openEditLotTypeFieldByClick(clickEvent) { clickEvent.preventDefault(); const lotTypeFieldId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotTypeField').dataset.lotTypeFieldId ?? '', 10); - const lotTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.lotTypeId ?? '', 10); - openEditLotTypeField(lotTypeId, lotTypeFieldId); + const burialSiteTypeId = Number.parseInt(clickEvent.currentTarget.closest('.container--lotType').dataset.burialSiteTypeId ?? '', 10); + openEditLotTypeField(burialSiteTypeId, lotTypeFieldId); } function moveLotTypeField(clickEvent) { const buttonElement = clickEvent.currentTarget; @@ -255,11 +255,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); moveToEnd: clickEvent.shiftKey ? '1' : '0' }, lotTypeResponseHandler); } - function renderLotTypeFields(panelElement, lotTypeId, lotTypeFields) { + function renderLotTypeFields(panelElement, burialSiteTypeId, lotTypeFields) { if (lotTypeFields.length === 0) { // eslint-disable-next-line no-unsanitized/method panelElement.insertAdjacentHTML('beforeend', `
+ ${expandedLotTypes.has(burialSiteTypeId) ? '' : ' is-hidden'}">

There are no additional fields.

`); } @@ -268,7 +268,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const panelBlockElement = document.createElement('div'); panelBlockElement.className = 'panel-block is-block container--lotTypeField'; - if (!expandedLotTypes.has(lotTypeId)) { + if (!expandedLotTypes.has(burialSiteTypeId)) { panelBlockElement.classList.add('is-hidden'); } panelBlockElement.dataset.lotTypeFieldId = @@ -309,14 +309,14 @@ Object.defineProperty(exports, "__esModule", { value: true }); for (const lotType of lotTypes) { const lotTypeContainer = document.createElement('div'); lotTypeContainer.className = 'panel container--lotType'; - lotTypeContainer.dataset.lotTypeId = lotType.lotTypeId.toString(); + lotTypeContainer.dataset.burialSiteTypeId = lotType.burialSiteTypeId.toString(); // eslint-disable-next-line no-unsanitized/property lotTypeContainer.innerHTML = `
@@ -350,7 +350,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
`; - renderLotTypeFields(lotTypeContainer, lotType.lotTypeId, lotType.lotTypeFields ?? []); + renderLotTypeFields(lotTypeContainer, lotType.burialSiteTypeId, lotType.lotTypeFields ?? []); lotTypeContainer .querySelector('.button--toggleLotTypeFields') ?.addEventListener('click', toggleLotTypeFields); diff --git a/public/javascripts/adminLotTypes.ts b/public/javascripts/adminLotTypes.ts index a3f1f41a..5b06f8c4 100644 --- a/public/javascripts/adminLotTypes.ts +++ b/public/javascripts/adminLotTypes.ts @@ -31,26 +31,26 @@ type ResponseJSON = const expandedLotTypes = new Set() - function toggleLotTypeFields(clickEvent: Event): void { + function toggleBurialSiteTypeFields(clickEvent: Event): void { const toggleButtonElement = clickEvent.currentTarget as HTMLButtonElement const lotTypeElement = toggleButtonElement.closest( '.container--lotType' ) as HTMLElement - const lotTypeId = Number.parseInt( - lotTypeElement.dataset.lotTypeId ?? '', + const burialSiteTypeId = Number.parseInt( + lotTypeElement.dataset.burialSiteTypeId ?? '', 10 ) - if (expandedLotTypes.has(lotTypeId)) { - expandedLotTypes.delete(lotTypeId) + if (expandedLotTypes.has(burialSiteTypeId)) { + expandedLotTypes.delete(burialSiteTypeId) } else { - expandedLotTypes.add(lotTypeId) + expandedLotTypes.add(burialSiteTypeId) } // eslint-disable-next-line no-unsanitized/property - toggleButtonElement.innerHTML = expandedLotTypes.has(lotTypeId) + toggleButtonElement.innerHTML = expandedLotTypes.has(burialSiteTypeId) ? '' : '' @@ -78,12 +78,12 @@ type ResponseJSON = } function deleteLotType(clickEvent: Event): void { - const lotTypeId = Number.parseInt( + const burialSiteTypeId = Number.parseInt( ( (clickEvent.currentTarget as HTMLElement).closest( '.container--lotType' ) as HTMLElement - ).dataset.lotTypeId ?? '', + ).dataset.burialSiteTypeId ?? '', 10 ) @@ -91,7 +91,7 @@ type ResponseJSON = cityssm.postJSON( `${los.urlPrefix}/admin/doDeleteLotType`, { - lotTypeId + burialSiteTypeId }, lotTypeResponseHandler ) @@ -109,17 +109,17 @@ type ResponseJSON = } function openEditLotType(clickEvent: Event): void { - const lotTypeId = Number.parseInt( + const burialSiteTypeId = Number.parseInt( ( (clickEvent.currentTarget as HTMLElement).closest( '.container--lotType' ) as HTMLElement - ).dataset.lotTypeId ?? '', + ).dataset.burialSiteTypeId ?? '', 10 ) const lotType = lotTypes.find( - (currentLotType) => lotTypeId === currentLotType.lotTypeId + (currentLotType) => burialSiteTypeId === currentLotType.burialSiteTypeId ) as LotType let editCloseModalFunction: () => void @@ -146,9 +146,9 @@ type ResponseJSON = los.populateAliases(modalElement) ;( modalElement.querySelector( - '#lotTypeEdit--lotTypeId' + '#lotTypeEdit--burialSiteTypeId' ) as HTMLInputElement - ).value = lotTypeId.toString() + ).value = burialSiteTypeId.toString() ;( modalElement.querySelector( '#lotTypeEdit--lotType' @@ -174,12 +174,12 @@ type ResponseJSON = } function openAddLotTypeField(clickEvent: Event): void { - const lotTypeId = Number.parseInt( + const burialSiteTypeId = Number.parseInt( ( (clickEvent.currentTarget as HTMLElement).closest( '.container--lotType' ) as HTMLElement - ).dataset.lotTypeId ?? '', + ).dataset.burialSiteTypeId ?? '', 10 ) @@ -194,13 +194,13 @@ type ResponseJSON = (rawResponseJSON) => { const responseJSON = rawResponseJSON as ResponseJSON - expandedLotTypes.add(lotTypeId) + expandedLotTypes.add(burialSiteTypeId) lotTypeResponseHandler(responseJSON) if (responseJSON.success) { addCloseModalFunction() openEditLotTypeField( - lotTypeId, + burialSiteTypeId, responseJSON.lotTypeFieldId as number ) } @@ -212,12 +212,12 @@ type ResponseJSON = onshow(modalElement) { los.populateAliases(modalElement) - if (lotTypeId) { + if (burialSiteTypeId) { ;( modalElement.querySelector( - '#lotTypeFieldAdd--lotTypeId' + '#lotTypeFieldAdd--burialSiteTypeId' ) as HTMLInputElement - ).value = lotTypeId.toString() + ).value = burialSiteTypeId.toString() } }, onshown(modalElement, closeModalFunction) { @@ -241,9 +241,9 @@ type ResponseJSON = function moveLotType(clickEvent: MouseEvent): void { const buttonElement = clickEvent.currentTarget as HTMLButtonElement - const lotTypeId = ( + const burialSiteTypeId = ( buttonElement.closest('.container--lotType') as HTMLElement - ).dataset.lotTypeId + ).dataset.burialSiteTypeId cityssm.postJSON( `${los.urlPrefix}/admin/${ @@ -252,7 +252,7 @@ type ResponseJSON = : 'doMoveLotTypeDown' }`, { - lotTypeId, + burialSiteTypeId, moveToEnd: clickEvent.shiftKey ? '1' : '0' }, lotTypeResponseHandler @@ -260,14 +260,14 @@ type ResponseJSON = } function openEditLotTypeField( - lotTypeId: number, + burialSiteTypeId: number, lotTypeFieldId: number ): void { const lotType = lotTypes.find( - (currentLotType) => currentLotType.lotTypeId === lotTypeId + (currentLotType) => currentLotType.burialSiteTypeId === burialSiteTypeId ) as LotType - const lotTypeField = (lotType.lotTypeFields ?? []).find( + const lotTypeField = (lotType.BurialSiteTypeFields ?? []).find( (currentLotTypeField) => currentLotTypeField.lotTypeFieldId === lotTypeFieldId ) as LotTypeField @@ -447,16 +447,16 @@ type ResponseJSON = 10 ) - const lotTypeId = Number.parseInt( + const burialSiteTypeId = Number.parseInt( ( (clickEvent.currentTarget as HTMLElement).closest( '.container--lotType' ) as HTMLElement - ).dataset.lotTypeId ?? '', + ).dataset.burialSiteTypeId ?? '', 10 ) - openEditLotTypeField(lotTypeId, lotTypeFieldId) + openEditLotTypeField(burialSiteTypeId, lotTypeFieldId) } function moveLotTypeField(clickEvent: MouseEvent): void { @@ -480,27 +480,27 @@ type ResponseJSON = ) } - function renderLotTypeFields( + function renderBurialSiteTypeFields( panelElement: HTMLElement, - lotTypeId: number, - lotTypeFields: LotTypeField[] + burialSiteTypeId: number, + BurialSiteTypeFields: LotTypeField[] ): void { - if (lotTypeFields.length === 0) { + if (BurialSiteTypeFields.length === 0) { // eslint-disable-next-line no-unsanitized/method panelElement.insertAdjacentHTML( 'beforeend', `
+ ${expandedLotTypes.has(burialSiteTypeId) ? '' : ' is-hidden'}">

There are no additional fields.

` ) } else { - for (const lotTypeField of lotTypeFields) { + for (const lotTypeField of BurialSiteTypeFields) { const panelBlockElement = document.createElement('div') panelBlockElement.className = 'panel-block is-block container--lotTypeField' - if (!expandedLotTypes.has(lotTypeId)) { + if (!expandedLotTypes.has(burialSiteTypeId)) { panelBlockElement.classList.add('is-hidden') } @@ -565,16 +565,16 @@ type ResponseJSON = lotTypeContainer.className = 'panel container--lotType' - lotTypeContainer.dataset.lotTypeId = lotType.lotTypeId.toString() + lotTypeContainer.dataset.burialSiteTypeId = lotType.burialSiteTypeId.toString() // eslint-disable-next-line no-unsanitized/property lotTypeContainer.innerHTML = `
-
` - renderLotTypeFields( + renderBurialSiteTypeFields( lotTypeContainer, - lotType.lotTypeId, - lotType.lotTypeFields ?? [] + lotType.burialSiteTypeId, + lotType.BurialSiteTypeFields ?? [] ) lotTypeContainer - .querySelector('.button--toggleLotTypeFields') - ?.addEventListener('click', toggleLotTypeFields) + .querySelector('.button--toggleBurialSiteTypeFields') + ?.addEventListener('click', toggleBurialSiteTypeFields) lotTypeContainer .querySelector('.button--deleteLotType') diff --git a/public/javascripts/adminOccupancyTypes.js b/public/javascripts/adminOccupancyTypes.js index f32dbc1c..e7e14bc0 100644 --- a/public/javascripts/adminOccupancyTypes.js +++ b/public/javascripts/adminOccupancyTypes.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); (() => { const los = exports.los; const occupancyTypesContainerElement = document.querySelector('#container--occupancyTypes'); - const occupancyTypePrintsContainerElement = document.querySelector('#container--occupancyTypePrints'); + const ContractTypePrintsContainerElement = document.querySelector('#container--ContractTypePrints'); let occupancyTypes = exports.occupancyTypes; delete exports.occupancyTypes; let allOccupancyTypeFields = exports.allOccupancyTypeFields; @@ -374,8 +374,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); } }); } - function renderOccupancyTypePrints(panelElement, occupancyTypeId, occupancyTypePrints) { - if (occupancyTypePrints.length === 0) { + function renderContractTypePrints(panelElement, occupancyTypeId, ContractTypePrints) { + if (ContractTypePrints.length === 0) { panelElement.insertAdjacentHTML('beforeend', `

There are no prints associated with this record.

@@ -383,7 +383,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
`); } else { - for (const printEJS of occupancyTypePrints) { + for (const printEJS of ContractTypePrints) { const panelBlockElement = document.createElement('div'); panelBlockElement.className = 'panel-block is-block container--occupancyTypePrint'; @@ -449,7 +449,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
`; - occupancyTypePrintsContainerElement.innerHTML = ''; + ContractTypePrintsContainerElement.innerHTML = ''; renderOccupancyTypeFields(occupancyTypesContainerElement.querySelector('#container--allOccupancyTypeFields'), undefined, allOccupancyTypeFields); occupancyTypesContainerElement .querySelector('.button--addOccupancyTypeField') @@ -460,7 +460,7 @@ Object.defineProperty(exports, "__esModule", { value: true });

There are no active ${los.escapedAliases.occupancy} types.

`); // eslint-disable-next-line no-unsanitized/method - occupancyTypePrintsContainerElement.insertAdjacentHTML('afterbegin', `

There are no active ${los.escapedAliases.occupancy} types.

`); return; @@ -554,11 +554,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
`; - renderOccupancyTypePrints(occupancyTypePrintContainer, occupancyType.occupancyTypeId, occupancyType.occupancyTypePrints ?? []); + renderContractTypePrints(occupancyTypePrintContainer, occupancyType.occupancyTypeId, occupancyType.ContractTypePrints ?? []); occupancyTypePrintContainer .querySelector('.button--addOccupancyTypePrint') ?.addEventListener('click', openAddOccupancyTypePrint); - occupancyTypePrintsContainerElement.append(occupancyTypePrintContainer); + ContractTypePrintsContainerElement.append(occupancyTypePrintContainer); } } document diff --git a/public/javascripts/adminOccupancyTypes.ts b/public/javascripts/adminOccupancyTypes.ts index a00f93de..89019625 100644 --- a/public/javascripts/adminOccupancyTypes.ts +++ b/public/javascripts/adminOccupancyTypes.ts @@ -16,8 +16,8 @@ type ResponseJSON = | { success: true occupancyTypes: OccupancyType[] - allOccupancyTypeFields: OccupancyTypeField[] - occupancyTypeFieldId?: number + allContractTypeFields: OccupancyTypeField[] + contractTypeFieldId?: number } | { success: false @@ -30,39 +30,39 @@ type ResponseJSON = '#container--occupancyTypes' ) as HTMLElement - const occupancyTypePrintsContainerElement = document.querySelector( - '#container--occupancyTypePrints' + const ContractTypePrintsContainerElement = document.querySelector( + '#container--ContractTypePrints' ) as HTMLElement let occupancyTypes = exports.occupancyTypes as OccupancyType[] delete exports.occupancyTypes - let allOccupancyTypeFields = - exports.allOccupancyTypeFields as OccupancyTypeField[] - delete exports.allOccupancyTypeFields + let allContractTypeFields = + exports.allContractTypeFields as OccupancyTypeField[] + delete exports.allContractTypeFields const expandedOccupancyTypes = new Set() - function toggleOccupancyTypeFields(clickEvent: Event): void { + function toggleContractTypeFields(clickEvent: Event): void { const toggleButtonElement = clickEvent.currentTarget as HTMLButtonElement const occupancyTypeElement = toggleButtonElement.closest( '.container--occupancyType' ) as HTMLElement - const occupancyTypeId = Number.parseInt( - occupancyTypeElement.dataset.occupancyTypeId ?? '', + const contractTypeId = Number.parseInt( + occupancyTypeElement.dataset.contractTypeId ?? '', 10 ) - if (expandedOccupancyTypes.has(occupancyTypeId)) { - expandedOccupancyTypes.delete(occupancyTypeId) + if (expandedOccupancyTypes.has(contractTypeId)) { + expandedOccupancyTypes.delete(contractTypeId) } else { - expandedOccupancyTypes.add(occupancyTypeId) + expandedOccupancyTypes.add(contractTypeId) } // eslint-disable-next-line no-unsanitized/property - toggleButtonElement.innerHTML = expandedOccupancyTypes.has(occupancyTypeId) + toggleButtonElement.innerHTML = expandedOccupancyTypes.has(contractTypeId) ? '' : '' @@ -79,12 +79,12 @@ type ResponseJSON = success: boolean errorMessage?: string occupancyTypes: OccupancyType[] - allOccupancyTypeFields: OccupancyTypeField[] + allContractTypeFields: OccupancyTypeField[] } if (responseJSON.success) { occupancyTypes = responseJSON.occupancyTypes - allOccupancyTypeFields = responseJSON.allOccupancyTypeFields + allContractTypeFields = responseJSON.allContractTypeFields renderOccupancyTypes() } else { bulmaJS.alert({ @@ -96,12 +96,12 @@ type ResponseJSON = } function deleteOccupancyType(clickEvent: Event): void { - const occupancyTypeId = Number.parseInt( + const contractTypeId = Number.parseInt( ( (clickEvent.currentTarget as HTMLElement).closest( '.container--occupancyType' ) as HTMLElement - ).dataset.occupancyTypeId ?? '', + ).dataset.contractTypeId ?? '', 10 ) @@ -109,7 +109,7 @@ type ResponseJSON = cityssm.postJSON( `${los.urlPrefix}/admin/doDeleteOccupancyType`, { - occupancyTypeId + contractTypeId }, occupancyTypeResponseHandler ) @@ -127,18 +127,18 @@ type ResponseJSON = } function openEditOccupancyType(clickEvent: Event): void { - const occupancyTypeId = Number.parseInt( + const contractTypeId = Number.parseInt( ( (clickEvent.currentTarget as HTMLElement).closest( '.container--occupancyType' ) as HTMLElement - ).dataset.occupancyTypeId ?? '', + ).dataset.contractTypeId ?? '', 10 ) const occupancyType = occupancyTypes.find( (currentOccupancyType) => - occupancyTypeId === currentOccupancyType.occupancyTypeId + contractTypeId === currentOccupancyType.contractTypeId ) as OccupancyType let editCloseModalFunction: () => void @@ -165,9 +165,9 @@ type ResponseJSON = los.populateAliases(modalElement) ;( modalElement.querySelector( - '#occupancyTypeEdit--occupancyTypeId' + '#occupancyTypeEdit--contractTypeId' ) as HTMLInputElement - ).value = occupancyTypeId.toString() + ).value = contractTypeId.toString() ;( modalElement.querySelector( '#occupancyTypeEdit--occupancyType' @@ -193,12 +193,12 @@ type ResponseJSON = } function openAddOccupancyTypeField(clickEvent: Event): void { - const occupancyTypeId = Number.parseInt( + const contractTypeId = Number.parseInt( ( (clickEvent.currentTarget as HTMLElement).closest( '.container--occupancyType' ) as HTMLElement - ).dataset.occupancyTypeId ?? '', + ).dataset.contractTypeId ?? '', 10 ) @@ -213,14 +213,14 @@ type ResponseJSON = (rawResponseJSON) => { const responseJSON = rawResponseJSON as ResponseJSON - expandedOccupancyTypes.add(occupancyTypeId) + expandedOccupancyTypes.add(contractTypeId) occupancyTypeResponseHandler(responseJSON) if (responseJSON.success) { addCloseModalFunction() openEditOccupancyTypeField( - occupancyTypeId, - responseJSON.occupancyTypeFieldId ?? 0 + contractTypeId, + responseJSON.contractTypeFieldId ?? 0 ) } } @@ -231,12 +231,12 @@ type ResponseJSON = onshow(modalElement) { los.populateAliases(modalElement) - if (occupancyTypeId) { + if (contractTypeId) { ;( modalElement.querySelector( - '#occupancyTypeFieldAdd--occupancyTypeId' + '#occupancyTypeFieldAdd--contractTypeId' ) as HTMLInputElement - ).value = occupancyTypeId.toString() + ).value = contractTypeId.toString() } }, onshown(modalElement, closeModalFunction) { @@ -260,11 +260,11 @@ type ResponseJSON = function moveOccupancyType(clickEvent: MouseEvent): void { const buttonElement = clickEvent.currentTarget as HTMLButtonElement - const occupancyTypeId = ( + const contractTypeId = ( (clickEvent.currentTarget as HTMLElement).closest( '.container--occupancyType' ) as HTMLElement - ).dataset.occupancyTypeId + ).dataset.contractTypeId cityssm.postJSON( `${los.urlPrefix}/admin/${ @@ -273,7 +273,7 @@ type ResponseJSON = : 'doMoveOccupancyTypeDown' }`, { - occupancyTypeId, + contractTypeId, moveToEnd: clickEvent.shiftKey ? '1' : '0' }, occupancyTypeResponseHandler @@ -281,25 +281,25 @@ type ResponseJSON = } function openEditOccupancyTypeField( - occupancyTypeId: number, - occupancyTypeFieldId: number + contractTypeId: number, + contractTypeFieldId: number ): void { let occupancyType: OccupancyType | undefined - if (occupancyTypeId) { + if (contractTypeId) { occupancyType = occupancyTypes.find( (currentOccupancyType) => - currentOccupancyType.occupancyTypeId === occupancyTypeId + currentOccupancyType.contractTypeId === contractTypeId ) } const occupancyTypeField = ( occupancyType - ? occupancyType.occupancyTypeFields ?? [] - : allOccupancyTypeFields + ? occupancyType.ContractTypeFields ?? [] + : allContractTypeFields ).find( (currentOccupancyTypeField) => - currentOccupancyTypeField.occupancyTypeFieldId === occupancyTypeFieldId + currentOccupancyTypeField.contractTypeFieldId === contractTypeFieldId ) as OccupancyTypeField let fieldTypeElement: HTMLSelectElement @@ -361,7 +361,7 @@ type ResponseJSON = cityssm.postJSON( `${los.urlPrefix}/admin/doDeleteOccupancyTypeField`, { - occupancyTypeFieldId + contractTypeFieldId }, (rawResponseJSON) => { const responseJSON = rawResponseJSON as ResponseJSON @@ -392,9 +392,9 @@ type ResponseJSON = los.populateAliases(modalElement) ;( modalElement.querySelector( - '#occupancyTypeFieldEdit--occupancyTypeFieldId' + '#occupancyTypeFieldEdit--contractTypeFieldId' ) as HTMLInputElement - ).value = occupancyTypeField.occupancyTypeFieldId.toString() + ).value = occupancyTypeField.contractTypeFieldId.toString() ;( modalElement.querySelector( '#occupancyTypeFieldEdit--occupancyTypeField' @@ -469,35 +469,35 @@ type ResponseJSON = function openEditOccupancyTypeFieldByClick(clickEvent: Event): void { clickEvent.preventDefault() - const occupancyTypeFieldId = Number.parseInt( + const contractTypeFieldId = Number.parseInt( ( (clickEvent.currentTarget as HTMLElement).closest( '.container--occupancyTypeField' ) as HTMLElement - ).dataset.occupancyTypeFieldId ?? '', + ).dataset.contractTypeFieldId ?? '', 10 ) - const occupancyTypeId = Number.parseInt( + const contractTypeId = Number.parseInt( ( (clickEvent.currentTarget as HTMLElement).closest( '.container--occupancyType' ) as HTMLElement - ).dataset.occupancyTypeId ?? '', + ).dataset.contractTypeId ?? '', 10 ) - openEditOccupancyTypeField(occupancyTypeId, occupancyTypeFieldId) + openEditOccupancyTypeField(contractTypeId, contractTypeFieldId) } function moveOccupancyTypeField(clickEvent: MouseEvent): void { const buttonElement = clickEvent.currentTarget as HTMLButtonElement - const occupancyTypeFieldId = ( + const contractTypeFieldId = ( (clickEvent.currentTarget as HTMLElement).closest( '.container--occupancyTypeField' ) as HTMLElement - ).dataset.occupancyTypeFieldId + ).dataset.contractTypeFieldId cityssm.postJSON( `${los.urlPrefix}/admin/${ @@ -507,24 +507,24 @@ type ResponseJSON = 'doMoveOccupancyTypeFieldDown' }`, { - occupancyTypeFieldId, + contractTypeFieldId, moveToEnd: clickEvent.shiftKey ? '1' : '0' }, occupancyTypeResponseHandler ) } - function renderOccupancyTypeFields( + function renderContractTypeFields( panelElement: HTMLElement, - occupancyTypeId: number | undefined, - occupancyTypeFields: OccupancyTypeField[] + contractTypeId: number | undefined, + ContractTypeFields: OccupancyTypeField[] ): void { - if (occupancyTypeFields.length === 0) { + if (ContractTypeFields.length === 0) { // eslint-disable-next-line no-unsanitized/method panelElement.insertAdjacentHTML( 'beforeend', `
@@ -532,17 +532,17 @@ type ResponseJSON =
` ) } else { - for (const occupancyTypeField of occupancyTypeFields) { + for (const occupancyTypeField of ContractTypeFields) { const panelBlockElement = document.createElement('div') panelBlockElement.className = 'panel-block is-block container--occupancyTypeField' - if (occupancyTypeId && !expandedOccupancyTypes.has(occupancyTypeId)) { + if (contractTypeId && !expandedOccupancyTypes.has(contractTypeId)) { panelBlockElement.classList.add('is-hidden') } - panelBlockElement.dataset.occupancyTypeFieldId = - occupancyTypeField.occupancyTypeFieldId.toString() + panelBlockElement.dataset.contractTypeFieldId = + occupancyTypeField.contractTypeFieldId.toString() // eslint-disable-next-line no-unsanitized/property panelBlockElement.innerHTML = `
@@ -583,12 +583,12 @@ type ResponseJSON = } function openAddOccupancyTypePrint(clickEvent: Event): void { - const occupancyTypeId = + const contractTypeId = ( (clickEvent.currentTarget as HTMLElement).closest( '.container--occupancyTypePrintList' ) as HTMLElement - ).dataset.occupancyTypeId ?? '' + ).dataset.contractTypeId ?? '' let closeAddModalFunction: () => void @@ -615,9 +615,9 @@ type ResponseJSON = los.populateAliases(modalElement) ;( modalElement.querySelector( - '#occupancyTypePrintAdd--occupancyTypeId' + '#occupancyTypePrintAdd--contractTypeId' ) as HTMLInputElement - ).value = occupancyTypeId + ).value = contractTypeId const printSelectElement = modalElement.querySelector( '#occupancyTypePrintAdd--printEJS' @@ -647,9 +647,9 @@ type ResponseJSON = buttonElement.closest('.container--occupancyTypePrint') as HTMLElement ).dataset.printEJS - const occupancyTypeId = ( + const contractTypeId = ( buttonElement.closest('.container--occupancyTypePrintList') as HTMLElement - ).dataset.occupancyTypeId + ).dataset.contractTypeId cityssm.postJSON( `${los.urlPrefix}/admin/${ @@ -660,7 +660,7 @@ type ResponseJSON = 'doMoveOccupancyTypePrintDown' }`, { - occupancyTypeId, + contractTypeId, printEJS, moveToEnd: clickEvent.shiftKey ? '1' : '0' }, @@ -677,17 +677,17 @@ type ResponseJSON = ) as HTMLElement ).dataset.printEJS - const occupancyTypeId = ( + const contractTypeId = ( (clickEvent.currentTarget as HTMLElement).closest( '.container--occupancyTypePrintList' ) as HTMLElement - ).dataset.occupancyTypeId + ).dataset.contractTypeId function doDelete(): void { cityssm.postJSON( `${los.urlPrefix}/admin/doDeleteOccupancyTypePrint`, { - occupancyTypeId, + contractTypeId, printEJS }, occupancyTypeResponseHandler @@ -705,12 +705,12 @@ type ResponseJSON = }) } - function renderOccupancyTypePrints( + function renderContractTypePrints( panelElement: HTMLElement, - occupancyTypeId: number, - occupancyTypePrints: string[] + contractTypeId: number, + ContractTypePrints: string[] ): void { - if (occupancyTypePrints.length === 0) { + if (ContractTypePrints.length === 0) { panelElement.insertAdjacentHTML( 'beforeend', `
@@ -720,7 +720,7 @@ type ResponseJSON =
` ) } else { - for (const printEJS of occupancyTypePrints) { + for (const printEJS of ContractTypePrints) { const panelBlockElement = document.createElement('div') panelBlockElement.className = 'panel-block is-block container--occupancyTypePrint' @@ -788,7 +788,7 @@ type ResponseJSON = function renderOccupancyTypes(): void { // eslint-disable-next-line no-unsanitized/property - occupancyTypesContainerElement.innerHTML = `
+ occupancyTypesContainerElement.innerHTML = `
@@ -808,14 +808,14 @@ type ResponseJSON =
` - occupancyTypePrintsContainerElement.innerHTML = '' + ContractTypePrintsContainerElement.innerHTML = '' - renderOccupancyTypeFields( + renderContractTypeFields( occupancyTypesContainerElement.querySelector( - '#container--allOccupancyTypeFields' + '#container--allContractTypeFields' ) as HTMLElement, undefined, - allOccupancyTypeFields + allContractTypeFields ) occupancyTypesContainerElement @@ -832,7 +832,7 @@ type ResponseJSON = ) // eslint-disable-next-line no-unsanitized/method - occupancyTypePrintsContainerElement.insertAdjacentHTML( + ContractTypePrintsContainerElement.insertAdjacentHTML( 'afterbegin', `
There are no active ${los.escapedAliases.occupancy} types.

@@ -851,17 +851,17 @@ type ResponseJSON = occupancyTypeContainer.className = 'panel container--occupancyType' - occupancyTypeContainer.dataset.occupancyTypeId = - occupancyType.occupancyTypeId.toString() + occupancyTypeContainer.dataset.contractTypeId = + occupancyType.contractTypeId.toString() // eslint-disable-next-line no-unsanitized/property occupancyTypeContainer.innerHTML = `
-
` - renderOccupancyTypeFields( + renderContractTypeFields( occupancyTypeContainer, - occupancyType.occupancyTypeId, - occupancyType.occupancyTypeFields ?? [] + occupancyType.contractTypeId, + occupancyType.ContractTypeFields ?? [] ) occupancyTypeContainer - .querySelector('.button--toggleOccupancyTypeFields') - ?.addEventListener('click', toggleOccupancyTypeFields) + .querySelector('.button--toggleContractTypeFields') + ?.addEventListener('click', toggleContractTypeFields) occupancyTypeContainer .querySelector('.button--deleteOccupancyType') @@ -943,8 +943,8 @@ type ResponseJSON = occupancyTypePrintContainer.className = 'panel container--occupancyTypePrintList' - occupancyTypePrintContainer.dataset.occupancyTypeId = - occupancyType.occupancyTypeId.toString() + occupancyTypePrintContainer.dataset.contractTypeId = + occupancyType.contractTypeId.toString() occupancyTypePrintContainer.innerHTML = `
@@ -964,17 +964,17 @@ type ResponseJSON =
` - renderOccupancyTypePrints( + renderContractTypePrints( occupancyTypePrintContainer, - occupancyType.occupancyTypeId, - occupancyType.occupancyTypePrints ?? [] + occupancyType.contractTypeId, + occupancyType.ContractTypePrints ?? [] ) occupancyTypePrintContainer .querySelector('.button--addOccupancyTypePrint') ?.addEventListener('click', openAddOccupancyTypePrint) - occupancyTypePrintsContainerElement.append(occupancyTypePrintContainer) + ContractTypePrintsContainerElement.append(occupancyTypePrintContainer) } } diff --git a/public/javascripts/adminTables.js b/public/javascripts/adminTables.js index 75420885..acc7a199 100644 --- a/public/javascripts/adminTables.js +++ b/public/javascripts/adminTables.js @@ -369,10 +369,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); } function deleteLotStatus(clickEvent) { const tableRowElement = clickEvent.currentTarget.closest('tr'); - const lotStatusId = tableRowElement.dataset.lotStatusId; + const burialSiteStatusId = tableRowElement.dataset.burialSiteStatusId; function doDelete() { cityssm.postJSON(`${los.urlPrefix}/admin/doDeleteLotStatus`, { - lotStatusId + burialSiteStatusId }, (rawResponseJSON) => { const responseJSON = rawResponseJSON; if (responseJSON.success) { @@ -412,11 +412,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); function moveLotStatus(clickEvent) { const buttonElement = clickEvent.currentTarget; const tableRowElement = buttonElement.closest('tr'); - const lotStatusId = tableRowElement.dataset.lotStatusId; + const burialSiteStatusId = tableRowElement.dataset.burialSiteStatusId; cityssm.postJSON(`${los.urlPrefix}/admin/${buttonElement.dataset.direction === 'up' ? 'doMoveLotStatusUp' : 'doMoveLotStatusDown'}`, { - lotStatusId, + burialSiteStatusId, moveToEnd: clickEvent.shiftKey ? '1' : '0' }, (rawResponseJSON) => { const responseJSON = rawResponseJSON; @@ -447,11 +447,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); containerElement.innerHTML = ''; for (const lotStatus of lotStatuses) { const tableRowElement = document.createElement('tr'); - tableRowElement.dataset.lotStatusId = lotStatus.lotStatusId.toString(); + tableRowElement.dataset.burialSiteStatusId = lotStatus.burialSiteStatusId.toString(); // eslint-disable-next-line no-unsanitized/property tableRowElement.innerHTML = ` - +
{ const responseJSON = rawResponseJSON as ResponseJSON @@ -615,7 +615,7 @@ declare const bulmaJS: BulmaJS const tableRowElement = buttonElement.closest('tr') as HTMLTableRowElement - const lotStatusId = tableRowElement.dataset.lotStatusId + const burialSiteStatusId = tableRowElement.dataset.burialSiteStatusId cityssm.postJSON( `${los.urlPrefix}/admin/${ @@ -624,7 +624,7 @@ declare const bulmaJS: BulmaJS : 'doMoveLotStatusDown' }`, { - lotStatusId, + burialSiteStatusId, moveToEnd: clickEvent.shiftKey ? '1' : '0' }, (rawResponseJSON) => { @@ -665,12 +665,12 @@ declare const bulmaJS: BulmaJS for (const lotStatus of lotStatuses) { const tableRowElement = document.createElement('tr') - tableRowElement.dataset.lotStatusId = lotStatus.lotStatusId.toString() + tableRowElement.dataset.burialSiteStatusId = lotStatus.burialSiteStatusId.toString() // eslint-disable-next-line no-unsanitized/property tableRowElement.innerHTML = ` - +
{ - if (lotTypeIdElement.value === '') { + burialSiteTypeIdElement.addEventListener('change', () => { + if (burialSiteTypeIdElement.value === '') { // eslint-disable-next-line no-unsanitized/property lotFieldsContainerElement.innerHTML = `

Select the ${los.escapedAliases.lot} type to load the available fields.

@@ -98,7 +98,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); return; } cityssm.postJSON(`${los.urlPrefix}/lots/doGetLotTypeFields`, { - lotTypeId: lotTypeIdElement.value + burialSiteTypeId: burialSiteTypeIdElement.value }, (rawResponseJSON) => { const responseJSON = rawResponseJSON; if (responseJSON.lotTypeFields.length === 0) { @@ -160,9 +160,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); }); } else { - const originalLotTypeId = lotTypeIdElement.value; - lotTypeIdElement.addEventListener('change', () => { - if (lotTypeIdElement.value !== originalLotTypeId) { + const originalburialSiteTypeId = burialSiteTypeIdElement.value; + burialSiteTypeIdElement.addEventListener('change', () => { + if (burialSiteTypeIdElement.value !== originalburialSiteTypeId) { bulmaJS.confirm({ title: 'Confirm Change', message: `Are you sure you want to change the ${los.escapedAliases.lot} type?\n @@ -177,7 +177,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); cancelButton: { text: 'Revert the Change', callbackFunction() { - lotTypeIdElement.value = originalLotTypeId; + burialSiteTypeIdElement.value = originalburialSiteTypeId; } } }); diff --git a/public/javascripts/lotEdit.ts b/public/javascripts/lotEdit.ts index 2bd3055d..859ff0e5 100644 --- a/public/javascripts/lotEdit.ts +++ b/public/javascripts/lotEdit.ts @@ -127,8 +127,8 @@ declare const exports: Record // Lot Type - const lotTypeIdElement = document.querySelector( - '#lot--lotTypeId' + const burialSiteTypeIdElement = document.querySelector( + '#lot--burialSiteTypeId' ) as HTMLSelectElement if (isCreate) { @@ -136,8 +136,8 @@ declare const exports: Record '#container--lotFields' ) as HTMLElement - lotTypeIdElement.addEventListener('change', () => { - if (lotTypeIdElement.value === '') { + burialSiteTypeIdElement.addEventListener('change', () => { + if (burialSiteTypeIdElement.value === '') { // eslint-disable-next-line no-unsanitized/property lotFieldsContainerElement.innerHTML = `

Select the ${los.escapedAliases.lot} type to load the available fields.

@@ -147,16 +147,16 @@ declare const exports: Record } cityssm.postJSON( - `${los.urlPrefix}/lots/doGetLotTypeFields`, + `${los.urlPrefix}/lots/doGetBurialSiteTypeFields`, { - lotTypeId: lotTypeIdElement.value + burialSiteTypeId: burialSiteTypeIdElement.value }, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { - lotTypeFields: LotTypeField[] + BurialSiteTypeFields: LotTypeField[] } - if (responseJSON.lotTypeFields.length === 0) { + if (responseJSON.BurialSiteTypeFields.length === 0) { // eslint-disable-next-line no-unsanitized/property lotFieldsContainerElement.innerHTML = `

@@ -171,7 +171,7 @@ declare const exports: Record let lotTypeFieldIds = '' - for (const lotTypeField of responseJSON.lotTypeFields) { + for (const lotTypeField of responseJSON.BurialSiteTypeFields) { lotTypeFieldIds += `,${lotTypeField.lotTypeFieldId.toString()}` const fieldName = `lotFieldValue_${lotTypeField.lotTypeFieldId.toString()}` @@ -246,10 +246,10 @@ declare const exports: Record ) }) } else { - const originalLotTypeId = lotTypeIdElement.value + const originalburialSiteTypeId = burialSiteTypeIdElement.value - lotTypeIdElement.addEventListener('change', () => { - if (lotTypeIdElement.value !== originalLotTypeId) { + burialSiteTypeIdElement.addEventListener('change', () => { + if (burialSiteTypeIdElement.value !== originalburialSiteTypeId) { bulmaJS.confirm({ title: 'Confirm Change', message: `Are you sure you want to change the ${los.escapedAliases.lot} type?\n @@ -264,7 +264,7 @@ declare const exports: Record cancelButton: { text: 'Revert the Change', callbackFunction() { - lotTypeIdElement.value = originalLotTypeId + burialSiteTypeIdElement.value = originalburialSiteTypeId } } }) diff --git a/public/javascripts/lotOccupancyEdit.js b/public/javascripts/lotOccupancyEdit.js index df8d6f11..b0032df2 100644 --- a/public/javascripts/lotOccupancyEdit.js +++ b/public/javascripts/lotOccupancyEdit.js @@ -400,17 +400,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); const regex = exports.lotNamePattern; modalElement.querySelector('#lotCreate--lotName').pattern = regex.source; } - const lotTypeElement = modalElement.querySelector('#lotCreate--lotTypeId'); + const lotTypeElement = modalElement.querySelector('#lotCreate--burialSiteTypeId'); for (const lotType of exports.lotTypes) { const optionElement = document.createElement('option'); - optionElement.value = lotType.lotTypeId.toString(); + optionElement.value = lotType.burialSiteTypeId.toString(); optionElement.textContent = lotType.lotType; lotTypeElement.append(optionElement); } - const lotStatusElement = modalElement.querySelector('#lotCreate--lotStatusId'); + const lotStatusElement = modalElement.querySelector('#lotCreate--burialSiteStatusId'); for (const lotStatus of exports.lotStatuses) { const optionElement = document.createElement('option'); - optionElement.value = lotStatus.lotStatusId.toString(); + optionElement.value = lotStatus.burialSiteStatusId.toString(); optionElement.textContent = lotStatus.lotStatus; lotStatusElement.append(optionElement); } diff --git a/public/javascripts/lotOccupancyEdit.ts b/public/javascripts/lotOccupancyEdit.ts index 1fd1b054..f8a13ebd 100644 --- a/public/javascripts/lotOccupancyEdit.ts +++ b/public/javascripts/lotOccupancyEdit.ts @@ -25,10 +25,10 @@ declare const exports: Record ;(() => { const los = exports.los as LOS - const lotOccupancyId = ( - document.querySelector('#lotOccupancy--lotOccupancyId') as HTMLInputElement + const burialSiteContractId = ( + document.querySelector('#lotOccupancy--burialSiteContractId') as HTMLInputElement ).value - const isCreate = lotOccupancyId === '' + const isCreate = burialSiteContractId === '' /* * Main form @@ -63,7 +63,7 @@ declare const exports: Record (rawResponseJSON) => { const responseJSON = rawResponseJSON as { success: boolean - lotOccupancyId?: number + burialSiteContractId?: number errorMessage?: string } @@ -72,7 +72,7 @@ declare const exports: Record if (isCreate || refreshAfterSave) { globalThis.location.href = los.getLotOccupancyURL( - responseJSON.lotOccupancyId, + responseJSON.burialSiteContractId, true, true ) @@ -103,20 +103,20 @@ declare const exports: Record cityssm.postJSON( `${los.urlPrefix}/lotOccupancies/doCopyLotOccupancy`, { - lotOccupancyId + burialSiteContractId }, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { success: boolean errorMessage?: string - lotOccupancyId?: number + burialSiteContractId?: number } if (responseJSON.success) { clearUnsavedChanges() globalThis.location.href = los.getLotOccupancyURL( - responseJSON.lotOccupancyId, + responseJSON.burialSiteContractId, true ) } else { @@ -163,7 +163,7 @@ declare const exports: Record cityssm.postJSON( `${los.urlPrefix}/lotOccupancies/doDeleteLotOccupancy`, { - lotOccupancyId + burialSiteContractId }, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { @@ -248,9 +248,9 @@ declare const exports: Record onshow(modalElement) { ;( modalElement.querySelector( - '#workOrderCreate--lotOccupancyId' + '#workOrderCreate--burialSiteContractId' ) as HTMLInputElement - ).value = lotOccupancyId + ).value = burialSiteContractId ;( modalElement.querySelector( '#workOrderCreate--workOrderOpenDateString' @@ -301,8 +301,8 @@ declare const exports: Record // Occupancy Type - const occupancyTypeIdElement = document.querySelector( - '#lotOccupancy--occupancyTypeId' + const contractTypeIdElement = document.querySelector( + '#lotOccupancy--contractTypeId' ) as HTMLSelectElement if (isCreate) { @@ -310,8 +310,8 @@ declare const exports: Record '#container--lotOccupancyFields' ) as HTMLElement - occupancyTypeIdElement.addEventListener('change', () => { - if (occupancyTypeIdElement.value === '') { + contractTypeIdElement.addEventListener('change', () => { + if (contractTypeIdElement.value === '') { // eslint-disable-next-line no-unsanitized/property lotOccupancyFieldsContainerElement.innerHTML = `

Select the ${los.escapedAliases.occupancy} type to load the available fields.

@@ -321,16 +321,16 @@ declare const exports: Record } cityssm.postJSON( - `${los.urlPrefix}/lotOccupancies/doGetOccupancyTypeFields`, + `${los.urlPrefix}/lotOccupancies/doGetContractTypeFields`, { - occupancyTypeId: occupancyTypeIdElement.value + contractTypeId: contractTypeIdElement.value }, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { - occupancyTypeFields: OccupancyTypeField[] + ContractTypeFields: OccupancyTypeField[] } - if (responseJSON.occupancyTypeFields.length === 0) { + if (responseJSON.ContractTypeFields.length === 0) { // eslint-disable-next-line no-unsanitized/property lotOccupancyFieldsContainerElement.innerHTML = `

There are no additional fields for this ${los.escapedAliases.occupancy} type.

@@ -341,12 +341,12 @@ declare const exports: Record lotOccupancyFieldsContainerElement.innerHTML = '' - let occupancyTypeFieldIds = '' + let contractTypeFieldIds = '' - for (const occupancyTypeField of responseJSON.occupancyTypeFields) { - occupancyTypeFieldIds += `,${occupancyTypeField.occupancyTypeFieldId.toString()}` + for (const occupancyTypeField of responseJSON.ContractTypeFields) { + contractTypeFieldIds += `,${occupancyTypeField.contractTypeFieldId.toString()}` - const fieldName = `lotOccupancyFieldValue_${occupancyTypeField.occupancyTypeFieldId.toString()}` + const fieldName = `lotOccupancyFieldValue_${occupancyTypeField.contractTypeFieldId.toString()}` const fieldId = `lotOccupancy--${fieldName}` @@ -421,17 +421,17 @@ declare const exports: Record lotOccupancyFieldsContainerElement.insertAdjacentHTML( 'beforeend', // eslint-disable-next-line no-secrets/no-secrets - `` + `` ) } ) }) } else { - const originalOccupancyTypeId = occupancyTypeIdElement.value + const originalcontractTypeId = contractTypeIdElement.value - occupancyTypeIdElement.addEventListener('change', () => { - if (occupancyTypeIdElement.value !== originalOccupancyTypeId) { + contractTypeIdElement.addEventListener('change', () => { + if (contractTypeIdElement.value !== originalcontractTypeId) { bulmaJS.confirm({ title: 'Confirm Change', message: `Are you sure you want to change the ${los.escapedAliases.occupancy} type?\n @@ -446,7 +446,7 @@ declare const exports: Record cancelButton: { text: 'Revert the Change', callbackFunction: () => { - occupancyTypeIdElement.value = originalOccupancyTypeId + contractTypeIdElement.value = originalcontractTypeId } } }) @@ -532,7 +532,7 @@ declare const exports: Record panelBlockElement.innerHTML = `
${cityssm.escapeHTML(lot.lotName ?? '')}
- ${cityssm.escapeHTML(lot.mapName ?? '')} + ${cityssm.escapeHTML(lot.cemeteryName ?? '')}
${cityssm.escapeHTML(lot.lotStatus as string)}
@@ -648,36 +648,36 @@ declare const exports: Record } const lotTypeElement = modalElement.querySelector( - '#lotCreate--lotTypeId' + '#lotCreate--burialSiteTypeId' ) as HTMLSelectElement for (const lotType of exports.lotTypes as LotType[]) { const optionElement = document.createElement('option') - optionElement.value = lotType.lotTypeId.toString() + optionElement.value = lotType.burialSiteTypeId.toString() optionElement.textContent = lotType.lotType lotTypeElement.append(optionElement) } const lotStatusElement = modalElement.querySelector( - '#lotCreate--lotStatusId' + '#lotCreate--burialSiteStatusId' ) as HTMLSelectElement for (const lotStatus of exports.lotStatuses as LotStatus[]) { const optionElement = document.createElement('option') - optionElement.value = lotStatus.lotStatusId.toString() + optionElement.value = lotStatus.burialSiteStatusId.toString() optionElement.textContent = lotStatus.lotStatus lotStatusElement.append(optionElement) } const mapElement = modalElement.querySelector( - '#lotCreate--mapId' + '#lotCreate--cemeteryId' ) as HTMLSelectElement for (const map of exports.maps as MapRecord[]) { const optionElement = document.createElement('option') - optionElement.value = map.mapId!.toString() + optionElement.value = map.cemeteryId!.toString() optionElement.textContent = - (map.mapName ?? '') === '' ? '(No Name)' : map.mapName ?? '' + (map.cemeteryName ?? '') === '' ? '(No Name)' : map.cemeteryName ?? '' mapElement.append(optionElement) } @@ -731,17 +731,17 @@ declare const exports: Record los.initializeDatePickers(formElement) document - .querySelector('#lotOccupancy--occupancyStartDateString') + .querySelector('#lotOccupancy--contractStartDateString') ?.addEventListener('change', () => { const endDatePicker = ( document.querySelector( - '#lotOccupancy--occupancyEndDateString' + '#lotOccupancy--contractEndDateString' ) as HTMLInputElement ).bulmaCalendar.datePicker endDatePicker.min = ( document.querySelector( - '#lotOccupancy--occupancyStartDateString' + '#lotOccupancy--contractStartDateString' ) as HTMLInputElement ).value @@ -810,9 +810,9 @@ declare const exports: Record los.populateAliases(modalElement) ;( modalElement.querySelector( - '#lotOccupancyOccupantEdit--lotOccupancyId' + '#lotOccupancyOccupantEdit--burialSiteContractId' ) as HTMLInputElement - ).value = lotOccupancyId + ).value = burialSiteContractId ;( modalElement.querySelector( '#lotOccupancyOccupantEdit--lotOccupantIndex' @@ -988,7 +988,7 @@ declare const exports: Record cityssm.postJSON( `${los.urlPrefix}/lotOccupancies/doDeleteLotOccupancyOccupant`, { - lotOccupancyId, + burialSiteContractId, lotOccupantIndex }, (rawResponseJSON) => { @@ -1238,7 +1238,7 @@ declare const exports: Record }) } else { occupant.lotOccupantTypeId = Number.parseInt(lotOccupantTypeId, 10) - occupant.lotOccupancyId = Number.parseInt(lotOccupancyId, 10) + occupant.burialSiteContractId = Number.parseInt(burialSiteContractId, 10) addOccupant(occupant) } } @@ -1326,9 +1326,9 @@ declare const exports: Record los.populateAliases(modalElement) ;( modalElement.querySelector( - '#lotOccupancyOccupantAdd--lotOccupancyId' + '#lotOccupancyOccupantAdd--burialSiteContractId' ) as HTMLInputElement - ).value = lotOccupancyId + ).value = burialSiteContractId const lotOccupantTypeSelectElement = modalElement.querySelector( '#lotOccupancyOccupantAdd--lotOccupantTypeId' @@ -1449,17 +1449,17 @@ declare const exports: Record delete exports.lotOccupancyComments function openEditLotOccupancyComment(clickEvent: Event): void { - const lotOccupancyCommentId = Number.parseInt( + const burialSiteContractCommentId = Number.parseInt( (clickEvent.currentTarget as HTMLElement).closest('tr')?.dataset - .lotOccupancyCommentId ?? '', + .burialSiteContractCommentId ?? '', 10 ) const lotOccupancyComment = lotOccupancyComments.find( (currentLotOccupancyComment) => { return ( - currentLotOccupancyComment.lotOccupancyCommentId === - lotOccupancyCommentId + currentLotOccupancyComment.burialSiteContractCommentId === + burialSiteContractCommentId ) } ) as LotOccupancyComment @@ -1500,14 +1500,14 @@ declare const exports: Record los.populateAliases(modalElement) ;( modalElement.querySelector( - '#lotOccupancyCommentEdit--lotOccupancyId' + '#lotOccupancyCommentEdit--burialSiteContractId' ) as HTMLInputElement - ).value = lotOccupancyId + ).value = burialSiteContractId ;( modalElement.querySelector( - '#lotOccupancyCommentEdit--lotOccupancyCommentId' + '#lotOccupancyCommentEdit--burialSiteContractCommentId' ) as HTMLInputElement - ).value = lotOccupancyCommentId.toString() + ).value = burialSiteContractCommentId.toString() ;( modalElement.querySelector( '#lotOccupancyCommentEdit--lotOccupancyComment' @@ -1560,9 +1560,9 @@ declare const exports: Record } function deleteLotOccupancyComment(clickEvent: Event): void { - const lotOccupancyCommentId = Number.parseInt( + const burialSiteContractCommentId = Number.parseInt( (clickEvent.currentTarget as HTMLElement).closest('tr')?.dataset - .lotOccupancyCommentId ?? '', + .burialSiteContractCommentId ?? '', 10 ) @@ -1570,8 +1570,8 @@ declare const exports: Record cityssm.postJSON( `${los.urlPrefix}/lotOccupancies/doDeleteLotOccupancyComment`, { - lotOccupancyId, - lotOccupancyCommentId + burialSiteContractId, + burialSiteContractCommentId }, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { @@ -1629,8 +1629,8 @@ declare const exports: Record for (const lotOccupancyComment of lotOccupancyComments) { const tableRowElement = document.createElement('tr') - tableRowElement.dataset.lotOccupancyCommentId = - lotOccupancyComment.lotOccupancyCommentId?.toString() + tableRowElement.dataset.burialSiteContractCommentId = + lotOccupancyComment.burialSiteContractCommentId?.toString() tableRowElement.innerHTML = `${cityssm.escapeHTML(lotOccupancyComment.recordCreate_userName ?? '')} @@ -1710,9 +1710,9 @@ declare const exports: Record los.populateAliases(modalElement) ;( modalElement.querySelector( - '#lotOccupancyCommentAdd--lotOccupancyId' + '#lotOccupancyCommentAdd--burialSiteContractId' ) as HTMLInputElement - ).value = lotOccupancyId + ).value = burialSiteContractId }, onshown(modalElement, closeModalFunction) { bulmaJS.toggleHtmlClipped() @@ -1812,9 +1812,9 @@ declare const exports: Record onshow(modalElement) { ;( modalElement.querySelector( - '#lotOccupancyFeeQuantity--lotOccupancyId' + '#lotOccupancyFeeQuantity--burialSiteContractId' ) as HTMLInputElement - ).value = lotOccupancyId + ).value = burialSiteContractId ;( modalElement.querySelector( '#lotOccupancyFeeQuantity--feeId' @@ -1862,7 +1862,7 @@ declare const exports: Record cityssm.postJSON( `${los.urlPrefix}/lotOccupancies/doDeleteLotOccupancyFee`, { - lotOccupancyId, + burialSiteContractId, feeId }, (rawResponseJSON) => { @@ -2046,7 +2046,7 @@ declare const exports: Record cityssm.postJSON( `${los.urlPrefix}/lotOccupancies/doAddLotOccupancyFeeCategory`, { - lotOccupancyId, + burialSiteContractId, feeCategoryId }, (rawResponseJSON) => { @@ -2079,7 +2079,7 @@ declare const exports: Record cityssm.postJSON( `${los.urlPrefix}/lotOccupancies/doAddLotOccupancyFee`, { - lotOccupancyId, + burialSiteContractId, feeId, quantity }, @@ -2287,7 +2287,7 @@ declare const exports: Record cityssm.postJSON( `${los.urlPrefix}/lotOccupancies/doGetFees`, { - lotOccupancyId + burialSiteContractId }, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { @@ -2382,9 +2382,9 @@ declare const exports: Record los.populateAliases(modalElement) ;( modalElement.querySelector( - '#lotOccupancyTransactionEdit--lotOccupancyId' + '#lotOccupancyTransactionEdit--burialSiteContractId' ) as HTMLInputElement - ).value = lotOccupancyId + ).value = burialSiteContractId ;( modalElement.querySelector( '#lotOccupancyTransactionEdit--transactionIndex' @@ -2449,7 +2449,7 @@ declare const exports: Record cityssm.postJSON( `${los.urlPrefix}/lotOccupancies/doDeleteLotOccupancyTransaction`, { - lotOccupancyId, + burialSiteContractId, transactionIndex }, (rawResponseJSON) => { @@ -2714,9 +2714,9 @@ declare const exports: Record los.populateAliases(modalElement) ;( modalElement.querySelector( - '#lotOccupancyTransactionAdd--lotOccupancyId' + '#lotOccupancyTransactionAdd--burialSiteContractId' ) as HTMLInputElement - ).value = lotOccupancyId.toString() + ).value = burialSiteContractId.toString() const feeGrandTotal = getFeeGrandTotal() const transactionGrandTotal = getTransactionGrandTotal() diff --git a/public/javascripts/lotOccupancySearch.ts b/public/javascripts/lotOccupancySearch.ts index f6267511..03ac5cf5 100644 --- a/public/javascripts/lotOccupancySearch.ts +++ b/public/javascripts/lotOccupancySearch.ts @@ -52,14 +52,14 @@ declare const exports: Record let occupancyTimeHTML = '' if ( - lotOccupancy.occupancyStartDateString! <= nowDateString && - (lotOccupancy.occupancyEndDateString === '' || - lotOccupancy.occupancyEndDateString! >= nowDateString) + lotOccupancy.contractStartDateString! <= nowDateString && + (lotOccupancy.contractEndDateString === '' || + lotOccupancy.contractEndDateString! >= nowDateString) ) { occupancyTimeHTML = ` ` - } else if (lotOccupancy.occupancyStartDateString! > nowDateString) { + } else if (lotOccupancy.contractStartDateString! > nowDateString) { occupancyTimeHTML = ` ` @@ -125,23 +125,23 @@ declare const exports: Record ${occupancyTimeHTML} + href="${los.getLotOccupancyURL(lotOccupancy.burialSiteContractId)}"> ${cityssm.escapeHTML(lotOccupancy.occupancyType ?? '')}
- #${lotOccupancy.lotOccupancyId} + #${lotOccupancy.burialSiteContractId} ${ (lotOccupancy.lotId ?? -1) === -1 ? `(No ${los.escapedAliases.Lot})` : `${cityssm.escapeHTML(lotOccupancy.lotName ?? '')}` }
- ${cityssm.escapeHTML(lotOccupancy.mapName ?? '')} + ${cityssm.escapeHTML(lotOccupancy.cemeteryName ?? '')} - ${lotOccupancy.occupancyStartDateString} + ${lotOccupancy.contractStartDateString} ${ - lotOccupancy.occupancyEndDate - ? lotOccupancy.occupancyEndDateString + lotOccupancy.contractEndDate + ? lotOccupancy.contractEndDateString : '(No End Date)' } @@ -156,7 +156,7 @@ declare const exports: Record ${ lotOccupancy.printEJS ? ` + href="${los.urlPrefix}/print/${lotOccupancy.printEJS}/?burialSiteContractId=${lotOccupancy.burialSiteContractId.toString()}" target="_blank"> ` : '' @@ -170,7 +170,7 @@ declare const exports: Record ${los.escapedAliases.Occupancy} Type ${los.escapedAliases.Lot} - ${los.escapedAliases.OccupancyStartDate} + ${los.escapedAliases.contractStartDate} End Date ${los.escapedAliases.Occupants} Fees and Transactions diff --git a/public/javascripts/lotSearch.js b/public/javascripts/lotSearch.js index 4189e159..ecbc4be6 100644 --- a/public/javascripts/lotSearch.js +++ b/public/javascripts/lotSearch.js @@ -32,7 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); ${cityssm.escapeHTML(lot.lotType ?? '')} - ${lot.lotStatusId + ${lot.burialSiteStatusId ? cityssm.escapeHTML(lot.lotStatus ?? '') : '(No Status)'}
${(lot.lotOccupancyCount ?? 0) > 0 diff --git a/public/javascripts/lotSearch.ts b/public/javascripts/lotSearch.ts index d5e9fb60..8a463b03 100644 --- a/public/javascripts/lotSearch.ts +++ b/public/javascripts/lotSearch.ts @@ -53,10 +53,10 @@ declare const exports: Record ${cityssm.escapeHTML(lot.lotName ?? '')} - + ${ - lot.mapName - ? cityssm.escapeHTML(lot.mapName) + lot.cemeteryName + ? cityssm.escapeHTML(lot.cemeteryName) : '(No Name)' } @@ -64,7 +64,7 @@ declare const exports: Record ${cityssm.escapeHTML(lot.lotType ?? '')} ${ - lot.lotStatusId + lot.burialSiteStatusId ? cityssm.escapeHTML(lot.lotStatus ?? '') : '(No Status)' }
diff --git a/public/javascripts/main.ts b/public/javascripts/main.ts index 21edf94d..91b15e61 100644 --- a/public/javascripts/main.ts +++ b/public/javascripts/main.ts @@ -295,9 +295,9 @@ declare const exports: Record & { exports.aliases.externalReceiptNumber.toLowerCase() ), - OccupancyStartDate: cityssm.escapeHTML(exports.aliases.occupancyStartDate), - occupancyStartDate: cityssm.escapeHTML( - exports.aliases.occupancyStartDate.toLowerCase() + contractStartDate: cityssm.escapeHTML(exports.aliases.contractStartDate), + contractStartDate: cityssm.escapeHTML( + exports.aliases.contractStartDate.toLowerCase() ), WorkOrderOpenDate: cityssm.escapeHTML(exports.aliases.workOrderOpenDate), @@ -445,11 +445,11 @@ declare const exports: Record & { } function getMapURL( - mapId: number | string = '', + cemeteryId: number | string = '', edit = false, time = false ): string { - return getRecordURL('maps', mapId, edit, time) + return getRecordURL('maps', cemeteryId, edit, time) } function getLotURL( @@ -461,11 +461,11 @@ declare const exports: Record & { } function getLotOccupancyURL( - lotOccupancyId: number | string = '', + burialSiteContractId: number | string = '', edit = false, time = false ): string { - return getRecordURL('lotOccupancies', lotOccupancyId, edit, time) + return getRecordURL('lotOccupancies', burialSiteContractId, edit, time) } function getWorkOrderURL( diff --git a/public/javascripts/mapEdit.ts b/public/javascripts/mapEdit.ts index ba77b95f..4d6b33e6 100644 --- a/public/javascripts/mapEdit.ts +++ b/public/javascripts/mapEdit.ts @@ -10,9 +10,9 @@ declare const exports: Record ;(() => { const los = exports.los as LOS - const mapId = (document.querySelector('#map--mapId') as HTMLInputElement) + const cemeteryId = (document.querySelector('#map--cemeteryId') as HTMLInputElement) .value - const isCreate = mapId === '' + const isCreate = cemeteryId === '' const mapForm = document.querySelector('#form--map') as HTMLFormElement @@ -39,7 +39,7 @@ declare const exports: Record (rawResponseJSON) => { const responseJSON = rawResponseJSON as { success: boolean - mapId?: number + cemeteryId?: number errorMessage?: string } @@ -47,7 +47,7 @@ declare const exports: Record clearUnsavedChanges() if (isCreate) { - globalThis.location.href = los.getMapURL(responseJSON.mapId, true) + globalThis.location.href = los.getMapURL(responseJSON.cemeteryId, true) } else { bulmaJS.alert({ message: `${los.escapedAliases.Map} Updated Successfully`, @@ -83,7 +83,7 @@ declare const exports: Record cityssm.postJSON( `${los.urlPrefix}/maps/doDeleteMap`, { - mapId + cemeteryId }, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { diff --git a/public/javascripts/mapSearch.ts b/public/javascripts/mapSearch.ts index 2ac7e906..eaff5002 100644 --- a/public/javascripts/mapSearch.ts +++ b/public/javascripts/mapSearch.ts @@ -34,7 +34,7 @@ declare const exports: Record .split(' ') for (const map of maps) { - const mapSearchString = `${map.mapName ?? ''} ${ + const mapSearchString = `${map.cemeteryName ?? ''} ${ map.mapDescription ?? '' } ${map.mapAddress1 ?? ''} ${map.mapAddress2 ?? ''}`.toLowerCase() @@ -58,9 +58,9 @@ declare const exports: Record 'beforeend', ` - + ${cityssm.escapeHTML( - (map.mapName ?? '') === '' ? '(No Name)' : map.mapName ?? '' + (map.cemeteryName ?? '') === '' ? '(No Name)' : map.cemeteryName ?? '' )}
@@ -104,7 +104,7 @@ declare const exports: Record : '' } - ${map.lotCount} + ${map.lotCount} ` ) diff --git a/public/javascripts/workOrderEdit.js b/public/javascripts/workOrderEdit.js index 1b9c587e..3464d843 100644 --- a/public/javascripts/workOrderEdit.js +++ b/public/javascripts/workOrderEdit.js @@ -359,25 +359,25 @@ Object.defineProperty(exports, "__esModule", { value: true }); los.populateAliases(modalElement); modalElement.querySelector('#lotStatusEdit--lotId').value = lotId.toString(); modalElement.querySelector('#lotStatusEdit--lotName').value = lot.lotName ?? ''; - const lotStatusElement = modalElement.querySelector('#lotStatusEdit--lotStatusId'); + const lotStatusElement = modalElement.querySelector('#lotStatusEdit--burialSiteStatusId'); let lotStatusFound = false; for (const lotStatus of exports.lotStatuses) { const optionElement = document.createElement('option'); - optionElement.value = lotStatus.lotStatusId.toString(); + optionElement.value = lotStatus.burialSiteStatusId.toString(); optionElement.textContent = lotStatus.lotStatus; - if (lotStatus.lotStatusId === lot.lotStatusId) { + if (lotStatus.burialSiteStatusId === lot.burialSiteStatusId) { lotStatusFound = true; } lotStatusElement.append(optionElement); } - if (!lotStatusFound && lot.lotStatusId) { + if (!lotStatusFound && lot.burialSiteStatusId) { const optionElement = document.createElement('option'); - optionElement.value = lot.lotStatusId.toString(); + optionElement.value = lot.burialSiteStatusId.toString(); optionElement.textContent = lot.lotStatus ?? ''; lotStatusElement.append(optionElement); } - if (lot.lotStatusId) { - lotStatusElement.value = lot.lotStatusId.toString(); + if (lot.burialSiteStatusId) { + lotStatusElement.value = lot.burialSiteStatusId.toString(); } // eslint-disable-next-line no-unsanitized/method modalElement @@ -462,7 +462,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); ${cityssm.escapeHTML(lot.lotType ?? '')} - ${lot.lotStatusId + ${lot.burialSiteStatusId ? cityssm.escapeHTML(lot.lotStatus ?? '') : '(No Status)'} @@ -671,10 +671,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); searchFormElement = modalElement.querySelector('form'); searchResultsContainerElement = modalElement.querySelector('#resultsContainer--lotAdd'); modalElement.querySelector('#lotSearch--notWorkOrderId').value = workOrderId; - const lotStatusElement = modalElement.querySelector('#lotSearch--lotStatusId'); + const lotStatusElement = modalElement.querySelector('#lotSearch--burialSiteStatusId'); for (const lotStatus of exports.lotStatuses) { const optionElement = document.createElement('option'); - optionElement.value = lotStatus.lotStatusId.toString(); + optionElement.value = lotStatus.burialSiteStatusId.toString(); optionElement.textContent = lotStatus.lotStatus; lotStatusElement.append(optionElement); } @@ -686,7 +686,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); lotNameElement.addEventListener('change', doSearch); lotNameElement.focus(); modalElement - .querySelector('#lotSearch--lotStatusId') + .querySelector('#lotSearch--burialSiteStatusId') ?.addEventListener('change', doSearch); searchFormElement.addEventListener('submit', doSearch); }, diff --git a/public/javascripts/workOrderEdit.ts b/public/javascripts/workOrderEdit.ts index adbd9977..8b43710f 100644 --- a/public/javascripts/workOrderEdit.ts +++ b/public/javascripts/workOrderEdit.ts @@ -225,18 +225,18 @@ declare const exports: Record delete exports.workOrderLotOccupancies function deleteLotOccupancy(clickEvent: Event): void { - const lotOccupancyId = ( + const burialSiteContractId = ( (clickEvent.currentTarget as HTMLElement).closest( '.container--lotOccupancy' ) as HTMLElement - ).dataset.lotOccupancyId + ).dataset.burialSiteContractId function doDelete(): void { cityssm.postJSON( `${los.urlPrefix}/workOrders/doDeleteWorkOrderLotOccupancy`, { workOrderId, - lotOccupancyId + burialSiteContractId }, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { @@ -306,14 +306,14 @@ declare const exports: Record } function addLotOccupancy( - lotOccupancyId: number | string, + burialSiteContractId: number | string, callbackFunction?: (success?: boolean) => void ): void { cityssm.postJSON( `${los.urlPrefix}/workOrders/doAddWorkOrderLotOccupancy`, { workOrderId, - lotOccupancyId + burialSiteContractId }, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { @@ -372,7 +372,7 @@ declare const exports: Record ${los.escapedAliases.Occupancy} Type ${los.escapedAliases.Lot} - ${los.escapedAliases.OccupancyStartDate} + ${los.escapedAliases.contractStartDate} End Date ${los.escapedAliases.Occupants} @@ -385,12 +385,12 @@ declare const exports: Record for (const lotOccupancy of workOrderLotOccupancies) { const rowElement = document.createElement('tr') rowElement.className = 'container--lotOccupancy' - rowElement.dataset.lotOccupancyId = - lotOccupancy.lotOccupancyId.toString() + rowElement.dataset.burialSiteContractId = + lotOccupancy.burialSiteContractId.toString() const isActive = !( - lotOccupancy.occupancyEndDate && - lotOccupancy.occupancyEndDateString! < currentDateString + lotOccupancy.contractEndDate && + lotOccupancy.contractEndDateString! < currentDateString ) const hasLotRecord = @@ -405,10 +405,10 @@ declare const exports: Record : `` } - + ${cityssm.escapeHTML(lotOccupancy.occupancyType ?? '')}
- #${lotOccupancy.lotOccupancyId} + #${lotOccupancy.burialSiteContractId} ` if (lotOccupancy.lotId) { @@ -458,11 +458,11 @@ declare const exports: Record rowElement.insertAdjacentHTML( 'beforeend', ` - ${lotOccupancy.occupancyStartDateString} + ${lotOccupancy.contractStartDateString} ${ - lotOccupancy.occupancyEndDate - ? lotOccupancy.occupancyEndDateString + lotOccupancy.contractEndDate + ? lotOccupancy.contractEndDateString : '(No End Date)' } @@ -549,32 +549,32 @@ declare const exports: Record ).value = lot.lotName ?? '' const lotStatusElement = modalElement.querySelector( - '#lotStatusEdit--lotStatusId' + '#lotStatusEdit--burialSiteStatusId' ) as HTMLSelectElement let lotStatusFound = false for (const lotStatus of exports.lotStatuses as LotStatus[]) { const optionElement = document.createElement('option') - optionElement.value = lotStatus.lotStatusId.toString() + optionElement.value = lotStatus.burialSiteStatusId.toString() optionElement.textContent = lotStatus.lotStatus - if (lotStatus.lotStatusId === lot.lotStatusId) { + if (lotStatus.burialSiteStatusId === lot.burialSiteStatusId) { lotStatusFound = true } lotStatusElement.append(optionElement) } - if (!lotStatusFound && lot.lotStatusId) { + if (!lotStatusFound && lot.burialSiteStatusId) { const optionElement = document.createElement('option') - optionElement.value = lot.lotStatusId.toString() + optionElement.value = lot.burialSiteStatusId.toString() optionElement.textContent = lot.lotStatus ?? '' lotStatusElement.append(optionElement) } - if (lot.lotStatusId) { - lotStatusElement.value = lot.lotStatusId.toString() + if (lot.burialSiteStatusId) { + lotStatusElement.value = lot.burialSiteStatusId.toString() } // eslint-disable-next-line no-unsanitized/method @@ -690,12 +690,12 @@ declare const exports: Record ${cityssm.escapeHTML(lot.lotName ?? '')} - ${cityssm.escapeHTML(lot.mapName ?? '')} + ${cityssm.escapeHTML(lot.cemeteryName ?? '')} ${cityssm.escapeHTML(lot.lotType ?? '')} ${ - lot.lotStatusId + lot.burialSiteStatusId ? cityssm.escapeHTML(lot.lotStatus ?? '') : '(No Status)' } @@ -732,9 +732,9 @@ declare const exports: Record 'tr' ) as HTMLTableRowElement - const lotOccupancyId = rowElement.dataset.lotOccupancyId ?? '' + const burialSiteContractId = rowElement.dataset.burialSiteContractId ?? '' - addLotOccupancy(lotOccupancyId, (success) => { + addLotOccupancy(burialSiteContractId, (success) => { if (success) { rowElement.remove() } @@ -778,7 +778,7 @@ declare const exports: Record ${los.escapedAliases.Occupancy} Type ${los.escapedAliases.Lot} - ${los.escapedAliases.OccupancyStartDate} + ${los.escapedAliases.contractStartDate} End Date ${los.escapedAliases.Occupants} @@ -788,8 +788,8 @@ declare const exports: Record for (const lotOccupancy of responseJSON.lotOccupancies) { const rowElement = document.createElement('tr') rowElement.className = 'container--lotOccupancy' - rowElement.dataset.lotOccupancyId = - lotOccupancy.lotOccupancyId.toString() + rowElement.dataset.burialSiteContractId = + lotOccupancy.burialSiteContractId.toString() rowElement.innerHTML = `
-