updated type syntax

deepsource-autofix-76c6eb20
Dan Gowans 2023-04-13 10:16:48 -04:00
parent 7ba2712d93
commit 93de43ae62
49 changed files with 238 additions and 184 deletions

View File

@ -48,18 +48,18 @@ export async function addLotOccupancyFee(
} }
// Check if record already exists // Check if record already exists
const record: { const record = database
feeAmount?: number
taxAmount?: number
recordDelete_timeMillis?: number
} = database
.prepare( .prepare(
`select feeAmount, taxAmount, recordDelete_timeMillis `select feeAmount, taxAmount, recordDelete_timeMillis
from LotOccupancyFees from LotOccupancyFees
where lotOccupancyId = ? where lotOccupancyId = ?
and feeId = ?` and feeId = ?`
) )
.get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId) .get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId) as {
feeAmount?: number
taxAmount?: number
recordDelete_timeMillis?: number
}
if (record) { if (record) {
if (record.recordDelete_timeMillis) { if (record.recordDelete_timeMillis) {

View File

@ -27,7 +27,7 @@ export async function addLotOccupancyOccupant(
let lotOccupantIndex = 0 let lotOccupantIndex = 0
const maxIndexResult: { lotOccupantIndex: number } | undefined = database const maxIndexResult = database
.prepare( .prepare(
`select lotOccupantIndex `select lotOccupantIndex
from LotOccupancyOccupants from LotOccupancyOccupants
@ -35,7 +35,9 @@ export async function addLotOccupancyOccupant(
order by lotOccupantIndex desc order by lotOccupantIndex desc
limit 1` limit 1`
) )
.get(lotOccupancyOccupantForm.lotOccupancyId) .get(lotOccupancyOccupantForm.lotOccupancyId) as
| { lotOccupantIndex: number }
| undefined
if (maxIndexResult !== undefined) { if (maxIndexResult !== undefined) {
lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1 lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1

View File

@ -26,7 +26,7 @@ export async function addLotOccupancyTransaction(
let transactionIndex = 0 let transactionIndex = 0
const maxIndexResult: { transactionIndex: number } | undefined = database const maxIndexResult = database
.prepare( .prepare(
`select transactionIndex `select transactionIndex
from LotOccupancyTransactions from LotOccupancyTransactions
@ -34,7 +34,9 @@ export async function addLotOccupancyTransaction(
order by transactionIndex desc order by transactionIndex desc
limit 1` limit 1`
) )
.get(lotOccupancyTransactionForm.lotOccupancyId) .get(lotOccupancyTransactionForm.lotOccupancyId) as
| { transactionIndex: number }
| undefined
if (maxIndexResult !== undefined) { if (maxIndexResult !== undefined) {
transactionIndex = maxIndexResult.transactionIndex + 1 transactionIndex = maxIndexResult.transactionIndex + 1

View File

@ -15,14 +15,16 @@ export async function addWorkOrderLot(
const rightNowMillis = Date.now() const rightNowMillis = Date.now()
const row: { recordDelete_timeMillis?: number } = database const row = database
.prepare( .prepare(
`select recordDelete_timeMillis `select recordDelete_timeMillis
from WorkOrderLots from WorkOrderLots
where workOrderId = ? where workOrderId = ?
and lotId = ?` and lotId = ?`
) )
.get(workOrderLotForm.workOrderId, workOrderLotForm.lotId) .get(workOrderLotForm.workOrderId, workOrderLotForm.lotId) as {
recordDelete_timeMillis?: number
}
if (row === undefined) { if (row === undefined) {
database database

View File

@ -27,7 +27,7 @@ export async function getFee(
where f.recordDelete_timeMillis is null where f.recordDelete_timeMillis is null
and f.feeId = ?` and f.feeId = ?`
) )
.get(feeId) .get(feeId) as recordTypes.Fee
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release() database.release()

View File

@ -47,14 +47,14 @@ export async function getFeeCategories(
sqlParameters.push(filters.lotTypeId) sqlParameters.push(filters.lotTypeId)
} }
const feeCategories: recordTypes.FeeCategory[] = database const feeCategories = database
.prepare( .prepare(
'select feeCategoryId, feeCategory, orderNumber' + 'select feeCategoryId, feeCategory, orderNumber' +
' from FeeCategories' + ' from FeeCategories' +
sqlWhereClause + sqlWhereClause +
' order by orderNumber, feeCategory' ' order by orderNumber, feeCategory'
) )
.all(sqlParameters) .all(sqlParameters) as recordTypes.FeeCategory[]
if (options.includeFees ?? false) { if (options.includeFees ?? false) {
let expectedOrderNumber = 0 let expectedOrderNumber = 0

View File

@ -39,7 +39,7 @@ export async function getFees(
sqlParameters.push(additionalFilters.lotTypeId) sqlParameters.push(additionalFilters.lotTypeId)
} }
const fees: recordTypes.Fee[] = database const fees = database
.prepare( .prepare(
`select f.feeId, f.feeName, f.feeDescription, `select f.feeId, f.feeName, f.feeDescription,
f.occupancyTypeId, o.occupancyType, f.occupancyTypeId, o.occupancyType,
@ -62,7 +62,7 @@ export async function getFees(
${sqlWhereClause} ${sqlWhereClause}
order by f.orderNumber, f.feeName` order by f.orderNumber, f.feeName`
) )
.all(sqlParameters) .all(sqlParameters) as recordTypes.Fee[]
if (updateOrderNumbers) { if (updateOrderNumbers) {
let expectedOrderNumber = 0 let expectedOrderNumber = 0

View File

@ -23,7 +23,7 @@ async function _getLot(
): Promise<recordTypes.Lot | undefined> { ): Promise<recordTypes.Lot | undefined> {
const database = await acquireConnection() const database = await acquireConnection()
const lot: recordTypes.Lot = database.prepare(sql).get(lotIdOrLotName) const lot = database.prepare(sql).get(lotIdOrLotName) as recordTypes.Lot | undefined
if (lot !== undefined) { if (lot !== undefined) {
const lotOccupancies = await getLotOccupancies( const lotOccupancies = await getLotOccupancies(

View File

@ -33,7 +33,7 @@ export async function getLotComments(
and lotId = ? and lotId = ?
order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc` order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc`
) )
.all(lotId) .all(lotId) as recordTypes.LotComment[]
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release() database.release()

View File

@ -9,7 +9,7 @@ export async function getLotFields(
): Promise<recordTypes.LotField[]> { ): Promise<recordTypes.LotField[]> {
const database = connectedDatabase ?? (await acquireConnection()) const database = connectedDatabase ?? (await acquireConnection())
const lotFields: recordTypes.LotField[] = database const lotFields = database
.prepare( .prepare(
`select l.lotId, l.lotTypeFieldId, `select l.lotId, l.lotTypeFieldId,
l.lotFieldValue, l.lotFieldValue,
@ -38,7 +38,7 @@ export async function getLotFields(
and f.lotTypeFieldId not in (select lotTypeFieldId from LotFields where lotId = ? and recordDelete_timeMillis is null) and f.lotTypeFieldId not in (select lotTypeFieldId from LotFields where lotId = ? and recordDelete_timeMillis is null)
order by lotTypeOrderNumber, f.orderNumber, f.lotTypeField` order by lotTypeOrderNumber, f.orderNumber, f.lotTypeField`
) )
.all(lotId, lotId, lotId, lotId) .all(lotId, lotId, lotId, lotId) as recordTypes.LotField[]
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release() database.release()

View File

@ -180,14 +180,16 @@ export async function getLotOccupancies(
const isLimited = options.limit !== -1 const isLimited = options.limit !== -1
if (isLimited) { if (isLimited) {
count = database count = (
.prepare( database
`select count(*) as recordCount .prepare(
`select count(*) as recordCount
from LotOccupancies o from LotOccupancies o
left join Lots l on o.lotId = l.lotId left join Lots l on o.lotId = l.lotId
${sqlWhereClause}` ${sqlWhereClause}`
) )
.get(sqlParameters).recordCount .get(sqlParameters) as { recordCount: number }
).recordCount
} }
let lotOccupancies: recordTypes.LotOccupancy[] = [] let lotOccupancies: recordTypes.LotOccupancy[] = []
@ -210,7 +212,7 @@ export async function getLotOccupancies(
order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc` + order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc` +
(isLimited ? ` limit ${options.limit} offset ${options.offset}` : '') (isLimited ? ` limit ${options.limit} offset ${options.offset}` : '')
) )
.all(sqlParameters) .all(sqlParameters) as recordTypes.LotOccupancy[]
if (!isLimited) { if (!isLimited) {
count = lotOccupancies.length count = lotOccupancies.length

View File

@ -20,7 +20,7 @@ export async function getLotOccupancy(
database.function('userFn_dateIntegerToString', dateIntegerToString) database.function('userFn_dateIntegerToString', dateIntegerToString)
const lotOccupancy: recordTypes.LotOccupancy | undefined = database const lotOccupancy = database
.prepare( .prepare(
`select o.lotOccupancyId, `select o.lotOccupancyId,
o.occupancyTypeId, t.occupancyType, o.occupancyTypeId, t.occupancyType,
@ -36,7 +36,7 @@ export async function getLotOccupancy(
where o.recordDelete_timeMillis is null where o.recordDelete_timeMillis is null
and o.lotOccupancyId = ?` and o.lotOccupancyId = ?`
) )
.get(lotOccupancyId) .get(lotOccupancyId) as recordTypes.LotOccupancy | undefined
if (lotOccupancy !== undefined) { if (lotOccupancy !== undefined) {
lotOccupancy.lotOccupancyFields = await getLotOccupancyFields( lotOccupancy.lotOccupancyFields = await getLotOccupancyFields(

View File

@ -33,7 +33,7 @@ export async function getLotOccupancyComments(
and lotOccupancyId = ? and lotOccupancyId = ?
order by lotOccupancyCommentDate desc, lotOccupancyCommentTime desc, lotOccupancyCommentId desc` order by lotOccupancyCommentDate desc, lotOccupancyCommentTime desc, lotOccupancyCommentId desc`
) )
.all(lotOccupancyId) .all(lotOccupancyId) as recordTypes.LotOccupancyComment[]
if (connectedDatabase === null) { if (connectedDatabase === null) {
database.release() database.release()

View File

@ -9,7 +9,7 @@ export async function getLotOccupancyFees(
): Promise<recordTypes.LotOccupancyFee[]> { ): Promise<recordTypes.LotOccupancyFee[]> {
const database = connectedDatabase ?? (await acquireConnection()) const database = connectedDatabase ?? (await acquireConnection())
const lotOccupancyFees: recordTypes.LotOccupancyFee[] = database const lotOccupancyFees = database
.prepare( .prepare(
`select o.lotOccupancyId, o.feeId, `select o.lotOccupancyId, o.feeId,
c.feeCategory, f.feeName, c.feeCategory, f.feeName,
@ -21,7 +21,7 @@ export async function getLotOccupancyFees(
and o.lotOccupancyId = ? and o.lotOccupancyId = ?
order by o.recordCreate_timeMillis` order by o.recordCreate_timeMillis`
) )
.all(lotOccupancyId) .all(lotOccupancyId) as recordTypes.LotOccupancyFee[]
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release() database.release()

View File

@ -9,7 +9,7 @@ export async function getLotOccupancyFields(
): Promise<recordTypes.LotOccupancyField[]> { ): Promise<recordTypes.LotOccupancyField[]> {
const database = connectedDatabase ?? (await acquireConnection()) const database = connectedDatabase ?? (await acquireConnection())
const lotOccupancyFields: recordTypes.LotOccupancyField[] = database const lotOccupancyFields = database
.prepare( .prepare(
`select o.lotOccupancyId, o.occupancyTypeFieldId, `select o.lotOccupancyId, o.occupancyTypeFieldId,
o.lotOccupancyFieldValue, f.occupancyTypeField, f.occupancyTypeFieldValues, o.lotOccupancyFieldValue, f.occupancyTypeField, f.occupancyTypeFieldValues,
@ -35,7 +35,7 @@ export async function getLotOccupancyFields(
and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null) and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null)
order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField` order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField`
) )
.all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId) .all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId) as recordTypes.LotOccupancyField[]
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release() database.release()

View File

@ -9,7 +9,7 @@ export async function getLotOccupancyOccupants(
): Promise<recordTypes.LotOccupancyOccupant[]> { ): Promise<recordTypes.LotOccupancyOccupant[]> {
const database = connectedDatabase ?? (await acquireConnection()) const database = connectedDatabase ?? (await acquireConnection())
const lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[] = database const lotOccupancyOccupants = database
.prepare( .prepare(
`select o.lotOccupancyId, o.lotOccupantIndex, `select o.lotOccupancyId, o.lotOccupantIndex,
o.occupantName, o.occupantFamilyName, o.occupantName, o.occupantFamilyName,
@ -25,7 +25,7 @@ export async function getLotOccupancyOccupants(
and o.lotOccupancyId = ? and o.lotOccupancyId = ?
order by t.orderNumber, t.lotOccupantType, o.occupantName, o.lotOccupantIndex` order by t.orderNumber, t.lotOccupantType, o.occupantName, o.lotOccupantIndex`
) )
.all(lotOccupancyId) .all(lotOccupancyId) as recordTypes.LotOccupancyOccupant[]
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release() database.release()

View File

@ -20,10 +20,9 @@ export async function getLotOccupancyTransactions(
database.function('userFn_dateIntegerToString', dateIntegerToString) database.function('userFn_dateIntegerToString', dateIntegerToString)
database.function('userFn_timeIntegerToString', timeIntegerToString) database.function('userFn_timeIntegerToString', timeIntegerToString)
const lotOccupancyTransactions: recordTypes.LotOccupancyTransaction[] = const lotOccupancyTransactions = database
database .prepare(
.prepare( `select lotOccupancyId, transactionIndex,
`select lotOccupancyId, transactionIndex,
transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString, transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString,
transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString, transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString,
transactionAmount, externalReceiptNumber, transactionNote transactionAmount, externalReceiptNumber, transactionNote
@ -31,8 +30,8 @@ export async function getLotOccupancyTransactions(
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
and lotOccupancyId = ? and lotOccupancyId = ?
order by transactionDate, transactionTime, transactionIndex` order by transactionDate, transactionTime, transactionIndex`
) )
.all(lotOccupancyId) .all(lotOccupancyId) as recordTypes.LotOccupancyTransaction[]
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release() database.release()

View File

@ -11,7 +11,7 @@ export async function getLotOccupantTypes(): Promise<
> { > {
const database = await acquireConnection() const database = await acquireConnection()
const lotOccupantTypes: recordTypes.LotOccupantType[] = database const lotOccupantTypes = database
.prepare( .prepare(
`select lotOccupantTypeId, lotOccupantType, fontAwesomeIconClass, occupantCommentTitle, `select lotOccupantTypeId, lotOccupantType, fontAwesomeIconClass, occupantCommentTitle,
orderNumber orderNumber
@ -19,7 +19,7 @@ export async function getLotOccupantTypes(): Promise<
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
order by orderNumber, lotOccupantType` order by orderNumber, lotOccupantType`
) )
.all() .all() as recordTypes.LotOccupantType[]
let expectedOrderNumber = 0 let expectedOrderNumber = 0

View File

@ -23,7 +23,7 @@ export async function getLotStatusSummary(
sqlParameters.push(filters.mapId) sqlParameters.push(filters.mapId)
} }
const lotStatuses: LotStatusSummary[] = database const lotStatuses = database
.prepare( .prepare(
`select s.lotStatusId, s.lotStatus, count(l.lotId) as lotCount `select s.lotStatusId, s.lotStatus, count(l.lotId) as lotCount
from Lots l from Lots l
@ -32,7 +32,7 @@ export async function getLotStatusSummary(
group by s.lotStatusId, s.lotStatus, s.orderNumber group by s.lotStatusId, s.lotStatus, s.orderNumber
order by s.orderNumber` order by s.orderNumber`
) )
.all(sqlParameters) .all(sqlParameters) as LotStatusSummary[]
database.release() database.release()

View File

@ -7,14 +7,14 @@ import type * as recordTypes from '../../types/recordTypes'
export async function getLotStatuses(): Promise<recordTypes.LotStatus[]> { export async function getLotStatuses(): Promise<recordTypes.LotStatus[]> {
const database = await acquireConnection() const database = await acquireConnection()
const lotStatuses: recordTypes.LotStatus[] = database const lotStatuses = database
.prepare( .prepare(
`select lotStatusId, lotStatus, orderNumber `select lotStatusId, lotStatus, orderNumber
from LotStatuses from LotStatuses
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
order by orderNumber, lotStatus` order by orderNumber, lotStatus`
) )
.all() .all() as recordTypes.LotStatus[]
let expectedOrderNumber = 0 let expectedOrderNumber = 0

View File

@ -10,7 +10,7 @@ export async function getLotTypeFields(
): Promise<recordTypes.LotTypeField[]> { ): Promise<recordTypes.LotTypeField[]> {
const database = connectedDatabase ?? (await acquireConnection()) const database = connectedDatabase ?? (await acquireConnection())
const lotTypeFields: recordTypes.LotTypeField[] = database const lotTypeFields = database
.prepare( .prepare(
`select lotTypeFieldId, `select lotTypeFieldId,
lotTypeField, lotTypeFieldValues, lotTypeField, lotTypeFieldValues,
@ -20,7 +20,7 @@ export async function getLotTypeFields(
and lotTypeId = ? and lotTypeId = ?
order by orderNumber, lotTypeField` order by orderNumber, lotTypeField`
) )
.all(lotTypeId) .all(lotTypeId) as recordTypes.LotTypeField[]
let expectedOrderNumber = 0 let expectedOrderNumber = 0

View File

@ -23,7 +23,7 @@ export async function getLotTypeSummary(
sqlParameters.push(filters.mapId) sqlParameters.push(filters.mapId)
} }
const lotTypes: LotTypeSummary[] = database const lotTypes = database
.prepare( .prepare(
`select t.lotTypeId, t.lotType, count(l.lotId) as lotCount `select t.lotTypeId, t.lotType, count(l.lotId) as lotCount
from Lots l from Lots l
@ -32,7 +32,7 @@ export async function getLotTypeSummary(
group by t.lotTypeId, t.lotType, t.orderNumber group by t.lotTypeId, t.lotType, t.orderNumber
order by t.orderNumber` order by t.orderNumber`
) )
.all(sqlParameters) .all(sqlParameters) as LotTypeSummary[]
database.release() database.release()

View File

@ -8,14 +8,14 @@ import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
export async function getLotTypes(): Promise<recordTypes.LotType[]> { export async function getLotTypes(): Promise<recordTypes.LotType[]> {
const database = await acquireConnection() const database = await acquireConnection()
const lotTypes: recordTypes.LotType[] = database const lotTypes = database
.prepare( .prepare(
`select lotTypeId, lotType, orderNumber `select lotTypeId, lotType, orderNumber
from LotTypes from LotTypes
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
order by orderNumber, lotType` order by orderNumber, lotType`
) )
.all() .all() as recordTypes.LotType[]
let expectedTypeOrderNumber = -1 let expectedTypeOrderNumber = -1

View File

@ -91,9 +91,10 @@ export async function getLots(
let count = 0 let count = 0
if (options.limit !== -1) { if (options.limit !== -1) {
count = database count = (
.prepare( database
`select count(*) as recordCount .prepare(
`select count(*) as recordCount
from Lots l from Lots l
left join ( left join (
select lotId, count(lotOccupancyId) as lotOccupancyCount from LotOccupancies select lotId, count(lotOccupancyId) as lotOccupancyCount from LotOccupancies
@ -103,8 +104,9 @@ export async function getLots(
group by lotId group by lotId
) o on l.lotId = o.lotId ) o on l.lotId = o.lotId
${sqlWhereClause}` ${sqlWhereClause}`
) )
.get(sqlParameters).recordCount .get(sqlParameters) as { recordCount: number }
).recordCount
} }
let lots: recordTypes.Lot[] = [] let lots: recordTypes.Lot[] = []
@ -155,7 +157,7 @@ export async function getLots(
: ` limit ${options.limit.toString()} offset ${options.offset.toString()}` : ` limit ${options.limit.toString()} offset ${options.offset.toString()}`
}` }`
) )
.all(sqlParameters) .all(sqlParameters) as recordTypes.Lot[]
if (options.limit === -1) { if (options.limit === -1) {
count = lots.length count = lots.length

View File

@ -7,7 +7,7 @@ export async function getMap(
): Promise<recordTypes.Map | undefined> { ): Promise<recordTypes.Map | undefined> {
const database = await acquireConnection() const database = await acquireConnection()
const map: recordTypes.Map = database const map = database
.prepare( .prepare(
`select m.mapId, m.mapName, m.mapDescription, `select m.mapId, m.mapName, m.mapDescription,
m.mapLatitude, m.mapLongitude, m.mapSVG, m.mapLatitude, m.mapLongitude, m.mapSVG,
@ -29,7 +29,7 @@ export async function getMap(
m.recordUpdate_userName, m.recordUpdate_timeMillis, m.recordUpdate_userName, m.recordUpdate_timeMillis,
m.recordDelete_userName, m.recordDelete_timeMillis` m.recordDelete_userName, m.recordDelete_timeMillis`
) )
.get(mapId) .get(mapId) as recordTypes.Map | undefined
database.release() database.release()

View File

@ -5,7 +5,7 @@ import type * as recordTypes from '../../types/recordTypes'
export async function getMaps(): Promise<recordTypes.Map[]> { export async function getMaps(): Promise<recordTypes.Map[]> {
const database = await acquireConnection() const database = await acquireConnection()
const maps: recordTypes.Map[] = database const maps = database
.prepare( .prepare(
`select m.mapId, m.mapName, m.mapDescription, `select m.mapId, m.mapName, m.mapDescription,
m.mapLatitude, m.mapLongitude, m.mapSVG, m.mapLatitude, m.mapLongitude, m.mapSVG,
@ -20,7 +20,7 @@ export async function getMaps(): Promise<recordTypes.Map[]> {
) l on m.mapId = l.mapId ) l on m.mapId = l.mapId
where m.recordDelete_timeMillis is null order by m.mapName, m.mapId` where m.recordDelete_timeMillis is null order by m.mapName, m.mapId`
) )
.all() .all() as recordTypes.Map[]
database.release() database.release()

View File

@ -12,9 +12,7 @@ export async function getNextLotId(
configFunctions.getProperty('settings.lot.lotNameSortNameFunction') configFunctions.getProperty('settings.lot.lotNameSortNameFunction')
) )
const result: { const result = database
lotId: number
} = database
.prepare( .prepare(
`select lotId `select lotId
from Lots from Lots
@ -23,7 +21,9 @@ export async function getNextLotId(
order by userFn_lotNameSortName(lotName) order by userFn_lotNameSortName(lotName)
limit 1` limit 1`
) )
.get(lotId) .get(lotId) as {
lotId: number
}
database.release() database.release()

View File

@ -5,9 +5,7 @@ export async function getNextMapId(
): Promise<number | undefined> { ): Promise<number | undefined> {
const database = await acquireConnection() const database = await acquireConnection()
const result: { const result = database
mapId: number
} = database
.prepare( .prepare(
`select mapId `select mapId
from Maps from Maps
@ -16,7 +14,9 @@ export async function getNextMapId(
order by mapName order by mapName
limit 1` limit 1`
) )
.get(mapId) .get(mapId) as {
mapId: number
}
database.release() database.release()

View File

@ -28,7 +28,9 @@ export async function getNextWorkOrderNumber(
where userFn_matchesWorkOrderNumberSyntax(workOrderNumber) = 1 where userFn_matchesWorkOrderNumberSyntax(workOrderNumber) = 1
order by cast(substr(workOrderNumber, instr(workOrderNumber, '-') + 1) as integer) desc` order by cast(substr(workOrderNumber, instr(workOrderNumber, '-') + 1) as integer) desc`
) )
.get() .get() as {
workOrderNumber: string
}
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release() database.release()

View File

@ -16,7 +16,7 @@ export async function getOccupancyTypeFields(
sqlParameters.push(occupancyTypeId) sqlParameters.push(occupancyTypeId)
} }
const occupancyTypeFields: recordTypes.OccupancyTypeField[] = database const occupancyTypeFields = database
.prepare( .prepare(
'select occupancyTypeFieldId,' + 'select occupancyTypeFieldId,' +
' occupancyTypeField, occupancyTypeFieldValues, isRequired, pattern,' + ' occupancyTypeField, occupancyTypeFieldValues, isRequired, pattern,' +
@ -29,7 +29,7 @@ export async function getOccupancyTypeFields(
: ' and occupancyTypeId = ?') + : ' and occupancyTypeId = ?') +
' order by orderNumber, occupancyTypeField' ' order by orderNumber, occupancyTypeField'
) )
.all(sqlParameters) .all(sqlParameters) as recordTypes.OccupancyTypeField[]
let expectedOrderNumber = 0 let expectedOrderNumber = 0

View File

@ -27,7 +27,7 @@ export async function getOccupancyTypePrints(
userFunction_configContainsPrintEJS userFunction_configContainsPrintEJS
) )
const results: Array<{ printEJS: string; orderNumber: number }> = database const results = database
.prepare( .prepare(
`select printEJS, orderNumber `select printEJS, orderNumber
from OccupancyTypePrints from OccupancyTypePrints
@ -36,7 +36,7 @@ export async function getOccupancyTypePrints(
and userFn_configContainsPrintEJS(printEJS) = 1 and userFn_configContainsPrintEJS(printEJS) = 1
order by orderNumber, printEJS` order by orderNumber, printEJS`
) )
.all(occupancyTypeId) .all(occupancyTypeId) as Array<{ printEJS: string; orderNumber: number }>
let expectedOrderNumber = -1 let expectedOrderNumber = -1

View File

@ -13,14 +13,14 @@ export async function getOccupancyTypes(): Promise<
> { > {
const database = await acquireConnection() const database = await acquireConnection()
const occupancyTypes: recordTypes.OccupancyType[] = database const occupancyTypes = database
.prepare( .prepare(
`select occupancyTypeId, occupancyType, orderNumber `select occupancyTypeId, occupancyType, orderNumber
from OccupancyTypes from OccupancyTypes
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
order by orderNumber, occupancyType` order by orderNumber, occupancyType`
) )
.all() .all() as recordTypes.OccupancyType[]
let expectedTypeOrderNumber = -1 let expectedTypeOrderNumber = -1

View File

@ -61,9 +61,9 @@ export async function getPastLotOccupancyOccupants(
order by lotOccupancyIdCount desc, recordUpdate_timeMillisMax desc order by lotOccupancyIdCount desc, recordUpdate_timeMillisMax desc
limit ${options.limit}` limit ${options.limit}`
const lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[] = database const lotOccupancyOccupants = database
.prepare(sql) .prepare(sql)
.all(sqlParameters) .all(sqlParameters) as recordTypes.LotOccupancyOccupant[]
database.release() database.release()

View File

@ -12,9 +12,7 @@ export async function getPreviousLotId(
configFunctions.getProperty('settings.lot.lotNameSortNameFunction') configFunctions.getProperty('settings.lot.lotNameSortNameFunction')
) )
const result: { const result = database
lotId: number
} = database
.prepare( .prepare(
`select lotId from Lots `select lotId from Lots
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
@ -22,7 +20,9 @@ export async function getPreviousLotId(
order by userFn_lotNameSortName(lotName) desc order by userFn_lotNameSortName(lotName) desc
limit 1` limit 1`
) )
.get(lotId) .get(lotId) as {
lotId: number
}
database.release() database.release()

View File

@ -5,9 +5,7 @@ export async function getPreviousMapId(
): Promise<number | undefined> { ): Promise<number | undefined> {
const database = await acquireConnection() const database = await acquireConnection()
const result: { const result = database
mapId: number
} = database
.prepare( .prepare(
`select mapId from Maps `select mapId from Maps
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
@ -15,7 +13,9 @@ export async function getPreviousMapId(
order by mapName desc order by mapName desc
limit 1` limit 1`
) )
.get(mapId) .get(mapId) as {
mapId: number
}
database.release() database.release()

View File

@ -16,9 +16,7 @@ const baseSQL = `select w.workOrderId,
async function _getWorkOrder(sql, workOrderIdOrWorkOrderNumber, options, connectedDatabase) { async function _getWorkOrder(sql, workOrderIdOrWorkOrderNumber, options, connectedDatabase) {
const database = connectedDatabase ?? (await acquireConnection()); const database = connectedDatabase ?? (await acquireConnection());
database.function('userFn_dateIntegerToString', dateIntegerToString); database.function('userFn_dateIntegerToString', dateIntegerToString);
const workOrder = database const workOrder = database.prepare(sql).get(workOrderIdOrWorkOrderNumber);
.prepare(sql)
.get(workOrderIdOrWorkOrderNumber);
if (workOrder !== undefined) { if (workOrder !== undefined) {
if (options.includeLotsAndLotOccupancies) { if (options.includeLotsAndLotOccupancies) {
const workOrderLotsResults = await getLots({ const workOrderLotsResults = await getLots({

View File

@ -39,9 +39,9 @@ async function _getWorkOrder(
database.function('userFn_dateIntegerToString', dateIntegerToString) database.function('userFn_dateIntegerToString', dateIntegerToString)
const workOrder: recordTypes.WorkOrder = database const workOrder = database.prepare(sql).get(workOrderIdOrWorkOrderNumber) as
.prepare(sql) | recordTypes.WorkOrder
.get(workOrderIdOrWorkOrderNumber) | undefined
if (workOrder !== undefined) { if (workOrder !== undefined) {
if (options.includeLotsAndLotOccupancies) { if (options.includeLotsAndLotOccupancies) {

View File

@ -33,7 +33,7 @@ export async function getWorkOrderComments(
and workOrderId = ? and workOrderId = ?
order by workOrderCommentDate desc, workOrderCommentTime desc, workOrderCommentId desc` order by workOrderCommentDate desc, workOrderCommentTime desc, workOrderCommentId desc`
) )
.all(workOrderId) .all(workOrderId) as recordTypes.WorkOrderComment[]
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release() database.release()

View File

@ -7,14 +7,14 @@ import type * as recordTypes from '../../types/recordTypes'
export async function getWorkOrderMilestoneTypes(): Promise<recordTypes.WorkOrderMilestoneType[]> { export async function getWorkOrderMilestoneTypes(): Promise<recordTypes.WorkOrderMilestoneType[]> {
const database = await acquireConnection() const database = await acquireConnection()
const workOrderMilestoneTypes: recordTypes.WorkOrderMilestoneType[] = database const workOrderMilestoneTypes = database
.prepare( .prepare(
`select workOrderMilestoneTypeId, workOrderMilestoneType, orderNumber `select workOrderMilestoneTypeId, workOrderMilestoneType, orderNumber
from WorkOrderMilestoneTypes from WorkOrderMilestoneTypes
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
order by orderNumber, workOrderMilestoneType` order by orderNumber, workOrderMilestoneType`
) )
.all() .all() as recordTypes.WorkOrderMilestoneType[]
let expectedOrderNumber = 0 let expectedOrderNumber = 0

View File

@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/indent */
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
import type { PoolConnection } from 'better-sqlite-pool' import type { PoolConnection } from 'better-sqlite-pool'
@ -18,7 +20,12 @@ import type * as recordTypes from '../../types/recordTypes'
export interface WorkOrderMilestoneFilters { export interface WorkOrderMilestoneFilters {
workOrderId?: number | string workOrderId?: number | string
workOrderMilestoneDateFilter?: 'upcomingMissed' | 'recent' | 'date' | 'blank' | 'notBlank' workOrderMilestoneDateFilter?:
| 'upcomingMissed'
| 'recent'
| 'date'
| 'blank'
| 'notBlank'
workOrderMilestoneDateString?: string workOrderMilestoneDateString?: string
workOrderTypeIds?: string workOrderTypeIds?: string
workOrderMilestoneTypeIds?: string workOrderMilestoneTypeIds?: string
@ -134,7 +141,10 @@ export async function getWorkOrderMilestones(
database.function('userFn_dateIntegerToString', dateIntegerToString) database.function('userFn_dateIntegerToString', dateIntegerToString)
database.function('userFn_timeIntegerToString', timeIntegerToString) database.function('userFn_timeIntegerToString', timeIntegerToString)
database.function('userFn_timeIntegerToPeriodString', timeIntegerToPeriodString) database.function(
'userFn_timeIntegerToPeriodString',
timeIntegerToPeriodString
)
// Filters // Filters
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters) const { sqlWhereClause, sqlParameters } = buildWhereClause(filters)
@ -188,9 +198,9 @@ export async function getWorkOrderMilestones(
sqlWhereClause + sqlWhereClause +
orderByClause orderByClause
const workOrderMilestones: recordTypes.WorkOrderMilestone[] = database const workOrderMilestones = database
.prepare(sql) .prepare(sql)
.all(sqlParameters) .all(sqlParameters) as recordTypes.WorkOrderMilestone[]
if (options.includeWorkOrders ?? false) { if (options.includeWorkOrders ?? false) {
for (const workOrderMilestone of workOrderMilestones) { for (const workOrderMilestone of workOrderMilestones) {

View File

@ -11,14 +11,14 @@ export async function getWorkOrderTypes(): Promise<
> { > {
const database = await acquireConnection() const database = await acquireConnection()
const workOrderTypes: recordTypes.WorkOrderType[] = database const workOrderTypes = database
.prepare( .prepare(
`select workOrderTypeId, workOrderType, orderNumber `select workOrderTypeId, workOrderType, orderNumber
from WorkOrderTypes from WorkOrderTypes
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
order by orderNumber, workOrderType` order by orderNumber, workOrderType`
) )
.all() .all() as recordTypes.WorkOrderType[]
let expectedOrderNumber = 0 let expectedOrderNumber = 0
@ -26,7 +26,7 @@ export async function getWorkOrderTypes(): Promise<
if (workOrderType.orderNumber !== expectedOrderNumber) { if (workOrderType.orderNumber !== expectedOrderNumber) {
updateRecordOrderNumber( updateRecordOrderNumber(
'WorkOrderTypes', 'WorkOrderTypes',
workOrderType.workOrderTypeId!, workOrderType.workOrderTypeId,
expectedOrderNumber, expectedOrderNumber,
database database
) )

View File

@ -176,13 +176,15 @@ export async function getWorkOrders(
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters) const { sqlWhereClause, sqlParameters } = buildWhereClause(filters)
const count: number = database const count: number = (
.prepare( database
`select count(*) as recordCount .prepare(
`select count(*) as recordCount
from WorkOrders w from WorkOrders w
${sqlWhereClause}` ${sqlWhereClause}`
) )
.get(sqlParameters).recordCount .get(sqlParameters) as { recordCount: number }
).recordCount
let workOrders: recordTypes.WorkOrder[] = [] let workOrders: recordTypes.WorkOrder[] = []
@ -219,7 +221,7 @@ export async function getWorkOrders(
: ` limit ${options.limit} offset ${options.offset}` : ` limit ${options.limit} offset ${options.offset}`
}` }`
) )
.all(sqlParameters) .all(sqlParameters) as recordTypes.WorkOrder[]
} }
const hasInclusions = const hasInclusions =

View File

@ -37,14 +37,16 @@ export async function moveFeeDownToBottom(
const currentFee = await getFee(feeId, database) const currentFee = await getFee(feeId, database)
const maxOrderNumber: number = database const maxOrderNumber = (
.prepare( database
`select max(orderNumber) as maxOrderNumber .prepare(
`select max(orderNumber) as maxOrderNumber
from Fees from Fees
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
and feeCategoryId = ?` and feeCategoryId = ?`
) )
.get(currentFee.feeCategoryId).maxOrderNumber .get(currentFee.feeCategoryId) as { maxOrderNumber: number }
).maxOrderNumber
if (currentFee.orderNumber !== maxOrderNumber) { if (currentFee.orderNumber !== maxOrderNumber) {
updateRecordOrderNumber('Fees', feeId, maxOrderNumber + 1, database) updateRecordOrderNumber('Fees', feeId, maxOrderNumber + 1, database)

View File

@ -8,17 +8,18 @@ function getCurrentField(
lotTypeFieldId: number | string, lotTypeFieldId: number | string,
connectedDatabase: PoolConnection connectedDatabase: PoolConnection
): { lotTypeId?: number; orderNumber: number } { ): { lotTypeId?: number; orderNumber: number } {
const currentField: { lotTypeId?: number; orderNumber: number } = const currentField = connectedDatabase
connectedDatabase .prepare(
.prepare( 'select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?'
'select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?' )
) .get(lotTypeFieldId) as { lotTypeId?: number; orderNumber: number }
.get(lotTypeFieldId)
return currentField return currentField
} }
export async function moveLotTypeFieldDown(lotTypeFieldId: number | string): Promise<boolean> { export async function moveLotTypeFieldDown(
lotTypeFieldId: number | string
): Promise<boolean> {
const database = await acquireConnection() const database = await acquireConnection()
const currentField = getCurrentField(lotTypeFieldId, database) const currentField = getCurrentField(lotTypeFieldId, database)
@ -53,14 +54,16 @@ export async function moveLotTypeFieldDownToBottom(
const currentField = getCurrentField(lotTypeFieldId, database) const currentField = getCurrentField(lotTypeFieldId, database)
const maxOrderNumber: number = database const maxOrderNumber = (
.prepare( database
`select max(orderNumber) as maxOrderNumber .prepare(
`select max(orderNumber) as maxOrderNumber
from LotTypeFields from LotTypeFields
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
and lotTypeId = ?` and lotTypeId = ?`
) )
.get(currentField.lotTypeId).maxOrderNumber .get(currentField.lotTypeId) as { maxOrderNumber: number }
).maxOrderNumber
if (currentField.orderNumber !== maxOrderNumber) { if (currentField.orderNumber !== maxOrderNumber) {
updateRecordOrderNumber( updateRecordOrderNumber(
@ -88,7 +91,9 @@ export async function moveLotTypeFieldDownToBottom(
return true return true
} }
export async function moveLotTypeFieldUp(lotTypeFieldId: number | string): Promise<boolean> { export async function moveLotTypeFieldUp(
lotTypeFieldId: number | string
): Promise<boolean> {
const database = await acquireConnection() const database = await acquireConnection()
const currentField = getCurrentField(lotTypeFieldId, database) const currentField = getCurrentField(lotTypeFieldId, database)

View File

@ -17,7 +17,9 @@ export async function moveOccupancyTypeFieldDown(occupancyTypeFieldId) {
' set orderNumber = orderNumber - 1' + ' set orderNumber = orderNumber - 1' +
' where recordDelete_timeMillis is null' + ' where recordDelete_timeMillis is null' +
(currentField.occupancyTypeId (currentField.occupancyTypeId
? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'" ? " and occupancyTypeId = '" +
currentField.occupancyTypeId.toString() +
"'"
: ' and occupancyTypeId is null') + : ' and occupancyTypeId is null') +
' and orderNumber = ? + 1') ' and orderNumber = ? + 1')
.run(currentField.orderNumber); .run(currentField.orderNumber);
@ -70,7 +72,9 @@ export async function moveOccupancyTypeFieldUp(occupancyTypeFieldId) {
' set orderNumber = orderNumber + 1' + ' set orderNumber = orderNumber + 1' +
' where recordDelete_timeMillis is null' + ' where recordDelete_timeMillis is null' +
(currentField.occupancyTypeId (currentField.occupancyTypeId
? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'" ? " and occupancyTypeId = '" +
currentField.occupancyTypeId.toString() +
"'"
: ' and occupancyTypeId is null') + : ' and occupancyTypeId is null') +
' and orderNumber = ? - 1') ' and orderNumber = ? - 1')
.run(currentField.orderNumber); .run(currentField.orderNumber);

View File

@ -8,14 +8,16 @@ function getCurrentField(
occupancyTypeFieldId: number, occupancyTypeFieldId: number,
connectedDatabase: PoolConnection connectedDatabase: PoolConnection
): { occupancyTypeId?: number; orderNumber: number } { ): { occupancyTypeId?: number; orderNumber: number } {
const currentField: { occupancyTypeId?: number; orderNumber: number } = const currentField = connectedDatabase
connectedDatabase .prepare(
.prepare( `select occupancyTypeId, orderNumber
`select occupancyTypeId, orderNumber
from OccupancyTypeFields from OccupancyTypeFields
where occupancyTypeFieldId = ?` where occupancyTypeFieldId = ?`
) )
.get(occupancyTypeFieldId) .get(occupancyTypeFieldId) as {
occupancyTypeId?: number
orderNumber: number
}
return currentField return currentField
} }
@ -33,7 +35,9 @@ export async function moveOccupancyTypeFieldDown(
' set orderNumber = orderNumber - 1' + ' set orderNumber = orderNumber - 1' +
' where recordDelete_timeMillis is null' + ' where recordDelete_timeMillis is null' +
(currentField.occupancyTypeId (currentField.occupancyTypeId
? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'" ? " and occupancyTypeId = '" +
currentField.occupancyTypeId.toString() +
"'"
: ' and occupancyTypeId is null') + : ' and occupancyTypeId is null') +
' and orderNumber = ? + 1' ' and orderNumber = ? + 1'
) )
@ -66,16 +70,18 @@ export async function moveOccupancyTypeFieldDownToBottom(
occupancyTypeParameters.push(currentField.occupancyTypeId) occupancyTypeParameters.push(currentField.occupancyTypeId)
} }
const maxOrderNumber: number = database const maxOrderNumber: number = (
.prepare( database
'select max(orderNumber) as maxOrderNumber' + .prepare(
' from OccupancyTypeFields' + 'select max(orderNumber) as maxOrderNumber' +
' where recordDelete_timeMillis is null' + ' from OccupancyTypeFields' +
(currentField.occupancyTypeId ' where recordDelete_timeMillis is null' +
? ' and occupancyTypeId = ?' (currentField.occupancyTypeId
: ' and occupancyTypeId is null') ? ' and occupancyTypeId = ?'
) : ' and occupancyTypeId is null')
.get(occupancyTypeParameters).maxOrderNumber )
.get(occupancyTypeParameters) as { maxOrderNumber: number }
).maxOrderNumber
if (currentField.orderNumber !== maxOrderNumber) { if (currentField.orderNumber !== maxOrderNumber) {
updateRecordOrderNumber( updateRecordOrderNumber(
@ -125,7 +131,9 @@ export async function moveOccupancyTypeFieldUp(
' set orderNumber = orderNumber + 1' + ' set orderNumber = orderNumber + 1' +
' where recordDelete_timeMillis is null' + ' where recordDelete_timeMillis is null' +
(currentField.occupancyTypeId (currentField.occupancyTypeId
? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'" ? " and occupancyTypeId = '" +
currentField.occupancyTypeId.toString() +
"'"
: ' and occupancyTypeId is null') + : ' and occupancyTypeId is null') +
' and orderNumber = ? - 1' ' and orderNumber = ? - 1'
) )

View File

@ -8,11 +8,13 @@ export async function moveOccupancyTypePrintDown(
): Promise<boolean> { ): Promise<boolean> {
const database = await acquireConnection() const database = await acquireConnection()
const currentOrderNumber = database const currentOrderNumber = (
.prepare( database
'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' .prepare(
) 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?'
.get(occupancyTypeId, printEJS).orderNumber )
.get(occupancyTypeId, printEJS) as { orderNumber: number }
).orderNumber
database database
.prepare( .prepare(
@ -43,20 +45,24 @@ export async function moveOccupancyTypePrintDownToBottom(
): Promise<boolean> { ): Promise<boolean> {
const database = await acquireConnection() const database = await acquireConnection()
const currentOrderNumber = database const currentOrderNumber = (
.prepare( database
'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' .prepare(
) 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?'
.get(occupancyTypeId, printEJS).orderNumber )
.get(occupancyTypeId, printEJS) as { orderNumber: number }
).orderNumber
const maxOrderNumber: number = database const maxOrderNumber: number = (
.prepare( database
`select max(orderNumber) as maxOrderNumber .prepare(
`select max(orderNumber) as maxOrderNumber
from OccupancyTypePrints from OccupancyTypePrints
where recordDelete_timeMillis is null where recordDelete_timeMillis is null
and occupancyTypeId = ?` and occupancyTypeId = ?`
) )
.get(occupancyTypeId).maxOrderNumber .get(occupancyTypeId) as { maxOrderNumber: number }
).maxOrderNumber
if (currentOrderNumber !== maxOrderNumber) { if (currentOrderNumber !== maxOrderNumber) {
database database

View File

@ -8,11 +8,13 @@ export async function moveOccupancyTypePrintUp(
): Promise<boolean> { ): Promise<boolean> {
const database = await acquireConnection() const database = await acquireConnection()
const currentOrderNumber = database const currentOrderNumber = (
.prepare( database
'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' .prepare(
) 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?'
.get(occupancyTypeId, printEJS).orderNumber )
.get(occupancyTypeId, printEJS) as { orderNumber: number }
).orderNumber
if (currentOrderNumber <= 0) { if (currentOrderNumber <= 0) {
database.release() database.release()
@ -48,11 +50,13 @@ export async function moveOccupancyTypePrintUpToTop(
): Promise<boolean> { ): Promise<boolean> {
const database = await acquireConnection() const database = await acquireConnection()
const currentOrderNumber = database const currentOrderNumber = (
.prepare( database
'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' .prepare(
) 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?'
.get(occupancyTypeId, printEJS).orderNumber )
.get(occupancyTypeId, printEJS) as { orderNumber: number }
).orderNumber
if (currentOrderNumber > 0) { if (currentOrderNumber > 0) {
database database

View File

@ -27,13 +27,15 @@ function getCurrentOrderNumber(
recordId: number | string, recordId: number | string,
database: sqlite.Database database: sqlite.Database
): number { ): number {
const currentOrderNumber: number = database const currentOrderNumber: number = (
.prepare( database
`select orderNumber .prepare(
`select orderNumber
from ${recordTable} from ${recordTable}
where ${recordIdColumns.get(recordTable)!} = ?` where ${recordIdColumns.get(recordTable)!} = ?`
) )
.get(recordId).orderNumber .get(recordId) as { orderNumber: number }
).orderNumber
return currentOrderNumber return currentOrderNumber
} }
@ -85,13 +87,15 @@ export async function moveRecordDownToBottom(
database database
) )
const maxOrderNumber: number = database const maxOrderNumber = (
.prepare( database
`select max(orderNumber) as maxOrderNumber .prepare(
`select max(orderNumber) as maxOrderNumber
from ${recordTable} from ${recordTable}
where recordDelete_timeMillis is null` where recordDelete_timeMillis is null`
) )
.get().maxOrderNumber .get() as { maxOrderNumber: number }
).maxOrderNumber
if (currentOrderNumber !== maxOrderNumber) { if (currentOrderNumber !== maxOrderNumber) {
updateRecordOrderNumber(recordTable, recordId, maxOrderNumber + 1, database) updateRecordOrderNumber(recordTable, recordId, maxOrderNumber + 1, database)