cityssm/parking-ticket-system

View on GitHub
database/parkingDB/createParkingTicketRemark.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { dateToInteger, dateToTimeInteger } from '@cityssm/utils-datetime';
import sqlite from 'better-sqlite3';
import { parkingDB as databasePath } from '../../data/databasePaths.js';
import getNextParkingTicketRemarkIndex from './getNextParkingTicketRemarkIndex.js';
export default function createParkingTicketRemark(requestBody, sessionUser) {
    const database = sqlite(databasePath);
    const remarkIndexNew = getNextParkingTicketRemarkIndex(requestBody.ticketId, database);
    const rightNow = new Date();
    database
        .prepare(`insert into ParkingTicketRemarks (
        ticketId, remarkIndex,
        remarkDate, remarkTime,
        remark,
        recordCreate_userName, recordCreate_timeMillis,
        recordUpdate_userName, recordUpdate_timeMillis)
        values (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
        .run(requestBody.ticketId, remarkIndexNew, dateToInteger(rightNow), dateToTimeInteger(rightNow), requestBody.remark, sessionUser.userName, rightNow.getTime(), sessionUser.userName, rightNow.getTime());
    database.close();
    return remarkIndexNew;
}