parent cemeteries, linting

pull/11/head
Dan Gowans 2025-04-11 14:50:00 -04:00
parent ed87174c19
commit 9bc85e6a8b
39 changed files with 385 additions and 362 deletions

View File

@ -2,6 +2,7 @@ export interface AddCemeteryForm {
cemeteryDescription: string; cemeteryDescription: string;
cemeteryKey: string; cemeteryKey: string;
cemeteryName: string; cemeteryName: string;
parentCemeteryId: string;
cemeteryLatitude: string; cemeteryLatitude: string;
cemeteryLongitude: string; cemeteryLongitude: string;
cemeterySvg: string; cemeterySvg: string;

View File

@ -9,10 +9,11 @@ export default async function addCemetery(addForm, user) {
cemeteryAddress1, cemeteryAddress2, cemeteryAddress1, cemeteryAddress2,
cemeteryCity, cemeteryProvince, cemeteryPostalCode, cemeteryCity, cemeteryProvince, cemeteryPostalCode,
cemeteryPhoneNumber, cemeteryPhoneNumber,
parentCemeteryId,
recordCreate_userName, recordCreate_timeMillis, recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis) recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
.run(addForm.cemeteryName, addForm.cemeteryKey, addForm.cemeteryDescription, addForm.cemeterySvg, addForm.cemeteryLatitude === '' ? undefined : addForm.cemeteryLatitude, addForm.cemeteryLongitude === '' ? undefined : addForm.cemeteryLongitude, addForm.cemeteryAddress1, addForm.cemeteryAddress2, addForm.cemeteryCity, addForm.cemeteryProvince, addForm.cemeteryPostalCode, addForm.cemeteryPhoneNumber, user.userName, rightNowMillis, user.userName, rightNowMillis); .run(addForm.cemeteryName, addForm.cemeteryKey, addForm.cemeteryDescription, addForm.cemeterySvg, addForm.cemeteryLatitude === '' ? undefined : addForm.cemeteryLatitude, addForm.cemeteryLongitude === '' ? undefined : addForm.cemeteryLongitude, addForm.cemeteryAddress1, addForm.cemeteryAddress2, addForm.cemeteryCity, addForm.cemeteryProvince, addForm.cemeteryPostalCode, addForm.cemeteryPhoneNumber, addForm.parentCemeteryId === '' ? undefined : addForm.parentCemeteryId, user.userName, rightNowMillis, user.userName, rightNowMillis);
database.release(); database.release();
return result.lastInsertRowid; return result.lastInsertRowid;
} }

View File

