diff --git a/helpers/lotOccupancyDB/addLotOccupancyFee.ts b/helpers/lotOccupancyDB/addLotOccupancyFee.ts index f15cfce9..5a6664bd 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyFee.ts +++ b/helpers/lotOccupancyDB/addLotOccupancyFee.ts @@ -48,18 +48,18 @@ export async function addLotOccupancyFee( } // Check if record already exists - const record: { - feeAmount?: number - taxAmount?: number - recordDelete_timeMillis?: number - } = database + const record = database .prepare( `select feeAmount, taxAmount, recordDelete_timeMillis from LotOccupancyFees where lotOccupancyId = ? and feeId = ?` ) - .get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId) + .get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId) as { + feeAmount?: number + taxAmount?: number + recordDelete_timeMillis?: number + } if (record) { if (record.recordDelete_timeMillis) { diff --git a/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts b/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts index bea702d9..aff022c7 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts +++ b/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts @@ -27,7 +27,7 @@ export async function addLotOccupancyOccupant( let lotOccupantIndex = 0 - const maxIndexResult: { lotOccupantIndex: number } | undefined = database + const maxIndexResult = database .prepare( `select lotOccupantIndex from LotOccupancyOccupants @@ -35,7 +35,9 @@ export async function addLotOccupancyOccupant( order by lotOccupantIndex desc limit 1` ) - .get(lotOccupancyOccupantForm.lotOccupancyId) + .get(lotOccupancyOccupantForm.lotOccupancyId) as + | { lotOccupantIndex: number } + | undefined if (maxIndexResult !== undefined) { lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1 diff --git a/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts b/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts index 81fe934c..afea9328 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts +++ b/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts @@ -26,7 +26,7 @@ export async function addLotOccupancyTransaction( let transactionIndex = 0 - const maxIndexResult: { transactionIndex: number } | undefined = database + const maxIndexResult = database .prepare( `select transactionIndex from LotOccupancyTransactions @@ -34,7 +34,9 @@ export async function addLotOccupancyTransaction( order by transactionIndex desc limit 1` ) - .get(lotOccupancyTransactionForm.lotOccupancyId) + .get(lotOccupancyTransactionForm.lotOccupancyId) as + | { transactionIndex: number } + | undefined if (maxIndexResult !== undefined) { transactionIndex = maxIndexResult.transactionIndex + 1 diff --git a/helpers/lotOccupancyDB/addWorkOrderLot.ts b/helpers/lotOccupancyDB/addWorkOrderLot.ts index 8d038831..7a1459b9 100644 --- a/helpers/lotOccupancyDB/addWorkOrderLot.ts +++ b/helpers/lotOccupancyDB/addWorkOrderLot.ts @@ -15,14 +15,16 @@ export async function addWorkOrderLot( const rightNowMillis = Date.now() - const row: { recordDelete_timeMillis?: number } = database + const row = database .prepare( `select recordDelete_timeMillis from WorkOrderLots where workOrderId = ? and lotId = ?` ) - .get(workOrderLotForm.workOrderId, workOrderLotForm.lotId) + .get(workOrderLotForm.workOrderId, workOrderLotForm.lotId) as { + recordDelete_timeMillis?: number + } if (row === undefined) { database diff --git a/helpers/lotOccupancyDB/getFee.ts b/helpers/lotOccupancyDB/getFee.ts index 1aec9226..4b25d3bb 100644 --- a/helpers/lotOccupancyDB/getFee.ts +++ b/helpers/lotOccupancyDB/getFee.ts @@ -27,7 +27,7 @@ export async function getFee( where f.recordDelete_timeMillis is null and f.feeId = ?` ) - .get(feeId) + .get(feeId) as recordTypes.Fee if (connectedDatabase === undefined) { database.release() diff --git a/helpers/lotOccupancyDB/getFeeCategories.ts b/helpers/lotOccupancyDB/getFeeCategories.ts index 42bcd658..40e76a76 100644 --- a/helpers/lotOccupancyDB/getFeeCategories.ts +++ b/helpers/lotOccupancyDB/getFeeCategories.ts @@ -47,14 +47,14 @@ export async function getFeeCategories( sqlParameters.push(filters.lotTypeId) } - const feeCategories: recordTypes.FeeCategory[] = database + const feeCategories = database .prepare( 'select feeCategoryId, feeCategory, orderNumber' + ' from FeeCategories' + sqlWhereClause + ' order by orderNumber, feeCategory' ) - .all(sqlParameters) + .all(sqlParameters) as recordTypes.FeeCategory[] if (options.includeFees ?? false) { let expectedOrderNumber = 0 diff --git a/helpers/lotOccupancyDB/getFees.ts b/helpers/lotOccupancyDB/getFees.ts index 7e0680b8..9178f3b8 100644 --- a/helpers/lotOccupancyDB/getFees.ts +++ b/helpers/lotOccupancyDB/getFees.ts @@ -39,7 +39,7 @@ export async function getFees( sqlParameters.push(additionalFilters.lotTypeId) } - const fees: recordTypes.Fee[] = database + const fees = database .prepare( `select f.feeId, f.feeName, f.feeDescription, f.occupancyTypeId, o.occupancyType, @@ -62,7 +62,7 @@ export async function getFees( ${sqlWhereClause} order by f.orderNumber, f.feeName` ) - .all(sqlParameters) + .all(sqlParameters) as recordTypes.Fee[] if (updateOrderNumbers) { let expectedOrderNumber = 0 diff --git a/helpers/lotOccupancyDB/getLot.ts b/helpers/lotOccupancyDB/getLot.ts index d2a031d4..66fd5384 100644 --- a/helpers/lotOccupancyDB/getLot.ts +++ b/helpers/lotOccupancyDB/getLot.ts @@ -23,7 +23,7 @@ async function _getLot( ): Promise { 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) { const lotOccupancies = await getLotOccupancies( diff --git a/helpers/lotOccupancyDB/getLotComments.ts b/helpers/lotOccupancyDB/getLotComments.ts index 697c9a77..72ae21fa 100644 --- a/helpers/lotOccupancyDB/getLotComments.ts +++ b/helpers/lotOccupancyDB/getLotComments.ts @@ -33,7 +33,7 @@ export async function getLotComments( and lotId = ? order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc` ) - .all(lotId) + .all(lotId) as recordTypes.LotComment[] if (connectedDatabase === undefined) { database.release() diff --git a/helpers/lotOccupancyDB/getLotFields.ts b/helpers/lotOccupancyDB/getLotFields.ts index 5cd47e00..948a2482 100644 --- a/helpers/lotOccupancyDB/getLotFields.ts +++ b/helpers/lotOccupancyDB/getLotFields.ts @@ -9,7 +9,7 @@ export async function getLotFields( ): Promise { const database = connectedDatabase ?? (await acquireConnection()) - const lotFields: recordTypes.LotField[] = database + const lotFields = database .prepare( `select l.lotId, l.lotTypeFieldId, 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) order by lotTypeOrderNumber, f.orderNumber, f.lotTypeField` ) - .all(lotId, lotId, lotId, lotId) + .all(lotId, lotId, lotId, lotId) as recordTypes.LotField[] if (connectedDatabase === undefined) { database.release() diff --git a/helpers/lotOccupancyDB/getLotOccupancies.ts b/helpers/lotOccupancyDB/getLotOccupancies.ts index 2a266bf2..a108717f 100644 --- a/helpers/lotOccupancyDB/getLotOccupancies.ts +++ b/helpers/lotOccupancyDB/getLotOccupancies.ts @@ -180,14 +180,16 @@ export async function getLotOccupancies( const isLimited = options.limit !== -1 if (isLimited) { - count = database - .prepare( - `select count(*) as recordCount + count = ( + database + .prepare( + `select count(*) as recordCount from LotOccupancies o left join Lots l on o.lotId = l.lotId ${sqlWhereClause}` - ) - .get(sqlParameters).recordCount + ) + .get(sqlParameters) as { recordCount: number } + ).recordCount } 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` + (isLimited ? ` limit ${options.limit} offset ${options.offset}` : '') ) - .all(sqlParameters) + .all(sqlParameters) as recordTypes.LotOccupancy[] if (!isLimited) { count = lotOccupancies.length diff --git a/helpers/lotOccupancyDB/getLotOccupancy.ts b/helpers/lotOccupancyDB/getLotOccupancy.ts index 527ecb7a..8ff7a579 100644 --- a/helpers/lotOccupancyDB/getLotOccupancy.ts +++ b/helpers/lotOccupancyDB/getLotOccupancy.ts @@ -20,7 +20,7 @@ export async function getLotOccupancy( database.function('userFn_dateIntegerToString', dateIntegerToString) - const lotOccupancy: recordTypes.LotOccupancy | undefined = database + const lotOccupancy = database .prepare( `select o.lotOccupancyId, o.occupancyTypeId, t.occupancyType, @@ -36,7 +36,7 @@ export async function getLotOccupancy( where o.recordDelete_timeMillis is null and o.lotOccupancyId = ?` ) - .get(lotOccupancyId) + .get(lotOccupancyId) as recordTypes.LotOccupancy | undefined if (lotOccupancy !== undefined) { lotOccupancy.lotOccupancyFields = await getLotOccupancyFields( diff --git a/helpers/lotOccupancyDB/getLotOccupancyComments.ts b/helpers/lotOccupancyDB/getLotOccupancyComments.ts index ed1b09bf..ac41f74a 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyComments.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyComments.ts @@ -33,7 +33,7 @@ export async function getLotOccupancyComments( and lotOccupancyId = ? order by lotOccupancyCommentDate desc, lotOccupancyCommentTime desc, lotOccupancyCommentId desc` ) - .all(lotOccupancyId) + .all(lotOccupancyId) as recordTypes.LotOccupancyComment[] if (connectedDatabase === null) { database.release() diff --git a/helpers/lotOccupancyDB/getLotOccupancyFees.ts b/helpers/lotOccupancyDB/getLotOccupancyFees.ts index 71661f69..972a666a 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFees.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyFees.ts @@ -9,7 +9,7 @@ export async function getLotOccupancyFees( ): Promise { const database = connectedDatabase ?? (await acquireConnection()) - const lotOccupancyFees: recordTypes.LotOccupancyFee[] = database + const lotOccupancyFees = database .prepare( `select o.lotOccupancyId, o.feeId, c.feeCategory, f.feeName, @@ -21,7 +21,7 @@ export async function getLotOccupancyFees( and o.lotOccupancyId = ? order by o.recordCreate_timeMillis` ) - .all(lotOccupancyId) + .all(lotOccupancyId) as recordTypes.LotOccupancyFee[] if (connectedDatabase === undefined) { database.release() diff --git a/helpers/lotOccupancyDB/getLotOccupancyFields.ts b/helpers/lotOccupancyDB/getLotOccupancyFields.ts index cd19ecf9..79f6d4b0 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFields.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyFields.ts @@ -9,7 +9,7 @@ export async function getLotOccupancyFields( ): Promise { const database = connectedDatabase ?? (await acquireConnection()) - const lotOccupancyFields: recordTypes.LotOccupancyField[] = database + const lotOccupancyFields = database .prepare( `select o.lotOccupancyId, o.occupancyTypeFieldId, 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) order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField` ) - .all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId) + .all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId) as recordTypes.LotOccupancyField[] if (connectedDatabase === undefined) { database.release() diff --git a/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts b/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts index 7119b566..23efff92 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts @@ -9,7 +9,7 @@ export async function getLotOccupancyOccupants( ): Promise { const database = connectedDatabase ?? (await acquireConnection()) - const lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[] = database + const lotOccupancyOccupants = database .prepare( `select o.lotOccupancyId, o.lotOccupantIndex, o.occupantName, o.occupantFamilyName, @@ -25,7 +25,7 @@ export async function getLotOccupancyOccupants( and o.lotOccupancyId = ? order by t.orderNumber, t.lotOccupantType, o.occupantName, o.lotOccupantIndex` ) - .all(lotOccupancyId) + .all(lotOccupancyId) as recordTypes.LotOccupancyOccupant[] if (connectedDatabase === undefined) { database.release() diff --git a/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts b/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts index fa3a982e..eb14e554 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts @@ -20,10 +20,9 @@ export async function getLotOccupancyTransactions( database.function('userFn_dateIntegerToString', dateIntegerToString) database.function('userFn_timeIntegerToString', timeIntegerToString) - const lotOccupancyTransactions: recordTypes.LotOccupancyTransaction[] = - database - .prepare( - `select lotOccupancyId, transactionIndex, + const lotOccupancyTransactions = database + .prepare( + `select lotOccupancyId, transactionIndex, transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString, transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString, transactionAmount, externalReceiptNumber, transactionNote @@ -31,8 +30,8 @@ export async function getLotOccupancyTransactions( where recordDelete_timeMillis is null and lotOccupancyId = ? order by transactionDate, transactionTime, transactionIndex` - ) - .all(lotOccupancyId) + ) + .all(lotOccupancyId) as recordTypes.LotOccupancyTransaction[] if (connectedDatabase === undefined) { database.release() diff --git a/helpers/lotOccupancyDB/getLotOccupantTypes.ts b/helpers/lotOccupancyDB/getLotOccupantTypes.ts index 698764ad..d3da9c0c 100644 --- a/helpers/lotOccupancyDB/getLotOccupantTypes.ts +++ b/helpers/lotOccupancyDB/getLotOccupantTypes.ts @@ -11,7 +11,7 @@ export async function getLotOccupantTypes(): Promise< > { const database = await acquireConnection() - const lotOccupantTypes: recordTypes.LotOccupantType[] = database + const lotOccupantTypes = database .prepare( `select lotOccupantTypeId, lotOccupantType, fontAwesomeIconClass, occupantCommentTitle, orderNumber @@ -19,7 +19,7 @@ export async function getLotOccupantTypes(): Promise< where recordDelete_timeMillis is null order by orderNumber, lotOccupantType` ) - .all() + .all() as recordTypes.LotOccupantType[] let expectedOrderNumber = 0 diff --git a/helpers/lotOccupancyDB/getLotStatusSummary.ts b/helpers/lotOccupancyDB/getLotStatusSummary.ts index a45b48dc..67d92ded 100644 --- a/helpers/lotOccupancyDB/getLotStatusSummary.ts +++ b/helpers/lotOccupancyDB/getLotStatusSummary.ts @@ -23,7 +23,7 @@ export async function getLotStatusSummary( sqlParameters.push(filters.mapId) } - const lotStatuses: LotStatusSummary[] = database + const lotStatuses = database .prepare( `select s.lotStatusId, s.lotStatus, count(l.lotId) as lotCount from Lots l @@ -32,7 +32,7 @@ export async function getLotStatusSummary( group by s.lotStatusId, s.lotStatus, s.orderNumber order by s.orderNumber` ) - .all(sqlParameters) + .all(sqlParameters) as LotStatusSummary[] database.release() diff --git a/helpers/lotOccupancyDB/getLotStatuses.ts b/helpers/lotOccupancyDB/getLotStatuses.ts index eacd9350..aae1f5de 100644 --- a/helpers/lotOccupancyDB/getLotStatuses.ts +++ b/helpers/lotOccupancyDB/getLotStatuses.ts @@ -7,14 +7,14 @@ import type * as recordTypes from '../../types/recordTypes' export async function getLotStatuses(): Promise { const database = await acquireConnection() - const lotStatuses: recordTypes.LotStatus[] = database + const lotStatuses = database .prepare( `select lotStatusId, lotStatus, orderNumber from LotStatuses where recordDelete_timeMillis is null order by orderNumber, lotStatus` ) - .all() + .all() as recordTypes.LotStatus[] let expectedOrderNumber = 0 diff --git a/helpers/lotOccupancyDB/getLotTypeFields.ts b/helpers/lotOccupancyDB/getLotTypeFields.ts index b9155ef2..4f842462 100644 --- a/helpers/lotOccupancyDB/getLotTypeFields.ts +++ b/helpers/lotOccupancyDB/getLotTypeFields.ts @@ -10,7 +10,7 @@ export async function getLotTypeFields( ): Promise { const database = connectedDatabase ?? (await acquireConnection()) - const lotTypeFields: recordTypes.LotTypeField[] = database + const lotTypeFields = database .prepare( `select lotTypeFieldId, lotTypeField, lotTypeFieldValues, @@ -20,7 +20,7 @@ export async function getLotTypeFields( and lotTypeId = ? order by orderNumber, lotTypeField` ) - .all(lotTypeId) + .all(lotTypeId) as recordTypes.LotTypeField[] let expectedOrderNumber = 0 diff --git a/helpers/lotOccupancyDB/getLotTypeSummary.ts b/helpers/lotOccupancyDB/getLotTypeSummary.ts index 834de133..de432c10 100644 --- a/helpers/lotOccupancyDB/getLotTypeSummary.ts +++ b/helpers/lotOccupancyDB/getLotTypeSummary.ts @@ -23,7 +23,7 @@ export async function getLotTypeSummary( sqlParameters.push(filters.mapId) } - const lotTypes: LotTypeSummary[] = database + const lotTypes = database .prepare( `select t.lotTypeId, t.lotType, count(l.lotId) as lotCount from Lots l @@ -32,7 +32,7 @@ export async function getLotTypeSummary( group by t.lotTypeId, t.lotType, t.orderNumber order by t.orderNumber` ) - .all(sqlParameters) + .all(sqlParameters) as LotTypeSummary[] database.release() diff --git a/helpers/lotOccupancyDB/getLotTypes.ts b/helpers/lotOccupancyDB/getLotTypes.ts index ac1e1767..4450cd9f 100644 --- a/helpers/lotOccupancyDB/getLotTypes.ts +++ b/helpers/lotOccupancyDB/getLotTypes.ts @@ -8,14 +8,14 @@ import { updateRecordOrderNumber } from './updateRecordOrderNumber.js' export async function getLotTypes(): Promise { const database = await acquireConnection() - const lotTypes: recordTypes.LotType[] = database + const lotTypes = database .prepare( `select lotTypeId, lotType, orderNumber from LotTypes where recordDelete_timeMillis is null order by orderNumber, lotType` ) - .all() + .all() as recordTypes.LotType[] let expectedTypeOrderNumber = -1 diff --git a/helpers/lotOccupancyDB/getLots.ts b/helpers/lotOccupancyDB/getLots.ts index b8d7f116..d2d6763c 100644 --- a/helpers/lotOccupancyDB/getLots.ts +++ b/helpers/lotOccupancyDB/getLots.ts @@ -91,9 +91,10 @@ export async function getLots( let count = 0 if (options.limit !== -1) { - count = database - .prepare( - `select count(*) as recordCount + count = ( + database + .prepare( + `select count(*) as recordCount from Lots l left join ( select lotId, count(lotOccupancyId) as lotOccupancyCount from LotOccupancies @@ -103,8 +104,9 @@ export async function getLots( group by lotId ) o on l.lotId = o.lotId ${sqlWhereClause}` - ) - .get(sqlParameters).recordCount + ) + .get(sqlParameters) as { recordCount: number } + ).recordCount } let lots: recordTypes.Lot[] = [] @@ -155,7 +157,7 @@ export async function getLots( : ` limit ${options.limit.toString()} offset ${options.offset.toString()}` }` ) - .all(sqlParameters) + .all(sqlParameters) as recordTypes.Lot[] if (options.limit === -1) { count = lots.length diff --git a/helpers/lotOccupancyDB/getMap.ts b/helpers/lotOccupancyDB/getMap.ts index d6949f66..77ca8732 100644 --- a/helpers/lotOccupancyDB/getMap.ts +++ b/helpers/lotOccupancyDB/getMap.ts @@ -7,7 +7,7 @@ export async function getMap( ): Promise { const database = await acquireConnection() - const map: recordTypes.Map = database + const map = database .prepare( `select m.mapId, m.mapName, m.mapDescription, m.mapLatitude, m.mapLongitude, m.mapSVG, @@ -29,7 +29,7 @@ export async function getMap( m.recordUpdate_userName, m.recordUpdate_timeMillis, m.recordDelete_userName, m.recordDelete_timeMillis` ) - .get(mapId) + .get(mapId) as recordTypes.Map | undefined database.release() diff --git a/helpers/lotOccupancyDB/getMaps.ts b/helpers/lotOccupancyDB/getMaps.ts index 6e4853d8..c73ac75c 100644 --- a/helpers/lotOccupancyDB/getMaps.ts +++ b/helpers/lotOccupancyDB/getMaps.ts @@ -5,7 +5,7 @@ import type * as recordTypes from '../../types/recordTypes' export async function getMaps(): Promise { const database = await acquireConnection() - const maps: recordTypes.Map[] = database + const maps = database .prepare( `select m.mapId, m.mapName, m.mapDescription, m.mapLatitude, m.mapLongitude, m.mapSVG, @@ -20,7 +20,7 @@ export async function getMaps(): Promise { ) l on m.mapId = l.mapId where m.recordDelete_timeMillis is null order by m.mapName, m.mapId` ) - .all() + .all() as recordTypes.Map[] database.release() diff --git a/helpers/lotOccupancyDB/getNextLotId.ts b/helpers/lotOccupancyDB/getNextLotId.ts index 386b92a3..2d600bf5 100644 --- a/helpers/lotOccupancyDB/getNextLotId.ts +++ b/helpers/lotOccupancyDB/getNextLotId.ts @@ -12,9 +12,7 @@ export async function getNextLotId( configFunctions.getProperty('settings.lot.lotNameSortNameFunction') ) - const result: { - lotId: number - } = database + const result = database .prepare( `select lotId from Lots @@ -23,7 +21,9 @@ export async function getNextLotId( order by userFn_lotNameSortName(lotName) limit 1` ) - .get(lotId) + .get(lotId) as { + lotId: number + } database.release() diff --git a/helpers/lotOccupancyDB/getNextMapId.ts b/helpers/lotOccupancyDB/getNextMapId.ts index 7c9c8ab4..a705d0c8 100644 --- a/helpers/lotOccupancyDB/getNextMapId.ts +++ b/helpers/lotOccupancyDB/getNextMapId.ts @@ -5,9 +5,7 @@ export async function getNextMapId( ): Promise { const database = await acquireConnection() - const result: { - mapId: number - } = database + const result = database .prepare( `select mapId from Maps @@ -16,7 +14,9 @@ export async function getNextMapId( order by mapName limit 1` ) - .get(mapId) + .get(mapId) as { + mapId: number + } database.release() diff --git a/helpers/lotOccupancyDB/getNextWorkOrderNumber.ts b/helpers/lotOccupancyDB/getNextWorkOrderNumber.ts index bdb61de6..b53cd78e 100644 --- a/helpers/lotOccupancyDB/getNextWorkOrderNumber.ts +++ b/helpers/lotOccupancyDB/getNextWorkOrderNumber.ts @@ -28,7 +28,9 @@ export async function getNextWorkOrderNumber( where userFn_matchesWorkOrderNumberSyntax(workOrderNumber) = 1 order by cast(substr(workOrderNumber, instr(workOrderNumber, '-') + 1) as integer) desc` ) - .get() + .get() as { + workOrderNumber: string + } if (connectedDatabase === undefined) { database.release() diff --git a/helpers/lotOccupancyDB/getOccupancyTypeFields.ts b/helpers/lotOccupancyDB/getOccupancyTypeFields.ts index cc0529fc..d57e8dd4 100644 --- a/helpers/lotOccupancyDB/getOccupancyTypeFields.ts +++ b/helpers/lotOccupancyDB/getOccupancyTypeFields.ts @@ -16,7 +16,7 @@ export async function getOccupancyTypeFields( sqlParameters.push(occupancyTypeId) } - const occupancyTypeFields: recordTypes.OccupancyTypeField[] = database + const occupancyTypeFields = database .prepare( 'select occupancyTypeFieldId,' + ' occupancyTypeField, occupancyTypeFieldValues, isRequired, pattern,' + @@ -29,7 +29,7 @@ export async function getOccupancyTypeFields( : ' and occupancyTypeId = ?') + ' order by orderNumber, occupancyTypeField' ) - .all(sqlParameters) + .all(sqlParameters) as recordTypes.OccupancyTypeField[] let expectedOrderNumber = 0 diff --git a/helpers/lotOccupancyDB/getOccupancyTypePrints.ts b/helpers/lotOccupancyDB/getOccupancyTypePrints.ts index fab4271e..77d8c6b8 100644 --- a/helpers/lotOccupancyDB/getOccupancyTypePrints.ts +++ b/helpers/lotOccupancyDB/getOccupancyTypePrints.ts @@ -27,7 +27,7 @@ export async function getOccupancyTypePrints( userFunction_configContainsPrintEJS ) - const results: Array<{ printEJS: string; orderNumber: number }> = database + const results = database .prepare( `select printEJS, orderNumber from OccupancyTypePrints @@ -36,7 +36,7 @@ export async function getOccupancyTypePrints( and userFn_configContainsPrintEJS(printEJS) = 1 order by orderNumber, printEJS` ) - .all(occupancyTypeId) + .all(occupancyTypeId) as Array<{ printEJS: string; orderNumber: number }> let expectedOrderNumber = -1 diff --git a/helpers/lotOccupancyDB/getOccupancyTypes.ts b/helpers/lotOccupancyDB/getOccupancyTypes.ts index 20241886..feb2f85c 100644 --- a/helpers/lotOccupancyDB/getOccupancyTypes.ts +++ b/helpers/lotOccupancyDB/getOccupancyTypes.ts @@ -13,14 +13,14 @@ export async function getOccupancyTypes(): Promise< > { const database = await acquireConnection() - const occupancyTypes: recordTypes.OccupancyType[] = database + const occupancyTypes = database .prepare( `select occupancyTypeId, occupancyType, orderNumber from OccupancyTypes where recordDelete_timeMillis is null order by orderNumber, occupancyType` ) - .all() + .all() as recordTypes.OccupancyType[] let expectedTypeOrderNumber = -1 diff --git a/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.ts b/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.ts index b0484d73..5170ed2c 100644 --- a/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.ts +++ b/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.ts @@ -61,9 +61,9 @@ export async function getPastLotOccupancyOccupants( order by lotOccupancyIdCount desc, recordUpdate_timeMillisMax desc limit ${options.limit}` - const lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[] = database + const lotOccupancyOccupants = database .prepare(sql) - .all(sqlParameters) + .all(sqlParameters) as recordTypes.LotOccupancyOccupant[] database.release() diff --git a/helpers/lotOccupancyDB/getPreviousLotId.ts b/helpers/lotOccupancyDB/getPreviousLotId.ts index 528fecf9..edaa441c 100644 --- a/helpers/lotOccupancyDB/getPreviousLotId.ts +++ b/helpers/lotOccupancyDB/getPreviousLotId.ts @@ -12,9 +12,7 @@ export async function getPreviousLotId( configFunctions.getProperty('settings.lot.lotNameSortNameFunction') ) - const result: { - lotId: number - } = database + const result = database .prepare( `select lotId from Lots where recordDelete_timeMillis is null @@ -22,7 +20,9 @@ export async function getPreviousLotId( order by userFn_lotNameSortName(lotName) desc limit 1` ) - .get(lotId) + .get(lotId) as { + lotId: number + } database.release() diff --git a/helpers/lotOccupancyDB/getPreviousMapId.ts b/helpers/lotOccupancyDB/getPreviousMapId.ts index c07f70a8..19a95769 100644 --- a/helpers/lotOccupancyDB/getPreviousMapId.ts +++ b/helpers/lotOccupancyDB/getPreviousMapId.ts @@ -5,9 +5,7 @@ export async function getPreviousMapId( ): Promise { const database = await acquireConnection() - const result: { - mapId: number - } = database + const result = database .prepare( `select mapId from Maps where recordDelete_timeMillis is null @@ -15,7 +13,9 @@ export async function getPreviousMapId( order by mapName desc limit 1` ) - .get(mapId) + .get(mapId) as { + mapId: number + } database.release() diff --git a/helpers/lotOccupancyDB/getWorkOrder.js b/helpers/lotOccupancyDB/getWorkOrder.js index 0aacf35c..1648da0c 100644 --- a/helpers/lotOccupancyDB/getWorkOrder.js +++ b/helpers/lotOccupancyDB/getWorkOrder.js @@ -16,9 +16,7 @@ const baseSQL = `select w.workOrderId, async function _getWorkOrder(sql, workOrderIdOrWorkOrderNumber, options, connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); database.function('userFn_dateIntegerToString', dateIntegerToString); - const workOrder = database - .prepare(sql) - .get(workOrderIdOrWorkOrderNumber); + const workOrder = database.prepare(sql).get(workOrderIdOrWorkOrderNumber); if (workOrder !== undefined) { if (options.includeLotsAndLotOccupancies) { const workOrderLotsResults = await getLots({ diff --git a/helpers/lotOccupancyDB/getWorkOrder.ts b/helpers/lotOccupancyDB/getWorkOrder.ts index dcea647f..8dcb7ab9 100644 --- a/helpers/lotOccupancyDB/getWorkOrder.ts +++ b/helpers/lotOccupancyDB/getWorkOrder.ts @@ -39,9 +39,9 @@ async function _getWorkOrder( database.function('userFn_dateIntegerToString', dateIntegerToString) - const workOrder: recordTypes.WorkOrder = database - .prepare(sql) - .get(workOrderIdOrWorkOrderNumber) + const workOrder = database.prepare(sql).get(workOrderIdOrWorkOrderNumber) as + | recordTypes.WorkOrder + | undefined if (workOrder !== undefined) { if (options.includeLotsAndLotOccupancies) { diff --git a/helpers/lotOccupancyDB/getWorkOrderComments.ts b/helpers/lotOccupancyDB/getWorkOrderComments.ts index e7f43d2d..f5264ce9 100644 --- a/helpers/lotOccupancyDB/getWorkOrderComments.ts +++ b/helpers/lotOccupancyDB/getWorkOrderComments.ts @@ -33,7 +33,7 @@ export async function getWorkOrderComments( and workOrderId = ? order by workOrderCommentDate desc, workOrderCommentTime desc, workOrderCommentId desc` ) - .all(workOrderId) + .all(workOrderId) as recordTypes.WorkOrderComment[] if (connectedDatabase === undefined) { database.release() diff --git a/helpers/lotOccupancyDB/getWorkOrderMilestoneTypes.ts b/helpers/lotOccupancyDB/getWorkOrderMilestoneTypes.ts index 9ce51ffb..068dba8c 100644 --- a/helpers/lotOccupancyDB/getWorkOrderMilestoneTypes.ts +++ b/helpers/lotOccupancyDB/getWorkOrderMilestoneTypes.ts @@ -7,14 +7,14 @@ import type * as recordTypes from '../../types/recordTypes' export async function getWorkOrderMilestoneTypes(): Promise { const database = await acquireConnection() - const workOrderMilestoneTypes: recordTypes.WorkOrderMilestoneType[] = database + const workOrderMilestoneTypes = database .prepare( `select workOrderMilestoneTypeId, workOrderMilestoneType, orderNumber from WorkOrderMilestoneTypes where recordDelete_timeMillis is null order by orderNumber, workOrderMilestoneType` ) - .all() + .all() as recordTypes.WorkOrderMilestoneType[] let expectedOrderNumber = 0 diff --git a/helpers/lotOccupancyDB/getWorkOrderMilestones.ts b/helpers/lotOccupancyDB/getWorkOrderMilestones.ts index d8fee01b..265ed414 100644 --- a/helpers/lotOccupancyDB/getWorkOrderMilestones.ts +++ b/helpers/lotOccupancyDB/getWorkOrderMilestones.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/indent */ + import { acquireConnection } from './pool.js' import type { PoolConnection } from 'better-sqlite-pool' @@ -18,7 +20,12 @@ import type * as recordTypes from '../../types/recordTypes' export interface WorkOrderMilestoneFilters { workOrderId?: number | string - workOrderMilestoneDateFilter?: 'upcomingMissed' | 'recent' | 'date' | 'blank' | 'notBlank' + workOrderMilestoneDateFilter?: + | 'upcomingMissed' + | 'recent' + | 'date' + | 'blank' + | 'notBlank' workOrderMilestoneDateString?: string workOrderTypeIds?: string workOrderMilestoneTypeIds?: string @@ -134,7 +141,10 @@ export async function getWorkOrderMilestones( database.function('userFn_dateIntegerToString', dateIntegerToString) database.function('userFn_timeIntegerToString', timeIntegerToString) - database.function('userFn_timeIntegerToPeriodString', timeIntegerToPeriodString) + database.function( + 'userFn_timeIntegerToPeriodString', + timeIntegerToPeriodString + ) // Filters const { sqlWhereClause, sqlParameters } = buildWhereClause(filters) @@ -188,9 +198,9 @@ export async function getWorkOrderMilestones( sqlWhereClause + orderByClause - const workOrderMilestones: recordTypes.WorkOrderMilestone[] = database + const workOrderMilestones = database .prepare(sql) - .all(sqlParameters) + .all(sqlParameters) as recordTypes.WorkOrderMilestone[] if (options.includeWorkOrders ?? false) { for (const workOrderMilestone of workOrderMilestones) { diff --git a/helpers/lotOccupancyDB/getWorkOrderTypes.ts b/helpers/lotOccupancyDB/getWorkOrderTypes.ts index 6f2ffc21..371df6c9 100644 --- a/helpers/lotOccupancyDB/getWorkOrderTypes.ts +++ b/helpers/lotOccupancyDB/getWorkOrderTypes.ts @@ -11,14 +11,14 @@ export async function getWorkOrderTypes(): Promise< > { const database = await acquireConnection() - const workOrderTypes: recordTypes.WorkOrderType[] = database + const workOrderTypes = database .prepare( `select workOrderTypeId, workOrderType, orderNumber from WorkOrderTypes where recordDelete_timeMillis is null order by orderNumber, workOrderType` ) - .all() + .all() as recordTypes.WorkOrderType[] let expectedOrderNumber = 0 @@ -26,7 +26,7 @@ export async function getWorkOrderTypes(): Promise< if (workOrderType.orderNumber !== expectedOrderNumber) { updateRecordOrderNumber( 'WorkOrderTypes', - workOrderType.workOrderTypeId!, + workOrderType.workOrderTypeId, expectedOrderNumber, database ) diff --git a/helpers/lotOccupancyDB/getWorkOrders.ts b/helpers/lotOccupancyDB/getWorkOrders.ts index 5eb48088..a685ef94 100644 --- a/helpers/lotOccupancyDB/getWorkOrders.ts +++ b/helpers/lotOccupancyDB/getWorkOrders.ts @@ -176,13 +176,15 @@ export async function getWorkOrders( const { sqlWhereClause, sqlParameters } = buildWhereClause(filters) - const count: number = database - .prepare( - `select count(*) as recordCount + const count: number = ( + database + .prepare( + `select count(*) as recordCount from WorkOrders w ${sqlWhereClause}` - ) - .get(sqlParameters).recordCount + ) + .get(sqlParameters) as { recordCount: number } + ).recordCount let workOrders: recordTypes.WorkOrder[] = [] @@ -219,7 +221,7 @@ export async function getWorkOrders( : ` limit ${options.limit} offset ${options.offset}` }` ) - .all(sqlParameters) + .all(sqlParameters) as recordTypes.WorkOrder[] } const hasInclusions = diff --git a/helpers/lotOccupancyDB/moveFee.ts b/helpers/lotOccupancyDB/moveFee.ts index 53e65c29..03de2c26 100644 --- a/helpers/lotOccupancyDB/moveFee.ts +++ b/helpers/lotOccupancyDB/moveFee.ts @@ -37,14 +37,16 @@ export async function moveFeeDownToBottom( const currentFee = await getFee(feeId, database) - const maxOrderNumber: number = database - .prepare( - `select max(orderNumber) as maxOrderNumber + const maxOrderNumber = ( + database + .prepare( + `select max(orderNumber) as maxOrderNumber from Fees where recordDelete_timeMillis is null and feeCategoryId = ?` - ) - .get(currentFee.feeCategoryId).maxOrderNumber + ) + .get(currentFee.feeCategoryId) as { maxOrderNumber: number } + ).maxOrderNumber if (currentFee.orderNumber !== maxOrderNumber) { updateRecordOrderNumber('Fees', feeId, maxOrderNumber + 1, database) diff --git a/helpers/lotOccupancyDB/moveLotTypeField.ts b/helpers/lotOccupancyDB/moveLotTypeField.ts index b23fb9b0..6092386f 100644 --- a/helpers/lotOccupancyDB/moveLotTypeField.ts +++ b/helpers/lotOccupancyDB/moveLotTypeField.ts @@ -8,17 +8,18 @@ function getCurrentField( lotTypeFieldId: number | string, connectedDatabase: PoolConnection ): { lotTypeId?: number; orderNumber: number } { - const currentField: { lotTypeId?: number; orderNumber: number } = - connectedDatabase - .prepare( - 'select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?' - ) - .get(lotTypeFieldId) + const currentField = connectedDatabase + .prepare( + 'select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?' + ) + .get(lotTypeFieldId) as { lotTypeId?: number; orderNumber: number } return currentField } -export async function moveLotTypeFieldDown(lotTypeFieldId: number | string): Promise { +export async function moveLotTypeFieldDown( + lotTypeFieldId: number | string +): Promise { const database = await acquireConnection() const currentField = getCurrentField(lotTypeFieldId, database) @@ -53,14 +54,16 @@ export async function moveLotTypeFieldDownToBottom( const currentField = getCurrentField(lotTypeFieldId, database) - const maxOrderNumber: number = database - .prepare( - `select max(orderNumber) as maxOrderNumber + const maxOrderNumber = ( + database + .prepare( + `select max(orderNumber) as maxOrderNumber from LotTypeFields where recordDelete_timeMillis is null and lotTypeId = ?` - ) - .get(currentField.lotTypeId).maxOrderNumber + ) + .get(currentField.lotTypeId) as { maxOrderNumber: number } + ).maxOrderNumber if (currentField.orderNumber !== maxOrderNumber) { updateRecordOrderNumber( @@ -88,7 +91,9 @@ export async function moveLotTypeFieldDownToBottom( return true } -export async function moveLotTypeFieldUp(lotTypeFieldId: number | string): Promise { +export async function moveLotTypeFieldUp( + lotTypeFieldId: number | string +): Promise { const database = await acquireConnection() const currentField = getCurrentField(lotTypeFieldId, database) diff --git a/helpers/lotOccupancyDB/moveOccupancyTypeField.js b/helpers/lotOccupancyDB/moveOccupancyTypeField.js index be1cea31..0acc8fbd 100644 --- a/helpers/lotOccupancyDB/moveOccupancyTypeField.js +++ b/helpers/lotOccupancyDB/moveOccupancyTypeField.js @@ -17,7 +17,9 @@ export async function moveOccupancyTypeFieldDown(occupancyTypeFieldId) { ' set orderNumber = orderNumber - 1' + ' where recordDelete_timeMillis is null' + (currentField.occupancyTypeId - ? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'" + ? " and occupancyTypeId = '" + + currentField.occupancyTypeId.toString() + + "'" : ' and occupancyTypeId is null') + ' and orderNumber = ? + 1') .run(currentField.orderNumber); @@ -70,7 +72,9 @@ export async function moveOccupancyTypeFieldUp(occupancyTypeFieldId) { ' set orderNumber = orderNumber + 1' + ' where recordDelete_timeMillis is null' + (currentField.occupancyTypeId - ? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'" + ? " and occupancyTypeId = '" + + currentField.occupancyTypeId.toString() + + "'" : ' and occupancyTypeId is null') + ' and orderNumber = ? - 1') .run(currentField.orderNumber); diff --git a/helpers/lotOccupancyDB/moveOccupancyTypeField.ts b/helpers/lotOccupancyDB/moveOccupancyTypeField.ts index 9fb8b2d4..e8205063 100644 --- a/helpers/lotOccupancyDB/moveOccupancyTypeField.ts +++ b/helpers/lotOccupancyDB/moveOccupancyTypeField.ts @@ -8,14 +8,16 @@ function getCurrentField( occupancyTypeFieldId: number, connectedDatabase: PoolConnection ): { occupancyTypeId?: number; orderNumber: number } { - const currentField: { occupancyTypeId?: number; orderNumber: number } = - connectedDatabase - .prepare( - `select occupancyTypeId, orderNumber + const currentField = connectedDatabase + .prepare( + `select occupancyTypeId, orderNumber from OccupancyTypeFields where occupancyTypeFieldId = ?` - ) - .get(occupancyTypeFieldId) + ) + .get(occupancyTypeFieldId) as { + occupancyTypeId?: number + orderNumber: number + } return currentField } @@ -33,7 +35,9 @@ export async function moveOccupancyTypeFieldDown( ' set orderNumber = orderNumber - 1' + ' where recordDelete_timeMillis is null' + (currentField.occupancyTypeId - ? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'" + ? " and occupancyTypeId = '" + + currentField.occupancyTypeId.toString() + + "'" : ' and occupancyTypeId is null') + ' and orderNumber = ? + 1' ) @@ -66,16 +70,18 @@ export async function moveOccupancyTypeFieldDownToBottom( occupancyTypeParameters.push(currentField.occupancyTypeId) } - const maxOrderNumber: number = database - .prepare( - 'select max(orderNumber) as maxOrderNumber' + - ' from OccupancyTypeFields' + - ' where recordDelete_timeMillis is null' + - (currentField.occupancyTypeId - ? ' and occupancyTypeId = ?' - : ' and occupancyTypeId is null') - ) - .get(occupancyTypeParameters).maxOrderNumber + const maxOrderNumber: number = ( + database + .prepare( + 'select max(orderNumber) as maxOrderNumber' + + ' from OccupancyTypeFields' + + ' where recordDelete_timeMillis is null' + + (currentField.occupancyTypeId + ? ' and occupancyTypeId = ?' + : ' and occupancyTypeId is null') + ) + .get(occupancyTypeParameters) as { maxOrderNumber: number } + ).maxOrderNumber if (currentField.orderNumber !== maxOrderNumber) { updateRecordOrderNumber( @@ -125,7 +131,9 @@ export async function moveOccupancyTypeFieldUp( ' set orderNumber = orderNumber + 1' + ' where recordDelete_timeMillis is null' + (currentField.occupancyTypeId - ? " and occupancyTypeId = '" + currentField.occupancyTypeId.toString() + "'" + ? " and occupancyTypeId = '" + + currentField.occupancyTypeId.toString() + + "'" : ' and occupancyTypeId is null') + ' and orderNumber = ? - 1' ) diff --git a/helpers/lotOccupancyDB/moveOccupancyTypePrintDown.ts b/helpers/lotOccupancyDB/moveOccupancyTypePrintDown.ts index 95f5b61e..6c9ca543 100644 --- a/helpers/lotOccupancyDB/moveOccupancyTypePrintDown.ts +++ b/helpers/lotOccupancyDB/moveOccupancyTypePrintDown.ts @@ -8,11 +8,13 @@ export async function moveOccupancyTypePrintDown( ): Promise { const database = await acquireConnection() - const currentOrderNumber = database - .prepare( - 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' - ) - .get(occupancyTypeId, printEJS).orderNumber + const currentOrderNumber = ( + database + .prepare( + 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' + ) + .get(occupancyTypeId, printEJS) as { orderNumber: number } + ).orderNumber database .prepare( @@ -43,20 +45,24 @@ export async function moveOccupancyTypePrintDownToBottom( ): Promise { const database = await acquireConnection() - const currentOrderNumber = database - .prepare( - 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' - ) - .get(occupancyTypeId, printEJS).orderNumber + const currentOrderNumber = ( + database + .prepare( + 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' + ) + .get(occupancyTypeId, printEJS) as { orderNumber: number } + ).orderNumber - const maxOrderNumber: number = database - .prepare( - `select max(orderNumber) as maxOrderNumber + const maxOrderNumber: number = ( + database + .prepare( + `select max(orderNumber) as maxOrderNumber from OccupancyTypePrints where recordDelete_timeMillis is null and occupancyTypeId = ?` - ) - .get(occupancyTypeId).maxOrderNumber + ) + .get(occupancyTypeId) as { maxOrderNumber: number } + ).maxOrderNumber if (currentOrderNumber !== maxOrderNumber) { database diff --git a/helpers/lotOccupancyDB/moveOccupancyTypePrintUp.ts b/helpers/lotOccupancyDB/moveOccupancyTypePrintUp.ts index c4270d04..d5284681 100644 --- a/helpers/lotOccupancyDB/moveOccupancyTypePrintUp.ts +++ b/helpers/lotOccupancyDB/moveOccupancyTypePrintUp.ts @@ -8,11 +8,13 @@ export async function moveOccupancyTypePrintUp( ): Promise { const database = await acquireConnection() - const currentOrderNumber = database - .prepare( - 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' - ) - .get(occupancyTypeId, printEJS).orderNumber + const currentOrderNumber = ( + database + .prepare( + 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' + ) + .get(occupancyTypeId, printEJS) as { orderNumber: number } + ).orderNumber if (currentOrderNumber <= 0) { database.release() @@ -48,11 +50,13 @@ export async function moveOccupancyTypePrintUpToTop( ): Promise { const database = await acquireConnection() - const currentOrderNumber = database - .prepare( - 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' - ) - .get(occupancyTypeId, printEJS).orderNumber + const currentOrderNumber = ( + database + .prepare( + 'select orderNumber from OccupancyTypePrints where occupancyTypeId = ? and printEJS = ?' + ) + .get(occupancyTypeId, printEJS) as { orderNumber: number } + ).orderNumber if (currentOrderNumber > 0) { database diff --git a/helpers/lotOccupancyDB/moveRecord.ts b/helpers/lotOccupancyDB/moveRecord.ts index 5dcaffda..c4eb3456 100644 --- a/helpers/lotOccupancyDB/moveRecord.ts +++ b/helpers/lotOccupancyDB/moveRecord.ts @@ -27,13 +27,15 @@ function getCurrentOrderNumber( recordId: number | string, database: sqlite.Database ): number { - const currentOrderNumber: number = database - .prepare( - `select orderNumber + const currentOrderNumber: number = ( + database + .prepare( + `select orderNumber from ${recordTable} where ${recordIdColumns.get(recordTable)!} = ?` - ) - .get(recordId).orderNumber + ) + .get(recordId) as { orderNumber: number } + ).orderNumber return currentOrderNumber } @@ -85,13 +87,15 @@ export async function moveRecordDownToBottom( database ) - const maxOrderNumber: number = database - .prepare( - `select max(orderNumber) as maxOrderNumber + const maxOrderNumber = ( + database + .prepare( + `select max(orderNumber) as maxOrderNumber from ${recordTable} where recordDelete_timeMillis is null` - ) - .get().maxOrderNumber + ) + .get() as { maxOrderNumber: number } + ).maxOrderNumber if (currentOrderNumber !== maxOrderNumber) { updateRecordOrderNumber(recordTable, recordId, maxOrderNumber + 1, database)