cityssm/parking-ticket-system

View on GitHub
database/parkingDB/createConvictionBatch.js

Summary

Maintainability
A
2 hrs
Test Coverage
F
14%
import { dateToInteger, dateToString } from '@cityssm/utils-datetime';
import sqlite from 'better-sqlite3';
import { parkingDB as databasePath } from '../../data/databasePaths.js';
export default function createConvictionBatch(sessionUser) {
    const database = sqlite(databasePath);
    const rightNow = new Date();
    const info = database
        .prepare(`insert into ParkingTicketConvictionBatches (
        batchDate, recordCreate_userName,
        recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis)
        values (?, ?, ?, ?, ?)`)
        .run(dateToInteger(rightNow), sessionUser.userName, rightNow.getTime(), sessionUser.userName, rightNow.getTime());
    database.close();
    return info.changes > 0
        ? {
            success: true,
            batch: {
                recordType: 'batch',
                batchId: info.lastInsertRowid,
                batchDate: dateToInteger(rightNow),
                batchDateString: dateToString(rightNow),
                lockDate: undefined,
                lockDateString: '',
                batchEntries: []
            }
        }
        : { success: false };
}