Compare commits
No commits in common. "main" and "v1.0.0-alpha.9" have entirely different histories.
main
...
v1.0.0-alp
|
|
@ -1,2 +1,2 @@
|
||||||
theme: jekyll-theme-cayman
|
theme: jekyll-theme-cayman
|
||||||
title: Sunrise Cemetery Management System (CMS)
|
title: Sunrise Cemetery Management System
|
||||||
|
|
@ -12,7 +12,7 @@ import { getConfigProperty } from '../helpers/config.helpers.js';
|
||||||
import version from '../version.js';
|
import version from '../version.js';
|
||||||
const debug = Debug(`${DEBUG_NAMESPACE}:www:${process.pid}`);
|
const debug = Debug(`${DEBUG_NAMESPACE}:www:${process.pid}`);
|
||||||
// INITIALIZE THE DATABASE
|
// INITIALIZE THE DATABASE
|
||||||
initializeDatabase();
|
await initializeDatabase();
|
||||||
const directoryName = path.dirname(fileURLToPath(import.meta.url));
|
const directoryName = path.dirname(fileURLToPath(import.meta.url));
|
||||||
const processCount = Math.min(getConfigProperty('application.maximumProcesses'), os.cpus().length * 2);
|
const processCount = Math.min(getConfigProperty('application.maximumProcesses'), os.cpus().length * 2);
|
||||||
const applicationName = getConfigProperty('application.applicationName');
|
const applicationName = getConfigProperty('application.applicationName');
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import version from '../version.js'
|
||||||
const debug = Debug(`${DEBUG_NAMESPACE}:www:${process.pid}`)
|
const debug = Debug(`${DEBUG_NAMESPACE}:www:${process.pid}`)
|
||||||
|
|
||||||
// INITIALIZE THE DATABASE
|
// INITIALIZE THE DATABASE
|
||||||
initializeDatabase()
|
await initializeDatabase()
|
||||||
|
|
||||||
const directoryName = path.dirname(fileURLToPath(import.meta.url))
|
const directoryName = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { getConfigProperty } from '../helpers/config.helpers.js';
|
||||||
const debug = Debug(`${DEBUG_NAMESPACE}:wwwProcess:${process.pid.toString().padEnd(5)}`);
|
const debug = Debug(`${DEBUG_NAMESPACE}:wwwProcess:${process.pid.toString().padEnd(5)}`);
|
||||||
if (process.send === undefined) {
|
if (process.send === undefined) {
|
||||||
// INITIALIZE THE DATABASE
|
// INITIALIZE THE DATABASE
|
||||||
initializeDatabase();
|
await initializeDatabase();
|
||||||
}
|
}
|
||||||
function onError(error) {
|
function onError(error) {
|
||||||
if (error.syscall !== 'listen') {
|
if (error.syscall !== 'listen') {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ const debug = Debug(`${DEBUG_NAMESPACE}:wwwProcess:${process.pid.toString().padE
|
||||||
|
|
||||||
if (process.send === undefined) {
|
if (process.send === undefined) {
|
||||||
// INITIALIZE THE DATABASE
|
// INITIALIZE THE DATABASE
|
||||||
initializeDatabase()
|
await initializeDatabase()
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ServerError extends Error {
|
interface ServerError extends Error {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ export const config = {
|
||||||
settings: {
|
settings: {
|
||||||
adminCleanup: {},
|
adminCleanup: {},
|
||||||
burialSites: {},
|
burialSites: {},
|
||||||
burialSiteTypes: {},
|
|
||||||
cemeteries: {},
|
cemeteries: {},
|
||||||
contracts: {},
|
contracts: {},
|
||||||
dynamicsGP: {
|
dynamicsGP: {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ export const config: Config = {
|
||||||
settings: {
|
settings: {
|
||||||
adminCleanup: {},
|
adminCleanup: {},
|
||||||
burialSites: {},
|
burialSites: {},
|
||||||
burialSiteTypes: {},
|
|
||||||
cemeteries: {},
|
cemeteries: {},
|
||||||
contracts: {},
|
contracts: {},
|
||||||
dynamicsGP: {
|
dynamicsGP: {
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,6 @@ export declare const configDefaultValues: {
|
||||||
'settings.longitudeMax': number;
|
'settings.longitudeMax': number;
|
||||||
'settings.longitudeMin': number;
|
'settings.longitudeMin': number;
|
||||||
'settings.cemeteries.refreshImageChanges': boolean;
|
'settings.cemeteries.refreshImageChanges': boolean;
|
||||||
'settings.burialSiteTypes.bodyCapacityMaxDefault': number;
|
|
||||||
'settings.burialSiteTypes.crematedCapacityMaxDefault': number;
|
|
||||||
'settings.burialSites.burialSiteNameSegments': ConfigBurialSiteNameSegments;
|
'settings.burialSites.burialSiteNameSegments': ConfigBurialSiteNameSegments;
|
||||||
'settings.burialSites.burialSiteNameSegments.includeCemeteryKey': boolean;
|
'settings.burialSites.burialSiteNameSegments.includeCemeteryKey': boolean;
|
||||||
'settings.burialSites.refreshImageChanges': boolean;
|
'settings.burialSites.refreshImageChanges': boolean;
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,6 @@ export const configDefaultValues = {
|
||||||
'settings.longitudeMax': 180,
|
'settings.longitudeMax': 180,
|
||||||
'settings.longitudeMin': -180,
|
'settings.longitudeMin': -180,
|
||||||
'settings.cemeteries.refreshImageChanges': false,
|
'settings.cemeteries.refreshImageChanges': false,
|
||||||
// eslint-disable-next-line no-secrets/no-secrets
|
|
||||||
'settings.burialSiteTypes.bodyCapacityMaxDefault': 2,
|
|
||||||
// eslint-disable-next-line no-secrets/no-secrets
|
|
||||||
'settings.burialSiteTypes.crematedCapacityMaxDefault': 6,
|
|
||||||
'settings.burialSites.burialSiteNameSegments': {
|
'settings.burialSites.burialSiteNameSegments': {
|
||||||
includeCemeteryKey: false,
|
includeCemeteryKey: false,
|
||||||
separator: '-',
|
separator: '-',
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { hoursToMillis } from '@cityssm/to-millis'
|
|
||||||
import type { config as MSSQLConfig } from 'mssql'
|
import type { config as MSSQLConfig } from 'mssql'
|
||||||
|
|
||||||
|
import { hoursToMillis } from '@cityssm/to-millis'
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ConfigActiveDirectory,
|
ConfigActiveDirectory,
|
||||||
ConfigBurialSiteNameSegments,
|
ConfigBurialSiteNameSegments,
|
||||||
|
|
@ -51,12 +52,6 @@ export const configDefaultValues = {
|
||||||
|
|
||||||
'settings.cemeteries.refreshImageChanges': false,
|
'settings.cemeteries.refreshImageChanges': false,
|
||||||
|
|
||||||
// eslint-disable-next-line no-secrets/no-secrets
|
|
||||||
'settings.burialSiteTypes.bodyCapacityMaxDefault': 2,
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-secrets/no-secrets
|
|
||||||
'settings.burialSiteTypes.crematedCapacityMaxDefault': 6,
|
|
||||||
|
|
||||||
'settings.burialSites.burialSiteNameSegments': {
|
'settings.burialSites.burialSiteNameSegments': {
|
||||||
includeCemeteryKey: false,
|
includeCemeteryKey: false,
|
||||||
separator: '-',
|
separator: '-',
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ export interface AddBurialSiteForm {
|
||||||
burialSiteNameSegment5?: string;
|
burialSiteNameSegment5?: string;
|
||||||
burialSiteStatusId: number | string;
|
burialSiteStatusId: number | string;
|
||||||
burialSiteTypeId: number | string;
|
burialSiteTypeId: number | string;
|
||||||
bodyCapacity?: number | string;
|
|
||||||
crematedCapacity?: number | string;
|
|
||||||
burialSiteImage?: string;
|
burialSiteImage?: string;
|
||||||
cemeteryId: number | string;
|
cemeteryId: number | string;
|
||||||
cemeterySvgId?: string;
|
cemeterySvgId?: string;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import getCemetery from './getCemetery.js';
|
||||||
* @returns The new burial site's id.
|
* @returns The new burial site's id.
|
||||||
* @throws If an active burial site with the same name already exists.
|
* @throws If an active burial site with the same name already exists.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line complexity
|
|
||||||
export default function addBurialSite(burialSiteForm, user) {
|
export default function addBurialSite(burialSiteForm, user) {
|
||||||
const database = sqlite(sunriseDB);
|
const database = sqlite(sunriseDB);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
|
|
@ -39,22 +38,17 @@ export default function addBurialSite(burialSiteForm, user) {
|
||||||
burialSiteNameSegment5,
|
burialSiteNameSegment5,
|
||||||
burialSiteName,
|
burialSiteName,
|
||||||
burialSiteTypeId, burialSiteStatusId,
|
burialSiteTypeId, burialSiteStatusId,
|
||||||
bodyCapacity, crematedCapacity,
|
|
||||||
cemeteryId, cemeterySvgId, burialSiteImage,
|
cemeteryId, cemeterySvgId, burialSiteImage,
|
||||||
burialSiteLatitude, burialSiteLongitude,
|
burialSiteLatitude, burialSiteLongitude,
|
||||||
|
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?,
|
values (?, ?, ?,
|
||||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||||
?, ?, ?, ?)`)
|
?, ?, ?, ?)`)
|
||||||
.run(burialSiteForm.burialSiteNameSegment1 ?? '', burialSiteForm.burialSiteNameSegment2 ?? '', burialSiteForm.burialSiteNameSegment3 ?? '', burialSiteForm.burialSiteNameSegment4 ?? '', burialSiteForm.burialSiteNameSegment5 ?? '', burialSiteName, burialSiteForm.burialSiteTypeId, burialSiteForm.burialSiteStatusId === ''
|
.run(burialSiteForm.burialSiteNameSegment1 ?? '', burialSiteForm.burialSiteNameSegment2 ?? '', burialSiteForm.burialSiteNameSegment3 ?? '', burialSiteForm.burialSiteNameSegment4 ?? '', burialSiteForm.burialSiteNameSegment5 ?? '', burialSiteName, burialSiteForm.burialSiteTypeId, burialSiteForm.burialSiteStatusId === ''
|
||||||
? undefined
|
? undefined
|
||||||
: burialSiteForm.burialSiteStatusId, burialSiteForm.bodyCapacity === ''
|
: burialSiteForm.burialSiteStatusId, burialSiteForm.cemeteryId === '' ? undefined : burialSiteForm.cemeteryId, burialSiteForm.cemeterySvgId, burialSiteForm.burialSiteImage ?? '', burialSiteForm.burialSiteLatitude === ''
|
||||||
? undefined
|
|
||||||
: burialSiteForm.bodyCapacity, burialSiteForm.crematedCapacity === ''
|
|
||||||
? undefined
|
|
||||||
: burialSiteForm.crematedCapacity, burialSiteForm.cemeteryId === '' ? undefined : burialSiteForm.cemeteryId, burialSiteForm.cemeterySvgId, burialSiteForm.burialSiteImage ?? '', burialSiteForm.burialSiteLatitude === ''
|
|
||||||
? undefined
|
? undefined
|
||||||
: burialSiteForm.burialSiteLatitude, burialSiteForm.burialSiteLongitude === ''
|
: burialSiteForm.burialSiteLatitude, burialSiteForm.burialSiteLongitude === ''
|
||||||
? undefined
|
? undefined
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,6 @@ export interface AddBurialSiteForm {
|
||||||
burialSiteStatusId: number | string
|
burialSiteStatusId: number | string
|
||||||
burialSiteTypeId: number | string
|
burialSiteTypeId: number | string
|
||||||
|
|
||||||
bodyCapacity?: number | string
|
|
||||||
crematedCapacity?: number | string
|
|
||||||
|
|
||||||
burialSiteImage?: string
|
burialSiteImage?: string
|
||||||
cemeteryId: number | string
|
cemeteryId: number | string
|
||||||
cemeterySvgId?: string
|
cemeterySvgId?: string
|
||||||
|
|
@ -38,7 +35,6 @@ export interface AddBurialSiteForm {
|
||||||
* @returns The new burial site's id.
|
* @returns The new burial site's id.
|
||||||
* @throws If an active burial site with the same name already exists.
|
* @throws If an active burial site with the same name already exists.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line complexity
|
|
||||||
export default function addBurialSite(
|
export default function addBurialSite(
|
||||||
burialSiteForm: AddBurialSiteForm,
|
burialSiteForm: AddBurialSiteForm,
|
||||||
user: User
|
user: User
|
||||||
|
|
@ -84,13 +80,12 @@ export default function addBurialSite(
|
||||||
burialSiteNameSegment5,
|
burialSiteNameSegment5,
|
||||||
burialSiteName,
|
burialSiteName,
|
||||||
burialSiteTypeId, burialSiteStatusId,
|
burialSiteTypeId, burialSiteStatusId,
|
||||||
bodyCapacity, crematedCapacity,
|
|
||||||
cemeteryId, cemeterySvgId, burialSiteImage,
|
cemeteryId, cemeterySvgId, burialSiteImage,
|
||||||
burialSiteLatitude, burialSiteLongitude,
|
burialSiteLatitude, burialSiteLongitude,
|
||||||
|
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?,
|
values (?, ?, ?,
|
||||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||||
?, ?, ?, ?)`
|
?, ?, ?, ?)`
|
||||||
)
|
)
|
||||||
|
|
@ -105,15 +100,6 @@ export default function addBurialSite(
|
||||||
burialSiteForm.burialSiteStatusId === ''
|
burialSiteForm.burialSiteStatusId === ''
|
||||||
? undefined
|
? undefined
|
||||||
: burialSiteForm.burialSiteStatusId,
|
: burialSiteForm.burialSiteStatusId,
|
||||||
|
|
||||||
burialSiteForm.bodyCapacity === ''
|
|
||||||
? undefined
|
|
||||||
: burialSiteForm.bodyCapacity,
|
|
||||||
|
|
||||||
burialSiteForm.crematedCapacity === ''
|
|
||||||
? undefined
|
|
||||||
: burialSiteForm.crematedCapacity,
|
|
||||||
|
|
||||||
burialSiteForm.cemeteryId === '' ? undefined : burialSiteForm.cemeteryId,
|
burialSiteForm.cemeteryId === '' ? undefined : burialSiteForm.cemeteryId,
|
||||||
burialSiteForm.cemeterySvgId,
|
burialSiteForm.cemeterySvgId,
|
||||||
burialSiteForm.burialSiteImage ?? '',
|
burialSiteForm.burialSiteImage ?? '',
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
export interface AddBurialSiteTypeForm {
|
|
||||||
burialSiteType: string;
|
|
||||||
bodyCapacityMax: number | string;
|
|
||||||
crematedCapacityMax: number | string;
|
|
||||||
orderNumber?: number | string;
|
|
||||||
}
|
|
||||||
export default function addBurialSiteType(addForm: AddBurialSiteTypeForm, user: User): number;
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
import sqlite from 'better-sqlite3';
|
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
|
||||||
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
|
||||||
export default function addBurialSiteType(addForm, user) {
|
|
||||||
const database = sqlite(sunriseDB);
|
|
||||||
const rightNowMillis = Date.now();
|
|
||||||
const result = database
|
|
||||||
.prepare(`insert into BurialSiteTypes (
|
|
||||||
burialSiteType, bodyCapacityMax, crematedCapacityMax,
|
|
||||||
orderNumber,
|
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
||||||
.run(addForm.burialSiteType, addForm.bodyCapacityMax === '' ? undefined : addForm.bodyCapacityMax, addForm.crematedCapacityMax === ''
|
|
||||||
? undefined
|
|
||||||
: addForm.crematedCapacityMax, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
|
||||||
database.close();
|
|
||||||
clearCacheByTableName('BurialSiteTypes');
|
|
||||||
return result.lastInsertRowid;
|
|
||||||
}
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
import sqlite from 'better-sqlite3'
|
|
||||||
|
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
|
||||||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
|
||||||
|
|
||||||
export interface AddBurialSiteTypeForm {
|
|
||||||
burialSiteType: string
|
|
||||||
|
|
||||||
bodyCapacityMax: number | string
|
|
||||||
crematedCapacityMax: number | string
|
|
||||||
|
|
||||||
orderNumber?: number | string
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function addBurialSiteType(
|
|
||||||
addForm: AddBurialSiteTypeForm,
|
|
||||||
user: User
|
|
||||||
): number {
|
|
||||||
const database = sqlite(sunriseDB)
|
|
||||||
|
|
||||||
const rightNowMillis = Date.now()
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(
|
|
||||||
`insert into BurialSiteTypes (
|
|
||||||
burialSiteType, bodyCapacityMax, crematedCapacityMax,
|
|
||||||
orderNumber,
|
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?)`
|
|
||||||
)
|
|
||||||
.run(
|
|
||||||
addForm.burialSiteType,
|
|
||||||
addForm.bodyCapacityMax === '' ? undefined : addForm.bodyCapacityMax,
|
|
||||||
addForm.crematedCapacityMax === ''
|
|
||||||
? undefined
|
|
||||||
: addForm.crematedCapacityMax,
|
|
||||||
addForm.orderNumber ?? -1,
|
|
||||||
user.userName,
|
|
||||||
rightNowMillis,
|
|
||||||
user.userName,
|
|
||||||
rightNowMillis
|
|
||||||
)
|
|
||||||
|
|
||||||
database.close()
|
|
||||||
|
|
||||||
clearCacheByTableName('BurialSiteTypes')
|
|
||||||
|
|
||||||
return result.lastInsertRowid as number
|
|
||||||
}
|
|
||||||
|
|
@ -14,9 +14,7 @@ export default function addBurialSiteTypeField(addForm, user) {
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||||
.run(addForm.burialSiteTypeId, addForm.burialSiteTypeField, addForm.fieldType ?? 'text', addForm.fieldValues ?? '', addForm.isRequired === '' ? 0 : 1, addForm.pattern ?? '', addForm.minLength ?? 0,
|
.run(addForm.burialSiteTypeId, addForm.burialSiteTypeField, addForm.fieldType ?? 'text', addForm.fieldValues ?? '', addForm.isRequired === '' ? 0 : 1, addForm.pattern ?? '', addForm.minLength ?? 0, addForm.maxLength ?? 100, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
||||||
addForm.maxLength ?? 100, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
|
||||||
database.close();
|
database.close();
|
||||||
clearCacheByTableName('BurialSiteTypeFields');
|
clearCacheByTableName('BurialSiteTypeFields');
|
||||||
return result.lastInsertRowid;
|
return result.lastInsertRowid;
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ export default function addBurialSiteTypeField(
|
||||||
addForm.isRequired === '' ? 0 : 1,
|
addForm.isRequired === '' ? 0 : 1,
|
||||||
addForm.pattern ?? '',
|
addForm.pattern ?? '',
|
||||||
addForm.minLength ?? 0,
|
addForm.minLength ?? 0,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
||||||
addForm.maxLength ?? 100,
|
addForm.maxLength ?? 100,
|
||||||
addForm.orderNumber ?? -1,
|
addForm.orderNumber ?? -1,
|
||||||
user.userName,
|
user.userName,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import { type DateString, type TimeString } from '@cityssm/utils-datetime';
|
|
||||||
export interface AddTransactionForm {
|
export interface AddTransactionForm {
|
||||||
contractId: number | string;
|
contractId: number | string;
|
||||||
transactionDateString?: '' | DateString;
|
transactionDateString?: string;
|
||||||
transactionTimeString?: '' | TimeString;
|
transactionTimeString?: string;
|
||||||
externalReceiptNumber: string;
|
externalReceiptNumber: string;
|
||||||
transactionAmount: number | string;
|
transactionAmount: number | string;
|
||||||
transactionNote: string;
|
transactionNote: string;
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,12 @@ export default function addContractTransaction(contractTransactionForm, user) {
|
||||||
transactionIndex = maxIndexResult.transactionIndex + 1;
|
transactionIndex = maxIndexResult.transactionIndex + 1;
|
||||||
}
|
}
|
||||||
const rightNow = new Date();
|
const rightNow = new Date();
|
||||||
const transactionDate = (contractTransactionForm.transactionDateString ?? '') === ''
|
const transactionDate = contractTransactionForm.transactionDateString
|
||||||
? dateToInteger(rightNow)
|
? dateStringToInteger(contractTransactionForm.transactionDateString)
|
||||||
: dateStringToInteger(contractTransactionForm.transactionDateString);
|
: dateToInteger(rightNow);
|
||||||
const transactionTime = (contractTransactionForm.transactionTimeString ?? '') === ''
|
const transactionTime = contractTransactionForm.transactionTimeString
|
||||||
? dateToTimeInteger(rightNow)
|
? timeStringToInteger(contractTransactionForm.transactionTimeString)
|
||||||
: timeStringToInteger(contractTransactionForm.transactionTimeString);
|
: dateToTimeInteger(rightNow);
|
||||||
database
|
database
|
||||||
.prepare(`insert into ContractTransactions (
|
.prepare(`insert into ContractTransactions (
|
||||||
contractId, transactionIndex,
|
contractId, transactionIndex,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import {
|
import {
|
||||||
type DateString,
|
|
||||||
type TimeString,
|
|
||||||
dateStringToInteger,
|
dateStringToInteger,
|
||||||
dateToInteger,
|
dateToInteger,
|
||||||
dateToTimeInteger,
|
dateToTimeInteger,
|
||||||
|
|
@ -13,8 +11,8 @@ import { sunriseDB } from '../helpers/database.helpers.js'
|
||||||
export interface AddTransactionForm {
|
export interface AddTransactionForm {
|
||||||
contractId: number | string
|
contractId: number | string
|
||||||
|
|
||||||
transactionDateString?: '' | DateString
|
transactionDateString?: string
|
||||||
transactionTimeString?: '' | TimeString
|
transactionTimeString?: string
|
||||||
|
|
||||||
externalReceiptNumber: string
|
externalReceiptNumber: string
|
||||||
transactionAmount: number | string
|
transactionAmount: number | string
|
||||||
|
|
@ -47,19 +45,13 @@ export default function addContractTransaction(
|
||||||
|
|
||||||
const rightNow = new Date()
|
const rightNow = new Date()
|
||||||
|
|
||||||
const transactionDate =
|
const transactionDate = contractTransactionForm.transactionDateString
|
||||||
(contractTransactionForm.transactionDateString ?? '') === ''
|
? dateStringToInteger(contractTransactionForm.transactionDateString)
|
||||||
? dateToInteger(rightNow)
|
: dateToInteger(rightNow)
|
||||||
: dateStringToInteger(
|
|
||||||
contractTransactionForm.transactionDateString as DateString
|
|
||||||
)
|
|
||||||
|
|
||||||
const transactionTime =
|
const transactionTime = contractTransactionForm.transactionTimeString
|
||||||
(contractTransactionForm.transactionTimeString ?? '') === ''
|
? timeStringToInteger(contractTransactionForm.transactionTimeString)
|
||||||
? dateToTimeInteger(rightNow)
|
: dateToTimeInteger(rightNow)
|
||||||
: timeStringToInteger(
|
|
||||||
contractTransactionForm.transactionTimeString as TimeString
|
|
||||||
)
|
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
export interface AddContractTypeFieldForm {
|
export interface AddContractTypeFieldForm {
|
||||||
contractTypeId?: number | string;
|
contractTypeId?: number | string;
|
||||||
contractTypeField: string;
|
contractTypeField: string;
|
||||||
fieldType?: string;
|
|
||||||
fieldValues?: string;
|
fieldValues?: string;
|
||||||
|
fieldType?: string;
|
||||||
isRequired?: string;
|
isRequired?: string;
|
||||||
maxLength?: number | string;
|
maxLength?: number | string;
|
||||||
minLength?: number | string;
|
minLength?: number | string;
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,7 @@ export default function addContractTypeField(addForm, user) {
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||||
.run(addForm.contractTypeId ?? undefined, addForm.contractTypeField, addForm.fieldType ?? 'text', addForm.fieldValues ?? '', addForm.isRequired === '' ? 0 : 1, addForm.pattern ?? '', addForm.minLength ?? 0,
|
.run(addForm.contractTypeId ?? undefined, addForm.contractTypeField, addForm.fieldType ?? 'text', addForm.fieldValues ?? '', addForm.isRequired === '' ? 0 : 1, addForm.pattern ?? '', addForm.minLength ?? 0, addForm.maxLength ?? 100, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
||||||
addForm.maxLength ?? 100, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
|
||||||
database.close();
|
database.close();
|
||||||
clearCacheByTableName('ContractTypeFields');
|
clearCacheByTableName('ContractTypeFields');
|
||||||
return result.lastInsertRowid;
|
return result.lastInsertRowid;
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,9 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||||
|
|
||||||
export interface AddContractTypeFieldForm {
|
export interface AddContractTypeFieldForm {
|
||||||
contractTypeId?: number | string
|
contractTypeId?: number | string
|
||||||
|
|
||||||
contractTypeField: string
|
contractTypeField: string
|
||||||
|
|
||||||
fieldType?: string
|
|
||||||
fieldValues?: string
|
fieldValues?: string
|
||||||
|
fieldType?: string
|
||||||
isRequired?: string
|
isRequired?: string
|
||||||
maxLength?: number | string
|
maxLength?: number | string
|
||||||
minLength?: number | string
|
minLength?: number | string
|
||||||
|
|
@ -45,7 +43,6 @@ export default function addContractTypeField(
|
||||||
addForm.isRequired === '' ? 0 : 1,
|
addForm.isRequired === '' ? 0 : 1,
|
||||||
addForm.pattern ?? '',
|
addForm.pattern ?? '',
|
||||||
addForm.minLength ?? 0,
|
addForm.minLength ?? 0,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
||||||
addForm.maxLength ?? 100,
|
addForm.maxLength ?? 100,
|
||||||
addForm.orderNumber ?? -1,
|
addForm.orderNumber ?? -1,
|
||||||
user.userName,
|
user.userName,
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ export default function addContractTypePrint(addForm, user) {
|
||||||
let result = database
|
let result = database
|
||||||
.prepare(`update ContractTypePrints
|
.prepare(`update ContractTypePrints
|
||||||
set recordUpdate_userName = ?,
|
set recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?,
|
recordUpdate_timeMillis = ?,
|
||||||
recordDelete_userName = null,
|
recordDelete_userName = null,
|
||||||
recordDelete_timeMillis = null
|
recordDelete_timeMillis = null
|
||||||
where contractTypeId = ?
|
where contractTypeId = ?
|
||||||
and printEJS = ?`)
|
and printEJS = ?`)
|
||||||
.run(user.userName, rightNowMillis, addForm.contractTypeId, addForm.printEJS);
|
.run(user.userName, rightNowMillis, addForm.contractTypeId, addForm.printEJS);
|
||||||
if (result.changes === 0) {
|
if (result.changes === 0) {
|
||||||
result = database
|
result = database
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||||
export interface AddContractTypePrintForm {
|
export interface AddContractTypePrintForm {
|
||||||
contractTypeId: number | string
|
contractTypeId: number | string
|
||||||
printEJS: string
|
printEJS: string
|
||||||
|
|
||||||
orderNumber?: number
|
orderNumber?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,11 +21,11 @@ export default function addContractTypePrint(
|
||||||
.prepare(
|
.prepare(
|
||||||
`update ContractTypePrints
|
`update ContractTypePrints
|
||||||
set recordUpdate_userName = ?,
|
set recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?,
|
recordUpdate_timeMillis = ?,
|
||||||
recordDelete_userName = null,
|
recordDelete_userName = null,
|
||||||
recordDelete_timeMillis = null
|
recordDelete_timeMillis = null
|
||||||
where contractTypeId = ?
|
where contractTypeId = ?
|
||||||
and printEJS = ?`
|
and printEJS = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
user.userName,
|
user.userName,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
export interface AddForm {
|
export interface AddForm {
|
||||||
funeralHomeKey: string;
|
|
||||||
funeralHomeName: string;
|
funeralHomeName: string;
|
||||||
|
funeralHomeKey: string;
|
||||||
funeralHomeAddress1: string;
|
funeralHomeAddress1: string;
|
||||||
funeralHomeAddress2: string;
|
funeralHomeAddress2: string;
|
||||||
funeralHomeCity: string;
|
funeralHomeCity: string;
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ import sqlite from 'better-sqlite3'
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||||
|
|
||||||
export interface AddForm {
|
export interface AddForm {
|
||||||
funeralHomeKey: string
|
|
||||||
funeralHomeName: string
|
funeralHomeName: string
|
||||||
|
funeralHomeKey: string
|
||||||
|
|
||||||
funeralHomeAddress1: string
|
funeralHomeAddress1: string
|
||||||
funeralHomeAddress2: string
|
funeralHomeAddress2: string
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ export default function addOrUpdateBurialSiteField(fieldForm, user, connectedDat
|
||||||
let result = database
|
let result = database
|
||||||
.prepare(`update BurialSiteFields
|
.prepare(`update BurialSiteFields
|
||||||
set fieldValue = ?,
|
set fieldValue = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?,
|
recordUpdate_timeMillis = ?,
|
||||||
recordDelete_userName = null,
|
recordDelete_userName = null,
|
||||||
recordDelete_timeMillis = null
|
recordDelete_timeMillis = null
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and burialSiteTypeFieldId = ?`)
|
and burialSiteTypeFieldId = ?`)
|
||||||
.run(fieldForm.fieldValue, user.userName, rightNowMillis, fieldForm.burialSiteId, fieldForm.burialSiteTypeFieldId);
|
.run(fieldForm.fieldValue, user.userName, rightNowMillis, fieldForm.burialSiteId, fieldForm.burialSiteTypeFieldId);
|
||||||
if (result.changes === 0) {
|
if (result.changes === 0) {
|
||||||
result = database
|
result = database
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,12 @@ export default function addOrUpdateBurialSiteField(
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteFields
|
`update BurialSiteFields
|
||||||
set fieldValue = ?,
|
set fieldValue = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?,
|
recordUpdate_timeMillis = ?,
|
||||||
recordDelete_userName = null,
|
recordDelete_userName = null,
|
||||||
recordDelete_timeMillis = null
|
recordDelete_timeMillis = null
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and burialSiteTypeFieldId = ?`
|
and burialSiteTypeFieldId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
fieldForm.fieldValue,
|
fieldForm.fieldValue,
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ export default function addOrUpdateContractField(fieldForm, user, connectedDatab
|
||||||
let result = database
|
let result = database
|
||||||
.prepare(`update ContractFields
|
.prepare(`update ContractFields
|
||||||
set fieldValue = ?,
|
set fieldValue = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?,
|
recordUpdate_timeMillis = ?,
|
||||||
recordDelete_userName = null,
|
recordDelete_userName = null,
|
||||||
recordDelete_timeMillis = null
|
recordDelete_timeMillis = null
|
||||||
where contractId = ?
|
where contractId = ?
|
||||||
and contractTypeFieldId = ?`)
|
and contractTypeFieldId = ?`)
|
||||||
.run(fieldForm.fieldValue, user.userName, rightNowMillis, fieldForm.contractId, fieldForm.contractTypeFieldId);
|
.run(fieldForm.fieldValue, user.userName, rightNowMillis, fieldForm.contractId, fieldForm.contractTypeFieldId);
|
||||||
if (result.changes === 0) {
|
if (result.changes === 0) {
|
||||||
result = database
|
result = database
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,12 @@ export default function addOrUpdateContractField(
|
||||||
.prepare(
|
.prepare(
|
||||||
`update ContractFields
|
`update ContractFields
|
||||||
set fieldValue = ?,
|
set fieldValue = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?,
|
recordUpdate_timeMillis = ?,
|
||||||
recordDelete_userName = null,
|
recordDelete_userName = null,
|
||||||
recordDelete_timeMillis = null
|
recordDelete_timeMillis = null
|
||||||
where contractId = ?
|
where contractId = ?
|
||||||
and contractTypeFieldId = ?`
|
and contractTypeFieldId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
fieldForm.fieldValue,
|
fieldForm.fieldValue,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
type RecordTable = 'BurialSiteStatuses' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes';
|
type RecordTable = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes';
|
||||||
export default function addRecord(recordTable: RecordTable, recordName: string, orderNumber: number | string, user: User): number;
|
export default function addRecord(recordTable: RecordTable, recordName: string, orderNumber: number | string, user: User): number;
|
||||||
export {};
|
export {};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { sunriseDB } from '../helpers/database.helpers.js';
|
||||||
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
||||||
const recordNameColumns = new Map([
|
const recordNameColumns = new Map([
|
||||||
['BurialSiteStatuses', 'burialSiteStatus'],
|
['BurialSiteStatuses', 'burialSiteStatus'],
|
||||||
|
['BurialSiteTypes', 'burialSiteType'],
|
||||||
['WorkOrderMilestoneTypes', 'workOrderMilestoneType'],
|
['WorkOrderMilestoneTypes', 'workOrderMilestoneType'],
|
||||||
['WorkOrderTypes', 'workOrderType']
|
['WorkOrderTypes', 'workOrderType']
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,13 @@ import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||||
|
|
||||||
type RecordTable =
|
type RecordTable =
|
||||||
| 'BurialSiteStatuses'
|
| 'BurialSiteStatuses'
|
||||||
|
| 'BurialSiteTypes'
|
||||||
| 'WorkOrderMilestoneTypes'
|
| 'WorkOrderMilestoneTypes'
|
||||||
| 'WorkOrderTypes'
|
| 'WorkOrderTypes'
|
||||||
|
|
||||||
const recordNameColumns = new Map<RecordTable, string>([
|
const recordNameColumns = new Map<RecordTable, string>([
|
||||||
['BurialSiteStatuses', 'burialSiteStatus'],
|
['BurialSiteStatuses', 'burialSiteStatus'],
|
||||||
|
['BurialSiteTypes', 'burialSiteType'],
|
||||||
['WorkOrderMilestoneTypes', 'workOrderMilestoneType'],
|
['WorkOrderMilestoneTypes', 'workOrderMilestoneType'],
|
||||||
['WorkOrderTypes', 'workOrderType']
|
['WorkOrderTypes', 'workOrderType']
|
||||||
])
|
])
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
export interface AddWorkOrderForm {
|
export interface AddWorkOrderForm {
|
||||||
workOrderDescription: string;
|
|
||||||
workOrderNumber?: string;
|
|
||||||
workOrderTypeId: number | string;
|
workOrderTypeId: number | string;
|
||||||
workOrderCloseDateString?: string;
|
workOrderNumber?: string;
|
||||||
|
workOrderDescription: string;
|
||||||
workOrderOpenDateString?: string;
|
workOrderOpenDateString?: string;
|
||||||
|
workOrderCloseDateString?: string;
|
||||||
contractId?: string;
|
contractId?: string;
|
||||||
}
|
}
|
||||||
export default function addWorkOrder(workOrderForm: AddWorkOrderForm, user: User): number;
|
export default function addWorkOrder(workOrderForm: AddWorkOrderForm, user: User): number;
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ export default function addWorkOrder(workOrderForm, user) {
|
||||||
const workOrderId = result.lastInsertRowid;
|
const workOrderId = result.lastInsertRowid;
|
||||||
if ((workOrderForm.contractId ?? '') !== '') {
|
if ((workOrderForm.contractId ?? '') !== '') {
|
||||||
addWorkOrderContract({
|
addWorkOrderContract({
|
||||||
contractId: workOrderForm.contractId,
|
|
||||||
workOrderId,
|
workOrderId,
|
||||||
|
contractId: workOrderForm.contractId
|
||||||
}, user, database);
|
}, user, database);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,11 @@ import addWorkOrderContract from './addWorkOrderContract.js'
|
||||||
import getNextWorkOrderNumber from './getNextWorkOrderNumber.js'
|
import getNextWorkOrderNumber from './getNextWorkOrderNumber.js'
|
||||||
|
|
||||||
export interface AddWorkOrderForm {
|
export interface AddWorkOrderForm {
|
||||||
workOrderDescription: string
|
|
||||||
workOrderNumber?: string
|
|
||||||
|
|
||||||
workOrderTypeId: number | string
|
workOrderTypeId: number | string
|
||||||
|
workOrderNumber?: string
|
||||||
workOrderCloseDateString?: string
|
workOrderDescription: string
|
||||||
workOrderOpenDateString?: string
|
workOrderOpenDateString?: string
|
||||||
|
workOrderCloseDateString?: string
|
||||||
contractId?: string
|
contractId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,8 +67,8 @@ export default function addWorkOrder(
|
||||||
if ((workOrderForm.contractId ?? '') !== '') {
|
if ((workOrderForm.contractId ?? '') !== '') {
|
||||||
addWorkOrderContract(
|
addWorkOrderContract(
|
||||||
{
|
{
|
||||||
contractId: workOrderForm.contractId as string,
|
|
||||||
workOrderId,
|
workOrderId,
|
||||||
|
contractId: workOrderForm.contractId as string
|
||||||
},
|
},
|
||||||
user,
|
user,
|
||||||
database
|
database
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
export interface AddForm {
|
export interface AddForm {
|
||||||
burialSiteId: number | string;
|
|
||||||
workOrderId: number | string;
|
workOrderId: number | string;
|
||||||
|
burialSiteId: number | string;
|
||||||
}
|
}
|
||||||
export default function addWorkOrderBurialSite(workOrderLotForm: AddForm, user: User): boolean;
|
export default function addWorkOrderBurialSite(workOrderLotForm: AddForm, user: User): boolean;
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ import sqlite from 'better-sqlite3'
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||||
|
|
||||||
export interface AddForm {
|
export interface AddForm {
|
||||||
burialSiteId: number | string
|
|
||||||
workOrderId: number | string
|
workOrderId: number | string
|
||||||
|
burialSiteId: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function addWorkOrderBurialSite(
|
export default function addWorkOrderBurialSite(
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
export interface AddWorkOrderCommentForm {
|
export interface AddWorkOrderCommentForm {
|
||||||
comment: string;
|
|
||||||
workOrderId: string;
|
workOrderId: string;
|
||||||
|
comment: string;
|
||||||
}
|
}
|
||||||
export default function addWorkOrderComment(workOrderCommentForm: AddWorkOrderCommentForm, user: User): number;
|
export default function addWorkOrderComment(workOrderCommentForm: AddWorkOrderCommentForm, user: User): number;
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import sqlite from 'better-sqlite3'
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||||
|
|
||||||
export interface AddWorkOrderCommentForm {
|
export interface AddWorkOrderCommentForm {
|
||||||
comment: string
|
|
||||||
workOrderId: string
|
workOrderId: string
|
||||||
|
comment: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function addWorkOrderComment(
|
export default function addWorkOrderComment(
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
import { type DateString, type TimeString } from '@cityssm/utils-datetime';
|
|
||||||
export interface AddWorkOrderMilestoneForm {
|
export interface AddWorkOrderMilestoneForm {
|
||||||
workOrderId: number | string;
|
workOrderId: number | string;
|
||||||
workOrderMilestoneTypeId: number | string;
|
workOrderMilestoneTypeId: number | string;
|
||||||
workOrderMilestoneDateString: '' | DateString;
|
workOrderMilestoneDateString: string;
|
||||||
workOrderMilestoneTimeString?: '' | TimeString;
|
workOrderMilestoneTimeString?: string;
|
||||||
workOrderMilestoneDescription: string;
|
workOrderMilestoneDescription: string;
|
||||||
workOrderMilestoneCompletionDateString?: '' | DateString;
|
workOrderMilestoneCompletionDateString?: string;
|
||||||
workOrderMilestoneCompletionTimeString?: '' | TimeString;
|
workOrderMilestoneCompletionTimeString?: string;
|
||||||
}
|
}
|
||||||
export default function addWorkOrderMilestone(milestoneForm: AddWorkOrderMilestoneForm, user: User): number;
|
export default function addWorkOrderMilestone(milestoneForm: AddWorkOrderMilestoneForm, user: User): number;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import {
|
import {
|
||||||
type DateString,
|
|
||||||
type TimeString,
|
|
||||||
dateStringToInteger,
|
dateStringToInteger,
|
||||||
timeStringToInteger
|
timeStringToInteger
|
||||||
} from '@cityssm/utils-datetime'
|
} from '@cityssm/utils-datetime'
|
||||||
|
|
@ -12,13 +10,13 @@ export interface AddWorkOrderMilestoneForm {
|
||||||
workOrderId: number | string
|
workOrderId: number | string
|
||||||
workOrderMilestoneTypeId: number | string
|
workOrderMilestoneTypeId: number | string
|
||||||
|
|
||||||
workOrderMilestoneDateString: '' | DateString
|
workOrderMilestoneDateString: string
|
||||||
workOrderMilestoneTimeString?: '' | TimeString
|
workOrderMilestoneTimeString?: string
|
||||||
|
|
||||||
workOrderMilestoneDescription: string
|
workOrderMilestoneDescription: string
|
||||||
|
|
||||||
workOrderMilestoneCompletionDateString?: '' | DateString
|
workOrderMilestoneCompletionDateString?: string
|
||||||
workOrderMilestoneCompletionTimeString?: '' | TimeString
|
workOrderMilestoneCompletionTimeString?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function addWorkOrderMilestone(
|
export default function addWorkOrderMilestone(
|
||||||
|
|
@ -50,19 +48,17 @@ export default function addWorkOrderMilestone(
|
||||||
: dateStringToInteger(milestoneForm.workOrderMilestoneDateString),
|
: dateStringToInteger(milestoneForm.workOrderMilestoneDateString),
|
||||||
(milestoneForm.workOrderMilestoneTimeString ?? '') === ''
|
(milestoneForm.workOrderMilestoneTimeString ?? '') === ''
|
||||||
? 0
|
? 0
|
||||||
: timeStringToInteger(
|
: timeStringToInteger(milestoneForm.workOrderMilestoneTimeString!),
|
||||||
milestoneForm.workOrderMilestoneTimeString as TimeString
|
|
||||||
),
|
|
||||||
milestoneForm.workOrderMilestoneDescription,
|
milestoneForm.workOrderMilestoneDescription,
|
||||||
(milestoneForm.workOrderMilestoneCompletionDateString ?? '') === ''
|
(milestoneForm.workOrderMilestoneCompletionDateString ?? '') === ''
|
||||||
? undefined
|
? undefined
|
||||||
: dateStringToInteger(
|
: dateStringToInteger(
|
||||||
milestoneForm.workOrderMilestoneCompletionDateString as DateString
|
milestoneForm.workOrderMilestoneCompletionDateString!
|
||||||
),
|
),
|
||||||
(milestoneForm.workOrderMilestoneCompletionTimeString ?? '') === ''
|
(milestoneForm.workOrderMilestoneCompletionTimeString ?? '') === ''
|
||||||
? undefined
|
? undefined
|
||||||
: timeStringToInteger(
|
: timeStringToInteger(
|
||||||
milestoneForm.workOrderMilestoneCompletionTimeString as TimeString
|
milestoneForm.workOrderMilestoneCompletionTimeString!
|
||||||
),
|
),
|
||||||
user.userName,
|
user.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export declare function backupDatabase(): Promise<false | string>;
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
import sqlite from 'better-sqlite3';
|
|
||||||
import Debug from 'debug';
|
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
|
||||||
const debug = Debug('sunrise:database:backupDatabase');
|
|
||||||
const backupFolder = 'data/backups';
|
|
||||||
export async function backupDatabase() {
|
|
||||||
const databasePathSplit = sunriseDB.split(/[/\\]/);
|
|
||||||
const backupDatabasePath = `${backupFolder}/${databasePathSplit.at(-1)}.${Date.now().toString()}`;
|
|
||||||
const database = sqlite(sunriseDB);
|
|
||||||
try {
|
|
||||||
const result = await database.backup(backupDatabasePath);
|
|
||||||
if (result.remainingPages === 0) {
|
|
||||||
debug('Database backup completed successfully:', backupDatabasePath);
|
|
||||||
return backupDatabasePath;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
debug('Database backup incomplete:', result.remainingPages, 'pages remaining');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
debug('Error backing up database:', error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
database.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
import sqlite from 'better-sqlite3'
|
|
||||||
import Debug from 'debug'
|
|
||||||
|
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
|
||||||
|
|
||||||
const debug = Debug('sunrise:database:backupDatabase')
|
|
||||||
|
|
||||||
const backupFolder = 'data/backups'
|
|
||||||
|
|
||||||
export async function backupDatabase(): Promise<false | string> {
|
|
||||||
const databasePathSplit = sunriseDB.split(/[/\\]/)
|
|
||||||
|
|
||||||
const backupDatabasePath = `${backupFolder}/${databasePathSplit.at(-1)}.${Date.now().toString()}`
|
|
||||||
|
|
||||||
const database = sqlite(sunriseDB)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await database.backup(backupDatabasePath)
|
|
||||||
|
|
||||||
if (result.remainingPages === 0) {
|
|
||||||
debug('Database backup completed successfully:', backupDatabasePath)
|
|
||||||
return backupDatabasePath
|
|
||||||
} else {
|
|
||||||
debug(
|
|
||||||
'Database backup incomplete:',
|
|
||||||
result.remainingPages,
|
|
||||||
'pages remaining'
|
|
||||||
)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
debug('Error backing up database:', error)
|
|
||||||
return false
|
|
||||||
} finally {
|
|
||||||
database.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -15,10 +15,10 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update WorkOrderComments
|
.prepare(`update WorkOrderComments
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and workOrderId in (
|
and workOrderId in (
|
||||||
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`)
|
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from WorkOrderComments where recordDelete_timeMillis <= ?')
|
.prepare('delete from WorkOrderComments where recordDelete_timeMillis <= ?')
|
||||||
|
|
@ -29,10 +29,10 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update WorkOrderContracts
|
.prepare(`update WorkOrderContracts
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and workOrderId in (
|
and workOrderId in (
|
||||||
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`)
|
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from WorkOrderContracts where recordDelete_timeMillis <= ?')
|
.prepare('delete from WorkOrderContracts where recordDelete_timeMillis <= ?')
|
||||||
|
|
@ -43,10 +43,10 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update WorkOrderBurialSites
|
.prepare(`update WorkOrderBurialSites
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and workOrderId in (
|
and workOrderId in (
|
||||||
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`)
|
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from WorkOrderBurialSites where recordDelete_timeMillis <= ?')
|
.prepare('delete from WorkOrderBurialSites where recordDelete_timeMillis <= ?')
|
||||||
|
|
@ -57,10 +57,10 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update WorkOrderMilestones
|
.prepare(`update WorkOrderMilestones
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and workOrderId in (
|
and workOrderId in (
|
||||||
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`)
|
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from WorkOrderMilestones where recordDelete_timeMillis <= ?')
|
.prepare('delete from WorkOrderMilestones where recordDelete_timeMillis <= ?')
|
||||||
|
|
@ -71,10 +71,10 @@ export default function cleanupDatabase(user) {
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from WorkOrders
|
.prepare(`delete from WorkOrders
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and workOrderId not in (select workOrderId from WorkOrderComments)
|
and workOrderId not in (select workOrderId from WorkOrderComments)
|
||||||
and workOrderId not in (select workOrderId from WorkOrderContracts)
|
and workOrderId not in (select workOrderId from WorkOrderContracts)
|
||||||
and workOrderId not in (select workOrderId from WorkOrderBurialSites)
|
and workOrderId not in (select workOrderId from WorkOrderBurialSites)
|
||||||
and workOrderId not in (select workOrderId from WorkOrderMilestones)`)
|
and workOrderId not in (select workOrderId from WorkOrderMilestones)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Work Order Milestone Types
|
* Work Order Milestone Types
|
||||||
|
|
@ -82,8 +82,8 @@ export default function cleanupDatabase(user) {
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from WorkOrderMilestoneTypes
|
.prepare(`delete from WorkOrderMilestoneTypes
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and workOrderMilestoneTypeId not in (
|
and workOrderMilestoneTypeId not in (
|
||||||
select workOrderMilestoneTypeId from WorkOrderMilestones)`)
|
select workOrderMilestoneTypeId from WorkOrderMilestones)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Work Order Types
|
* Work Order Types
|
||||||
|
|
@ -91,7 +91,7 @@ export default function cleanupDatabase(user) {
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from WorkOrderTypes
|
.prepare(`delete from WorkOrderTypes
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and workOrderTypeId not in (select workOrderTypeId from WorkOrders)`)
|
and workOrderTypeId not in (select workOrderTypeId from WorkOrders)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Burial Site Contract Comments
|
* Burial Site Contract Comments
|
||||||
|
|
@ -99,10 +99,10 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update ContractComments
|
.prepare(`update ContractComments
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractId in (
|
and contractId in (
|
||||||
select contractId from Contracts where recordDelete_timeMillis is not null)`)
|
select contractId from Contracts where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from ContractComments where recordDelete_timeMillis <= ?')
|
.prepare('delete from ContractComments where recordDelete_timeMillis <= ?')
|
||||||
|
|
@ -113,16 +113,16 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update ContractFields
|
.prepare(`update ContractFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractId in (select contractId from Contracts where recordDelete_timeMillis is not null)`)
|
and contractId in (select contractId from Contracts where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from ContractFields where recordDelete_timeMillis <= ?')
|
.prepare('delete from ContractFields where recordDelete_timeMillis <= ?')
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Burial Site Contract Fees/Transactions
|
* Burial Site Contract Fees/Transactions
|
||||||
* - Maintain financial data, do not delete related.
|
* - Maintain financials, do not delete related.
|
||||||
*/
|
*/
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from ContractFees where recordDelete_timeMillis <= ?')
|
.prepare('delete from ContractFees where recordDelete_timeMillis <= ?')
|
||||||
|
|
@ -136,12 +136,12 @@ export default function cleanupDatabase(user) {
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from Contracts
|
.prepare(`delete from Contracts
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and contractId not in (select contractId from ContractComments)
|
and contractId not in (select contractId from ContractComments)
|
||||||
and contractId not in (select contractId from ContractFees)
|
and contractId not in (select contractId from ContractFees)
|
||||||
and contractId not in (select contractId from ContractFields)
|
and contractId not in (select contractId from ContractFields)
|
||||||
and contractId not in (select contractId from ContractInterments)
|
and contractId not in (select contractId from ContractInterments)
|
||||||
and contractId not in (select contractId from ContractTransactions)
|
and contractId not in (select contractId from ContractTransactions)
|
||||||
and contractId not in (select contractId from WorkOrderContracts)`)
|
and contractId not in (select contractId from WorkOrderContracts)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Fees
|
* Fees
|
||||||
|
|
@ -149,14 +149,14 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update Fees
|
.prepare(`update Fees
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and feeCategoryId in (select feeCategoryId from FeeCategories where recordDelete_timeMillis is not null)`)
|
and feeCategoryId in (select feeCategoryId from FeeCategories where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from Fees
|
.prepare(`delete from Fees
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and feeId not in (select feeId from ContractFees)`)
|
and feeId not in (select feeId from ContractFees)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Fee Categories
|
* Fee Categories
|
||||||
|
|
@ -164,7 +164,7 @@ export default function cleanupDatabase(user) {
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from FeeCategories
|
.prepare(`delete from FeeCategories
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and feeCategoryId not in (select feeCategoryId from Fees)`)
|
and feeCategoryId not in (select feeCategoryId from Fees)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Contract Type Fields
|
* Contract Type Fields
|
||||||
|
|
@ -172,14 +172,14 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update ContractTypeFields
|
.prepare(`update ContractTypeFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractTypeId in (select contractTypeId from ContractTypes where recordDelete_timeMillis is not null)`)
|
and contractTypeId in (select contractTypeId from ContractTypes where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from ContractTypeFields
|
.prepare(`delete from ContractTypeFields
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and contractTypeFieldId not in (select contractTypeFieldId from ContractFields)`)
|
and contractTypeFieldId not in (select contractTypeFieldId from ContractFields)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Contract Type Prints
|
* Contract Type Prints
|
||||||
|
|
@ -187,9 +187,9 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update ContractTypePrints
|
.prepare(`update ContractTypePrints
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractTypeId in (select contractTypeId from ContractTypes where recordDelete_timeMillis is not null)`)
|
and contractTypeId in (select contractTypeId from ContractTypes where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from ContractTypePrints where recordDelete_timeMillis <= ?')
|
.prepare('delete from ContractTypePrints where recordDelete_timeMillis <= ?')
|
||||||
|
|
@ -200,10 +200,10 @@ export default function cleanupDatabase(user) {
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from ContractTypes
|
.prepare(`delete from ContractTypes
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and contractTypeId not in (select contractTypeId from ContractTypeFields)
|
and contractTypeId not in (select contractTypeId from ContractTypeFields)
|
||||||
and contractTypeId not in (select contractTypeId from ContractTypePrints)
|
and contractTypeId not in (select contractTypeId from ContractTypePrints)
|
||||||
and contractTypeId not in (select contractTypeId from Contracts)
|
and contractTypeId not in (select contractTypeId from Contracts)
|
||||||
and contractTypeId not in (select contractTypeId from Fees)`)
|
and contractTypeId not in (select contractTypeId from Fees)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Burial Site Comments
|
* Burial Site Comments
|
||||||
|
|
@ -211,9 +211,9 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update BurialSiteComments
|
.prepare(`update BurialSiteComments
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteId in (select burialSiteId from BurialSites where recordDelete_timeMillis is not null)`)
|
and burialSiteId in (select burialSiteId from BurialSites where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from BurialSiteComments where recordDelete_timeMillis <= ?')
|
.prepare('delete from BurialSiteComments where recordDelete_timeMillis <= ?')
|
||||||
|
|
@ -224,9 +224,9 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update BurialSiteFields
|
.prepare(`update BurialSiteFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteId in (select burialSiteId from BurialSites where recordDelete_timeMillis is not null)`)
|
and burialSiteId in (select burialSiteId from BurialSites where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare('delete from BurialSiteFields where recordDelete_timeMillis <= ?')
|
.prepare('delete from BurialSiteFields where recordDelete_timeMillis <= ?')
|
||||||
|
|
@ -237,17 +237,17 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update BurialSites
|
.prepare(`update BurialSites
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and cemeteryId in (select cemeteryId from Cemeteries where recordDelete_timeMillis is not null)`)
|
and cemeteryId in (select cemeteryId from Cemeteries where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from BurialSites
|
.prepare(`delete from BurialSites
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteId not in (select burialSiteId from BurialSiteComments)
|
and burialSiteId not in (select burialSiteId from BurialSiteComments)
|
||||||
and burialSiteId not in (select burialSiteId from BurialSiteFields)
|
and burialSiteId not in (select burialSiteId from BurialSiteFields)
|
||||||
and burialSiteId not in (select burialSiteId from Contracts)
|
and burialSiteId not in (select burialSiteId from Contracts)
|
||||||
and burialSiteId not in (select burialSiteId from WorkOrderBurialSites)`)
|
and burialSiteId not in (select burialSiteId from WorkOrderBurialSites)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Burial Site Statuses
|
* Burial Site Statuses
|
||||||
|
|
@ -255,7 +255,7 @@ export default function cleanupDatabase(user) {
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from BurialSiteStatuses
|
.prepare(`delete from BurialSiteStatuses
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteStatusId not in (select burialSiteStatusId from BurialSites)`)
|
and burialSiteStatusId not in (select burialSiteStatusId from BurialSites)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Burial Site Type Fields
|
* Burial Site Type Fields
|
||||||
|
|
@ -263,14 +263,14 @@ export default function cleanupDatabase(user) {
|
||||||
inactivatedRecordCount += database
|
inactivatedRecordCount += database
|
||||||
.prepare(`update BurialSiteTypeFields
|
.prepare(`update BurialSiteTypeFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteTypeId in (select burialSiteTypeId from BurialSiteTypes where recordDelete_timeMillis is not null)`)
|
and burialSiteTypeId in (select burialSiteTypeId from BurialSiteTypes where recordDelete_timeMillis is not null)`)
|
||||||
.run(user.userName, rightNowMillis).changes;
|
.run(user.userName, rightNowMillis).changes;
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from BurialSiteTypeFields
|
.prepare(`delete from BurialSiteTypeFields
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteTypeFieldId not in (select burialSiteTypeFieldId from BurialSiteFields)`)
|
and burialSiteTypeFieldId not in (select burialSiteTypeFieldId from BurialSiteFields)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
/*
|
/*
|
||||||
* Burial Site Types
|
* Burial Site Types
|
||||||
|
|
@ -278,7 +278,7 @@ export default function cleanupDatabase(user) {
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
.prepare(`delete from BurialSiteTypes
|
.prepare(`delete from BurialSiteTypes
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteTypeId not in (select burialSiteTypeId from BurialSites)`)
|
and burialSiteTypeId not in (select burialSiteTypeId from BurialSites)`)
|
||||||
.run(recordDeleteTimeMillisMin).changes;
|
.run(recordDeleteTimeMillisMin).changes;
|
||||||
database.close();
|
database.close();
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderComments
|
`update WorkOrderComments
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and workOrderId in (
|
and workOrderId in (
|
||||||
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`
|
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -45,10 +45,10 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderContracts
|
`update WorkOrderContracts
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and workOrderId in (
|
and workOrderId in (
|
||||||
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`
|
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -66,10 +66,10 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderBurialSites
|
`update WorkOrderBurialSites
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and workOrderId in (
|
and workOrderId in (
|
||||||
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`
|
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -87,10 +87,10 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderMilestones
|
`update WorkOrderMilestones
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and workOrderId in (
|
and workOrderId in (
|
||||||
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`
|
select workOrderId from WorkOrders where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -108,10 +108,10 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from WorkOrders
|
`delete from WorkOrders
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and workOrderId not in (select workOrderId from WorkOrderComments)
|
and workOrderId not in (select workOrderId from WorkOrderComments)
|
||||||
and workOrderId not in (select workOrderId from WorkOrderContracts)
|
and workOrderId not in (select workOrderId from WorkOrderContracts)
|
||||||
and workOrderId not in (select workOrderId from WorkOrderBurialSites)
|
and workOrderId not in (select workOrderId from WorkOrderBurialSites)
|
||||||
and workOrderId not in (select workOrderId from WorkOrderMilestones)`
|
and workOrderId not in (select workOrderId from WorkOrderMilestones)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -123,8 +123,8 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from WorkOrderMilestoneTypes
|
`delete from WorkOrderMilestoneTypes
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and workOrderMilestoneTypeId not in (
|
and workOrderMilestoneTypeId not in (
|
||||||
select workOrderMilestoneTypeId from WorkOrderMilestones)`
|
select workOrderMilestoneTypeId from WorkOrderMilestones)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from WorkOrderTypes
|
`delete from WorkOrderTypes
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and workOrderTypeId not in (select workOrderTypeId from WorkOrders)`
|
and workOrderTypeId not in (select workOrderTypeId from WorkOrders)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -148,10 +148,10 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update ContractComments
|
`update ContractComments
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractId in (
|
and contractId in (
|
||||||
select contractId from Contracts where recordDelete_timeMillis is not null)`
|
select contractId from Contracts where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -167,9 +167,9 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update ContractFields
|
`update ContractFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractId in (select contractId from Contracts where recordDelete_timeMillis is not null)`
|
and contractId in (select contractId from Contracts where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -179,7 +179,7 @@ export default function cleanupDatabase(user: User): {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Burial Site Contract Fees/Transactions
|
* Burial Site Contract Fees/Transactions
|
||||||
* - Maintain financial data, do not delete related.
|
* - Maintain financials, do not delete related.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
purgedRecordCount += database
|
purgedRecordCount += database
|
||||||
|
|
@ -200,12 +200,12 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from Contracts
|
`delete from Contracts
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and contractId not in (select contractId from ContractComments)
|
and contractId not in (select contractId from ContractComments)
|
||||||
and contractId not in (select contractId from ContractFees)
|
and contractId not in (select contractId from ContractFees)
|
||||||
and contractId not in (select contractId from ContractFields)
|
and contractId not in (select contractId from ContractFields)
|
||||||
and contractId not in (select contractId from ContractInterments)
|
and contractId not in (select contractId from ContractInterments)
|
||||||
and contractId not in (select contractId from ContractTransactions)
|
and contractId not in (select contractId from ContractTransactions)
|
||||||
and contractId not in (select contractId from WorkOrderContracts)`
|
and contractId not in (select contractId from WorkOrderContracts)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -217,9 +217,9 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update Fees
|
`update Fees
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and feeCategoryId in (select feeCategoryId from FeeCategories where recordDelete_timeMillis is not null)`
|
and feeCategoryId in (select feeCategoryId from FeeCategories where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -227,7 +227,7 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from Fees
|
`delete from Fees
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and feeId not in (select feeId from ContractFees)`
|
and feeId not in (select feeId from ContractFees)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -239,7 +239,7 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from FeeCategories
|
`delete from FeeCategories
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and feeCategoryId not in (select feeCategoryId from Fees)`
|
and feeCategoryId not in (select feeCategoryId from Fees)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -251,9 +251,9 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update ContractTypeFields
|
`update ContractTypeFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractTypeId in (select contractTypeId from ContractTypes where recordDelete_timeMillis is not null)`
|
and contractTypeId in (select contractTypeId from ContractTypes where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -261,7 +261,7 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from ContractTypeFields
|
`delete from ContractTypeFields
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and contractTypeFieldId not in (select contractTypeFieldId from ContractFields)`
|
and contractTypeFieldId not in (select contractTypeFieldId from ContractFields)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -273,9 +273,9 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update ContractTypePrints
|
`update ContractTypePrints
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractTypeId in (select contractTypeId from ContractTypes where recordDelete_timeMillis is not null)`
|
and contractTypeId in (select contractTypeId from ContractTypes where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -293,10 +293,10 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from ContractTypes
|
`delete from ContractTypes
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and contractTypeId not in (select contractTypeId from ContractTypeFields)
|
and contractTypeId not in (select contractTypeId from ContractTypeFields)
|
||||||
and contractTypeId not in (select contractTypeId from ContractTypePrints)
|
and contractTypeId not in (select contractTypeId from ContractTypePrints)
|
||||||
and contractTypeId not in (select contractTypeId from Contracts)
|
and contractTypeId not in (select contractTypeId from Contracts)
|
||||||
and contractTypeId not in (select contractTypeId from Fees)`
|
and contractTypeId not in (select contractTypeId from Fees)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -308,9 +308,9 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteComments
|
`update BurialSiteComments
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteId in (select burialSiteId from BurialSites where recordDelete_timeMillis is not null)`
|
and burialSiteId in (select burialSiteId from BurialSites where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -328,9 +328,9 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteFields
|
`update BurialSiteFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteId in (select burialSiteId from BurialSites where recordDelete_timeMillis is not null)`
|
and burialSiteId in (select burialSiteId from BurialSites where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -346,9 +346,9 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSites
|
`update BurialSites
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and cemeteryId in (select cemeteryId from Cemeteries where recordDelete_timeMillis is not null)`
|
and cemeteryId in (select cemeteryId from Cemeteries where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -356,10 +356,10 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from BurialSites
|
`delete from BurialSites
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteId not in (select burialSiteId from BurialSiteComments)
|
and burialSiteId not in (select burialSiteId from BurialSiteComments)
|
||||||
and burialSiteId not in (select burialSiteId from BurialSiteFields)
|
and burialSiteId not in (select burialSiteId from BurialSiteFields)
|
||||||
and burialSiteId not in (select burialSiteId from Contracts)
|
and burialSiteId not in (select burialSiteId from Contracts)
|
||||||
and burialSiteId not in (select burialSiteId from WorkOrderBurialSites)`
|
and burialSiteId not in (select burialSiteId from WorkOrderBurialSites)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -371,7 +371,7 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from BurialSiteStatuses
|
`delete from BurialSiteStatuses
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteStatusId not in (select burialSiteStatusId from BurialSites)`
|
and burialSiteStatusId not in (select burialSiteStatusId from BurialSites)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -383,9 +383,9 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteTypeFields
|
`update BurialSiteTypeFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and burialSiteTypeId in (select burialSiteTypeId from BurialSiteTypes where recordDelete_timeMillis is not null)`
|
and burialSiteTypeId in (select burialSiteTypeId from BurialSiteTypes where recordDelete_timeMillis is not null)`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis).changes
|
.run(user.userName, rightNowMillis).changes
|
||||||
|
|
||||||
|
|
@ -393,7 +393,7 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from BurialSiteTypeFields
|
`delete from BurialSiteTypeFields
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteTypeFieldId not in (select burialSiteTypeFieldId from BurialSiteFields)`
|
and burialSiteTypeFieldId not in (select burialSiteTypeFieldId from BurialSiteFields)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
@ -405,7 +405,7 @@ export default function cleanupDatabase(user: User): {
|
||||||
.prepare(
|
.prepare(
|
||||||
`delete from BurialSiteTypes
|
`delete from BurialSiteTypes
|
||||||
where recordDelete_timeMillis <= ?
|
where recordDelete_timeMillis <= ?
|
||||||
and burialSiteTypeId not in (select burialSiteTypeId from BurialSites)`
|
and burialSiteTypeId not in (select burialSiteTypeId from BurialSites)`
|
||||||
)
|
)
|
||||||
.run(recordDeleteTimeMillisMin).changes
|
.run(recordDeleteTimeMillisMin).changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { type DateString } from '@cityssm/utils-datetime';
|
|
||||||
export interface CloseWorkOrderForm {
|
export interface CloseWorkOrderForm {
|
||||||
workOrderId: number | string;
|
workOrderId: number | string;
|
||||||
workOrderCloseDateString?: '' | DateString;
|
workOrderCloseDateString?: string;
|
||||||
}
|
}
|
||||||
export default function closeWorkOrder(workOrderForm: CloseWorkOrderForm, user: User): boolean;
|
export default function closeWorkOrder(workOrderForm: CloseWorkOrderForm, user: User): boolean;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,4 @@
|
||||||
import {
|
import { dateStringToInteger, dateToInteger } from '@cityssm/utils-datetime'
|
||||||
type DateString,
|
|
||||||
dateStringToInteger,
|
|
||||||
dateToInteger
|
|
||||||
} from '@cityssm/utils-datetime'
|
|
||||||
import sqlite from 'better-sqlite3'
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||||
|
|
@ -10,7 +6,7 @@ import { sunriseDB } from '../helpers/database.helpers.js'
|
||||||
export interface CloseWorkOrderForm {
|
export interface CloseWorkOrderForm {
|
||||||
workOrderId: number | string
|
workOrderId: number | string
|
||||||
|
|
||||||
workOrderCloseDateString?: '' | DateString
|
workOrderCloseDateString?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function closeWorkOrder(
|
export default function closeWorkOrder(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { type DateString, type TimeString } from '@cityssm/utils-datetime';
|
|
||||||
export interface CompleteWorkOrderMilestoneForm {
|
export interface CompleteWorkOrderMilestoneForm {
|
||||||
workOrderMilestoneId: number | string;
|
workOrderMilestoneId: number | string;
|
||||||
workOrderMilestoneCompletionDateString?: '' | DateString;
|
workOrderMilestoneCompletionDateString?: string;
|
||||||
workOrderMilestoneCompletionTimeString?: '' | TimeString;
|
workOrderMilestoneCompletionTimeString?: string;
|
||||||
}
|
}
|
||||||
export default function completeWorkOrderMilestone(milestoneForm: CompleteWorkOrderMilestoneForm, user: User): boolean;
|
export default function completeWorkOrderMilestone(milestoneForm: CompleteWorkOrderMilestoneForm, user: User): boolean;
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,6 @@ import { sunriseDB } from '../helpers/database.helpers.js';
|
||||||
export default function completeWorkOrderMilestone(milestoneForm, user) {
|
export default function completeWorkOrderMilestone(milestoneForm, user) {
|
||||||
const rightNow = new Date();
|
const rightNow = new Date();
|
||||||
const database = sqlite(sunriseDB);
|
const database = sqlite(sunriseDB);
|
||||||
const completionDate = (milestoneForm.workOrderMilestoneCompletionDateString ?? '') === ''
|
|
||||||
? dateToInteger(rightNow)
|
|
||||||
: dateStringToInteger(milestoneForm.workOrderMilestoneCompletionDateString);
|
|
||||||
const completionTime = (milestoneForm.workOrderMilestoneCompletionTimeString ?? '') === ''
|
|
||||||
? dateToTimeInteger(rightNow)
|
|
||||||
: timeStringToInteger(milestoneForm.workOrderMilestoneCompletionTimeString);
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update WorkOrderMilestones
|
.prepare(`update WorkOrderMilestones
|
||||||
set workOrderMilestoneCompletionDate = ?,
|
set workOrderMilestoneCompletionDate = ?,
|
||||||
|
|
@ -17,7 +11,11 @@ export default function completeWorkOrderMilestone(milestoneForm, user) {
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where workOrderMilestoneId = ?`)
|
where workOrderMilestoneId = ?`)
|
||||||
.run(completionDate, completionTime, user.userName, rightNow.getTime(), milestoneForm.workOrderMilestoneId);
|
.run((milestoneForm.workOrderMilestoneCompletionDateString ?? '') === ''
|
||||||
|
? dateToInteger(rightNow)
|
||||||
|
: dateStringToInteger(milestoneForm.workOrderMilestoneCompletionDateString), (milestoneForm.workOrderMilestoneCompletionTimeString ?? '') === ''
|
||||||
|
? dateToTimeInteger(rightNow)
|
||||||
|
: timeStringToInteger(milestoneForm.workOrderMilestoneCompletionTimeString), user.userName, rightNow.getTime(), milestoneForm.workOrderMilestoneId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import {
|
import {
|
||||||
type DateString,
|
|
||||||
type TimeString,
|
|
||||||
dateStringToInteger,
|
dateStringToInteger,
|
||||||
dateToInteger,
|
dateToInteger,
|
||||||
dateToTimeInteger,
|
dateToTimeInteger,
|
||||||
|
|
@ -13,8 +11,8 @@ import { sunriseDB } from '../helpers/database.helpers.js'
|
||||||
export interface CompleteWorkOrderMilestoneForm {
|
export interface CompleteWorkOrderMilestoneForm {
|
||||||
workOrderMilestoneId: number | string
|
workOrderMilestoneId: number | string
|
||||||
|
|
||||||
workOrderMilestoneCompletionDateString?: '' | DateString
|
workOrderMilestoneCompletionDateString?: string
|
||||||
workOrderMilestoneCompletionTimeString?: '' | TimeString
|
workOrderMilestoneCompletionTimeString?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function completeWorkOrderMilestone(
|
export default function completeWorkOrderMilestone(
|
||||||
|
|
@ -25,20 +23,6 @@ export default function completeWorkOrderMilestone(
|
||||||
|
|
||||||
const database = sqlite(sunriseDB)
|
const database = sqlite(sunriseDB)
|
||||||
|
|
||||||
const completionDate =
|
|
||||||
(milestoneForm.workOrderMilestoneCompletionDateString ?? '') === ''
|
|
||||||
? dateToInteger(rightNow)
|
|
||||||
: dateStringToInteger(
|
|
||||||
milestoneForm.workOrderMilestoneCompletionDateString as DateString
|
|
||||||
)
|
|
||||||
|
|
||||||
const completionTime =
|
|
||||||
(milestoneForm.workOrderMilestoneCompletionTimeString ?? '') === ''
|
|
||||||
? dateToTimeInteger(rightNow)
|
|
||||||
: timeStringToInteger(
|
|
||||||
milestoneForm.workOrderMilestoneCompletionTimeString as TimeString
|
|
||||||
)
|
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderMilestones
|
`update WorkOrderMilestones
|
||||||
|
|
@ -49,8 +33,16 @@ export default function completeWorkOrderMilestone(
|
||||||
where workOrderMilestoneId = ?`
|
where workOrderMilestoneId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
completionDate,
|
(milestoneForm.workOrderMilestoneCompletionDateString ?? '') === ''
|
||||||
completionTime,
|
? dateToInteger(rightNow)
|
||||||
|
: dateStringToInteger(
|
||||||
|
milestoneForm.workOrderMilestoneCompletionDateString!
|
||||||
|
),
|
||||||
|
(milestoneForm.workOrderMilestoneCompletionTimeString ?? '') === ''
|
||||||
|
? dateToTimeInteger(rightNow)
|
||||||
|
: timeStringToInteger(
|
||||||
|
milestoneForm.workOrderMilestoneCompletionTimeString!
|
||||||
|
),
|
||||||
user.userName,
|
user.userName,
|
||||||
rightNow.getTime(),
|
rightNow.getTime(),
|
||||||
milestoneForm.workOrderMilestoneId
|
milestoneForm.workOrderMilestoneId
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ export default async function copyContract(
|
||||||
funeralDirectorName: oldContract.funeralDirectorName,
|
funeralDirectorName: oldContract.funeralDirectorName,
|
||||||
funeralHomeId: oldContract.funeralHomeId ?? '',
|
funeralHomeId: oldContract.funeralHomeId ?? '',
|
||||||
funeralTimeString: oldContract.funeralTimeString ?? '',
|
funeralTimeString: oldContract.funeralTimeString ?? '',
|
||||||
|
|
||||||
purchaserAddress1: oldContract.purchaserAddress1,
|
purchaserAddress1: oldContract.purchaserAddress1,
|
||||||
purchaserAddress2: oldContract.purchaserAddress2,
|
purchaserAddress2: oldContract.purchaserAddress2,
|
||||||
purchaserCity: oldContract.purchaserCity,
|
purchaserCity: oldContract.purchaserCity,
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ export function deleteBurialSite(burialSiteId, user) {
|
||||||
.prepare(`select contractId
|
.prepare(`select contractId
|
||||||
from Contracts
|
from Contracts
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and recordDelete_timeMillis is null
|
and recordDelete_timeMillis is null
|
||||||
and (contractEndDate is null or contractEndDate >= ?)`)
|
and (contractEndDate is null or contractEndDate >= ?)`)
|
||||||
.pluck()
|
.pluck()
|
||||||
.get(burialSiteId, currentDateInteger);
|
.get(burialSiteId, currentDateInteger);
|
||||||
if (activeContract !== undefined) {
|
if (activeContract !== undefined) {
|
||||||
|
|
@ -26,9 +26,26 @@ export function deleteBurialSite(burialSiteId, user) {
|
||||||
database
|
database
|
||||||
.prepare(`update BurialSites
|
.prepare(`update BurialSites
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and recordDelete_timeMillis is null`)
|
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);
|
.run(user.userName, rightNowMillis, burialSiteId);
|
||||||
database.close();
|
database.close();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ export function deleteBurialSite(burialSiteId: number, user: User): boolean {
|
||||||
`select contractId
|
`select contractId
|
||||||
from Contracts
|
from Contracts
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and recordDelete_timeMillis is null
|
and recordDelete_timeMillis is null
|
||||||
and (contractEndDate is null or contractEndDate >= ?)`
|
and (contractEndDate is null or contractEndDate >= ?)`
|
||||||
)
|
)
|
||||||
.pluck()
|
.pluck()
|
||||||
.get(burialSiteId, currentDateInteger) as number | undefined
|
.get(burialSiteId, currentDateInteger) as number | undefined
|
||||||
|
|
@ -38,9 +38,33 @@ export function deleteBurialSite(burialSiteId: number, user: User): boolean {
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSites
|
`update BurialSites
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and recordDelete_timeMillis is null`
|
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)
|
.run(user.userName, rightNowMillis, burialSiteId)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ export default function deleteBurialSiteField(burialSiteId, burialSiteTypeFieldI
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update BurialSiteFields
|
.prepare(`update BurialSiteFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and burialSiteTypeFieldId = ?`)
|
and burialSiteTypeFieldId = ?`)
|
||||||
.run(user.userName, Date.now(), burialSiteId, burialSiteTypeFieldId);
|
.run(user.userName, Date.now(), burialSiteId, burialSiteTypeFieldId);
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.close();
|
database.close();
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,9 @@ export default function deleteBurialSiteField(
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSiteFields
|
`update BurialSiteFields
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and burialSiteTypeFieldId = ?`
|
and burialSiteTypeFieldId = ?`
|
||||||
)
|
)
|
||||||
.run(user.userName, Date.now(), burialSiteId, burialSiteTypeFieldId)
|
.run(user.userName, Date.now(), burialSiteId, burialSiteTypeFieldId)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import sqlite from 'better-sqlite3';
|
import sqlite from 'better-sqlite3';
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||||
import { cacheTableNames, clearCacheByTableName } from '../helpers/functions.cache.js';
|
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
||||||
const recordIdColumns = new Map([
|
const recordIdColumns = new Map([
|
||||||
['BurialSiteComments', 'burialSiteCommentId'],
|
['BurialSiteComments', 'burialSiteCommentId'],
|
||||||
['BurialSiteStatuses', 'burialSiteStatusId'],
|
['BurialSiteStatuses', 'burialSiteStatusId'],
|
||||||
|
|
@ -55,9 +55,6 @@ export function deleteRecord(recordTable, recordId, user) {
|
||||||
.run(user.userName, rightNowMillis, recordId);
|
.run(user.userName, rightNowMillis, recordId);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
// Clear cache for tables that are cached
|
clearCacheByTableName(recordTable);
|
||||||
if (cacheTableNames.includes(recordTable)) {
|
|
||||||
clearCacheByTableName(recordTable);
|
|
||||||
}
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
import sqlite from 'better-sqlite3'
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||||
import {
|
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||||
CacheTableNames,
|
|
||||||
cacheTableNames,
|
|
||||||
clearCacheByTableName
|
|
||||||
} from '../helpers/functions.cache.js'
|
|
||||||
|
|
||||||
type RecordTable =
|
type RecordTable =
|
||||||
| 'BurialSiteComments'
|
| 'BurialSiteComments'
|
||||||
|
|
@ -77,7 +73,7 @@ export function deleteRecord(
|
||||||
`update ${recordTable}
|
`update ${recordTable}
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where ${recordIdColumns.get(recordTable)} = ?
|
where ${recordIdColumns.get(recordTable)!} = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis, recordId)
|
.run(user.userName, rightNowMillis, recordId)
|
||||||
|
|
@ -88,7 +84,7 @@ export function deleteRecord(
|
||||||
`update ${relatedTable}
|
`update ${relatedTable}
|
||||||
set recordDelete_userName = ?,
|
set recordDelete_userName = ?,
|
||||||
recordDelete_timeMillis = ?
|
recordDelete_timeMillis = ?
|
||||||
where ${recordIdColumns.get(recordTable)} = ?
|
where ${recordIdColumns.get(recordTable)!} = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.run(user.userName, rightNowMillis, recordId)
|
.run(user.userName, rightNowMillis, recordId)
|
||||||
|
|
@ -96,10 +92,7 @@ export function deleteRecord(
|
||||||
|
|
||||||
database.close()
|
database.close()
|
||||||
|
|
||||||
// Clear cache for tables that are cached
|
clearCacheByTableName(recordTable)
|
||||||
if (cacheTableNames.includes(recordTable as CacheTableNames)) {
|
|
||||||
clearCacheByTableName(recordTable as CacheTableNames)
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.changes > 0
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import type { BurialSite } from '../types/record.types.js';
|
import type { BurialSite } from '../types/record.types.js';
|
||||||
export default function getBurialSite(burialSiteId: number | string, includeDeleted?: boolean): Promise<BurialSite | undefined>;
|
export default function getBurialSite(burialSiteId: number | string): Promise<BurialSite | undefined>;
|
||||||
export declare function getBurialSiteByBurialSiteName(burialSiteName: string, includeDeleted?: boolean): Promise<BurialSite | undefined>;
|
export declare function getBurialSiteByBurialSiteName(burialSiteName: string): Promise<BurialSite | undefined>;
|
||||||
|
|
|
||||||
|
|
@ -13,31 +13,25 @@ const baseSQL = `select l.burialSiteId,
|
||||||
l.burialSiteName,
|
l.burialSiteName,
|
||||||
l.burialSiteStatusId, s.burialSiteStatus,
|
l.burialSiteStatusId, s.burialSiteStatus,
|
||||||
|
|
||||||
l.bodyCapacity, l.crematedCapacity,
|
|
||||||
t.bodyCapacityMax, t.crematedCapacityMax,
|
|
||||||
|
|
||||||
l.cemeteryId, m.cemeteryName,
|
l.cemeteryId, m.cemeteryName,
|
||||||
m.cemeteryLatitude, m.cemeteryLongitude,
|
m.cemeteryLatitude, m.cemeteryLongitude,
|
||||||
m.cemeterySvg, l.cemeterySvgId, l.burialSiteImage,
|
m.cemeterySvg, l.cemeterySvgId, l.burialSiteImage,
|
||||||
l.burialSiteLatitude, l.burialSiteLongitude,
|
l.burialSiteLatitude, l.burialSiteLongitude
|
||||||
|
|
||||||
l.recordDelete_userName, l.recordDelete_timeMillis
|
|
||||||
|
|
||||||
from BurialSites l
|
from BurialSites l
|
||||||
left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId
|
left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId
|
||||||
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId`;
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
export default async function getBurialSite(burialSiteId, includeDeleted = false) {
|
where l.recordDelete_timeMillis is null`;
|
||||||
return await _getBurialSite(`l.burialSiteId = ?`, burialSiteId, includeDeleted);
|
export default async function getBurialSite(burialSiteId) {
|
||||||
|
return await _getBurialSite(`${baseSQL} and l.burialSiteId = ?`, burialSiteId);
|
||||||
}
|
}
|
||||||
export async function getBurialSiteByBurialSiteName(burialSiteName, includeDeleted = false) {
|
export async function getBurialSiteByBurialSiteName(burialSiteName) {
|
||||||
return await _getBurialSite(`l.burialSiteName = ?`, burialSiteName, includeDeleted);
|
return await _getBurialSite(`${baseSQL} and l.burialSiteName = ?`, burialSiteName);
|
||||||
}
|
}
|
||||||
async function _getBurialSite(whereClausePiece, burialSiteIdOrLotName, includeDeleted = false) {
|
async function _getBurialSite(sql, burialSiteIdOrLotName) {
|
||||||
const database = sqlite(sunriseDB, { readonly: true });
|
const database = sqlite(sunriseDB, { readonly: true });
|
||||||
const burialSite = database
|
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName);
|
||||||
.prepare(`${baseSQL} ${includeDeleted ? 'where' : 'where l.recordDelete_timeMillis is null and'} ${whereClausePiece}`)
|
|
||||||
.get(burialSiteIdOrLotName);
|
|
||||||
if (burialSite !== undefined) {
|
if (burialSite !== undefined) {
|
||||||
const contracts = await getContracts({
|
const contracts = await getContracts({
|
||||||
burialSiteId: burialSite.burialSiteId
|
burialSiteId: burialSite.burialSiteId
|
||||||
|
|
|
||||||
|
|
@ -17,55 +17,41 @@ const baseSQL = `select l.burialSiteId,
|
||||||
l.burialSiteName,
|
l.burialSiteName,
|
||||||
l.burialSiteStatusId, s.burialSiteStatus,
|
l.burialSiteStatusId, s.burialSiteStatus,
|
||||||
|
|
||||||
l.bodyCapacity, l.crematedCapacity,
|
|
||||||
t.bodyCapacityMax, t.crematedCapacityMax,
|
|
||||||
|
|
||||||
l.cemeteryId, m.cemeteryName,
|
l.cemeteryId, m.cemeteryName,
|
||||||
m.cemeteryLatitude, m.cemeteryLongitude,
|
m.cemeteryLatitude, m.cemeteryLongitude,
|
||||||
m.cemeterySvg, l.cemeterySvgId, l.burialSiteImage,
|
m.cemeterySvg, l.cemeterySvgId, l.burialSiteImage,
|
||||||
l.burialSiteLatitude, l.burialSiteLongitude,
|
l.burialSiteLatitude, l.burialSiteLongitude
|
||||||
|
|
||||||
l.recordDelete_userName, l.recordDelete_timeMillis
|
|
||||||
|
|
||||||
from BurialSites l
|
from BurialSites l
|
||||||
left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId
|
left join BurialSiteTypes t on l.burialSiteTypeId = t.burialSiteTypeId
|
||||||
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
left join BurialSiteStatuses s on l.burialSiteStatusId = s.burialSiteStatusId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId`
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
|
where l.recordDelete_timeMillis is null`
|
||||||
|
|
||||||
export default async function getBurialSite(
|
export default async function getBurialSite(
|
||||||
burialSiteId: number | string,
|
burialSiteId: number | string
|
||||||
includeDeleted = false
|
|
||||||
): Promise<BurialSite | undefined> {
|
): Promise<BurialSite | undefined> {
|
||||||
return await _getBurialSite(
|
return await _getBurialSite(`${baseSQL} and l.burialSiteId = ?`, burialSiteId)
|
||||||
`l.burialSiteId = ?`,
|
|
||||||
burialSiteId,
|
|
||||||
includeDeleted
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBurialSiteByBurialSiteName(
|
export async function getBurialSiteByBurialSiteName(
|
||||||
burialSiteName: string,
|
burialSiteName: string
|
||||||
includeDeleted = false
|
|
||||||
): Promise<BurialSite | undefined> {
|
): Promise<BurialSite | undefined> {
|
||||||
return await _getBurialSite(
|
return await _getBurialSite(
|
||||||
`l.burialSiteName = ?`,
|
`${baseSQL} and l.burialSiteName = ?`,
|
||||||
burialSiteName,
|
burialSiteName
|
||||||
includeDeleted
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _getBurialSite(
|
async function _getBurialSite(
|
||||||
whereClausePiece: string,
|
sql: string,
|
||||||
burialSiteIdOrLotName: number | string,
|
burialSiteIdOrLotName: number | string
|
||||||
includeDeleted = false
|
|
||||||
): Promise<BurialSite | undefined> {
|
): Promise<BurialSite | undefined> {
|
||||||
const database = sqlite(sunriseDB, { readonly: true })
|
const database = sqlite(sunriseDB, { readonly: true })
|
||||||
|
|
||||||
const burialSite = database
|
const burialSite = database.prepare(sql).get(burialSiteIdOrLotName) as
|
||||||
.prepare(
|
| BurialSite
|
||||||
`${baseSQL} ${includeDeleted ? 'where' : 'where l.recordDelete_timeMillis is null and'} ${whereClausePiece}`
|
| undefined
|
||||||
)
|
|
||||||
.get(burialSiteIdOrLotName) as BurialSite | undefined
|
|
||||||
|
|
||||||
if (burialSite !== undefined) {
|
if (burialSite !== undefined) {
|
||||||
const contracts = await getContracts(
|
const contracts = await getContracts(
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
import type { BurialSiteStatus } from '../types/record.types.js';
|
import type { BurialSiteStatus } from '../types/record.types.js';
|
||||||
export default function getBurialSiteStatuses(includeDeleted?: boolean): BurialSiteStatus[];
|
export default function getBurialSiteStatuses(): BurialSiteStatus[];
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,21 @@
|
||||||
import sqlite from 'better-sqlite3';
|
import sqlite from 'better-sqlite3';
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||||
export default function getBurialSiteStatuses(includeDeleted = false) {
|
export default function getBurialSiteStatuses() {
|
||||||
const database = sqlite(sunriseDB);
|
const database = sqlite(sunriseDB);
|
||||||
const updateOrderNumbers = !includeDeleted;
|
|
||||||
const statuses = database
|
const statuses = database
|
||||||
.prepare(`select burialSiteStatusId, burialSiteStatus, orderNumber
|
.prepare(`select burialSiteStatusId, burialSiteStatus, orderNumber
|
||||||
from BurialSiteStatuses
|
from BurialSiteStatuses
|
||||||
${includeDeleted ? '' : ' where recordDelete_timeMillis is null '}
|
where recordDelete_timeMillis is null
|
||||||
order by orderNumber, burialSiteStatus`)
|
order by orderNumber, burialSiteStatus`)
|
||||||
.all();
|
.all();
|
||||||
if (updateOrderNumbers) {
|
let expectedOrderNumber = 0;
|
||||||
let expectedOrderNumber = 0;
|
for (const status of statuses) {
|
||||||
for (const status of statuses) {
|
if (status.orderNumber !== expectedOrderNumber) {
|
||||||
if (status.orderNumber !== expectedOrderNumber) {
|
updateRecordOrderNumber('BurialSiteStatuses', status.burialSiteStatusId, expectedOrderNumber, database);
|
||||||
updateRecordOrderNumber('BurialSiteStatuses', status.burialSiteStatusId, expectedOrderNumber, database);
|
status.orderNumber = expectedOrderNumber;
|
||||||
status.orderNumber = expectedOrderNumber;
|
|
||||||
}
|
|
||||||
expectedOrderNumber += 1;
|
|
||||||
}
|
}
|
||||||
|
expectedOrderNumber += 1;
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
return statuses;
|
return statuses;
|
||||||
|
|
|
||||||
|
|
@ -5,39 +5,32 @@ import type { BurialSiteStatus } from '../types/record.types.js'
|
||||||
|
|
||||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
||||||
|
|
||||||
export default function getBurialSiteStatuses(
|
export default function getBurialSiteStatuses(): BurialSiteStatus[] {
|
||||||
includeDeleted = false
|
|
||||||
): BurialSiteStatus[] {
|
|
||||||
const database = sqlite(sunriseDB)
|
const database = sqlite(sunriseDB)
|
||||||
|
|
||||||
const updateOrderNumbers = !includeDeleted
|
|
||||||
|
|
||||||
const statuses = database
|
const statuses = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select burialSiteStatusId, burialSiteStatus, orderNumber
|
`select burialSiteStatusId, burialSiteStatus, orderNumber
|
||||||
from BurialSiteStatuses
|
from BurialSiteStatuses
|
||||||
${includeDeleted ? '' : ' where recordDelete_timeMillis is null '}
|
where recordDelete_timeMillis is null
|
||||||
order by orderNumber, burialSiteStatus`
|
order by orderNumber, burialSiteStatus`
|
||||||
)
|
)
|
||||||
.all() as BurialSiteStatus[]
|
.all() as BurialSiteStatus[]
|
||||||
|
|
||||||
if (updateOrderNumbers) {
|
let expectedOrderNumber = 0
|
||||||
let expectedOrderNumber = 0
|
|
||||||
|
|
||||||
for (const status of statuses) {
|
for (const status of statuses) {
|
||||||
if (status.orderNumber !== expectedOrderNumber) {
|
if (status.orderNumber !== expectedOrderNumber) {
|
||||||
updateRecordOrderNumber(
|
updateRecordOrderNumber(
|
||||||
'BurialSiteStatuses',
|
'BurialSiteStatuses',
|
||||||
status.burialSiteStatusId,
|
status.burialSiteStatusId,
|
||||||
expectedOrderNumber,
|
expectedOrderNumber,
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
|
status.orderNumber = expectedOrderNumber
|
||||||
status.orderNumber = expectedOrderNumber
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedOrderNumber += 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expectedOrderNumber += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
database.close()
|
database.close()
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,9 @@ import getBurialSiteTypeFields from './getBurialSiteTypeFields.js';
|
||||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||||
export default function getBurialSiteTypes(includeDeleted = false) {
|
export default function getBurialSiteTypes(includeDeleted = false) {
|
||||||
const database = sqlite(sunriseDB);
|
const database = sqlite(sunriseDB);
|
||||||
const updateOrderNumbers = !includeDeleted;
|
const updateOrderNumbers = !database.readonly && !includeDeleted;
|
||||||
const burialSiteTypes = database
|
const burialSiteTypes = database
|
||||||
.prepare(`select burialSiteTypeId, burialSiteType,
|
.prepare(`select burialSiteTypeId, burialSiteType, orderNumber
|
||||||
bodyCapacityMax, crematedCapacityMax,
|
|
||||||
orderNumber
|
|
||||||
from BurialSiteTypes
|
from BurialSiteTypes
|
||||||
${includeDeleted ? '' : ' where recordDelete_timeMillis is null '}
|
${includeDeleted ? '' : ' where recordDelete_timeMillis is null '}
|
||||||
order by orderNumber, burialSiteType`)
|
order by orderNumber, burialSiteType`)
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,11 @@ export default function getBurialSiteTypes(
|
||||||
): BurialSiteType[] {
|
): BurialSiteType[] {
|
||||||
const database = sqlite(sunriseDB)
|
const database = sqlite(sunriseDB)
|
||||||
|
|
||||||
const updateOrderNumbers = !includeDeleted
|
const updateOrderNumbers = !database.readonly && !includeDeleted
|
||||||
|
|
||||||
const burialSiteTypes = database
|
const burialSiteTypes = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select burialSiteTypeId, burialSiteType,
|
`select burialSiteTypeId, burialSiteType, orderNumber
|
||||||
bodyCapacityMax, crematedCapacityMax,
|
|
||||||
orderNumber
|
|
||||||
from BurialSiteTypes
|
from BurialSiteTypes
|
||||||
${includeDeleted ? '' : ' where recordDelete_timeMillis is null '}
|
${includeDeleted ? '' : ' where recordDelete_timeMillis is null '}
|
||||||
order by orderNumber, burialSiteType`
|
order by orderNumber, burialSiteType`
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ export interface GetBurialSitesFilters {
|
||||||
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith';
|
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith';
|
||||||
burialSiteName?: string;
|
burialSiteName?: string;
|
||||||
cemeteryId?: number | string;
|
cemeteryId?: number | string;
|
||||||
burialSiteStatusId?: number | string;
|
|
||||||
burialSiteTypeId?: number | string;
|
burialSiteTypeId?: number | string;
|
||||||
|
burialSiteStatusId?: number | string;
|
||||||
contractStatus?: '' | 'occupied' | 'unoccupied';
|
contractStatus?: '' | 'occupied' | 'unoccupied';
|
||||||
workOrderId?: number | string;
|
workOrderId?: number | string;
|
||||||
}
|
}
|
||||||
|
|
@ -16,6 +16,6 @@ export interface GetBurialSitesOptions {
|
||||||
includeContractCount?: boolean;
|
includeContractCount?: boolean;
|
||||||
}
|
}
|
||||||
export default function getBurialSites(filters: GetBurialSitesFilters, options: GetBurialSitesOptions, connectedDatabase?: sqlite.Database): {
|
export default function getBurialSites(filters: GetBurialSitesFilters, options: GetBurialSitesOptions, connectedDatabase?: sqlite.Database): {
|
||||||
burialSites: BurialSite[];
|
|
||||||
count: number;
|
count: number;
|
||||||
|
burialSites: BurialSite[];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,24 +4,23 @@ import { sunriseDB } from '../helpers/database.helpers.js';
|
||||||
import { getBurialSiteNameWhereClause } from '../helpers/functions.sqlFilters.js';
|
import { getBurialSiteNameWhereClause } from '../helpers/functions.sqlFilters.js';
|
||||||
export default function getBurialSites(filters, options, connectedDatabase) {
|
export default function getBurialSites(filters, options, connectedDatabase) {
|
||||||
const database = connectedDatabase ?? sqlite(sunriseDB, { readonly: true });
|
const database = connectedDatabase ?? sqlite(sunriseDB, { readonly: true });
|
||||||
const { sqlParameters, sqlWhereClause } = buildWhereClause(filters);
|
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
||||||
const currentDate = dateToInteger(new Date());
|
const currentDate = dateToInteger(new Date());
|
||||||
let count = 0;
|
let count = 0;
|
||||||
if (options.limit !== -1) {
|
if (options.limit !== -1) {
|
||||||
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 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
|
||||||
and contractStartDate <= ${currentDate.toString()}
|
and contractStartDate <= ${currentDate.toString()}
|
||||||
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
|
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
|
||||||
group by burialSiteId
|
group by burialSiteId
|
||||||
) o on l.burialSiteId = o.burialSiteId
|
) o on l.burialSiteId = o.burialSiteId
|
||||||
${sqlWhereClause}`)
|
${sqlWhereClause}`)
|
||||||
.pluck()
|
.get(sqlParameters).recordCount;
|
||||||
.get(sqlParameters);
|
|
||||||
}
|
}
|
||||||
let burialSites = [];
|
let burialSites = [];
|
||||||
if (options.limit === -1 || count > 0) {
|
if (options.limit === -1 || count > 0) {
|
||||||
|
|
@ -38,7 +37,6 @@ export default function getBurialSites(filters, options, connectedDatabase) {
|
||||||
l.burialSiteNameSegment5,
|
l.burialSiteNameSegment5,
|
||||||
l.burialSiteName,
|
l.burialSiteName,
|
||||||
t.burialSiteType,
|
t.burialSiteType,
|
||||||
l.bodyCapacity, l.crematedCapacity,
|
|
||||||
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
|
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
|
||||||
l.burialSiteStatusId, s.burialSiteStatus
|
l.burialSiteStatusId, s.burialSiteStatus
|
||||||
${includeContractCount
|
${includeContractCount
|
||||||
|
|
@ -72,8 +70,8 @@ export default function getBurialSites(filters, options, connectedDatabase) {
|
||||||
database.close();
|
database.close();
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
burialSites,
|
count,
|
||||||
count
|
burialSites
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function buildWhereClause(filters) {
|
function buildWhereClause(filters) {
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,8 @@ export interface GetBurialSitesFilters {
|
||||||
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith'
|
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith'
|
||||||
burialSiteName?: string
|
burialSiteName?: string
|
||||||
cemeteryId?: number | string
|
cemeteryId?: number | string
|
||||||
|
|
||||||
burialSiteStatusId?: number | string
|
|
||||||
burialSiteTypeId?: number | string
|
burialSiteTypeId?: number | string
|
||||||
|
burialSiteStatusId?: number | string
|
||||||
contractStatus?: '' | 'occupied' | 'unoccupied'
|
contractStatus?: '' | 'occupied' | 'unoccupied'
|
||||||
workOrderId?: number | string
|
workOrderId?: number | string
|
||||||
}
|
}
|
||||||
|
|
@ -28,32 +27,33 @@ export default function getBurialSites(
|
||||||
filters: GetBurialSitesFilters,
|
filters: GetBurialSitesFilters,
|
||||||
options: GetBurialSitesOptions,
|
options: GetBurialSitesOptions,
|
||||||
connectedDatabase?: sqlite.Database
|
connectedDatabase?: sqlite.Database
|
||||||
): { burialSites: BurialSite[]; count: number } {
|
): { count: number; burialSites: BurialSite[] } {
|
||||||
const database = connectedDatabase ?? sqlite(sunriseDB, { readonly: true })
|
const database = connectedDatabase ?? sqlite(sunriseDB, { readonly: true })
|
||||||
|
|
||||||
const { sqlParameters, sqlWhereClause } = buildWhereClause(filters)
|
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters)
|
||||||
|
|
||||||
const currentDate = dateToInteger(new Date())
|
const currentDate = dateToInteger(new Date())
|
||||||
|
|
||||||
let count = 0
|
let count = 0
|
||||||
|
|
||||||
if (options.limit !== -1) {
|
if (options.limit !== -1) {
|
||||||
count = database
|
count = (
|
||||||
.prepare(
|
database
|
||||||
`select count(*) as recordCount
|
.prepare(
|
||||||
from BurialSites l
|
`select count(*) as recordCount
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
from BurialSites l
|
||||||
left join (
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
select burialSiteId, count(contractId) as contractCount from Contracts
|
left join (
|
||||||
where recordDelete_timeMillis is null
|
select burialSiteId, count(contractId) as contractCount from Contracts
|
||||||
and contractStartDate <= ${currentDate.toString()}
|
where recordDelete_timeMillis is null
|
||||||
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
|
and contractStartDate <= ${currentDate.toString()}
|
||||||
group by burialSiteId
|
and (contractEndDate is null or contractEndDate >= ${currentDate.toString()})
|
||||||
) o on l.burialSiteId = o.burialSiteId
|
group by burialSiteId
|
||||||
${sqlWhereClause}`
|
) o on l.burialSiteId = o.burialSiteId
|
||||||
)
|
${sqlWhereClause}`
|
||||||
.pluck()
|
)
|
||||||
.get(sqlParameters) as number
|
.get(sqlParameters) as { recordCount: number }
|
||||||
|
).recordCount
|
||||||
}
|
}
|
||||||
|
|
||||||
let burialSites: BurialSite[] = []
|
let burialSites: BurialSite[] = []
|
||||||
|
|
@ -75,7 +75,6 @@ export default function getBurialSites(
|
||||||
l.burialSiteNameSegment5,
|
l.burialSiteNameSegment5,
|
||||||
l.burialSiteName,
|
l.burialSiteName,
|
||||||
t.burialSiteType,
|
t.burialSiteType,
|
||||||
l.bodyCapacity, l.crematedCapacity,
|
|
||||||
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
|
l.cemeteryId, m.cemeteryName, l.cemeterySvgId,
|
||||||
l.burialSiteStatusId, s.burialSiteStatus
|
l.burialSiteStatusId, s.burialSiteStatus
|
||||||
${
|
${
|
||||||
|
|
@ -119,8 +118,8 @@ export default function getBurialSites(
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
burialSites,
|
count,
|
||||||
count
|
burialSites
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ export default async function getContract(contractId, connectedDatabase) {
|
||||||
.prepare(`select o.contractId,
|
.prepare(`select o.contractId,
|
||||||
o.contractTypeId, t.contractType, t.isPreneed,
|
o.contractTypeId, t.contractType, t.isPreneed,
|
||||||
o.burialSiteId, l.burialSiteName, l.burialSiteTypeId,
|
o.burialSiteId, l.burialSiteName, l.burialSiteTypeId,
|
||||||
case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive,
|
|
||||||
l.cemeteryId, m.cemeteryName,
|
l.cemeteryId, m.cemeteryName,
|
||||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ export default async function getContract(
|
||||||
`select o.contractId,
|
`select o.contractId,
|
||||||
o.contractTypeId, t.contractType, t.isPreneed,
|
o.contractTypeId, t.contractType, t.isPreneed,
|
||||||
o.burialSiteId, l.burialSiteName, l.burialSiteTypeId,
|
o.burialSiteId, l.burialSiteName, l.burialSiteTypeId,
|
||||||
case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive,
|
|
||||||
l.cemeteryId, m.cemeteryName,
|
l.cemeteryId, m.cemeteryName,
|
||||||
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||||
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,12 @@ export default async function GetContractTransactions(contractId, options, conne
|
||||||
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
database.function('userFn_timeIntegerToString', timeIntegerToString);
|
||||||
const contractTransactions = database
|
const contractTransactions = database
|
||||||
.prepare(`select contractId, transactionIndex,
|
.prepare(`select contractId, transactionIndex,
|
||||||
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
|
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
|
||||||
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
|
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
|
||||||
transactionAmount, externalReceiptNumber, transactionNote
|
transactionAmount, externalReceiptNumber, transactionNote
|
||||||
from ContractTransactions
|
from ContractTransactions
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractId = ?
|
and contractId = ?
|
||||||
order by transactionDate, transactionTime, transactionIndex`)
|
order by transactionDate, transactionTime, transactionIndex`)
|
||||||
.all(contractId);
|
.all(contractId);
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,12 @@ export default async function GetContractTransactions(
|
||||||
const contractTransactions = database
|
const contractTransactions = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select contractId, transactionIndex,
|
`select contractId, transactionIndex,
|
||||||
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
|
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
|
||||||
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
|
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
|
||||||
transactionAmount, externalReceiptNumber, transactionNote
|
transactionAmount, externalReceiptNumber, transactionNote
|
||||||
from ContractTransactions
|
from ContractTransactions
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and contractId = ?
|
and contractId = ?
|
||||||
order by transactionDate, transactionTime, transactionIndex`
|
order by transactionDate, transactionTime, transactionIndex`
|
||||||
)
|
)
|
||||||
.all(contractId) as ContractTransaction[]
|
.all(contractId) as ContractTransaction[]
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
import type { ContractType } from '../types/record.types.js';
|
import type { ContractType } from '../types/record.types.js';
|
||||||
export default function getContractTypes(includeDeleted?: boolean): ContractType[];
|
export default function getContractTypes(): ContractType[];
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,18 @@ import { sunriseDB } from '../helpers/database.helpers.js';
|
||||||
import getContractTypeFields from './getContractTypeFields.js';
|
import getContractTypeFields from './getContractTypeFields.js';
|
||||||
import getContractTypePrints from './getContractTypePrints.js';
|
import getContractTypePrints from './getContractTypePrints.js';
|
||||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||||
export default function getContractTypes(includeDeleted = false) {
|
export default function getContractTypes() {
|
||||||
const database = sqlite(sunriseDB);
|
const database = sqlite(sunriseDB);
|
||||||
const updateOrderNumbers = !includeDeleted;
|
|
||||||
const contractTypes = database
|
const contractTypes = database
|
||||||
.prepare(`select contractTypeId, contractType, isPreneed, orderNumber
|
.prepare(`select contractTypeId, contractType, isPreneed, orderNumber
|
||||||
from ContractTypes
|
from ContractTypes
|
||||||
${includeDeleted ? '' : ' where recordDelete_timeMillis is null '}
|
where recordDelete_timeMillis is null
|
||||||
order by orderNumber, contractType, contractTypeId`)
|
order by orderNumber, contractType, contractTypeId`)
|
||||||
.all();
|
.all();
|
||||||
let expectedOrderNumber = -1;
|
let expectedOrderNumber = -1;
|
||||||
for (const contractType of contractTypes) {
|
for (const contractType of contractTypes) {
|
||||||
expectedOrderNumber += 1;
|
expectedOrderNumber += 1;
|
||||||
if (updateOrderNumbers &&
|
if (contractType.orderNumber !== expectedOrderNumber) {
|
||||||
contractType.orderNumber !== expectedOrderNumber) {
|
|
||||||
updateRecordOrderNumber('ContractTypes', contractType.contractTypeId, expectedOrderNumber, database);
|
updateRecordOrderNumber('ContractTypes', contractType.contractTypeId, expectedOrderNumber, database);
|
||||||
contractType.orderNumber = expectedOrderNumber;
|
contractType.orderNumber = expectedOrderNumber;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,14 @@ import getContractTypeFields from './getContractTypeFields.js'
|
||||||
import getContractTypePrints from './getContractTypePrints.js'
|
import getContractTypePrints from './getContractTypePrints.js'
|
||||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
||||||
|
|
||||||
export default function getContractTypes(
|
export default function getContractTypes(): ContractType[] {
|
||||||
includeDeleted = false
|
|
||||||
): ContractType[] {
|
|
||||||
const database = sqlite(sunriseDB)
|
const database = sqlite(sunriseDB)
|
||||||
|
|
||||||
const updateOrderNumbers = !includeDeleted
|
|
||||||
|
|
||||||
const contractTypes = database
|
const contractTypes = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select contractTypeId, contractType, isPreneed, orderNumber
|
`select contractTypeId, contractType, isPreneed, orderNumber
|
||||||
from ContractTypes
|
from ContractTypes
|
||||||
${includeDeleted ? '' : ' where recordDelete_timeMillis is null '}
|
where recordDelete_timeMillis is null
|
||||||
order by orderNumber, contractType, contractTypeId`
|
order by orderNumber, contractType, contractTypeId`
|
||||||
)
|
)
|
||||||
.all() as ContractType[]
|
.all() as ContractType[]
|
||||||
|
|
@ -28,10 +24,7 @@ export default function getContractTypes(
|
||||||
for (const contractType of contractTypes) {
|
for (const contractType of contractTypes) {
|
||||||
expectedOrderNumber += 1
|
expectedOrderNumber += 1
|
||||||
|
|
||||||
if (
|
if (contractType.orderNumber !== expectedOrderNumber) {
|
||||||
updateOrderNumbers &&
|
|
||||||
contractType.orderNumber !== expectedOrderNumber
|
|
||||||
) {
|
|
||||||
updateRecordOrderNumber(
|
updateRecordOrderNumber(
|
||||||
'ContractTypes',
|
'ContractTypes',
|
||||||
contractType.contractTypeId,
|
contractType.contractTypeId,
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,13 @@ export interface GetContractsFilters {
|
||||||
contractEffectiveDateString?: string;
|
contractEffectiveDateString?: string;
|
||||||
contractStartDateString?: DateString;
|
contractStartDateString?: DateString;
|
||||||
contractTime?: '' | 'current' | 'future' | 'past';
|
contractTime?: '' | 'current' | 'future' | 'past';
|
||||||
cemeteryId?: number | string;
|
|
||||||
contractTypeId?: number | string;
|
|
||||||
deceasedName?: string;
|
deceasedName?: string;
|
||||||
|
contractTypeId?: number | string;
|
||||||
|
cemeteryId?: number | string;
|
||||||
burialSiteName?: string;
|
burialSiteName?: string;
|
||||||
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith';
|
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith';
|
||||||
burialSiteTypeId?: number | string;
|
burialSiteTypeId?: number | string;
|
||||||
funeralHomeId?: number | string;
|
funeralHomeId?: number | string;
|
||||||
funeralTime?: '' | 'upcoming';
|
|
||||||
notWorkOrderId?: number | string;
|
notWorkOrderId?: number | string;
|
||||||
workOrderId?: number | string;
|
workOrderId?: number | string;
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +20,6 @@ export interface GetContractsOptions {
|
||||||
/** -1 for no limit */
|
/** -1 for no limit */
|
||||||
limit: number | string;
|
limit: number | string;
|
||||||
offset: number | string;
|
offset: number | string;
|
||||||
orderBy?: string;
|
|
||||||
includeFees: boolean;
|
includeFees: boolean;
|
||||||
includeInterments: boolean;
|
includeInterments: boolean;
|
||||||
includeTransactions: boolean;
|
includeTransactions: boolean;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { dateIntegerToString, dateStringToInteger, dateToInteger, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
|
import { dateIntegerToString, dateStringToInteger, timeIntegerToPeriodString, timeIntegerToString } from '@cityssm/utils-datetime';
|
||||||
import sqlite from 'better-sqlite3';
|
import sqlite from 'better-sqlite3';
|
||||||
import { getConfigProperty } from '../helpers/config.helpers.js';
|
import { getConfigProperty } from '../helpers/config.helpers.js';
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||||
|
|
@ -20,55 +20,48 @@ export default async function getContracts(filters, options, connectedDatabase)
|
||||||
if (isLimited) {
|
if (isLimited) {
|
||||||
count = database
|
count = database
|
||||||
.prepare(`select count(*) as recordCount
|
.prepare(`select count(*) as recordCount
|
||||||
from Contracts c
|
from Contracts o
|
||||||
left join BurialSites l on c.burialSiteId = l.burialSiteId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
${sqlWhereClause}`)
|
${sqlWhereClause}`)
|
||||||
.pluck()
|
.get(sqlParameters).recordCount;
|
||||||
.get(sqlParameters);
|
|
||||||
}
|
}
|
||||||
let contracts = [];
|
let contracts = [];
|
||||||
if (count !== 0) {
|
if (count !== 0) {
|
||||||
const sqlLimitClause = isLimited
|
|
||||||
? ` limit ${options.limit} offset ${options.offset}`
|
|
||||||
: '';
|
|
||||||
contracts = database
|
contracts = database
|
||||||
.prepare(`select c.contractId,
|
.prepare(`select o.contractId,
|
||||||
c.contractTypeId, t.contractType, t.isPreneed,
|
o.contractTypeId, t.contractType, t.isPreneed,
|
||||||
c.burialSiteId, lt.burialSiteType, l.burialSiteName,
|
o.burialSiteId, lt.burialSiteType, l.burialSiteName,
|
||||||
case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive,
|
l.cemeteryId, m.cemeteryName,
|
||||||
l.cemeteryId, m.cemeteryName,
|
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||||
c.contractStartDate, userFn_dateIntegerToString(c.contractStartDate) as contractStartDateString,
|
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
||||||
c.contractEndDate, userFn_dateIntegerToString(c.contractEndDate) as contractEndDateString,
|
o.purchaserName, o.purchaserAddress1, o.purchaserAddress2,
|
||||||
c.purchaserName, c.purchaserAddress1, c.purchaserAddress2,
|
o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode,
|
||||||
c.purchaserCity, c.purchaserProvince, c.purchaserPostalCode,
|
o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship,
|
||||||
c.purchaserPhoneNumber, c.purchaserEmail, c.purchaserRelationship,
|
o.funeralHomeId, o.funeralDirectorName, f.funeralHomeName,
|
||||||
c.funeralHomeId, c.funeralDirectorName, f.funeralHomeName,
|
|
||||||
|
|
||||||
c.funeralDate, userFn_dateIntegerToString(c.funeralDate) as funeralDateString,
|
o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString,
|
||||||
c.funeralTime,
|
o.funeralTime,
|
||||||
userFn_timeIntegerToString(c.funeralTime) as funeralTimeString,
|
userFn_timeIntegerToString(o.funeralTime) as funeralTimeString,
|
||||||
userFn_timeIntegerToPeriodString(c.funeralTime) as funeralTimePeriodString,
|
userFn_timeIntegerToPeriodString(o.funeralTime) as funeralTimePeriodString,
|
||||||
c.directionOfArrival,
|
o.directionOfArrival,
|
||||||
c.committalTypeId, cm.committalType
|
o.committalTypeId, c.committalType
|
||||||
from Contracts c
|
from Contracts o
|
||||||
left join ContractTypes t on c.contractTypeId = t.contractTypeId
|
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
||||||
left join CommittalTypes cm on c.committalTypeId = cm.committalTypeId
|
left join CommittalTypes c on o.committalTypeId = c.committalTypeId
|
||||||
left join BurialSites l on c.burialSiteId = l.burialSiteId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
left join FuneralHomes f on c.funeralHomeId = f.funeralHomeId
|
left join FuneralHomes f on o.funeralHomeId = f.funeralHomeId
|
||||||
${sqlWhereClause}
|
${sqlWhereClause}
|
||||||
${options.orderBy !== undefined && options.orderBy !== ''
|
order by o.contractStartDate desc, ifnull(o.contractEndDate, 99999999) desc,
|
||||||
? ` order by ${options.orderBy}`
|
l.burialSiteNameSegment1,
|
||||||
: ` order by c.contractStartDate desc, ifnull(c.contractEndDate, 99999999) desc,
|
l.burialSiteNameSegment2,
|
||||||
l.burialSiteNameSegment1,
|
l.burialSiteNameSegment3,
|
||||||
l.burialSiteNameSegment2,
|
l.burialSiteNameSegment4,
|
||||||
l.burialSiteNameSegment3,
|
l.burialSiteNameSegment5,
|
||||||
l.burialSiteNameSegment4,
|
o.burialSiteId, o.contractId desc
|
||||||
l.burialSiteNameSegment5,
|
${isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''}`)
|
||||||
c.burialSiteId, c.contractId desc`}
|
|
||||||
${sqlLimitClause}`)
|
|
||||||
.all(sqlParameters);
|
.all(sqlParameters);
|
||||||
if (!isLimited) {
|
if (!isLimited) {
|
||||||
count = contracts.length;
|
count = contracts.length;
|
||||||
|
|
@ -105,38 +98,38 @@ async function addInclusions(contract, options, database) {
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line complexity
|
// eslint-disable-next-line complexity
|
||||||
function buildWhereClause(filters) {
|
function buildWhereClause(filters) {
|
||||||
let sqlWhereClause = ' where c.recordDelete_timeMillis is null';
|
let sqlWhereClause = ' where o.recordDelete_timeMillis is null';
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
if ((filters.burialSiteId ?? '') !== '') {
|
if ((filters.burialSiteId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and c.burialSiteId = ?';
|
sqlWhereClause += ' and o.burialSiteId = ?';
|
||||||
sqlParameters.push(filters.burialSiteId);
|
sqlParameters.push(filters.burialSiteId);
|
||||||
}
|
}
|
||||||
const burialSiteNameFilters = getBurialSiteNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l');
|
const burialSiteNameFilters = getBurialSiteNameWhereClause(filters.burialSiteName, filters.burialSiteNameSearchType ?? '', 'l');
|
||||||
sqlWhereClause += burialSiteNameFilters.sqlWhereClause;
|
sqlWhereClause += burialSiteNameFilters.sqlWhereClause;
|
||||||
sqlParameters.push(...burialSiteNameFilters.sqlParameters);
|
sqlParameters.push(...burialSiteNameFilters.sqlParameters);
|
||||||
const deceasedNameFilters = getDeceasedNameWhereClause(filters.deceasedName, 'c');
|
const deceasedNameFilters = getDeceasedNameWhereClause(filters.deceasedName, 'o');
|
||||||
if (deceasedNameFilters.sqlParameters.length > 0) {
|
if (deceasedNameFilters.sqlParameters.length > 0) {
|
||||||
sqlWhereClause += ` and c.contractId in (
|
sqlWhereClause += ` and o.contractId in (
|
||||||
select contractId from ContractInterments c
|
select contractId from ContractInterments o
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
${deceasedNameFilters.sqlWhereClause})`;
|
${deceasedNameFilters.sqlWhereClause})`;
|
||||||
sqlParameters.push(...deceasedNameFilters.sqlParameters);
|
sqlParameters.push(...deceasedNameFilters.sqlParameters);
|
||||||
}
|
}
|
||||||
if ((filters.contractTypeId ?? '') !== '') {
|
if ((filters.contractTypeId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and c.contractTypeId = ?';
|
sqlWhereClause += ' and o.contractTypeId = ?';
|
||||||
sqlParameters.push(filters.contractTypeId);
|
sqlParameters.push(filters.contractTypeId);
|
||||||
}
|
}
|
||||||
const contractTimeFilters = getContractTimeWhereClause(filters.contractTime ?? '', 'c');
|
const contractTimeFilters = getContractTimeWhereClause(filters.contractTime ?? '', 'o');
|
||||||
sqlWhereClause += contractTimeFilters.sqlWhereClause;
|
sqlWhereClause += contractTimeFilters.sqlWhereClause;
|
||||||
sqlParameters.push(...contractTimeFilters.sqlParameters);
|
sqlParameters.push(...contractTimeFilters.sqlParameters);
|
||||||
if ((filters.contractStartDateString ?? '') !== '') {
|
if ((filters.contractStartDateString ?? '') !== '') {
|
||||||
sqlWhereClause += ' and c.contractStartDate = ?';
|
sqlWhereClause += ' and o.contractStartDate = ?';
|
||||||
sqlParameters.push(dateStringToInteger(filters.contractStartDateString));
|
sqlParameters.push(dateStringToInteger(filters.contractStartDateString));
|
||||||
}
|
}
|
||||||
if ((filters.contractEffectiveDateString ?? '') !== '') {
|
if ((filters.contractEffectiveDateString ?? '') !== '') {
|
||||||
sqlWhereClause += ` and (
|
sqlWhereClause += ` and (
|
||||||
c.contractEndDate is null
|
o.contractEndDate is null
|
||||||
or (c.contractStartDate <= ? and c.contractEndDate >= ?)
|
or (o.contractStartDate <= ? and o.contractEndDate >= ?)
|
||||||
)`;
|
)`;
|
||||||
sqlParameters.push(dateStringToInteger(filters.contractEffectiveDateString), dateStringToInteger(filters.contractEffectiveDateString));
|
sqlParameters.push(dateStringToInteger(filters.contractEffectiveDateString), dateStringToInteger(filters.contractEffectiveDateString));
|
||||||
}
|
}
|
||||||
|
|
@ -149,21 +142,17 @@ function buildWhereClause(filters) {
|
||||||
sqlParameters.push(filters.burialSiteTypeId);
|
sqlParameters.push(filters.burialSiteTypeId);
|
||||||
}
|
}
|
||||||
if ((filters.funeralHomeId ?? '') !== '') {
|
if ((filters.funeralHomeId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and c.funeralHomeId = ?';
|
sqlWhereClause += ' and o.funeralHomeId = ?';
|
||||||
sqlParameters.push(filters.funeralHomeId);
|
sqlParameters.push(filters.funeralHomeId);
|
||||||
}
|
}
|
||||||
if ((filters.funeralTime ?? '') === 'upcoming') {
|
|
||||||
sqlWhereClause += ' and c.funeralDate >= ?';
|
|
||||||
sqlParameters.push(dateToInteger(new Date()));
|
|
||||||
}
|
|
||||||
if ((filters.workOrderId ?? '') !== '') {
|
if ((filters.workOrderId ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
sqlWhereClause +=
|
||||||
' and c.contractId in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
|
' and o.contractId in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
|
||||||
sqlParameters.push(filters.workOrderId);
|
sqlParameters.push(filters.workOrderId);
|
||||||
}
|
}
|
||||||
if ((filters.notWorkOrderId ?? '') !== '') {
|
if ((filters.notWorkOrderId ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
sqlWhereClause +=
|
||||||
' and c.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
|
' and o.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)';
|
||||||
sqlParameters.push(filters.notWorkOrderId);
|
sqlParameters.push(filters.notWorkOrderId);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import {
|
||||||
type DateString,
|
type DateString,
|
||||||
dateIntegerToString,
|
dateIntegerToString,
|
||||||
dateStringToInteger,
|
dateStringToInteger,
|
||||||
dateToInteger,
|
|
||||||
timeIntegerToPeriodString,
|
timeIntegerToPeriodString,
|
||||||
timeIntegerToString
|
timeIntegerToString
|
||||||
} from '@cityssm/utils-datetime'
|
} from '@cityssm/utils-datetime'
|
||||||
|
|
@ -29,17 +28,15 @@ export interface GetContractsFilters {
|
||||||
contractStartDateString?: DateString
|
contractStartDateString?: DateString
|
||||||
contractTime?: '' | 'current' | 'future' | 'past'
|
contractTime?: '' | 'current' | 'future' | 'past'
|
||||||
|
|
||||||
cemeteryId?: number | string
|
|
||||||
contractTypeId?: number | string
|
|
||||||
deceasedName?: string
|
deceasedName?: string
|
||||||
|
contractTypeId?: number | string
|
||||||
|
cemeteryId?: number | string
|
||||||
|
|
||||||
burialSiteName?: string
|
burialSiteName?: string
|
||||||
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith'
|
burialSiteNameSearchType?: '' | 'endsWith' | 'startsWith'
|
||||||
|
|
||||||
burialSiteTypeId?: number | string
|
burialSiteTypeId?: number | string
|
||||||
|
|
||||||
funeralHomeId?: number | string
|
funeralHomeId?: number | string
|
||||||
funeralTime?: '' | 'upcoming'
|
|
||||||
|
|
||||||
notWorkOrderId?: number | string
|
notWorkOrderId?: number | string
|
||||||
workOrderId?: number | string
|
workOrderId?: number | string
|
||||||
|
|
@ -50,8 +47,6 @@ export interface GetContractsOptions {
|
||||||
limit: number | string
|
limit: number | string
|
||||||
offset: number | string
|
offset: number | string
|
||||||
|
|
||||||
orderBy?: string
|
|
||||||
|
|
||||||
includeFees: boolean
|
includeFees: boolean
|
||||||
includeInterments: boolean
|
includeInterments: boolean
|
||||||
includeTransactions: boolean
|
includeTransactions: boolean
|
||||||
|
|
@ -67,9 +62,7 @@ export default async function getContracts(
|
||||||
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
database.function('userFn_dateIntegerToString', dateIntegerToString)
|
||||||
database.function('userFn_timeIntegerToString', timeIntegerToString)
|
database.function('userFn_timeIntegerToString', timeIntegerToString)
|
||||||
database.function(
|
database.function(
|
||||||
'userFn_timeIntegerToPeriodString',
|
'userFn_timeIntegerToPeriodString', timeIntegerToPeriodString)
|
||||||
timeIntegerToPeriodString
|
|
||||||
)
|
|
||||||
|
|
||||||
const { sqlParameters, sqlWhereClause } = buildWhereClause(filters)
|
const { sqlParameters, sqlWhereClause } = buildWhereClause(filters)
|
||||||
|
|
||||||
|
|
@ -81,65 +74,59 @@ export default async function getContracts(
|
||||||
const isLimited = options.limit !== -1
|
const isLimited = options.limit !== -1
|
||||||
|
|
||||||
if (isLimited) {
|
if (isLimited) {
|
||||||
count = database
|
count = (
|
||||||
.prepare(
|
database
|
||||||
`select count(*) as recordCount
|
.prepare(
|
||||||
from Contracts c
|
`select count(*) as recordCount
|
||||||
left join BurialSites l on c.burialSiteId = l.burialSiteId
|
from Contracts o
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
${sqlWhereClause}`
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
)
|
${sqlWhereClause}`
|
||||||
.pluck()
|
)
|
||||||
.get(sqlParameters) as number
|
.get(sqlParameters) as { recordCount: number }
|
||||||
|
).recordCount
|
||||||
}
|
}
|
||||||
|
|
||||||
let contracts: Contract[] = []
|
let contracts: Contract[] = []
|
||||||
|
|
||||||
if (count !== 0) {
|
if (count !== 0) {
|
||||||
const sqlLimitClause = isLimited
|
|
||||||
? ` limit ${options.limit} offset ${options.offset}`
|
|
||||||
: ''
|
|
||||||
|
|
||||||
contracts = database
|
contracts = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select c.contractId,
|
`select o.contractId,
|
||||||
c.contractTypeId, t.contractType, t.isPreneed,
|
o.contractTypeId, t.contractType, t.isPreneed,
|
||||||
c.burialSiteId, lt.burialSiteType, l.burialSiteName,
|
o.burialSiteId, lt.burialSiteType, l.burialSiteName,
|
||||||
case when l.recordDelete_timeMillis is null then 1 else 0 end as burialSiteIsActive,
|
l.cemeteryId, m.cemeteryName,
|
||||||
l.cemeteryId, m.cemeteryName,
|
o.contractStartDate, userFn_dateIntegerToString(o.contractStartDate) as contractStartDateString,
|
||||||
c.contractStartDate, userFn_dateIntegerToString(c.contractStartDate) as contractStartDateString,
|
o.contractEndDate, userFn_dateIntegerToString(o.contractEndDate) as contractEndDateString,
|
||||||
c.contractEndDate, userFn_dateIntegerToString(c.contractEndDate) as contractEndDateString,
|
o.purchaserName, o.purchaserAddress1, o.purchaserAddress2,
|
||||||
c.purchaserName, c.purchaserAddress1, c.purchaserAddress2,
|
o.purchaserCity, o.purchaserProvince, o.purchaserPostalCode,
|
||||||
c.purchaserCity, c.purchaserProvince, c.purchaserPostalCode,
|
o.purchaserPhoneNumber, o.purchaserEmail, o.purchaserRelationship,
|
||||||
c.purchaserPhoneNumber, c.purchaserEmail, c.purchaserRelationship,
|
o.funeralHomeId, o.funeralDirectorName, f.funeralHomeName,
|
||||||
c.funeralHomeId, c.funeralDirectorName, f.funeralHomeName,
|
|
||||||
|
|
||||||
c.funeralDate, userFn_dateIntegerToString(c.funeralDate) as funeralDateString,
|
o.funeralDate, userFn_dateIntegerToString(o.funeralDate) as funeralDateString,
|
||||||
c.funeralTime,
|
o.funeralTime,
|
||||||
userFn_timeIntegerToString(c.funeralTime) as funeralTimeString,
|
userFn_timeIntegerToString(o.funeralTime) as funeralTimeString,
|
||||||
userFn_timeIntegerToPeriodString(c.funeralTime) as funeralTimePeriodString,
|
userFn_timeIntegerToPeriodString(o.funeralTime) as funeralTimePeriodString,
|
||||||
c.directionOfArrival,
|
o.directionOfArrival,
|
||||||
c.committalTypeId, cm.committalType
|
o.committalTypeId, c.committalType
|
||||||
from Contracts c
|
from Contracts o
|
||||||
left join ContractTypes t on c.contractTypeId = t.contractTypeId
|
left join ContractTypes t on o.contractTypeId = t.contractTypeId
|
||||||
left join CommittalTypes cm on c.committalTypeId = cm.committalTypeId
|
left join CommittalTypes c on o.committalTypeId = c.committalTypeId
|
||||||
left join BurialSites l on c.burialSiteId = l.burialSiteId
|
left join BurialSites l on o.burialSiteId = l.burialSiteId
|
||||||
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
left join BurialSiteTypes lt on l.burialSiteTypeId = lt.burialSiteTypeId
|
||||||
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
left join Cemeteries m on l.cemeteryId = m.cemeteryId
|
||||||
left join FuneralHomes f on c.funeralHomeId = f.funeralHomeId
|
left join FuneralHomes f on o.funeralHomeId = f.funeralHomeId
|
||||||
${sqlWhereClause}
|
${sqlWhereClause}
|
||||||
|
order by o.contractStartDate desc, ifnull(o.contractEndDate, 99999999) desc,
|
||||||
|
l.burialSiteNameSegment1,
|
||||||
|
l.burialSiteNameSegment2,
|
||||||
|
l.burialSiteNameSegment3,
|
||||||
|
l.burialSiteNameSegment4,
|
||||||
|
l.burialSiteNameSegment5,
|
||||||
|
o.burialSiteId, o.contractId desc
|
||||||
${
|
${
|
||||||
options.orderBy !== undefined && options.orderBy !== ''
|
isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''
|
||||||
? ` order by ${options.orderBy}`
|
}`
|
||||||
: ` order by c.contractStartDate desc, ifnull(c.contractEndDate, 99999999) desc,
|
|
||||||
l.burialSiteNameSegment1,
|
|
||||||
l.burialSiteNameSegment2,
|
|
||||||
l.burialSiteNameSegment3,
|
|
||||||
l.burialSiteNameSegment4,
|
|
||||||
l.burialSiteNameSegment5,
|
|
||||||
c.burialSiteId, c.contractId desc`
|
|
||||||
}
|
|
||||||
${sqlLimitClause}`
|
|
||||||
)
|
)
|
||||||
.all(sqlParameters) as Contract[]
|
.all(sqlParameters) as Contract[]
|
||||||
|
|
||||||
|
|
@ -204,11 +191,11 @@ function buildWhereClause(filters: GetContractsFilters): {
|
||||||
sqlParameters: unknown[]
|
sqlParameters: unknown[]
|
||||||
sqlWhereClause: string
|
sqlWhereClause: string
|
||||||
} {
|
} {
|
||||||
let sqlWhereClause = ' where c.recordDelete_timeMillis is null'
|
let sqlWhereClause = ' where o.recordDelete_timeMillis is null'
|
||||||
const sqlParameters: unknown[] = []
|
const sqlParameters: unknown[] = []
|
||||||
|
|
||||||
if ((filters.burialSiteId ?? '') !== '') {
|
if ((filters.burialSiteId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and c.burialSiteId = ?'
|
sqlWhereClause += ' and o.burialSiteId = ?'
|
||||||
sqlParameters.push(filters.burialSiteId)
|
sqlParameters.push(filters.burialSiteId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -222,30 +209,30 @@ function buildWhereClause(filters: GetContractsFilters): {
|
||||||
|
|
||||||
const deceasedNameFilters = getDeceasedNameWhereClause(
|
const deceasedNameFilters = getDeceasedNameWhereClause(
|
||||||
filters.deceasedName,
|
filters.deceasedName,
|
||||||
'c'
|
'o'
|
||||||
)
|
)
|
||||||
if (deceasedNameFilters.sqlParameters.length > 0) {
|
if (deceasedNameFilters.sqlParameters.length > 0) {
|
||||||
sqlWhereClause += ` and c.contractId in (
|
sqlWhereClause += ` and o.contractId in (
|
||||||
select contractId from ContractInterments c
|
select contractId from ContractInterments o
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
${deceasedNameFilters.sqlWhereClause})`
|
${deceasedNameFilters.sqlWhereClause})`
|
||||||
sqlParameters.push(...deceasedNameFilters.sqlParameters)
|
sqlParameters.push(...deceasedNameFilters.sqlParameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((filters.contractTypeId ?? '') !== '') {
|
if ((filters.contractTypeId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and c.contractTypeId = ?'
|
sqlWhereClause += ' and o.contractTypeId = ?'
|
||||||
sqlParameters.push(filters.contractTypeId)
|
sqlParameters.push(filters.contractTypeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
const contractTimeFilters = getContractTimeWhereClause(
|
const contractTimeFilters = getContractTimeWhereClause(
|
||||||
filters.contractTime ?? '',
|
filters.contractTime ?? '',
|
||||||
'c'
|
'o'
|
||||||
)
|
)
|
||||||
sqlWhereClause += contractTimeFilters.sqlWhereClause
|
sqlWhereClause += contractTimeFilters.sqlWhereClause
|
||||||
sqlParameters.push(...contractTimeFilters.sqlParameters)
|
sqlParameters.push(...contractTimeFilters.sqlParameters)
|
||||||
|
|
||||||
if ((filters.contractStartDateString ?? '') !== '') {
|
if ((filters.contractStartDateString ?? '') !== '') {
|
||||||
sqlWhereClause += ' and c.contractStartDate = ?'
|
sqlWhereClause += ' and o.contractStartDate = ?'
|
||||||
sqlParameters.push(
|
sqlParameters.push(
|
||||||
dateStringToInteger(filters.contractStartDateString as DateString)
|
dateStringToInteger(filters.contractStartDateString as DateString)
|
||||||
)
|
)
|
||||||
|
|
@ -253,8 +240,8 @@ function buildWhereClause(filters: GetContractsFilters): {
|
||||||
|
|
||||||
if ((filters.contractEffectiveDateString ?? '') !== '') {
|
if ((filters.contractEffectiveDateString ?? '') !== '') {
|
||||||
sqlWhereClause += ` and (
|
sqlWhereClause += ` and (
|
||||||
c.contractEndDate is null
|
o.contractEndDate is null
|
||||||
or (c.contractStartDate <= ? and c.contractEndDate >= ?)
|
or (o.contractStartDate <= ? and o.contractEndDate >= ?)
|
||||||
)`
|
)`
|
||||||
sqlParameters.push(
|
sqlParameters.push(
|
||||||
dateStringToInteger(filters.contractEffectiveDateString as DateString),
|
dateStringToInteger(filters.contractEffectiveDateString as DateString),
|
||||||
|
|
@ -273,24 +260,19 @@ function buildWhereClause(filters: GetContractsFilters): {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((filters.funeralHomeId ?? '') !== '') {
|
if ((filters.funeralHomeId ?? '') !== '') {
|
||||||
sqlWhereClause += ' and c.funeralHomeId = ?'
|
sqlWhereClause += ' and o.funeralHomeId = ?'
|
||||||
sqlParameters.push(filters.funeralHomeId)
|
sqlParameters.push(filters.funeralHomeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((filters.funeralTime ?? '') === 'upcoming') {
|
|
||||||
sqlWhereClause += ' and c.funeralDate >= ?'
|
|
||||||
sqlParameters.push(dateToInteger(new Date()))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((filters.workOrderId ?? '') !== '') {
|
if ((filters.workOrderId ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
sqlWhereClause +=
|
||||||
' and c.contractId in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
|
' and o.contractId in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
|
||||||
sqlParameters.push(filters.workOrderId)
|
sqlParameters.push(filters.workOrderId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((filters.notWorkOrderId ?? '') !== '') {
|
if ((filters.notWorkOrderId ?? '') !== '') {
|
||||||
sqlWhereClause +=
|
sqlWhereClause +=
|
||||||
' and c.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
|
' and o.contractId not in (select contractId from WorkOrderContracts where recordDelete_timeMillis is null and workOrderId = ?)'
|
||||||
sqlParameters.push(filters.notWorkOrderId)
|
sqlParameters.push(filters.notWorkOrderId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ export default function getNextWorkOrderNumber(connectedDatabase) {
|
||||||
const database = connectedDatabase ?? sqlite(sunriseDB, { readonly: true });
|
const database = connectedDatabase ?? sqlite(sunriseDB, { readonly: true });
|
||||||
const paddingLength = getConfigProperty('settings.workOrders.workOrderNumberLength');
|
const paddingLength = getConfigProperty('settings.workOrders.workOrderNumberLength');
|
||||||
const currentYearString = new Date().getFullYear().toString();
|
const currentYearString = new Date().getFullYear().toString();
|
||||||
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
||||||
const regex = new RegExp(`^${currentYearString}-\\d+$`);
|
const regex = new RegExp(`^${currentYearString}-\\d+$`);
|
||||||
database.function(
|
database.function(
|
||||||
// eslint-disable-next-line no-secrets/no-secrets
|
// eslint-disable-next-line no-secrets/no-secrets
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ export default function getNextWorkOrderNumber(
|
||||||
)
|
)
|
||||||
const currentYearString = new Date().getFullYear().toString()
|
const currentYearString = new Date().getFullYear().toString()
|
||||||
|
|
||||||
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
||||||
const regex = new RegExp(`^${currentYearString}-\\d+$`)
|
const regex = new RegExp(`^${currentYearString}-\\d+$`)
|
||||||
|
|
||||||
database.function(
|
database.function(
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
import type { WorkOrderMilestoneType } from '../types/record.types.js';
|
import type { WorkOrderMilestoneType } from '../types/record.types.js';
|
||||||
export default function getWorkOrderMilestoneTypes(includeDeleted?: boolean): WorkOrderMilestoneType[];
|
export default function getWorkOrderMilestoneTypes(): WorkOrderMilestoneType[];
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,21 @@
|
||||||
import sqlite from 'better-sqlite3';
|
import sqlite from 'better-sqlite3';
|
||||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||||
export default function getWorkOrderMilestoneTypes(includeDeleted = false) {
|
export default function getWorkOrderMilestoneTypes() {
|
||||||
const database = sqlite(sunriseDB);
|
const database = sqlite(sunriseDB);
|
||||||
const updateOrderNumbers = !includeDeleted;
|
|
||||||
const workOrderMilestoneTypes = database
|
const workOrderMilestoneTypes = database
|
||||||
.prepare(`select workOrderMilestoneTypeId, workOrderMilestoneType, orderNumber
|
.prepare(`select workOrderMilestoneTypeId, workOrderMilestoneType, orderNumber
|
||||||
from WorkOrderMilestoneTypes
|
from WorkOrderMilestoneTypes
|
||||||
${includeDeleted ? '' : ' where recordDelete_timeMillis is null '}
|
where recordDelete_timeMillis is null
|
||||||
order by orderNumber, workOrderMilestoneType`)
|
order by orderNumber, workOrderMilestoneType`)
|
||||||
.all();
|
.all();
|
||||||
if (updateOrderNumbers) {
|
let expectedOrderNumber = 0;
|
||||||
let expectedOrderNumber = 0;
|
for (const workOrderMilestoneType of workOrderMilestoneTypes) {
|
||||||
for (const workOrderMilestoneType of workOrderMilestoneTypes) {
|
if (workOrderMilestoneType.orderNumber !== expectedOrderNumber) {
|
||||||
if (workOrderMilestoneType.orderNumber !== expectedOrderNumber) {
|
updateRecordOrderNumber('WorkOrderMilestoneTypes', workOrderMilestoneType.workOrderMilestoneTypeId, expectedOrderNumber, database);
|
||||||
updateRecordOrderNumber('WorkOrderMilestoneTypes', workOrderMilestoneType.workOrderMilestoneTypeId, expectedOrderNumber, database);
|
workOrderMilestoneType.orderNumber = expectedOrderNumber;
|
||||||
workOrderMilestoneType.orderNumber = expectedOrderNumber;
|
|
||||||
}
|
|
||||||
expectedOrderNumber += 1;
|
|
||||||
}
|
}
|
||||||
|
expectedOrderNumber += 1;
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
return workOrderMilestoneTypes;
|
return workOrderMilestoneTypes;
|
||||||
|
|
|
||||||
|
|
@ -5,39 +5,33 @@ import type { WorkOrderMilestoneType } from '../types/record.types.js'
|
||||||
|
|
||||||
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
||||||
|
|
||||||
export default function getWorkOrderMilestoneTypes(
|
export default function getWorkOrderMilestoneTypes(): WorkOrderMilestoneType[] {
|
||||||
includeDeleted = false
|
|
||||||
): WorkOrderMilestoneType[] {
|
|
||||||
const database = sqlite(sunriseDB)
|
const database = sqlite(sunriseDB)
|
||||||
|
|
||||||
const updateOrderNumbers = !includeDeleted
|
|
||||||
|
|
||||||
const workOrderMilestoneTypes = database
|
const workOrderMilestoneTypes = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select workOrderMilestoneTypeId, workOrderMilestoneType, orderNumber
|
`select workOrderMilestoneTypeId, workOrderMilestoneType, orderNumber
|
||||||
from WorkOrderMilestoneTypes
|
from WorkOrderMilestoneTypes
|
||||||
${includeDeleted ? '' : ' where recordDelete_timeMillis is null '}
|
where recordDelete_timeMillis is null
|
||||||
order by orderNumber, workOrderMilestoneType`
|
order by orderNumber, workOrderMilestoneType`
|
||||||
)
|
)
|
||||||
.all() as WorkOrderMilestoneType[]
|
.all() as WorkOrderMilestoneType[]
|
||||||
|
|
||||||
if (updateOrderNumbers) {
|
let expectedOrderNumber = 0
|
||||||
let expectedOrderNumber = 0
|
|
||||||
|
|
||||||
for (const workOrderMilestoneType of workOrderMilestoneTypes) {
|
for (const workOrderMilestoneType of workOrderMilestoneTypes) {
|
||||||
if (workOrderMilestoneType.orderNumber !== expectedOrderNumber) {
|
if (workOrderMilestoneType.orderNumber !== expectedOrderNumber) {
|
||||||
updateRecordOrderNumber(
|
updateRecordOrderNumber(
|
||||||
'WorkOrderMilestoneTypes',
|
'WorkOrderMilestoneTypes',
|
||||||
workOrderMilestoneType.workOrderMilestoneTypeId,
|
workOrderMilestoneType.workOrderMilestoneTypeId,
|
||||||
expectedOrderNumber,
|
expectedOrderNumber,
|
||||||
database
|
database
|
||||||
)
|
)
|
||||||
|
|
||||||
workOrderMilestoneType.orderNumber = expectedOrderNumber
|
workOrderMilestoneType.orderNumber = expectedOrderNumber
|
||||||
}
|
|
||||||
|
|
||||||
expectedOrderNumber += 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expectedOrderNumber += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
database.close()
|
database.close()
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,9 @@ export async function getWorkOrders(filters, options, connectedDatabase) {
|
||||||
const { sqlParameters, sqlWhereClause } = buildWhereClause(filters);
|
const { sqlParameters, sqlWhereClause } = buildWhereClause(filters);
|
||||||
const count = database
|
const count = database
|
||||||
.prepare(`select count(*) as recordCount
|
.prepare(`select count(*) as recordCount
|
||||||
from WorkOrders w
|
from WorkOrders w
|
||||||
${sqlWhereClause}`)
|
${sqlWhereClause}`)
|
||||||
.pluck()
|
.get(sqlParameters).recordCount;
|
||||||
.get(sqlParameters);
|
|
||||||
let workOrders = [];
|
let workOrders = [];
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
workOrders = database
|
workOrders = database
|
||||||
|
|
|
||||||
|
|
@ -48,14 +48,15 @@ export async function getWorkOrders(
|
||||||
|
|
||||||
const { sqlParameters, sqlWhereClause } = buildWhereClause(filters)
|
const { sqlParameters, sqlWhereClause } = buildWhereClause(filters)
|
||||||
|
|
||||||
const count: number = database
|
const count: number = (
|
||||||
.prepare(
|
database
|
||||||
`select count(*) as recordCount
|
.prepare(
|
||||||
from WorkOrders w
|
`select count(*) as recordCount
|
||||||
${sqlWhereClause}`
|
from WorkOrders w
|
||||||
)
|
${sqlWhereClause}`
|
||||||
.pluck()
|
)
|
||||||
.get(sqlParameters) as number
|
.get(sqlParameters) as { recordCount: number }
|
||||||
|
).recordCount
|
||||||
|
|
||||||
let workOrders: WorkOrder[] = []
|
let workOrders: WorkOrder[] = []
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
|
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
|
||||||
/* eslint-disable @typescript-eslint/no-magic-numbers, max-lines, no-secrets/no-secrets */
|
/* eslint-disable max-lines, no-secrets/no-secrets */
|
||||||
import sqlite from 'better-sqlite3';
|
import sqlite from 'better-sqlite3';
|
||||||
import Debug from 'debug';
|
import Debug from 'debug';
|
||||||
import { DEBUG_NAMESPACE } from '../debug.config.js';
|
import { DEBUG_NAMESPACE } from '../debug.config.js';
|
||||||
import { sunriseDB as databasePath } from '../helpers/database.helpers.js';
|
import { sunriseDB as databasePath } from '../helpers/database.helpers.js';
|
||||||
import addBurialSiteType from './addBurialSiteType.js';
|
|
||||||
import addCommittalType from './addCommittalType.js';
|
import addCommittalType from './addCommittalType.js';
|
||||||
import addContractType from './addContractType.js';
|
import addContractType from './addContractType.js';
|
||||||
import addFeeCategory from './addFeeCategory.js';
|
import addFeeCategory from './addFeeCategory.js';
|
||||||
|
|
@ -24,8 +23,6 @@ const createStatements = [
|
||||||
`create table if not exists BurialSiteTypes (
|
`create table if not exists BurialSiteTypes (
|
||||||
burialSiteTypeId integer not null primary key autoincrement,
|
burialSiteTypeId integer not null primary key autoincrement,
|
||||||
burialSiteType varchar(100) not null,
|
burialSiteType varchar(100) not null,
|
||||||
bodyCapacityMax smallint,
|
|
||||||
crematedCapacityMax smallint,
|
|
||||||
orderNumber smallint not null default 0,
|
orderNumber smallint not null default 0,
|
||||||
${recordColumns})`,
|
${recordColumns})`,
|
||||||
`create index if not exists idx_BurialSiteTypes_orderNumber
|
`create index if not exists idx_BurialSiteTypes_orderNumber
|
||||||
|
|
@ -97,9 +94,6 @@ const createStatements = [
|
||||||
burialSiteNameSegment5 varchar(20) not null,
|
burialSiteNameSegment5 varchar(20) not null,
|
||||||
burialSiteName varchar(200) not null,
|
burialSiteName varchar(200) not null,
|
||||||
|
|
||||||
bodyCapacity smallint,
|
|
||||||
crematedCapacity smallint,
|
|
||||||
|
|
||||||
cemeteryId integer,
|
cemeteryId integer,
|
||||||
cemeterySvgId varchar(100),
|
cemeterySvgId varchar(100),
|
||||||
burialSiteImage varchar(100) not null default '',
|
burialSiteImage varchar(100) not null default '',
|
||||||
|
|
@ -418,42 +412,12 @@ export function initializeDatabase() {
|
||||||
}
|
}
|
||||||
function initializeData() {
|
function initializeData() {
|
||||||
debug('Initializing data...');
|
debug('Initializing data...');
|
||||||
addBurialSiteType({
|
addRecord('BurialSiteTypes', 'Casket Grave', 1, initializingUser);
|
||||||
burialSiteType: 'In-Ground Grave',
|
addRecord('BurialSiteTypes', 'Columbarium', 2, initializingUser);
|
||||||
bodyCapacityMax: 2,
|
addRecord('BurialSiteTypes', 'Mausoleum', 2, initializingUser);
|
||||||
crematedCapacityMax: 6,
|
addRecord('BurialSiteTypes', 'Niche Wall', 2, initializingUser);
|
||||||
orderNumber: 1
|
addRecord('BurialSiteTypes', 'Urn Garden', 2, initializingUser);
|
||||||
}, initializingUser);
|
addRecord('BurialSiteTypes', 'Crematorium', 2, initializingUser);
|
||||||
addBurialSiteType({
|
|
||||||
burialSiteType: 'Columbarium',
|
|
||||||
bodyCapacityMax: 0,
|
|
||||||
crematedCapacityMax: '',
|
|
||||||
orderNumber: 2
|
|
||||||
}, initializingUser);
|
|
||||||
addBurialSiteType({
|
|
||||||
burialSiteType: 'Mausoleum',
|
|
||||||
bodyCapacityMax: 2,
|
|
||||||
crematedCapacityMax: 0,
|
|
||||||
orderNumber: 2
|
|
||||||
}, initializingUser);
|
|
||||||
addBurialSiteType({
|
|
||||||
burialSiteType: 'Niche Wall',
|
|
||||||
bodyCapacityMax: 0,
|
|
||||||
crematedCapacityMax: 1,
|
|
||||||
orderNumber: 2
|
|
||||||
}, initializingUser);
|
|
||||||
addBurialSiteType({
|
|
||||||
burialSiteType: 'Urn Garden',
|
|
||||||
bodyCapacityMax: 0,
|
|
||||||
crematedCapacityMax: 1,
|
|
||||||
orderNumber: 2
|
|
||||||
}, initializingUser);
|
|
||||||
addBurialSiteType({
|
|
||||||
burialSiteType: 'Crematorium',
|
|
||||||
bodyCapacityMax: 0,
|
|
||||||
crematedCapacityMax: 1,
|
|
||||||
orderNumber: 2
|
|
||||||
}, initializingUser);
|
|
||||||
addRecord('BurialSiteStatuses', 'Available', 1, initializingUser);
|
addRecord('BurialSiteStatuses', 'Available', 1, initializingUser);
|
||||||
addRecord('BurialSiteStatuses', 'Reserved', 2, initializingUser);
|
addRecord('BurialSiteStatuses', 'Reserved', 2, initializingUser);
|
||||||
addRecord('BurialSiteStatuses', 'Taken', 3, initializingUser);
|
addRecord('BurialSiteStatuses', 'Taken', 3, initializingUser);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
|
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
|
||||||
/* eslint-disable @typescript-eslint/no-magic-numbers, max-lines, no-secrets/no-secrets */
|
/* eslint-disable max-lines, no-secrets/no-secrets */
|
||||||
|
|
||||||
import sqlite from 'better-sqlite3'
|
import sqlite from 'better-sqlite3'
|
||||||
import Debug from 'debug'
|
import Debug from 'debug'
|
||||||
|
|
@ -7,7 +7,6 @@ import Debug from 'debug'
|
||||||
import { DEBUG_NAMESPACE } from '../debug.config.js'
|
import { DEBUG_NAMESPACE } from '../debug.config.js'
|
||||||
import { sunriseDB as databasePath } from '../helpers/database.helpers.js'
|
import { sunriseDB as databasePath } from '../helpers/database.helpers.js'
|
||||||
|
|
||||||
import addBurialSiteType from './addBurialSiteType.js'
|
|
||||||
import addCommittalType from './addCommittalType.js'
|
import addCommittalType from './addCommittalType.js'
|
||||||
import addContractType from './addContractType.js'
|
import addContractType from './addContractType.js'
|
||||||
import addFeeCategory from './addFeeCategory.js'
|
import addFeeCategory from './addFeeCategory.js'
|
||||||
|
|
@ -31,8 +30,6 @@ const createStatements = [
|
||||||
`create table if not exists BurialSiteTypes (
|
`create table if not exists BurialSiteTypes (
|
||||||
burialSiteTypeId integer not null primary key autoincrement,
|
burialSiteTypeId integer not null primary key autoincrement,
|
||||||
burialSiteType varchar(100) not null,
|
burialSiteType varchar(100) not null,
|
||||||
bodyCapacityMax smallint,
|
|
||||||
crematedCapacityMax smallint,
|
|
||||||
orderNumber smallint not null default 0,
|
orderNumber smallint not null default 0,
|
||||||
${recordColumns})`,
|
${recordColumns})`,
|
||||||
|
|
||||||
|
|
@ -115,9 +112,6 @@ const createStatements = [
|
||||||
burialSiteNameSegment5 varchar(20) not null,
|
burialSiteNameSegment5 varchar(20) not null,
|
||||||
burialSiteName varchar(200) not null,
|
burialSiteName varchar(200) not null,
|
||||||
|
|
||||||
bodyCapacity smallint,
|
|
||||||
crematedCapacity smallint,
|
|
||||||
|
|
||||||
cemeteryId integer,
|
cemeteryId integer,
|
||||||
cemeterySvgId varchar(100),
|
cemeterySvgId varchar(100),
|
||||||
burialSiteImage varchar(100) not null default '',
|
burialSiteImage varchar(100) not null default '',
|
||||||
|
|
@ -488,71 +482,12 @@ export function initializeDatabase(): boolean {
|
||||||
function initializeData(): void {
|
function initializeData(): void {
|
||||||
debug('Initializing data...')
|
debug('Initializing data...')
|
||||||
|
|
||||||
addBurialSiteType(
|
addRecord('BurialSiteTypes', 'Casket Grave', 1, initializingUser)
|
||||||
{
|
addRecord('BurialSiteTypes', 'Columbarium', 2, initializingUser)
|
||||||
burialSiteType: 'In-Ground Grave',
|
addRecord('BurialSiteTypes', 'Mausoleum', 2, initializingUser)
|
||||||
|
addRecord('BurialSiteTypes', 'Niche Wall', 2, initializingUser)
|
||||||
bodyCapacityMax: 2,
|
addRecord('BurialSiteTypes', 'Urn Garden', 2, initializingUser)
|
||||||
crematedCapacityMax: 6,
|
addRecord('BurialSiteTypes', 'Crematorium', 2, initializingUser)
|
||||||
orderNumber: 1
|
|
||||||
},
|
|
||||||
initializingUser
|
|
||||||
)
|
|
||||||
|
|
||||||
addBurialSiteType(
|
|
||||||
{
|
|
||||||
burialSiteType: 'Columbarium',
|
|
||||||
|
|
||||||
bodyCapacityMax: 0,
|
|
||||||
crematedCapacityMax: '',
|
|
||||||
orderNumber: 2
|
|
||||||
},
|
|
||||||
initializingUser
|
|
||||||
)
|
|
||||||
|
|
||||||
addBurialSiteType(
|
|
||||||
{
|
|
||||||
burialSiteType: 'Mausoleum',
|
|
||||||
|
|
||||||
bodyCapacityMax: 2,
|
|
||||||
crematedCapacityMax: 0,
|
|
||||||
orderNumber: 2
|
|
||||||
},
|
|
||||||
initializingUser
|
|
||||||
)
|
|
||||||
|
|
||||||
addBurialSiteType(
|
|
||||||
{
|
|
||||||
burialSiteType: 'Niche Wall',
|
|
||||||
|
|
||||||
bodyCapacityMax: 0,
|
|
||||||
crematedCapacityMax: 1,
|
|
||||||
orderNumber: 2
|
|
||||||
},
|
|
||||||
initializingUser
|
|
||||||
)
|
|
||||||
|
|
||||||
addBurialSiteType(
|
|
||||||
{
|
|
||||||
burialSiteType: 'Urn Garden',
|
|
||||||
|
|
||||||
bodyCapacityMax: 0,
|
|
||||||
crematedCapacityMax: 1,
|
|
||||||
orderNumber: 2
|
|
||||||
},
|
|
||||||
initializingUser
|
|
||||||
)
|
|
||||||
|
|
||||||
addBurialSiteType(
|
|
||||||
{
|
|
||||||
burialSiteType: 'Crematorium',
|
|
||||||
|
|
||||||
bodyCapacityMax: 0,
|
|
||||||
crematedCapacityMax: 1,
|
|
||||||
orderNumber: 2
|
|
||||||
},
|
|
||||||
initializingUser
|
|
||||||
)
|
|
||||||
|
|
||||||
addRecord('BurialSiteStatuses', 'Available', 1, initializingUser)
|
addRecord('BurialSiteStatuses', 'Available', 1, initializingUser)
|
||||||
addRecord('BurialSiteStatuses', 'Reserved', 2, initializingUser)
|
addRecord('BurialSiteStatuses', 'Reserved', 2, initializingUser)
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ export default function reopenWorkOrder(workOrderId, user) {
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update WorkOrders
|
.prepare(`update WorkOrders
|
||||||
set workOrderCloseDate = null,
|
set workOrderCloseDate = null,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and workOrderCloseDate is not null`)
|
and workOrderCloseDate is not null`)
|
||||||
.run(user.userName, Date.now(), workOrderId);
|
.run(user.userName, Date.now(), workOrderId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ export default function reopenWorkOrder(
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrders
|
`update WorkOrders
|
||||||
set workOrderCloseDate = null,
|
set workOrderCloseDate = null,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and workOrderCloseDate is not null`
|
and workOrderCloseDate is not null`
|
||||||
)
|
)
|
||||||
.run(user.userName, Date.now(), workOrderId)
|
.run(user.userName, Date.now(), workOrderId)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export declare function restoreBurialSite(burialSiteId: number, user: User): boolean;
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
@ -7,8 +7,6 @@ export interface UpdateBurialSiteForm {
|
||||||
burialSiteNameSegment5?: string;
|
burialSiteNameSegment5?: string;
|
||||||
burialSiteStatusId: number | string;
|
burialSiteStatusId: number | string;
|
||||||
burialSiteTypeId: number | string;
|
burialSiteTypeId: number | string;
|
||||||
bodyCapacity?: number | string;
|
|
||||||
crematedCapacity?: number | string;
|
|
||||||
burialSiteImage: string;
|
burialSiteImage: string;
|
||||||
cemeteryId: number | string;
|
cemeteryId: number | string;
|
||||||
cemeterySvgId: string;
|
cemeterySvgId: string;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import getCemetery from './getCemetery.js';
|
||||||
* @returns True if the burial site was updated.
|
* @returns True if the burial site was updated.
|
||||||
* @throws If an active burial site with the same name already exists.
|
* @throws If an active burial site with the same name already exists.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line complexity
|
|
||||||
export default function updateBurialSite(updateForm, user) {
|
export default function updateBurialSite(updateForm, user) {
|
||||||
const database = sqlite(sunriseDB);
|
const database = sqlite(sunriseDB);
|
||||||
const cemetery = updateForm.cemeteryId === ''
|
const cemetery = updateForm.cemeteryId === ''
|
||||||
|
|
@ -34,29 +33,25 @@ export default function updateBurialSite(updateForm, user) {
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update BurialSites
|
.prepare(`update BurialSites
|
||||||
set burialSiteNameSegment1 = ?,
|
set burialSiteNameSegment1 = ?,
|
||||||
burialSiteNameSegment2 = ?,
|
burialSiteNameSegment2 = ?,
|
||||||
burialSiteNameSegment3 = ?,
|
burialSiteNameSegment3 = ?,
|
||||||
burialSiteNameSegment4 = ?,
|
burialSiteNameSegment4 = ?,
|
||||||
burialSiteNameSegment5 = ?,
|
burialSiteNameSegment5 = ?,
|
||||||
burialSiteName = ?,
|
burialSiteName = ?,
|
||||||
burialSiteTypeId = ?,
|
burialSiteTypeId = ?,
|
||||||
burialSiteStatusId = ?,
|
burialSiteStatusId = ?,
|
||||||
bodyCapacity = ?,
|
cemeteryId = ?,
|
||||||
crematedCapacity = ?,
|
cemeterySvgId = ?,
|
||||||
cemeteryId = ?,
|
burialSiteImage = ?,
|
||||||
cemeterySvgId = ?,
|
burialSiteLatitude = ?,
|
||||||
burialSiteImage = ?,
|
burialSiteLongitude = ?,
|
||||||
burialSiteLatitude = ?,
|
recordUpdate_userName = ?,
|
||||||
burialSiteLongitude = ?,
|
recordUpdate_timeMillis = ?
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and recordDelete_timeMillis is null`)
|
and recordDelete_timeMillis is null`)
|
||||||
.run(updateForm.burialSiteNameSegment1 ?? '', updateForm.burialSiteNameSegment2 ?? '', updateForm.burialSiteNameSegment3 ?? '', updateForm.burialSiteNameSegment4 ?? '', updateForm.burialSiteNameSegment5 ?? '', burialSiteName, updateForm.burialSiteTypeId, updateForm.burialSiteStatusId === ''
|
.run(updateForm.burialSiteNameSegment1 ?? '', updateForm.burialSiteNameSegment2 ?? '', updateForm.burialSiteNameSegment3 ?? '', updateForm.burialSiteNameSegment4 ?? '', updateForm.burialSiteNameSegment5 ?? '', burialSiteName, updateForm.burialSiteTypeId, updateForm.burialSiteStatusId === ''
|
||||||
? undefined
|
? undefined
|
||||||
: updateForm.burialSiteStatusId, updateForm.bodyCapacity === '' ? undefined : updateForm.bodyCapacity, updateForm.crematedCapacity === ''
|
: updateForm.burialSiteStatusId, updateForm.cemeteryId === '' ? undefined : updateForm.cemeteryId, updateForm.cemeterySvgId, updateForm.burialSiteImage, updateForm.burialSiteLatitude === ''
|
||||||
? undefined
|
|
||||||
: updateForm.crematedCapacity, updateForm.cemeteryId === '' ? undefined : updateForm.cemeteryId, updateForm.cemeterySvgId, updateForm.burialSiteImage, updateForm.burialSiteLatitude === ''
|
|
||||||
? undefined
|
? undefined
|
||||||
: updateForm.burialSiteLatitude, updateForm.burialSiteLongitude === ''
|
: updateForm.burialSiteLatitude, updateForm.burialSiteLongitude === ''
|
||||||
? undefined
|
? undefined
|
||||||
|
|
@ -83,10 +78,10 @@ export function updateBurialSiteStatus(burialSiteId, burialSiteStatusId, user) {
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update BurialSites
|
.prepare(`update BurialSites
|
||||||
set burialSiteStatusId = ?,
|
set burialSiteStatusId = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and recordDelete_timeMillis is null`)
|
and recordDelete_timeMillis is null`)
|
||||||
.run(burialSiteStatusId === '' ? undefined : burialSiteStatusId, user.userName, rightNowMillis, burialSiteId);
|
.run(burialSiteStatusId === '' ? undefined : burialSiteStatusId, user.userName, rightNowMillis, burialSiteId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,6 @@ export interface UpdateBurialSiteForm {
|
||||||
burialSiteStatusId: number | string
|
burialSiteStatusId: number | string
|
||||||
burialSiteTypeId: number | string
|
burialSiteTypeId: number | string
|
||||||
|
|
||||||
bodyCapacity?: number | string
|
|
||||||
crematedCapacity?: number | string
|
|
||||||
|
|
||||||
burialSiteImage: string
|
burialSiteImage: string
|
||||||
cemeteryId: number | string
|
cemeteryId: number | string
|
||||||
cemeterySvgId: string
|
cemeterySvgId: string
|
||||||
|
|
@ -40,7 +37,6 @@ export interface UpdateBurialSiteForm {
|
||||||
* @returns True if the burial site was updated.
|
* @returns True if the burial site was updated.
|
||||||
* @throws If an active burial site with the same name already exists.
|
* @throws If an active burial site with the same name already exists.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line complexity
|
|
||||||
export default function updateBurialSite(
|
export default function updateBurialSite(
|
||||||
updateForm: UpdateBurialSiteForm,
|
updateForm: UpdateBurialSiteForm,
|
||||||
user: User
|
user: User
|
||||||
|
|
@ -76,24 +72,22 @@ export default function updateBurialSite(
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSites
|
`update BurialSites
|
||||||
set burialSiteNameSegment1 = ?,
|
set burialSiteNameSegment1 = ?,
|
||||||
burialSiteNameSegment2 = ?,
|
burialSiteNameSegment2 = ?,
|
||||||
burialSiteNameSegment3 = ?,
|
burialSiteNameSegment3 = ?,
|
||||||
burialSiteNameSegment4 = ?,
|
burialSiteNameSegment4 = ?,
|
||||||
burialSiteNameSegment5 = ?,
|
burialSiteNameSegment5 = ?,
|
||||||
burialSiteName = ?,
|
burialSiteName = ?,
|
||||||
burialSiteTypeId = ?,
|
burialSiteTypeId = ?,
|
||||||
burialSiteStatusId = ?,
|
burialSiteStatusId = ?,
|
||||||
bodyCapacity = ?,
|
cemeteryId = ?,
|
||||||
crematedCapacity = ?,
|
cemeterySvgId = ?,
|
||||||
cemeteryId = ?,
|
burialSiteImage = ?,
|
||||||
cemeterySvgId = ?,
|
burialSiteLatitude = ?,
|
||||||
burialSiteImage = ?,
|
burialSiteLongitude = ?,
|
||||||
burialSiteLatitude = ?,
|
recordUpdate_userName = ?,
|
||||||
burialSiteLongitude = ?,
|
recordUpdate_timeMillis = ?
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
updateForm.burialSiteNameSegment1 ?? '',
|
updateForm.burialSiteNameSegment1 ?? '',
|
||||||
|
|
@ -106,13 +100,6 @@ export default function updateBurialSite(
|
||||||
updateForm.burialSiteStatusId === ''
|
updateForm.burialSiteStatusId === ''
|
||||||
? undefined
|
? undefined
|
||||||
: updateForm.burialSiteStatusId,
|
: updateForm.burialSiteStatusId,
|
||||||
|
|
||||||
updateForm.bodyCapacity === '' ? undefined : updateForm.bodyCapacity,
|
|
||||||
|
|
||||||
updateForm.crematedCapacity === ''
|
|
||||||
? undefined
|
|
||||||
: updateForm.crematedCapacity,
|
|
||||||
|
|
||||||
updateForm.cemeteryId === '' ? undefined : updateForm.cemeteryId,
|
updateForm.cemeteryId === '' ? undefined : updateForm.cemeteryId,
|
||||||
updateForm.cemeterySvgId,
|
updateForm.cemeterySvgId,
|
||||||
updateForm.burialSiteImage,
|
updateForm.burialSiteImage,
|
||||||
|
|
@ -174,10 +161,10 @@ export function updateBurialSiteStatus(
|
||||||
.prepare(
|
.prepare(
|
||||||
`update BurialSites
|
`update BurialSites
|
||||||
set burialSiteStatusId = ?,
|
set burialSiteStatusId = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where burialSiteId = ?
|
where burialSiteId = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
burialSiteStatusId === '' ? undefined : burialSiteStatusId,
|
burialSiteStatusId === '' ? undefined : burialSiteStatusId,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
export interface UpdateBurialSiteTypeForm {
|
|
||||||
burialSiteTypeId: number | string;
|
|
||||||
burialSiteType: string;
|
|
||||||
bodyCapacityMax: number | string;
|
|
||||||
crematedCapacityMax: number | string;
|
|
||||||
}
|
|
||||||
export default function updateBurialSiteType(updateForm: UpdateBurialSiteTypeForm, user: User): boolean;
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue