cityssm/parking-ticket-system

View on GitHub
database/parkingDB/deleteParkingTicket.ts

Summary

Maintainability
A
3 hrs
Test Coverage
import sqlite from 'better-sqlite3'

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

export default function deleteParkingTicket(
  ticketId: number,
  sessionUser: PTSUser
): { success: boolean } {
  const database = sqlite(databasePath)

  const info = database
    .prepare(
      `update ParkingTickets
        set recordDelete_userName = ?,
        recordDelete_timeMillis = ?
        where ticketId = ?
        and recordDelete_timeMillis is null`
    )
    .run(sessionUser.userName, Date.now(), ticketId)

  database.close()

  return {
    success: info.changes > 0
  }
}