cityssm/parking-ticket-system

View on GitHub
database/parkingDB/unlockConvictionBatch.ts

Summary

Maintainability
A
0 mins
Test Coverage
import sqlite from 'better-sqlite3'

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

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

  const rightNowMillis = Date.now()

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

  database.close()

  return info.changes > 0
}