diff --git a/database/deleteBurialSite.js b/database/deleteBurialSite.js index 9410c475..610bb691 100644 --- a/database/deleteBurialSite.js +++ b/database/deleteBurialSite.js @@ -30,23 +30,6 @@ export function deleteBurialSite(burialSiteId, user) { 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.close(); return true; } diff --git a/database/deleteBurialSite.ts b/database/deleteBurialSite.ts index 95fd442c..21f167ba 100644 --- a/database/deleteBurialSite.ts +++ b/database/deleteBurialSite.ts @@ -44,30 +44,6 @@ export function deleteBurialSite(burialSiteId: number, user: User): boolean { ) .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.close() return true diff --git a/database/getBurialSite.d.ts b/database/getBurialSite.d.ts index d8f77727..e72f75b0 100644 --- a/database/getBurialSite.d.ts +++ b/database/getBurialSite.d.ts @@ -1,3 +1,3 @@ import type { BurialSite } from '../types/record.types.js'; -export default function getBurialSite(burialSiteId: number | string): Promise; -export declare function getBurialSiteByBurialSiteName(burialSiteName: string): Promise; +export default function getBurialSite(burialSiteId: number | string, includeDeleted?: boolean): Promise; +export declare function getBurialSiteByBurialSiteName(burialSiteName: string, includeDeleted?: boolean): Promise; diff --git a/database/getBurialSite.js b/database/getBurialSite.js index 407dcc3a..862ed849 100644 --- a/database/getBurialSite.js +++ b/database/getBurialSite.js @@ -19,22 +19,25 @@ const baseSQL = `select l.burialSiteId, l.cemeteryId, m.cemeteryName, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, l.cemeterySvgId, l.burialSiteImage, - l.burialSiteLatitude, l.burialSiteLongitude + l.burialSiteLatitude, l.burialSiteLongitude, + + l.recordDelete_userName, l.recordDelete_timeMillis 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 - where l.recordDelete_timeMillis is null`; -export default async function getBurialSite(burialSiteId) { - return await _getBurialSite(`${baseSQL} and l.burialSiteId = ?`, burialSiteId); + left join Cemeteries m on l.cemeteryId = m.cemeteryId`; +export default async function getBurialSite(burialSiteId, includeDeleted = false) { + return await _getBurialSite(`l.burialSiteId = ?`, burialSiteId, includeDeleted); } -export async function getBurialSiteByBurialSiteName(burialSiteName) { - return await _getBurialSite(`${baseSQL} and l.burialSiteName = ?`, burialSiteName); +export async function getBurialSiteByBurialSiteName(burialSiteName, includeDeleted = false) { + return await _getBurialSite(`l.burialSiteName = ?`, burialSiteName, includeDeleted); } -async function _getBurialSite(sql, burialSiteIdOrLotName) { +async function _getBurialSite(whereClausePiece, burialSiteIdOrLotName, includeDeleted = false) { const database = sqlite(sunriseDB, { readonly: true }); - const burialSite = database.prepare(sql).get(burialSiteIdOrLotName); + const burialSite = database + .prepare(`${baseSQL} ${includeDeleted ? 'where' : 'where l.recordDelete_timeMillis is null and'} ${whereClausePiece}`) + .get(burialSiteIdOrLotName); if (burialSite !== undefined) { const contracts = await getContracts({ burialSiteId: burialSite.burialSiteId diff --git a/database/getBurialSite.ts b/database/getBurialSite.ts index 53c42638..624893d5 100644 --- a/database/getBurialSite.ts +++ b/database/getBurialSite.ts @@ -23,38 +23,49 @@ const baseSQL = `select l.burialSiteId, l.cemeteryId, m.cemeteryName, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, l.cemeterySvgId, l.burialSiteImage, - l.burialSiteLatitude, l.burialSiteLongitude + l.burialSiteLatitude, l.burialSiteLongitude, + + l.recordDelete_userName, l.recordDelete_timeMillis 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 - where l.recordDelete_timeMillis is null` + left join Cemeteries m on l.cemeteryId = m.cemeteryId` export default async function getBurialSite( - burialSiteId: number | string + burialSiteId: number | string, + includeDeleted = false ): Promise { - return await _getBurialSite(`${baseSQL} and l.burialSiteId = ?`, burialSiteId) + return await _getBurialSite( + `l.burialSiteId = ?`, + burialSiteId, + includeDeleted + ) } export async function getBurialSiteByBurialSiteName( - burialSiteName: string + burialSiteName: string, + includeDeleted = false ): Promise { return await _getBurialSite( - `${baseSQL} and l.burialSiteName = ?`, - burialSiteName + `l.burialSiteName = ?`, + burialSiteName, + includeDeleted ) } async function _getBurialSite( - sql: string, - burialSiteIdOrLotName: number | string + whereClausePiece: string, + burialSiteIdOrLotName: number | string, + includeDeleted = false ): Promise { const database = sqlite(sunriseDB, { readonly: true }) - const burialSite = database.prepare(sql).get(burialSiteIdOrLotName) as - | BurialSite - | undefined + const burialSite = database + .prepare( + `${baseSQL} ${includeDeleted ? 'where' : 'where l.recordDelete_timeMillis is null and'} ${whereClausePiece}` + ) + .get(burialSiteIdOrLotName) as BurialSite | undefined if (burialSite !== undefined) { const contracts = await getContracts( diff --git a/database/getContract.js b/database/getContract.js index 9635bc49..449801fc 100644 --- a/database/getContract.js +++ b/database/getContract.js @@ -16,6 +16,7 @@ export default async function getContract(contractId, connectedDatabase) { .prepare(`select o.contractId, o.contractTypeId, t.contractType, t.isPreneed, o.burialSiteId, l.burialSiteName, l.burialSiteTypeId, + case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive, l.cemeteryId, m.cemeteryName, o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString, diff --git a/database/getContract.ts b/database/getContract.ts index 77de0945..d6fc5489 100644 --- a/database/getContract.ts +++ b/database/getContract.ts @@ -33,6 +33,7 @@ export default async function getContract( `select o.contractId, o.contractTypeId, t.contractType, t.isPreneed, o.burialSiteId, l.burialSiteName, l.burialSiteTypeId, + case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive, l.cemeteryId, m.cemeteryName, o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString, diff --git a/database/getContracts.js b/database/getContracts.js index 6f4002ec..b23ba0ee 100644 --- a/database/getContracts.js +++ b/database/getContracts.js @@ -32,6 +32,7 @@ export default async function getContracts(filters, options, connectedDatabase) .prepare(`select o.contractId, o.contractTypeId, t.contractType, t.isPreneed, o.burialSiteId, lt.burialSiteType, l.burialSiteName, + case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive, l.cemeteryId, m.cemeteryName, o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString, diff --git a/database/getContracts.ts b/database/getContracts.ts index be12ff22..692c398e 100644 --- a/database/getContracts.ts +++ b/database/getContracts.ts @@ -95,6 +95,7 @@ export default async function getContracts( `select o.contractId, o.contractTypeId, t.contractType, t.isPreneed, o.burialSiteId, lt.burialSiteType, l.burialSiteName, + case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive, l.cemeteryId, m.cemeteryName, o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString, o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString, diff --git a/database/restoreBurialSite.d.ts b/database/restoreBurialSite.d.ts new file mode 100644 index 00000000..53eb8d86 --- /dev/null +++ b/database/restoreBurialSite.d.ts @@ -0,0 +1 @@ +export declare function restoreBurialSite(burialSiteId: number, user: User): boolean; diff --git a/database/restoreBurialSite.js b/database/restoreBurialSite.js new file mode 100644 index 00000000..c066f581 --- /dev/null +++ b/database/restoreBurialSite.js @@ -0,0 +1,17 @@ +import sqlite from 'better-sqlite3'; +import { sunriseDB } from '../helpers/database.helpers.js'; +export function restoreBurialSite(burialSiteId, user) { + const database = sqlite(sunriseDB); + const rightNowMillis = Date.now(); + const result = database + .prepare(`update BurialSites + set recordDelete_userName = null, + recordDelete_timeMillis = null, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where burialSiteId = ? + and recordDelete_timeMillis is not null`) + .run(user.userName, rightNowMillis, burialSiteId); + database.close(); + return result.changes > 0; +} diff --git a/database/restoreBurialSite.ts b/database/restoreBurialSite.ts new file mode 100644 index 00000000..93dda997 --- /dev/null +++ b/database/restoreBurialSite.ts @@ -0,0 +1,25 @@ +import sqlite from 'better-sqlite3' + +import { sunriseDB } from '../helpers/database.helpers.js' + +export function restoreBurialSite(burialSiteId: number, user: User): boolean { + const database = sqlite(sunriseDB) + + const rightNowMillis = Date.now() + + const result = database + .prepare( + `update BurialSites + set recordDelete_userName = null, + recordDelete_timeMillis = null, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where burialSiteId = ? + and recordDelete_timeMillis is not null` + ) + .run(user.userName, rightNowMillis, burialSiteId) + + database.close() + + return result.changes > 0 +} diff --git a/handlers/burialSites-get/view.js b/handlers/burialSites-get/view.js index a3c60580..fc3d1184 100644 --- a/handlers/burialSites-get/view.js +++ b/handlers/burialSites-get/view.js @@ -2,17 +2,20 @@ import getBurialSite from '../../database/getBurialSite.js'; import { getNextBurialSiteId, getPreviousBurialSiteId } from '../../helpers/burialSites.helpers.js'; import { getConfigProperty } from '../../helpers/config.helpers.js'; export default async function handler(request, response) { - const burialSite = await getBurialSite(request.params.burialSiteId); + const burialSite = await getBurialSite(request.params.burialSiteId, request.session.user?.userProperties?.canUpdate); if (burialSite === undefined) { response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/burialSites/?error=burialSiteIdNotFound`); return; } + const burialSiteIsDeleted = burialSite.recordDelete_timeMillis !== null; response.render('burialSite-view', { headTitle: burialSite.burialSiteName, burialSite }); - response.on('finish', () => { - getNextBurialSiteId(burialSite.burialSiteId); - getPreviousBurialSiteId(burialSite.burialSiteId); - }); + if (!burialSiteIsDeleted) { + response.on('finish', () => { + getNextBurialSiteId(burialSite.burialSiteId); + getPreviousBurialSiteId(burialSite.burialSiteId); + }); + } } diff --git a/handlers/burialSites-get/view.ts b/handlers/burialSites-get/view.ts index 9d7c6582..f72679df 100644 --- a/handlers/burialSites-get/view.ts +++ b/handlers/burialSites-get/view.ts @@ -11,7 +11,10 @@ export default async function handler( request: Request, response: Response ): Promise { - const burialSite = await getBurialSite(request.params.burialSiteId) + const burialSite = await getBurialSite( + request.params.burialSiteId, + request.session.user?.userProperties?.canUpdate + ) if (burialSite === undefined) { response.redirect( @@ -20,14 +23,18 @@ export default async function handler( return } + const burialSiteIsDeleted = burialSite.recordDelete_timeMillis !== null + response.render('burialSite-view', { headTitle: burialSite.burialSiteName, burialSite }) - response.on('finish', () => { - getNextBurialSiteId(burialSite.burialSiteId) - getPreviousBurialSiteId(burialSite.burialSiteId) - }) + if (!burialSiteIsDeleted) { + response.on('finish', () => { + getNextBurialSiteId(burialSite.burialSiteId) + getPreviousBurialSiteId(burialSite.burialSiteId) + }) + } } diff --git a/handlers/burialSites-post/doRestoreBurialSite.d.ts b/handlers/burialSites-post/doRestoreBurialSite.d.ts new file mode 100644 index 00000000..748432a6 --- /dev/null +++ b/handlers/burialSites-post/doRestoreBurialSite.d.ts @@ -0,0 +1,4 @@ +import type { Request, Response } from 'express'; +export default function handler(request: Request, response: Response): void; diff --git a/handlers/burialSites-post/doRestoreBurialSite.js b/handlers/burialSites-post/doRestoreBurialSite.js new file mode 100644 index 00000000..3a0e9365 --- /dev/null +++ b/handlers/burialSites-post/doRestoreBurialSite.js @@ -0,0 +1,17 @@ +import { restoreBurialSite } from '../../database/restoreBurialSite.js'; +import { clearNextPreviousBurialSiteIdCache } from '../../helpers/burialSites.helpers.js'; +export default function handler(request, response) { + const success = restoreBurialSite(request.body.burialSiteId, request.session.user); + const burialSiteId = typeof request.body.burialSiteId === 'string' + ? Number.parseInt(request.body.burialSiteId, 10) + : request.body.burialSiteId; + response.json({ + success, + burialSiteId + }); + if (success) { + response.on('finish', () => { + clearNextPreviousBurialSiteIdCache(); + }); + } +} diff --git a/handlers/burialSites-post/doRestoreBurialSite.ts b/handlers/burialSites-post/doRestoreBurialSite.ts new file mode 100644 index 00000000..5e8cee09 --- /dev/null +++ b/handlers/burialSites-post/doRestoreBurialSite.ts @@ -0,0 +1,31 @@ +import type { Request, Response } from 'express' + +import { restoreBurialSite } from '../../database/restoreBurialSite.js' +import { clearNextPreviousBurialSiteIdCache } from '../../helpers/burialSites.helpers.js' + +export default function handler( + request: Request, + response: Response +): void { + const success = restoreBurialSite( + request.body.burialSiteId, + request.session.user as User + ) + + const burialSiteId = + typeof request.body.burialSiteId === 'string' + ? Number.parseInt(request.body.burialSiteId, 10) + : request.body.burialSiteId + + response.json({ + success, + + burialSiteId + }) + + if (success) { + response.on('finish', () => { + clearNextPreviousBurialSiteIdCache() + }) + } +} diff --git a/public/javascripts/burialSite.view.js b/public/javascripts/burialSite.view.js index 30a810e8..783914ee 100644 --- a/public/javascripts/burialSite.view.js +++ b/public/javascripts/burialSite.view.js @@ -39,4 +39,41 @@ Object.defineProperty(exports, "__esModule", { value: true }); tableRowElement.classList.toggle('is-hidden'); } }); + /* + * Restore Deleted + */ + document + .querySelector('button.is-restore-burial-site-button') + ?.addEventListener('click', (clickEvent) => { + clickEvent.preventDefault(); + const buttonElement = clickEvent.currentTarget; + const burialSiteId = buttonElement.dataset.burialSiteId ?? ''; + if (burialSiteId === '') { + return; + } + function doRestore() { + cityssm.postJSON(`${sunrise.urlPrefix}/burialSites/doRestoreBurialSite`, { burialSiteId }, (rawResponseJSON) => { + const responseJSON = rawResponseJSON; + if (responseJSON.success) { + globalThis.location.reload(); + } + else { + bulmaJS.alert({ + title: 'Error Restoring Burial Site', + message: responseJSON.errorMessage ?? '', + contextualColorName: 'danger' + }); + } + }); + } + bulmaJS.confirm({ + contextualColorName: 'warning', + title: 'Restore Burial Site', + message: 'Are you sure you want to restore this burial site? It will be visible again.', + okButton: { + text: 'Yes, Restore Burial Site', + callbackFunction: doRestore + } + }); + }); })(); diff --git a/public/javascripts/burialSite.view.ts b/public/javascripts/burialSite.view.ts index c9b336da..03426c61 100644 --- a/public/javascripts/burialSite.view.ts +++ b/public/javascripts/burialSite.view.ts @@ -1,7 +1,12 @@ +import type { BulmaJS } from '@cityssm/bulma-js/types.js' +import type { cityssmGlobal } from '@cityssm/bulma-webapp-js/src/types.js' import type * as Leaflet from 'leaflet' import type { Sunrise } from './types.js' +declare const cityssm: cityssmGlobal +declare const bulmaJS: BulmaJS + declare const L: typeof Leaflet declare const exports: { sunrise: Sunrise @@ -72,4 +77,58 @@ declare const exports: { tableRowElement.classList.toggle('is-hidden') } }) + + /* + * Restore Deleted + */ + + document + .querySelector('button.is-restore-burial-site-button') + ?.addEventListener('click', (clickEvent) => { + clickEvent.preventDefault() + + const buttonElement = clickEvent.currentTarget as HTMLButtonElement + + const burialSiteId = buttonElement.dataset.burialSiteId ?? '' + + if (burialSiteId === '') { + return + } + + function doRestore(): void { + cityssm.postJSON( + `${sunrise.urlPrefix}/burialSites/doRestoreBurialSite`, + { burialSiteId }, + (rawResponseJSON) => { + const responseJSON = rawResponseJSON as { + success: boolean + errorMessage?: string + } + + if (responseJSON.success) { + globalThis.location.reload() + } else { + bulmaJS.alert({ + title: 'Error Restoring Burial Site', + message: responseJSON.errorMessage ?? '', + contextualColorName: 'danger' + }) + } + } + ) + } + + bulmaJS.confirm({ + contextualColorName: 'warning', + title: 'Restore Burial Site', + + message: + 'Are you sure you want to restore this burial site? It will be visible again.', + + okButton: { + text: 'Yes, Restore Burial Site', + callbackFunction: doRestore + } + }) + }) })() diff --git a/public/javascripts/contract.search.js b/public/javascripts/contract.search.js index 97b06ec4..a3b63770 100644 --- a/public/javascripts/contract.search.js +++ b/public/javascripts/contract.search.js @@ -75,6 +75,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); : 'has-text-danger'}" aria-hidden="true"> `; } + const burialSiteLinkClass = contract.burialSiteIsActive === 0 ? 'has-text-danger-dark' : ''; // eslint-disable-next-line no-unsanitized/method resultsTbodyElement.insertAdjacentHTML('beforeend', ` @@ -88,9 +89,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); ${(contract.burialSiteId ?? -1) === -1 ? '(No Burial Site)' - : ` - ${cityssm.escapeHTML(contract.burialSiteName ?? '')} + ${cityssm.escapeHTML(contract.burialSiteName ?? '')} `}
${cityssm.escapeHTML(contract.cemeteryName ?? '')} diff --git a/public/javascripts/contract.search.ts b/public/javascripts/contract.search.ts index a9dbcba9..d780f6a4 100644 --- a/public/javascripts/contract.search.ts +++ b/public/javascripts/contract.search.ts @@ -130,6 +130,9 @@ declare const exports: Record ` } + const burialSiteLinkClass = + contract.burialSiteIsActive === 0 ? 'has-text-danger-dark' : '' + // eslint-disable-next-line no-unsanitized/method resultsTbodyElement.insertAdjacentHTML( 'beforeend', @@ -146,9 +149,10 @@ declare const exports: Record ${ (contract.burialSiteId ?? -1) === -1 ? '(No Burial Site)' - : ` - ${cityssm.escapeHTML(contract.burialSiteName ?? '')} + ${cityssm.escapeHTML(contract.burialSiteName ?? '')} ` }
${cityssm.escapeHTML(contract.cemeteryName ?? '')} diff --git a/routes/burialSites.js b/routes/burialSites.js index a80222e1..9809172c 100644 --- a/routes/burialSites.js +++ b/routes/burialSites.js @@ -10,18 +10,19 @@ import handler_doCreateBurialSite from '../handlers/burialSites-post/doCreateBur import handler_doDeleteBurialSite from '../handlers/burialSites-post/doDeleteBurialSite.js'; import handler_doDeleteBurialSiteComment from '../handlers/burialSites-post/doDeleteBurialSiteComment.js'; import handler_doGetBurialSiteTypeFields from '../handlers/burialSites-post/doGetBurialSiteTypeFields.js'; +import handler_doRestoreBurialSite from '../handlers/burialSites-post/doRestoreBurialSite.js'; import handler_doSearchBurialSites from '../handlers/burialSites-post/doSearchBurialSites.js'; import handler_doUpdateBurialSite from '../handlers/burialSites-post/doUpdateBurialSite.js'; import handler_doUpdateBurialSiteComment from '../handlers/burialSites-post/doUpdateBurialSiteComment.js'; -import { updateGetHandler, updatePostHandler } from '../handlers/permissions.js'; +import { adminPostHandler, updateGetHandler, updatePostHandler } from '../handlers/permissions.js'; export const router = Router(); /* - * Lot Search + * Burial Site Search */ router.get('/', handler_search); router.post('/doSearchBurialSites', handler_doSearchBurialSites); /* - * Lot View / Edit + * Burial Site View / Edit */ router.get('/new', updateGetHandler, handler_new); router.get('/:burialSiteId', handler_view); @@ -32,6 +33,10 @@ router.post('/doGetBurialSiteTypeFields', updatePostHandler, handler_doGetBurial router.post('/doCreateBurialSite', updatePostHandler, handler_doCreateBurialSite); router.post('/doUpdateBurialSite', updatePostHandler, handler_doUpdateBurialSite); router.post('/doDeleteBurialSite', updatePostHandler, handler_doDeleteBurialSite); +router.post('/doRestoreBurialSite', adminPostHandler, handler_doRestoreBurialSite); +/* + * Burial Site Comments + */ router.post('/doAddBurialSiteComment', updatePostHandler, handler_doAddBurialSiteComment); router.post('/doUpdateBurialSiteComment', updatePostHandler, handler_doUpdateBurialSiteComment); router.post('/doDeleteBurialSiteComment', updatePostHandler, handler_doDeleteBurialSiteComment); diff --git a/routes/burialSites.ts b/routes/burialSites.ts index fad1616d..6a639d1a 100644 --- a/routes/burialSites.ts +++ b/routes/burialSites.ts @@ -11,15 +11,16 @@ import handler_doCreateBurialSite from '../handlers/burialSites-post/doCreateBur import handler_doDeleteBurialSite from '../handlers/burialSites-post/doDeleteBurialSite.js' import handler_doDeleteBurialSiteComment from '../handlers/burialSites-post/doDeleteBurialSiteComment.js' import handler_doGetBurialSiteTypeFields from '../handlers/burialSites-post/doGetBurialSiteTypeFields.js' +import handler_doRestoreBurialSite from '../handlers/burialSites-post/doRestoreBurialSite.js' import handler_doSearchBurialSites from '../handlers/burialSites-post/doSearchBurialSites.js' import handler_doUpdateBurialSite from '../handlers/burialSites-post/doUpdateBurialSite.js' import handler_doUpdateBurialSiteComment from '../handlers/burialSites-post/doUpdateBurialSiteComment.js' -import { updateGetHandler, updatePostHandler } from '../handlers/permissions.js' +import { adminPostHandler, updateGetHandler, updatePostHandler } from '../handlers/permissions.js' export const router = Router() /* - * Lot Search + * Burial Site Search */ router.get('/', handler_search) @@ -27,7 +28,7 @@ router.get('/', handler_search) router.post('/doSearchBurialSites', handler_doSearchBurialSites) /* - * Lot View / Edit + * Burial Site View / Edit */ router.get('/new', updateGetHandler, handler_new) @@ -64,6 +65,16 @@ router.post( handler_doDeleteBurialSite ) +router.post( + '/doRestoreBurialSite', + adminPostHandler, + handler_doRestoreBurialSite +) + +/* + * Burial Site Comments + */ + router.post( '/doAddBurialSiteComment', updatePostHandler, diff --git a/types/record.types.d.ts b/types/record.types.d.ts index 3a8c187d..fdceb799 100644 --- a/types/record.types.d.ts +++ b/types/record.types.d.ts @@ -107,6 +107,7 @@ export interface Contract extends Record { isPreneed: boolean; printEJS?: string; burialSiteId?: number; + burialSiteIsActive?: 0 | 1; burialSiteName?: string; burialSiteType?: string; burialSiteTypeId?: number; @@ -285,8 +286,8 @@ export interface Record { recordUpdate_timeString?: string; recordUpdate_userName?: string; recordDelete_dateString?: string; - recordDelete_timeMillis?: number; - recordDelete_userName?: string; + recordDelete_timeMillis?: number | null; + recordDelete_userName?: string | null; } export interface WorkOrder extends Record { workOrderId: number; diff --git a/types/record.types.ts b/types/record.types.ts index 3d0b23c5..d0d66b90 100644 --- a/types/record.types.ts +++ b/types/record.types.ts @@ -153,6 +153,7 @@ export interface Contract extends Record { printEJS?: string burialSiteId?: number + burialSiteIsActive?: 0 | 1 burialSiteName?: string burialSiteType?: string burialSiteTypeId?: number @@ -393,8 +394,8 @@ export interface Record { recordUpdate_userName?: string recordDelete_dateString?: string - recordDelete_timeMillis?: number - recordDelete_userName?: string + recordDelete_timeMillis?: number | null + recordDelete_userName?: string | null } /* diff --git a/views/burialSite-view.ejs b/views/burialSite-view.ejs index 96f07310..7d9bc4a4 100644 --- a/views/burialSite-view.ejs +++ b/views/burialSite-view.ejs @@ -21,6 +21,21 @@ <%= burialSite.burialSiteName %> +<% const burialSiteIsDeleted = burialSite.recordDelete_timeMillis !== null; %> +<% if (burialSiteIsDeleted) { %> +
+
+

Burial Site Deleted

+
+
+

This burial site has been deleted. It is no longer available for use.

+ <% if (!user.userProperties.isAdmin) { %> +

To restore this burial site, please contact your system administrator.

+ <% } %> +
+
+<% } %> + diff --git a/views/contract-view.ejs b/views/contract-view.ejs index f13bc6e3..78738edd 100644 --- a/views/contract-view.ejs +++ b/views/contract-view.ejs @@ -125,7 +125,9 @@

Burial Site
<% if (contract.burialSiteId) { %> - <%= contract.burialSiteName %> + + <%= contract.burialSiteName %> + <% } else { %> (No Burial Site) <% } %>