@ -4,6 +4,7 @@ export interface AddCemeteryForm {
cemeteryDescription: string cemeteryDescription: string
cemeteryKey: string cemeteryKey: string
cemeteryName: string cemeteryName: string
parentCemeteryId: string
cemeteryLatitude: string cemeteryLatitude: string
cemeteryLongitude: string cemeteryLongitude: string
@ -34,9 +35,10 @@ export default async function addCemetery(
cemeteryAddress1, cemeteryAddress2, cemeteryAddress1, cemeteryAddress2,
cemeteryCity, cemeteryProvince, cemeteryPostalCode, cemeteryCity, cemeteryProvince, cemeteryPostalCode,
cemeteryPhoneNumber, cemeteryPhoneNumber,
parentCemeteryId,
recordCreate_userName, recordCreate_timeMillis, recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis) recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
) )
.run( .run(
addForm.cemeteryName, addForm.cemeteryName,
@ -51,6 +53,7 @@ export default async function addCemetery(
addForm.cemeteryProvince, addForm.cemeteryProvince,
addForm.cemeteryPostalCode, addForm.cemeteryPostalCode,
addForm.cemeteryPhoneNumber, addForm.cemeteryPhoneNumber,
addForm.parentCemeteryId === '' ? undefined : addForm.parentCemeteryId,
user.userName, user.userName,
rightNowMillis, rightNowMillis,
user.userName, user.userName,

View File

@ -8,8 +8,8 @@ function buildWhereClause(filters) {
sqlWhereClause += burialSiteNameFilters.sqlWhereClause; sqlWhereClause += burialSiteNameFilters.sqlWhereClause;
sqlParameters.push(...burialSiteNameFilters.sqlParameters); sqlParameters.push(...burialSiteNameFilters.sqlParameters);
if ((filters.cemeteryId ?? '') !== '') { if ((filters.cemeteryId ?? '') !== '') {
sqlWhereClause += ' and l.cemeteryId = ?'; sqlWhereClause += ' and (m.cemeteryId = ? or m.parentCemeteryId = ?)';
sqlParameters.push(filters.cemeteryId); sqlParameters.push(filters.cemeteryId, filters.cemeteryId);
} }
if ((filters.burialSiteTypeId ?? '') !== '') { if ((filters.burialSiteTypeId ?? '') !== '') {
sqlWhereClause += ' and l.burialSiteTypeId = ?'; sqlWhereClause += ' and l.burialSiteTypeId = ?';
@ -47,6 +47,7 @@ export default async function getBurialSites(filters, options, connectedDatabase
count = database count = database
.prepare(`select count(*) as recordCount .prepare(`select count(*) as recordCount
from BurialSites l from BurialSites l
left join Cemeteries m on l.cemeteryId = m.cemeteryId
left join ( left join (
select burialSiteId, count(contractId) as contractCount from Contracts select burialSiteId, count(contractId) as contractCount from Contracts
where recordDelete_timeMillis is null where recordDelete_timeMillis is null

View File

@ -40,8 +40,8 @@ function buildWhereClause(filters: GetBurialSitesFilters): {
sqlParameters.push(...burialSiteNameFilters.sqlParameters) sqlParameters.push(...burialSiteNameFilters.sqlParameters)
if ((filters.cemeteryId ?? '') !== '') { if ((filters.cemeteryId ?? '') !== '') {
sqlWhereClause += ' and l.cemeteryId = ?' sqlWhereClause += ' and (m.cemeteryId = ? or m.parentCemeteryId = ?)'
sqlParameters.push(filters.cemeteryId) sqlParameters.push(filters.cemeteryId, filters.cemeteryId)
} }
if ((filters.burialSiteTypeId ?? '') !== '') { if ((filters.burialSiteTypeId ?? '') !== '') {
@ -94,6 +94,7 @@ export default async function getBurialSites(
.prepare( .prepare(
`select count(*) as recordCount `select count(*) as recordCount
from BurialSites l from BurialSites l
left join Cemeteries m on l.cemeteryId = m.cemeteryId
left join ( left join (
select burialSiteId, count(contractId) as contractCount from Contracts select burialSiteId, count(contractId) as contractCount from Contracts
where recordDelete_timeMillis is null where recordDelete_timeMillis is null

View File

@ -6,14 +6,17 @@ export default async function getCemeteries() {
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
m.cemeteryPhoneNumber, m.cemeteryPhoneNumber,
p.cemeteryId as parentCemeteryId, p.cemeteryName as parentCemeteryName,
count(b.burialSiteId) as burialSiteCount count(b.burialSiteId) as burialSiteCount
from Cemeteries m from Cemeteries m
left join Cemeteries p on m.parentCemeteryId = p.cemeteryId and p.recordDelete_timeMillis is null
left join BurialSites b on m.cemeteryId = b.cemeteryId and b.recordDelete_timeMillis is null left join BurialSites b on m.cemeteryId = b.cemeteryId and b.recordDelete_timeMillis is null
where m.recordDelete_timeMillis is null where m.recordDelete_timeMillis is null
group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription, group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription,
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
m.cemeteryPhoneNumber m.cemeteryPhoneNumber,
p.cemeteryId, p.cemeteryName
order by m.cemeteryName, m.cemeteryId`) order by m.cemeteryName, m.cemeteryId`)
.all(); .all();
database.release(); database.release();

View File

@ -11,14 +11,17 @@ export default async function getCemeteries(): Promise<Cemetery[]> {
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
m.cemeteryPhoneNumber, m.cemeteryPhoneNumber,
p.cemeteryId as parentCemeteryId, p.cemeteryName as parentCemeteryName,
count(b.burialSiteId) as burialSiteCount count(b.burialSiteId) as burialSiteCount
from Cemeteries m from Cemeteries m
left join Cemeteries p on m.parentCemeteryId = p.cemeteryId and p.recordDelete_timeMillis is null
left join BurialSites b on m.cemeteryId = b.cemeteryId and b.recordDelete_timeMillis is null left join BurialSites b on m.cemeteryId = b.cemeteryId and b.recordDelete_timeMillis is null
where m.recordDelete_timeMillis is null where m.recordDelete_timeMillis is null
group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription, group by m.cemeteryId, m.cemeteryName, m.cemeteryDescription,
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
m.cemeteryPhoneNumber m.cemeteryPhoneNumber,
p.cemeteryId, p.cemeteryName
order by m.cemeteryName, m.cemeteryId` order by m.cemeteryName, m.cemeteryId`
) )
.all() as Cemetery[] .all() as Cemetery[]

View File

@ -6,11 +6,13 @@ async function _getCemetery(keyColumn, cemeteryIdOrKey, connectedDatabase) {
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
m.cemeteryPhoneNumber, m.cemeteryPhoneNumber,
p.cemeteryId as parentCemeteryId, p.cemeteryName as parentCemeteryName,
m.recordCreate_userName, m.recordCreate_timeMillis, m.recordCreate_userName, m.recordCreate_timeMillis,
m.recordUpdate_userName, m.recordUpdate_timeMillis, m.recordUpdate_userName, m.recordUpdate_timeMillis,
m.recordDelete_userName, m.recordDelete_timeMillis, m.recordDelete_userName, m.recordDelete_timeMillis,
count(l.burialSiteId) as burialSiteCount count(l.burialSiteId) as burialSiteCount
from Cemeteries m from Cemeteries m
left join Cemeteries p on m.parentCemeteryId = p.cemeteryId and p.recordDelete_timeMillis is null
left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null
where m.${keyColumn} = ? where m.${keyColumn} = ?
and m.recordDelete_timeMillis is null and m.recordDelete_timeMillis is null
@ -18,6 +20,7 @@ async function _getCemetery(keyColumn, cemeteryIdOrKey, connectedDatabase) {
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
m.cemeteryPhoneNumber, m.cemeteryPhoneNumber,
p.cemeteryId, p.cemeteryName,
m.recordCreate_userName, m.recordCreate_timeMillis, m.recordCreate_userName, m.recordCreate_timeMillis,
m.recordUpdate_userName, m.recordUpdate_timeMillis, m.recordUpdate_userName, m.recordUpdate_timeMillis,
m.recordDelete_userName, m.recordDelete_timeMillis`) m.recordDelete_userName, m.recordDelete_timeMillis`)

View File

@ -17,11 +17,13 @@ async function _getCemetery(
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
m.cemeteryPhoneNumber, m.cemeteryPhoneNumber,
p.cemeteryId as parentCemeteryId, p.cemeteryName as parentCemeteryName,
m.recordCreate_userName, m.recordCreate_timeMillis, m.recordCreate_userName, m.recordCreate_timeMillis,
m.recordUpdate_userName, m.recordUpdate_timeMillis, m.recordUpdate_userName, m.recordUpdate_timeMillis,
m.recordDelete_userName, m.recordDelete_timeMillis, m.recordDelete_userName, m.recordDelete_timeMillis,
count(l.burialSiteId) as burialSiteCount count(l.burialSiteId) as burialSiteCount
from Cemeteries m from Cemeteries m
left join Cemeteries p on m.parentCemeteryId = p.cemeteryId and p.recordDelete_timeMillis is null
left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null left join BurialSites l on m.cemeteryId = l.cemeteryId and l.recordDelete_timeMillis is null
where m.${keyColumn} = ? where m.${keyColumn} = ?
and m.recordDelete_timeMillis is null and m.recordDelete_timeMillis is null
@ -29,6 +31,7 @@ async function _getCemetery(
m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg, m.cemeteryLatitude, m.cemeteryLongitude, m.cemeterySvg,
m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode, m.cemeteryAddress1, m.cemeteryAddress2, m.cemeteryCity, m.cemeteryProvince, m.cemeteryPostalCode,
m.cemeteryPhoneNumber, m.cemeteryPhoneNumber,
p.cemeteryId, p.cemeteryName,
m.recordCreate_userName, m.recordCreate_timeMillis, m.recordCreate_userName, m.recordCreate_timeMillis,
m.recordUpdate_userName, m.recordUpdate_timeMillis, m.recordUpdate_userName, m.recordUpdate_timeMillis,
m.recordDelete_userName, m.recordDelete_timeMillis` m.recordDelete_userName, m.recordDelete_timeMillis`

View File

@ -1,6 +1,7 @@
import { dateIntegerToString, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime'
import type { PoolConnection } from 'better-sqlite-pool' import type { PoolConnection } from 'better-sqlite-pool'
import { dateIntegerToString, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime'
import type { Contract } from '../types/recordTypes.js' import type { Contract } from '../types/recordTypes.js'
import getContractComments from './getContractComments.js' import getContractComments from './getContractComments.js'

View File

@ -1,9 +1,10 @@
import type { PoolConnection } from 'better-sqlite-pool'
import { import {
dateIntegerToString, dateIntegerToString,
timeIntegerToPeriodString, timeIntegerToPeriodString,
timeIntegerToString timeIntegerToString
} from '@cityssm/utils-datetime' } from '@cityssm/utils-datetime'
import type { PoolConnection } from 'better-sqlite-pool'
import type { ContractComment } from '../types/recordTypes.js' import type { ContractComment } from '../types/recordTypes.js'

View File

@ -1,7 +1,8 @@
import type { PoolConnection } from 'better-sqlite-pool'
import { import {
dateIntegerToString dateIntegerToString
} from '@cityssm/utils-datetime' } from '@cityssm/utils-datetime'
import type { PoolConnection } from 'better-sqlite-pool'
import type { ContractInterment } from '../types/recordTypes.js' import type { ContractInterment } from '../types/recordTypes.js'

View File

@ -1,8 +1,9 @@
import type { PoolConnection } from 'better-sqlite-pool'
import { import {
dateIntegerToString, dateIntegerToString,
timeIntegerToString timeIntegerToString
} from '@cityssm/utils-datetime' } from '@cityssm/utils-datetime'
import type { PoolConnection } from 'better-sqlite-pool'
import { getConfigProperty } from '../helpers/config.helpers.js' import { getConfigProperty } from '../helpers/config.helpers.js'
import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.js' import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.js'

View File

@ -1,20 +1,20 @@
import { type DateString } from '@cityssm/utils-datetime';
import type { PoolConnection } from 'better-sqlite-pool'; import type { PoolConnection } from 'better-sqlite-pool';
import { type DateString } from '@cityssm/utils-datetime';
import type { Contract } from '../types/recordTypes.js'; import type { Contract } from '../types/recordTypes.js';
export interface GetContractsFilters { export interface GetContractsFilters {
burialSiteId?: number | string; burialSiteId?: number | string;
contractTime?: '' | 'past' | 'current' | 'future'; contractTime?: '' | 'current' | 'future' | 'past';
contractStartDateString?: DateString; contractStartDateString?: DateString;
contractEffectiveDateString?: string; contractEffectiveDateString?: string;
deceasedName?: string; deceasedName?: string;
contractTypeId?: number | string; contractTypeId?: number | string;
cemeteryId?: number | string; cemeteryId?: number | string;
burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith';
burialSiteName?: string; burialSiteName?: string;
burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith';
burialSiteTypeId?: number | string; burialSiteTypeId?: number | string;
funeralHomeId?: number | string; funeralHomeId?: number | string;
workOrderId?: number | string;
notWorkOrderId?: number | string; notWorkOrderId?: number | string;
workOrderId?: number | string;
} }
export interface GetContractsOptions { export interface GetContractsOptions {
/** -1 for no limit */ /** -1 for no limit */

View File

@ -1,87 +1,11 @@
import { dateIntegerToString, dateStringToInteger, timeIntegerToString } from '@cityssm/utils-datetime'; import { dateIntegerToString, dateStringToInteger, timeIntegerToString } from '@cityssm/utils-datetime';
import { getConfigProperty } from '../helpers/config.helpers.js'; import { getConfigProperty } from '../helpers/config.helpers.js';
import { getContractTypeById } from '../helpers/functions.cache.js'; import { getContractTypeById } from '../helpers/functions.cache.js';
import { getBurialSiteNameWhereClause, getContractTimeWhereClause, getDeceasedNameWhereClause, } from '../helpers/functions.sqlFilters.js'; import { getBurialSiteNameWhereClause, getContractTimeWhereClause, getDeceasedNameWhereClause } from '../helpers/functions.sqlFilters.js';
import getContractFees from './getContractFees.js'; import getContractFees from './getContractFees.js';
import getContractInterments from './getContractInterments.js'; import getContractInterments from './getContractInterments.js';
import getContractTransactions from './getContractTransactions.js'; import getContractTransactions from './getContractTransactions.js';
import { acquireConnection } from './pool.js'; import { acquireConnection } from './pool.js';
// eslint-disable-next-line complexity
function buildWhereClause(filters) {
let sqlWhereClause = ' where o.recordDelete_timeMillis is null';
const sqlParameters = [];
if ((filters.burialSiteId ?? '') !== '') {
sqlWhereClause += ' and o.burialSiteId = ?';
sqlParameters.push(filters.burialSiteId);
}
const burialSiteNameFilters = getBurialSiteNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l');
sqlWhereClause += burialSiteNameFilters.sqlWhereClause;
sqlParameters.push(...burialSiteNameFilters.sqlParameters);
const deceasedNameFilters = getDeceasedNameWhereClause(filters.deceasedName, 'o');
if (deceasedNameFilters.sqlParameters.length > 0) {
sqlWhereClause += ` and o.contractId in (
select contractId from ContractInterments o
where recordDelete_timeMillis is null
${deceasedNameFilters.sqlWhereClause})`;
sqlParameters.push(...deceasedNameFilters.sqlParameters);
}
if ((filters.contractTypeId ?? '') !== '') {
sqlWhereClause += ' and o.contractTypeId = ?';
sqlParameters.push(filters.contractTypeId);
}
const contractTimeFilters = getContractTimeWhereClause(filters.contractTime ?? '', 'o');
sqlWhereClause += contractTimeFilters.sqlWhereClause;
sqlParameters.push(...contractTimeFilters.sqlParameters);
if ((filters.contractStartDateString ?? '') !== '') {
sqlWhereClause += ' and o.contractStartDate = ?';
sqlParameters.push(dateStringToInteger(filters.contractStartDateString));
}
if ((filters.contractEffectiveDateString ?? '') !== '') {
sqlWhereClause += ` and (
o.contractEndDate is null
or (o.contractStartDate <= ? and o.contractEndDate >= ?)
)`;
sqlParameters.push(dateStringToInteger(filters.contractEffectiveDateString), dateStringToInteger(filters.contractEffectiveDateString));
}
if ((filters.cemeteryId ?? '') !== '') {
sqlWhereClause += ' and l.cemeteryId = ?';
sqlParameters.push(filters.cemeteryId);
}
if ((filters.burialSiteTypeId ?? '') !== '') {
sqlWhereClause += ' and l.burialSiteTypeId = ?';
sqlParameters.push(filters.burialSiteTypeId);
}
if ((filters.funeralHomeId ?? '') !== '') {
sqlWhereClause += ' and o.funeralHomeId = ?';
sqlParameters.push(filters.funeralHomeId);
}
if ((filters.workOrderId ?? '') !== '') {
sqlWhereClause +=
' and o.contractId in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
sqlParameters.push(filters.workOrderId);
}
if ((filters.notWorkOrderId ?? '') !== '') {
sqlWhereClause +=
' and o.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
sqlParameters.push(filters.notWorkOrderId);
}
return {
sqlWhereClause,
sqlParameters
};
}
async function addInclusions(contract, options, database) {
if (options.includeFees) {
contract.contractFees = await getContractFees(contract.contractId, database);
}
if (options.includeTransactions) {
contract.contractTransactions = await getContractTransactions(contract.contractId, { includeIntegrations: false }, database);
}
if (options.includeInterments) {
contract.contractInterments = await getContractInterments(contract.contractId, database);
}
return contract;
}
export default async function getContracts(filters, options, connectedDatabase) { export default async function getContracts(filters, options, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection()); const database = connectedDatabase ?? (await acquireConnection());
database.function('userFn_dateIntegerToString', dateIntegerToString); database.function('userFn_dateIntegerToString', dateIntegerToString);
@ -96,6 +20,7 @@ export default async function getContracts(filters, options, connectedDatabase)
.prepare(`select count(*) as recordCount .prepare(`select count(*) as recordCount
from Contracts o from Contracts o
left join BurialSites l on o.burialSiteId = l.burialSiteId left join BurialSites l on o.burialSiteId = l.burialSiteId
left join Cemeteries m on l.cemeteryId = m.cemeteryId
${sqlWhereClause}`) ${sqlWhereClause}`)
.get(sqlParameters).recordCount; .get(sqlParameters).recordCount;
} }
@ -154,3 +79,79 @@ export default async function getContracts(filters, options, connectedDatabase)
contracts contracts
}; };
} }
async function addInclusions(contract, options, database) {
if (options.includeFees) {
contract.contractFees = await getContractFees(contract.contractId, database);
}
if (options.includeTransactions) {
contract.contractTransactions = await getContractTransactions(contract.contractId, { includeIntegrations: false }, database);
}
if (options.includeInterments) {
contract.contractInterments = await getContractInterments(contract.contractId, database);
}
return contract;
}
// eslint-disable-next-line complexity
function buildWhereClause(filters) {
let sqlWhereClause = ' where o.recordDelete_timeMillis is null';
const sqlParameters = [];
if ((filters.burialSiteId ?? '') !== '') {
sqlWhereClause += ' and o.burialSiteId = ?';
sqlParameters.push(filters.burialSiteId);
}
const burialSiteNameFilters = getBurialSiteNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l');
sqlWhereClause += burialSiteNameFilters.sqlWhereClause;
sqlParameters.push(...burialSiteNameFilters.sqlParameters);
const deceasedNameFilters = getDeceasedNameWhereClause(filters.deceasedName, 'o');
if (deceasedNameFilters.sqlParameters.length > 0) {
sqlWhereClause += ` and o.contractId in (
select contractId from ContractInterments o
where recordDelete_timeMillis is null
${deceasedNameFilters.sqlWhereClause})`;
sqlParameters.push(...deceasedNameFilters.sqlParameters);
}
if ((filters.contractTypeId ?? '') !== '') {
sqlWhereClause += ' and o.contractTypeId = ?';
sqlParameters.push(filters.contractTypeId);
}
const contractTimeFilters = getContractTimeWhereClause(filters.contractTime ?? '', 'o');
sqlWhereClause += contractTimeFilters.sqlWhereClause;
sqlParameters.push(...contractTimeFilters.sqlParameters);
if ((filters.contractStartDateString ?? '') !== '') {
sqlWhereClause += ' and o.contractStartDate = ?';
sqlParameters.push(dateStringToInteger(filters.contractStartDateString));
}
if ((filters.contractEffectiveDateString ?? '') !== '') {
sqlWhereClause += ` and (
o.contractEndDate is null
or (o.contractStartDate <= ? and o.contractEndDate >= ?)
)`;
sqlParameters.push(dateStringToInteger(filters.contractEffectiveDateString), dateStringToInteger(filters.contractEffectiveDateString));
}
if ((filters.cemeteryId ?? '') !== '') {
sqlWhereClause += ' and (m.cemeteryId = ? or m.parentCemeteryId = ?)';
sqlParameters.push(filters.cemeteryId, filters.cemeteryId);
}
if ((filters.burialSiteTypeId ?? '') !== '') {
sqlWhereClause += ' and l.burialSiteTypeId = ?';
sqlParameters.push(filters.burialSiteTypeId);
}
if ((filters.funeralHomeId ?? '') !== '') {
sqlWhereClause += ' and o.funeralHomeId = ?';
sqlParameters.push(filters.funeralHomeId);
}
if ((filters.workOrderId ?? '') !== '') {
sqlWhereClause +=
' and o.contractId in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
sqlParameters.push(filters.workOrderId);
}
if ((filters.notWorkOrderId ?? '') !== '') {
sqlWhereClause +=
' and o.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
sqlParameters.push(filters.notWorkOrderId);
}
return {
sqlWhereClause,
sqlParameters
};
}

View File

@ -1,17 +1,18 @@
import type { PoolConnection } from 'better-sqlite-pool'
import { import {
type DateString, type DateString,
dateIntegerToString, dateIntegerToString,
dateStringToInteger, dateStringToInteger,
timeIntegerToString timeIntegerToString
} from '@cityssm/utils-datetime' } from '@cityssm/utils-datetime'
import type { PoolConnection } from 'better-sqlite-pool'
import { getConfigProperty } from '../helpers/config.helpers.js' import { getConfigProperty } from '../helpers/config.helpers.js'
import { getContractTypeById } from '../helpers/functions.cache.js' import { getContractTypeById } from '../helpers/functions.cache.js'
import { import {
getBurialSiteNameWhereClause, getBurialSiteNameWhereClause,
getContractTimeWhereClause, getContractTimeWhereClause,
getDeceasedNameWhereClause, getDeceasedNameWhereClause
} from '../helpers/functions.sqlFilters.js' } from '../helpers/functions.sqlFilters.js'
import type { Contract } from '../types/recordTypes.js' import type { Contract } from '../types/recordTypes.js'
@ -22,18 +23,23 @@ import { acquireConnection } from './pool.js'
export interface GetContractsFilters { export interface GetContractsFilters {
burialSiteId?: number | string burialSiteId?: number | string
contractTime?: '' | 'past' | 'current' | 'future'
contractTime?: '' | 'current' | 'future' | 'past'
contractStartDateString?: DateString contractStartDateString?: DateString
contractEffectiveDateString?: string contractEffectiveDateString?: string
deceasedName?: string deceasedName?: string
contractTypeId?: number | string contractTypeId?: number | string
cemeteryId?: number | string cemeteryId?: number | string
burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith'
burialSiteName?: string burialSiteName?: string
burialSiteNameSearchType?: '' | 'startsWith' | 'endsWith'
burialSiteTypeId?: number | string burialSiteTypeId?: number | string
funeralHomeId?: number | string funeralHomeId?: number | string
workOrderId?: number | string
notWorkOrderId?: number | string notWorkOrderId?: number | string
workOrderId?: number | string
} }
export interface GetContractsOptions { export interface GetContractsOptions {
@ -45,129 +51,6 @@ export interface GetContractsOptions {
includeTransactions: boolean includeTransactions: boolean
} }
// eslint-disable-next-line complexity
function buildWhereClause(filters: GetContractsFilters): {
sqlWhereClause: string
sqlParameters: unknown[]
} {
let sqlWhereClause = ' where o.recordDelete_timeMillis is null'
const sqlParameters: unknown[] = []
if ((filters.burialSiteId ?? '') !== '') {
sqlWhereClause += ' and o.burialSiteId = ?'
sqlParameters.push(filters.burialSiteId)
}
const burialSiteNameFilters = getBurialSiteNameWhereClause(
filters.burialSiteName,
filters.burialSiteNameSearchType ?? '',
'l'
)
sqlWhereClause += burialSiteNameFilters.sqlWhereClause
sqlParameters.push(...burialSiteNameFilters.sqlParameters)
const deceasedNameFilters = getDeceasedNameWhereClause(
filters.deceasedName,
'o'
)
if (deceasedNameFilters.sqlParameters.length > 0) {
sqlWhereClause += ` and o.contractId in (
select contractId from ContractInterments o
where recordDelete_timeMillis is null
${deceasedNameFilters.sqlWhereClause})`
sqlParameters.push(...deceasedNameFilters.sqlParameters)
}
if ((filters.contractTypeId ?? '') !== '') {
sqlWhereClause += ' and o.contractTypeId = ?'
sqlParameters.push(filters.contractTypeId)
}
const contractTimeFilters = getContractTimeWhereClause(
filters.contractTime ?? '',
'o'
)
sqlWhereClause += contractTimeFilters.sqlWhereClause
sqlParameters.push(...contractTimeFilters.sqlParameters)
if ((filters.contractStartDateString ?? '') !== '') {
sqlWhereClause += ' and o.contractStartDate = ?'
sqlParameters.push(
dateStringToInteger(filters.contractStartDateString as DateString)
)
}
if ((filters.contractEffectiveDateString ?? '') !== '') {
sqlWhereClause += ` and (
o.contractEndDate is null
or (o.contractStartDate <= ? and o.contractEndDate >= ?)
)`
sqlParameters.push(
dateStringToInteger(filters.contractEffectiveDateString as DateString),
dateStringToInteger(filters.contractEffectiveDateString 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.funeralHomeId ?? '') !== '') {
sqlWhereClause += ' and o.funeralHomeId = ?'
sqlParameters.push(filters.funeralHomeId)
}
if ((filters.workOrderId ?? '') !== '') {
sqlWhereClause +=
' and o.contractId in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
sqlParameters.push(filters.workOrderId)
}
if ((filters.notWorkOrderId ?? '') !== '') {
sqlWhereClause +=
' and o.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
sqlParameters.push(filters.notWorkOrderId)
}
return {
sqlWhereClause,
sqlParameters
}
}
async function addInclusions(
contract: Contract,
options: GetContractsOptions,
database: PoolConnection
): Promise<Contract> {
if (options.includeFees) {
contract.contractFees = await getContractFees(contract.contractId, database)
}
if (options.includeTransactions) {
contract.contractTransactions = await getContractTransactions(
contract.contractId,
{ includeIntegrations: false },
database
)
}
if (options.includeInterments) {
contract.contractInterments = await getContractInterments(
contract.contractId,
database
)
}
return contract
}
export default async function getContracts( export default async function getContracts(
filters: GetContractsFilters, filters: GetContractsFilters,
options: GetContractsOptions, options: GetContractsOptions,
@ -194,6 +77,7 @@ export default async function getContracts(
`select count(*) as recordCount `select count(*) as recordCount
from Contracts o from Contracts o
left join BurialSites l on o.burialSiteId = l.burialSiteId left join BurialSites l on o.burialSiteId = l.burialSiteId
left join Cemeteries m on l.cemeteryId = m.cemeteryId
${sqlWhereClause}` ${sqlWhereClause}`
) )
.get(sqlParameters) as { recordCount: number } .get(sqlParameters) as { recordCount: number }
@ -268,3 +152,126 @@ export default async function getContracts(
contracts contracts
} }
} }
async function addInclusions(
contract: Contract,
options: GetContractsOptions,
database: PoolConnection
): Promise<Contract> {
if (options.includeFees) {
contract.contractFees = await getContractFees(contract.contractId, database)
}
if (options.includeTransactions) {
contract.contractTransactions = await getContractTransactions(
contract.contractId,
{ includeIntegrations: false },
database
)
}
if (options.includeInterments) {
contract.contractInterments = await getContractInterments(
contract.contractId,
database
)
}
return contract
}
// eslint-disable-next-line complexity
function buildWhereClause(filters: GetContractsFilters): {
sqlWhereClause: string
sqlParameters: unknown[]
} {
let sqlWhereClause = ' where o.recordDelete_timeMillis is null'
const sqlParameters: unknown[] = []
if ((filters.burialSiteId ?? '') !== '') {
sqlWhereClause += ' and o.burialSiteId = ?'
sqlParameters.push(filters.burialSiteId)
}
const burialSiteNameFilters = getBurialSiteNameWhereClause(
filters.burialSiteName,
filters.burialSiteNameSearchType ?? '',
'l'
)
sqlWhereClause += burialSiteNameFilters.sqlWhereClause
sqlParameters.push(...burialSiteNameFilters.sqlParameters)
const deceasedNameFilters = getDeceasedNameWhereClause(
filters.deceasedName,
'o'
)
if (deceasedNameFilters.sqlParameters.length > 0) {
sqlWhereClause += ` and o.contractId in (
select contractId from ContractInterments o
where recordDelete_timeMillis is null
${deceasedNameFilters.sqlWhereClause})`
sqlParameters.push(...deceasedNameFilters.sqlParameters)
}
if ((filters.contractTypeId ?? '') !== '') {
sqlWhereClause += ' and o.contractTypeId = ?'
sqlParameters.push(filters.contractTypeId)
}
const contractTimeFilters = getContractTimeWhereClause(
filters.contractTime ?? '',
'o'
)
sqlWhereClause += contractTimeFilters.sqlWhereClause
sqlParameters.push(...contractTimeFilters.sqlParameters)
if ((filters.contractStartDateString ?? '') !== '') {
sqlWhereClause += ' and o.contractStartDate = ?'
sqlParameters.push(
dateStringToInteger(filters.contractStartDateString as DateString)
)
}
if ((filters.contractEffectiveDateString ?? '') !== '') {
sqlWhereClause += ` and (
o.contractEndDate is null
or (o.contractStartDate <= ? and o.contractEndDate >= ?)
)`
sqlParameters.push(
dateStringToInteger(filters.contractEffectiveDateString as DateString),
dateStringToInteger(filters.contractEffectiveDateString as DateString)
)
}
if ((filters.cemeteryId ?? '') !== '') {
sqlWhereClause += ' and (m.cemeteryId = ? or m.parentCemeteryId = ?)'
sqlParameters.push(filters.cemeteryId, filters.cemeteryId)
}
if ((filters.burialSiteTypeId ?? '') !== '') {
sqlWhereClause += ' and l.burialSiteTypeId = ?'
sqlParameters.push(filters.burialSiteTypeId)
}
if ((filters.funeralHomeId ?? '') !== '') {
sqlWhereClause += ' and o.funeralHomeId = ?'
sqlParameters.push(filters.funeralHomeId)
}
if ((filters.workOrderId ?? '') !== '') {
sqlWhereClause +=
' and o.contractId in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
sqlParameters.push(filters.workOrderId)
}
if ((filters.notWorkOrderId ?? '') !== '') {
sqlWhereClause +=
' and o.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
sqlParameters.push(filters.notWorkOrderId)
}
return {
sqlWhereClause,
sqlParameters
}
}

View File

@ -1,8 +1,8 @@
import type { PoolConnection } from 'better-sqlite-pool'; import type { PoolConnection } from 'better-sqlite-pool';
import type { FeeCategory } from '../types/recordTypes.js'; import type { FeeCategory } from '../types/recordTypes.js';
interface GetFeeCategoriesFilters { interface GetFeeCategoriesFilters {
contractTypeId?: number | string;
burialSiteTypeId?: number | string; burialSiteTypeId?: number | string;
contractTypeId?: number | string;
feeCategoryId?: number | string; feeCategoryId?: number | string;
} }
interface GetFeeCategoriesOptions { interface GetFeeCategoriesOptions {

View File

@ -7,8 +7,8 @@ import { acquireConnection } from './pool.js'
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
interface GetFeeCategoriesFilters { interface GetFeeCategoriesFilters {
contractTypeId?: number | string
burialSiteTypeId?: number | string burialSiteTypeId?: number | string
contractTypeId?: number | string
feeCategoryId?: number | string feeCategoryId?: number | string
} }

View File

@ -1,4 +1,10 @@
import { acquireConnection } from './pool.js'; import { acquireConnection } from './pool.js';
export default async function getFuneralHome(funeralHomeId) {
return await _getFuneralHome('funeralHomeId', funeralHomeId);
}
export async function getFuneralHomeByKey(funeralHomeKey) {
return await _getFuneralHome('funeralHomeKey', funeralHomeKey);
}
async function _getFuneralHome(keyColumn, funeralHomeIdOrKey) { async function _getFuneralHome(keyColumn, funeralHomeIdOrKey) {
const database = await acquireConnection(); const database = await acquireConnection();
const funeralHome = database const funeralHome = database
@ -13,9 +19,3 @@ async function _getFuneralHome(keyColumn, funeralHomeIdOrKey) {
database.release(); database.release();
return funeralHome; return funeralHome;
} }
export default async function getFuneralHome(funeralHomeId) {
return await _getFuneralHome('funeralHomeId', funeralHomeId);
}
export async function getFuneralHomeByKey(funeralHomeKey) {
return await _getFuneralHome('funeralHomeKey', funeralHomeKey);
}

View File

@ -2,6 +2,18 @@ import type { Cemetery, FuneralHome } from '../types/recordTypes.js'
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
export default async function getFuneralHome(
funeralHomeId: number | string
): Promise<FuneralHome | undefined> {
return await _getFuneralHome('funeralHomeId', funeralHomeId)
}
export async function getFuneralHomeByKey(
funeralHomeKey: string
): Promise<FuneralHome | undefined> {
return await _getFuneralHome('funeralHomeKey', funeralHomeKey)
}
async function _getFuneralHome( async function _getFuneralHome(
keyColumn: 'funeralHomeId' | 'funeralHomeKey', keyColumn: 'funeralHomeId' | 'funeralHomeKey',
funeralHomeIdOrKey: number | string funeralHomeIdOrKey: number | string
@ -24,15 +36,3 @@ async function _getFuneralHome(
return funeralHome return funeralHome
} }
export default async function getFuneralHome(
funeralHomeId: number | string
): Promise<FuneralHome | undefined> {
return await _getFuneralHome('funeralHomeId', funeralHomeId)
}
export async function getFuneralHomeByKey(
funeralHomeKey: string
): Promise<FuneralHome | undefined> {
return await _getFuneralHome('funeralHomeKey', funeralHomeKey)
}

View File

@ -71,7 +71,9 @@ const createStatements = [
cemeteryProvince varchar(2), cemeteryProvince varchar(2),
cemeteryPostalCode varchar(7), cemeteryPostalCode varchar(7),
cemeteryPhoneNumber varchar(30), cemeteryPhoneNumber varchar(30),
${recordColumns})`, parentCemeteryId integer,
${recordColumns},
foreign key (parentCemeteryId) references Cemeteries (cemeteryId))`,
/* /*
* Burial Sites * Burial Sites
*/ */

View File

@ -86,7 +86,9 @@ const createStatements = [
cemeteryProvince varchar(2), cemeteryProvince varchar(2),
cemeteryPostalCode varchar(7), cemeteryPostalCode varchar(7),
cemeteryPhoneNumber varchar(30), cemeteryPhoneNumber varchar(30),
${recordColumns})`, parentCemeteryId integer,
${recordColumns},
foreign key (parentCemeteryId) references Cemeteries (cemeteryId))`,
/* /*
* Burial Sites * Burial Sites

View File

@ -3,6 +3,7 @@ export interface UpdateCemeteryForm {
cemeteryDescription: string; cemeteryDescription: string;
cemeteryKey: string; cemeteryKey: string;
cemeteryName: string; cemeteryName: string;
parentCemeteryId: string;
cemeteryAddress1: string; cemeteryAddress1: string;
cemeteryAddress2: string; cemeteryAddress2: string;
cemeteryCity: string; cemeteryCity: string;
@ -13,7 +14,4 @@ export interface UpdateCemeteryForm {
cemeteryLongitude: string; cemeteryLongitude: string;
cemeterySvg: string; cemeterySvg: string;
} }
export default function updateCemetery(updateForm: UpdateCemeteryForm, user: User): Promise<{ export default function updateCemetery(updateForm: UpdateCemeteryForm, user: User): Promise<boolean>;
doRebuildBurialSiteNames: boolean;
success: boolean;
}>;

View File

@ -1,6 +1,3 @@
import { buildBurialSiteName } from '../helpers/burialSites.helpers.js';
import { getConfigProperty } from '../helpers/config.helpers.js';
import getBurialSites from './getBurialSites.js';
import { acquireConnection } from './pool.js'; import { acquireConnection } from './pool.js';
export default async function updateCemetery(updateForm, user) { export default async function updateCemetery(updateForm, user) {
const database = await acquireConnection(); const database = await acquireConnection();
@ -18,6 +15,7 @@ export default async function updateCemetery(updateForm, user) {
cemeteryProvince = ?, cemeteryProvince = ?,
cemeteryPostalCode = ?, cemeteryPostalCode = ?,
cemeteryPhoneNumber = ?, cemeteryPhoneNumber = ?,
parentCemeteryId = ?,
recordUpdate_userName = ?, recordUpdate_userName = ?,
recordUpdate_timeMillis = ? recordUpdate_timeMillis = ?
where cemeteryId = ? where cemeteryId = ?
@ -26,27 +24,9 @@ export default async function updateCemetery(updateForm, user) {
? undefined ? undefined
: updateForm.cemeteryLatitude, updateForm.cemeteryLongitude === '' : updateForm.cemeteryLatitude, updateForm.cemeteryLongitude === ''
? undefined ? undefined
: updateForm.cemeteryLongitude, updateForm.cemeteryAddress1, updateForm.cemeteryAddress2, updateForm.cemeteryCity, updateForm.cemeteryProvince, updateForm.cemeteryPostalCode, updateForm.cemeteryPhoneNumber, user.userName, Date.now(), updateForm.cemeteryId); : updateForm.cemeteryLongitude, updateForm.cemeteryAddress1, updateForm.cemeteryAddress2, updateForm.cemeteryCity, updateForm.cemeteryProvince, updateForm.cemeteryPostalCode, updateForm.cemeteryPhoneNumber, updateForm.parentCemeteryId === ''
/* ? undefined
* Check if burial site names need to be updated : updateForm.parentCemeteryId, user.userName, Date.now(), updateForm.cemeteryId);
*/
let doRebuildBurialSiteNames = false;
if (getConfigProperty('settings.burialSites.burialSiteNameSegments.includeCemeteryKey')) {
const burialSites = await getBurialSites({ cemeteryId: updateForm.cemeteryId }, { limit: 1, offset: 0 }, database);
if (burialSites.count > 0 &&
buildBurialSiteName(updateForm.cemeteryKey, {
burialSiteNameSegment1: burialSites.burialSites[0].burialSiteNameSegment1,
burialSiteNameSegment2: burialSites.burialSites[0].burialSiteNameSegment2,
burialSiteNameSegment3: burialSites.burialSites[0].burialSiteNameSegment3,
burialSiteNameSegment4: burialSites.burialSites[0].burialSiteNameSegment4,
burialSiteNameSegment5: burialSites.burialSites[0].burialSiteNameSegment5
}) !== burialSites.burialSites[0].burialSiteName) {
doRebuildBurialSiteNames = true;
}
}
database.release(); database.release();
return { return result.changes > 0;
doRebuildBurialSiteNames,
success: result.changes > 0
};
} }

View File

@ -1,7 +1,3 @@
import { buildBurialSiteName } from '../helpers/burialSites.helpers.js'
import { getConfigProperty } from '../helpers/config.helpers.js'
import getBurialSites from './getBurialSites.js'
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
export interface UpdateCemeteryForm { export interface UpdateCemeteryForm {
@ -10,6 +6,7 @@ export interface UpdateCemeteryForm {
cemeteryDescription: string cemeteryDescription: string
cemeteryKey: string cemeteryKey: string
cemeteryName: string cemeteryName: string
parentCemeteryId: string
cemeteryAddress1: string cemeteryAddress1: string
cemeteryAddress2: string cemeteryAddress2: string
@ -27,7 +24,7 @@ export interface UpdateCemeteryForm {
export default async function updateCemetery( export default async function updateCemetery(
updateForm: UpdateCemeteryForm, updateForm: UpdateCemeteryForm,
user: User user: User
): Promise<{ doRebuildBurialSiteNames: boolean; success: boolean; }> { ): Promise<boolean> {
const database = await acquireConnection() const database = await acquireConnection()
const result = database const result = database
@ -45,6 +42,7 @@ export default async function updateCemetery(
cemeteryProvince = ?, cemeteryProvince = ?,
cemeteryPostalCode = ?, cemeteryPostalCode = ?,
cemeteryPhoneNumber = ?, cemeteryPhoneNumber = ?,
parentCemeteryId = ?,
recordUpdate_userName = ?, recordUpdate_userName = ?,
recordUpdate_timeMillis = ? recordUpdate_timeMillis = ?
where cemeteryId = ? where cemeteryId = ?
@ -67,51 +65,15 @@ export default async function updateCemetery(
updateForm.cemeteryProvince, updateForm.cemeteryProvince,
updateForm.cemeteryPostalCode, updateForm.cemeteryPostalCode,
updateForm.cemeteryPhoneNumber, updateForm.cemeteryPhoneNumber,
updateForm.parentCemeteryId === ''
? undefined
: updateForm.parentCemeteryId,
user.userName, user.userName,
Date.now(), Date.now(),
updateForm.cemeteryId updateForm.cemeteryId
) )
/*
* Check if burial site names need to be updated
*/
let doRebuildBurialSiteNames = false
if (
getConfigProperty(
'settings.burialSites.burialSiteNameSegments.includeCemeteryKey'
)
) {
const burialSites = await getBurialSites(
{ cemeteryId: updateForm.cemeteryId },
{ limit: 1, offset: 0 },
database
)
if (
burialSites.count > 0 &&
buildBurialSiteName(updateForm.cemeteryKey, {
burialSiteNameSegment1:
burialSites.burialSites[0].burialSiteNameSegment1,
burialSiteNameSegment2:
burialSites.burialSites[0].burialSiteNameSegment2,
burialSiteNameSegment3:
burialSites.burialSites[0].burialSiteNameSegment3,
burialSiteNameSegment4:
burialSites.burialSites[0].burialSiteNameSegment4,
burialSiteNameSegment5:
burialSites.burialSites[0].burialSiteNameSegment5
}) !== burialSites.burialSites[0].burialSiteName
) {
doRebuildBurialSiteNames = true
}
}
database.release() database.release()
return { return result.changes > 0
doRebuildBurialSiteNames,
success: result.changes > 0
}
} }

View File

@ -1,5 +1,6 @@
import getBurialSiteStatusSummary from '../../database/getBurialSiteStatusSummary.js'; import getBurialSiteStatusSummary from '../../database/getBurialSiteStatusSummary.js';
import getBurialSiteTypeSummary from '../../database/getBurialSiteTypeSummary.js'; import getBurialSiteTypeSummary from '../../database/getBurialSiteTypeSummary.js';
import getCemeteries from '../../database/getCemeteries.js';
import getCemetery from '../../database/getCemetery.js'; import getCemetery from '../../database/getCemetery.js';
import { getConfigProperty } from '../../helpers/config.helpers.js'; import { getConfigProperty } from '../../helpers/config.helpers.js';
import { getCemeterySVGs } from '../../helpers/images.helpers.js'; import { getCemeterySVGs } from '../../helpers/images.helpers.js';
@ -9,6 +10,7 @@ export default async function handler(request, response) {
response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/cemeteries/?error=cemeteryIdNotFound`); response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/cemeteries/?error=cemeteryIdNotFound`);
return; return;
} }
const cemeteries = await getCemeteries();
const cemeterySVGs = await getCemeterySVGs(); const cemeterySVGs = await getCemeterySVGs();
const burialSiteTypeSummary = await getBurialSiteTypeSummary({ const burialSiteTypeSummary = await getBurialSiteTypeSummary({
cemeteryId: cemetery.cemeteryId cemeteryId: cemetery.cemeteryId
@ -22,6 +24,7 @@ export default async function handler(request, response) {
cemeterySVGs, cemeterySVGs,
isCreate: false, isCreate: false,
burialSiteStatusSummary, burialSiteStatusSummary,
burialSiteTypeSummary burialSiteTypeSummary,
cemeteries
}); });
} }

View File

@ -2,6 +2,7 @@ import type { Request, Response } from 'express'
import getBurialSiteStatusSummary from '../../database/getBurialSiteStatusSummary.js' import getBurialSiteStatusSummary from '../../database/getBurialSiteStatusSummary.js'
import getBurialSiteTypeSummary from '../../database/getBurialSiteTypeSummary.js' import getBurialSiteTypeSummary from '../../database/getBurialSiteTypeSummary.js'
import getCemeteries from '../../database/getCemeteries.js'
import getCemetery from '../../database/getCemetery.js' import getCemetery from '../../database/getCemetery.js'
import { getConfigProperty } from '../../helpers/config.helpers.js' import { getConfigProperty } from '../../helpers/config.helpers.js'
import { getCemeterySVGs } from '../../helpers/images.helpers.js' import { getCemeterySVGs } from '../../helpers/images.helpers.js'
@ -19,6 +20,8 @@ export default async function handler(
return return
} }
const cemeteries = await getCemeteries()
const cemeterySVGs = await getCemeterySVGs() const cemeterySVGs = await getCemeterySVGs()
const burialSiteTypeSummary = await getBurialSiteTypeSummary({ const burialSiteTypeSummary = await getBurialSiteTypeSummary({
@ -37,6 +40,7 @@ export default async function handler(
isCreate: false, isCreate: false,
burialSiteStatusSummary, burialSiteStatusSummary,
burialSiteTypeSummary burialSiteTypeSummary,
cemeteries
}) })
} }

View File

@ -2,13 +2,12 @@ import rebuildBurialSiteNames from '../../database/rebuildBurialSiteNames.js';
import updateCemetery from '../../database/updateCemetery.js'; import updateCemetery from '../../database/updateCemetery.js';
import { clearNextPreviousBurialSiteIdCache } from '../../helpers/burialSites.helpers.js'; import { clearNextPreviousBurialSiteIdCache } from '../../helpers/burialSites.helpers.js';
export default async function handler(request, response) { export default async function handler(request, response) {
const result = await updateCemetery(request.body, request.session.user); const success = await updateCemetery(request.body, request.session.user);
response.json({ response.json({
success: result.success, success,
cemeteryId: request.body.cemeteryId, cemeteryId: request.body.cemeteryId
doRebuildBurialSiteNames: result.doRebuildBurialSiteNames
}); });
if (result.doRebuildBurialSiteNames) { if (success) {
response.on('finish', () => { response.on('finish', () => {
void rebuildBurialSiteNames(request.body.cemeteryId, request.session.user); void rebuildBurialSiteNames(request.body.cemeteryId, request.session.user);
clearNextPreviousBurialSiteIdCache(); clearNextPreviousBurialSiteIdCache();

View File

@ -10,19 +10,18 @@ export default async function handler(
request: Request<unknown, unknown, UpdateCemeteryForm>, request: Request<unknown, unknown, UpdateCemeteryForm>,
response: Response response: Response
): Promise<void> { ): Promise<void> {
const result = await updateCemetery( const success = await updateCemetery(
request.body, request.body,
request.session.user as User request.session.user as User
) )
response.json({ response.json({
success: result.success, success,
cemeteryId: request.body.cemeteryId, cemeteryId: request.body.cemeteryId
doRebuildBurialSiteNames: result.doRebuildBurialSiteNames
}) })
if (result.doRebuildBurialSiteNames) { if (success) {
response.on('finish', () => { response.on('finish', () => {
void rebuildBurialSiteNames( void rebuildBurialSiteNames(
request.body.cemeteryId, request.body.cemeteryId,

View File

@ -45,20 +45,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
globalThis.location.href = sunrise.getCemeteryURL(responseJSON.cemeteryId, true); globalThis.location.href = sunrise.getCemeteryURL(responseJSON.cemeteryId, true);
} }
else { else {
if (responseJSON.doRebuildBurialSiteNames ?? false) { bulmaJS.alert({
bulmaJS.alert({ message: 'Cemetery Updated Successfully',
message: `<strong>Cemetery Updated Successfully</strong><br /> contextualColorName: 'success'
Note that rebuilding burial site names may take a few minutes.`, });
messageIsHtml: true,
contextualColorName: 'warning'
});
}
else {
bulmaJS.alert({
message: 'Cemetery Updated Successfully',
contextualColorName: 'success'
});
}
} }
} }
else { else {

View File

@ -71,7 +71,6 @@ declare const exports: Record<string, unknown>
const responseJSON = rawResponseJSON as { const responseJSON = rawResponseJSON as {
success: boolean success: boolean
cemeteryId?: number cemeteryId?: number
doRebuildBurialSiteNames?: boolean
errorMessage?: string errorMessage?: string
} }
@ -84,20 +83,10 @@ declare const exports: Record<string, unknown>
true true
) )
} else { } else {
if (responseJSON.doRebuildBurialSiteNames ?? false) { bulmaJS.alert({
bulmaJS.alert({ message: 'Cemetery Updated Successfully',
message: `<strong>Cemetery Updated Successfully</strong><br /> contextualColorName: 'success'
Note that rebuilding burial site names may take a few minutes.`, })
messageIsHtml: true,
contextualColorName: 'warning'
})
} else {
bulmaJS.alert({
message: 'Cemetery Updated Successfully',
contextualColorName: 'success'
})
}
} }
} else { } else {
bulmaJS.alert({ bulmaJS.alert({

View File

@ -42,6 +42,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
${cityssm.escapeHTML(cemetery.cemeteryName === '' ${cityssm.escapeHTML(cemetery.cemeteryName === ''
? '(No Name)' ? '(No Name)'
: cemetery.cemeteryName)} : cemetery.cemeteryName)}
${cemetery.cemeteryName === ''
? `<span class="icon is-small has-text-danger">
<i class="fas fa-exclamation-triangle" aria-hidden="true"></i>
</span>`
: ''}
</a><br /> </a><br />
<span class="is-size-7"> <span class="is-size-7">
${cityssm.escapeHTML(cemetery.cemeteryDescription)} ${cityssm.escapeHTML(cemetery.cemeteryDescription)}
@ -62,6 +67,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
: ''} : ''}
</td><td> </td><td>
${cityssm.escapeHTML(cemetery.cemeteryPhoneNumber)} ${cityssm.escapeHTML(cemetery.cemeteryPhoneNumber)}
</td><td class="has-text-centered">
${cemetery.parentCemeteryId === null
? ''
: `<span data-tooltip="Parent: ${cemetery.parentCemeteryName ?? '(No Name)'}">
<i class="fas fa-turn-up" role="img" aria-label="Parent: ${cemetery.parentCemeteryName ?? '(No Name)'}"></i>
</span>`}
</td><td class="has-text-centered"> </td><td class="has-text-centered">
${cemetery.cemeteryLatitude && cemetery.cemeteryLongitude ${cemetery.cemeteryLatitude && cemetery.cemeteryLongitude
? `<span data-tooltip="Has Geographic Coordinates"> ? `<span data-tooltip="Has Geographic Coordinates">
@ -92,6 +103,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
<th>Key</th> <th>Key</th>
<th>Address</th> <th>Address</th>
<th>Phone Number</th> <th>Phone Number</th>
<th class="has-text-centered">Parent</th>
<th class="has-text-centered">Coordinates</th> <th class="has-text-centered">Coordinates</th>
<th class="has-text-centered">Image</th> <th class="has-text-centered">Image</th>
<th class="has-text-right">Burial Site Count</th> <th class="has-text-right">Burial Site Count</th>

View File

@ -71,6 +71,13 @@ declare const exports: Record<string, unknown>
? '(No Name)' ? '(No Name)'
: cemetery.cemeteryName : cemetery.cemeteryName
)} )}
${
cemetery.cemeteryName === ''
? `<span class="icon is-small has-text-danger">
<i class="fas fa-exclamation-triangle" aria-hidden="true"></i>
</span>`
: ''
}
</a><br /> </a><br />
<span class="is-size-7"> <span class="is-size-7">
${cityssm.escapeHTML(cemetery.cemeteryDescription)} ${cityssm.escapeHTML(cemetery.cemeteryDescription)}
@ -97,6 +104,14 @@ declare const exports: Record<string, unknown>
} }
</td><td> </td><td>
${cityssm.escapeHTML(cemetery.cemeteryPhoneNumber)} ${cityssm.escapeHTML(cemetery.cemeteryPhoneNumber)}
</td><td class="has-text-centered">
${
cemetery.parentCemeteryId === null
? ''
: `<span data-tooltip="Parent: ${cemetery.parentCemeteryName ?? '(No Name)'}">
<i class="fas fa-turn-up" role="img" aria-label="Parent: ${cemetery.parentCemeteryName ?? '(No Name)'}"></i>
</span>`
}
</td><td class="has-text-centered"> </td><td class="has-text-centered">
${ ${
cemetery.cemeteryLatitude && cemetery.cemeteryLongitude cemetery.cemeteryLatitude && cemetery.cemeteryLongitude
@ -135,6 +150,7 @@ declare const exports: Record<string, unknown>
<th>Key</th> <th>Key</th>
<th>Address</th> <th>Address</th>
<th>Phone Number</th> <th>Phone Number</th>
<th class="has-text-centered">Parent</th>
<th class="has-text-centered">Coordinates</th> <th class="has-text-centered">Coordinates</th>
<th class="has-text-centered">Image</th> <th class="has-text-centered">Image</th>
<th class="has-text-right">Burial Site Count</th> <th class="has-text-right">Burial Site Count</th>

View File

@ -44,7 +44,8 @@ export async function getCemeteryIdByKey(cemeteryKeyToSearch, user) {
cemeteryCity: 'Sault Ste. Marie', cemeteryCity: 'Sault Ste. Marie',
cemeteryPostalCode: '', cemeteryPostalCode: '',
cemeteryProvince: 'ON', cemeteryProvince: 'ON',
cemeteryPhoneNumber: '' cemeteryPhoneNumber: '',
parentCemeteryId: '',
}, user); }, user);
cemeteryCache.set(cemeteryKey, cemeteryId); cemeteryCache.set(cemeteryKey, cemeteryId);
} }

View File

@ -62,7 +62,8 @@ export async function getCemeteryIdByKey(
cemeteryPostalCode: '', cemeteryPostalCode: '',
cemeteryProvince: 'ON', cemeteryProvince: 'ON',
cemeteryPhoneNumber: '' cemeteryPhoneNumber: '',
parentCemeteryId: '',
}, },
user user
) )

View File

@ -67,6 +67,8 @@ export interface Cemetery extends Record {
cemeteryDescription: string; cemeteryDescription: string;
cemeteryKey: string; cemeteryKey: string;
cemeteryName: string; cemeteryName: string;
parentCemeteryId?: number | null;
parentCemeteryName?: string | null;
cemeteryLatitude?: number; cemeteryLatitude?: number;
cemeteryLongitude?: number; cemeteryLongitude?: number;
cemeterySvg?: string; cemeterySvg?: string;

View File

@ -94,6 +94,9 @@ export interface Cemetery extends Record {
cemeteryKey: string cemeteryKey: string
cemeteryName: string cemeteryName: string
parentCemeteryId?: number | null
parentCemeteryName?: string | null
cemeteryLatitude?: number cemeteryLatitude?: number
cemeteryLongitude?: number cemeteryLongitude?: number
cemeterySvg?: string cemeterySvg?: string

View File

@ -127,6 +127,27 @@
<textarea class="textarea" id="cemetery--cemeteryDescription" name="cemeteryDescription"><%= cemetery.cemeteryDescription %></textarea> <textarea class="textarea" id="cemetery--cemeteryDescription" name="cemeteryDescription"><%= cemetery.cemeteryDescription %></textarea>
</div> </div>
</div> </div>
<div class="field">
<label class="label" for="cemetery--parentCemeteryId">Parent Cemetery</label>
<div class="control">
<div class="select is-fullwidth">
<select id="cemetery--parentCemeteryId" name="parentCemeteryId">
<option value="">(No Parent Cemetery)</option>
<% for (const parentCemetery of cemeteries) { %>
<%
if (parentCemetery.cemeteryId === cemetery.cemeteryId || parentCemetery.parentCemeteryId !== null) {
// Skip the current cemetery and any cemeteries that are already a parent
continue;
}
%>
<option value="<%= parentCemetery.cemeteryId %>" <%= (cemetery.parentCemeteryId === parentCemetery.cemeteryId) ? " selected" : "" %>>
<%= parentCemetery.cemeteryName === '' ? '(No Name)' : parentCemetery.cemeteryName %>
</option>
<% } %>
</select>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -89,6 +89,14 @@
<%= cemetery.cemeteryPhoneNumber %> <%= cemetery.cemeteryPhoneNumber %>
</div> </div>
<% } %> <% } %>
<% if (cemetery.parentCemeteryId !== null) { %>
<div class="column">
<strong>Parent Cemetery</strong><br />
<a href="<%= urlPrefix %>/cemeteries/<%= cemetery.parentCemeteryId %>">
<%= (cemetery.parentCemeteryName ?? '') === '' ? "(No Name)" : cemetery.parentCemeteryName %>
</a>
</div>
<% } %>
</div> </div>
</div> </div>
</div> </div>