add lot occupancy comment
parent
2836831c54
commit
727932bda9
|
|
@ -11,7 +11,7 @@ const recordColumns = " recordCreate_userName varchar(30) not null," +
|
|||
export const initLotOccupancyDB = () => {
|
||||
const lotOccupancyDB = sqlite(databasePath);
|
||||
const row = lotOccupancyDB
|
||||
.prepare("select name from sqlite_master where type = 'table' and name = 'Lots'")
|
||||
.prepare("select name from sqlite_master where type = 'table' and name = 'LotOccupancies'")
|
||||
.get();
|
||||
if (!row) {
|
||||
debugSQL("Creating " + databasePath);
|
||||
|
|
@ -140,7 +140,7 @@ export const initLotOccupancyDB = () => {
|
|||
lotOccupancyDB.prepare("create table if not exists LotOccupancies (" +
|
||||
"lotOccupancyId integer not null primary key autoincrement," +
|
||||
" occupancyTypeId integer not null," +
|
||||
" lotId integer not null," +
|
||||
" lotId integer," +
|
||||
" occupancyStartDate integer not null check (occupancyStartDate > 0)," +
|
||||
" occupancyEndDate integer check (occupancyEndDate > 0)," +
|
||||
recordColumns + "," +
|
||||
|
|
@ -167,6 +167,17 @@ export const initLotOccupancyDB = () => {
|
|||
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," +
|
||||
" foreign key (occupancyTypeFieldId) references OccupancyTypeFields (occupancyTypeFieldId)" +
|
||||
") without rowid").run();
|
||||
lotOccupancyDB.prepare("create table if not exists LotOccupancyComments (" +
|
||||
"lotOccupancyCommentId integer not null primary key autoincrement," +
|
||||
" lotOccupancyId integer not null," +
|
||||
" lotOccupancyCommentDate integer not null check (lotOccupancyCommentDate > 0)," +
|
||||
" lotOccupancyCommentTime integer not null check (lotOccupancyCommentTime >= 0)," +
|
||||
" lotOccupancyComment text not null," +
|
||||
recordColumns + "," +
|
||||
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" +
|
||||
")").run();
|
||||
lotOccupancyDB.prepare("create index if not exists idx_lotoccupancycomments_datetime" +
|
||||
" on LotOccupancyComments (lotOccupancyId, lotOccupancyCommentDate, lotOccupancyCommentTime)").run();
|
||||
lotOccupancyDB.prepare("create table if not exists Fees (" +
|
||||
"feeId integer not null primary key autoincrement," +
|
||||
" feeName varchar(100) not null," +
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import sqlite from "better-sqlite3";
|
||||
|
||||
import { lotOccupancyDB as databasePath } from "../data/databasePaths.js";
|
||||
import {
|
||||
lotOccupancyDB as databasePath
|
||||
} from "../data/databasePaths.js";
|
||||
|
||||
import debug from "debug";
|
||||
const debugSQL = debug("lot-occupancy-system:databaseInitializer");
|
||||
|
|
@ -18,7 +20,7 @@ export const initLotOccupancyDB = (): boolean => {
|
|||
const lotOccupancyDB = sqlite(databasePath);
|
||||
|
||||
const row = lotOccupancyDB
|
||||
.prepare("select name from sqlite_master where type = 'table' and name = 'Lots'")
|
||||
.prepare("select name from sqlite_master where type = 'table' and name = 'LotOccupancies'")
|
||||
.get();
|
||||
|
||||
if (!row) {
|
||||
|
|
@ -181,7 +183,7 @@ export const initLotOccupancyDB = (): boolean => {
|
|||
lotOccupancyDB.prepare("create table if not exists LotOccupancies (" +
|
||||
"lotOccupancyId integer not null primary key autoincrement," +
|
||||
" occupancyTypeId integer not null," +
|
||||
" lotId integer not null," +
|
||||
" lotId integer," +
|
||||
" occupancyStartDate integer not null check (occupancyStartDate > 0)," +
|
||||
" occupancyEndDate integer check (occupancyEndDate > 0)," +
|
||||
recordColumns + "," +
|
||||
|
|
@ -211,6 +213,19 @@ export const initLotOccupancyDB = (): boolean => {
|
|||
" foreign key (occupancyTypeFieldId) references OccupancyTypeFields (occupancyTypeFieldId)" +
|
||||
") without rowid").run();
|
||||
|
||||
lotOccupancyDB.prepare("create table if not exists LotOccupancyComments (" +
|
||||
"lotOccupancyCommentId integer not null primary key autoincrement," +
|
||||
" lotOccupancyId integer not null," +
|
||||
" lotOccupancyCommentDate integer not null check (lotOccupancyCommentDate > 0)," +
|
||||
" lotOccupancyCommentTime integer not null check (lotOccupancyCommentTime >= 0)," +
|
||||
" lotOccupancyComment text not null," +
|
||||
recordColumns + "," +
|
||||
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" +
|
||||
")").run();
|
||||
|
||||
lotOccupancyDB.prepare("create index if not exists idx_lotoccupancycomments_datetime" +
|
||||
" on LotOccupancyComments (lotOccupancyId, lotOccupancyCommentDate, lotOccupancyCommentTime)").run();
|
||||
|
||||
// Occupancy Fees and Transactions
|
||||
|
||||
lotOccupancyDB.prepare("create table if not exists Fees (" +
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
import type * as recordTypes from "../../types/recordTypes";
|
||||
interface AddLotOccupancyCommentForm {
|
||||
lotOccupancyId: string | number;
|
||||
lotOccupancyCommentDateString: string;
|
||||
lotOccupancyCommentTimeString: string;
|
||||
lotOccupancyComment: string;
|
||||
}
|
||||
export declare const addLotOccupancyComment: (commentForm: AddLotOccupancyCommentForm, requestSession: recordTypes.PartialSession) => number;
|
||||
export default addLotOccupancyComment;
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import { dateStringToInteger, timeStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||
import sqlite from "better-sqlite3";
|
||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||
export const addLotOccupancyComment = (commentForm, requestSession) => {
|
||||
const database = sqlite(databasePath);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare("insert into LotOccupancyComments (" +
|
||||
"lotOccupancyId, lotOccupancyCommentDate, lotOccupancyCommentTime, lotOccupancyComment," +
|
||||
" recordCreate_userName, recordCreate_timeMillis," +
|
||||
" recordUpdate_userName, recordUpdate_timeMillis)" +
|
||||
" values (?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
.run(commentForm.lotOccupancyId, dateStringToInteger(commentForm.lotOccupancyCommentDateString), timeStringToInteger(commentForm.lotOccupancyCommentTimeString), commentForm.lotOccupancyComment, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
|
||||
database.close();
|
||||
return result.lastInsertRowid;
|
||||
};
|
||||
export default addLotOccupancyComment;
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
import { dateStringToInteger, timeStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||
import sqlite from "better-sqlite3";
|
||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||
|
||||
import type * as recordTypes from "../../types/recordTypes";
|
||||
|
||||
|
||||
interface AddLotOccupancyCommentForm {
|
||||
lotOccupancyId: string | number;
|
||||
lotOccupancyCommentDateString: string;
|
||||
lotOccupancyCommentTimeString: string;
|
||||
lotOccupancyComment: string;
|
||||
}
|
||||
|
||||
|
||||
export const addLotOccupancyComment =
|
||||
(commentForm: AddLotOccupancyCommentForm, requestSession: recordTypes.PartialSession): number => {
|
||||
|
||||
const database = sqlite(databasePath);
|
||||
|
||||
const rightNowMillis = Date.now();
|
||||
|
||||
const result = database
|
||||
.prepare("insert into LotOccupancyComments (" +
|
||||
"lotOccupancyId, lotOccupancyCommentDate, lotOccupancyCommentTime, lotOccupancyComment," +
|
||||
" recordCreate_userName, recordCreate_timeMillis," +
|
||||
" recordUpdate_userName, recordUpdate_timeMillis)" +
|
||||
" values (?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
.run(commentForm.lotOccupancyId,
|
||||
dateStringToInteger(commentForm.lotOccupancyCommentDateString),
|
||||
timeStringToInteger(commentForm.lotOccupancyCommentTimeString),
|
||||
commentForm.lotOccupancyComment,
|
||||
requestSession.user.userName,
|
||||
rightNowMillis,
|
||||
requestSession.user.userName,
|
||||
rightNowMillis);
|
||||
|
||||
database.close();
|
||||
|
||||
return result.lastInsertRowid as number;
|
||||
};
|
||||
|
||||
|
||||
export default addLotOccupancyComment;
|
||||
Loading…
Reference in New Issue