cityssm/parking-ticket-system

View on GitHub
database/parkingDB/markLookupBatchAsSent.ts

Summary

Maintainability
A
35 mins
Test Coverage
import { dateToInteger } from '@cityssm/utils-datetime'
import sqlite from 'better-sqlite3'

import { parkingDB as databasePath } from '../../data/databasePaths.js'

export default function markLookupBatchAsSent(batchId: number,
  sessionUser: PTSUser): boolean {
  const database = sqlite(databasePath)

  const rightNow = new Date()

  const info = database
    .prepare(
      `update LicencePlateLookupBatches
        set sentDate = ?,
        recordUpdate_userName = ?,
        recordUpdate_timeMillis = ?
        where batchId = ?
        and recordDelete_timeMillis is null
        and lockDate is not null
        and sentDate is null`
    )
    .run(
      dateToInteger(rightNow),
      sessionUser.userName,
      rightNow.getTime(),
      batchId
    )

  database.close()

  return info.changes > 0
}