cityssm/parking-ticket-system

View on GitHub
database/parkingDB/isParkingTicketConvicted.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import sqlite from 'better-sqlite3';
import { parkingDB as databasePath } from '../../data/databasePaths.js';
export default function isParkingTicketConvicted(ticketId, connectedDatabase) {
    const database = connectedDatabase ?? sqlite(databasePath);
    const statusIndex = database
        .prepare(`select statusIndex
        from ParkingTicketStatusLog
        where recordDelete_timeMillis is null
        and ticketId = ?
        and statusKey = 'convicted'`)
        .pluck()
        .get(ticketId);
    if (connectedDatabase === undefined) {
        database.close();
    }
    return statusIndex !== undefined;
}