47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import type sqlite from 'better-sqlite3'
|
|
|
|
type RecordTable =
|
|
| 'BurialSiteStatuses'
|
|
| 'BurialSiteTypeFields'
|
|
| 'BurialSiteTypes'
|
|
| 'CommittalTypes'
|
|
| 'ContractTypeFields'
|
|
| 'ContractTypes'
|
|
| 'FeeCategories'
|
|
| 'Fees'
|
|
| 'IntermentContainerTypes'
|
|
| 'WorkOrderMilestoneTypes'
|
|
| 'WorkOrderTypes'
|
|
|
|
const recordIdColumns = new Map<RecordTable, string>([
|
|
['BurialSiteStatuses', 'burialSiteStatusId'],
|
|
['BurialSiteTypeFields', 'burialSiteTypeFieldId'],
|
|
['BurialSiteTypes', 'burialSiteTypeId'],
|
|
['CommittalTypes', 'committalTypeId'],
|
|
['ContractTypeFields', 'contractTypeFieldId'],
|
|
['ContractTypes', 'contractTypeId'],
|
|
['FeeCategories', 'feeCategoryId'],
|
|
['Fees', 'feeId'],
|
|
['IntermentContainerTypes', 'intermentContainerTypeId'],
|
|
['WorkOrderMilestoneTypes', 'workOrderMilestoneTypeId'],
|
|
['WorkOrderTypes', 'workOrderTypeId']
|
|
])
|
|
|
|
export function updateRecordOrderNumber(
|
|
recordTable: RecordTable,
|
|
recordId: number | string,
|
|
orderNumber: number | string,
|
|
connectedDatabase: sqlite.Database
|
|
): boolean {
|
|
const result = connectedDatabase
|
|
.prepare(
|
|
`update ${recordTable}
|
|
set orderNumber = ?
|
|
where recordDelete_timeMillis is null
|
|
and ${recordIdColumns.get(recordTable)} = ?`
|
|
)
|
|
.run(orderNumber, recordId)
|
|
|
|
return result.changes > 0
|
|
}
|