diff --git a/cypress.config.js b/cypress.config.js index 30690679..f9c7694e 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -2,8 +2,8 @@ import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { baseUrl: 'http://localhost:9000', + projectId: '26a4bi', specPattern: 'cypress/e2e/**/*.cy.js', - supportFile: false, - projectId: '26a4bi' + supportFile: false } }); diff --git a/cypress.config.ts b/cypress.config.ts index f93dd9e1..f71461c4 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -3,8 +3,8 @@ import { defineConfig } from 'cypress' export default defineConfig({ e2e: { baseUrl: 'http://localhost:9000', + projectId: '26a4bi', specPattern: 'cypress/e2e/**/*.cy.js', - supportFile: false, - projectId: '26a4bi' + supportFile: false } }) diff --git a/database/addBurialSite.d.ts b/database/addBurialSite.d.ts index 0278cda2..67a30b4e 100644 --- a/database/addBurialSite.d.ts +++ b/database/addBurialSite.d.ts @@ -4,9 +4,9 @@ export interface AddBurialSiteForm { burialSiteNameSegment3?: string; burialSiteNameSegment4?: string; burialSiteNameSegment5?: string; - burialSiteTypeId: string | number; - burialSiteStatusId: string | number; - cemeteryId: string | number; + burialSiteStatusId: number | string; + burialSiteTypeId: number | string; + cemeteryId: number | string; cemeterySvgId: string; burialSiteLatitude: string; burialSiteLongitude: string; diff --git a/database/addBurialSite.ts b/database/addBurialSite.ts index a617e29e..042b7f35 100644 --- a/database/addBurialSite.ts +++ b/database/addBurialSite.ts @@ -11,16 +11,17 @@ export interface AddBurialSiteForm { burialSiteNameSegment4?: string burialSiteNameSegment5?: string - burialSiteTypeId: string | number - burialSiteStatusId: string | number + burialSiteStatusId: number | string + burialSiteTypeId: number | string - cemeteryId: string | number + cemeteryId: number | string cemeterySvgId: string burialSiteLatitude: string burialSiteLongitude: string burialSiteTypeFieldIds?: string + [fieldValue_burialSiteTypeFieldId: string]: unknown } diff --git a/database/addCemetery.d.ts b/database/addCemetery.d.ts index 008a545a..13ed47f1 100644 --- a/database/addCemetery.d.ts +++ b/database/addCemetery.d.ts @@ -1,15 +1,15 @@ export interface AddCemeteryForm { - cemeteryName: string; - cemeteryKey: string; cemeteryDescription: string; - cemeterySvg: string; + cemeteryKey: string; + cemeteryName: string; cemeteryLatitude: string; cemeteryLongitude: string; + cemeterySvg: string; cemeteryAddress1: string; cemeteryAddress2: string; cemeteryCity: string; - cemeteryProvince: string; cemeteryPostalCode: string; + cemeteryProvince: string; cemeteryPhoneNumber: string; } export default function addCemetery(addForm: AddCemeteryForm, user: User): Promise; diff --git a/database/addCemetery.ts b/database/addCemetery.ts index 9388407b..a6c2a58a 100644 --- a/database/addCemetery.ts +++ b/database/addCemetery.ts @@ -1,19 +1,20 @@ import { acquireConnection } from './pool.js' export interface AddCemeteryForm { - cemeteryName: string - cemeteryKey: string cemeteryDescription: string + cemeteryKey: string + cemeteryName: string - cemeterySvg: string cemeteryLatitude: string cemeteryLongitude: string + cemeterySvg: string cemeteryAddress1: string cemeteryAddress2: string cemeteryCity: string - cemeteryProvince: string cemeteryPostalCode: string + cemeteryProvince: string + cemeteryPhoneNumber: string } diff --git a/database/addContract.d.ts b/database/addContract.d.ts index 2a6592b0..8b0e539c 100644 --- a/database/addContract.d.ts +++ b/database/addContract.d.ts @@ -1,15 +1,28 @@ import type { PoolConnection } from 'better-sqlite-pool'; import { type DateString, type TimeString } from '@cityssm/utils-datetime'; export interface AddContractForm { - [fieldValue_contractTypeFieldId: `fieldValue_${string}`]: unknown; - birthDateString?: '' | DateString; - birthPlace?: string; burialSiteId: number | string; - committalTypeId?: number | string; contractEndDateString: '' | DateString; contractStartDateString: '' | DateString; - contractTypeFieldIds?: string; contractTypeId: number | string; + [fieldValue_contractTypeFieldId: `fieldValue_${string}`]: unknown; + contractTypeFieldIds?: string; + committalTypeId?: number | string; + funeralDateString?: '' | DateString; + funeralDirectorName?: string; + funeralHomeId?: number | string; + funeralTimeString?: '' | TimeString; + purchaserAddress1?: string; + purchaserAddress2?: string; + purchaserCity?: string; + purchaserEmail?: string; + purchaserName?: string; + purchaserPhoneNumber?: string; + purchaserPostalCode?: string; + purchaserProvince?: string; + purchaserRelationship?: string; + birthDateString?: '' | DateString; + birthPlace?: string; deathAge?: string; deathAgePeriod?: string; deathDateString?: '' | DateString; @@ -20,19 +33,6 @@ export interface AddContractForm { deceasedName?: string; deceasedPostalCode?: string; deceasedProvince?: string; - funeralDateString?: '' | DateString; - funeralDirectorName?: string; - funeralHomeId?: number | string; - funeralTimeString?: '' | TimeString; intermentContainerTypeId?: number | string; - purchaserAddress1?: string; - purchaserAddress2?: string; - purchaserCity?: string; - purchaserEmail?: string; - purchaserName?: string; - purchaserPhoneNumber?: string; - purchaserPostalCode?: string; - purchaserProvince?: string; - purchaserRelationship?: string; } export default function addContract(addForm: AddContractForm, user: User, connectedDatabase?: PoolConnection): Promise; diff --git a/database/addContract.ts b/database/addContract.ts index a5c12668..0946f9e5 100644 --- a/database/addContract.ts +++ b/database/addContract.ts @@ -2,8 +2,8 @@ import type { PoolConnection } from 'better-sqlite-pool' import { type DateString, - dateStringToInteger, type TimeString, + dateStringToInteger, timeStringToInteger } from '@cityssm/utils-datetime' @@ -11,35 +11,19 @@ import addOrUpdateContractField from './addOrUpdateContractField.js' import { acquireConnection } from './pool.js' export interface AddContractForm { - [fieldValue_contractTypeFieldId: `fieldValue_${string}`]: unknown - birthDateString?: '' | DateString - - birthPlace?: string burialSiteId: number | string + contractEndDateString: '' | DateString + contractStartDateString: '' | DateString + contractTypeId: number | string + + [fieldValue_contractTypeFieldId: `fieldValue_${string}`]: unknown + contractTypeFieldIds?: string committalTypeId?: number | string - contractEndDateString: '' | DateString - - contractStartDateString: '' | DateString - contractTypeFieldIds?: string - contractTypeId: number | string - deathAge?: string - deathAgePeriod?: string - deathDateString?: '' | DateString - deathPlace?: string - - deceasedAddress1?: string - deceasedAddress2?: string - deceasedCity?: string - deceasedName?: string - deceasedPostalCode?: string - deceasedProvince?: string - funeralDateString?: '' | DateString funeralDirectorName?: string funeralHomeId?: number | string funeralTimeString?: '' | TimeString - intermentContainerTypeId?: number | string purchaserAddress1?: string purchaserAddress2?: string @@ -50,6 +34,20 @@ export interface AddContractForm { purchaserPostalCode?: string purchaserProvince?: string purchaserRelationship?: string + + birthDateString?: '' | DateString + birthPlace?: string + deathAge?: string + deathAgePeriod?: string + deathDateString?: '' | DateString + deathPlace?: string + deceasedAddress1?: string + deceasedAddress2?: string + deceasedCity?: string + deceasedName?: string + deceasedPostalCode?: string + deceasedProvince?: string + intermentContainerTypeId?: number | string } // eslint-disable-next-line complexity diff --git a/database/addContractComment.d.ts b/database/addContractComment.d.ts index 434442a2..aba2b60b 100644 --- a/database/addContractComment.d.ts +++ b/database/addContractComment.d.ts @@ -1,8 +1,8 @@ import { type DateString, type TimeString } from '@cityssm/utils-datetime'; export interface AddContractCommentForm { - contractId: string | number; + comment: string; commentDateString?: DateString; commentTimeString?: TimeString; - comment: string; + contractId: number | string; } export default function addContractComment(commentForm: AddContractCommentForm, user: User): Promise; diff --git a/database/addContractComment.ts b/database/addContractComment.ts index 1075ec2e..c051b4fb 100644 --- a/database/addContractComment.ts +++ b/database/addContractComment.ts @@ -10,10 +10,10 @@ import { import { acquireConnection } from './pool.js' export interface AddContractCommentForm { - contractId: string | number + comment: string commentDateString?: DateString commentTimeString?: TimeString - comment: string + contractId: number | string } export default async function addContractComment( diff --git a/database/addContractFee.d.ts b/database/addContractFee.d.ts index a434c205..25453c82 100644 --- a/database/addContractFee.d.ts +++ b/database/addContractFee.d.ts @@ -2,8 +2,8 @@ import type { PoolConnection } from 'better-sqlite-pool'; export interface AddContractFeeForm { contractId: number | string; feeId: number | string; - quantity: number | string; feeAmount?: number | string; + quantity: number | string; taxAmount?: number | string; } export default function addContractFee(addFeeForm: AddContractFeeForm, user: User, connectedDatabase?: PoolConnection): Promise; diff --git a/database/addContractFee.ts b/database/addContractFee.ts index 5699304d..15b1c250 100644 --- a/database/addContractFee.ts +++ b/database/addContractFee.ts @@ -13,8 +13,9 @@ import { acquireConnection } from './pool.js' export interface AddContractFeeForm { contractId: number | string feeId: number | string - quantity: number | string + feeAmount?: number | string + quantity: number | string taxAmount?: number | string } diff --git a/database/deleteBurialSite.d.ts b/database/deleteBurialSite.d.ts new file mode 100644 index 00000000..48879dd0 --- /dev/null +++ b/database/deleteBurialSite.d.ts @@ -0,0 +1 @@ +export declare function deleteBurialSite(burialSiteId: number, user: User): Promise; diff --git a/database/deleteBurialSite.js b/database/deleteBurialSite.js new file mode 100644 index 00000000..4579a933 --- /dev/null +++ b/database/deleteBurialSite.js @@ -0,0 +1,51 @@ +import { dateToInteger } from '@cityssm/utils-datetime'; +import { acquireConnection } from './pool.js'; +export async function deleteBurialSite(burialSiteId, user) { + const database = await acquireConnection(); + /* + * Ensure no active contracts reference the burial site + */ + const currentDateInteger = dateToInteger(new Date()); + const activeContract = database + .prepare(`select contractId + from Contracts + where burialSiteId = ? + and recordDelete_timeMillis is null + and (contractEndDate is null or contractEndDate >= ?)`) + .pluck() + .get(burialSiteId, currentDateInteger); + if (activeContract !== undefined) { + database.release(); + return false; + } + /* + * Delete the burial site + */ + const rightNowMillis = Date.now(); + database + .prepare(`update BurialSites + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where burialSiteId = ? + and recordDelete_timeMillis is null`) + .run(user.userName, rightNowMillis, burialSiteId); + /* + * Delete fields and comments + */ + database + .prepare(`update BurialSiteFields + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where burialSiteId = ? + and recordDelete_timeMillis is null`) + .run(user.userName, rightNowMillis, burialSiteId); + database + .prepare(`update BurialSiteComments + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where burialSiteId = ? + and recordDelete_timeMillis is null`) + .run(user.userName, rightNowMillis, burialSiteId); + database.release(); + return true; +} diff --git a/database/deleteBurialSite.ts b/database/deleteBurialSite.ts new file mode 100644 index 00000000..6d4c1f1d --- /dev/null +++ b/database/deleteBurialSite.ts @@ -0,0 +1,76 @@ +import { dateToInteger } from '@cityssm/utils-datetime' + +import { acquireConnection } from './pool.js' + +export async function deleteBurialSite( + burialSiteId: number, + user: User +): Promise { + const database = await acquireConnection() + + /* + * Ensure no active contracts reference the burial site + */ + + const currentDateInteger = dateToInteger(new Date()) + + const activeContract = database + .prepare( + `select contractId + from Contracts + where burialSiteId = ? + and recordDelete_timeMillis is null + and (contractEndDate is null or contractEndDate >= ?)` + ) + .pluck() + .get(burialSiteId, currentDateInteger) as number | undefined + + if (activeContract !== undefined) { + database.release() + return false + } + + /* + * Delete the burial site + */ + + const rightNowMillis = Date.now() + + database + .prepare( + `update BurialSites + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where burialSiteId = ? + and recordDelete_timeMillis is null` + ) + .run(user.userName, rightNowMillis, burialSiteId) + + /* + * Delete fields and comments + */ + + database + .prepare( + `update BurialSiteFields + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where burialSiteId = ? + and recordDelete_timeMillis is null` + ) + .run(user.userName, rightNowMillis, burialSiteId) + + database + .prepare( + `update BurialSiteComments + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where burialSiteId = ? + and recordDelete_timeMillis is null` + ) + .run(user.userName, rightNowMillis, burialSiteId) + + database.release() + + return true +} diff --git a/database/deleteCemetery.d.ts b/database/deleteCemetery.d.ts new file mode 100644 index 00000000..66dfcfff --- /dev/null +++ b/database/deleteCemetery.d.ts @@ -0,0 +1 @@ +export default function deleteCemetery(cemeteryId: number | string, user: User): Promise; diff --git a/database/deleteCemetery.js b/database/deleteCemetery.js new file mode 100644 index 00000000..e245934c --- /dev/null +++ b/database/deleteCemetery.js @@ -0,0 +1,61 @@ +import { dateToInteger } from '@cityssm/utils-datetime'; +import { acquireConnection } from './pool.js'; +export default async function deleteCemetery(cemeteryId, user) { + const database = await acquireConnection(); + /* + * Ensure no active contracts reference the cemetery + */ + const currentDateInteger = dateToInteger(new Date()); + const activeContract = database + .prepare(`select contractId + from Contracts + where burialSiteId in ( + select burialSiteId from BurialSites where recordDelete_timeMillis is null and cemeteryId = ?) + and recordDelete_timeMillis is null + and (contractEndDate is null or contractEndDate >= ?)`) + .pluck() + .get(cemeteryId, currentDateInteger); + if (activeContract !== undefined) { + database.release(); + return false; + } + /* + * Delete the cemetery + */ + const rightNowMillis = Date.now(); + database + .prepare(`update Cemeteries + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where cemeteryId = ? + and recordDelete_timeMillis is null`) + .run(user.userName, rightNowMillis, cemeteryId); + /* + * Delete burial sites, fields, and comments + */ + database + .prepare(`update BurialSites + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where cemeteryId = ? + and recordDelete_timeMillis is null`) + .run(user.userName, rightNowMillis, cemeteryId); + database + .prepare(`update BurialSiteFields + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where burialSiteId in ( + select burialSiteId from BurialSites where cemeteryId = ?) + and recordDelete_timeMillis is null`) + .run(user.userName, rightNowMillis, cemeteryId); + database + .prepare(`update BurialSiteComments + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where burialSiteId in ( + select burialSiteId from BurialSites where cemeteryId = ?) + and recordDelete_timeMillis is null`) + .run(user.userName, rightNowMillis, cemeteryId); + database.release(); + return true; +} diff --git a/database/deleteCemetery.ts b/database/deleteCemetery.ts new file mode 100644 index 00000000..b89837a6 --- /dev/null +++ b/database/deleteCemetery.ts @@ -0,0 +1,89 @@ +import { dateToInteger } from '@cityssm/utils-datetime' + +import { acquireConnection } from './pool.js' + +export default async function deleteCemetery( + cemeteryId: number | string, + user: User +): Promise { + const database = await acquireConnection() + + /* + * Ensure no active contracts reference the cemetery + */ + + const currentDateInteger = dateToInteger(new Date()) + + const activeContract = database + .prepare( + `select contractId + from Contracts + where burialSiteId in ( + select burialSiteId from BurialSites where recordDelete_timeMillis is null and cemeteryId = ?) + and recordDelete_timeMillis is null + and (contractEndDate is null or contractEndDate >= ?)` + ) + .pluck() + .get(cemeteryId, currentDateInteger) as number | undefined + + if (activeContract !== undefined) { + database.release() + return false + } + + /* + * Delete the cemetery + */ + + const rightNowMillis = Date.now() + + database + .prepare( + `update Cemeteries + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where cemeteryId = ? + and recordDelete_timeMillis is null` + ) + .run(user.userName, rightNowMillis, cemeteryId) + + /* + * Delete burial sites, fields, and comments + */ + + database + .prepare( + `update BurialSites + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where cemeteryId = ? + and recordDelete_timeMillis is null` + ) + .run(user.userName, rightNowMillis, cemeteryId) + + database + .prepare( + `update BurialSiteFields + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where burialSiteId in ( + select burialSiteId from BurialSites where cemeteryId = ?) + and recordDelete_timeMillis is null` + ) + .run(user.userName, rightNowMillis, cemeteryId) + + database + .prepare( + `update BurialSiteComments + set recordDelete_userName = ?, + recordDelete_timeMillis = ? + where burialSiteId in ( + select burialSiteId from BurialSites where cemeteryId = ?) + and recordDelete_timeMillis is null` + ) + .run(user.userName, rightNowMillis, cemeteryId) + + database.release() + + return true +} diff --git a/database/deleteRecord.d.ts b/database/deleteRecord.d.ts index 6966ba3e..20e2f4fa 100644 --- a/database/deleteRecord.d.ts +++ b/database/deleteRecord.d.ts @@ -1,3 +1,3 @@ -type RecordTable = 'BurialSiteComments' | 'BurialSites' | 'BurialSiteStatuses' | 'BurialSiteTypeFields' | 'BurialSiteTypes' | 'Cemeteries' | 'ContractComments' | 'Contracts' | 'ContractTypeFields' | 'ContractTypes' | 'FeeCategories' | 'Fees' | 'FuneralHomes' | 'WorkOrderComments' | 'WorkOrderMilestones' | 'WorkOrderMilestoneTypes' | 'WorkOrders' | 'WorkOrderTypes'; +type RecordTable = 'BurialSiteComments' | 'BurialSiteStatuses' | 'BurialSiteTypeFields' | 'BurialSiteTypes' | 'ContractComments' | 'Contracts' | 'ContractTypeFields' | 'ContractTypes' | 'FeeCategories' | 'Fees' | 'FuneralHomes' | 'WorkOrderComments' | 'WorkOrderMilestones' | 'WorkOrderMilestoneTypes' | 'WorkOrders' | 'WorkOrderTypes'; export declare function deleteRecord(recordTable: RecordTable, recordId: number | string, user: User): Promise; export {}; diff --git a/database/deleteRecord.js b/database/deleteRecord.js index 0a9d320d..8aefe359 100644 --- a/database/deleteRecord.js +++ b/database/deleteRecord.js @@ -2,11 +2,9 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js'; import { acquireConnection } from './pool.js'; const recordIdColumns = new Map([ ['BurialSiteComments', 'burialSiteCommentId'], - ['BurialSites', 'burialSiteId'], ['BurialSiteStatuses', 'burialSiteStatusId'], ['BurialSiteTypeFields', 'burialSiteTypeFieldId'], ['BurialSiteTypes', 'burialSiteTypeId'], - ['Cemeteries', 'cemeteryId'], ['ContractComments', 'contractCommentId'], ['Contracts', 'contractId'], ['ContractTypeFields', 'contractTypeFieldId'], @@ -21,9 +19,7 @@ const recordIdColumns = new Map([ ['WorkOrderTypes', 'workOrderTypeId'] ]); const relatedTables = new Map([ - ['BurialSites', ['BurialSiteFields', 'BurialSiteComments']], ['BurialSiteTypes', ['BurialSiteTypeFields']], - ['Cemeteries', ['BurialSites']], ['Contracts', ['ContractFields', 'ContractComments']], ['ContractTypes', ['ContractTypePrints', 'ContractTypeFields']], [ diff --git a/database/deleteRecord.ts b/database/deleteRecord.ts index 9e65b385..e3181483 100644 --- a/database/deleteRecord.ts +++ b/database/deleteRecord.ts @@ -1,13 +1,12 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js' + import { acquireConnection } from './pool.js' type RecordTable = | 'BurialSiteComments' - | 'BurialSites' | 'BurialSiteStatuses' | 'BurialSiteTypeFields' | 'BurialSiteTypes' - | 'Cemeteries' | 'ContractComments' | 'Contracts' | 'ContractTypeFields' @@ -23,11 +22,9 @@ type RecordTable = const recordIdColumns = new Map([ ['BurialSiteComments', 'burialSiteCommentId'], - ['BurialSites', 'burialSiteId'], ['BurialSiteStatuses', 'burialSiteStatusId'], ['BurialSiteTypeFields', 'burialSiteTypeFieldId'], ['BurialSiteTypes', 'burialSiteTypeId'], - ['Cemeteries', 'cemeteryId'], ['ContractComments', 'contractCommentId'], ['Contracts', 'contractId'], ['ContractTypeFields', 'contractTypeFieldId'], @@ -43,9 +40,7 @@ const recordIdColumns = new Map([ ]) const relatedTables = new Map([ - ['BurialSites', ['BurialSiteFields', 'BurialSiteComments']], ['BurialSiteTypes', ['BurialSiteTypeFields']], - ['Cemeteries', ['BurialSites']], ['Contracts', ['ContractFields', 'ContractComments']], ['ContractTypes', ['ContractTypePrints', 'ContractTypeFields']], [ diff --git a/handlers/burialSites-post/doDeleteBurialSite.js b/handlers/burialSites-post/doDeleteBurialSite.js index 642e6057..e84b2f7c 100644 --- a/handlers/burialSites-post/doDeleteBurialSite.js +++ b/handlers/burialSites-post/doDeleteBurialSite.js @@ -1,12 +1,17 @@ -import { deleteRecord } from '../../database/deleteRecord.js'; +import { deleteBurialSite } from '../../database/deleteBurialSite.js'; import { clearNextPreviousBurialSiteIdCache } from '../../helpers/burialSites.helpers.js'; export default async function handler(request, response) { const burialSiteId = Number.parseInt(request.body.burialSiteId, 10); - const success = await deleteRecord('BurialSites', burialSiteId, request.session.user); + const success = await deleteBurialSite(burialSiteId, request.session.user); response.json({ + errorMessage: success + ? '' + : 'Note that burial sites with active contracts cannot be deleted.', success }); - response.on('finish', () => { - clearNextPreviousBurialSiteIdCache(burialSiteId); - }); + if (success) { + response.on('finish', () => { + clearNextPreviousBurialSiteIdCache(burialSiteId); + }); + } } diff --git a/handlers/burialSites-post/doDeleteBurialSite.ts b/handlers/burialSites-post/doDeleteBurialSite.ts index 705ff343..9fe37d41 100644 --- a/handlers/burialSites-post/doDeleteBurialSite.ts +++ b/handlers/burialSites-post/doDeleteBurialSite.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express' -import { deleteRecord } from '../../database/deleteRecord.js' +import { deleteBurialSite } from '../../database/deleteBurialSite.js' import { clearNextPreviousBurialSiteIdCache } from '../../helpers/burialSites.helpers.js' export default async function handler( @@ -9,17 +9,21 @@ export default async function handler( ): Promise { const burialSiteId = Number.parseInt(request.body.burialSiteId, 10) - const success = await deleteRecord( - 'BurialSites', + const success = await deleteBurialSite( burialSiteId, request.session.user as User ) response.json({ + errorMessage: success + ? '' + : 'Note that burial sites with active contracts cannot be deleted.', success }) - response.on('finish', () => { - clearNextPreviousBurialSiteIdCache(burialSiteId) - }) + if (success) { + response.on('finish', () => { + clearNextPreviousBurialSiteIdCache(burialSiteId) + }) + } } diff --git a/handlers/cemeteries-post/doDeleteCemetery.d.ts b/handlers/cemeteries-post/doDeleteCemetery.d.ts index 9c8cc345..f4f9ece7 100644 --- a/handlers/cemeteries-post/doDeleteCemetery.d.ts +++ b/handlers/cemeteries-post/doDeleteCemetery.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/cemeteries-post/doDeleteCemetery.js b/handlers/cemeteries-post/doDeleteCemetery.js index ca75cff2..025613bd 100644 --- a/handlers/cemeteries-post/doDeleteCemetery.js +++ b/handlers/cemeteries-post/doDeleteCemetery.js @@ -1,11 +1,16 @@ -import { deleteRecord } from '../../database/deleteRecord.js'; +import deleteCemetery from '../../database/deleteCemetery.js'; import { clearNextPreviousBurialSiteIdCache } from '../../helpers/burialSites.helpers.js'; export default async function handler(request, response) { - const success = await deleteRecord('Cemeteries', request.body.cemeteryId, request.session.user); + const success = await deleteCemetery(request.body.cemeteryId, request.session.user); response.json({ + errorMessage: success + ? '' + : 'Note that cemeteries with active contracts cannot be deleted.', success }); - response.on('finish', () => { - clearNextPreviousBurialSiteIdCache(-1); - }); + if (success) { + response.on('finish', () => { + clearNextPreviousBurialSiteIdCache(-1); + }); + } } diff --git a/handlers/cemeteries-post/doDeleteCemetery.ts b/handlers/cemeteries-post/doDeleteCemetery.ts index ad1d47c8..5cb5256d 100644 --- a/handlers/cemeteries-post/doDeleteCemetery.ts +++ b/handlers/cemeteries-post/doDeleteCemetery.ts @@ -1,23 +1,27 @@ import type { Request, Response } from 'express' -import { deleteRecord } from '../../database/deleteRecord.js' +import deleteCemetery from '../../database/deleteCemetery.js' import { clearNextPreviousBurialSiteIdCache } from '../../helpers/burialSites.helpers.js' export default async function handler( - request: Request, + request: Request, response: Response ): Promise { - const success = await deleteRecord( - 'Cemeteries', + const success = await deleteCemetery( request.body.cemeteryId, request.session.user as User ) response.json({ + errorMessage: success + ? '' + : 'Note that cemeteries with active contracts cannot be deleted.', success }) - response.on('finish', () => { - clearNextPreviousBurialSiteIdCache(-1) - }) + if (success) { + response.on('finish', () => { + clearNextPreviousBurialSiteIdCache(-1) + }) + } } diff --git a/helpers/functions.database.d.ts b/helpers/functions.database.d.ts index 04e6541a..78075fb7 100644 --- a/helpers/functions.database.d.ts +++ b/helpers/functions.database.d.ts @@ -1 +1 @@ -export declare function backupDatabase(): Promise; +export declare function backupDatabase(): Promise; diff --git a/helpers/functions.database.ts b/helpers/functions.database.ts index 95bc0f53..793eab3b 100644 --- a/helpers/functions.database.ts +++ b/helpers/functions.database.ts @@ -5,7 +5,7 @@ import { sunriseDB as databasePath } from '../helpers/database.helpers.js' -export async function backupDatabase(): Promise { +export async function backupDatabase(): Promise { const databasePathSplit = databasePath.split(/[/\\]/) const backupDatabasePath = `${backupFolder}/${databasePathSplit.at(-1)}.${Date.now().toString()}` diff --git a/helpers/functions.print.d.ts b/helpers/functions.print.d.ts index 48ac6e1a..ecbd9a9f 100644 --- a/helpers/functions.print.d.ts +++ b/helpers/functions.print.d.ts @@ -1,7 +1,7 @@ import type { BurialSite, Contract, WorkOrder } from '../types/recordTypes.js'; interface PrintConfig { - title: string; params: string[]; + title: string; } interface ReportData { headTitle: string; @@ -9,8 +9,8 @@ interface ReportData { contract?: Contract; workOrder?: WorkOrder; configFunctions: unknown; - dateTimeFunctions: unknown; contractFunctions: unknown; + dateTimeFunctions: unknown; } export declare function getScreenPrintConfig(printName: string): PrintConfig | undefined; export declare function getPdfPrintConfig(printName: string): PrintConfig | undefined; diff --git a/helpers/functions.print.js b/helpers/functions.print.js index c44a38fd..1138c1b1 100644 --- a/helpers/functions.print.js +++ b/helpers/functions.print.js @@ -40,12 +40,12 @@ export function getPdfPrintConfig(printName) { export function getPrintConfig(screenOrPdfPrintName) { const printNameSplit = screenOrPdfPrintName.split('/'); switch (printNameSplit[0]) { - case 'screen': { - return getScreenPrintConfig(printNameSplit[1]); - } case 'pdf': { return getPdfPrintConfig(printNameSplit[1]); } + case 'screen': { + return getScreenPrintConfig(printNameSplit[1]); + } } return undefined; } @@ -53,8 +53,8 @@ export async function getReportData(printConfig, requestQuery) { const reportData = { headTitle: printConfig.title, configFunctions, - dateTimeFunctions, - contractFunctions + contractFunctions, + dateTimeFunctions }; if (printConfig.params.includes('contractId') && typeof requestQuery.contractId === 'string') { diff --git a/helpers/functions.print.ts b/helpers/functions.print.ts index dccb11a4..c90e3c54 100644 --- a/helpers/functions.print.ts +++ b/helpers/functions.print.ts @@ -12,8 +12,8 @@ import * as configFunctions from './config.helpers.js' import * as contractFunctions from './contracts.helpers.js' interface PrintConfig { - title: string params: string[] + title: string } interface ReportData { @@ -24,8 +24,8 @@ interface ReportData { workOrder?: WorkOrder configFunctions: unknown - dateTimeFunctions: unknown contractFunctions: unknown + dateTimeFunctions: unknown } const screenPrintConfigs: Record = { @@ -72,12 +72,12 @@ export function getPrintConfig( const printNameSplit = screenOrPdfPrintName.split('/') switch (printNameSplit[0]) { - case 'screen': { - return getScreenPrintConfig(printNameSplit[1]) - } case 'pdf': { return getPdfPrintConfig(printNameSplit[1]) } + case 'screen': { + return getScreenPrintConfig(printNameSplit[1]) + } } return undefined @@ -89,9 +89,10 @@ export async function getReportData( ): Promise { const reportData: ReportData = { headTitle: printConfig.title, + configFunctions, - dateTimeFunctions, - contractFunctions + contractFunctions, + dateTimeFunctions } if ( diff --git a/helpers/functions.sqlFilters.d.ts b/helpers/functions.sqlFilters.d.ts index 679f35bf..17678893 100644 --- a/helpers/functions.sqlFilters.d.ts +++ b/helpers/functions.sqlFilters.d.ts @@ -1,10 +1,10 @@ -type BurialSiteNameSearchType = 'startsWith' | 'endsWith' | ''; +type BurialSiteNameSearchType = '' | 'endsWith' | 'startsWith'; +type ContractTime = '' | 'current' | 'future' | 'past'; interface WhereClauseReturn { - sqlWhereClause: string; sqlParameters: unknown[]; + sqlWhereClause: string; } export declare function getBurialSiteNameWhereClause(burialSiteName?: string, burialSiteNameSearchType?: BurialSiteNameSearchType, burialSitesTableAlias?: string): WhereClauseReturn; -type ContractTime = '' | 'current' | 'past' | 'future'; export declare function getContractTimeWhereClause(contractTime: ContractTime | undefined, contractsTableAlias?: string): WhereClauseReturn; export declare function getDeceasedNameWhereClause(deceasedName?: string, tableAlias?: string): WhereClauseReturn; export {}; diff --git a/helpers/functions.sqlFilters.js b/helpers/functions.sqlFilters.js index a99a3671..6b4c5911 100644 --- a/helpers/functions.sqlFilters.js +++ b/helpers/functions.sqlFilters.js @@ -4,13 +4,13 @@ export function getBurialSiteNameWhereClause(burialSiteName = '', burialSiteName const sqlParameters = []; if (burialSiteName !== '') { switch (burialSiteNameSearchType) { - case 'startsWith': { - sqlWhereClause += ` and ${burialSitesTableAlias}.burialSiteName like ? || '%'`; + case 'endsWith': { + sqlWhereClause += ` and ${burialSitesTableAlias}.burialSiteName like '%' || ?`; sqlParameters.push(burialSiteName); break; } - case 'endsWith': { - sqlWhereClause += ` and ${burialSitesTableAlias}.burialSiteName like '%' || ?`; + case 'startsWith': { + sqlWhereClause += ` and ${burialSitesTableAlias}.burialSiteName like ? || '%'`; sqlParameters.push(burialSiteName); break; } @@ -29,8 +29,8 @@ export function getBurialSiteNameWhereClause(burialSiteName = '', burialSiteName } } return { - sqlWhereClause, - sqlParameters + sqlParameters, + sqlWhereClause }; } export function getContractTimeWhereClause(contractTime, contractsTableAlias = 'o') { @@ -45,22 +45,22 @@ export function getContractTimeWhereClause(contractTime, contractsTableAlias = ' sqlParameters.push(currentDateString, currentDateString); break; } - case 'past': { - sqlWhereClause += - ` and ${contractsTableAlias}.contractEndDate < ?`; - sqlParameters.push(currentDateString); - break; - } case 'future': { sqlWhereClause += ` and ${contractsTableAlias}.contractStartDate > ?`; sqlParameters.push(currentDateString); break; } + case 'past': { + sqlWhereClause += + ` and ${contractsTableAlias}.contractEndDate < ?`; + sqlParameters.push(currentDateString); + break; + } } return { - sqlWhereClause, - sqlParameters + sqlParameters, + sqlWhereClause }; } export function getDeceasedNameWhereClause(deceasedName = '', tableAlias = 'o') { @@ -77,7 +77,7 @@ export function getDeceasedNameWhereClause(deceasedName = '', tableAlias = 'o') sqlParameters.push(namePiece); } return { - sqlWhereClause, - sqlParameters + sqlParameters, + sqlWhereClause }; } diff --git a/helpers/functions.sqlFilters.ts b/helpers/functions.sqlFilters.ts index 25c20cb5..47c5a2ec 100644 --- a/helpers/functions.sqlFilters.ts +++ b/helpers/functions.sqlFilters.ts @@ -1,10 +1,12 @@ import { dateToInteger } from '@cityssm/utils-datetime' -type BurialSiteNameSearchType = 'startsWith' | 'endsWith' | '' +type BurialSiteNameSearchType = '' | 'endsWith' | 'startsWith' + +type ContractTime = '' | 'current' | 'future' | 'past' interface WhereClauseReturn { - sqlWhereClause: string sqlParameters: unknown[] + sqlWhereClause: string } export function getBurialSiteNameWhereClause( @@ -17,13 +19,13 @@ export function getBurialSiteNameWhereClause( if (burialSiteName !== '') { switch (burialSiteNameSearchType) { - case 'startsWith': { - sqlWhereClause += ` and ${burialSitesTableAlias}.burialSiteName like ? || '%'` + case 'endsWith': { + sqlWhereClause += ` and ${burialSitesTableAlias}.burialSiteName like '%' || ?` sqlParameters.push(burialSiteName) break } - case 'endsWith': { - sqlWhereClause += ` and ${burialSitesTableAlias}.burialSiteName like '%' || ?` + case 'startsWith': { + sqlWhereClause += ` and ${burialSitesTableAlias}.burialSiteName like ? || '%'` sqlParameters.push(burialSiteName) break } @@ -47,13 +49,11 @@ export function getBurialSiteNameWhereClause( } return { - sqlWhereClause, - sqlParameters + sqlParameters, + sqlWhereClause } } -type ContractTime = '' | 'current' | 'past' | 'future' - export function getContractTimeWhereClause( contractTime: ContractTime | undefined, contractsTableAlias = 'o' @@ -72,24 +72,24 @@ export function getContractTimeWhereClause( break } - case 'past': { - sqlWhereClause += - ` and ${contractsTableAlias}.contractEndDate < ?` - sqlParameters.push(currentDateString) - break - } - case 'future': { sqlWhereClause += ` and ${contractsTableAlias}.contractStartDate > ?` sqlParameters.push(currentDateString) break } + + case 'past': { + sqlWhereClause += + ` and ${contractsTableAlias}.contractEndDate < ?` + sqlParameters.push(currentDateString) + break + } } return { - sqlWhereClause, - sqlParameters + sqlParameters, + sqlWhereClause } } @@ -115,7 +115,7 @@ export function getDeceasedNameWhereClause( } return { - sqlWhereClause, - sqlParameters + sqlParameters, + sqlWhereClause } } diff --git a/package-lock.json b/package-lock.json index 4b715360..42feec6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -67,7 +67,7 @@ "axe-core": "^4.10.3", "cypress": "^14.2.0", "cypress-axe": "^1.6.0", - "eslint-config-cityssm": "^22.1.0", + "eslint-config-cityssm": "^22.2.2", "nodemon": "^3.1.9", "prettier-config-cityssm": "^1.0.0" }, @@ -4915,9 +4915,9 @@ } }, "node_modules/eslint-config-cityssm": { - "version": "22.1.0", - "resolved": "https://registry.npmjs.org/eslint-config-cityssm/-/eslint-config-cityssm-22.1.0.tgz", - "integrity": "sha512-JfF7dzleImnd78sM0+NpvZpKgT+NvB4SlFXd/gXf0t1F1HQbaZftEL7zJ9eATWklF9lcj6tiYMDaZekHVuFaJw==", + "version": "22.2.2", + "resolved": "https://registry.npmjs.org/eslint-config-cityssm/-/eslint-config-cityssm-22.2.2.tgz", + "integrity": "sha512-gPPoAb1REP5Fob9poF6OEn/+fr4oflx7aa09gLZ7Nab28bl4Jsk/Pyr+KvAw39MXVdFRLPfCV1Rly0enpGlZmg==", "dev": true, "license": "Unlicense", "dependencies": { diff --git a/package.json b/package.json index 90a91ee9..594f60d5 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "axe-core": "^4.10.3", "cypress": "^14.2.0", "cypress-axe": "^1.6.0", - "eslint-config-cityssm": "^22.1.0", + "eslint-config-cityssm": "^22.2.2", "nodemon": "^3.1.9", "prettier-config-cityssm": "^1.0.0" }, diff --git a/public/javascripts/burialSite.edit.ts b/public/javascripts/burialSite.edit.ts index 2c551f41..1bb56c49 100644 --- a/public/javascripts/burialSite.edit.ts +++ b/public/javascripts/burialSite.edit.ts @@ -52,9 +52,9 @@ declare const exports: Record formElement, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { - success: boolean burialSiteId?: number errorMessage?: string + success: boolean } if (responseJSON.success) { @@ -106,8 +106,8 @@ declare const exports: Record }, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { - success: boolean errorMessage?: string + success: boolean } if (responseJSON.success) { @@ -309,9 +309,9 @@ declare const exports: Record editFormElement, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { - success: boolean - errorMessage?: string burialSiteComments: BurialSiteComment[] + errorMessage?: string + success: boolean } if (responseJSON.success) { diff --git a/public/javascripts/contract.edit.ts b/public/javascripts/contract.edit.ts index ea7bb02c..8247818e 100644 --- a/public/javascripts/contract.edit.ts +++ b/public/javascripts/contract.edit.ts @@ -54,9 +54,10 @@ declare const exports: Record formElement, (rawResponseJSON) => { const responseJSON = rawResponseJSON as { - success: boolean - contractId?: number errorMessage?: string + success: boolean + + contractId?: number } if (responseJSON.success) {