sunrise-cms/database/updateRecordOrderNumber.ts

47 lines
1.3 KiB
TypeScript

import type { PoolConnection } from 'better-sqlite-pool'
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: PoolConnection
): 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
}