remove better-sqlite-pool
parent
38c1288856
commit
4f6fc87e05
|
|
@ -21,4 +21,4 @@ export interface AddBurialSiteForm {
|
|||
* @returns The new burial site's id.
|
||||
* @throws If an active burial site with the same name already exists.
|
||||
*/
|
||||
export default function addBurialSite(burialSiteForm: AddBurialSiteForm, user: User): Promise<number>;
|
||||
export default function addBurialSite(burialSiteForm: AddBurialSiteForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import sqlite from 'better-sqlite3';
|
||||
import { buildBurialSiteName } from '../helpers/burialSites.helpers.js';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import addOrUpdateBurialSiteField from './addOrUpdateBurialSiteField.js';
|
||||
import getCemetery from './getCemetery.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
/**
|
||||
* Creates a new burial site.
|
||||
* @param burialSiteForm - The new burial site's information
|
||||
|
|
@ -9,12 +10,12 @@ import { acquireConnection } from './pool.js';
|
|||
* @returns The new burial site's id.
|
||||
* @throws If an active burial site with the same name already exists.
|
||||
*/
|
||||
export default async function addBurialSite(burialSiteForm, user) {
|
||||
const database = await acquireConnection();
|
||||
export default function addBurialSite(burialSiteForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const cemetery = burialSiteForm.cemeteryId === ''
|
||||
? undefined
|
||||
: await getCemetery(burialSiteForm.cemeteryId, database);
|
||||
: getCemetery(burialSiteForm.cemeteryId, database);
|
||||
const burialSiteName = buildBurialSiteName(cemetery?.cemeteryKey, burialSiteForm);
|
||||
// Ensure no active burial sites share the same name
|
||||
const existingBurialSite = database
|
||||
|
|
@ -25,7 +26,7 @@ export default async function addBurialSite(burialSiteForm, user) {
|
|||
.pluck()
|
||||
.get(burialSiteName);
|
||||
if (existingBurialSite !== undefined) {
|
||||
database.release();
|
||||
database.close();
|
||||
throw new Error('An active burial site with that name already exists.');
|
||||
}
|
||||
const result = database
|
||||
|
|
@ -57,13 +58,13 @@ export default async function addBurialSite(burialSiteForm, user) {
|
|||
for (const burialSiteTypeFieldId of burialSiteTypeFieldIds) {
|
||||
const fieldValue = burialSiteForm[`burialSiteFieldValue_${burialSiteTypeFieldId}`];
|
||||
if ((fieldValue ?? '') !== '') {
|
||||
await addOrUpdateBurialSiteField({
|
||||
addOrUpdateBurialSiteField({
|
||||
burialSiteId,
|
||||
burialSiteTypeFieldId,
|
||||
fieldValue: fieldValue ?? ''
|
||||
}, user, database);
|
||||
}
|
||||
}
|
||||
database.release();
|
||||
database.close();
|
||||
return burialSiteId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { buildBurialSiteName } from '../helpers/burialSites.helpers.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
import addOrUpdateBurialSiteField from './addOrUpdateBurialSiteField.js'
|
||||
import getCemetery from './getCemetery.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddBurialSiteForm {
|
||||
burialSiteNameSegment1?: string
|
||||
|
|
@ -33,18 +35,18 @@ export interface AddBurialSiteForm {
|
|||
* @returns The new burial site's id.
|
||||
* @throws If an active burial site with the same name already exists.
|
||||
*/
|
||||
export default async function addBurialSite(
|
||||
export default function addBurialSite(
|
||||
burialSiteForm: AddBurialSiteForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
const cemetery =
|
||||
burialSiteForm.cemeteryId === ''
|
||||
? undefined
|
||||
: await getCemetery(burialSiteForm.cemeteryId, database)
|
||||
: getCemetery(burialSiteForm.cemeteryId, database)
|
||||
|
||||
const burialSiteName = buildBurialSiteName(
|
||||
cemetery?.cemeteryKey,
|
||||
|
|
@ -64,7 +66,7 @@ export default async function addBurialSite(
|
|||
.get(burialSiteName) as number | undefined
|
||||
|
||||
if (existingBurialSite !== undefined) {
|
||||
database.release()
|
||||
database.close()
|
||||
throw new Error('An active burial site with that name already exists.')
|
||||
}
|
||||
|
||||
|
|
@ -125,7 +127,7 @@ export default async function addBurialSite(
|
|||
] as string | undefined
|
||||
|
||||
if ((fieldValue ?? '') !== '') {
|
||||
await addOrUpdateBurialSiteField(
|
||||
addOrUpdateBurialSiteField(
|
||||
{
|
||||
burialSiteId,
|
||||
burialSiteTypeFieldId,
|
||||
|
|
@ -137,7 +139,7 @@ export default async function addBurialSite(
|
|||
}
|
||||
}
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return burialSiteId
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ export interface AddBurialSiteCommentForm {
|
|||
burialSiteId: string;
|
||||
comment: string;
|
||||
}
|
||||
export default function addBurialSiteComment(commentForm: AddBurialSiteCommentForm, user: User): Promise<number>;
|
||||
export default function addBurialSiteComment(commentForm: AddBurialSiteCommentForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { dateToInteger, dateToTimeInteger } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addBurialSiteComment(commentForm, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addBurialSiteComment(commentForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNow = new Date();
|
||||
const result = database
|
||||
.prepare(`insert into BurialSiteComments (
|
||||
|
|
@ -11,6 +12,6 @@ export default async function addBurialSiteComment(commentForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(commentForm.burialSiteId, dateToInteger(rightNow), dateToTimeInteger(rightNow), commentForm.comment, user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
|
||||
database.release();
|
||||
database.close();
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
import { dateToInteger, dateToTimeInteger } from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddBurialSiteCommentForm {
|
||||
burialSiteId: string
|
||||
comment: string
|
||||
}
|
||||
|
||||
export default async function addBurialSiteComment(
|
||||
export default function addBurialSiteComment(
|
||||
commentForm: AddBurialSiteCommentForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNow = new Date()
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ export default async function addBurialSiteComment(
|
|||
rightNow.getTime()
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return result.lastInsertRowid as number
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ export interface AddBurialSiteTypeFieldForm {
|
|||
fieldType?: string;
|
||||
fieldValues?: string;
|
||||
isRequired?: string;
|
||||
pattern?: string;
|
||||
minLength?: number | string;
|
||||
maxLength?: number | string;
|
||||
minLength?: number | string;
|
||||
pattern?: string;
|
||||
orderNumber?: number;
|
||||
}
|
||||
export default function addBurialSiteTypeField(addForm: AddBurialSiteTypeFieldForm, user: User): Promise<number>;
|
||||
export default function addBurialSiteTypeField(addForm: AddBurialSiteTypeFieldForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addBurialSiteTypeField(addForm, user) {
|
||||
const database = await acquireConnection();
|
||||
export default function addBurialSiteTypeField(addForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into BurialSiteTypeFields (
|
||||
|
|
@ -14,7 +15,7 @@ export default async function addBurialSiteTypeField(addForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.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);
|
||||
database.release();
|
||||
database.close();
|
||||
clearCacheByTableName('BurialSiteTypeFields');
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,29 @@
|
|||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
|
||||
export interface AddBurialSiteTypeFieldForm {
|
||||
burialSiteTypeId: number | string
|
||||
|
||||
burialSiteTypeField: string
|
||||
|
||||
fieldType?: string
|
||||
fieldValues?: string
|
||||
|
||||
isRequired?: string
|
||||
pattern?: string
|
||||
minLength?: number | string
|
||||
maxLength?: number | string
|
||||
minLength?: number | string
|
||||
pattern?: string
|
||||
|
||||
orderNumber?: number
|
||||
}
|
||||
|
||||
export default async function addBurialSiteTypeField(
|
||||
export default function addBurialSiteTypeField(
|
||||
addForm: AddBurialSiteTypeFieldForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -50,7 +55,7 @@ export default async function addBurialSiteTypeField(
|
|||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
clearCacheByTableName('BurialSiteTypeFields')
|
||||
|
||||
|
|
|
|||
|
|
@ -13,4 +13,4 @@ export interface AddCemeteryForm {
|
|||
cemeteryProvince: string;
|
||||
cemeteryPhoneNumber: string;
|
||||
}
|
||||
export default function addCemetery(addForm: AddCemeteryForm, user: User): Promise<number>;
|
||||
export default function addCemetery(addForm: AddCemeteryForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function addCemetery(addForm, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addCemetery(addForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into Cemeteries (
|
||||
|
|
@ -14,6 +15,6 @@ export default async function addCemetery(addForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(addForm.cemeteryName, addForm.cemeteryKey, addForm.cemeteryDescription, addForm.cemeterySvg, addForm.cemeteryLatitude === '' ? undefined : addForm.cemeteryLatitude, addForm.cemeteryLongitude === '' ? undefined : addForm.cemeteryLongitude, addForm.cemeteryAddress1, addForm.cemeteryAddress2, addForm.cemeteryCity, addForm.cemeteryProvince, addForm.cemeteryPostalCode, addForm.cemeteryPhoneNumber, addForm.parentCemeteryId === '' ? undefined : addForm.parentCemeteryId, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
database.close();
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
import { acquireConnection } from './pool.js'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddCemeteryForm {
|
||||
cemeteryDescription: string
|
||||
|
|
@ -19,11 +21,11 @@ export interface AddCemeteryForm {
|
|||
cemeteryPhoneNumber: string
|
||||
}
|
||||
|
||||
export default async function addCemetery(
|
||||
export default function addCemetery(
|
||||
addForm: AddCemeteryForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -60,7 +62,7 @@ export default async function addCemetery(
|
|||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return result.lastInsertRowid as number
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@ export interface AddForm {
|
|||
committalTypeKey?: string;
|
||||
orderNumber?: number;
|
||||
}
|
||||
export default function addCommittalType(addForm: AddForm, user: User): Promise<number>;
|
||||
export default function addCommittalType(addForm: AddForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addCommittalType(addForm, user) {
|
||||
const database = await acquireConnection();
|
||||
export default function addCommittalType(addForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into CommittalTypes (
|
||||
|
|
@ -10,7 +11,7 @@ export default async function addCommittalType(addForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(addForm.committalType, addForm.committalTypeKey ?? '', addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
database.close();
|
||||
clearCacheByTableName('CommittalTypes');
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
|
||||
export interface AddForm {
|
||||
committalType: string
|
||||
|
|
@ -8,11 +9,8 @@ export interface AddForm {
|
|||
orderNumber?: number
|
||||
}
|
||||
|
||||
export default async function addCommittalType(
|
||||
addForm: AddForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
export default function addCommittalType(addForm: AddForm, user: User): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -34,7 +32,7 @@ export default async function addCommittalType(
|
|||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
clearCacheByTableName('CommittalTypes')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import { type DateString, type TimeString } from '@cityssm/utils-datetime';
|
||||
import sqlite from 'better-sqlite3';
|
||||
export interface AddContractForm {
|
||||
burialSiteId: number | string;
|
||||
contractEndDateString: '' | DateString;
|
||||
|
|
@ -35,4 +35,4 @@ export interface AddContractForm {
|
|||
deceasedProvince?: string;
|
||||
intermentContainerTypeId?: number | string;
|
||||
}
|
||||
export default function addContract(addForm: AddContractForm, user: User, connectedDatabase?: PoolConnection): Promise<number>;
|
||||
export default function addContract(addForm: AddContractForm, user: User, connectedDatabase?: sqlite.Database): number;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import { dateStringToInteger, timeStringToInteger } from '@cityssm/utils-datetime';
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import addOrUpdateContractField from './addOrUpdateContractField.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
// eslint-disable-next-line complexity
|
||||
export default async function addContract(addForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
export default function addContract(addForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const contractStartDate = dateStringToInteger(addForm.contractStartDateString);
|
||||
const result = database
|
||||
|
|
@ -34,7 +35,7 @@ export default async function addContract(addForm, user, connectedDatabase) {
|
|||
for (const contractTypeFieldId of contractTypeFieldIds) {
|
||||
const fieldValue = addForm[`fieldValue_${contractTypeFieldId}`];
|
||||
if ((fieldValue ?? '') !== '') {
|
||||
await addOrUpdateContractField({
|
||||
addOrUpdateContractField({
|
||||
contractId,
|
||||
contractTypeFieldId,
|
||||
fieldValue: fieldValue ?? ''
|
||||
|
|
@ -66,7 +67,7 @@ export default async function addContract(addForm, user, connectedDatabase) {
|
|||
: addForm.intermentContainerTypeId, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
}
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
database.close();
|
||||
}
|
||||
return contractId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import {
|
||||
type DateString,
|
||||
type TimeString,
|
||||
dateStringToInteger,
|
||||
timeStringToInteger
|
||||
} from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
import addOrUpdateContractField from './addOrUpdateContractField.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddContractForm {
|
||||
burialSiteId: number | string
|
||||
|
|
@ -51,12 +51,12 @@ export interface AddContractForm {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
export default async function addContract(
|
||||
export default function addContract(
|
||||
addForm: AddContractForm,
|
||||
user: User,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<number> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
connectedDatabase?: sqlite.Database
|
||||
): number {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ export default async function addContract(
|
|||
| undefined
|
||||
|
||||
if ((fieldValue ?? '') !== '') {
|
||||
await addOrUpdateContractField(
|
||||
addOrUpdateContractField(
|
||||
{
|
||||
contractId,
|
||||
contractTypeFieldId,
|
||||
|
|
@ -186,7 +186,7 @@ export default async function addContract(
|
|||
}
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
database.close()
|
||||
}
|
||||
|
||||
return contractId
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ export interface AddContractCommentForm {
|
|||
commentDateString?: DateString;
|
||||
commentTimeString?: TimeString;
|
||||
}
|
||||
export default function addContractComment(commentForm: AddContractCommentForm, user: User): Promise<number>;
|
||||
export default function addContractComment(commentForm: AddContractCommentForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { dateStringToInteger, dateToInteger, dateToTimeInteger, timeStringToInteger } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addContractComment(commentForm, user) {
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addContractComment(commentForm, user) {
|
||||
const rightNow = new Date();
|
||||
let commentDate = 0;
|
||||
let commentTime = 0;
|
||||
|
|
@ -12,7 +13,7 @@ export default async function addContractComment(commentForm, user) {
|
|||
commentDate = dateStringToInteger(commentForm.commentDateString);
|
||||
commentTime = timeStringToInteger(commentForm.commentTimeString);
|
||||
}
|
||||
const database = await acquireConnection();
|
||||
const database = sqlite(sunriseDB);
|
||||
const result = database
|
||||
.prepare(`insert into ContractComments (
|
||||
contractId,
|
||||
|
|
@ -22,6 +23,6 @@ export default async function addContractComment(commentForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(commentForm.contractId, commentDate, commentTime ?? 0, commentForm.comment, user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
|
||||
database.release();
|
||||
database.close();
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ import {
|
|||
dateToTimeInteger,
|
||||
timeStringToInteger
|
||||
} from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddContractCommentForm {
|
||||
contractId: number | string
|
||||
|
|
@ -17,10 +18,10 @@ export interface AddContractCommentForm {
|
|||
commentTimeString?: TimeString
|
||||
}
|
||||
|
||||
export default async function addContractComment(
|
||||
export default function addContractComment(
|
||||
commentForm: AddContractCommentForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
): number {
|
||||
const rightNow = new Date()
|
||||
|
||||
let commentDate = 0
|
||||
|
|
@ -38,7 +39,7 @@ export default async function addContractComment(
|
|||
)
|
||||
}
|
||||
|
||||
const database = await acquireConnection()
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const result = database
|
||||
.prepare(
|
||||
|
|
@ -61,7 +62,7 @@ export default async function addContractComment(
|
|||
rightNow.getTime()
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return result.lastInsertRowid as number
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import sqlite from 'better-sqlite3';
|
||||
export interface AddContractFeeForm {
|
||||
contractId: number | string;
|
||||
feeId: number | string;
|
||||
|
|
@ -6,4 +6,4 @@ export interface AddContractFeeForm {
|
|||
quantity: number | string;
|
||||
taxAmount?: number | string;
|
||||
}
|
||||
export default function addContractFee(addFeeForm: AddContractFeeForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;
|
||||
export default function addContractFee(addFeeForm: AddContractFeeForm, user: User, connectedDatabase?: sqlite.Database): Promise<boolean>;
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import { calculateFeeAmount, calculateTaxAmount } from '../helpers/functions.fee.js';
|
||||
import getContract from './getContract.js';
|
||||
import getFee from './getFee.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addContractFee(addFeeForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
// Calculate fee and tax (if not set)
|
||||
let feeAmount;
|
||||
let taxAmount;
|
||||
if ((addFeeForm.feeAmount ?? '') === '') {
|
||||
const contract = (await getContract(addFeeForm.contractId));
|
||||
const fee = (await getFee(addFeeForm.feeId));
|
||||
const fee = getFee(addFeeForm.feeId);
|
||||
feeAmount = calculateFeeAmount(fee, contract);
|
||||
taxAmount = calculateTaxAmount(fee, feeAmount);
|
||||
}
|
||||
|
|
@ -83,7 +84,7 @@ export default async function addContractFee(addFeeForm, user, connectedDatabase
|
|||
}
|
||||
finally {
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
database.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
import {
|
||||
calculateFeeAmount,
|
||||
calculateTaxAmount
|
||||
|
|
@ -8,7 +9,6 @@ import type { Contract, Fee } from '../types/record.types.js'
|
|||
|
||||
import getContract from './getContract.js'
|
||||
import getFee from './getFee.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddContractFeeForm {
|
||||
contractId: number | string
|
||||
|
|
@ -22,9 +22,9 @@ export interface AddContractFeeForm {
|
|||
export default async function addContractFee(
|
||||
addFeeForm: AddContractFeeForm,
|
||||
user: User,
|
||||
connectedDatabase?: PoolConnection
|
||||
connectedDatabase?: sqlite.Database
|
||||
): Promise<boolean> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -33,11 +33,9 @@ export default async function addContractFee(
|
|||
let taxAmount: number
|
||||
|
||||
if ((addFeeForm.feeAmount ?? '') === '') {
|
||||
const contract = (await getContract(
|
||||
addFeeForm.contractId
|
||||
)) as Contract
|
||||
const contract = (await getContract(addFeeForm.contractId)) as Contract
|
||||
|
||||
const fee = (await getFee(addFeeForm.feeId)) as Fee
|
||||
const fee = getFee(addFeeForm.feeId) as Fee
|
||||
|
||||
feeAmount = calculateFeeAmount(fee, contract)
|
||||
taxAmount = calculateTaxAmount(fee, feeAmount)
|
||||
|
|
@ -65,6 +63,7 @@ export default async function addContractFee(
|
|||
| {
|
||||
feeAmount: number | null
|
||||
taxAmount: number | null
|
||||
|
||||
recordDelete_timeMillis: number | null
|
||||
}
|
||||
| undefined
|
||||
|
|
@ -156,7 +155,7 @@ export default async function addContractFee(
|
|||
return result.changes > 0
|
||||
} finally {
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
database.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import addContractFee from './addContractFee.js';
|
||||
import { getFeeCategory } from './getFeeCategories.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addContractFeeCategory(addFeeCategoryForm, user) {
|
||||
const database = await acquireConnection();
|
||||
const feeCategory = await getFeeCategory(addFeeCategoryForm.feeCategoryId, database);
|
||||
const database = sqlite(sunriseDB);
|
||||
const feeCategory = getFeeCategory(addFeeCategoryForm.feeCategoryId, database);
|
||||
let addedFeeCount = 0;
|
||||
for (const fee of feeCategory?.fees ?? []) {
|
||||
const success = await addContractFee({
|
||||
|
|
@ -15,6 +16,6 @@ export default async function addContractFeeCategory(addFeeCategoryForm, user) {
|
|||
addedFeeCount += 1;
|
||||
}
|
||||
}
|
||||
database.release();
|
||||
database.close();
|
||||
return addedFeeCount;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
import addContractFee from './addContractFee.js'
|
||||
import { getFeeCategory } from './getFeeCategories.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddContractCategoryForm {
|
||||
contractId: number | string
|
||||
|
|
@ -11,12 +14,9 @@ export default async function addContractFeeCategory(
|
|||
addFeeCategoryForm: AddContractCategoryForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const feeCategory = await getFeeCategory(
|
||||
addFeeCategoryForm.feeCategoryId,
|
||||
database
|
||||
)
|
||||
const feeCategory = getFeeCategory(addFeeCategoryForm.feeCategoryId, database)
|
||||
|
||||
let addedFeeCount = 0
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ export default async function addContractFeeCategory(
|
|||
}
|
||||
}
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return addedFeeCount
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import { type DateString } from '@cityssm/utils-datetime';
|
||||
import sqlite from 'better-sqlite3';
|
||||
export interface AddForm {
|
||||
contractId: number | string;
|
||||
deceasedName: string;
|
||||
|
|
@ -16,4 +16,4 @@ export interface AddForm {
|
|||
deathAgePeriod: string;
|
||||
intermentContainerTypeId: number | string;
|
||||
}
|
||||
export default function addContractInterment(contractForm: AddForm, user: User, connectedDatabase?: PoolConnection): Promise<number>;
|
||||
export default function addContractInterment(contractForm: AddForm, user: User, connectedDatabase?: sqlite.Database): number;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { dateStringToInteger } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addContractInterment(contractForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addContractInterment(contractForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB);
|
||||
const maxIntermentNumber = (database
|
||||
.prepare(`select max(intermentNumber) as maxIntermentNumber
|
||||
from ContractInterments
|
||||
|
|
@ -26,7 +27,7 @@ export default async function addContractInterment(contractForm, user, connected
|
|||
? undefined
|
||||
: contractForm.intermentContainerTypeId, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
database.close();
|
||||
}
|
||||
return newIntermentNumber;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
|
||||
import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddForm {
|
||||
contractId: number | string
|
||||
|
|
@ -26,12 +25,12 @@ export interface AddForm {
|
|||
intermentContainerTypeId: number | string
|
||||
}
|
||||
|
||||
export default async function addContractInterment(
|
||||
export default function addContractInterment(
|
||||
contractForm: AddForm,
|
||||
user: User,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<number> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
connectedDatabase?: sqlite.Database
|
||||
): number {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB)
|
||||
|
||||
const maxIntermentNumber = (database
|
||||
.prepare(
|
||||
|
|
@ -82,7 +81,7 @@ export default async function addContractInterment(
|
|||
)
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
database.close()
|
||||
}
|
||||
|
||||
return newIntermentNumber
|
||||
|
|
|
|||
|
|
@ -6,4 +6,4 @@ export interface AddTransactionForm {
|
|||
transactionAmount: number | string;
|
||||
transactionNote: string;
|
||||
}
|
||||
export default function addContractTransaction(contractTransactionForm: AddTransactionForm, user: User): Promise<number>;
|
||||
export default function addContractTransaction(contractTransactionForm: AddTransactionForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { dateStringToInteger, dateToInteger, dateToTimeInteger, timeStringToInteger } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addContractTransaction(contractTransactionForm, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addContractTransaction(contractTransactionForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
let transactionIndex = 0;
|
||||
const maxIndexResult = database
|
||||
.prepare(`select transactionIndex
|
||||
|
|
@ -29,6 +30,6 @@ export default async function addContractTransaction(contractTransactionForm, us
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(contractTransactionForm.contractId, transactionIndex, transactionDate, transactionTime, contractTransactionForm.transactionAmount, contractTransactionForm.externalReceiptNumber, contractTransactionForm.transactionNote, user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
|
||||
database.release();
|
||||
database.close();
|
||||
return transactionIndex;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ import {
|
|||
dateToTimeInteger,
|
||||
timeStringToInteger
|
||||
} from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddTransactionForm {
|
||||
contractId: number | string
|
||||
|
|
@ -18,11 +19,11 @@ export interface AddTransactionForm {
|
|||
transactionNote: string
|
||||
}
|
||||
|
||||
export default async function addContractTransaction(
|
||||
export default function addContractTransaction(
|
||||
contractTransactionForm: AddTransactionForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
let transactionIndex = 0
|
||||
|
||||
|
|
@ -76,7 +77,7 @@ export default async function addContractTransaction(
|
|||
rightNow.getTime()
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return transactionIndex
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@ export interface AddForm {
|
|||
isPreneed?: string;
|
||||
orderNumber?: number;
|
||||
}
|
||||
export default function addContractType(addForm: AddForm, user: User): Promise<number>;
|
||||
export default function addContractType(addForm: AddForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addContractType(addForm, user) {
|
||||
const database = await acquireConnection();
|
||||
export default function addContractType(addForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into ContractTypes (
|
||||
|
|
@ -10,7 +11,7 @@ export default async function addContractType(addForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(addForm.contractType, addForm.isPreneed === undefined ? 0 : 1, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
database.close();
|
||||
clearCacheByTableName('ContractTypes');
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
|
||||
export interface AddForm {
|
||||
contractType: string
|
||||
|
|
@ -8,11 +9,8 @@ export interface AddForm {
|
|||
orderNumber?: number
|
||||
}
|
||||
|
||||
export default async function addContractType(
|
||||
addForm: AddForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
export default function addContractType(addForm: AddForm, user: User): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -34,7 +32,7 @@ export default async function addContractType(
|
|||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
clearCacheByTableName('ContractTypes')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
export interface AddContractTypeFieldForm {
|
||||
contractTypeId?: string | number;
|
||||
contractTypeId?: number | string;
|
||||
contractTypeField: string;
|
||||
fieldValues?: string;
|
||||
fieldType?: string;
|
||||
isRequired?: string;
|
||||
maxLength?: number | string;
|
||||
minLength?: number | string;
|
||||
pattern?: string;
|
||||
minLength?: string | number;
|
||||
maxLength?: string | number;
|
||||
orderNumber?: number;
|
||||
}
|
||||
export default function addContractTypeField(addForm: AddContractTypeFieldForm, user: User): Promise<number>;
|
||||
export default function addContractTypeField(addForm: AddContractTypeFieldForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addContractTypeField(addForm, user) {
|
||||
const database = await acquireConnection();
|
||||
export default function addContractTypeField(addForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into ContractTypeFields (
|
||||
|
|
@ -13,7 +14,7 @@ export default async function addContractTypeField(addForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.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);
|
||||
database.release();
|
||||
database.close();
|
||||
clearCacheByTableName('ContractTypeFields');
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,26 @@
|
|||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddContractTypeFieldForm {
|
||||
contractTypeId?: string | number
|
||||
contractTypeId?: number | string
|
||||
contractTypeField: string
|
||||
fieldValues?: string
|
||||
fieldType?: string
|
||||
isRequired?: string
|
||||
maxLength?: number | string
|
||||
minLength?: number | string
|
||||
pattern?: string
|
||||
minLength?: string | number
|
||||
maxLength?: string | number
|
||||
|
||||
orderNumber?: number
|
||||
}
|
||||
|
||||
export default async function addContractTypeField(
|
||||
export default function addContractTypeField(
|
||||
addForm: AddContractTypeFieldForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -49,7 +51,7 @@ export default async function addContractTypeField(
|
|||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
clearCacheByTableName('ContractTypeFields')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
export interface AddContractTypePrintForm {
|
||||
contractTypeId: string | number;
|
||||
contractTypeId: number | string;
|
||||
printEJS: string;
|
||||
orderNumber?: number;
|
||||
}
|
||||
export default function addContractTypePrint(addForm: AddContractTypePrintForm, user: User): Promise<boolean>;
|
||||
export default function addContractTypePrint(addForm: AddContractTypePrintForm, user: User): boolean;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addContractTypePrint(addForm, user) {
|
||||
const database = await acquireConnection();
|
||||
export default function addContractTypePrint(addForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
let result = database
|
||||
.prepare(`update ContractTypePrints
|
||||
|
|
@ -21,7 +22,7 @@ export default async function addContractTypePrint(addForm, user) {
|
|||
values (?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(addForm.contractTypeId, addForm.printEJS, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
}
|
||||
database.release();
|
||||
database.close();
|
||||
clearCacheByTableName('ContractTypePrints');
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddContractTypePrintForm {
|
||||
contractTypeId: string | number
|
||||
contractTypeId: number | string
|
||||
printEJS: string
|
||||
orderNumber?: number
|
||||
}
|
||||
|
||||
export default async function addContractTypePrint(
|
||||
export default function addContractTypePrint(
|
||||
addForm: AddContractTypePrintForm,
|
||||
user: User
|
||||
): Promise<boolean> {
|
||||
const database = await acquireConnection()
|
||||
): boolean {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -53,7 +54,7 @@ export default async function addContractTypePrint(
|
|||
)
|
||||
}
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
clearCacheByTableName('ContractTypePrints')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
export interface AddFeeForm {
|
||||
feeCategoryId: string | number;
|
||||
feeCategoryId: number | string;
|
||||
feeName: string;
|
||||
feeDescription: string;
|
||||
feeAccount: string;
|
||||
contractTypeId: string | number;
|
||||
burialSiteTypeId: string | number;
|
||||
contractTypeId: number | string;
|
||||
burialSiteTypeId: number | string;
|
||||
feeAmount?: string;
|
||||
feeFunction?: string;
|
||||
taxAmount?: string;
|
||||
|
|
@ -14,4 +14,4 @@ export interface AddFeeForm {
|
|||
isRequired?: '' | '1';
|
||||
orderNumber?: number;
|
||||
}
|
||||
export default function addFee(feeForm: AddFeeForm, user: User): Promise<number>;
|
||||
export default function addFee(feeForm: AddFeeForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function addFee(feeForm, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addFee(feeForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into Fees (
|
||||
|
|
@ -15,6 +16,6 @@ export default async function addFee(feeForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.feeAccount, feeForm.contractTypeId === '' ? undefined : feeForm.contractTypeId, feeForm.burialSiteTypeId === '' ? undefined : feeForm.burialSiteTypeId, feeForm.feeAmount === '' ? undefined : feeForm.feeAmount, feeForm.feeFunction ?? undefined, feeForm.taxAmount === '' ? undefined : feeForm.taxAmount, feeForm.taxPercentage === '' ? undefined : feeForm.taxPercentage, (feeForm.includeQuantity ?? '') === '' ? 0 : 1, feeForm.quantityUnit, (feeForm.isRequired ?? '') === '' ? 0 : 1, feeForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
database.close();
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import { acquireConnection } from './pool.js'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddFeeForm {
|
||||
feeCategoryId: string | number
|
||||
feeCategoryId: number | string
|
||||
feeName: string
|
||||
feeDescription: string
|
||||
feeAccount: string
|
||||
contractTypeId: string | number
|
||||
burialSiteTypeId: string | number
|
||||
contractTypeId: number | string
|
||||
burialSiteTypeId: number | string
|
||||
feeAmount?: string
|
||||
feeFunction?: string
|
||||
taxAmount?: string
|
||||
|
|
@ -17,11 +19,8 @@ export interface AddFeeForm {
|
|||
orderNumber?: number
|
||||
}
|
||||
|
||||
export default async function addFee(
|
||||
feeForm: AddFeeForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
export default function addFee(feeForm: AddFeeForm, user: User): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -60,7 +59,7 @@ export default async function addFee(
|
|||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return result.lastInsertRowid as number
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@ export interface AddFeeCategoryForm {
|
|||
isGroupedFee?: '1';
|
||||
orderNumber?: number;
|
||||
}
|
||||
export default function addFeeCategory(feeCategoryForm: AddFeeCategoryForm, user: User): Promise<number>;
|
||||
export default function addFeeCategory(feeCategoryForm: AddFeeCategoryForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function addFeeCategory(feeCategoryForm, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addFeeCategory(feeCategoryForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into FeeCategories (
|
||||
|
|
@ -10,6 +11,6 @@ export default async function addFeeCategory(feeCategoryForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(feeCategoryForm.feeCategory, (feeCategoryForm.isGroupedFee ?? '') === '1' ? 1 : 0, feeCategoryForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
database.close();
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
import { acquireConnection } from './pool.js'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddFeeCategoryForm {
|
||||
feeCategory: string
|
||||
|
|
@ -6,11 +8,11 @@ export interface AddFeeCategoryForm {
|
|||
orderNumber?: number
|
||||
}
|
||||
|
||||
export default async function addFeeCategory(
|
||||
export default function addFeeCategory(
|
||||
feeCategoryForm: AddFeeCategoryForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -33,7 +35,7 @@ export default async function addFeeCategory(
|
|||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return result.lastInsertRowid as number
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ export interface AddForm {
|
|||
funeralHomeAddress1: string;
|
||||
funeralHomeAddress2: string;
|
||||
funeralHomeCity: string;
|
||||
funeralHomeProvince: string;
|
||||
funeralHomePostalCode: string;
|
||||
funeralHomeProvince: string;
|
||||
funeralHomePhoneNumber: string;
|
||||
}
|
||||
export default function addFuneralHome(addForm: AddForm, user: User): Promise<number>;
|
||||
export default function addFuneralHome(addForm: AddForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function addFuneralHome(addForm, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addFuneralHome(addForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into FuneralHomes (
|
||||
|
|
@ -10,6 +11,6 @@ export default async function addFuneralHome(addForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(addForm.funeralHomeName, addForm.funeralHomeKey, addForm.funeralHomeAddress1, addForm.funeralHomeAddress2, addForm.funeralHomeCity, addForm.funeralHomeProvince, addForm.funeralHomePostalCode, addForm.funeralHomePhoneNumber, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
database.close();
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,22 @@
|
|||
import { acquireConnection } from './pool.js'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddForm {
|
||||
funeralHomeName: string
|
||||
funeralHomeKey: string
|
||||
|
||||
funeralHomeAddress1: string
|
||||
funeralHomeAddress2: string
|
||||
funeralHomeCity: string
|
||||
funeralHomeProvince: string
|
||||
funeralHomePostalCode: string
|
||||
funeralHomeProvince: string
|
||||
|
||||
funeralHomePhoneNumber: string
|
||||
}
|
||||
|
||||
export default async function addFuneralHome(
|
||||
addForm: AddForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
export default function addFuneralHome(addForm: AddForm, user: User): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ export default async function addFuneralHome(
|
|||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return result.lastInsertRowid as number
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,4 +4,4 @@ export interface AddForm {
|
|||
isCremationType?: string;
|
||||
orderNumber?: number;
|
||||
}
|
||||
export default function addIntermentContainerType(addForm: AddForm, user: User): Promise<number>;
|
||||
export default function addIntermentContainerType(addForm: AddForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addIntermentContainerType(addForm, user) {
|
||||
const database = await acquireConnection();
|
||||
export default function addIntermentContainerType(addForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into IntermentContainerTypes (
|
||||
|
|
@ -10,7 +11,7 @@ export default async function addIntermentContainerType(addForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(addForm.intermentContainerType, addForm.intermentContainerTypeKey ?? '', addForm.isCremationType === undefined ? 0 : 1, addForm.orderNumber ?? -1, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
database.close();
|
||||
clearCacheByTableName('IntermentContainerTypes');
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
|
||||
export interface AddForm {
|
||||
intermentContainerType: string
|
||||
|
|
@ -9,11 +10,11 @@ export interface AddForm {
|
|||
orderNumber?: number
|
||||
}
|
||||
|
||||
export default async function addIntermentContainerType(
|
||||
export default function addIntermentContainerType(
|
||||
addForm: AddForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -36,7 +37,7 @@ export default async function addIntermentContainerType(
|
|||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
clearCacheByTableName('IntermentContainerTypes')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import sqlite from 'better-sqlite3';
|
||||
export interface BurialSiteFieldForm {
|
||||
burialSiteId: string | number;
|
||||
burialSiteTypeFieldId: string | number;
|
||||
burialSiteId: number | string;
|
||||
burialSiteTypeFieldId: number | string;
|
||||
fieldValue: string;
|
||||
}
|
||||
export default function addOrUpdateBurialSiteField(fieldForm: BurialSiteFieldForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;
|
||||
export default function addOrUpdateBurialSiteField(fieldForm: BurialSiteFieldForm, user: User, connectedDatabase?: sqlite.Database): boolean;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function addOrUpdateBurialSiteField(fieldForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addOrUpdateBurialSiteField(fieldForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
let result = database
|
||||
.prepare(`update BurialSiteFields
|
||||
|
|
@ -22,7 +23,7 @@ export default async function addOrUpdateBurialSiteField(fieldForm, user, connec
|
|||
.run(fieldForm.burialSiteId, fieldForm.burialSiteTypeFieldId, fieldForm.fieldValue, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
}
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
database.close();
|
||||
}
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface BurialSiteFieldForm {
|
||||
burialSiteId: string | number
|
||||
burialSiteTypeFieldId: string | number
|
||||
burialSiteId: number | string
|
||||
burialSiteTypeFieldId: number | string
|
||||
fieldValue: string
|
||||
}
|
||||
|
||||
export default async function addOrUpdateBurialSiteField(
|
||||
export default function addOrUpdateBurialSiteField(
|
||||
fieldForm: BurialSiteFieldForm,
|
||||
user: User,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<boolean> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
connectedDatabase?: sqlite.Database
|
||||
): boolean {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ export default async function addOrUpdateBurialSiteField(
|
|||
}
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
database.close()
|
||||
}
|
||||
|
||||
return result.changes > 0
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import sqlite from 'better-sqlite3';
|
||||
export interface ContractFieldForm {
|
||||
contractId: string | number;
|
||||
contractTypeFieldId: string | number;
|
||||
contractId: number | string;
|
||||
contractTypeFieldId: number | string;
|
||||
fieldValue: string;
|
||||
}
|
||||
export default function addOrUpdateContractField(fieldForm: ContractFieldForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;
|
||||
export default function addOrUpdateContractField(fieldForm: ContractFieldForm, user: User, connectedDatabase?: sqlite.Database): boolean;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function addOrUpdateContractField(fieldForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addOrUpdateContractField(fieldForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
let result = database
|
||||
.prepare(`update ContractFields
|
||||
|
|
@ -22,7 +23,7 @@ export default async function addOrUpdateContractField(fieldForm, user, connecte
|
|||
.run(fieldForm.contractId, fieldForm.contractTypeFieldId, fieldForm.fieldValue, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
}
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
database.close();
|
||||
}
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface ContractFieldForm {
|
||||
contractId: string | number
|
||||
contractTypeFieldId: string | number
|
||||
contractId: number | string
|
||||
contractTypeFieldId: number | string
|
||||
fieldValue: string
|
||||
}
|
||||
|
||||
export default async function addOrUpdateContractField(
|
||||
export default function addOrUpdateContractField(
|
||||
fieldForm: ContractFieldForm,
|
||||
user: User,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<boolean> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
connectedDatabase?: sqlite.Database
|
||||
): boolean {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ export default async function addOrUpdateContractField(
|
|||
}
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
database.close()
|
||||
}
|
||||
|
||||
return result.changes > 0
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
type RecordTable = 'BurialSiteStatuses' | 'BurialSiteTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes';
|
||||
export default function addRecord(recordTable: RecordTable, recordName: string, orderNumber: number | string, user: User): Promise<number>;
|
||||
export default function addRecord(recordTable: RecordTable, recordName: string, orderNumber: number | string, user: User): number;
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
const recordNameColumns = new Map([
|
||||
['BurialSiteStatuses', 'burialSiteStatus'],
|
||||
['BurialSiteTypes', 'burialSiteType'],
|
||||
['WorkOrderMilestoneTypes', 'workOrderMilestoneType'],
|
||||
['WorkOrderTypes', 'workOrderType']
|
||||
]);
|
||||
export default async function addRecord(recordTable, recordName, orderNumber, user) {
|
||||
const database = await acquireConnection();
|
||||
export default function addRecord(recordTable, recordName, orderNumber, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare(`insert into ${recordTable} (
|
||||
|
|
@ -17,7 +18,7 @@ export default async function addRecord(recordTable, recordName, orderNumber, us
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?)`)
|
||||
.run(recordName, orderNumber === '' ? -1 : orderNumber, user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
database.close();
|
||||
clearCacheByTableName(recordTable);
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
import { clearCacheByTableName } from '../helpers/functions.cache.js'
|
||||
|
||||
type RecordTable =
|
||||
| 'BurialSiteStatuses'
|
||||
|
|
@ -15,13 +16,13 @@ const recordNameColumns = new Map<RecordTable, string>([
|
|||
['WorkOrderTypes', 'workOrderType']
|
||||
])
|
||||
|
||||
export default async function addRecord(
|
||||
export default function addRecord(
|
||||
recordTable: RecordTable,
|
||||
recordName: string,
|
||||
orderNumber: number | string,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ export default async function addRecord(
|
|||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
clearCacheByTableName(recordTable)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,4 +6,4 @@ export interface AddWorkOrderForm {
|
|||
workOrderCloseDateString?: string;
|
||||
contractId?: string;
|
||||
}
|
||||
export default function addWorkOrder(workOrderForm: AddWorkOrderForm, user: User): Promise<number>;
|
||||
export default function addWorkOrder(workOrderForm: AddWorkOrderForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
import { dateStringToInteger, dateToInteger } from '@cityssm/utils-datetime';
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import addWorkOrderContract from './addWorkOrderContract.js';
|
||||
import getNextWorkOrderNumber from './getNextWorkOrderNumber.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addWorkOrder(workOrderForm, user) {
|
||||
const database = await acquireConnection();
|
||||
export default function addWorkOrder(workOrderForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNow = new Date();
|
||||
let workOrderNumber = workOrderForm.workOrderNumber;
|
||||
if ((workOrderNumber ?? '') === '') {
|
||||
workOrderNumber = await getNextWorkOrderNumber(database);
|
||||
workOrderNumber = getNextWorkOrderNumber(database);
|
||||
}
|
||||
const result = database
|
||||
.prepare(`insert into WorkOrders (
|
||||
|
|
@ -23,11 +24,11 @@ export default async function addWorkOrder(workOrderForm, user) {
|
|||
: dateStringToInteger(workOrderForm.workOrderCloseDateString), user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
|
||||
const workOrderId = result.lastInsertRowid;
|
||||
if ((workOrderForm.contractId ?? '') !== '') {
|
||||
await addWorkOrderContract({
|
||||
addWorkOrderContract({
|
||||
workOrderId,
|
||||
contractId: workOrderForm.contractId
|
||||
}, user, database);
|
||||
}
|
||||
database.release();
|
||||
database.close();
|
||||
return workOrderId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@ import {
|
|||
dateStringToInteger,
|
||||
dateToInteger
|
||||
} from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
import addWorkOrderContract from './addWorkOrderContract.js'
|
||||
import getNextWorkOrderNumber from './getNextWorkOrderNumber.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export interface AddWorkOrderForm {
|
||||
workOrderTypeId: number | string
|
||||
|
|
@ -17,18 +19,18 @@ export interface AddWorkOrderForm {
|
|||
contractId?: string
|
||||
}
|
||||
|
||||
export default async function addWorkOrder(
|
||||
export default function addWorkOrder(
|
||||
workOrderForm: AddWorkOrderForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNow = new Date()
|
||||
|
||||
let workOrderNumber = workOrderForm.workOrderNumber
|
||||
|
||||
if ((workOrderNumber ?? '') === '') {
|
||||
workOrderNumber = await getNextWorkOrderNumber(database)
|
||||
workOrderNumber = getNextWorkOrderNumber(database)
|
||||
}
|
||||
|
||||
const result = database
|
||||
|
|
@ -63,7 +65,7 @@ export default async function addWorkOrder(
|
|||
const workOrderId = result.lastInsertRowid as number
|
||||
|
||||
if ((workOrderForm.contractId ?? '') !== '') {
|
||||
await addWorkOrderContract(
|
||||
addWorkOrderContract(
|
||||
{
|
||||
workOrderId,
|
||||
contractId: workOrderForm.contractId as string
|
||||
|
|
@ -73,7 +75,7 @@ export default async function addWorkOrder(
|
|||
)
|
||||
}
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return workOrderId
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ export interface AddForm {
|
|||
workOrderId: number | string;
|
||||
burialSiteId: number | string;
|
||||
}
|
||||
export default function addWorkOrderBurialSite(workOrderLotForm: AddForm, user: User): Promise<boolean>;
|
||||
export default function addWorkOrderBurialSite(workOrderLotForm: AddForm, user: User): boolean;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function addWorkOrderBurialSite(workOrderLotForm, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addWorkOrderBurialSite(workOrderLotForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const row = database
|
||||
.prepare(`select recordDelete_timeMillis
|
||||
|
|
@ -32,6 +33,6 @@ export default async function addWorkOrderBurialSite(workOrderLotForm, user) {
|
|||
.run(user.userName, rightNowMillis, user.userName, rightNowMillis, workOrderLotForm.workOrderId, workOrderLotForm.burialSiteId);
|
||||
}
|
||||
}
|
||||
database.release();
|
||||
database.close();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
import { acquireConnection } from './pool.js'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddForm {
|
||||
workOrderId: number | string
|
||||
burialSiteId: number | string
|
||||
}
|
||||
|
||||
export default async function addWorkOrderBurialSite(
|
||||
export default function addWorkOrderBurialSite(
|
||||
workOrderLotForm: AddForm,
|
||||
user: User
|
||||
): Promise<boolean> {
|
||||
const database = await acquireConnection()
|
||||
): boolean {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -68,7 +70,7 @@ export default async function addWorkOrderBurialSite(
|
|||
}
|
||||
}
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ export interface AddWorkOrderCommentForm {
|
|||
workOrderId: string;
|
||||
comment: string;
|
||||
}
|
||||
export default function addWorkOrderComment(workOrderCommentForm: AddWorkOrderCommentForm, user: User): Promise<number>;
|
||||
export default function addWorkOrderComment(workOrderCommentForm: AddWorkOrderCommentForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { dateToInteger, dateToTimeInteger } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addWorkOrderComment(workOrderCommentForm, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addWorkOrderComment(workOrderCommentForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNow = new Date();
|
||||
const result = database
|
||||
.prepare(`insert into WorkOrderComments (
|
||||
|
|
@ -12,6 +13,6 @@ export default async function addWorkOrderComment(workOrderCommentForm, user) {
|
|||
recordUpdate_userName, recordUpdate_timeMillis)
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||
.run(workOrderCommentForm.workOrderId, dateToInteger(rightNow), dateToTimeInteger(rightNow), workOrderCommentForm.comment, user.userName, rightNow.getTime(), user.userName, rightNow.getTime());
|
||||
database.release();
|
||||
database.close();
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
import { dateToInteger, dateToTimeInteger } from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddWorkOrderCommentForm {
|
||||
workOrderId: string
|
||||
comment: string
|
||||
}
|
||||
|
||||
export default async function addWorkOrderComment(
|
||||
export default function addWorkOrderComment(
|
||||
workOrderCommentForm: AddWorkOrderCommentForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
): number {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNow = new Date()
|
||||
|
||||
|
|
@ -36,7 +37,7 @@ export default async function addWorkOrderComment(
|
|||
rightNow.getTime()
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return result.lastInsertRowid as number
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
import sqlite from 'better-sqlite3';
|
||||
export interface AddForm {
|
||||
workOrderId: number | string;
|
||||
contractId: number | string;
|
||||
workOrderId: number | string;
|
||||
}
|
||||
export default function addWorkOrderContract(addForm: AddForm, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;
|
||||
export default function addWorkOrderContract(addForm: AddForm, user: User, connectedDatabase?: sqlite.Database): boolean;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function addWorkOrderContract(addForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addWorkOrderContract(addForm, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const recordDeleteTimeMillis = database
|
||||
.prepare(`select recordDelete_timeMillis
|
||||
|
|
@ -34,7 +35,7 @@ export default async function addWorkOrderContract(addForm, user, connectedDatab
|
|||
}
|
||||
}
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
database.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddForm {
|
||||
workOrderId: number | string
|
||||
contractId: number | string
|
||||
workOrderId: number | string
|
||||
}
|
||||
|
||||
export default async function addWorkOrderContract(
|
||||
export default function addWorkOrderContract(
|
||||
addForm: AddForm,
|
||||
user: User,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<boolean> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
connectedDatabase?: sqlite.Database
|
||||
): boolean {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
|
|
@ -24,10 +24,7 @@ export default async function addWorkOrderContract(
|
|||
and contractId = ?`
|
||||
)
|
||||
.pluck()
|
||||
.get(
|
||||
addForm.workOrderId,
|
||||
addForm.contractId
|
||||
) as number | null | undefined
|
||||
.get(addForm.workOrderId, addForm.contractId) as number | null | undefined
|
||||
|
||||
if (recordDeleteTimeMillis === undefined) {
|
||||
database
|
||||
|
|
@ -72,7 +69,7 @@ export default async function addWorkOrderContract(
|
|||
}
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
database.close()
|
||||
}
|
||||
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export interface AddWorkOrderMilestoneForm {
|
||||
workOrderId: string | number;
|
||||
workOrderId: number | string;
|
||||
workOrderMilestoneTypeId: number | string;
|
||||
workOrderMilestoneDateString: string;
|
||||
workOrderMilestoneTimeString?: string;
|
||||
|
|
@ -7,4 +7,4 @@ export interface AddWorkOrderMilestoneForm {
|
|||
workOrderMilestoneCompletionDateString?: string;
|
||||
workOrderMilestoneCompletionTimeString?: string;
|
||||
}
|
||||
export default function addWorkOrderMilestone(milestoneForm: AddWorkOrderMilestoneForm, user: User): Promise<number>;
|
||||
export default function addWorkOrderMilestone(milestoneForm: AddWorkOrderMilestoneForm, user: User): number;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { dateStringToInteger, timeStringToInteger } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function addWorkOrderMilestone(milestoneForm, user) {
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function addWorkOrderMilestone(milestoneForm, user) {
|
||||
const rightNowMillis = Date.now();
|
||||
const database = await acquireConnection();
|
||||
const database = sqlite(sunriseDB);
|
||||
const result = database
|
||||
.prepare(`insert into WorkOrderMilestones (
|
||||
workOrderId, workOrderMilestoneTypeId,
|
||||
|
|
@ -23,6 +24,6 @@ export default async function addWorkOrderMilestone(milestoneForm, user) {
|
|||
: dateStringToInteger(milestoneForm.workOrderMilestoneCompletionDateString), (milestoneForm.workOrderMilestoneCompletionTimeString ?? '') === ''
|
||||
? undefined
|
||||
: timeStringToInteger(milestoneForm.workOrderMilestoneCompletionTimeString), user.userName, rightNowMillis, user.userName, rightNowMillis);
|
||||
database.release();
|
||||
database.close();
|
||||
return result.lastInsertRowid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,26 +2,30 @@ import {
|
|||
dateStringToInteger,
|
||||
timeStringToInteger
|
||||
} from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface AddWorkOrderMilestoneForm {
|
||||
workOrderId: string | number
|
||||
workOrderId: number | string
|
||||
workOrderMilestoneTypeId: number | string
|
||||
|
||||
workOrderMilestoneDateString: string
|
||||
workOrderMilestoneTimeString?: string
|
||||
|
||||
workOrderMilestoneDescription: string
|
||||
|
||||
workOrderMilestoneCompletionDateString?: string
|
||||
workOrderMilestoneCompletionTimeString?: string
|
||||
}
|
||||
|
||||
export default async function addWorkOrderMilestone(
|
||||
export default function addWorkOrderMilestone(
|
||||
milestoneForm: AddWorkOrderMilestoneForm,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
): number {
|
||||
const rightNowMillis = Date.now()
|
||||
|
||||
const database = await acquireConnection()
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const result = database
|
||||
.prepare(
|
||||
|
|
@ -62,7 +66,7 @@ export default async function addWorkOrderMilestone(
|
|||
rightNowMillis
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return result.lastInsertRowid as number
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export default function cleanupDatabase(user: User): Promise<{
|
||||
export default function cleanupDatabase(user: User): {
|
||||
inactivatedRecordCount: number;
|
||||
purgedRecordCount: number;
|
||||
}>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { daysToMillis } from '@cityssm/to-millis';
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { getConfigProperty } from '../helpers/config.helpers.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function cleanupDatabase(user) {
|
||||
const database = await acquireConnection();
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function cleanupDatabase(user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNowMillis = Date.now();
|
||||
const recordDeleteTimeMillisMin = rightNowMillis -
|
||||
daysToMillis(getConfigProperty('settings.adminCleanup.recordDeleteAgeDays'));
|
||||
|
|
@ -279,7 +280,7 @@ export default async function cleanupDatabase(user) {
|
|||
where recordDelete_timeMillis <= ?
|
||||
and burialSiteTypeId not in (select burialSiteTypeId from BurialSites)`)
|
||||
.run(recordDeleteTimeMillisMin).changes;
|
||||
database.release();
|
||||
database.close();
|
||||
return {
|
||||
inactivatedRecordCount,
|
||||
purgedRecordCount
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
import { daysToMillis } from '@cityssm/to-millis'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { getConfigProperty } from '../helpers/config.helpers.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
export default async function cleanupDatabase(
|
||||
user: User
|
||||
): Promise<{ inactivatedRecordCount: number; purgedRecordCount: number }> {
|
||||
const database = await acquireConnection()
|
||||
export default function cleanupDatabase(user: User): {
|
||||
inactivatedRecordCount: number
|
||||
purgedRecordCount: number
|
||||
} {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNowMillis = Date.now()
|
||||
const recordDeleteTimeMillisMin =
|
||||
|
|
@ -155,9 +156,7 @@ export default async function cleanupDatabase(
|
|||
.run(user.userName, rightNowMillis).changes
|
||||
|
||||
purgedRecordCount += database
|
||||
.prepare(
|
||||
'delete from ContractComments where recordDelete_timeMillis <= ?'
|
||||
)
|
||||
.prepare('delete from ContractComments where recordDelete_timeMillis <= ?')
|
||||
.run(recordDeleteTimeMillisMin).changes
|
||||
|
||||
/*
|
||||
|
|
@ -175,9 +174,7 @@ export default async function cleanupDatabase(
|
|||
.run(user.userName, rightNowMillis).changes
|
||||
|
||||
purgedRecordCount += database
|
||||
.prepare(
|
||||
'delete from ContractFields where recordDelete_timeMillis <= ?'
|
||||
)
|
||||
.prepare('delete from ContractFields where recordDelete_timeMillis <= ?')
|
||||
.run(recordDeleteTimeMillisMin).changes
|
||||
|
||||
/*
|
||||
|
|
@ -186,9 +183,7 @@ export default async function cleanupDatabase(
|
|||
*/
|
||||
|
||||
purgedRecordCount += database
|
||||
.prepare(
|
||||
'delete from ContractFees where recordDelete_timeMillis <= ?'
|
||||
)
|
||||
.prepare('delete from ContractFees where recordDelete_timeMillis <= ?')
|
||||
.run(recordDeleteTimeMillisMin).changes
|
||||
|
||||
purgedRecordCount += database
|
||||
|
|
@ -414,7 +409,7 @@ export default async function cleanupDatabase(
|
|||
)
|
||||
.run(recordDeleteTimeMillisMin).changes
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return {
|
||||
inactivatedRecordCount,
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ export interface CloseWorkOrderForm {
|
|||
workOrderId: number | string;
|
||||
workOrderCloseDateString?: string;
|
||||
}
|
||||
export default function closeWorkOrder(workOrderForm: CloseWorkOrderForm, user: User): Promise<boolean>;
|
||||
export default function closeWorkOrder(workOrderForm: CloseWorkOrderForm, user: User): boolean;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { dateStringToInteger, dateToInteger } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function closeWorkOrder(workOrderForm, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function closeWorkOrder(workOrderForm, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const rightNow = new Date();
|
||||
const result = database
|
||||
.prepare(`update WorkOrders
|
||||
|
|
@ -12,6 +13,6 @@ export default async function closeWorkOrder(workOrderForm, user) {
|
|||
.run(workOrderForm.workOrderCloseDateString
|
||||
? dateStringToInteger(workOrderForm.workOrderCloseDateString)
|
||||
: dateToInteger(new Date()), user.userName, rightNow.getTime(), workOrderForm.workOrderId);
|
||||
database.release();
|
||||
database.close();
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
import { dateStringToInteger, dateToInteger } from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface CloseWorkOrderForm {
|
||||
workOrderId: number | string
|
||||
|
||||
workOrderCloseDateString?: string
|
||||
}
|
||||
|
||||
export default async function closeWorkOrder(
|
||||
export default function closeWorkOrder(
|
||||
workOrderForm: CloseWorkOrderForm,
|
||||
user: User
|
||||
): Promise<boolean> {
|
||||
const database = await acquireConnection()
|
||||
): boolean {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const rightNow = new Date()
|
||||
|
||||
|
|
@ -32,7 +34,7 @@ export default async function closeWorkOrder(
|
|||
workOrderForm.workOrderId
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return result.changes > 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
export interface CompleteWorkOrderMilestoneForm {
|
||||
workOrderMilestoneId: string | number;
|
||||
workOrderMilestoneId: number | string;
|
||||
workOrderMilestoneCompletionDateString?: string;
|
||||
workOrderMilestoneCompletionTimeString?: string;
|
||||
}
|
||||
export default function completeWorkOrderMilestone(milestoneForm: CompleteWorkOrderMilestoneForm, user: User): Promise<boolean>;
|
||||
export default function completeWorkOrderMilestone(milestoneForm: CompleteWorkOrderMilestoneForm, user: User): boolean;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { dateStringToInteger, dateToInteger, dateToTimeInteger, timeStringToInteger } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function completeWorkOrderMilestone(milestoneForm, user) {
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function completeWorkOrderMilestone(milestoneForm, user) {
|
||||
const rightNow = new Date();
|
||||
const database = await acquireConnection();
|
||||
const database = sqlite(sunriseDB);
|
||||
const result = database
|
||||
.prepare(`update WorkOrderMilestones
|
||||
set workOrderMilestoneCompletionDate = ?,
|
||||
|
|
@ -15,6 +16,6 @@ export default async function completeWorkOrderMilestone(milestoneForm, user) {
|
|||
: dateStringToInteger(milestoneForm.workOrderMilestoneCompletionDateString), (milestoneForm.workOrderMilestoneCompletionTimeString ?? '') === ''
|
||||
? dateToTimeInteger(rightNow)
|
||||
: timeStringToInteger(milestoneForm.workOrderMilestoneCompletionTimeString), user.userName, rightNow.getTime(), milestoneForm.workOrderMilestoneId);
|
||||
database.release();
|
||||
database.close();
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,22 +4,24 @@ import {
|
|||
dateToTimeInteger,
|
||||
timeStringToInteger
|
||||
} from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export interface CompleteWorkOrderMilestoneForm {
|
||||
workOrderMilestoneId: string | number
|
||||
workOrderMilestoneId: number | string
|
||||
|
||||
workOrderMilestoneCompletionDateString?: string
|
||||
workOrderMilestoneCompletionTimeString?: string
|
||||
}
|
||||
|
||||
export default async function completeWorkOrderMilestone(
|
||||
export default function completeWorkOrderMilestone(
|
||||
milestoneForm: CompleteWorkOrderMilestoneForm,
|
||||
user: User
|
||||
): Promise<boolean> {
|
||||
): boolean {
|
||||
const rightNow = new Date()
|
||||
|
||||
const database = await acquireConnection()
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const result = database
|
||||
.prepare(
|
||||
|
|
@ -46,7 +48,7 @@ export default async function completeWorkOrderMilestone(
|
|||
milestoneForm.workOrderMilestoneId
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return result.changes > 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
import { dateToString } from '@cityssm/utils-datetime';
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
import addContract from './addContract.js';
|
||||
import addContractComment from './addContractComment.js';
|
||||
import addContractInterment from './addContractInterment.js';
|
||||
import getContract from './getContract.js';
|
||||
import { acquireConnection } from './pool.js';
|
||||
// eslint-disable-next-line complexity
|
||||
export default async function copyContract(oldContractId, user) {
|
||||
const database = await acquireConnection();
|
||||
const database = sqlite(sunriseDB);
|
||||
const oldContract = (await getContract(oldContractId, database));
|
||||
const newContractId = await addContract({
|
||||
const newContractId = addContract({
|
||||
burialSiteId: oldContract.burialSiteId ?? '',
|
||||
contractEndDateString: '',
|
||||
contractStartDateString: dateToString(new Date()),
|
||||
|
|
@ -44,7 +45,7 @@ export default async function copyContract(oldContractId, user) {
|
|||
* Copy Interments
|
||||
*/
|
||||
for (const interment of oldContract.contractInterments ?? []) {
|
||||
await addContractInterment({
|
||||
addContractInterment({
|
||||
birthDateString: interment.birthDateString ?? '',
|
||||
birthPlace: interment.birthPlace ?? '',
|
||||
contractId: newContractId,
|
||||
|
|
@ -64,10 +65,10 @@ export default async function copyContract(oldContractId, user) {
|
|||
/*
|
||||
* Add Comment
|
||||
*/
|
||||
await addContractComment({
|
||||
addContractComment({
|
||||
comment: `New record copied from #${oldContractId}.`,
|
||||
contractId: newContractId
|
||||
}, user);
|
||||
database.release();
|
||||
database.close();
|
||||
return newContractId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,24 @@
|
|||
import { dateToString } from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
import type { Contract } from '../types/record.types.js'
|
||||
|
||||
import addContract from './addContract.js'
|
||||
import addContractComment from './addContractComment.js'
|
||||
import addContractInterment from './addContractInterment.js'
|
||||
import getContract from './getContract.js'
|
||||
import { acquireConnection } from './pool.js'
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
export default async function copyContract(
|
||||
oldContractId: number | string,
|
||||
user: User
|
||||
): Promise<number> {
|
||||
const database = await acquireConnection()
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const oldContract = (await getContract(oldContractId, database)) as Contract
|
||||
|
||||
const newContractId = await addContract(
|
||||
const newContractId = addContract(
|
||||
{
|
||||
burialSiteId: oldContract.burialSiteId ?? '',
|
||||
contractEndDateString: '',
|
||||
|
|
@ -74,7 +75,7 @@ export default async function copyContract(
|
|||
*/
|
||||
|
||||
for (const interment of oldContract.contractInterments ?? []) {
|
||||
await addContractInterment(
|
||||
addContractInterment(
|
||||
{
|
||||
birthDateString: interment.birthDateString ?? '',
|
||||
birthPlace: interment.birthPlace ?? '',
|
||||
|
|
@ -102,7 +103,7 @@ export default async function copyContract(
|
|||
* Add Comment
|
||||
*/
|
||||
|
||||
await addContractComment(
|
||||
addContractComment(
|
||||
{
|
||||
comment: `New record copied from #${oldContractId}.`,
|
||||
contractId: newContractId
|
||||
|
|
@ -110,7 +111,7 @@ export default async function copyContract(
|
|||
user
|
||||
)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return newContractId
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
export declare function deleteBurialSite(burialSiteId: number, user: User): Promise<boolean>;
|
||||
export declare function deleteBurialSite(burialSiteId: number, user: User): boolean;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { dateToInteger } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export async function deleteBurialSite(burialSiteId, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export function deleteBurialSite(burialSiteId, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
/*
|
||||
* Ensure no active contracts reference the burial site
|
||||
*/
|
||||
|
|
@ -15,7 +16,7 @@ export async function deleteBurialSite(burialSiteId, user) {
|
|||
.pluck()
|
||||
.get(burialSiteId, currentDateInteger);
|
||||
if (activeContract !== undefined) {
|
||||
database.release();
|
||||
database.close();
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
|
|
@ -46,6 +47,6 @@ export async function deleteBurialSite(burialSiteId, user) {
|
|||
where burialSiteId = ?
|
||||
and recordDelete_timeMillis is null`)
|
||||
.run(user.userName, rightNowMillis, burialSiteId);
|
||||
database.release();
|
||||
database.close();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import { dateToInteger } from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export async function deleteBurialSite(
|
||||
burialSiteId: number,
|
||||
user: User
|
||||
): Promise<boolean> {
|
||||
const database = await acquireConnection()
|
||||
export function deleteBurialSite(burialSiteId: number, user: User): boolean {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
/*
|
||||
* Ensure no active contracts reference the burial site
|
||||
|
|
@ -26,7 +24,7 @@ export async function deleteBurialSite(
|
|||
.get(burialSiteId, currentDateInteger) as number | undefined
|
||||
|
||||
if (activeContract !== undefined) {
|
||||
database.release()
|
||||
database.close()
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +68,7 @@ export async function deleteBurialSite(
|
|||
)
|
||||
.run(user.userName, rightNowMillis, burialSiteId)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool';
|
||||
export default function deleteBurialSiteField(burialSiteId: number | string, burialSiteTypeFieldId: number | string, user: User, connectedDatabase?: PoolConnection): Promise<boolean>;
|
||||
import sqlite from 'better-sqlite3';
|
||||
export default function deleteBurialSiteField(burialSiteId: number | string, burialSiteTypeFieldId: number | string, user: User, connectedDatabase?: sqlite.Database): boolean;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function deleteBurialSiteField(burialSiteId, burialSiteTypeFieldId, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? (await acquireConnection());
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function deleteBurialSiteField(burialSiteId, burialSiteTypeFieldId, user, connectedDatabase) {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB);
|
||||
const result = database
|
||||
.prepare(`update BurialSiteFields
|
||||
set recordDelete_userName = ?,
|
||||
|
|
@ -9,7 +10,7 @@ export default async function deleteBurialSiteField(burialSiteId, burialSiteType
|
|||
and burialSiteTypeFieldId = ?`)
|
||||
.run(user.userName, Date.now(), burialSiteId, burialSiteTypeFieldId);
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release();
|
||||
database.close();
|
||||
}
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import type { PoolConnection } from 'better-sqlite-pool'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export default async function deleteBurialSiteField(
|
||||
export default function deleteBurialSiteField(
|
||||
burialSiteId: number | string,
|
||||
burialSiteTypeFieldId: number | string,
|
||||
user: User,
|
||||
connectedDatabase?: PoolConnection
|
||||
): Promise<boolean> {
|
||||
const database = connectedDatabase ?? (await acquireConnection())
|
||||
connectedDatabase?: sqlite.Database
|
||||
): boolean {
|
||||
const database = connectedDatabase ?? sqlite(sunriseDB)
|
||||
|
||||
const result = database
|
||||
.prepare(
|
||||
|
|
@ -21,7 +21,7 @@ export default async function deleteBurialSiteField(
|
|||
.run(user.userName, Date.now(), burialSiteId, burialSiteTypeFieldId)
|
||||
|
||||
if (connectedDatabase === undefined) {
|
||||
database.release()
|
||||
database.close()
|
||||
}
|
||||
|
||||
return result.changes > 0
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
export default function deleteCemetery(cemeteryId: number | string, user: User): Promise<boolean>;
|
||||
export default function deleteCemetery(cemeteryId: number | string, user: User): boolean;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { dateToInteger } from '@cityssm/utils-datetime';
|
||||
import { acquireConnection } from './pool.js';
|
||||
export default async function deleteCemetery(cemeteryId, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function deleteCemetery(cemeteryId, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
/*
|
||||
* Ensure no active contracts reference the cemetery
|
||||
*/
|
||||
|
|
@ -16,7 +17,7 @@ export default async function deleteCemetery(cemeteryId, user) {
|
|||
.pluck()
|
||||
.get(cemeteryId, currentDateInteger);
|
||||
if (activeContract !== undefined) {
|
||||
database.release();
|
||||
database.close();
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
|
|
@ -56,6 +57,6 @@ export default async function deleteCemetery(cemeteryId, user) {
|
|||
select burialSiteId from BurialSites where cemeteryId = ?)
|
||||
and recordDelete_timeMillis is null`)
|
||||
.run(user.userName, rightNowMillis, cemeteryId);
|
||||
database.release();
|
||||
database.close();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import { dateToInteger } from '@cityssm/utils-datetime'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
import { acquireConnection } from './pool.js'
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export default async function deleteCemetery(
|
||||
export default function deleteCemetery(
|
||||
cemeteryId: number | string,
|
||||
user: User
|
||||
): Promise<boolean> {
|
||||
const database = await acquireConnection()
|
||||
): boolean {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
/*
|
||||
* Ensure no active contracts reference the cemetery
|
||||
|
|
@ -27,7 +28,7 @@ export default async function deleteCemetery(
|
|||
.get(cemeteryId, currentDateInteger) as number | undefined
|
||||
|
||||
if (activeContract !== undefined) {
|
||||
database.release()
|
||||
database.close()
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +84,7 @@ export default async function deleteCemetery(
|
|||
)
|
||||
.run(user.userName, rightNowMillis, cemeteryId)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
export default function deleteContractFee(contractId: number | string, feeId: number | string, user: User): Promise<boolean>;
|
||||
export default function deleteContractFee(contractId: number | string, feeId: number | string, user: User): boolean;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { acquireConnection } from './pool.js';
|
||||
export default async function deleteContractFee(contractId, feeId, user) {
|
||||
const database = await acquireConnection();
|
||||
import sqlite from 'better-sqlite3';
|
||||
import { sunriseDB } from '../helpers/database.helpers.js';
|
||||
export default function deleteContractFee(contractId, feeId, user) {
|
||||
const database = sqlite(sunriseDB);
|
||||
const result = database
|
||||
.prepare(`update ContractFees
|
||||
set recordDelete_userName = ?,
|
||||
|
|
@ -8,6 +9,6 @@ export default async function deleteContractFee(contractId, feeId, user) {
|
|||
where contractId = ?
|
||||
and feeId = ?`)
|
||||
.run(user.userName, Date.now(), contractId, feeId);
|
||||
database.release();
|
||||
database.close();
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import { acquireConnection } from './pool.js'
|
||||
import sqlite from 'better-sqlite3'
|
||||
|
||||
export default async function deleteContractFee(
|
||||
import { sunriseDB } from '../helpers/database.helpers.js'
|
||||
|
||||
export default function deleteContractFee(
|
||||
contractId: number | string,
|
||||
feeId: number | string,
|
||||
user: User
|
||||
): Promise<boolean> {
|
||||
const database = await acquireConnection()
|
||||
): boolean {
|
||||
const database = sqlite(sunriseDB)
|
||||
|
||||
const result = database
|
||||
.prepare(
|
||||
|
|
@ -17,7 +19,7 @@ export default async function deleteContractFee(
|
|||
)
|
||||
.run(user.userName, Date.now(), contractId, feeId)
|
||||
|
||||
database.release()
|
||||
database.close()
|
||||
|
||||
return result.changes > 0
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue