From f6eb3bf550b1852f09ea44e81b602a0946be0176 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Fri, 25 Apr 2025 10:52:55 -0400 Subject: [PATCH] create burial site from contract closes #7 --- database/addBurialSite.d.ts | 13 +- database/addBurialSite.js | 7 +- database/addBurialSite.ts | 17 ++- .../burialSites-post/doCreateBurialSite.js | 5 +- .../burialSites-post/doCreateBurialSite.ts | 5 +- handlers/contracts-get/edit.js | 18 ++- handlers/contracts-get/edit.ts | 25 +++ handlers/contracts-get/new.js | 15 +- handlers/contracts-get/new.ts | 21 ++- public/html/contract-selectBurialSite.html | 144 +++++++++++++----- public/javascripts/contract.edit.js | 52 +++++++ public/javascripts/contract.edit.ts | 117 +++++++++++++- views/burialSite-edit.ejs | 2 +- views/contract-edit.ejs | 55 +++++++ 14 files changed, 433 insertions(+), 63 deletions(-) diff --git a/database/addBurialSite.d.ts b/database/addBurialSite.d.ts index 40fe226c..de8913ed 100644 --- a/database/addBurialSite.d.ts +++ b/database/addBurialSite.d.ts @@ -6,11 +6,11 @@ export interface AddBurialSiteForm { burialSiteNameSegment5?: string; burialSiteStatusId: number | string; burialSiteTypeId: number | string; - burialSiteImage: string; + burialSiteImage?: string; cemeteryId: number | string; - cemeterySvgId: string; - burialSiteLatitude: string; - burialSiteLongitude: string; + cemeterySvgId?: string; + burialSiteLatitude?: string; + burialSiteLongitude?: string; burialSiteTypeFieldIds?: string; [fieldValue_burialSiteTypeFieldId: string]: unknown; } @@ -21,4 +21,7 @@ export interface AddBurialSiteForm { * @returns The new burial site's id. * @throws If an active burial site with the same name already exists. */ -export default function addBurialSite(burialSiteForm: AddBurialSiteForm, user: User): number; +export default function addBurialSite(burialSiteForm: AddBurialSiteForm, user: User): { + burialSiteId: number; + burialSiteName: string; +}; diff --git a/database/addBurialSite.js b/database/addBurialSite.js index 1119204c..c6e4cc34 100644 --- a/database/addBurialSite.js +++ b/database/addBurialSite.js @@ -48,7 +48,7 @@ export default function addBurialSite(burialSiteForm, user) { ?, ?, ?, ?)`) .run(burialSiteForm.burialSiteNameSegment1 ?? '', burialSiteForm.burialSiteNameSegment2 ?? '', burialSiteForm.burialSiteNameSegment3 ?? '', burialSiteForm.burialSiteNameSegment4 ?? '', burialSiteForm.burialSiteNameSegment5 ?? '', burialSiteName, burialSiteForm.burialSiteTypeId, burialSiteForm.burialSiteStatusId === '' ? undefined - : burialSiteForm.burialSiteStatusId, burialSiteForm.cemeteryId === '' ? undefined : burialSiteForm.cemeteryId, burialSiteForm.cemeterySvgId, burialSiteForm.burialSiteImage, burialSiteForm.burialSiteLatitude === '' + : burialSiteForm.burialSiteStatusId, burialSiteForm.cemeteryId === '' ? undefined : burialSiteForm.cemeteryId, burialSiteForm.cemeterySvgId, burialSiteForm.burialSiteImage ?? '', burialSiteForm.burialSiteLatitude === '' ? undefined : burialSiteForm.burialSiteLatitude, burialSiteForm.burialSiteLongitude === '' ? undefined @@ -66,5 +66,8 @@ export default function addBurialSite(burialSiteForm, user) { } } database.close(); - return burialSiteId; + return { + burialSiteId, + burialSiteName + }; } diff --git a/database/addBurialSite.ts b/database/addBurialSite.ts index 91324147..a3108954 100644 --- a/database/addBurialSite.ts +++ b/database/addBurialSite.ts @@ -16,12 +16,12 @@ export interface AddBurialSiteForm { burialSiteStatusId: number | string burialSiteTypeId: number | string - burialSiteImage: string + burialSiteImage?: string cemeteryId: number | string - cemeterySvgId: string + cemeterySvgId?: string - burialSiteLatitude: string - burialSiteLongitude: string + burialSiteLatitude?: string + burialSiteLongitude?: string burialSiteTypeFieldIds?: string @@ -38,7 +38,7 @@ export interface AddBurialSiteForm { export default function addBurialSite( burialSiteForm: AddBurialSiteForm, user: User -): number { +): { burialSiteId: number; burialSiteName: string } { const database = sqlite(sunriseDB) const rightNowMillis = Date.now() @@ -102,7 +102,7 @@ export default function addBurialSite( : burialSiteForm.burialSiteStatusId, burialSiteForm.cemeteryId === '' ? undefined : burialSiteForm.cemeteryId, burialSiteForm.cemeterySvgId, - burialSiteForm.burialSiteImage, + burialSiteForm.burialSiteImage ?? '', burialSiteForm.burialSiteLatitude === '' ? undefined : burialSiteForm.burialSiteLatitude, @@ -141,5 +141,8 @@ export default function addBurialSite( database.close() - return burialSiteId + return { + burialSiteId, + burialSiteName + } } diff --git a/handlers/burialSites-post/doCreateBurialSite.js b/handlers/burialSites-post/doCreateBurialSite.js index cdd1c36a..da89a837 100644 --- a/handlers/burialSites-post/doCreateBurialSite.js +++ b/handlers/burialSites-post/doCreateBurialSite.js @@ -2,10 +2,11 @@ import addBurialSite from '../../database/addBurialSite.js'; import { clearNextPreviousBurialSiteIdCache } from '../../helpers/burialSites.helpers.js'; export default function handler(request, response) { try { - const burialSiteId = addBurialSite(request.body, request.session.user); + const burialSite = addBurialSite(request.body, request.session.user); response.json({ success: true, - burialSiteId + burialSiteId: burialSite.burialSiteId, + burialSiteName: burialSite.burialSiteName, }); response.on('finish', () => { clearNextPreviousBurialSiteIdCache(-1); diff --git a/handlers/burialSites-post/doCreateBurialSite.ts b/handlers/burialSites-post/doCreateBurialSite.ts index fa28a54f..98ecb870 100644 --- a/handlers/burialSites-post/doCreateBurialSite.ts +++ b/handlers/burialSites-post/doCreateBurialSite.ts @@ -10,7 +10,7 @@ export default function handler( response: Response ): void { try { - const burialSiteId = addBurialSite( + const burialSite = addBurialSite( request.body, request.session.user as User ) @@ -18,7 +18,8 @@ export default function handler( response.json({ success: true, - burialSiteId + burialSiteId: burialSite.burialSiteId, + burialSiteName: burialSite.burialSiteName, }) response.on('finish', () => { diff --git a/handlers/contracts-get/edit.js b/handlers/contracts-get/edit.js index d3cd1695..bb133120 100644 --- a/handlers/contracts-get/edit.js +++ b/handlers/contracts-get/edit.js @@ -1,7 +1,8 @@ +import getCemeteries from '../../database/getCemeteries.js'; import getContract from '../../database/getContract.js'; import getFuneralHomes from '../../database/getFuneralHomes.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; -import { getCommittalTypes, getContractTypePrintsById, getContractTypes, getIntermentContainerTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteStatuses, getBurialSiteTypes, getCommittalTypes, getContractTypePrintsById, getContractTypes, getIntermentContainerTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const contract = await getContract(request.params.contractId); if (contract === undefined) { @@ -9,10 +10,22 @@ export default async function handler(request, response) { return; } const contractTypePrints = getContractTypePrintsById(contract.contractTypeId); + /* + * Contract Drop Lists + */ const contractTypes = getContractTypes(); const funeralHomes = getFuneralHomes(); const committalTypes = getCommittalTypes(); const intermentContainerTypes = getIntermentContainerTypes(); + /* + * Burial Site Drop Lists + */ + const burialSiteStatuses = getBurialSiteStatuses(); + const burialSiteTypes = getBurialSiteTypes(); + const cemeteries = getCemeteries(); + /* + * Work Order Drop Lists + */ const workOrderTypes = getWorkOrderTypes(); response.render('contract-edit', { headTitle: 'Contract Update', @@ -22,6 +35,9 @@ export default async function handler(request, response) { contractTypes, funeralHomes, intermentContainerTypes, + burialSiteStatuses, + burialSiteTypes, + cemeteries, workOrderTypes, isCreate: false }); diff --git a/handlers/contracts-get/edit.ts b/handlers/contracts-get/edit.ts index c3398f1b..15522bcd 100644 --- a/handlers/contracts-get/edit.ts +++ b/handlers/contracts-get/edit.ts @@ -1,9 +1,12 @@ import type { Request, Response } from 'express' +import getCemeteries from '../../database/getCemeteries.js' import getContract from '../../database/getContract.js' import getFuneralHomes from '../../database/getFuneralHomes.js' import { getConfigProperty } from '../../helpers/config.helpers.js' import { + getBurialSiteStatuses, + getBurialSiteTypes, getCommittalTypes, getContractTypePrintsById, getContractTypes, @@ -28,10 +31,27 @@ export default async function handler( const contractTypePrints = getContractTypePrintsById(contract.contractTypeId) + /* + * Contract Drop Lists + */ + const contractTypes = getContractTypes() const funeralHomes = getFuneralHomes() const committalTypes = getCommittalTypes() const intermentContainerTypes = getIntermentContainerTypes() + + /* + * Burial Site Drop Lists + */ + + const burialSiteStatuses = getBurialSiteStatuses() + const burialSiteTypes = getBurialSiteTypes() + const cemeteries = getCemeteries() + + /* + * Work Order Drop Lists + */ + const workOrderTypes = getWorkOrderTypes() response.render('contract-edit', { @@ -44,6 +64,11 @@ export default async function handler( contractTypes, funeralHomes, intermentContainerTypes, + + burialSiteStatuses, + burialSiteTypes, + cemeteries, + workOrderTypes, isCreate: false diff --git a/handlers/contracts-get/new.js b/handlers/contracts-get/new.js index 633b42fe..396df70e 100644 --- a/handlers/contracts-get/new.js +++ b/handlers/contracts-get/new.js @@ -1,8 +1,9 @@ import { dateToInteger, dateToString } from '@cityssm/utils-datetime'; import getBurialSite from '../../database/getBurialSite.js'; +import getCemeteries from '../../database/getCemeteries.js'; import getFuneralHomes from '../../database/getFuneralHomes.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; -import { getCommittalTypes, getContractTypes, getIntermentContainerTypes } from '../../helpers/functions.cache.js'; +import { getBurialSiteStatuses, getBurialSiteTypes, getCommittalTypes, getContractTypes, getIntermentContainerTypes } from '../../helpers/functions.cache.js'; export default async function handler(request, response) { const startDate = new Date(); const contract = { @@ -21,10 +22,19 @@ export default async function handler(request, response) { contract.cemeteryName = burialSite.cemeteryName; } } + /* + * Contract Drop Lists + */ const contractTypes = getContractTypes(); const funeralHomes = getFuneralHomes(); const committalTypes = getCommittalTypes(); const intermentContainerTypes = getIntermentContainerTypes(); + /* + * Burial Site Drop Lists + */ + const burialSiteStatuses = getBurialSiteStatuses(); + const burialSiteTypes = getBurialSiteTypes(); + const cemeteries = getCemeteries(); response.render('contract-edit', { headTitle: 'Create a New Contract', contract, @@ -32,6 +42,9 @@ export default async function handler(request, response) { contractTypes, funeralHomes, intermentContainerTypes, + burialSiteStatuses, + burialSiteTypes, + cemeteries, isCreate: true }); } diff --git a/handlers/contracts-get/new.ts b/handlers/contracts-get/new.ts index d6fa4216..cbd371f6 100644 --- a/handlers/contracts-get/new.ts +++ b/handlers/contracts-get/new.ts @@ -3,9 +3,12 @@ import type { Request, Response } from 'express' import { dateToInteger, dateToString } from '@cityssm/utils-datetime' import getBurialSite from '../../database/getBurialSite.js' +import getCemeteries from '../../database/getCemeteries.js' import getFuneralHomes from '../../database/getFuneralHomes.js' import { getConfigProperty } from '../../helpers/config.helpers.js' import { + getBurialSiteStatuses, + getBurialSiteTypes, getCommittalTypes, getContractTypes, getIntermentContainerTypes @@ -20,7 +23,7 @@ export default async function handler( const contract: Partial = { isPreneed: false, - + contractStartDate: dateToInteger(startDate), contractStartDateString: dateToString(startDate), purchaserCity: getConfigProperty('settings.cityDefault'), @@ -38,11 +41,23 @@ export default async function handler( } } + /* + * Contract Drop Lists + */ + const contractTypes = getContractTypes() const funeralHomes = getFuneralHomes() const committalTypes = getCommittalTypes() const intermentContainerTypes = getIntermentContainerTypes() + /* + * Burial Site Drop Lists + */ + + const burialSiteStatuses = getBurialSiteStatuses() + const burialSiteTypes = getBurialSiteTypes() + const cemeteries = getCemeteries() + response.render('contract-edit', { headTitle: 'Create a New Contract', @@ -53,6 +68,10 @@ export default async function handler( funeralHomes, intermentContainerTypes, + burialSiteStatuses, + burialSiteTypes, + cemeteries, + isCreate: true }) } diff --git a/public/html/contract-selectBurialSite.html b/public/html/contract-selectBurialSite.html index 2300292b..89cda321 100644 --- a/public/html/contract-selectBurialSite.html +++ b/public/html/contract-selectBurialSite.html @@ -12,45 +12,113 @@ >