linting
parent
263c316573
commit
10fe9a612e
|
|
@ -21,6 +21,17 @@
|
||||||
"plugin:@typescript-eslint/recommended"
|
"plugin:@typescript-eslint/recommended"
|
||||||
],
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
|
"@typescript-eslint/member-delimiter-style": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"multiline": {
|
||||||
|
"delimiter": "none"
|
||||||
|
},
|
||||||
|
"singleline": {
|
||||||
|
"delimiter": "semi"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"@typescript-eslint/no-extra-semi": "off",
|
"@typescript-eslint/no-extra-semi": "off",
|
||||||
"@typescript-eslint/no-non-null-assertion": "off",
|
"@typescript-eslint/no-non-null-assertion": "off",
|
||||||
"@typescript-eslint/restrict-plus-operands": "warn",
|
"@typescript-eslint/restrict-plus-operands": "warn",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from 'express';
|
||||||
export declare const handler: RequestHandler;
|
export declare const handler: RequestHandler;
|
||||||
export default handler;
|
export default handler;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { dateToInteger, dateToString } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateToInteger, dateToString } from '@cityssm/expressjs-server-js/dateTimeFns.js';
|
||||||
import { getLotOccupantTypes, getLotStatuses, getLotTypes, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
import { getLotOccupantTypes, getLotStatuses, getLotTypes, getOccupancyTypes } from '../../helpers/functions.cache.js';
|
||||||
import { getLot } from "../../helpers/lotOccupancyDB/getLot.js";
|
import { getLot } from '../../helpers/lotOccupancyDB/getLot.js';
|
||||||
import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js";
|
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js';
|
||||||
import * as configFunctions from "../../helpers/functions.config.js";
|
import * as configFunctions from '../../helpers/functions.config.js';
|
||||||
export const handler = (request, response) => {
|
export const handler = (request, response) => {
|
||||||
const startDate = new Date();
|
const startDate = new Date();
|
||||||
const lotOccupancy = {
|
const lotOccupancy = {
|
||||||
|
|
@ -11,18 +11,20 @@ export const handler = (request, response) => {
|
||||||
};
|
};
|
||||||
if (request.query.lotId) {
|
if (request.query.lotId) {
|
||||||
const lot = getLot(request.query.lotId);
|
const lot = getLot(request.query.lotId);
|
||||||
lotOccupancy.lotId = lot.lotId;
|
if (lot) {
|
||||||
lotOccupancy.lotName = lot.lotName;
|
lotOccupancy.lotId = lot.lotId;
|
||||||
lotOccupancy.mapId = lot.mapId;
|
lotOccupancy.lotName = lot.lotName;
|
||||||
lotOccupancy.mapName = lot.mapName;
|
lotOccupancy.mapId = lot.mapId;
|
||||||
|
lotOccupancy.mapName = lot.mapName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const occupancyTypes = getOccupancyTypes();
|
const occupancyTypes = getOccupancyTypes();
|
||||||
const lotOccupantTypes = getLotOccupantTypes();
|
const lotOccupantTypes = getLotOccupantTypes();
|
||||||
const lotTypes = getLotTypes();
|
const lotTypes = getLotTypes();
|
||||||
const lotStatuses = getLotStatuses();
|
const lotStatuses = getLotStatuses();
|
||||||
const maps = getMaps();
|
const maps = getMaps();
|
||||||
return response.render("lotOccupancy-edit", {
|
response.render('lotOccupancy-edit', {
|
||||||
headTitle: `Create a New ${configFunctions.getProperty("aliases.occupancy")} Record`,
|
headTitle: `Create a New ${configFunctions.getProperty('aliases.occupancy')} Record`,
|
||||||
lotOccupancy,
|
lotOccupancy,
|
||||||
occupancyTypes,
|
occupancyTypes,
|
||||||
lotOccupantTypes,
|
lotOccupantTypes,
|
||||||
|
|
|
||||||
|
|
@ -1,55 +1,63 @@
|
||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from 'express'
|
||||||
|
|
||||||
import { dateToInteger, dateToString } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getLotOccupantTypes,
|
dateToInteger,
|
||||||
getLotStatuses,
|
dateToString
|
||||||
getLotTypes,
|
} from '@cityssm/expressjs-server-js/dateTimeFns.js'
|
||||||
getOccupancyTypes
|
|
||||||
} from "../../helpers/functions.cache.js";
|
|
||||||
|
|
||||||
import { getLot } from "../../helpers/lotOccupancyDB/getLot.js";
|
import {
|
||||||
import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js";
|
getLotOccupantTypes,
|
||||||
|
getLotStatuses,
|
||||||
|
getLotTypes,
|
||||||
|
getOccupancyTypes
|
||||||
|
} from '../../helpers/functions.cache.js'
|
||||||
|
|
||||||
import * as configFunctions from "../../helpers/functions.config.js";
|
import { getLot } from '../../helpers/lotOccupancyDB/getLot.js'
|
||||||
|
import { getMaps } from '../../helpers/lotOccupancyDB/getMaps.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import * as configFunctions from '../../helpers/functions.config.js'
|
||||||
|
|
||||||
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
export const handler: RequestHandler = (request, response) => {
|
export const handler: RequestHandler = (request, response) => {
|
||||||
const startDate = new Date();
|
const startDate = new Date()
|
||||||
|
|
||||||
const lotOccupancy: recordTypes.LotOccupancy = {
|
const lotOccupancy: recordTypes.LotOccupancy = {
|
||||||
occupancyStartDate: dateToInteger(startDate),
|
occupancyStartDate: dateToInteger(startDate),
|
||||||
occupancyStartDateString: dateToString(startDate)
|
occupancyStartDateString: dateToString(startDate)
|
||||||
};
|
}
|
||||||
|
|
||||||
if (request.query.lotId) {
|
if (request.query.lotId) {
|
||||||
const lot = getLot(request.query.lotId as string);
|
const lot = getLot(request.query.lotId as string)
|
||||||
lotOccupancy.lotId = lot.lotId;
|
|
||||||
lotOccupancy.lotName = lot.lotName;
|
if (lot) {
|
||||||
lotOccupancy.mapId = lot.mapId;
|
lotOccupancy.lotId = lot.lotId
|
||||||
lotOccupancy.mapName = lot.mapName;
|
lotOccupancy.lotName = lot.lotName
|
||||||
|
lotOccupancy.mapId = lot.mapId
|
||||||
|
lotOccupancy.mapName = lot.mapName
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const occupancyTypes = getOccupancyTypes();
|
const occupancyTypes = getOccupancyTypes()
|
||||||
const lotOccupantTypes = getLotOccupantTypes();
|
const lotOccupantTypes = getLotOccupantTypes()
|
||||||
const lotTypes = getLotTypes();
|
const lotTypes = getLotTypes()
|
||||||
const lotStatuses = getLotStatuses();
|
const lotStatuses = getLotStatuses()
|
||||||
const maps = getMaps();
|
const maps = getMaps()
|
||||||
|
|
||||||
return response.render("lotOccupancy-edit", {
|
response.render('lotOccupancy-edit', {
|
||||||
headTitle: `Create a New ${configFunctions.getProperty("aliases.occupancy")} Record`,
|
headTitle: `Create a New ${configFunctions.getProperty(
|
||||||
lotOccupancy,
|
'aliases.occupancy'
|
||||||
|
)} Record`,
|
||||||
|
lotOccupancy,
|
||||||
|
|
||||||
occupancyTypes,
|
occupancyTypes,
|
||||||
lotOccupantTypes,
|
lotOccupantTypes,
|
||||||
lotTypes,
|
lotTypes,
|
||||||
lotStatuses,
|
lotStatuses,
|
||||||
maps,
|
maps,
|
||||||
|
|
||||||
isCreate: true
|
isCreate: true
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
export default handler;
|
export default handler
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ interface WhereClauseReturn {
|
||||||
sqlWhereClause: string;
|
sqlWhereClause: string;
|
||||||
sqlParameters: unknown[];
|
sqlParameters: unknown[];
|
||||||
}
|
}
|
||||||
export declare function getLotNameWhereClause(lotName: string | undefined, lotNameSearchType: LotNameSearchType, lotsTableAlias?: string): WhereClauseReturn;
|
export declare function getLotNameWhereClause(lotName: string | undefined, lotNameSearchType: LotNameSearchType | undefined, lotsTableAlias?: string): WhereClauseReturn;
|
||||||
declare type OccupancyTime = '' | 'current' | 'past' | 'future';
|
declare type OccupancyTime = '' | 'current' | 'past' | 'future';
|
||||||
export declare function getOccupancyTimeWhereClause(occupancyTime: OccupancyTime, lotOccupanciesTableAlias?: string): WhereClauseReturn;
|
export declare function getOccupancyTimeWhereClause(occupancyTime: OccupancyTime | undefined, lotOccupanciesTableAlias?: string): WhereClauseReturn;
|
||||||
export declare function getOccupantNameWhereClause(occupantName?: string, tableAlias?: string): WhereClauseReturn;
|
export declare function getOccupantNameWhereClause(occupantName?: string, tableAlias?: string): WhereClauseReturn;
|
||||||
export {};
|
export {};
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ export function getLotNameWhereClause(lotName = '', lotNameSearchType, lotsTable
|
||||||
export function getOccupancyTimeWhereClause(occupancyTime, lotOccupanciesTableAlias = 'o') {
|
export function getOccupancyTimeWhereClause(occupancyTime, lotOccupanciesTableAlias = 'o') {
|
||||||
let sqlWhereClause = '';
|
let sqlWhereClause = '';
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
if (occupancyTime !== '') {
|
if (occupancyTime) {
|
||||||
const currentDateString = dateToInteger(new Date());
|
const currentDateString = dateToInteger(new Date());
|
||||||
switch (occupancyTime) {
|
switch (occupancyTime) {
|
||||||
case 'current': {
|
case 'current': {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ interface WhereClauseReturn {
|
||||||
|
|
||||||
export function getLotNameWhereClause(
|
export function getLotNameWhereClause(
|
||||||
lotName = '',
|
lotName = '',
|
||||||
lotNameSearchType: LotNameSearchType,
|
lotNameSearchType: LotNameSearchType | undefined,
|
||||||
lotsTableAlias = 'l'
|
lotsTableAlias = 'l'
|
||||||
): WhereClauseReturn {
|
): WhereClauseReturn {
|
||||||
let sqlWhereClause = ''
|
let sqlWhereClause = ''
|
||||||
|
|
@ -47,13 +47,13 @@ export function getLotNameWhereClause(
|
||||||
type OccupancyTime = '' | 'current' | 'past' | 'future'
|
type OccupancyTime = '' | 'current' | 'past' | 'future'
|
||||||
|
|
||||||
export function getOccupancyTimeWhereClause(
|
export function getOccupancyTimeWhereClause(
|
||||||
occupancyTime: OccupancyTime,
|
occupancyTime: OccupancyTime | undefined,
|
||||||
lotOccupanciesTableAlias = 'o'
|
lotOccupanciesTableAlias = 'o'
|
||||||
): WhereClauseReturn {
|
): WhereClauseReturn {
|
||||||
let sqlWhereClause = ''
|
let sqlWhereClause = ''
|
||||||
const sqlParameters: unknown[] = []
|
const sqlParameters: unknown[] = []
|
||||||
|
|
||||||
if (occupancyTime !== '') {
|
if (occupancyTime) {
|
||||||
const currentDateString = dateToInteger(new Date())
|
const currentDateString = dateToInteger(new Date())
|
||||||
|
|
||||||
switch (occupancyTime) {
|
switch (occupancyTime) {
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ interface AddFeeForm {
|
||||||
feeCategoryId: string;
|
feeCategoryId: string;
|
||||||
feeName: string;
|
feeName: string;
|
||||||
feeDescription: string;
|
feeDescription: string;
|
||||||
occupancyTypeId?: string;
|
occupancyTypeId: string;
|
||||||
lotTypeId?: string;
|
lotTypeId: string;
|
||||||
feeAmount?: string;
|
feeAmount?: string;
|
||||||
feeFunction?: string;
|
feeFunction: string;
|
||||||
taxAmount?: string;
|
taxAmount?: string;
|
||||||
taxPercentage?: string;
|
taxPercentage?: string;
|
||||||
includeQuantity: '' | '1';
|
includeQuantity: '' | '1';
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ export function addFee(feeForm, requestSession) {
|
||||||
recordCreate_userName, recordCreate_timeMillis,
|
recordCreate_userName, recordCreate_timeMillis,
|
||||||
recordUpdate_userName, recordUpdate_timeMillis)
|
recordUpdate_userName, recordUpdate_timeMillis)
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
||||||
.run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.occupancyTypeId ?? undefined, feeForm.lotTypeId ?? undefined, feeForm.feeAmount ?? undefined, feeForm.feeFunction ?? undefined, feeForm.taxAmount ?? undefined, feeForm.taxPercentage ?? undefined, (feeForm.includeQuantity ?? '') === '' ? 0 : 1, feeForm.quantityUnit, (feeForm.isRequired ?? '') === '' ? 0 : 1, feeForm.orderNumber ?? -1, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
|
.run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.occupancyTypeId === '' ? undefined : feeForm.occupancyTypeId, feeForm.lotTypeId === '' ? undefined : feeForm.lotTypeId, feeForm.feeAmount ?? undefined, feeForm.feeFunction ?? undefined, feeForm.taxAmount ?? undefined, feeForm.taxPercentage ?? undefined, (feeForm.includeQuantity ?? '') === '' ? 0 : 1, feeForm.quantityUnit, (feeForm.isRequired ?? '') === '' ? 0 : 1, feeForm.orderNumber ?? -1, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
|
||||||
database.close();
|
database.close();
|
||||||
return result.lastInsertRowid;
|
return result.lastInsertRowid;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ interface AddFeeForm {
|
||||||
feeCategoryId: string
|
feeCategoryId: string
|
||||||
feeName: string
|
feeName: string
|
||||||
feeDescription: string
|
feeDescription: string
|
||||||
occupancyTypeId?: string
|
occupancyTypeId: string
|
||||||
lotTypeId?: string
|
lotTypeId: string
|
||||||
feeAmount?: string
|
feeAmount?: string
|
||||||
feeFunction?: string
|
feeFunction: string
|
||||||
taxAmount?: string
|
taxAmount?: string
|
||||||
taxPercentage?: string
|
taxPercentage?: string
|
||||||
includeQuantity: '' | '1'
|
includeQuantity: '' | '1'
|
||||||
|
|
@ -47,8 +47,8 @@ export function addFee(
|
||||||
feeForm.feeCategoryId,
|
feeForm.feeCategoryId,
|
||||||
feeForm.feeName,
|
feeForm.feeName,
|
||||||
feeForm.feeDescription,
|
feeForm.feeDescription,
|
||||||
feeForm.occupancyTypeId ?? undefined,
|
feeForm.occupancyTypeId === '' ? undefined : feeForm.occupancyTypeId,
|
||||||
feeForm.lotTypeId ?? undefined,
|
feeForm.lotTypeId === '' ? undefined : feeForm.lotTypeId,
|
||||||
feeForm.feeAmount ?? undefined,
|
feeForm.feeAmount ?? undefined,
|
||||||
feeForm.feeFunction ?? undefined,
|
feeForm.feeFunction ?? undefined,
|
||||||
feeForm.taxAmount ?? undefined,
|
feeForm.taxAmount ?? undefined,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
export declare function getLotByLotName(lotName: string): recordTypes.Lot | undefined;
|
export declare function getLotByLotName(lotName: string): recordTypes.Lot | undefined;
|
||||||
export declare function getLot(lotId: number | string): recordTypes.Lot;
|
export declare function getLot(lotId: number | string): recordTypes.Lot | undefined;
|
||||||
export default getLot;
|
export default getLot;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { getLotFields } from "./getLotFields.js";
|
import { getLotFields } from './getLotFields.js';
|
||||||
import { getLotComments } from "./getLotComments.js";
|
import { getLotComments } from './getLotComments.js';
|
||||||
import { getLotOccupancies } from "./getLotOccupancies.js";
|
import { getLotOccupancies } from './getLotOccupancies.js';
|
||||||
const baseSQL = `select l.lotId, l.lotTypeId, t.lotType, l.lotName, l.lotStatusId, s.lotStatus,
|
const baseSQL = `select l.lotId, l.lotTypeId, t.lotType, l.lotName, l.lotStatusId, s.lotStatus,
|
||||||
l.mapId, m.mapName, m.mapSVG, l.mapKey,
|
l.mapId, m.mapName, m.mapSVG, l.mapKey,
|
||||||
l.lotLatitude, l.lotLongitude
|
l.lotLatitude, l.lotLongitude
|
||||||
|
|
@ -11,11 +11,11 @@ const baseSQL = `select l.lotId, l.lotTypeId, t.lotType, l.lotName, l.lotStatusI
|
||||||
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
||||||
left join Maps m on l.mapId = m.mapId
|
left join Maps m on l.mapId = m.mapId
|
||||||
where l.recordDelete_timeMillis is null`;
|
where l.recordDelete_timeMillis is null`;
|
||||||
function _getLot(sql, lotId_or_lotName) {
|
function _getLot(sql, lotIdOrLotName) {
|
||||||
const database = sqlite(databasePath, {
|
const database = sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
});
|
});
|
||||||
const lot = database.prepare(sql).get(lotId_or_lotName);
|
const lot = database.prepare(sql).get(lotIdOrLotName);
|
||||||
if (lot) {
|
if (lot) {
|
||||||
lot.lotOccupancies = getLotOccupancies({
|
lot.lotOccupancies = getLotOccupancies({
|
||||||
lotId: lot.lotId
|
lotId: lot.lotId
|
||||||
|
|
@ -31,9 +31,9 @@ function _getLot(sql, lotId_or_lotName) {
|
||||||
return lot;
|
return lot;
|
||||||
}
|
}
|
||||||
export function getLotByLotName(lotName) {
|
export function getLotByLotName(lotName) {
|
||||||
return _getLot(baseSQL + " and l.lotName = ?", lotName);
|
return _getLot(baseSQL + ' and l.lotName = ?', lotName);
|
||||||
}
|
}
|
||||||
export function getLot(lotId) {
|
export function getLot(lotId) {
|
||||||
return _getLot(baseSQL + " and l.lotId = ?", lotId);
|
return _getLot(baseSQL + ' and l.lotId = ?', lotId);
|
||||||
}
|
}
|
||||||
export default getLot;
|
export default getLot;
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import { getLotFields } from "./getLotFields.js";
|
import { getLotFields } from './getLotFields.js'
|
||||||
|
|
||||||
import { getLotComments } from "./getLotComments.js";
|
import { getLotComments } from './getLotComments.js'
|
||||||
|
|
||||||
import { getLotOccupancies } from "./getLotOccupancies.js";
|
import { getLotOccupancies } from './getLotOccupancies.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
const baseSQL = `select l.lotId, l.lotTypeId, t.lotType, l.lotName, l.lotStatusId, s.lotStatus,
|
const baseSQL = `select l.lotId, l.lotTypeId, t.lotType, l.lotName, l.lotStatusId, s.lotStatus,
|
||||||
l.mapId, m.mapName, m.mapSVG, l.mapKey,
|
l.mapId, m.mapName, m.mapSVG, l.mapKey,
|
||||||
|
|
@ -17,44 +17,47 @@ const baseSQL = `select l.lotId, l.lotTypeId, t.lotType, l.lotName, l.lotStatusI
|
||||||
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
||||||
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
||||||
left join Maps m on l.mapId = m.mapId
|
left join Maps m on l.mapId = m.mapId
|
||||||
where l.recordDelete_timeMillis is null`;
|
where l.recordDelete_timeMillis is null`
|
||||||
|
|
||||||
function _getLot(sql: string, lotId_or_lotName: number | string): recordTypes.Lot | undefined {
|
function _getLot(
|
||||||
const database = sqlite(databasePath, {
|
sql: string,
|
||||||
readonly: true
|
lotIdOrLotName: number | string
|
||||||
});
|
): recordTypes.Lot | undefined {
|
||||||
|
const database = sqlite(databasePath, {
|
||||||
|
readonly: true
|
||||||
|
})
|
||||||
|
|
||||||
const lot: recordTypes.Lot = database.prepare(sql).get(lotId_or_lotName);
|
const lot: recordTypes.Lot = database.prepare(sql).get(lotIdOrLotName)
|
||||||
|
|
||||||
if (lot) {
|
if (lot) {
|
||||||
lot.lotOccupancies = getLotOccupancies(
|
lot.lotOccupancies = getLotOccupancies(
|
||||||
{
|
{
|
||||||
lotId: lot.lotId
|
lotId: lot.lotId
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
includeOccupants: true,
|
includeOccupants: true,
|
||||||
limit: -1,
|
limit: -1,
|
||||||
offset: 0
|
offset: 0
|
||||||
},
|
},
|
||||||
database
|
database
|
||||||
).lotOccupancies;
|
).lotOccupancies
|
||||||
|
|
||||||
lot.lotFields = getLotFields(lot.lotId, database);
|
lot.lotFields = getLotFields(lot.lotId, database)
|
||||||
|
|
||||||
lot.lotComments = getLotComments(lot.lotId, database);
|
lot.lotComments = getLotComments(lot.lotId, database)
|
||||||
}
|
}
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return lot;
|
return lot
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLotByLotName(lotName: string): recordTypes.Lot | undefined {
|
export function getLotByLotName(lotName: string): recordTypes.Lot | undefined {
|
||||||
return _getLot(baseSQL + " and l.lotName = ?", lotName);
|
return _getLot(baseSQL + ' and l.lotName = ?', lotName)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLot(lotId: number | string): recordTypes.Lot {
|
export function getLot(lotId: number | string): recordTypes.Lot | undefined {
|
||||||
return _getLot(baseSQL + " and l.lotId = ?", lotId);
|
return _getLot(baseSQL + ' and l.lotId = ?', lotId)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getLot;
|
export default getLot
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface GetLotsFilters {
|
interface GetLotsFilters {
|
||||||
lotNameSearchType?: "" | "startsWith" | "endsWith";
|
lotNameSearchType?: '' | 'startsWith' | 'endsWith';
|
||||||
lotName?: string;
|
lotName?: string;
|
||||||
mapId?: number | string;
|
mapId?: number | string;
|
||||||
lotTypeId?: number | string;
|
lotTypeId?: number | string;
|
||||||
lotStatusId?: number | string;
|
lotStatusId?: number | string;
|
||||||
occupancyStatus?: "" | "occupied" | "unoccupied";
|
occupancyStatus?: '' | 'occupied' | 'unoccupied';
|
||||||
workOrderId?: number | string;
|
workOrderId?: number | string;
|
||||||
}
|
}
|
||||||
interface GetLotsOptions {
|
interface GetLotsOptions {
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,38 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateToInteger } from '@cityssm/expressjs-server-js/dateTimeFns.js';
|
||||||
import * as configFunctions from "../functions.config.js";
|
import * as configFunctions from '../functions.config.js';
|
||||||
import { getLotNameWhereClause } from "../functions.sqlFilters.js";
|
import { getLotNameWhereClause } from '../functions.sqlFilters.js';
|
||||||
function buildWhereClause(filters) {
|
function buildWhereClause(filters) {
|
||||||
let sqlWhereClause = " where l.recordDelete_timeMillis is null";
|
let sqlWhereClause = ' where l.recordDelete_timeMillis is null';
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
const lotNameFilters = getLotNameWhereClause(filters.lotName, filters.lotNameSearchType, "l");
|
const lotNameFilters = getLotNameWhereClause(filters.lotName, filters.lotNameSearchType ?? '', 'l');
|
||||||
sqlWhereClause += lotNameFilters.sqlWhereClause;
|
sqlWhereClause += lotNameFilters.sqlWhereClause;
|
||||||
sqlParameters.push(...lotNameFilters.sqlParameters);
|
sqlParameters.push(...lotNameFilters.sqlParameters);
|
||||||
if (filters.mapId) {
|
if (filters.mapId) {
|
||||||
sqlWhereClause += " and l.mapId = ?";
|
sqlWhereClause += ' and l.mapId = ?';
|
||||||
sqlParameters.push(filters.mapId);
|
sqlParameters.push(filters.mapId);
|
||||||
}
|
}
|
||||||
if (filters.lotTypeId) {
|
if (filters.lotTypeId) {
|
||||||
sqlWhereClause += " and l.lotTypeId = ?";
|
sqlWhereClause += ' and l.lotTypeId = ?';
|
||||||
sqlParameters.push(filters.lotTypeId);
|
sqlParameters.push(filters.lotTypeId);
|
||||||
}
|
}
|
||||||
if (filters.lotStatusId) {
|
if (filters.lotStatusId) {
|
||||||
sqlWhereClause += " and l.lotStatusId = ?";
|
sqlWhereClause += ' and l.lotStatusId = ?';
|
||||||
sqlParameters.push(filters.lotStatusId);
|
sqlParameters.push(filters.lotStatusId);
|
||||||
}
|
}
|
||||||
if (filters.occupancyStatus) {
|
if (filters.occupancyStatus) {
|
||||||
if (filters.occupancyStatus === "occupied") {
|
if (filters.occupancyStatus === 'occupied') {
|
||||||
sqlWhereClause += " and lotOccupancyCount > 0";
|
sqlWhereClause += ' and lotOccupancyCount > 0';
|
||||||
}
|
}
|
||||||
else if (filters.occupancyStatus === "unoccupied") {
|
else if (filters.occupancyStatus === 'unoccupied') {
|
||||||
sqlWhereClause += " and (lotOccupancyCount is null or lotOccupancyCount = 0)";
|
sqlWhereClause +=
|
||||||
|
' and (lotOccupancyCount is null or lotOccupancyCount = 0)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (filters.workOrderId) {
|
if (filters.workOrderId) {
|
||||||
sqlWhereClause +=
|
sqlWhereClause +=
|
||||||
" and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)";
|
' and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)';
|
||||||
sqlParameters.push(filters.workOrderId);
|
sqlParameters.push(filters.workOrderId);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
@ -40,7 +41,7 @@ function buildWhereClause(filters) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export function getLots(filters, options, connectedDatabase) {
|
export function getLots(filters, options, connectedDatabase) {
|
||||||
const database = connectedDatabase ||
|
const database = connectedDatabase ??
|
||||||
sqlite(databasePath, {
|
sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
});
|
});
|
||||||
|
|
@ -49,47 +50,47 @@ export function getLots(filters, options, connectedDatabase) {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
if (options.limit !== -1) {
|
if (options.limit !== -1) {
|
||||||
count = database
|
count = database
|
||||||
.prepare("select count(*) as recordCount" +
|
.prepare('select count(*) as recordCount' +
|
||||||
" from Lots l" +
|
' from Lots l' +
|
||||||
(" left join (" +
|
(' left join (' +
|
||||||
"select lotId, count(lotOccupancyId) as lotOccupancyCount" +
|
'select lotId, count(lotOccupancyId) as lotOccupancyCount' +
|
||||||
" from LotOccupancies" +
|
' from LotOccupancies' +
|
||||||
" where recordDelete_timeMillis is null" +
|
' where recordDelete_timeMillis is null' +
|
||||||
" and occupancyStartDate <= " +
|
' and occupancyStartDate <= ' +
|
||||||
currentDate +
|
currentDate +
|
||||||
" and (occupancyEndDate is null or occupancyEndDate >= " +
|
' and (occupancyEndDate is null or occupancyEndDate >= ' +
|
||||||
currentDate +
|
currentDate +
|
||||||
")" +
|
')' +
|
||||||
" group by lotId" +
|
' group by lotId' +
|
||||||
") o on l.lotId = o.lotId") +
|
') o on l.lotId = o.lotId') +
|
||||||
sqlWhereClause)
|
sqlWhereClause)
|
||||||
.get(sqlParameters).recordCount;
|
.get(sqlParameters).recordCount;
|
||||||
}
|
}
|
||||||
let lots = [];
|
let lots = [];
|
||||||
if (options.limit === -1 || count > 0) {
|
if (options.limit === -1 || count > 0) {
|
||||||
database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction"));
|
database.function('userFn_lotNameSortName', configFunctions.getProperty('settings.lot.lotNameSortNameFunction'));
|
||||||
sqlParameters.unshift(currentDate, currentDate);
|
sqlParameters.unshift(currentDate, currentDate);
|
||||||
lots = database
|
lots = database
|
||||||
.prepare("select l.lotId, l.lotName," +
|
.prepare('select l.lotId, l.lotName,' +
|
||||||
" t.lotType," +
|
' t.lotType,' +
|
||||||
" l.mapId, m.mapName, l.mapKey," +
|
' l.mapId, m.mapName, l.mapKey,' +
|
||||||
" l.lotStatusId, s.lotStatus," +
|
' l.lotStatusId, s.lotStatus,' +
|
||||||
" ifnull(o.lotOccupancyCount, 0) as lotOccupancyCount" +
|
' ifnull(o.lotOccupancyCount, 0) as lotOccupancyCount' +
|
||||||
" from Lots l" +
|
' from Lots l' +
|
||||||
" left join LotTypes t on l.lotTypeId = t.lotTypeId" +
|
' left join LotTypes t on l.lotTypeId = t.lotTypeId' +
|
||||||
" left join LotStatuses s on l.lotStatusId = s.lotStatusId" +
|
' left join LotStatuses s on l.lotStatusId = s.lotStatusId' +
|
||||||
" left join Maps m on l.mapId = m.mapId" +
|
' left join Maps m on l.mapId = m.mapId' +
|
||||||
(" left join (" +
|
(' left join (' +
|
||||||
"select lotId, count(lotOccupancyId) as lotOccupancyCount" +
|
'select lotId, count(lotOccupancyId) as lotOccupancyCount' +
|
||||||
" from LotOccupancies" +
|
' from LotOccupancies' +
|
||||||
" where recordDelete_timeMillis is null" +
|
' where recordDelete_timeMillis is null' +
|
||||||
" and occupancyStartDate <= ?" +
|
' and occupancyStartDate <= ?' +
|
||||||
" and (occupancyEndDate is null or occupancyEndDate >= ?)" +
|
' and (occupancyEndDate is null or occupancyEndDate >= ?)' +
|
||||||
" group by lotId" +
|
' group by lotId' +
|
||||||
") o on l.lotId = o.lotId") +
|
') o on l.lotId = o.lotId') +
|
||||||
sqlWhereClause +
|
sqlWhereClause +
|
||||||
" order by userFn_lotNameSortName(l.lotName), l.lotId" +
|
' order by userFn_lotNameSortName(l.lotName), l.lotId' +
|
||||||
(options ? ` limit ${options.limit} offset ${options.offset}` : ""))
|
(options ? ` limit ${options.limit} offset ${options.offset}` : ''))
|
||||||
.all(sqlParameters);
|
.all(sqlParameters);
|
||||||
if (options.limit === -1) {
|
if (options.limit === -1) {
|
||||||
count = lots.length;
|
count = lots.length;
|
||||||
|
|
|
||||||
|
|
@ -1,164 +1,171 @@
|
||||||
import sqlite from "better-sqlite3";
|
/* eslint-disable @typescript-eslint/indent */
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import * as configFunctions from "../functions.config.js";
|
import { dateToInteger } from '@cityssm/expressjs-server-js/dateTimeFns.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import * as configFunctions from '../functions.config.js'
|
||||||
import { getLotNameWhereClause } from "../functions.sqlFilters.js";
|
|
||||||
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
import { getLotNameWhereClause } from '../functions.sqlFilters.js'
|
||||||
|
|
||||||
interface GetLotsFilters {
|
interface GetLotsFilters {
|
||||||
lotNameSearchType?: "" | "startsWith" | "endsWith";
|
lotNameSearchType?: '' | 'startsWith' | 'endsWith'
|
||||||
lotName?: string;
|
lotName?: string
|
||||||
mapId?: number | string;
|
mapId?: number | string
|
||||||
lotTypeId?: number | string;
|
lotTypeId?: number | string
|
||||||
lotStatusId?: number | string;
|
lotStatusId?: number | string
|
||||||
occupancyStatus?: "" | "occupied" | "unoccupied";
|
occupancyStatus?: '' | 'occupied' | 'unoccupied'
|
||||||
workOrderId?: number | string;
|
workOrderId?: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GetLotsOptions {
|
interface GetLotsOptions {
|
||||||
limit: -1 | number;
|
limit: -1 | number
|
||||||
offset: number;
|
offset: number
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildWhereClause(filters: GetLotsFilters): {
|
function buildWhereClause(filters: GetLotsFilters): {
|
||||||
sqlWhereClause: string;
|
sqlWhereClause: string
|
||||||
sqlParameters: unknown[];
|
sqlParameters: unknown[]
|
||||||
} {
|
} {
|
||||||
let sqlWhereClause = " where l.recordDelete_timeMillis is null";
|
let sqlWhereClause = ' where l.recordDelete_timeMillis is null'
|
||||||
const sqlParameters: unknown[] = [];
|
const sqlParameters: unknown[] = []
|
||||||
|
|
||||||
const lotNameFilters = getLotNameWhereClause(filters.lotName, filters.lotNameSearchType, "l");
|
const lotNameFilters = getLotNameWhereClause(
|
||||||
sqlWhereClause += lotNameFilters.sqlWhereClause;
|
filters.lotName,
|
||||||
sqlParameters.push(...lotNameFilters.sqlParameters);
|
filters.lotNameSearchType ?? '',
|
||||||
|
'l'
|
||||||
|
)
|
||||||
|
sqlWhereClause += lotNameFilters.sqlWhereClause
|
||||||
|
sqlParameters.push(...lotNameFilters.sqlParameters)
|
||||||
|
|
||||||
if (filters.mapId) {
|
if (filters.mapId) {
|
||||||
sqlWhereClause += " and l.mapId = ?";
|
sqlWhereClause += ' and l.mapId = ?'
|
||||||
sqlParameters.push(filters.mapId);
|
sqlParameters.push(filters.mapId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filters.lotTypeId) {
|
||||||
|
sqlWhereClause += ' and l.lotTypeId = ?'
|
||||||
|
sqlParameters.push(filters.lotTypeId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filters.lotStatusId) {
|
||||||
|
sqlWhereClause += ' and l.lotStatusId = ?'
|
||||||
|
sqlParameters.push(filters.lotStatusId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filters.occupancyStatus) {
|
||||||
|
if (filters.occupancyStatus === 'occupied') {
|
||||||
|
sqlWhereClause += ' and lotOccupancyCount > 0'
|
||||||
|
} else if (filters.occupancyStatus === 'unoccupied') {
|
||||||
|
sqlWhereClause +=
|
||||||
|
' and (lotOccupancyCount is null or lotOccupancyCount = 0)'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (filters.lotTypeId) {
|
if (filters.workOrderId) {
|
||||||
sqlWhereClause += " and l.lotTypeId = ?";
|
sqlWhereClause +=
|
||||||
sqlParameters.push(filters.lotTypeId);
|
' and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)'
|
||||||
}
|
sqlParameters.push(filters.workOrderId)
|
||||||
|
}
|
||||||
|
|
||||||
if (filters.lotStatusId) {
|
return {
|
||||||
sqlWhereClause += " and l.lotStatusId = ?";
|
sqlWhereClause,
|
||||||
sqlParameters.push(filters.lotStatusId);
|
sqlParameters
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filters.occupancyStatus) {
|
|
||||||
if (filters.occupancyStatus === "occupied") {
|
|
||||||
sqlWhereClause += " and lotOccupancyCount > 0";
|
|
||||||
} else if (filters.occupancyStatus === "unoccupied") {
|
|
||||||
sqlWhereClause += " and (lotOccupancyCount is null or lotOccupancyCount = 0)";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filters.workOrderId) {
|
|
||||||
sqlWhereClause +=
|
|
||||||
" and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)";
|
|
||||||
sqlParameters.push(filters.workOrderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
sqlWhereClause,
|
|
||||||
sqlParameters
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLots(
|
export function getLots(
|
||||||
filters: GetLotsFilters,
|
filters: GetLotsFilters,
|
||||||
options: GetLotsOptions,
|
options: GetLotsOptions,
|
||||||
connectedDatabase?: sqlite.Database
|
connectedDatabase?: sqlite.Database
|
||||||
): {
|
): {
|
||||||
count: number;
|
count: number
|
||||||
lots: recordTypes.Lot[];
|
lots: recordTypes.Lot[]
|
||||||
} {
|
} {
|
||||||
const database =
|
const database =
|
||||||
connectedDatabase ||
|
connectedDatabase ??
|
||||||
sqlite(databasePath, {
|
sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
});
|
})
|
||||||
|
|
||||||
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters)
|
||||||
|
|
||||||
const currentDate = dateToInteger(new Date());
|
const currentDate = dateToInteger(new Date())
|
||||||
|
|
||||||
let count = 0;
|
let count = 0
|
||||||
|
|
||||||
if (options.limit !== -1) {
|
if (options.limit !== -1) {
|
||||||
count = database
|
count = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select count(*) as recordCount" +
|
'select count(*) as recordCount' +
|
||||||
" from Lots l" +
|
' from Lots l' +
|
||||||
(" left join (" +
|
(' left join (' +
|
||||||
"select lotId, count(lotOccupancyId) as lotOccupancyCount" +
|
'select lotId, count(lotOccupancyId) as lotOccupancyCount' +
|
||||||
" from LotOccupancies" +
|
' from LotOccupancies' +
|
||||||
" where recordDelete_timeMillis is null" +
|
' where recordDelete_timeMillis is null' +
|
||||||
" and occupancyStartDate <= " +
|
' and occupancyStartDate <= ' +
|
||||||
currentDate +
|
currentDate +
|
||||||
" and (occupancyEndDate is null or occupancyEndDate >= " +
|
' and (occupancyEndDate is null or occupancyEndDate >= ' +
|
||||||
currentDate +
|
currentDate +
|
||||||
")" +
|
')' +
|
||||||
" group by lotId" +
|
' group by lotId' +
|
||||||
") o on l.lotId = o.lotId") +
|
') o on l.lotId = o.lotId') +
|
||||||
sqlWhereClause
|
sqlWhereClause
|
||||||
)
|
)
|
||||||
.get(sqlParameters).recordCount;
|
.get(sqlParameters).recordCount
|
||||||
|
}
|
||||||
|
|
||||||
|
let lots: recordTypes.Lot[] = []
|
||||||
|
|
||||||
|
if (options.limit === -1 || count > 0) {
|
||||||
|
database.function(
|
||||||
|
'userFn_lotNameSortName',
|
||||||
|
configFunctions.getProperty('settings.lot.lotNameSortNameFunction')
|
||||||
|
)
|
||||||
|
|
||||||
|
sqlParameters.unshift(currentDate, currentDate)
|
||||||
|
|
||||||
|
lots = database
|
||||||
|
.prepare(
|
||||||
|
'select l.lotId, l.lotName,' +
|
||||||
|
' t.lotType,' +
|
||||||
|
' l.mapId, m.mapName, l.mapKey,' +
|
||||||
|
' l.lotStatusId, s.lotStatus,' +
|
||||||
|
' ifnull(o.lotOccupancyCount, 0) as lotOccupancyCount' +
|
||||||
|
' from Lots l' +
|
||||||
|
' left join LotTypes t on l.lotTypeId = t.lotTypeId' +
|
||||||
|
' left join LotStatuses s on l.lotStatusId = s.lotStatusId' +
|
||||||
|
' left join Maps m on l.mapId = m.mapId' +
|
||||||
|
(' left join (' +
|
||||||
|
'select lotId, count(lotOccupancyId) as lotOccupancyCount' +
|
||||||
|
' from LotOccupancies' +
|
||||||
|
' where recordDelete_timeMillis is null' +
|
||||||
|
' and occupancyStartDate <= ?' +
|
||||||
|
' and (occupancyEndDate is null or occupancyEndDate >= ?)' +
|
||||||
|
' group by lotId' +
|
||||||
|
') o on l.lotId = o.lotId') +
|
||||||
|
sqlWhereClause +
|
||||||
|
' order by userFn_lotNameSortName(l.lotName), l.lotId' +
|
||||||
|
(options ? ` limit ${options.limit} offset ${options.offset}` : '')
|
||||||
|
)
|
||||||
|
.all(sqlParameters)
|
||||||
|
|
||||||
|
if (options.limit === -1) {
|
||||||
|
count = lots.length
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let lots: recordTypes.Lot[] = [];
|
if (!connectedDatabase) {
|
||||||
|
database.close()
|
||||||
|
}
|
||||||
|
|
||||||
if (options.limit === -1 || count > 0) {
|
return {
|
||||||
database.function(
|
count,
|
||||||
"userFn_lotNameSortName",
|
lots
|
||||||
configFunctions.getProperty("settings.lot.lotNameSortNameFunction")
|
}
|
||||||
);
|
|
||||||
|
|
||||||
sqlParameters.unshift(currentDate, currentDate);
|
|
||||||
|
|
||||||
lots = database
|
|
||||||
.prepare(
|
|
||||||
"select l.lotId, l.lotName," +
|
|
||||||
" t.lotType," +
|
|
||||||
" l.mapId, m.mapName, l.mapKey," +
|
|
||||||
" l.lotStatusId, s.lotStatus," +
|
|
||||||
" ifnull(o.lotOccupancyCount, 0) as lotOccupancyCount" +
|
|
||||||
" from Lots l" +
|
|
||||||
" left join LotTypes t on l.lotTypeId = t.lotTypeId" +
|
|
||||||
" left join LotStatuses s on l.lotStatusId = s.lotStatusId" +
|
|
||||||
" left join Maps m on l.mapId = m.mapId" +
|
|
||||||
(" left join (" +
|
|
||||||
"select lotId, count(lotOccupancyId) as lotOccupancyCount" +
|
|
||||||
" from LotOccupancies" +
|
|
||||||
" where recordDelete_timeMillis is null" +
|
|
||||||
" and occupancyStartDate <= ?" +
|
|
||||||
" and (occupancyEndDate is null or occupancyEndDate >= ?)" +
|
|
||||||
" group by lotId" +
|
|
||||||
") o on l.lotId = o.lotId") +
|
|
||||||
sqlWhereClause +
|
|
||||||
" order by userFn_lotNameSortName(l.lotName), l.lotId" +
|
|
||||||
(options ? ` limit ${options.limit} offset ${options.offset}` : "")
|
|
||||||
)
|
|
||||||
.all(sqlParameters);
|
|
||||||
|
|
||||||
if (options.limit === -1) {
|
|
||||||
count = lots.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!connectedDatabase) {
|
|
||||||
database.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
count,
|
|
||||||
lots
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getLots;
|
export default getLots
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
export declare function getOccupancyTypeFields(occupancyTypeId?: number, connectedDatabase?: sqlite.Database): recordTypes.OccupancyTypeField[];
|
export declare function getOccupancyTypeFields(occupancyTypeId?: number, connectedDatabase?: sqlite.Database): recordTypes.OccupancyTypeField[];
|
||||||
export default getOccupancyTypeFields;
|
export default getOccupancyTypeFields;
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,28 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js";
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||||
export function getOccupancyTypeFields(occupancyTypeId, connectedDatabase) {
|
export function getOccupancyTypeFields(occupancyTypeId, connectedDatabase) {
|
||||||
const database = connectedDatabase || sqlite(databasePath);
|
const database = connectedDatabase ?? sqlite(databasePath);
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
if (occupancyTypeId) {
|
if (occupancyTypeId) {
|
||||||
sqlParameters.push(occupancyTypeId);
|
sqlParameters.push(occupancyTypeId);
|
||||||
}
|
}
|
||||||
const occupancyTypeFields = database
|
const occupancyTypeFields = database
|
||||||
.prepare("select occupancyTypeFieldId," +
|
.prepare('select occupancyTypeFieldId,' +
|
||||||
" occupancyTypeField, occupancyTypeFieldValues, isRequired, pattern," +
|
' occupancyTypeField, occupancyTypeFieldValues, isRequired, pattern,' +
|
||||||
" minimumLength, maximumLength," +
|
' minimumLength, maximumLength,' +
|
||||||
" orderNumber" +
|
' orderNumber' +
|
||||||
" from OccupancyTypeFields" +
|
' from OccupancyTypeFields' +
|
||||||
" where recordDelete_timeMillis is null" +
|
' where recordDelete_timeMillis is null' +
|
||||||
(occupancyTypeId ? " and occupancyTypeId = ?" : " and occupancyTypeId is null") +
|
(occupancyTypeId
|
||||||
" order by orderNumber, occupancyTypeField")
|
? ' and occupancyTypeId = ?'
|
||||||
|
: ' and occupancyTypeId is null') +
|
||||||
|
' order by orderNumber, occupancyTypeField')
|
||||||
.all(sqlParameters);
|
.all(sqlParameters);
|
||||||
let expectedOrderNumber = 0;
|
let expectedOrderNumber = 0;
|
||||||
for (const occupancyTypeField of occupancyTypeFields) {
|
for (const occupancyTypeField of occupancyTypeFields) {
|
||||||
if (occupancyTypeField.orderNumber !== expectedOrderNumber) {
|
if (occupancyTypeField.orderNumber !== expectedOrderNumber) {
|
||||||
updateRecordOrderNumber("OccupancyTypeFields", occupancyTypeField.occupancyTypeFieldId, expectedOrderNumber, database);
|
updateRecordOrderNumber('OccupancyTypeFields', occupancyTypeField.occupancyTypeFieldId, expectedOrderNumber, database);
|
||||||
occupancyTypeField.orderNumber = expectedOrderNumber;
|
occupancyTypeField.orderNumber = expectedOrderNumber;
|
||||||
}
|
}
|
||||||
expectedOrderNumber += 1;
|
expectedOrderNumber += 1;
|
||||||
|
|
|
||||||
|
|
@ -1,57 +1,59 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js";
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
||||||
|
|
||||||
export function getOccupancyTypeFields(
|
export function getOccupancyTypeFields(
|
||||||
occupancyTypeId?: number,
|
occupancyTypeId?: number,
|
||||||
connectedDatabase?: sqlite.Database
|
connectedDatabase?: sqlite.Database
|
||||||
): recordTypes.OccupancyTypeField[] {
|
): recordTypes.OccupancyTypeField[] {
|
||||||
const database = connectedDatabase || sqlite(databasePath);
|
const database = connectedDatabase ?? sqlite(databasePath)
|
||||||
|
|
||||||
const sqlParameters: unknown[] = [];
|
const sqlParameters: unknown[] = []
|
||||||
|
|
||||||
if (occupancyTypeId) {
|
if (occupancyTypeId) {
|
||||||
sqlParameters.push(occupancyTypeId);
|
sqlParameters.push(occupancyTypeId)
|
||||||
|
}
|
||||||
|
|
||||||
|
const occupancyTypeFields: recordTypes.OccupancyTypeField[] = database
|
||||||
|
.prepare(
|
||||||
|
'select occupancyTypeFieldId,' +
|
||||||
|
' occupancyTypeField, occupancyTypeFieldValues, isRequired, pattern,' +
|
||||||
|
' minimumLength, maximumLength,' +
|
||||||
|
' orderNumber' +
|
||||||
|
' from OccupancyTypeFields' +
|
||||||
|
' where recordDelete_timeMillis is null' +
|
||||||
|
(occupancyTypeId
|
||||||
|
? ' and occupancyTypeId = ?'
|
||||||
|
: ' and occupancyTypeId is null') +
|
||||||
|
' order by orderNumber, occupancyTypeField'
|
||||||
|
)
|
||||||
|
.all(sqlParameters)
|
||||||
|
|
||||||
|
let expectedOrderNumber = 0
|
||||||
|
|
||||||
|
for (const occupancyTypeField of occupancyTypeFields) {
|
||||||
|
if (occupancyTypeField.orderNumber !== expectedOrderNumber) {
|
||||||
|
updateRecordOrderNumber(
|
||||||
|
'OccupancyTypeFields',
|
||||||
|
occupancyTypeField.occupancyTypeFieldId!,
|
||||||
|
expectedOrderNumber,
|
||||||
|
database
|
||||||
|
)
|
||||||
|
|
||||||
|
occupancyTypeField.orderNumber = expectedOrderNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
const occupancyTypeFields: recordTypes.OccupancyTypeField[] = database
|
expectedOrderNumber += 1
|
||||||
.prepare(
|
}
|
||||||
"select occupancyTypeFieldId," +
|
|
||||||
" occupancyTypeField, occupancyTypeFieldValues, isRequired, pattern," +
|
|
||||||
" minimumLength, maximumLength," +
|
|
||||||
" orderNumber" +
|
|
||||||
" from OccupancyTypeFields" +
|
|
||||||
" where recordDelete_timeMillis is null" +
|
|
||||||
(occupancyTypeId ? " and occupancyTypeId = ?" : " and occupancyTypeId is null") +
|
|
||||||
" order by orderNumber, occupancyTypeField"
|
|
||||||
)
|
|
||||||
.all(sqlParameters);
|
|
||||||
|
|
||||||
let expectedOrderNumber = 0;
|
if (!connectedDatabase) {
|
||||||
|
database.close()
|
||||||
|
}
|
||||||
|
|
||||||
for (const occupancyTypeField of occupancyTypeFields) {
|
return occupancyTypeFields
|
||||||
if (occupancyTypeField.orderNumber !== expectedOrderNumber) {
|
|
||||||
updateRecordOrderNumber(
|
|
||||||
"OccupancyTypeFields",
|
|
||||||
occupancyTypeField.occupancyTypeFieldId,
|
|
||||||
expectedOrderNumber,
|
|
||||||
database
|
|
||||||
);
|
|
||||||
|
|
||||||
occupancyTypeField.orderNumber = expectedOrderNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedOrderNumber += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!connectedDatabase) {
|
|
||||||
database.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return occupancyTypeFields;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getOccupancyTypeFields;
|
export default getOccupancyTypeFields
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
export declare function getOccupancyTypePrints(occupancyTypeId: number, connectedDatabase?: sqlite.Database): string[];
|
export declare function getOccupancyTypePrints(occupancyTypeId: number, connectedDatabase?: sqlite.Database): string[];
|
||||||
export default getOccupancyTypePrints;
|
export default getOccupancyTypePrints;
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,23 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import * as configFunctions from "../functions.config.js";
|
import * as configFunctions from '../functions.config.js';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
const availablePrints = configFunctions.getProperty("settings.lotOccupancy.prints");
|
const availablePrints = configFunctions.getProperty('settings.lotOccupancy.prints');
|
||||||
const userFunction_configContainsPrintEJS = (printEJS) => {
|
const userFunction_configContainsPrintEJS = (printEJS) => {
|
||||||
if (printEJS === "*" || availablePrints.includes(printEJS)) {
|
if (printEJS === '*' || availablePrints.includes(printEJS)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
export function getOccupancyTypePrints(occupancyTypeId, connectedDatabase) {
|
export function getOccupancyTypePrints(occupancyTypeId, connectedDatabase) {
|
||||||
const database = connectedDatabase || sqlite(databasePath);
|
const database = connectedDatabase ?? sqlite(databasePath);
|
||||||
database.function("userFn_configContainsPrintEJS", userFunction_configContainsPrintEJS);
|
database.function('userFn_configContainsPrintEJS', userFunction_configContainsPrintEJS);
|
||||||
const results = database
|
const results = database
|
||||||
.prepare(`select printEJS, orderNumber
|
.prepare(`select printEJS, orderNumber
|
||||||
from OccupancyTypePrints
|
from OccupancyTypePrints
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and occupancyTypeId = ?
|
and occupancyTypeId = ?
|
||||||
and userFn_configContainsPrintEJS(printEJS) = 1
|
and userFn_configContainsPrintEJS(printEJS) = 1
|
||||||
order by orderNumber, printEJS`)
|
order by orderNumber, printEJS`)
|
||||||
.all(occupancyTypeId);
|
.all(occupancyTypeId);
|
||||||
let expectedOrderNumber = -1;
|
let expectedOrderNumber = -1;
|
||||||
const prints = [];
|
const prints = [];
|
||||||
|
|
@ -26,9 +26,9 @@ export function getOccupancyTypePrints(occupancyTypeId, connectedDatabase) {
|
||||||
if (result.orderNumber !== expectedOrderNumber) {
|
if (result.orderNumber !== expectedOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare(`update OccupancyTypePrints
|
.prepare(`update OccupancyTypePrints
|
||||||
set orderNumber = ?
|
set orderNumber = ?
|
||||||
where occupancyTypeId = ?
|
where occupancyTypeId = ?
|
||||||
and printEJS = ?`)
|
and printEJS = ?`)
|
||||||
.run(expectedOrderNumber, occupancyTypeId, result.printEJS);
|
.run(expectedOrderNumber, occupancyTypeId, result.printEJS);
|
||||||
}
|
}
|
||||||
prints.push(result.printEJS);
|
prints.push(result.printEJS);
|
||||||
|
|
|
||||||
|
|
@ -1,63 +1,69 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import * as configFunctions from "../functions.config.js";
|
import * as configFunctions from '../functions.config.js'
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
const availablePrints = configFunctions.getProperty("settings.lotOccupancy.prints");
|
const availablePrints = configFunctions.getProperty(
|
||||||
|
'settings.lotOccupancy.prints'
|
||||||
|
)
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
const userFunction_configContainsPrintEJS = (printEJS: string): number => {
|
const userFunction_configContainsPrintEJS = (printEJS: string): number => {
|
||||||
if (printEJS === "*" || availablePrints.includes(printEJS)) {
|
if (printEJS === '*' || availablePrints.includes(printEJS)) {
|
||||||
return 1;
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0
|
||||||
};
|
|
||||||
|
|
||||||
export function getOccupancyTypePrints(
|
|
||||||
occupancyTypeId: number,
|
|
||||||
connectedDatabase?: sqlite.Database
|
|
||||||
): string[] {
|
|
||||||
const database = connectedDatabase || sqlite(databasePath);
|
|
||||||
|
|
||||||
database.function("userFn_configContainsPrintEJS", userFunction_configContainsPrintEJS);
|
|
||||||
|
|
||||||
const results: { printEJS: string; orderNumber: number }[] = database
|
|
||||||
.prepare(
|
|
||||||
`select printEJS, orderNumber
|
|
||||||
from OccupancyTypePrints
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and occupancyTypeId = ?
|
|
||||||
and userFn_configContainsPrintEJS(printEJS) = 1
|
|
||||||
order by orderNumber, printEJS`
|
|
||||||
)
|
|
||||||
.all(occupancyTypeId);
|
|
||||||
|
|
||||||
let expectedOrderNumber = -1;
|
|
||||||
|
|
||||||
const prints = [];
|
|
||||||
|
|
||||||
for (const result of results) {
|
|
||||||
expectedOrderNumber += 1;
|
|
||||||
|
|
||||||
if (result.orderNumber !== expectedOrderNumber) {
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update OccupancyTypePrints
|
|
||||||
set orderNumber = ?
|
|
||||||
where occupancyTypeId = ?
|
|
||||||
and printEJS = ?`
|
|
||||||
)
|
|
||||||
.run(expectedOrderNumber, occupancyTypeId, result.printEJS);
|
|
||||||
}
|
|
||||||
|
|
||||||
prints.push(result.printEJS);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!connectedDatabase) {
|
|
||||||
database.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return prints;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getOccupancyTypePrints;
|
export function getOccupancyTypePrints(
|
||||||
|
occupancyTypeId: number,
|
||||||
|
connectedDatabase?: sqlite.Database
|
||||||
|
): string[] {
|
||||||
|
const database = connectedDatabase ?? sqlite(databasePath)
|
||||||
|
|
||||||
|
database.function(
|
||||||
|
'userFn_configContainsPrintEJS',
|
||||||
|
userFunction_configContainsPrintEJS
|
||||||
|
)
|
||||||
|
|
||||||
|
const results: Array<{ printEJS: string; orderNumber: number }> = database
|
||||||
|
.prepare(
|
||||||
|
`select printEJS, orderNumber
|
||||||
|
from OccupancyTypePrints
|
||||||
|
where recordDelete_timeMillis is null
|
||||||
|
and occupancyTypeId = ?
|
||||||
|
and userFn_configContainsPrintEJS(printEJS) = 1
|
||||||
|
order by orderNumber, printEJS`
|
||||||
|
)
|
||||||
|
.all(occupancyTypeId)
|
||||||
|
|
||||||
|
let expectedOrderNumber = -1
|
||||||
|
|
||||||
|
const prints: string[] = []
|
||||||
|
|
||||||
|
for (const result of results) {
|
||||||
|
expectedOrderNumber += 1
|
||||||
|
|
||||||
|
if (result.orderNumber !== expectedOrderNumber) {
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
`update OccupancyTypePrints
|
||||||
|
set orderNumber = ?
|
||||||
|
where occupancyTypeId = ?
|
||||||
|
and printEJS = ?`
|
||||||
|
)
|
||||||
|
.run(expectedOrderNumber, occupancyTypeId, result.printEJS)
|
||||||
|
}
|
||||||
|
|
||||||
|
prints.push(result.printEJS)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!connectedDatabase) {
|
||||||
|
database.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
return prints
|
||||||
|
}
|
||||||
|
|
||||||
|
export default getOccupancyTypePrints
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
export interface ReportParameters {
|
export declare type ReportParameters = Record<string, string | number>;
|
||||||
[parameterName: string]: string | number;
|
|
||||||
}
|
|
||||||
export declare function getReportData(reportName: string, reportParameters?: ReportParameters): unknown[] | undefined;
|
export declare function getReportData(reportName: string, reportParameters?: ReportParameters): unknown[] | undefined;
|
||||||
export default getReportData;
|
export default getReportData;
|
||||||
|
|
|
||||||
|
|
@ -1,231 +1,231 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import * as configFunctions from "../functions.config.js";
|
import * as configFunctions from '../functions.config.js';
|
||||||
import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import * as dateTimeFunctions from '@cityssm/expressjs-server-js/dateTimeFns.js';
|
||||||
import camelCase from "camelcase";
|
import camelCase from 'camelcase';
|
||||||
const mapCamelCase = camelCase(configFunctions.getProperty("aliases.map"));
|
const mapCamelCase = camelCase(configFunctions.getProperty('aliases.map'));
|
||||||
const mapNameAlias = mapCamelCase + "Name";
|
const mapNameAlias = mapCamelCase + 'Name';
|
||||||
const mapDescriptionAlias = mapCamelCase + "Description";
|
const mapDescriptionAlias = mapCamelCase + 'Description';
|
||||||
const mapAddress1Alias = mapCamelCase + "Address1";
|
const mapAddress1Alias = mapCamelCase + 'Address1';
|
||||||
const mapAddress2Alias = mapCamelCase + "Address2";
|
const mapAddress2Alias = mapCamelCase + 'Address2';
|
||||||
const mapCityAlias = mapCamelCase + "City";
|
const mapCityAlias = mapCamelCase + 'City';
|
||||||
const mapProvinceAlias = mapCamelCase + "Province";
|
const mapProvinceAlias = mapCamelCase + 'Province';
|
||||||
const mapPostalCodeAlias = mapCamelCase + "PostalCode";
|
const mapPostalCodeAlias = mapCamelCase + 'PostalCode';
|
||||||
const mapPhoneNumberAlias = mapCamelCase + "PhoneNumber";
|
const mapPhoneNumberAlias = mapCamelCase + 'PhoneNumber';
|
||||||
const lotCamelCase = camelCase(configFunctions.getProperty("aliases.lot"));
|
const lotCamelCase = camelCase(configFunctions.getProperty('aliases.lot'));
|
||||||
const lotIdAlias = lotCamelCase + "Id";
|
const lotIdAlias = lotCamelCase + 'Id';
|
||||||
const lotNameAlias = lotCamelCase + "Name";
|
const lotNameAlias = lotCamelCase + 'Name';
|
||||||
const lotTypeAlias = lotCamelCase + "Type";
|
const lotTypeAlias = lotCamelCase + 'Type';
|
||||||
const lotStatusAlias = lotCamelCase + "Status";
|
const lotStatusAlias = lotCamelCase + 'Status';
|
||||||
const occupancyCamelCase = camelCase(configFunctions.getProperty("aliases.occupancy"));
|
const occupancyCamelCase = camelCase(configFunctions.getProperty('aliases.occupancy'));
|
||||||
const lotOccupancyIdAlias = occupancyCamelCase + "Id";
|
const lotOccupancyIdAlias = occupancyCamelCase + 'Id';
|
||||||
const occupancyTypeAlias = occupancyCamelCase + "Type";
|
const occupancyTypeAlias = occupancyCamelCase + 'Type';
|
||||||
const occupancyStartDateAlias = occupancyCamelCase + "StartDate";
|
const occupancyStartDateAlias = occupancyCamelCase + 'StartDate';
|
||||||
const occupancyEndDateAlias = occupancyCamelCase + "EndDate";
|
const occupancyEndDateAlias = occupancyCamelCase + 'EndDate';
|
||||||
export function getReportData(reportName, reportParameters) {
|
export function getReportData(reportName, reportParameters = {}) {
|
||||||
let sql;
|
let sql;
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
switch (reportName) {
|
switch (reportName) {
|
||||||
case "maps-all": {
|
case 'maps-all': {
|
||||||
sql = "select * from Maps";
|
sql = 'select * from Maps';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "maps-formatted": {
|
case 'maps-formatted': {
|
||||||
sql = `select mapName as ${mapNameAlias},
|
sql = `select mapName as ${mapNameAlias},
|
||||||
mapDescription as ${mapDescriptionAlias},
|
mapDescription as ${mapDescriptionAlias},
|
||||||
mapAddress1 as ${mapAddress1Alias},
|
mapAddress1 as ${mapAddress1Alias},
|
||||||
mapAddress2 as ${mapAddress2Alias},
|
mapAddress2 as ${mapAddress2Alias},
|
||||||
mapCity as ${mapCityAlias},
|
mapCity as ${mapCityAlias},
|
||||||
mapProvince as ${mapProvinceAlias},
|
mapProvince as ${mapProvinceAlias},
|
||||||
mapPostalCode as ${mapPostalCodeAlias},
|
mapPostalCode as ${mapPostalCodeAlias},
|
||||||
mapPhoneNumber as ${mapPhoneNumberAlias}
|
mapPhoneNumber as ${mapPhoneNumberAlias}
|
||||||
from Maps
|
from Maps
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
order by mapName`;
|
order by mapName`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lots-all": {
|
case 'lots-all': {
|
||||||
sql = "select * from Lots";
|
sql = 'select * from Lots';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lots-byLotTypeId": {
|
case 'lots-byLotTypeId': {
|
||||||
sql = `select l.lotId as ${lotIdAlias},
|
sql = `select l.lotId as ${lotIdAlias},
|
||||||
m.mapName as ${mapNameAlias},
|
m.mapName as ${mapNameAlias},
|
||||||
l.lotName as ${lotNameAlias},
|
l.lotName as ${lotNameAlias},
|
||||||
t.lotType as ${lotTypeAlias},
|
t.lotType as ${lotTypeAlias},
|
||||||
s.lotStatus as ${lotStatusAlias}
|
s.lotStatus as ${lotStatusAlias}
|
||||||
from Lots l
|
from Lots l
|
||||||
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
||||||
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
||||||
left join Maps m on l.mapId = m.mapId
|
left join Maps m on l.mapId = m.mapId
|
||||||
where l.recordDelete_timeMillis is null
|
where l.recordDelete_timeMillis is null
|
||||||
and l.lotTypeId = ?`;
|
and l.lotTypeId = ?`;
|
||||||
sqlParameters.push(reportParameters.lotTypeId);
|
sqlParameters.push(reportParameters.lotTypeId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lots-byLotStatusId": {
|
case 'lots-byLotStatusId': {
|
||||||
sql = `select l.lotId as ${lotIdAlias},
|
sql = `select l.lotId as ${lotIdAlias},
|
||||||
m.mapName as ${mapNameAlias},
|
m.mapName as ${mapNameAlias},
|
||||||
l.lotName as ${lotNameAlias},
|
l.lotName as ${lotNameAlias},
|
||||||
t.lotType as ${lotTypeAlias},
|
t.lotType as ${lotTypeAlias},
|
||||||
s.lotStatus as ${lotStatusAlias}
|
s.lotStatus as ${lotStatusAlias}
|
||||||
from Lots l
|
from Lots l
|
||||||
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
||||||
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
||||||
left join Maps m on l.mapId = m.mapId
|
left join Maps m on l.mapId = m.mapId
|
||||||
where l.recordDelete_timeMillis is null
|
where l.recordDelete_timeMillis is null
|
||||||
and l.lotStatusId = ?`;
|
and l.lotStatusId = ?`;
|
||||||
sqlParameters.push(reportParameters.lotStatusId);
|
sqlParameters.push(reportParameters.lotStatusId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lots-byMapId": {
|
case 'lots-byMapId': {
|
||||||
sql = `select l.lotId as ${lotIdAlias},
|
sql = `select l.lotId as ${lotIdAlias},
|
||||||
m.mapName as ${mapNameAlias},
|
m.mapName as ${mapNameAlias},
|
||||||
l.lotName as ${lotNameAlias},
|
l.lotName as ${lotNameAlias},
|
||||||
t.lotType as ${lotTypeAlias},
|
t.lotType as ${lotTypeAlias},
|
||||||
s.lotStatus as ${lotStatusAlias}
|
s.lotStatus as ${lotStatusAlias}
|
||||||
from Lots l
|
from Lots l
|
||||||
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
||||||
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
||||||
left join Maps m on l.mapId = m.mapId
|
left join Maps m on l.mapId = m.mapId
|
||||||
where l.recordDelete_timeMillis is null
|
where l.recordDelete_timeMillis is null
|
||||||
and l.mapId = ?`;
|
and l.mapId = ?`;
|
||||||
sqlParameters.push(reportParameters.mapId);
|
sqlParameters.push(reportParameters.mapId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotComments-all": {
|
case 'lotComments-all': {
|
||||||
sql = "select * from LotComments";
|
sql = 'select * from LotComments';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotFields-all": {
|
case 'lotFields-all': {
|
||||||
sql = "select * from LotFields";
|
sql = 'select * from LotFields';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotOccupancies-all": {
|
case 'lotOccupancies-all': {
|
||||||
sql = "select * from LotOccupancies";
|
sql = 'select * from LotOccupancies';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotOccupancies-current-byMapId": {
|
case 'lotOccupancies-current-byMapId': {
|
||||||
sql = `select o.lotOccupancyId as ${lotOccupancyIdAlias},
|
sql = `select o.lotOccupancyId as ${lotOccupancyIdAlias},
|
||||||
l.lotName as ${lotNameAlias},
|
l.lotName as ${lotNameAlias},
|
||||||
m.mapName as ${mapNameAlias},
|
m.mapName as ${mapNameAlias},
|
||||||
ot.occupancyType as ${occupancyTypeAlias},
|
ot.occupancyType as ${occupancyTypeAlias},
|
||||||
o.occupancyStartDate as ${occupancyStartDateAlias},
|
o.occupancyStartDate as ${occupancyStartDateAlias},
|
||||||
o.occupancyEndDate as ${occupancyEndDateAlias}
|
o.occupancyEndDate as ${occupancyEndDateAlias}
|
||||||
from LotOccupancies o
|
from LotOccupancies o
|
||||||
left join OccupancyTypes ot on o.occupancyTypeId = ot.occupancyTypeId
|
left join OccupancyTypes ot on o.occupancyTypeId = ot.occupancyTypeId
|
||||||
left join Lots l on o.lotId = l.lotId
|
left join Lots l on o.lotId = l.lotId
|
||||||
left join Maps m on l.mapId = m.mapId
|
left join Maps m on l.mapId = m.mapId
|
||||||
where o.recordDelete_timeMillis is null
|
where o.recordDelete_timeMillis is null
|
||||||
and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)
|
and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)
|
||||||
and l.mapId = ?`;
|
and l.mapId = ?`;
|
||||||
sqlParameters.push(dateTimeFunctions.dateToInteger(new Date()), reportParameters.mapId);
|
sqlParameters.push(dateTimeFunctions.dateToInteger(new Date()), reportParameters.mapId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotOccupancyComments-all": {
|
case 'lotOccupancyComments-all': {
|
||||||
sql = "select * from LotOccupancyComments";
|
sql = 'select * from LotOccupancyComments';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotOccupancyFees-all": {
|
case 'lotOccupancyFees-all': {
|
||||||
sql = "select * from LotOccupancyFees";
|
sql = 'select * from LotOccupancyFees';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotOccupancyFields-all": {
|
case 'lotOccupancyFields-all': {
|
||||||
sql = "select * from LotOccupancyFields";
|
sql = 'select * from LotOccupancyFields';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotOccupancyOccupants-all": {
|
case 'lotOccupancyOccupants-all': {
|
||||||
sql = "select * from LotOccupancyOccupants";
|
sql = 'select * from LotOccupancyOccupants';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotOccupancyTransactions-all": {
|
case 'lotOccupancyTransactions-all': {
|
||||||
sql = "select * from LotOccupancyTransactions";
|
sql = 'select * from LotOccupancyTransactions';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotOccupancyTransactions-byTransactionDateString": {
|
case 'lotOccupancyTransactions-byTransactionDateString': {
|
||||||
sql = `select t.lotOccupancyId, t.transactionIndex,
|
sql = `select t.lotOccupancyId, t.transactionIndex,
|
||||||
t.transactionDate, t.transactionTime,
|
t.transactionDate, t.transactionTime,
|
||||||
t.transactionAmount,
|
t.transactionAmount,
|
||||||
t.externalReceiptNumber, t.transactionNote
|
t.externalReceiptNumber, t.transactionNote
|
||||||
from LotOccupancyTransactions t
|
from LotOccupancyTransactions t
|
||||||
where t.recordDelete_timeMillis is null
|
where t.recordDelete_timeMillis is null
|
||||||
and t.transactionDate = ?`;
|
and t.transactionDate = ?`;
|
||||||
sqlParameters.push(dateTimeFunctions.dateStringToInteger(reportParameters.transactionDateString));
|
sqlParameters.push(dateTimeFunctions.dateStringToInteger(reportParameters.transactionDateString));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "workOrders-all": {
|
case 'workOrders-all': {
|
||||||
sql = "select * from WorkOrders";
|
sql = 'select * from WorkOrders';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "workOrders-open": {
|
case 'workOrders-open': {
|
||||||
sql = `select w.workOrderId, w.workOrderNumber,
|
sql = `select w.workOrderId, w.workOrderNumber,
|
||||||
t.workOrderType, w.workOrderDescription,
|
t.workOrderType, w.workOrderDescription,
|
||||||
w.workOrderOpenDate,
|
w.workOrderOpenDate,
|
||||||
m.workOrderMilestoneCount, m.workOrderMilestoneCompletionCount
|
m.workOrderMilestoneCount, m.workOrderMilestoneCompletionCount
|
||||||
from WorkOrders w
|
from WorkOrders w
|
||||||
left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId
|
left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId
|
||||||
left join (
|
left join (
|
||||||
select m.workOrderId,
|
select m.workOrderId,
|
||||||
count(m.workOrderMilestoneId) as workOrderMilestoneCount,
|
count(m.workOrderMilestoneId) as workOrderMilestoneCount,
|
||||||
sum(case when m.workOrderMilestoneCompletionDate is null then 0 else 1 end) as workOrderMilestoneCompletionCount
|
sum(case when m.workOrderMilestoneCompletionDate is null then 0 else 1 end) as workOrderMilestoneCompletionCount
|
||||||
from WorkOrderMilestones m
|
from WorkOrderMilestones m
|
||||||
where m.recordDelete_timeMillis is null
|
where m.recordDelete_timeMillis is null
|
||||||
group by m.workOrderId
|
group by m.workOrderId
|
||||||
) m on w.workOrderId = m.workOrderId
|
) m on w.workOrderId = m.workOrderId
|
||||||
where w.recordDelete_timeMillis is null
|
where w.recordDelete_timeMillis is null
|
||||||
and w.workOrderCloseDate is null`;
|
and w.workOrderCloseDate is null`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "workOrderComments-all": {
|
case 'workOrderComments-all': {
|
||||||
sql = "select * from WorkOrderComments";
|
sql = 'select * from WorkOrderComments';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "workOrderLots-all": {
|
case 'workOrderLots-all': {
|
||||||
sql = "select * from WorkOrderLots";
|
sql = 'select * from WorkOrderLots';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "workOrderMilestones-all": {
|
case 'workOrderMilestones-all': {
|
||||||
sql = "select * from WorkOrderMilestones";
|
sql = 'select * from WorkOrderMilestones';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "fees-all": {
|
case 'fees-all': {
|
||||||
sql = "select * from Fees";
|
sql = 'select * from Fees';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "feeCategories-all": {
|
case 'feeCategories-all': {
|
||||||
sql = "select * from FeeCategories";
|
sql = 'select * from FeeCategories';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotTypes-all": {
|
case 'lotTypes-all': {
|
||||||
sql = "select * from LotTypes";
|
sql = 'select * from LotTypes';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotTypeFields-all": {
|
case 'lotTypeFields-all': {
|
||||||
sql = "select * from LotTypeFields";
|
sql = 'select * from LotTypeFields';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotStatuses-all": {
|
case 'lotStatuses-all': {
|
||||||
sql = "select * from LotStatuses";
|
sql = 'select * from LotStatuses';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "occupancyTypes-all": {
|
case 'occupancyTypes-all': {
|
||||||
sql = "select * from OccupancyTypes";
|
sql = 'select * from OccupancyTypes';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "occupancyTypeFields-all": {
|
case 'occupancyTypeFields-all': {
|
||||||
sql = "select * from OccupancyTypeFields";
|
sql = 'select * from OccupancyTypeFields';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "lotOccupantTypes-all": {
|
case 'lotOccupantTypes-all': {
|
||||||
sql = "select * from LotOccupantTypes";
|
sql = 'select * from LotOccupantTypes';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "workOrderTypes-all": {
|
case 'workOrderTypes-all': {
|
||||||
sql = "select * from WorkOrderTypes";
|
sql = 'select * from WorkOrderTypes';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "workOrderMilestoneTypes-all": {
|
case 'workOrderMilestoneTypes-all': {
|
||||||
sql = "select * from WorkOrderMilestoneTypes";
|
sql = 'select * from WorkOrderMilestoneTypes';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
@ -235,8 +235,8 @@ export function getReportData(reportName, reportParameters) {
|
||||||
const database = sqlite(databasePath, {
|
const database = sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
});
|
});
|
||||||
database.function("userFn_dateIntegerToString", dateTimeFunctions.dateIntegerToString);
|
database.function('userFn_dateIntegerToString', dateTimeFunctions.dateIntegerToString);
|
||||||
database.function("userFn_timeIntegerToString", dateTimeFunctions.timeIntegerToString);
|
database.function('userFn_timeIntegerToString', dateTimeFunctions.timeIntegerToString);
|
||||||
const rows = database.prepare(sql).all(sqlParameters);
|
const rows = database.prepare(sql).all(sqlParameters);
|
||||||
database.close();
|
database.close();
|
||||||
return rows;
|
return rows;
|
||||||
|
|
|
||||||
|
|
@ -1,310 +1,321 @@
|
||||||
/* eslint-disable no-case-declarations */
|
/* eslint-disable no-case-declarations */
|
||||||
|
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import * as configFunctions from "../functions.config.js";
|
import * as configFunctions from '../functions.config.js'
|
||||||
import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import * as dateTimeFunctions from '@cityssm/expressjs-server-js/dateTimeFns.js'
|
||||||
|
|
||||||
import camelCase from "camelcase";
|
import camelCase from 'camelcase'
|
||||||
|
|
||||||
export interface ReportParameters {
|
export type ReportParameters = Record<string, string | number>
|
||||||
[parameterName: string]: string | number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mapCamelCase = camelCase(configFunctions.getProperty("aliases.map"));
|
const mapCamelCase = camelCase(configFunctions.getProperty('aliases.map'))
|
||||||
const mapNameAlias = mapCamelCase + "Name";
|
const mapNameAlias = mapCamelCase + 'Name'
|
||||||
const mapDescriptionAlias = mapCamelCase + "Description";
|
const mapDescriptionAlias = mapCamelCase + 'Description'
|
||||||
const mapAddress1Alias = mapCamelCase + "Address1";
|
const mapAddress1Alias = mapCamelCase + 'Address1'
|
||||||
const mapAddress2Alias = mapCamelCase + "Address2";
|
const mapAddress2Alias = mapCamelCase + 'Address2'
|
||||||
const mapCityAlias = mapCamelCase + "City";
|
const mapCityAlias = mapCamelCase + 'City'
|
||||||
const mapProvinceAlias = mapCamelCase + "Province";
|
const mapProvinceAlias = mapCamelCase + 'Province'
|
||||||
const mapPostalCodeAlias = mapCamelCase + "PostalCode";
|
const mapPostalCodeAlias = mapCamelCase + 'PostalCode'
|
||||||
const mapPhoneNumberAlias = mapCamelCase + "PhoneNumber";
|
const mapPhoneNumberAlias = mapCamelCase + 'PhoneNumber'
|
||||||
|
|
||||||
const lotCamelCase = camelCase(configFunctions.getProperty("aliases.lot"));
|
const lotCamelCase = camelCase(configFunctions.getProperty('aliases.lot'))
|
||||||
const lotIdAlias = lotCamelCase + "Id";
|
const lotIdAlias = lotCamelCase + 'Id'
|
||||||
const lotNameAlias = lotCamelCase + "Name";
|
const lotNameAlias = lotCamelCase + 'Name'
|
||||||
const lotTypeAlias = lotCamelCase + "Type";
|
const lotTypeAlias = lotCamelCase + 'Type'
|
||||||
const lotStatusAlias = lotCamelCase + "Status";
|
const lotStatusAlias = lotCamelCase + 'Status'
|
||||||
|
|
||||||
const occupancyCamelCase = camelCase(configFunctions.getProperty("aliases.occupancy"));
|
const occupancyCamelCase = camelCase(
|
||||||
const lotOccupancyIdAlias = occupancyCamelCase + "Id";
|
configFunctions.getProperty('aliases.occupancy')
|
||||||
const occupancyTypeAlias = occupancyCamelCase + "Type";
|
)
|
||||||
const occupancyStartDateAlias = occupancyCamelCase + "StartDate";
|
const lotOccupancyIdAlias = occupancyCamelCase + 'Id'
|
||||||
const occupancyEndDateAlias = occupancyCamelCase + "EndDate";
|
const occupancyTypeAlias = occupancyCamelCase + 'Type'
|
||||||
|
const occupancyStartDateAlias = occupancyCamelCase + 'StartDate'
|
||||||
|
const occupancyEndDateAlias = occupancyCamelCase + 'EndDate'
|
||||||
|
|
||||||
export function getReportData(
|
export function getReportData(
|
||||||
reportName: string,
|
reportName: string,
|
||||||
reportParameters?: ReportParameters
|
reportParameters: ReportParameters = {}
|
||||||
): unknown[] | undefined {
|
): unknown[] | undefined {
|
||||||
let sql: string;
|
let sql: string
|
||||||
const sqlParameters: unknown[] = [];
|
const sqlParameters: unknown[] = []
|
||||||
|
|
||||||
switch (reportName) {
|
switch (reportName) {
|
||||||
case "maps-all": {
|
case 'maps-all': {
|
||||||
sql = "select * from Maps";
|
sql = 'select * from Maps'
|
||||||
break;
|
break
|
||||||
}
|
|
||||||
|
|
||||||
case "maps-formatted": {
|
|
||||||
sql = `select mapName as ${mapNameAlias},
|
|
||||||
mapDescription as ${mapDescriptionAlias},
|
|
||||||
mapAddress1 as ${mapAddress1Alias},
|
|
||||||
mapAddress2 as ${mapAddress2Alias},
|
|
||||||
mapCity as ${mapCityAlias},
|
|
||||||
mapProvince as ${mapProvinceAlias},
|
|
||||||
mapPostalCode as ${mapPostalCodeAlias},
|
|
||||||
mapPhoneNumber as ${mapPhoneNumberAlias}
|
|
||||||
from Maps
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
order by mapName`;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lots-all": {
|
|
||||||
sql = "select * from Lots";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lots-byLotTypeId": {
|
|
||||||
sql = `select l.lotId as ${lotIdAlias},
|
|
||||||
m.mapName as ${mapNameAlias},
|
|
||||||
l.lotName as ${lotNameAlias},
|
|
||||||
t.lotType as ${lotTypeAlias},
|
|
||||||
s.lotStatus as ${lotStatusAlias}
|
|
||||||
from Lots l
|
|
||||||
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
|
||||||
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
|
||||||
left join Maps m on l.mapId = m.mapId
|
|
||||||
where l.recordDelete_timeMillis is null
|
|
||||||
and l.lotTypeId = ?`;
|
|
||||||
|
|
||||||
sqlParameters.push(reportParameters.lotTypeId);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lots-byLotStatusId": {
|
|
||||||
sql = `select l.lotId as ${lotIdAlias},
|
|
||||||
m.mapName as ${mapNameAlias},
|
|
||||||
l.lotName as ${lotNameAlias},
|
|
||||||
t.lotType as ${lotTypeAlias},
|
|
||||||
s.lotStatus as ${lotStatusAlias}
|
|
||||||
from Lots l
|
|
||||||
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
|
||||||
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
|
||||||
left join Maps m on l.mapId = m.mapId
|
|
||||||
where l.recordDelete_timeMillis is null
|
|
||||||
and l.lotStatusId = ?`;
|
|
||||||
|
|
||||||
sqlParameters.push(reportParameters.lotStatusId);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lots-byMapId": {
|
|
||||||
sql = `select l.lotId as ${lotIdAlias},
|
|
||||||
m.mapName as ${mapNameAlias},
|
|
||||||
l.lotName as ${lotNameAlias},
|
|
||||||
t.lotType as ${lotTypeAlias},
|
|
||||||
s.lotStatus as ${lotStatusAlias}
|
|
||||||
from Lots l
|
|
||||||
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
|
||||||
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
|
||||||
left join Maps m on l.mapId = m.mapId
|
|
||||||
where l.recordDelete_timeMillis is null
|
|
||||||
and l.mapId = ?`;
|
|
||||||
|
|
||||||
sqlParameters.push(reportParameters.mapId);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotComments-all": {
|
|
||||||
sql = "select * from LotComments";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotFields-all": {
|
|
||||||
sql = "select * from LotFields";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotOccupancies-all": {
|
|
||||||
sql = "select * from LotOccupancies";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotOccupancies-current-byMapId": {
|
|
||||||
sql = `select o.lotOccupancyId as ${lotOccupancyIdAlias},
|
|
||||||
l.lotName as ${lotNameAlias},
|
|
||||||
m.mapName as ${mapNameAlias},
|
|
||||||
ot.occupancyType as ${occupancyTypeAlias},
|
|
||||||
o.occupancyStartDate as ${occupancyStartDateAlias},
|
|
||||||
o.occupancyEndDate as ${occupancyEndDateAlias}
|
|
||||||
from LotOccupancies o
|
|
||||||
left join OccupancyTypes ot on o.occupancyTypeId = ot.occupancyTypeId
|
|
||||||
left join Lots l on o.lotId = l.lotId
|
|
||||||
left join Maps m on l.mapId = m.mapId
|
|
||||||
where o.recordDelete_timeMillis is null
|
|
||||||
and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)
|
|
||||||
and l.mapId = ?`;
|
|
||||||
|
|
||||||
sqlParameters.push(dateTimeFunctions.dateToInteger(new Date()), reportParameters.mapId);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotOccupancyComments-all": {
|
|
||||||
sql = "select * from LotOccupancyComments";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotOccupancyFees-all": {
|
|
||||||
sql = "select * from LotOccupancyFees";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotOccupancyFields-all": {
|
|
||||||
sql = "select * from LotOccupancyFields";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotOccupancyOccupants-all": {
|
|
||||||
sql = "select * from LotOccupancyOccupants";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotOccupancyTransactions-all": {
|
|
||||||
sql = "select * from LotOccupancyTransactions";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotOccupancyTransactions-byTransactionDateString": {
|
|
||||||
sql = `select t.lotOccupancyId, t.transactionIndex,
|
|
||||||
t.transactionDate, t.transactionTime,
|
|
||||||
t.transactionAmount,
|
|
||||||
t.externalReceiptNumber, t.transactionNote
|
|
||||||
from LotOccupancyTransactions t
|
|
||||||
where t.recordDelete_timeMillis is null
|
|
||||||
and t.transactionDate = ?`;
|
|
||||||
|
|
||||||
sqlParameters.push(
|
|
||||||
dateTimeFunctions.dateStringToInteger(reportParameters.transactionDateString as string)
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "workOrders-all": {
|
|
||||||
sql = "select * from WorkOrders";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "workOrders-open": {
|
|
||||||
sql = `select w.workOrderId, w.workOrderNumber,
|
|
||||||
t.workOrderType, w.workOrderDescription,
|
|
||||||
w.workOrderOpenDate,
|
|
||||||
m.workOrderMilestoneCount, m.workOrderMilestoneCompletionCount
|
|
||||||
from WorkOrders w
|
|
||||||
left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId
|
|
||||||
left join (
|
|
||||||
select m.workOrderId,
|
|
||||||
count(m.workOrderMilestoneId) as workOrderMilestoneCount,
|
|
||||||
sum(case when m.workOrderMilestoneCompletionDate is null then 0 else 1 end) as workOrderMilestoneCompletionCount
|
|
||||||
from WorkOrderMilestones m
|
|
||||||
where m.recordDelete_timeMillis is null
|
|
||||||
group by m.workOrderId
|
|
||||||
) m on w.workOrderId = m.workOrderId
|
|
||||||
where w.recordDelete_timeMillis is null
|
|
||||||
and w.workOrderCloseDate is null`;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "workOrderComments-all": {
|
|
||||||
sql = "select * from WorkOrderComments";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "workOrderLots-all": {
|
|
||||||
sql = "select * from WorkOrderLots";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "workOrderMilestones-all": {
|
|
||||||
sql = "select * from WorkOrderMilestones";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "fees-all": {
|
|
||||||
sql = "select * from Fees";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "feeCategories-all": {
|
|
||||||
sql = "select * from FeeCategories";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotTypes-all": {
|
|
||||||
sql = "select * from LotTypes";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotTypeFields-all": {
|
|
||||||
sql = "select * from LotTypeFields";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotStatuses-all": {
|
|
||||||
sql = "select * from LotStatuses";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "occupancyTypes-all": {
|
|
||||||
sql = "select * from OccupancyTypes";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "occupancyTypeFields-all": {
|
|
||||||
sql = "select * from OccupancyTypeFields";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "lotOccupantTypes-all": {
|
|
||||||
sql = "select * from LotOccupantTypes";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "workOrderTypes-all": {
|
|
||||||
sql = "select * from WorkOrderTypes";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "workOrderMilestoneTypes-all": {
|
|
||||||
sql = "select * from WorkOrderMilestoneTypes";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const database = sqlite(databasePath, {
|
case 'maps-formatted': {
|
||||||
readonly: true
|
sql = `select mapName as ${mapNameAlias},
|
||||||
});
|
mapDescription as ${mapDescriptionAlias},
|
||||||
|
mapAddress1 as ${mapAddress1Alias},
|
||||||
|
mapAddress2 as ${mapAddress2Alias},
|
||||||
|
mapCity as ${mapCityAlias},
|
||||||
|
mapProvince as ${mapProvinceAlias},
|
||||||
|
mapPostalCode as ${mapPostalCodeAlias},
|
||||||
|
mapPhoneNumber as ${mapPhoneNumberAlias}
|
||||||
|
from Maps
|
||||||
|
where recordDelete_timeMillis is null
|
||||||
|
order by mapName`
|
||||||
|
|
||||||
database.function("userFn_dateIntegerToString", dateTimeFunctions.dateIntegerToString);
|
break
|
||||||
database.function("userFn_timeIntegerToString", dateTimeFunctions.timeIntegerToString);
|
}
|
||||||
|
|
||||||
const rows = database.prepare(sql).all(sqlParameters);
|
case 'lots-all': {
|
||||||
|
sql = 'select * from Lots'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
database.close();
|
case 'lots-byLotTypeId': {
|
||||||
|
sql = `select l.lotId as ${lotIdAlias},
|
||||||
|
m.mapName as ${mapNameAlias},
|
||||||
|
l.lotName as ${lotNameAlias},
|
||||||
|
t.lotType as ${lotTypeAlias},
|
||||||
|
s.lotStatus as ${lotStatusAlias}
|
||||||
|
from Lots l
|
||||||
|
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
||||||
|
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
||||||
|
left join Maps m on l.mapId = m.mapId
|
||||||
|
where l.recordDelete_timeMillis is null
|
||||||
|
and l.lotTypeId = ?`
|
||||||
|
|
||||||
return rows;
|
sqlParameters.push(reportParameters.lotTypeId)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lots-byLotStatusId': {
|
||||||
|
sql = `select l.lotId as ${lotIdAlias},
|
||||||
|
m.mapName as ${mapNameAlias},
|
||||||
|
l.lotName as ${lotNameAlias},
|
||||||
|
t.lotType as ${lotTypeAlias},
|
||||||
|
s.lotStatus as ${lotStatusAlias}
|
||||||
|
from Lots l
|
||||||
|
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
||||||
|
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
||||||
|
left join Maps m on l.mapId = m.mapId
|
||||||
|
where l.recordDelete_timeMillis is null
|
||||||
|
and l.lotStatusId = ?`
|
||||||
|
|
||||||
|
sqlParameters.push(reportParameters.lotStatusId)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lots-byMapId': {
|
||||||
|
sql = `select l.lotId as ${lotIdAlias},
|
||||||
|
m.mapName as ${mapNameAlias},
|
||||||
|
l.lotName as ${lotNameAlias},
|
||||||
|
t.lotType as ${lotTypeAlias},
|
||||||
|
s.lotStatus as ${lotStatusAlias}
|
||||||
|
from Lots l
|
||||||
|
left join LotTypes t on l.lotTypeId = t.lotTypeId
|
||||||
|
left join LotStatuses s on l.lotStatusId = s.lotStatusId
|
||||||
|
left join Maps m on l.mapId = m.mapId
|
||||||
|
where l.recordDelete_timeMillis is null
|
||||||
|
and l.mapId = ?`
|
||||||
|
|
||||||
|
sqlParameters.push(reportParameters.mapId)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotComments-all': {
|
||||||
|
sql = 'select * from LotComments'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotFields-all': {
|
||||||
|
sql = 'select * from LotFields'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotOccupancies-all': {
|
||||||
|
sql = 'select * from LotOccupancies'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotOccupancies-current-byMapId': {
|
||||||
|
sql = `select o.lotOccupancyId as ${lotOccupancyIdAlias},
|
||||||
|
l.lotName as ${lotNameAlias},
|
||||||
|
m.mapName as ${mapNameAlias},
|
||||||
|
ot.occupancyType as ${occupancyTypeAlias},
|
||||||
|
o.occupancyStartDate as ${occupancyStartDateAlias},
|
||||||
|
o.occupancyEndDate as ${occupancyEndDateAlias}
|
||||||
|
from LotOccupancies o
|
||||||
|
left join OccupancyTypes ot on o.occupancyTypeId = ot.occupancyTypeId
|
||||||
|
left join Lots l on o.lotId = l.lotId
|
||||||
|
left join Maps m on l.mapId = m.mapId
|
||||||
|
where o.recordDelete_timeMillis is null
|
||||||
|
and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)
|
||||||
|
and l.mapId = ?`
|
||||||
|
|
||||||
|
sqlParameters.push(
|
||||||
|
dateTimeFunctions.dateToInteger(new Date()),
|
||||||
|
reportParameters.mapId
|
||||||
|
)
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotOccupancyComments-all': {
|
||||||
|
sql = 'select * from LotOccupancyComments'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotOccupancyFees-all': {
|
||||||
|
sql = 'select * from LotOccupancyFees'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotOccupancyFields-all': {
|
||||||
|
sql = 'select * from LotOccupancyFields'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotOccupancyOccupants-all': {
|
||||||
|
sql = 'select * from LotOccupancyOccupants'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotOccupancyTransactions-all': {
|
||||||
|
sql = 'select * from LotOccupancyTransactions'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotOccupancyTransactions-byTransactionDateString': {
|
||||||
|
sql = `select t.lotOccupancyId, t.transactionIndex,
|
||||||
|
t.transactionDate, t.transactionTime,
|
||||||
|
t.transactionAmount,
|
||||||
|
t.externalReceiptNumber, t.transactionNote
|
||||||
|
from LotOccupancyTransactions t
|
||||||
|
where t.recordDelete_timeMillis is null
|
||||||
|
and t.transactionDate = ?`
|
||||||
|
|
||||||
|
sqlParameters.push(
|
||||||
|
dateTimeFunctions.dateStringToInteger(
|
||||||
|
reportParameters.transactionDateString as string
|
||||||
|
)
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'workOrders-all': {
|
||||||
|
sql = 'select * from WorkOrders'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'workOrders-open': {
|
||||||
|
sql = `select w.workOrderId, w.workOrderNumber,
|
||||||
|
t.workOrderType, w.workOrderDescription,
|
||||||
|
w.workOrderOpenDate,
|
||||||
|
m.workOrderMilestoneCount, m.workOrderMilestoneCompletionCount
|
||||||
|
from WorkOrders w
|
||||||
|
left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId
|
||||||
|
left join (
|
||||||
|
select m.workOrderId,
|
||||||
|
count(m.workOrderMilestoneId) as workOrderMilestoneCount,
|
||||||
|
sum(case when m.workOrderMilestoneCompletionDate is null then 0 else 1 end) as workOrderMilestoneCompletionCount
|
||||||
|
from WorkOrderMilestones m
|
||||||
|
where m.recordDelete_timeMillis is null
|
||||||
|
group by m.workOrderId
|
||||||
|
) m on w.workOrderId = m.workOrderId
|
||||||
|
where w.recordDelete_timeMillis is null
|
||||||
|
and w.workOrderCloseDate is null`
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'workOrderComments-all': {
|
||||||
|
sql = 'select * from WorkOrderComments'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'workOrderLots-all': {
|
||||||
|
sql = 'select * from WorkOrderLots'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'workOrderMilestones-all': {
|
||||||
|
sql = 'select * from WorkOrderMilestones'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'fees-all': {
|
||||||
|
sql = 'select * from Fees'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'feeCategories-all': {
|
||||||
|
sql = 'select * from FeeCategories'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotTypes-all': {
|
||||||
|
sql = 'select * from LotTypes'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotTypeFields-all': {
|
||||||
|
sql = 'select * from LotTypeFields'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotStatuses-all': {
|
||||||
|
sql = 'select * from LotStatuses'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'occupancyTypes-all': {
|
||||||
|
sql = 'select * from OccupancyTypes'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'occupancyTypeFields-all': {
|
||||||
|
sql = 'select * from OccupancyTypeFields'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lotOccupantTypes-all': {
|
||||||
|
sql = 'select * from LotOccupantTypes'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'workOrderTypes-all': {
|
||||||
|
sql = 'select * from WorkOrderTypes'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'workOrderMilestoneTypes-all': {
|
||||||
|
sql = 'select * from WorkOrderMilestoneTypes'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const database = sqlite(databasePath, {
|
||||||
|
readonly: true
|
||||||
|
})
|
||||||
|
|
||||||
|
database.function(
|
||||||
|
'userFn_dateIntegerToString',
|
||||||
|
dateTimeFunctions.dateIntegerToString
|
||||||
|
)
|
||||||
|
database.function(
|
||||||
|
'userFn_timeIntegerToString',
|
||||||
|
dateTimeFunctions.timeIntegerToString
|
||||||
|
)
|
||||||
|
|
||||||
|
const rows = database.prepare(sql).all(sqlParameters)
|
||||||
|
|
||||||
|
database.close()
|
||||||
|
|
||||||
|
return rows
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getReportData;
|
export default getReportData
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
export declare function getWorkOrderTypes(): recordTypes.WorkOrderType[];
|
export declare function getWorkOrderTypes(): recordTypes.WorkOrderType[];
|
||||||
export default getWorkOrderTypes;
|
export default getWorkOrderTypes;
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js";
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||||
export function getWorkOrderTypes() {
|
export function getWorkOrderTypes() {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const workOrderTypes = database
|
const workOrderTypes = database
|
||||||
.prepare(`select workOrderTypeId, workOrderType, orderNumber
|
.prepare(`select workOrderTypeId, workOrderType, orderNumber
|
||||||
from WorkOrderTypes
|
from WorkOrderTypes
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
order by orderNumber, workOrderType`)
|
order by orderNumber, workOrderType`)
|
||||||
.all();
|
.all();
|
||||||
let expectedOrderNumber = 0;
|
let expectedOrderNumber = 0;
|
||||||
for (const workOrderType of workOrderTypes) {
|
for (const workOrderType of workOrderTypes) {
|
||||||
if (workOrderType.orderNumber !== expectedOrderNumber) {
|
if (workOrderType.orderNumber !== expectedOrderNumber) {
|
||||||
updateRecordOrderNumber("WorkOrderTypes", workOrderType.workOrderTypeId, expectedOrderNumber, database);
|
updateRecordOrderNumber('WorkOrderTypes', workOrderType.workOrderTypeId, expectedOrderNumber, database);
|
||||||
workOrderType.orderNumber = expectedOrderNumber;
|
workOrderType.orderNumber = expectedOrderNumber;
|
||||||
}
|
}
|
||||||
expectedOrderNumber += 1;
|
expectedOrderNumber += 1;
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,43 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js";
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
export function getWorkOrderTypes(): recordTypes.WorkOrderType[] {
|
export function getWorkOrderTypes(): recordTypes.WorkOrderType[] {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const workOrderTypes: recordTypes.WorkOrderType[] = database
|
const workOrderTypes: recordTypes.WorkOrderType[] = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select workOrderTypeId, workOrderType, orderNumber
|
`select workOrderTypeId, workOrderType, orderNumber
|
||||||
from WorkOrderTypes
|
from WorkOrderTypes
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
order by orderNumber, workOrderType`
|
order by orderNumber, workOrderType`
|
||||||
)
|
)
|
||||||
.all();
|
.all()
|
||||||
|
|
||||||
let expectedOrderNumber = 0;
|
let expectedOrderNumber = 0
|
||||||
|
|
||||||
for (const workOrderType of workOrderTypes) {
|
for (const workOrderType of workOrderTypes) {
|
||||||
if (workOrderType.orderNumber !== expectedOrderNumber) {
|
if (workOrderType.orderNumber !== expectedOrderNumber) {
|
||||||
updateRecordOrderNumber(
|
updateRecordOrderNumber(
|
||||||
"WorkOrderTypes",
|
'WorkOrderTypes',
|
||||||
workOrderType.workOrderTypeId,
|
workOrderType.workOrderTypeId!,
|
||||||
expectedOrderNumber,
|
expectedOrderNumber,
|
||||||
database
|
database
|
||||||
);
|
)
|
||||||
|
|
||||||
workOrderType.orderNumber = expectedOrderNumber;
|
workOrderType.orderNumber = expectedOrderNumber
|
||||||
}
|
|
||||||
|
|
||||||
expectedOrderNumber += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
database.close();
|
expectedOrderNumber += 1
|
||||||
|
}
|
||||||
|
|
||||||
return workOrderTypes;
|
database.close()
|
||||||
|
|
||||||
|
return workOrderTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getWorkOrderTypes;
|
export default getWorkOrderTypes
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { getFee } from "./getFee.js";
|
import { getFee } from './getFee.js';
|
||||||
import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js";
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||||
export function moveFeeDown(feeId) {
|
export function moveFeeDown(feeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database);
|
||||||
database
|
database
|
||||||
.prepare(`update Fees
|
.prepare(`update Fees
|
||||||
set orderNumber = orderNumber - 1
|
set orderNumber = orderNumber - 1
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and feeCategoryId = ?
|
and feeCategoryId = ?
|
||||||
and orderNumber = ? + 1`)
|
and orderNumber = ? + 1`)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
||||||
const success = updateRecordOrderNumber("Fees", feeId, currentFee.orderNumber + 1, database);
|
const success = updateRecordOrderNumber('Fees', feeId, currentFee.orderNumber + 1, database);
|
||||||
database.close();
|
database.close();
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
@ -26,7 +26,7 @@ export function moveFeeDownToBottom(feeId) {
|
||||||
and feeCategoryId = ?`)
|
and feeCategoryId = ?`)
|
||||||
.get(currentFee.feeCategoryId).maxOrderNumber;
|
.get(currentFee.feeCategoryId).maxOrderNumber;
|
||||||
if (currentFee.orderNumber !== maxOrderNumber) {
|
if (currentFee.orderNumber !== maxOrderNumber) {
|
||||||
updateRecordOrderNumber("Fees", feeId, maxOrderNumber + 1, database);
|
updateRecordOrderNumber('Fees', feeId, maxOrderNumber + 1, database);
|
||||||
database
|
database
|
||||||
.prepare(`update Fees
|
.prepare(`update Fees
|
||||||
set orderNumber = orderNumber - 1
|
set orderNumber = orderNumber - 1
|
||||||
|
|
@ -51,7 +51,7 @@ export function moveFeeUp(feeId) {
|
||||||
and feeCategoryId = ?
|
and feeCategoryId = ?
|
||||||
and orderNumber = ? - 1`)
|
and orderNumber = ? - 1`)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
||||||
const success = updateRecordOrderNumber("Fees", feeId, currentFee.orderNumber - 1, database);
|
const success = updateRecordOrderNumber('Fees', feeId, currentFee.orderNumber - 1, database);
|
||||||
database.close();
|
database.close();
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
@ -59,13 +59,13 @@ export function moveFeeUpToTop(feeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database);
|
||||||
if (currentFee.orderNumber > 0) {
|
if (currentFee.orderNumber > 0) {
|
||||||
updateRecordOrderNumber("Fees", feeId, -1, database);
|
updateRecordOrderNumber('Fees', feeId, -1, database);
|
||||||
database
|
database
|
||||||
.prepare(`update Fees
|
.prepare(`update Fees
|
||||||
set orderNumber = orderNumber + 1
|
set orderNumber = orderNumber + 1
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and feeCategoryId = ?
|
and feeCategoryId = ?
|
||||||
and orderNumber < ?`)
|
and orderNumber < ?`)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
|
|
|
||||||
|
|
@ -1,113 +1,123 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import { getFee } from "./getFee.js";
|
import { getFee } from './getFee.js'
|
||||||
import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js";
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
||||||
|
|
||||||
export function moveFeeDown(feeId: number | string): boolean {
|
export function moveFeeDown(feeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database)
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
`update Fees
|
||||||
|
set orderNumber = orderNumber - 1
|
||||||
|
where recordDelete_timeMillis is null
|
||||||
|
and feeCategoryId = ?
|
||||||
|
and orderNumber = ? + 1`
|
||||||
|
)
|
||||||
|
.run(currentFee.feeCategoryId, currentFee.orderNumber)
|
||||||
|
|
||||||
|
const success = updateRecordOrderNumber(
|
||||||
|
'Fees',
|
||||||
|
feeId,
|
||||||
|
currentFee.orderNumber! + 1,
|
||||||
database
|
database
|
||||||
.prepare(
|
)
|
||||||
`update Fees
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and feeCategoryId = ?
|
|
||||||
and orderNumber = ? + 1`
|
|
||||||
)
|
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
|
||||||
|
|
||||||
const success = updateRecordOrderNumber("Fees", feeId, currentFee.orderNumber + 1, database);
|
database.close()
|
||||||
|
|
||||||
database.close();
|
return success
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveFeeDownToBottom(feeId: number | string): boolean {
|
export function moveFeeDownToBottom(feeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database)
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
const maxOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`select max(orderNumber) as maxOrderNumber
|
`select max(orderNumber) as maxOrderNumber
|
||||||
from Fees
|
from Fees
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and feeCategoryId = ?`
|
and feeCategoryId = ?`
|
||||||
)
|
)
|
||||||
.get(currentFee.feeCategoryId).maxOrderNumber;
|
.get(currentFee.feeCategoryId).maxOrderNumber
|
||||||
|
|
||||||
if (currentFee.orderNumber !== maxOrderNumber) {
|
if (currentFee.orderNumber !== maxOrderNumber) {
|
||||||
updateRecordOrderNumber("Fees", feeId, maxOrderNumber + 1, database);
|
updateRecordOrderNumber('Fees', feeId, maxOrderNumber + 1, database)
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update Fees
|
`update Fees
|
||||||
set orderNumber = orderNumber - 1
|
set orderNumber = orderNumber - 1
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and feeCategoryId = ? and orderNumber > ?`
|
and feeCategoryId = ? and orderNumber > ?`
|
||||||
)
|
)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveFeeUp(feeId: number): boolean {
|
export function moveFeeUp(feeId: number): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database)
|
||||||
|
|
||||||
if (currentFee.orderNumber <= 0) {
|
if (currentFee.orderNumber! <= 0) {
|
||||||
database.close();
|
database.close()
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update Fees
|
`update Fees
|
||||||
set orderNumber = orderNumber + 1
|
set orderNumber = orderNumber + 1
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and feeCategoryId = ?
|
and feeCategoryId = ?
|
||||||
and orderNumber = ? - 1`
|
and orderNumber = ? - 1`
|
||||||
)
|
)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber)
|
||||||
|
|
||||||
const success = updateRecordOrderNumber("Fees", feeId, currentFee.orderNumber - 1, database);
|
const success = updateRecordOrderNumber(
|
||||||
|
'Fees',
|
||||||
|
feeId,
|
||||||
|
currentFee.orderNumber! - 1,
|
||||||
|
database
|
||||||
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return success;
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveFeeUpToTop(feeId: number | string): boolean {
|
export function moveFeeUpToTop(feeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database)
|
||||||
|
|
||||||
if (currentFee.orderNumber > 0) {
|
if (currentFee.orderNumber! > 0) {
|
||||||
updateRecordOrderNumber("Fees", feeId, -1, database);
|
updateRecordOrderNumber('Fees', feeId, -1, database)
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update Fees
|
`update Fees
|
||||||
set orderNumber = orderNumber + 1
|
set orderNumber = orderNumber + 1
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and feeCategoryId = ?
|
and feeCategoryId = ?
|
||||||
and orderNumber < ?`
|
and orderNumber < ?`
|
||||||
)
|
)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveFeeUp;
|
export default moveFeeUp
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { clearCacheByTableName } from "../functions.cache.js";
|
import { clearCacheByTableName } from '../functions.cache.js';
|
||||||
import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js";
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js';
|
||||||
function getCurrentField(occupancyTypeFieldId, connectedDatabase) {
|
function getCurrentField(occupancyTypeFieldId, connectedDatabase) {
|
||||||
const currentField = connectedDatabase
|
const currentField = connectedDatabase
|
||||||
.prepare(`select occupancyTypeId, orderNumber from OccupancyTypeFields where occupancyTypeFieldId = ?`)
|
.prepare(`select occupancyTypeId, orderNumber
|
||||||
|
from OccupancyTypeFields
|
||||||
|
where occupancyTypeFieldId = ?`)
|
||||||
.get(occupancyTypeFieldId);
|
.get(occupancyTypeFieldId);
|
||||||
return currentField;
|
return currentField;
|
||||||
}
|
}
|
||||||
|
|
@ -12,17 +14,17 @@ export function moveOccupancyTypeFieldDown(occupancyTypeFieldId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentField = getCurrentField(occupancyTypeFieldId, database);
|
const currentField = getCurrentField(occupancyTypeFieldId, database);
|
||||||
database
|
database
|
||||||
.prepare("update OccupancyTypeFields" +
|
.prepare('update OccupancyTypeFields' +
|
||||||
" set orderNumber = orderNumber - 1" +
|
' set orderNumber = orderNumber - 1' +
|
||||||
" where recordDelete_timeMillis is null" +
|
' where recordDelete_timeMillis is null' +
|
||||||
(currentField.occupancyTypeId
|
(currentField.occupancyTypeId
|
||||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
||||||
: " and occupancyTypeId is null") +
|
: ' and occupancyTypeId is null') +
|
||||||
" and orderNumber = ? + 1")
|
' and orderNumber = ? + 1')
|
||||||
.run(currentField.orderNumber);
|
.run(currentField.orderNumber);
|
||||||
const success = updateRecordOrderNumber("OccupancyTypeFields", occupancyTypeFieldId, currentField.orderNumber + 1, database);
|
const success = updateRecordOrderNumber('OccupancyTypeFields', occupancyTypeFieldId, currentField.orderNumber + 1, database);
|
||||||
database.close();
|
database.close();
|
||||||
clearCacheByTableName("OccupancyTypeFields");
|
clearCacheByTableName('OccupancyTypeFields');
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
export function moveOccupancyTypeFieldDownToBottom(occupancyTypeFieldId) {
|
export function moveOccupancyTypeFieldDownToBottom(occupancyTypeFieldId) {
|
||||||
|
|
@ -33,26 +35,28 @@ export function moveOccupancyTypeFieldDownToBottom(occupancyTypeFieldId) {
|
||||||
occupancyTypeParameters.push(currentField.occupancyTypeId);
|
occupancyTypeParameters.push(currentField.occupancyTypeId);
|
||||||
}
|
}
|
||||||
const maxOrderNumber = database
|
const maxOrderNumber = database
|
||||||
.prepare("select max(orderNumber) as maxOrderNumber" +
|
.prepare('select max(orderNumber) as maxOrderNumber' +
|
||||||
" from OccupancyTypeFields" +
|
' from OccupancyTypeFields' +
|
||||||
" where recordDelete_timeMillis is null" +
|
' where recordDelete_timeMillis is null' +
|
||||||
(currentField.occupancyTypeId ? " and occupancyTypeId = ?" : " and occupancyTypeId is null"))
|
(currentField.occupancyTypeId
|
||||||
|
? ' and occupancyTypeId = ?'
|
||||||
|
: ' and occupancyTypeId is null'))
|
||||||
.get(occupancyTypeParameters).maxOrderNumber;
|
.get(occupancyTypeParameters).maxOrderNumber;
|
||||||
if (currentField.orderNumber !== maxOrderNumber) {
|
if (currentField.orderNumber !== maxOrderNumber) {
|
||||||
updateRecordOrderNumber("OccupancyTypeFields", occupancyTypeFieldId, maxOrderNumber + 1, database);
|
updateRecordOrderNumber('OccupancyTypeFields', occupancyTypeFieldId, maxOrderNumber + 1, database);
|
||||||
occupancyTypeParameters.push(currentField.orderNumber);
|
occupancyTypeParameters.push(currentField.orderNumber);
|
||||||
database
|
database
|
||||||
.prepare("update OccupancyTypeFields" +
|
.prepare('update OccupancyTypeFields' +
|
||||||
" set orderNumber = orderNumber - 1" +
|
' set orderNumber = orderNumber - 1' +
|
||||||
" where recordDelete_timeMillis is null" +
|
' where recordDelete_timeMillis is null' +
|
||||||
(currentField.occupancyTypeId
|
(currentField.occupancyTypeId
|
||||||
? " and occupancyTypeId = ?"
|
? ' and occupancyTypeId = ?'
|
||||||
: " and occupancyTypeId is null") +
|
: ' and occupancyTypeId is null') +
|
||||||
" and orderNumber > ?")
|
' and orderNumber > ?')
|
||||||
.run(occupancyTypeParameters);
|
.run(occupancyTypeParameters);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
clearCacheByTableName("OccupancyTypeFields");
|
clearCacheByTableName('OccupancyTypeFields');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
export function moveOccupancyTypeFieldUp(occupancyTypeFieldId) {
|
export function moveOccupancyTypeFieldUp(occupancyTypeFieldId) {
|
||||||
|
|
@ -63,40 +67,40 @@ export function moveOccupancyTypeFieldUp(occupancyTypeFieldId) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
database
|
database
|
||||||
.prepare("update OccupancyTypeFields" +
|
.prepare('update OccupancyTypeFields' +
|
||||||
" set orderNumber = orderNumber + 1" +
|
' set orderNumber = orderNumber + 1' +
|
||||||
" where recordDelete_timeMillis is null" +
|
' where recordDelete_timeMillis is null' +
|
||||||
(currentField.occupancyTypeId
|
(currentField.occupancyTypeId
|
||||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
||||||
: " and occupancyTypeId is null") +
|
: ' and occupancyTypeId is null') +
|
||||||
" and orderNumber = ? - 1")
|
' and orderNumber = ? - 1')
|
||||||
.run(currentField.orderNumber);
|
.run(currentField.orderNumber);
|
||||||
const success = updateRecordOrderNumber("OccupancyTypeFields", occupancyTypeFieldId, currentField.orderNumber - 1, database);
|
const success = updateRecordOrderNumber('OccupancyTypeFields', occupancyTypeFieldId, currentField.orderNumber - 1, database);
|
||||||
database.close();
|
database.close();
|
||||||
clearCacheByTableName("OccupancyTypeFields");
|
clearCacheByTableName('OccupancyTypeFields');
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
export function moveOccupancyTypeFieldUpToTop(occupancyTypeFieldId) {
|
export function moveOccupancyTypeFieldUpToTop(occupancyTypeFieldId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentField = getCurrentField(occupancyTypeFieldId, database);
|
const currentField = getCurrentField(occupancyTypeFieldId, database);
|
||||||
if (currentField.orderNumber > 0) {
|
if (currentField.orderNumber > 0) {
|
||||||
updateRecordOrderNumber("OccupancyTypeFields", occupancyTypeFieldId, -1, database);
|
updateRecordOrderNumber('OccupancyTypeFields', occupancyTypeFieldId, -1, database);
|
||||||
const occupancyTypeParameters = [];
|
const occupancyTypeParameters = [];
|
||||||
if (currentField.occupancyTypeId) {
|
if (currentField.occupancyTypeId) {
|
||||||
occupancyTypeParameters.push(currentField.occupancyTypeId);
|
occupancyTypeParameters.push(currentField.occupancyTypeId);
|
||||||
}
|
}
|
||||||
occupancyTypeParameters.push(currentField.orderNumber);
|
occupancyTypeParameters.push(currentField.orderNumber);
|
||||||
database
|
database
|
||||||
.prepare("update OccupancyTypeFields" +
|
.prepare('update OccupancyTypeFields' +
|
||||||
" set orderNumber = orderNumber + 1" +
|
' set orderNumber = orderNumber + 1' +
|
||||||
" where recordDelete_timeMillis is null" +
|
' where recordDelete_timeMillis is null' +
|
||||||
(currentField.occupancyTypeId
|
(currentField.occupancyTypeId
|
||||||
? " and occupancyTypeId = ?"
|
? ' and occupancyTypeId = ?'
|
||||||
: " and occupancyTypeId is null") +
|
: ' and occupancyTypeId is null') +
|
||||||
" and orderNumber < ?")
|
' and orderNumber < ?')
|
||||||
.run(occupancyTypeParameters);
|
.run(occupancyTypeParameters);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
clearCacheByTableName("OccupancyTypeFields");
|
clearCacheByTableName('OccupancyTypeFields');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,167 +1,190 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import { clearCacheByTableName } from "../functions.cache.js";
|
import { clearCacheByTableName } from '../functions.cache.js'
|
||||||
import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js";
|
import { updateRecordOrderNumber } from './updateRecordOrderNumber.js'
|
||||||
|
|
||||||
function getCurrentField(
|
function getCurrentField(
|
||||||
occupancyTypeFieldId: number,
|
occupancyTypeFieldId: number,
|
||||||
connectedDatabase: sqlite.Database
|
connectedDatabase: sqlite.Database
|
||||||
): { occupancyTypeId?: number; orderNumber: number } {
|
): { occupancyTypeId?: number; orderNumber: number } {
|
||||||
const currentField: { occupancyTypeId?: number; orderNumber: number } = connectedDatabase
|
const currentField: { occupancyTypeId?: number; orderNumber: number } =
|
||||||
.prepare(
|
connectedDatabase
|
||||||
`select occupancyTypeId, orderNumber from OccupancyTypeFields where occupancyTypeFieldId = ?`
|
.prepare(
|
||||||
)
|
`select occupancyTypeId, orderNumber
|
||||||
.get(occupancyTypeFieldId);
|
from OccupancyTypeFields
|
||||||
|
where occupancyTypeFieldId = ?`
|
||||||
|
)
|
||||||
|
.get(occupancyTypeFieldId)
|
||||||
|
|
||||||
return currentField;
|
return currentField
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveOccupancyTypeFieldDown(occupancyTypeFieldId: number): boolean {
|
export function moveOccupancyTypeFieldDown(
|
||||||
const database = sqlite(databasePath);
|
occupancyTypeFieldId: number
|
||||||
|
): boolean {
|
||||||
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const currentField = getCurrentField(occupancyTypeFieldId, database);
|
const currentField = getCurrentField(occupancyTypeFieldId, database)
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
'update OccupancyTypeFields' +
|
||||||
|
' set orderNumber = orderNumber - 1' +
|
||||||
|
' where recordDelete_timeMillis is null' +
|
||||||
|
(currentField.occupancyTypeId
|
||||||
|
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
||||||
|
: ' and occupancyTypeId is null') +
|
||||||
|
' and orderNumber = ? + 1'
|
||||||
|
)
|
||||||
|
.run(currentField.orderNumber)
|
||||||
|
|
||||||
|
const success = updateRecordOrderNumber(
|
||||||
|
'OccupancyTypeFields',
|
||||||
|
occupancyTypeFieldId,
|
||||||
|
currentField.orderNumber + 1,
|
||||||
|
database
|
||||||
|
)
|
||||||
|
|
||||||
|
database.close()
|
||||||
|
|
||||||
|
clearCacheByTableName('OccupancyTypeFields')
|
||||||
|
|
||||||
|
return success
|
||||||
|
}
|
||||||
|
|
||||||
|
export function moveOccupancyTypeFieldDownToBottom(
|
||||||
|
occupancyTypeFieldId: number
|
||||||
|
): boolean {
|
||||||
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
|
const currentField = getCurrentField(occupancyTypeFieldId, database)
|
||||||
|
|
||||||
|
const occupancyTypeParameters: unknown[] = []
|
||||||
|
|
||||||
|
if (currentField.occupancyTypeId) {
|
||||||
|
occupancyTypeParameters.push(currentField.occupancyTypeId)
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxOrderNumber: number = database
|
||||||
|
.prepare(
|
||||||
|
'select max(orderNumber) as maxOrderNumber' +
|
||||||
|
' from OccupancyTypeFields' +
|
||||||
|
' where recordDelete_timeMillis is null' +
|
||||||
|
(currentField.occupancyTypeId
|
||||||
|
? ' and occupancyTypeId = ?'
|
||||||
|
: ' and occupancyTypeId is null')
|
||||||
|
)
|
||||||
|
.get(occupancyTypeParameters).maxOrderNumber
|
||||||
|
|
||||||
|
if (currentField.orderNumber !== maxOrderNumber) {
|
||||||
|
updateRecordOrderNumber(
|
||||||
|
'OccupancyTypeFields',
|
||||||
|
occupancyTypeFieldId,
|
||||||
|
maxOrderNumber + 1,
|
||||||
|
database
|
||||||
|
)
|
||||||
|
|
||||||
|
occupancyTypeParameters.push(currentField.orderNumber)
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update OccupancyTypeFields" +
|
'update OccupancyTypeFields' +
|
||||||
" set orderNumber = orderNumber - 1" +
|
' set orderNumber = orderNumber - 1' +
|
||||||
" where recordDelete_timeMillis is null" +
|
' where recordDelete_timeMillis is null' +
|
||||||
(currentField.occupancyTypeId
|
(currentField.occupancyTypeId
|
||||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
? ' and occupancyTypeId = ?'
|
||||||
: " and occupancyTypeId is null") +
|
: ' and occupancyTypeId is null') +
|
||||||
" and orderNumber = ? + 1"
|
' and orderNumber > ?'
|
||||||
)
|
)
|
||||||
.run(currentField.orderNumber);
|
.run(occupancyTypeParameters)
|
||||||
|
}
|
||||||
|
|
||||||
const success = updateRecordOrderNumber(
|
database.close()
|
||||||
"OccupancyTypeFields",
|
|
||||||
occupancyTypeFieldId,
|
|
||||||
currentField.orderNumber + 1,
|
|
||||||
database
|
|
||||||
);
|
|
||||||
|
|
||||||
database.close();
|
clearCacheByTableName('OccupancyTypeFields')
|
||||||
|
|
||||||
clearCacheByTableName("OccupancyTypeFields");
|
return true
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveOccupancyTypeFieldDownToBottom(occupancyTypeFieldId: number): boolean {
|
export function moveOccupancyTypeFieldUp(
|
||||||
const database = sqlite(databasePath);
|
occupancyTypeFieldId: number
|
||||||
|
): boolean {
|
||||||
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const currentField = getCurrentField(occupancyTypeFieldId, database);
|
const currentField = getCurrentField(occupancyTypeFieldId, database)
|
||||||
|
|
||||||
const occupancyTypeParameters = [];
|
if (currentField.orderNumber <= 0) {
|
||||||
|
database.close()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
'update OccupancyTypeFields' +
|
||||||
|
' set orderNumber = orderNumber + 1' +
|
||||||
|
' where recordDelete_timeMillis is null' +
|
||||||
|
(currentField.occupancyTypeId
|
||||||
|
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
||||||
|
: ' and occupancyTypeId is null') +
|
||||||
|
' and orderNumber = ? - 1'
|
||||||
|
)
|
||||||
|
.run(currentField.orderNumber)
|
||||||
|
|
||||||
|
const success = updateRecordOrderNumber(
|
||||||
|
'OccupancyTypeFields',
|
||||||
|
occupancyTypeFieldId,
|
||||||
|
currentField.orderNumber - 1,
|
||||||
|
database
|
||||||
|
)
|
||||||
|
|
||||||
|
database.close()
|
||||||
|
|
||||||
|
clearCacheByTableName('OccupancyTypeFields')
|
||||||
|
|
||||||
|
return success
|
||||||
|
}
|
||||||
|
|
||||||
|
export function moveOccupancyTypeFieldUpToTop(
|
||||||
|
occupancyTypeFieldId: number
|
||||||
|
): boolean {
|
||||||
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
|
const currentField = getCurrentField(occupancyTypeFieldId, database)
|
||||||
|
|
||||||
|
if (currentField.orderNumber > 0) {
|
||||||
|
updateRecordOrderNumber(
|
||||||
|
'OccupancyTypeFields',
|
||||||
|
occupancyTypeFieldId,
|
||||||
|
-1,
|
||||||
|
database
|
||||||
|
)
|
||||||
|
|
||||||
|
const occupancyTypeParameters: unknown[] = []
|
||||||
|
|
||||||
if (currentField.occupancyTypeId) {
|
if (currentField.occupancyTypeId) {
|
||||||
occupancyTypeParameters.push(currentField.occupancyTypeId);
|
occupancyTypeParameters.push(currentField.occupancyTypeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
occupancyTypeParameters.push(currentField.orderNumber)
|
||||||
.prepare(
|
|
||||||
"select max(orderNumber) as maxOrderNumber" +
|
|
||||||
" from OccupancyTypeFields" +
|
|
||||||
" where recordDelete_timeMillis is null" +
|
|
||||||
(currentField.occupancyTypeId ? " and occupancyTypeId = ?" : " and occupancyTypeId is null")
|
|
||||||
)
|
|
||||||
.get(occupancyTypeParameters).maxOrderNumber;
|
|
||||||
|
|
||||||
if (currentField.orderNumber !== maxOrderNumber) {
|
|
||||||
updateRecordOrderNumber("OccupancyTypeFields", occupancyTypeFieldId, maxOrderNumber + 1, database);
|
|
||||||
|
|
||||||
occupancyTypeParameters.push(currentField.orderNumber);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
"update OccupancyTypeFields" +
|
|
||||||
" set orderNumber = orderNumber - 1" +
|
|
||||||
" where recordDelete_timeMillis is null" +
|
|
||||||
(currentField.occupancyTypeId
|
|
||||||
? " and occupancyTypeId = ?"
|
|
||||||
: " and occupancyTypeId is null") +
|
|
||||||
" and orderNumber > ?"
|
|
||||||
)
|
|
||||||
.run(occupancyTypeParameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearCacheByTableName("OccupancyTypeFields");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function moveOccupancyTypeFieldUp(occupancyTypeFieldId: number): boolean {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
const currentField = getCurrentField(occupancyTypeFieldId, database);
|
|
||||||
|
|
||||||
if (currentField.orderNumber <= 0) {
|
|
||||||
database.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update OccupancyTypeFields" +
|
'update OccupancyTypeFields' +
|
||||||
" set orderNumber = orderNumber + 1" +
|
' set orderNumber = orderNumber + 1' +
|
||||||
" where recordDelete_timeMillis is null" +
|
' where recordDelete_timeMillis is null' +
|
||||||
(currentField.occupancyTypeId
|
(currentField.occupancyTypeId
|
||||||
? " and occupancyTypeId = '" + currentField.occupancyTypeId + "'"
|
? ' and occupancyTypeId = ?'
|
||||||
: " and occupancyTypeId is null") +
|
: ' and occupancyTypeId is null') +
|
||||||
" and orderNumber = ? - 1"
|
' and orderNumber < ?'
|
||||||
)
|
)
|
||||||
.run(currentField.orderNumber);
|
.run(occupancyTypeParameters)
|
||||||
|
}
|
||||||
|
|
||||||
const success = updateRecordOrderNumber(
|
database.close()
|
||||||
"OccupancyTypeFields",
|
|
||||||
occupancyTypeFieldId,
|
|
||||||
currentField.orderNumber - 1,
|
|
||||||
database
|
|
||||||
);
|
|
||||||
|
|
||||||
database.close();
|
clearCacheByTableName('OccupancyTypeFields')
|
||||||
|
|
||||||
clearCacheByTableName("OccupancyTypeFields");
|
return true
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function moveOccupancyTypeFieldUpToTop(occupancyTypeFieldId: number): boolean {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
const currentField = getCurrentField(occupancyTypeFieldId, database);
|
|
||||||
|
|
||||||
if (currentField.orderNumber > 0) {
|
|
||||||
updateRecordOrderNumber("OccupancyTypeFields", occupancyTypeFieldId, -1, database);
|
|
||||||
|
|
||||||
const occupancyTypeParameters = [];
|
|
||||||
|
|
||||||
if (currentField.occupancyTypeId) {
|
|
||||||
occupancyTypeParameters.push(currentField.occupancyTypeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
occupancyTypeParameters.push(currentField.orderNumber);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
"update OccupancyTypeFields" +
|
|
||||||
" set orderNumber = orderNumber + 1" +
|
|
||||||
" where recordDelete_timeMillis is null" +
|
|
||||||
(currentField.occupancyTypeId
|
|
||||||
? " and occupancyTypeId = ?"
|
|
||||||
: " and occupancyTypeId is null") +
|
|
||||||
" and orderNumber < ?"
|
|
||||||
)
|
|
||||||
.run(occupancyTypeParameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearCacheByTableName("OccupancyTypeFields");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
export declare function reopenWorkOrder(workOrderId: number | string, requestSession: recordTypes.PartialSession): boolean;
|
export declare function reopenWorkOrder(workOrderId: number | string, requestSession: recordTypes.PartialSession): boolean;
|
||||||
export default reopenWorkOrder;
|
export default reopenWorkOrder;
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
export function reopenWorkOrder(workOrderId, requestSession) {
|
export function reopenWorkOrder(workOrderId, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update WorkOrders
|
.prepare(`update WorkOrders
|
||||||
set workOrderCloseDate = null,
|
set workOrderCloseDate = null,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and workOrderCloseDate is not null`)
|
and workOrderCloseDate is not null`)
|
||||||
.run(requestSession.user.userName, rightNowMillis, workOrderId);
|
.run(requestSession.user.userName, rightNowMillis, workOrderId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,31 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
export function reopenWorkOrder(
|
export function reopenWorkOrder(
|
||||||
workOrderId: number | string,
|
workOrderId: number | string,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrders
|
`update WorkOrders
|
||||||
set workOrderCloseDate = null,
|
set workOrderCloseDate = null,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and workOrderCloseDate is not null`
|
and workOrderCloseDate is not null`
|
||||||
)
|
)
|
||||||
.run(requestSession.user.userName, rightNowMillis, workOrderId);
|
.run(requestSession.user!.userName, rightNowMillis, workOrderId)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default reopenWorkOrder;
|
export default reopenWorkOrder
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
export declare function reopenWorkOrderMilestone(workOrderMilestoneId: number | string, requestSession: recordTypes.PartialSession): boolean;
|
export declare function reopenWorkOrderMilestone(workOrderMilestoneId: number | string, requestSession: recordTypes.PartialSession): boolean;
|
||||||
export default reopenWorkOrderMilestone;
|
export default reopenWorkOrderMilestone;
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
export function reopenWorkOrderMilestone(workOrderMilestoneId, requestSession) {
|
export function reopenWorkOrderMilestone(workOrderMilestoneId, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update WorkOrderMilestones
|
.prepare(`update WorkOrderMilestones
|
||||||
set workOrderMilestoneCompletionDate = null,
|
set workOrderMilestoneCompletionDate = null,
|
||||||
workOrderMilestoneCompletionTime = null,
|
workOrderMilestoneCompletionTime = null,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where workOrderMilestoneId = ?
|
where workOrderMilestoneId = ?
|
||||||
and workOrderMilestoneCompletionDate is not null`)
|
and workOrderMilestoneCompletionDate is not null`)
|
||||||
.run(requestSession.user.userName, rightNowMillis, workOrderMilestoneId);
|
.run(requestSession.user.userName, rightNowMillis, workOrderMilestoneId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,32 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
export function reopenWorkOrderMilestone(
|
export function reopenWorkOrderMilestone(
|
||||||
workOrderMilestoneId: number | string,
|
workOrderMilestoneId: number | string,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderMilestones
|
`update WorkOrderMilestones
|
||||||
set workOrderMilestoneCompletionDate = null,
|
set workOrderMilestoneCompletionDate = null,
|
||||||
workOrderMilestoneCompletionTime = null,
|
workOrderMilestoneCompletionTime = null,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where workOrderMilestoneId = ?
|
where workOrderMilestoneId = ?
|
||||||
and workOrderMilestoneCompletionDate is not null`
|
and workOrderMilestoneCompletionDate is not null`
|
||||||
)
|
)
|
||||||
.run(requestSession.user.userName, rightNowMillis, workOrderMilestoneId);
|
.run(requestSession.user!.userName, rightNowMillis, workOrderMilestoneId)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default reopenWorkOrderMilestone;
|
export default reopenWorkOrderMilestone
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateFeeForm {
|
interface UpdateFeeForm {
|
||||||
feeId: string;
|
feeId: string;
|
||||||
feeCategoryId: string;
|
feeCategoryId: string;
|
||||||
feeName: string;
|
feeName: string;
|
||||||
feeDescription: string;
|
feeDescription: string;
|
||||||
occupancyTypeId?: string;
|
occupancyTypeId: string;
|
||||||
lotTypeId?: string;
|
lotTypeId: string;
|
||||||
feeAmount?: string;
|
feeAmount?: string;
|
||||||
feeFunction?: string;
|
feeFunction?: string;
|
||||||
taxAmount?: string;
|
taxAmount?: string;
|
||||||
taxPercentage?: string;
|
taxPercentage?: string;
|
||||||
includeQuantity: "" | "1";
|
includeQuantity: '' | '1';
|
||||||
quantityUnit?: string;
|
quantityUnit?: string;
|
||||||
isRequired: "" | "1";
|
isRequired: '' | '1';
|
||||||
}
|
}
|
||||||
export declare function updateFee(feeForm: UpdateFeeForm, requestSession: recordTypes.PartialSession): boolean;
|
export declare function updateFee(feeForm: UpdateFeeForm, requestSession: recordTypes.PartialSession): boolean;
|
||||||
export default updateFee;
|
export default updateFee;
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,27 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
export function updateFee(feeForm, requestSession) {
|
export function updateFee(feeForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update Fees
|
.prepare(`update Fees
|
||||||
set feeCategoryId = ?,
|
set feeCategoryId = ?,
|
||||||
feeName = ?,
|
feeName = ?,
|
||||||
feeDescription = ?,
|
feeDescription = ?,
|
||||||
occupancyTypeId = ?,
|
occupancyTypeId = ?,
|
||||||
lotTypeId = ?,
|
lotTypeId = ?,
|
||||||
feeAmount = ?,
|
feeAmount = ?,
|
||||||
feeFunction = ?,
|
feeFunction = ?,
|
||||||
taxAmount = ?,
|
taxAmount = ?,
|
||||||
taxPercentage = ?,
|
taxPercentage = ?,
|
||||||
includeQuantity = ?,
|
includeQuantity = ?,
|
||||||
quantityUnit = ?,
|
quantityUnit = ?,
|
||||||
isRequired = ?,
|
isRequired = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and feeId = ?`)
|
and feeId = ?`)
|
||||||
.run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.occupancyTypeId || undefined, feeForm.lotTypeId || undefined, feeForm.feeAmount || undefined, feeForm.feeFunction || undefined, feeForm.taxAmount || undefined, feeForm.taxPercentage || undefined, feeForm.includeQuantity ? 1 : 0, feeForm.quantityUnit, feeForm.isRequired ? 1 : 0, requestSession.user.userName, rightNowMillis, feeForm.feeId);
|
.run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.occupancyTypeId === '' ? undefined : feeForm.occupancyTypeId, feeForm.lotTypeId === '' ? undefined : feeForm.lotTypeId, feeForm.feeAmount ?? undefined, feeForm.feeFunction ?? undefined, feeForm.taxAmount ?? undefined, feeForm.taxPercentage ?? undefined, feeForm.includeQuantity === '' ? 0 : 1, feeForm.quantityUnit, feeForm.isRequired === '' ? 0 : 1, requestSession.user.userName, rightNowMillis, feeForm.feeId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,71 +1,74 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateFeeForm {
|
interface UpdateFeeForm {
|
||||||
feeId: string;
|
feeId: string
|
||||||
feeCategoryId: string;
|
feeCategoryId: string
|
||||||
feeName: string;
|
feeName: string
|
||||||
feeDescription: string;
|
feeDescription: string
|
||||||
occupancyTypeId?: string;
|
occupancyTypeId: string
|
||||||
lotTypeId?: string;
|
lotTypeId: string
|
||||||
feeAmount?: string;
|
feeAmount?: string
|
||||||
feeFunction?: string;
|
feeFunction?: string
|
||||||
taxAmount?: string;
|
taxAmount?: string
|
||||||
taxPercentage?: string;
|
taxPercentage?: string
|
||||||
includeQuantity: "" | "1";
|
includeQuantity: '' | '1'
|
||||||
quantityUnit?: string;
|
quantityUnit?: string
|
||||||
isRequired: "" | "1";
|
isRequired: '' | '1'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateFee(feeForm: UpdateFeeForm, requestSession: recordTypes.PartialSession): boolean {
|
export function updateFee(
|
||||||
const database = sqlite(databasePath);
|
feeForm: UpdateFeeForm,
|
||||||
|
requestSession: recordTypes.PartialSession
|
||||||
|
): boolean {
|
||||||
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update Fees
|
`update Fees
|
||||||
set feeCategoryId = ?,
|
set feeCategoryId = ?,
|
||||||
feeName = ?,
|
feeName = ?,
|
||||||
feeDescription = ?,
|
feeDescription = ?,
|
||||||
occupancyTypeId = ?,
|
occupancyTypeId = ?,
|
||||||
lotTypeId = ?,
|
lotTypeId = ?,
|
||||||
feeAmount = ?,
|
feeAmount = ?,
|
||||||
feeFunction = ?,
|
feeFunction = ?,
|
||||||
taxAmount = ?,
|
taxAmount = ?,
|
||||||
taxPercentage = ?,
|
taxPercentage = ?,
|
||||||
includeQuantity = ?,
|
includeQuantity = ?,
|
||||||
quantityUnit = ?,
|
quantityUnit = ?,
|
||||||
isRequired = ?,
|
isRequired = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and feeId = ?`
|
and feeId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
feeForm.feeCategoryId,
|
feeForm.feeCategoryId,
|
||||||
feeForm.feeName,
|
feeForm.feeName,
|
||||||
feeForm.feeDescription,
|
feeForm.feeDescription,
|
||||||
feeForm.occupancyTypeId || undefined,
|
feeForm.occupancyTypeId === '' ? undefined : feeForm.occupancyTypeId,
|
||||||
feeForm.lotTypeId || undefined,
|
feeForm.lotTypeId === '' ? undefined : feeForm.lotTypeId,
|
||||||
feeForm.feeAmount || undefined,
|
feeForm.feeAmount ?? undefined,
|
||||||
feeForm.feeFunction || undefined,
|
feeForm.feeFunction ?? undefined,
|
||||||
feeForm.taxAmount || undefined,
|
feeForm.taxAmount ?? undefined,
|
||||||
feeForm.taxPercentage || undefined,
|
feeForm.taxPercentage ?? undefined,
|
||||||
feeForm.includeQuantity ? 1 : 0,
|
feeForm.includeQuantity === '' ? 0 : 1,
|
||||||
feeForm.quantityUnit,
|
feeForm.quantityUnit,
|
||||||
feeForm.isRequired ? 1 : 0,
|
feeForm.isRequired === '' ? 0 : 1,
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
feeForm.feeId
|
feeForm.feeId
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateFee;
|
export default updateFee
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateLotForm {
|
interface UpdateLotForm {
|
||||||
lotId: string | number;
|
lotId: string | number;
|
||||||
lotName: string;
|
lotName: string;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { addOrUpdateLotField } from "./addOrUpdateLotField.js";
|
import { addOrUpdateLotField } from './addOrUpdateLotField.js';
|
||||||
import { deleteLotField } from "./deleteLotField.js";
|
import { deleteLotField } from './deleteLotField.js';
|
||||||
export function updateLot(lotForm, requestSession) {
|
export function updateLot(lotForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
|
|
@ -18,12 +18,12 @@ export function updateLot(lotForm, requestSession) {
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where lotId = ?
|
where lotId = ?
|
||||||
and recordDelete_timeMillis is null`)
|
and recordDelete_timeMillis is null`)
|
||||||
.run(lotForm.lotName, lotForm.lotTypeId, lotForm.lotStatusId === "" ? undefined : lotForm.lotStatusId, lotForm.mapId === "" ? undefined : lotForm.mapId, lotForm.mapKey, lotForm.lotLatitude === "" ? undefined : lotForm.lotLatitude, lotForm.lotLongitude === "" ? undefined : lotForm.lotLongitude, requestSession.user.userName, rightNowMillis, lotForm.lotId);
|
.run(lotForm.lotName, lotForm.lotTypeId, lotForm.lotStatusId === '' ? undefined : lotForm.lotStatusId, lotForm.mapId === '' ? undefined : lotForm.mapId, lotForm.mapKey, lotForm.lotLatitude === '' ? undefined : lotForm.lotLatitude, lotForm.lotLongitude === '' ? undefined : lotForm.lotLongitude, requestSession.user.userName, rightNowMillis, lotForm.lotId);
|
||||||
if (result.changes > 0) {
|
if (result.changes > 0) {
|
||||||
const lotTypeFieldIds = (lotForm.lotTypeFieldIds || "").split(",");
|
const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(',');
|
||||||
for (const lotTypeFieldId of lotTypeFieldIds) {
|
for (const lotTypeFieldId of lotTypeFieldIds) {
|
||||||
const lotFieldValue = lotForm["lotFieldValue_" + lotTypeFieldId];
|
const lotFieldValue = lotForm['lotFieldValue_' + lotTypeFieldId];
|
||||||
if (lotFieldValue && lotFieldValue !== "") {
|
if (lotFieldValue && lotFieldValue !== '') {
|
||||||
addOrUpdateLotField({
|
addOrUpdateLotField({
|
||||||
lotId: lotForm.lotId,
|
lotId: lotForm.lotId,
|
||||||
lotTypeFieldId,
|
lotTypeFieldId,
|
||||||
|
|
@ -48,7 +48,7 @@ export function updateLotStatus(lotId, lotStatusId, requestSession) {
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where lotId = ?
|
where lotId = ?
|
||||||
and recordDelete_timeMillis is null`)
|
and recordDelete_timeMillis is null`)
|
||||||
.run(lotStatusId === "" ? undefined : lotStatusId, requestSession.user.userName, rightNowMillis, lotId);
|
.run(lotStatusId === '' ? undefined : lotStatusId, requestSession.user.userName, rightNowMillis, lotId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,39 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import { addOrUpdateLotField } from "./addOrUpdateLotField.js";
|
import { addOrUpdateLotField } from './addOrUpdateLotField.js'
|
||||||
import { deleteLotField } from "./deleteLotField.js";
|
import { deleteLotField } from './deleteLotField.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateLotForm {
|
interface UpdateLotForm {
|
||||||
lotId: string | number;
|
lotId: string | number
|
||||||
lotName: string;
|
lotName: string
|
||||||
lotTypeId: string | number;
|
lotTypeId: string | number
|
||||||
lotStatusId: string | number;
|
lotStatusId: string | number
|
||||||
|
|
||||||
mapId: string | number;
|
mapId: string | number
|
||||||
mapKey: string;
|
mapKey: string
|
||||||
|
|
||||||
lotLatitude: string;
|
lotLatitude: string
|
||||||
lotLongitude: string;
|
lotLongitude: string
|
||||||
|
|
||||||
lotTypeFieldIds?: string;
|
lotTypeFieldIds?: string
|
||||||
[lotFieldValue_lotTypeFieldId: string]: unknown;
|
[lotFieldValue_lotTypeFieldId: string]: unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateLot(
|
export function updateLot(
|
||||||
lotForm: UpdateLotForm,
|
lotForm: UpdateLotForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update Lots
|
`update Lots
|
||||||
set lotName = ?,
|
set lotName = ?,
|
||||||
lotTypeId = ?,
|
lotTypeId = ?,
|
||||||
lotStatusId = ?,
|
lotStatusId = ?,
|
||||||
|
|
@ -45,75 +45,75 @@ export function updateLot(
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where lotId = ?
|
where lotId = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
|
)
|
||||||
|
.run(
|
||||||
|
lotForm.lotName,
|
||||||
|
lotForm.lotTypeId,
|
||||||
|
lotForm.lotStatusId === '' ? undefined : lotForm.lotStatusId,
|
||||||
|
lotForm.mapId === '' ? undefined : lotForm.mapId,
|
||||||
|
lotForm.mapKey,
|
||||||
|
lotForm.lotLatitude === '' ? undefined : lotForm.lotLatitude,
|
||||||
|
lotForm.lotLongitude === '' ? undefined : lotForm.lotLongitude,
|
||||||
|
requestSession.user!.userName,
|
||||||
|
rightNowMillis,
|
||||||
|
lotForm.lotId
|
||||||
|
)
|
||||||
|
|
||||||
|
if (result.changes > 0) {
|
||||||
|
const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(',')
|
||||||
|
|
||||||
|
for (const lotTypeFieldId of lotTypeFieldIds) {
|
||||||
|
const lotFieldValue = lotForm['lotFieldValue_' + lotTypeFieldId] as string
|
||||||
|
|
||||||
|
if (lotFieldValue && lotFieldValue !== '') {
|
||||||
|
addOrUpdateLotField(
|
||||||
|
{
|
||||||
|
lotId: lotForm.lotId,
|
||||||
|
lotTypeFieldId,
|
||||||
|
lotFieldValue
|
||||||
|
},
|
||||||
|
requestSession,
|
||||||
|
database
|
||||||
)
|
)
|
||||||
.run(
|
} else {
|
||||||
lotForm.lotName,
|
deleteLotField(lotForm.lotId, lotTypeFieldId, requestSession, database)
|
||||||
lotForm.lotTypeId,
|
}
|
||||||
lotForm.lotStatusId === "" ? undefined : lotForm.lotStatusId,
|
|
||||||
lotForm.mapId === "" ? undefined : lotForm.mapId,
|
|
||||||
lotForm.mapKey,
|
|
||||||
lotForm.lotLatitude === "" ? undefined : lotForm.lotLatitude,
|
|
||||||
lotForm.lotLongitude === "" ? undefined : lotForm.lotLongitude,
|
|
||||||
requestSession.user.userName,
|
|
||||||
rightNowMillis,
|
|
||||||
lotForm.lotId
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result.changes > 0) {
|
|
||||||
const lotTypeFieldIds = (lotForm.lotTypeFieldIds || "").split(",");
|
|
||||||
|
|
||||||
for (const lotTypeFieldId of lotTypeFieldIds) {
|
|
||||||
const lotFieldValue = lotForm["lotFieldValue_" + lotTypeFieldId] as string;
|
|
||||||
|
|
||||||
if (lotFieldValue && lotFieldValue !== "") {
|
|
||||||
addOrUpdateLotField(
|
|
||||||
{
|
|
||||||
lotId: lotForm.lotId,
|
|
||||||
lotTypeFieldId,
|
|
||||||
lotFieldValue
|
|
||||||
},
|
|
||||||
requestSession,
|
|
||||||
database
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
deleteLotField(lotForm.lotId, lotTypeFieldId, requestSession, database);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateLotStatus(
|
export function updateLotStatus(
|
||||||
lotId: number | string,
|
lotId: number | string,
|
||||||
lotStatusId: number | string,
|
lotStatusId: number | string,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update Lots
|
`update Lots
|
||||||
set lotStatusId = ?,
|
set lotStatusId = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where lotId = ?
|
where lotId = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
lotStatusId === "" ? undefined : lotStatusId,
|
lotStatusId === '' ? undefined : lotStatusId,
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
lotId
|
lotId
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateLot;
|
export default updateLot
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateLotCommentForm {
|
interface UpdateLotCommentForm {
|
||||||
lotCommentId: string | number;
|
lotCommentId: string | number;
|
||||||
lotCommentDateString: string;
|
lotCommentDateString: string;
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { dateStringToInteger, timeStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateStringToInteger, timeStringToInteger } from '@cityssm/expressjs-server-js/dateTimeFns.js';
|
||||||
export function updateLotComment(commentForm, requestSession) {
|
export function updateLotComment(commentForm, requestSession) {
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update LotComments
|
.prepare(`update LotComments
|
||||||
set lotCommentDate = ?,
|
set lotCommentDate = ?,
|
||||||
lotCommentTime = ?,
|
lotCommentTime = ?,
|
||||||
lotComment = ?,
|
lotComment = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and lotCommentId = ?`)
|
and lotCommentId = ?`)
|
||||||
.run(dateStringToInteger(commentForm.lotCommentDateString), timeStringToInteger(commentForm.lotCommentTimeString), commentForm.lotComment, requestSession.user.userName, rightNowMillis, commentForm.lotCommentId);
|
.run(dateStringToInteger(commentForm.lotCommentDateString), timeStringToInteger(commentForm.lotCommentTimeString), commentForm.lotComment, requestSession.user.userName, rightNowMillis, commentForm.lotCommentId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,52 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
dateStringToInteger,
|
dateStringToInteger,
|
||||||
timeStringToInteger
|
timeStringToInteger
|
||||||
} from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
} from '@cityssm/expressjs-server-js/dateTimeFns.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateLotCommentForm {
|
interface UpdateLotCommentForm {
|
||||||
lotCommentId: string | number;
|
lotCommentId: string | number
|
||||||
lotCommentDateString: string;
|
lotCommentDateString: string
|
||||||
lotCommentTimeString: string;
|
lotCommentTimeString: string
|
||||||
lotComment: string;
|
lotComment: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateLotComment(
|
export function updateLotComment(
|
||||||
commentForm: UpdateLotCommentForm,
|
commentForm: UpdateLotCommentForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update LotComments
|
`update LotComments
|
||||||
set lotCommentDate = ?,
|
set lotCommentDate = ?,
|
||||||
lotCommentTime = ?,
|
lotCommentTime = ?,
|
||||||
lotComment = ?,
|
lotComment = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and lotCommentId = ?`
|
and lotCommentId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
dateStringToInteger(commentForm.lotCommentDateString),
|
dateStringToInteger(commentForm.lotCommentDateString),
|
||||||
timeStringToInteger(commentForm.lotCommentTimeString),
|
timeStringToInteger(commentForm.lotCommentTimeString),
|
||||||
commentForm.lotComment,
|
commentForm.lotComment,
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
commentForm.lotCommentId
|
commentForm.lotCommentId
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateLotComment;
|
export default updateLotComment
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateLotOccupancyForm {
|
interface UpdateLotOccupancyForm {
|
||||||
lotOccupancyId: string | number;
|
lotOccupancyId: string | number;
|
||||||
occupancyTypeId: string | number;
|
occupancyTypeId: string | number;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { dateStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateStringToInteger } from '@cityssm/expressjs-server-js/dateTimeFns.js';
|
||||||
import { addOrUpdateLotOccupancyField } from "./addOrUpdateLotOccupancyField.js";
|
import { addOrUpdateLotOccupancyField } from './addOrUpdateLotOccupancyField.js';
|
||||||
import { deleteLotOccupancyField } from "./deleteLotOccupancyField.js";
|
import { deleteLotOccupancyField } from './deleteLotOccupancyField.js';
|
||||||
export function updateLotOccupancy(lotOccupancyForm, requestSession) {
|
export function updateLotOccupancy(lotOccupancyForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
|
|
@ -16,14 +16,14 @@ export function updateLotOccupancy(lotOccupancyForm, requestSession) {
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where lotOccupancyId = ?
|
where lotOccupancyId = ?
|
||||||
and recordDelete_timeMillis is null`)
|
and recordDelete_timeMillis is null`)
|
||||||
.run(lotOccupancyForm.occupancyTypeId, lotOccupancyForm.lotId === "" ? undefined : lotOccupancyForm.lotId, dateStringToInteger(lotOccupancyForm.occupancyStartDateString), lotOccupancyForm.occupancyEndDateString === ""
|
.run(lotOccupancyForm.occupancyTypeId, lotOccupancyForm.lotId === '' ? undefined : lotOccupancyForm.lotId, dateStringToInteger(lotOccupancyForm.occupancyStartDateString), lotOccupancyForm.occupancyEndDateString === ''
|
||||||
? undefined
|
? undefined
|
||||||
: dateStringToInteger(lotOccupancyForm.occupancyEndDateString), requestSession.user.userName, rightNowMillis, lotOccupancyForm.lotOccupancyId);
|
: dateStringToInteger(lotOccupancyForm.occupancyEndDateString), requestSession.user.userName, rightNowMillis, lotOccupancyForm.lotOccupancyId);
|
||||||
if (result.changes > 0) {
|
if (result.changes > 0) {
|
||||||
const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds || "").split(",");
|
const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds ?? '').split(',');
|
||||||
for (const occupancyTypeFieldId of occupancyTypeFieldIds) {
|
for (const occupancyTypeFieldId of occupancyTypeFieldIds) {
|
||||||
const lotOccupancyFieldValue = lotOccupancyForm["lotOccupancyFieldValue_" + occupancyTypeFieldId];
|
const lotOccupancyFieldValue = lotOccupancyForm['lotOccupancyFieldValue_' + occupancyTypeFieldId];
|
||||||
if (lotOccupancyFieldValue && lotOccupancyFieldValue !== "") {
|
if (lotOccupancyFieldValue && lotOccupancyFieldValue !== '') {
|
||||||
addOrUpdateLotOccupancyField({
|
addOrUpdateLotOccupancyField({
|
||||||
lotOccupancyId: lotOccupancyForm.lotOccupancyId,
|
lotOccupancyId: lotOccupancyForm.lotOccupancyId,
|
||||||
occupancyTypeFieldId,
|
occupancyTypeFieldId,
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,38 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import { dateStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateStringToInteger } from '@cityssm/expressjs-server-js/dateTimeFns.js'
|
||||||
|
|
||||||
import { addOrUpdateLotOccupancyField } from "./addOrUpdateLotOccupancyField.js";
|
import { addOrUpdateLotOccupancyField } from './addOrUpdateLotOccupancyField.js'
|
||||||
|
|
||||||
import { deleteLotOccupancyField } from "./deleteLotOccupancyField.js";
|
import { deleteLotOccupancyField } from './deleteLotOccupancyField.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateLotOccupancyForm {
|
interface UpdateLotOccupancyForm {
|
||||||
lotOccupancyId: string | number;
|
lotOccupancyId: string | number
|
||||||
occupancyTypeId: string | number;
|
occupancyTypeId: string | number
|
||||||
lotId: string | number;
|
lotId: string | number
|
||||||
|
|
||||||
occupancyStartDateString: string;
|
occupancyStartDateString: string
|
||||||
occupancyEndDateString: string;
|
occupancyEndDateString: string
|
||||||
|
|
||||||
occupancyTypeFieldIds?: string;
|
occupancyTypeFieldIds?: string
|
||||||
[lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown;
|
[lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateLotOccupancy(
|
export function updateLotOccupancy(
|
||||||
lotOccupancyForm: UpdateLotOccupancyForm,
|
lotOccupancyForm: UpdateLotOccupancyForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update LotOccupancies
|
`update LotOccupancies
|
||||||
set occupancyTypeId = ?,
|
set occupancyTypeId = ?,
|
||||||
lotId = ?,
|
lotId = ?,
|
||||||
occupancyStartDate = ?,
|
occupancyStartDate = ?,
|
||||||
|
|
@ -41,51 +41,53 @@ export function updateLotOccupancy(
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where lotOccupancyId = ?
|
where lotOccupancyId = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
|
)
|
||||||
|
.run(
|
||||||
|
lotOccupancyForm.occupancyTypeId,
|
||||||
|
lotOccupancyForm.lotId === '' ? undefined : lotOccupancyForm.lotId,
|
||||||
|
dateStringToInteger(lotOccupancyForm.occupancyStartDateString),
|
||||||
|
lotOccupancyForm.occupancyEndDateString === ''
|
||||||
|
? undefined
|
||||||
|
: dateStringToInteger(lotOccupancyForm.occupancyEndDateString),
|
||||||
|
requestSession.user!.userName,
|
||||||
|
rightNowMillis,
|
||||||
|
lotOccupancyForm.lotOccupancyId
|
||||||
|
)
|
||||||
|
|
||||||
|
if (result.changes > 0) {
|
||||||
|
const occupancyTypeFieldIds = (
|
||||||
|
lotOccupancyForm.occupancyTypeFieldIds ?? ''
|
||||||
|
).split(',')
|
||||||
|
|
||||||
|
for (const occupancyTypeFieldId of occupancyTypeFieldIds) {
|
||||||
|
const lotOccupancyFieldValue = lotOccupancyForm[
|
||||||
|
'lotOccupancyFieldValue_' + occupancyTypeFieldId
|
||||||
|
] as string
|
||||||
|
|
||||||
|
if (lotOccupancyFieldValue && lotOccupancyFieldValue !== '') {
|
||||||
|
addOrUpdateLotOccupancyField(
|
||||||
|
{
|
||||||
|
lotOccupancyId: lotOccupancyForm.lotOccupancyId,
|
||||||
|
occupancyTypeFieldId,
|
||||||
|
lotOccupancyFieldValue
|
||||||
|
},
|
||||||
|
requestSession,
|
||||||
|
database
|
||||||
)
|
)
|
||||||
.run(
|
} else {
|
||||||
lotOccupancyForm.occupancyTypeId,
|
deleteLotOccupancyField(
|
||||||
lotOccupancyForm.lotId === "" ? undefined : lotOccupancyForm.lotId,
|
lotOccupancyForm.lotOccupancyId,
|
||||||
dateStringToInteger(lotOccupancyForm.occupancyStartDateString),
|
occupancyTypeFieldId,
|
||||||
lotOccupancyForm.occupancyEndDateString === ""
|
requestSession,
|
||||||
? undefined
|
database
|
||||||
: dateStringToInteger(lotOccupancyForm.occupancyEndDateString),
|
)
|
||||||
requestSession.user.userName,
|
}
|
||||||
rightNowMillis,
|
|
||||||
lotOccupancyForm.lotOccupancyId
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result.changes > 0) {
|
|
||||||
const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds || "").split(",");
|
|
||||||
|
|
||||||
for (const occupancyTypeFieldId of occupancyTypeFieldIds) {
|
|
||||||
const lotOccupancyFieldValue = lotOccupancyForm[
|
|
||||||
"lotOccupancyFieldValue_" + occupancyTypeFieldId
|
|
||||||
] as string;
|
|
||||||
|
|
||||||
if (lotOccupancyFieldValue && lotOccupancyFieldValue !== "") {
|
|
||||||
addOrUpdateLotOccupancyField(
|
|
||||||
{
|
|
||||||
lotOccupancyId: lotOccupancyForm.lotOccupancyId,
|
|
||||||
occupancyTypeFieldId,
|
|
||||||
lotOccupancyFieldValue
|
|
||||||
},
|
|
||||||
requestSession,
|
|
||||||
database
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
deleteLotOccupancyField(
|
|
||||||
lotOccupancyForm.lotOccupancyId,
|
|
||||||
occupancyTypeFieldId,
|
|
||||||
requestSession,
|
|
||||||
database
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateLotOccupancy;
|
export default updateLotOccupancy
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateLotOccupancyCommentForm {
|
interface UpdateLotOccupancyCommentForm {
|
||||||
lotOccupancyCommentId: string | number;
|
lotOccupancyCommentId: string | number;
|
||||||
lotOccupancyCommentDateString: string;
|
lotOccupancyCommentDateString: string;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { dateStringToInteger, timeStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateStringToInteger, timeStringToInteger } from '@cityssm/expressjs-server-js/dateTimeFns.js';
|
||||||
export function updateLotOccupancyComment(commentForm, requestSession) {
|
export function updateLotOccupancyComment(commentForm, requestSession) {
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,32 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
dateStringToInteger,
|
dateStringToInteger,
|
||||||
timeStringToInteger
|
timeStringToInteger
|
||||||
} from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
} from '@cityssm/expressjs-server-js/dateTimeFns.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateLotOccupancyCommentForm {
|
interface UpdateLotOccupancyCommentForm {
|
||||||
lotOccupancyCommentId: string | number;
|
lotOccupancyCommentId: string | number
|
||||||
lotOccupancyCommentDateString: string;
|
lotOccupancyCommentDateString: string
|
||||||
lotOccupancyCommentTimeString: string;
|
lotOccupancyCommentTimeString: string
|
||||||
lotOccupancyComment: string;
|
lotOccupancyComment: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateLotOccupancyComment(
|
export function updateLotOccupancyComment(
|
||||||
commentForm: UpdateLotOccupancyCommentForm,
|
commentForm: UpdateLotOccupancyCommentForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update LotOccupancyComments
|
`update LotOccupancyComments
|
||||||
set lotOccupancyCommentDate = ?,
|
set lotOccupancyCommentDate = ?,
|
||||||
lotOccupancyCommentTime = ?,
|
lotOccupancyCommentTime = ?,
|
||||||
lotOccupancyComment = ?,
|
lotOccupancyComment = ?,
|
||||||
|
|
@ -34,19 +34,19 @@ export function updateLotOccupancyComment(
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and lotOccupancyCommentId = ?`
|
and lotOccupancyCommentId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
dateStringToInteger(commentForm.lotOccupancyCommentDateString),
|
dateStringToInteger(commentForm.lotOccupancyCommentDateString),
|
||||||
timeStringToInteger(commentForm.lotOccupancyCommentTimeString),
|
timeStringToInteger(commentForm.lotOccupancyCommentTimeString),
|
||||||
commentForm.lotOccupancyComment,
|
commentForm.lotOccupancyComment,
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
commentForm.lotOccupancyCommentId
|
commentForm.lotOccupancyCommentId
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateLotOccupancyComment;
|
export default updateLotOccupancyComment
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateLotOccupancyOccupantForm {
|
interface UpdateLotOccupancyOccupantForm {
|
||||||
lotOccupancyId: string | number;
|
lotOccupancyId: string | number;
|
||||||
lotOccupantIndex: string | number;
|
lotOccupantIndex: string | number;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
export function updateLotOccupancyOccupant(lotOccupancyOccupantForm, requestSession) {
|
export function updateLotOccupancyOccupant(lotOccupancyOccupantForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,35 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateLotOccupancyOccupantForm {
|
interface UpdateLotOccupancyOccupantForm {
|
||||||
lotOccupancyId: string | number;
|
lotOccupancyId: string | number
|
||||||
lotOccupantIndex: string | number;
|
lotOccupantIndex: string | number
|
||||||
lotOccupantTypeId: string | number;
|
lotOccupantTypeId: string | number
|
||||||
occupantName: string;
|
occupantName: string
|
||||||
occupantAddress1: string;
|
occupantAddress1: string
|
||||||
occupantAddress2: string;
|
occupantAddress2: string
|
||||||
occupantCity: string;
|
occupantCity: string
|
||||||
occupantProvince: string;
|
occupantProvince: string
|
||||||
occupantPostalCode: string;
|
occupantPostalCode: string
|
||||||
occupantPhoneNumber: string;
|
occupantPhoneNumber: string
|
||||||
occupantEmailAddress: string;
|
occupantEmailAddress: string
|
||||||
occupantComment: string;
|
occupantComment: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateLotOccupancyOccupant(
|
export function updateLotOccupancyOccupant(
|
||||||
lotOccupancyOccupantForm: UpdateLotOccupancyOccupantForm,
|
lotOccupancyOccupantForm: UpdateLotOccupancyOccupantForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const results = database
|
const results = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update LotOccupancyOccupants
|
`update LotOccupancyOccupants
|
||||||
set occupantName = ?,
|
set occupantName = ?,
|
||||||
occupantAddress1 = ?,
|
occupantAddress1 = ?,
|
||||||
occupantAddress2 = ?,
|
occupantAddress2 = ?,
|
||||||
|
|
@ -45,27 +45,27 @@ export function updateLotOccupancyOccupant(
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and lotOccupancyId = ?
|
and lotOccupancyId = ?
|
||||||
and lotOccupantIndex = ?`
|
and lotOccupantIndex = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
lotOccupancyOccupantForm.occupantName,
|
lotOccupancyOccupantForm.occupantName,
|
||||||
lotOccupancyOccupantForm.occupantAddress1,
|
lotOccupancyOccupantForm.occupantAddress1,
|
||||||
lotOccupancyOccupantForm.occupantAddress2,
|
lotOccupancyOccupantForm.occupantAddress2,
|
||||||
lotOccupancyOccupantForm.occupantCity,
|
lotOccupancyOccupantForm.occupantCity,
|
||||||
lotOccupancyOccupantForm.occupantProvince,
|
lotOccupancyOccupantForm.occupantProvince,
|
||||||
lotOccupancyOccupantForm.occupantPostalCode,
|
lotOccupancyOccupantForm.occupantPostalCode,
|
||||||
lotOccupancyOccupantForm.occupantPhoneNumber,
|
lotOccupancyOccupantForm.occupantPhoneNumber,
|
||||||
lotOccupancyOccupantForm.occupantEmailAddress,
|
lotOccupancyOccupantForm.occupantEmailAddress,
|
||||||
lotOccupancyOccupantForm.occupantComment,
|
lotOccupancyOccupantForm.occupantComment,
|
||||||
lotOccupancyOccupantForm.lotOccupantTypeId,
|
lotOccupancyOccupantForm.lotOccupantTypeId,
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
lotOccupancyOccupantForm.lotOccupancyId,
|
lotOccupancyOccupantForm.lotOccupancyId,
|
||||||
lotOccupancyOccupantForm.lotOccupantIndex
|
lotOccupancyOccupantForm.lotOccupantIndex
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return results.changes > 0;
|
return results.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateLotOccupancyOccupant;
|
export default updateLotOccupancyOccupant
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateLotOccupantTypeForm {
|
interface UpdateLotOccupantTypeForm {
|
||||||
lotOccupantTypeId: number | string;
|
lotOccupantTypeId: number | string;
|
||||||
lotOccupantType: string;
|
lotOccupantType: string;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { clearCacheByTableName } from "../functions.cache.js";
|
import { clearCacheByTableName } from '../functions.cache.js';
|
||||||
export function updateLotOccupantType(lotOccupantTypeForm, requestSession) {
|
export function updateLotOccupantType(lotOccupantTypeForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
|
|
@ -12,9 +12,9 @@ export function updateLotOccupantType(lotOccupantTypeForm, requestSession) {
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where lotOccupantTypeId = ?
|
where lotOccupantTypeId = ?
|
||||||
and recordDelete_timeMillis is null`)
|
and recordDelete_timeMillis is null`)
|
||||||
.run(lotOccupantTypeForm.lotOccupantType, lotOccupantTypeForm.fontAwesomeIconClass || "", requestSession.user.userName, rightNowMillis, lotOccupantTypeForm.lotOccupantTypeId);
|
.run(lotOccupantTypeForm.lotOccupantType, lotOccupantTypeForm.fontAwesomeIconClass ?? '', requestSession.user.userName, rightNowMillis, lotOccupantTypeForm.lotOccupantTypeId);
|
||||||
database.close();
|
database.close();
|
||||||
clearCacheByTableName("LotOccupantTypes");
|
clearCacheByTableName('LotOccupantTypes');
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
export default updateLotOccupantType;
|
export default updateLotOccupantType;
|
||||||
|
|
|
||||||
|
|
@ -1,48 +1,48 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import { clearCacheByTableName } from "../functions.cache.js";
|
import { clearCacheByTableName } from '../functions.cache.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateLotOccupantTypeForm {
|
interface UpdateLotOccupantTypeForm {
|
||||||
lotOccupantTypeId: number | string;
|
lotOccupantTypeId: number | string
|
||||||
lotOccupantType: string;
|
lotOccupantType: string
|
||||||
fontAwesomeIconClass?: string;
|
fontAwesomeIconClass?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateLotOccupantType(
|
export function updateLotOccupantType(
|
||||||
lotOccupantTypeForm: UpdateLotOccupantTypeForm,
|
lotOccupantTypeForm: UpdateLotOccupantTypeForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update LotOccupantTypes
|
`update LotOccupantTypes
|
||||||
set lotOccupantType = ?,
|
set lotOccupantType = ?,
|
||||||
fontAwesomeIconClass = ?,
|
fontAwesomeIconClass = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where lotOccupantTypeId = ?
|
where lotOccupantTypeId = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
lotOccupantTypeForm.lotOccupantType,
|
lotOccupantTypeForm.lotOccupantType,
|
||||||
lotOccupantTypeForm.fontAwesomeIconClass || "",
|
lotOccupantTypeForm.fontAwesomeIconClass ?? '',
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
lotOccupantTypeForm.lotOccupantTypeId
|
lotOccupantTypeForm.lotOccupantTypeId
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
clearCacheByTableName("LotOccupantTypes");
|
clearCacheByTableName('LotOccupantTypes')
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateLotOccupantType;
|
export default updateLotOccupantType
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateLotTypeFieldForm {
|
interface UpdateLotTypeFieldForm {
|
||||||
lotTypeFieldId: number | string;
|
lotTypeFieldId: number | string;
|
||||||
lotTypeField: string;
|
lotTypeField: string;
|
||||||
isRequired: "0" | "1";
|
isRequired: '0' | '1';
|
||||||
minimumLength?: string;
|
minimumLength?: string;
|
||||||
maximumLength?: string;
|
maximumLength?: string;
|
||||||
pattern?: string;
|
pattern?: string;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { clearCacheByTableName } from "../functions.cache.js";
|
import { clearCacheByTableName } from '../functions.cache.js';
|
||||||
export function updateLotTypeField(lotTypeFieldForm, requestSession) {
|
export function updateLotTypeField(lotTypeFieldForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
|
|
@ -16,9 +16,9 @@ export function updateLotTypeField(lotTypeFieldForm, requestSession) {
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where lotTypeFieldId = ?
|
where lotTypeFieldId = ?
|
||||||
and recordDelete_timeMillis is null`)
|
and recordDelete_timeMillis is null`)
|
||||||
.run(lotTypeFieldForm.lotTypeField, Number.parseInt(lotTypeFieldForm.isRequired, 10), lotTypeFieldForm.minimumLength || 0, lotTypeFieldForm.maximumLength || 100, lotTypeFieldForm.pattern || "", lotTypeFieldForm.lotTypeFieldValues, requestSession.user.userName, rightNowMillis, lotTypeFieldForm.lotTypeFieldId);
|
.run(lotTypeFieldForm.lotTypeField, Number.parseInt(lotTypeFieldForm.isRequired, 10), lotTypeFieldForm.minimumLength ?? 0, lotTypeFieldForm.maximumLength ?? 100, lotTypeFieldForm.pattern ?? '', lotTypeFieldForm.lotTypeFieldValues, requestSession.user.userName, rightNowMillis, lotTypeFieldForm.lotTypeFieldId);
|
||||||
database.close();
|
database.close();
|
||||||
clearCacheByTableName("LotTypeFields");
|
clearCacheByTableName('LotTypeFields');
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
export default updateLotTypeField;
|
export default updateLotTypeField;
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,32 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import { clearCacheByTableName } from "../functions.cache.js";
|
import { clearCacheByTableName } from '../functions.cache.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateLotTypeFieldForm {
|
interface UpdateLotTypeFieldForm {
|
||||||
lotTypeFieldId: number | string;
|
lotTypeFieldId: number | string
|
||||||
lotTypeField: string;
|
lotTypeField: string
|
||||||
isRequired: "0" | "1";
|
isRequired: '0' | '1'
|
||||||
minimumLength?: string;
|
minimumLength?: string
|
||||||
maximumLength?: string;
|
maximumLength?: string
|
||||||
pattern?: string;
|
pattern?: string
|
||||||
lotTypeFieldValues: string;
|
lotTypeFieldValues: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateLotTypeField(
|
export function updateLotTypeField(
|
||||||
lotTypeFieldForm: UpdateLotTypeFieldForm,
|
lotTypeFieldForm: UpdateLotTypeFieldForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update LotTypeFields
|
`update LotTypeFields
|
||||||
set lotTypeField = ?,
|
set lotTypeField = ?,
|
||||||
isRequired = ?,
|
isRequired = ?,
|
||||||
minimumLength = ?,
|
minimumLength = ?,
|
||||||
|
|
@ -37,24 +37,24 @@ export function updateLotTypeField(
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where lotTypeFieldId = ?
|
where lotTypeFieldId = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
lotTypeFieldForm.lotTypeField,
|
lotTypeFieldForm.lotTypeField,
|
||||||
Number.parseInt(lotTypeFieldForm.isRequired, 10),
|
Number.parseInt(lotTypeFieldForm.isRequired, 10),
|
||||||
lotTypeFieldForm.minimumLength || 0,
|
lotTypeFieldForm.minimumLength ?? 0,
|
||||||
lotTypeFieldForm.maximumLength || 100,
|
lotTypeFieldForm.maximumLength ?? 100,
|
||||||
lotTypeFieldForm.pattern || "",
|
lotTypeFieldForm.pattern ?? '',
|
||||||
lotTypeFieldForm.lotTypeFieldValues,
|
lotTypeFieldForm.lotTypeFieldValues,
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
lotTypeFieldForm.lotTypeFieldId
|
lotTypeFieldForm.lotTypeFieldId
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
clearCacheByTableName("LotTypeFields");
|
clearCacheByTableName('LotTypeFields')
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateLotTypeField;
|
export default updateLotTypeField
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateMapForm {
|
interface UpdateMapForm {
|
||||||
mapId: string;
|
mapId: string;
|
||||||
mapName: string;
|
mapName: string;
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,26 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
export function updateMap(mapForm, requestSession) {
|
export function updateMap(mapForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update Maps
|
.prepare(`update Maps
|
||||||
set mapName = ?,
|
set mapName = ?,
|
||||||
mapDescription = ?,
|
mapDescription = ?,
|
||||||
mapSVG = ?,
|
mapSVG = ?,
|
||||||
mapLatitude = ?,
|
mapLatitude = ?,
|
||||||
mapLongitude = ?,
|
mapLongitude = ?,
|
||||||
mapAddress1 = ?,
|
mapAddress1 = ?,
|
||||||
mapAddress2 = ?,
|
mapAddress2 = ?,
|
||||||
mapCity = ?,
|
mapCity = ?,
|
||||||
mapProvince = ?,
|
mapProvince = ?,
|
||||||
mapPostalCode = ?,
|
mapPostalCode = ?,
|
||||||
mapPhoneNumber = ?,
|
mapPhoneNumber = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where mapId = ?
|
where mapId = ?
|
||||||
and recordDelete_timeMillis is null`)
|
and recordDelete_timeMillis is null`)
|
||||||
.run(mapForm.mapName, mapForm.mapDescription, mapForm.mapSVG, mapForm.mapLatitude === "" ? undefined : mapForm.mapLatitude, mapForm.mapLongitude === "" ? undefined : mapForm.mapLongitude, mapForm.mapAddress1, mapForm.mapAddress2, mapForm.mapCity, mapForm.mapProvince, mapForm.mapPostalCode, mapForm.mapPhoneNumber, requestSession.user.userName, rightNowMillis, mapForm.mapId);
|
.run(mapForm.mapName, mapForm.mapDescription, mapForm.mapSVG, mapForm.mapLatitude === '' ? undefined : mapForm.mapLatitude, mapForm.mapLongitude === '' ? undefined : mapForm.mapLongitude, mapForm.mapAddress1, mapForm.mapAddress2, mapForm.mapCity, mapForm.mapProvince, mapForm.mapPostalCode, mapForm.mapPhoneNumber, requestSession.user.userName, rightNowMillis, mapForm.mapId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,71 +1,71 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateMapForm {
|
interface UpdateMapForm {
|
||||||
mapId: string;
|
mapId: string
|
||||||
mapName: string;
|
mapName: string
|
||||||
mapDescription: string;
|
mapDescription: string
|
||||||
mapSVG: string;
|
mapSVG: string
|
||||||
mapLatitude: string;
|
mapLatitude: string
|
||||||
mapLongitude: string;
|
mapLongitude: string
|
||||||
mapAddress1: string;
|
mapAddress1: string
|
||||||
mapAddress2: string;
|
mapAddress2: string
|
||||||
mapCity: string;
|
mapCity: string
|
||||||
mapProvince: string;
|
mapProvince: string
|
||||||
mapPostalCode: string;
|
mapPostalCode: string
|
||||||
mapPhoneNumber: string;
|
mapPhoneNumber: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateMap(
|
export function updateMap(
|
||||||
mapForm: UpdateMapForm,
|
mapForm: UpdateMapForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update Maps
|
`update Maps
|
||||||
set mapName = ?,
|
set mapName = ?,
|
||||||
mapDescription = ?,
|
mapDescription = ?,
|
||||||
mapSVG = ?,
|
mapSVG = ?,
|
||||||
mapLatitude = ?,
|
mapLatitude = ?,
|
||||||
mapLongitude = ?,
|
mapLongitude = ?,
|
||||||
mapAddress1 = ?,
|
mapAddress1 = ?,
|
||||||
mapAddress2 = ?,
|
mapAddress2 = ?,
|
||||||
mapCity = ?,
|
mapCity = ?,
|
||||||
mapProvince = ?,
|
mapProvince = ?,
|
||||||
mapPostalCode = ?,
|
mapPostalCode = ?,
|
||||||
mapPhoneNumber = ?,
|
mapPhoneNumber = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where mapId = ?
|
where mapId = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
mapForm.mapName,
|
mapForm.mapName,
|
||||||
mapForm.mapDescription,
|
mapForm.mapDescription,
|
||||||
mapForm.mapSVG,
|
mapForm.mapSVG,
|
||||||
mapForm.mapLatitude === "" ? undefined : mapForm.mapLatitude,
|
mapForm.mapLatitude === '' ? undefined : mapForm.mapLatitude,
|
||||||
mapForm.mapLongitude === "" ? undefined : mapForm.mapLongitude,
|
mapForm.mapLongitude === '' ? undefined : mapForm.mapLongitude,
|
||||||
mapForm.mapAddress1,
|
mapForm.mapAddress1,
|
||||||
mapForm.mapAddress2,
|
mapForm.mapAddress2,
|
||||||
mapForm.mapCity,
|
mapForm.mapCity,
|
||||||
mapForm.mapProvince,
|
mapForm.mapProvince,
|
||||||
mapForm.mapPostalCode,
|
mapForm.mapPostalCode,
|
||||||
mapForm.mapPhoneNumber,
|
mapForm.mapPhoneNumber,
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
mapForm.mapId
|
mapForm.mapId
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateMap;
|
export default updateMap
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateOccupancyTypeFieldForm {
|
interface UpdateOccupancyTypeFieldForm {
|
||||||
occupancyTypeFieldId: number | string;
|
occupancyTypeFieldId: number | string;
|
||||||
occupancyTypeField: string;
|
occupancyTypeField: string;
|
||||||
isRequired: "0" | "1";
|
isRequired: '0' | '1';
|
||||||
minimumLength?: string;
|
minimumLength?: string;
|
||||||
maximumLength?: string;
|
maximumLength?: string;
|
||||||
pattern?: string;
|
pattern?: string;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { clearCacheByTableName } from "../functions.cache.js";
|
import { clearCacheByTableName } from '../functions.cache.js';
|
||||||
export function updateOccupancyTypeField(occupancyTypeFieldForm, requestSession) {
|
export function updateOccupancyTypeField(occupancyTypeFieldForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
|
|
@ -16,9 +16,9 @@ export function updateOccupancyTypeField(occupancyTypeFieldForm, requestSession)
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where occupancyTypeFieldId = ?
|
where occupancyTypeFieldId = ?
|
||||||
and recordDelete_timeMillis is null`)
|
and recordDelete_timeMillis is null`)
|
||||||
.run(occupancyTypeFieldForm.occupancyTypeField, Number.parseInt(occupancyTypeFieldForm.isRequired, 10), occupancyTypeFieldForm.minimumLength || 0, occupancyTypeFieldForm.maximumLength || 100, occupancyTypeFieldForm.pattern || "", occupancyTypeFieldForm.occupancyTypeFieldValues, requestSession.user.userName, rightNowMillis, occupancyTypeFieldForm.occupancyTypeFieldId);
|
.run(occupancyTypeFieldForm.occupancyTypeField, Number.parseInt(occupancyTypeFieldForm.isRequired, 10), occupancyTypeFieldForm.minimumLength ?? 0, occupancyTypeFieldForm.maximumLength ?? 100, occupancyTypeFieldForm.pattern ?? '', occupancyTypeFieldForm.occupancyTypeFieldValues, requestSession.user.userName, rightNowMillis, occupancyTypeFieldForm.occupancyTypeFieldId);
|
||||||
database.close();
|
database.close();
|
||||||
clearCacheByTableName("OccupancyTypeFields");
|
clearCacheByTableName('OccupancyTypeFields');
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
export default updateOccupancyTypeField;
|
export default updateOccupancyTypeField;
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,32 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import { clearCacheByTableName } from "../functions.cache.js";
|
import { clearCacheByTableName } from '../functions.cache.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateOccupancyTypeFieldForm {
|
interface UpdateOccupancyTypeFieldForm {
|
||||||
occupancyTypeFieldId: number | string;
|
occupancyTypeFieldId: number | string
|
||||||
occupancyTypeField: string;
|
occupancyTypeField: string
|
||||||
isRequired: "0" | "1";
|
isRequired: '0' | '1'
|
||||||
minimumLength?: string;
|
minimumLength?: string
|
||||||
maximumLength?: string;
|
maximumLength?: string
|
||||||
pattern?: string;
|
pattern?: string
|
||||||
occupancyTypeFieldValues: string;
|
occupancyTypeFieldValues: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateOccupancyTypeField(
|
export function updateOccupancyTypeField(
|
||||||
occupancyTypeFieldForm: UpdateOccupancyTypeFieldForm,
|
occupancyTypeFieldForm: UpdateOccupancyTypeFieldForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update OccupancyTypeFields
|
`update OccupancyTypeFields
|
||||||
set occupancyTypeField = ?,
|
set occupancyTypeField = ?,
|
||||||
isRequired = ?,
|
isRequired = ?,
|
||||||
minimumLength = ?,
|
minimumLength = ?,
|
||||||
|
|
@ -37,24 +37,24 @@ export function updateOccupancyTypeField(
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where occupancyTypeFieldId = ?
|
where occupancyTypeFieldId = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
occupancyTypeFieldForm.occupancyTypeField,
|
occupancyTypeFieldForm.occupancyTypeField,
|
||||||
Number.parseInt(occupancyTypeFieldForm.isRequired, 10),
|
Number.parseInt(occupancyTypeFieldForm.isRequired, 10),
|
||||||
occupancyTypeFieldForm.minimumLength || 0,
|
occupancyTypeFieldForm.minimumLength ?? 0,
|
||||||
occupancyTypeFieldForm.maximumLength || 100,
|
occupancyTypeFieldForm.maximumLength ?? 100,
|
||||||
occupancyTypeFieldForm.pattern || "",
|
occupancyTypeFieldForm.pattern ?? '',
|
||||||
occupancyTypeFieldForm.occupancyTypeFieldValues,
|
occupancyTypeFieldForm.occupancyTypeFieldValues,
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
occupancyTypeFieldForm.occupancyTypeFieldId
|
occupancyTypeFieldForm.occupancyTypeFieldId
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
clearCacheByTableName("OccupancyTypeFields");
|
clearCacheByTableName('OccupancyTypeFields')
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateOccupancyTypeField;
|
export default updateOccupancyTypeField
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
declare type RecordTable = "FeeCategories" | "LotStatuses" | "LotTypes" | "OccupancyTypes" | "WorkOrderMilestoneTypes" | "WorkOrderTypes";
|
declare type RecordTable = 'FeeCategories' | 'LotStatuses' | 'LotTypes' | 'OccupancyTypes' | 'WorkOrderMilestoneTypes' | 'WorkOrderTypes';
|
||||||
export declare function updateRecord(recordTable: RecordTable, recordId: number | string, recordName: string, requestSession: recordTypes.PartialSession): boolean;
|
export declare function updateRecord(recordTable: RecordTable, recordId: number | string, recordName: string, requestSession: recordTypes.PartialSession): boolean;
|
||||||
export {};
|
export {};
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { clearCacheByTableName } from "../functions.cache.js";
|
import { clearCacheByTableName } from '../functions.cache.js';
|
||||||
const recordNameIdColumns = new Map();
|
const recordNameIdColumns = new Map();
|
||||||
recordNameIdColumns.set("FeeCategories", ["feeCategory", "feeCategoryId"]);
|
recordNameIdColumns.set('FeeCategories', ['feeCategory', 'feeCategoryId']);
|
||||||
recordNameIdColumns.set("LotStatuses", ["lotStatus", "lotStatusId"]);
|
recordNameIdColumns.set('LotStatuses', ['lotStatus', 'lotStatusId']);
|
||||||
recordNameIdColumns.set("LotTypes", ["lotType", "lotTypeId"]);
|
recordNameIdColumns.set('LotTypes', ['lotType', 'lotTypeId']);
|
||||||
recordNameIdColumns.set("OccupancyTypes", ["occupancyType", "occupancyTypeId"]);
|
recordNameIdColumns.set('OccupancyTypes', ['occupancyType', 'occupancyTypeId']);
|
||||||
recordNameIdColumns.set("WorkOrderMilestoneTypes", ["workOrderMilestoneType", "workOrderMilestoneTypeId"]);
|
recordNameIdColumns.set('WorkOrderMilestoneTypes', [
|
||||||
recordNameIdColumns.set("WorkOrderTypes", ["workOrderType", "workOrderTypeId"]);
|
'workOrderMilestoneType',
|
||||||
|
'workOrderMilestoneTypeId'
|
||||||
|
]);
|
||||||
|
recordNameIdColumns.set('WorkOrderTypes', ['workOrderType', 'workOrderTypeId']);
|
||||||
export function updateRecord(recordTable, recordId, recordName, requestSession) {
|
export function updateRecord(recordTable, recordId, recordName, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,54 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import { clearCacheByTableName } from "../functions.cache.js";
|
import { clearCacheByTableName } from '../functions.cache.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
type RecordTable =
|
type RecordTable =
|
||||||
| "FeeCategories"
|
| 'FeeCategories'
|
||||||
| "LotStatuses"
|
| 'LotStatuses'
|
||||||
| "LotTypes"
|
| 'LotTypes'
|
||||||
| "OccupancyTypes"
|
| 'OccupancyTypes'
|
||||||
| "WorkOrderMilestoneTypes"
|
| 'WorkOrderMilestoneTypes'
|
||||||
| "WorkOrderTypes";
|
| 'WorkOrderTypes'
|
||||||
|
|
||||||
const recordNameIdColumns: Map<RecordTable, string[]> = new Map();
|
const recordNameIdColumns: Map<RecordTable, string[]> = new Map()
|
||||||
recordNameIdColumns.set("FeeCategories", ["feeCategory", "feeCategoryId"]);
|
recordNameIdColumns.set('FeeCategories', ['feeCategory', 'feeCategoryId'])
|
||||||
recordNameIdColumns.set("LotStatuses", ["lotStatus", "lotStatusId"]);
|
recordNameIdColumns.set('LotStatuses', ['lotStatus', 'lotStatusId'])
|
||||||
recordNameIdColumns.set("LotTypes", ["lotType", "lotTypeId"]);
|
recordNameIdColumns.set('LotTypes', ['lotType', 'lotTypeId'])
|
||||||
recordNameIdColumns.set("OccupancyTypes", ["occupancyType", "occupancyTypeId"]);
|
recordNameIdColumns.set('OccupancyTypes', ['occupancyType', 'occupancyTypeId'])
|
||||||
recordNameIdColumns.set("WorkOrderMilestoneTypes", ["workOrderMilestoneType", "workOrderMilestoneTypeId"]);
|
recordNameIdColumns.set('WorkOrderMilestoneTypes', [
|
||||||
recordNameIdColumns.set("WorkOrderTypes", ["workOrderType", "workOrderTypeId"]);
|
'workOrderMilestoneType',
|
||||||
|
'workOrderMilestoneTypeId'
|
||||||
|
])
|
||||||
|
recordNameIdColumns.set('WorkOrderTypes', ['workOrderType', 'workOrderTypeId'])
|
||||||
|
|
||||||
export function updateRecord(
|
export function updateRecord(
|
||||||
recordTable: RecordTable,
|
recordTable: RecordTable,
|
||||||
recordId: number | string,
|
recordId: number | string,
|
||||||
recordName: string,
|
recordName: string,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update ${recordTable}
|
`update ${recordTable}
|
||||||
set ${recordNameIdColumns.get(recordTable)[0]} = ?,
|
set ${recordNameIdColumns.get(recordTable)![0]} = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and ${recordNameIdColumns.get(recordTable)[1]} = ?`
|
and ${recordNameIdColumns.get(recordTable)![1]} = ?`
|
||||||
)
|
)
|
||||||
.run(recordName, requestSession.user.userName, rightNowMillis, recordId);
|
.run(recordName, requestSession.user!.userName, rightNowMillis, recordId)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
clearCacheByTableName(recordTable);
|
clearCacheByTableName(recordTable)
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateWorkOrderForm {
|
interface UpdateWorkOrderForm {
|
||||||
workOrderId: string;
|
workOrderId: string;
|
||||||
workOrderNumber: string;
|
workOrderNumber: string;
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
import { dateStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateStringToInteger } from '@cityssm/expressjs-server-js/dateTimeFns.js';
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
export function updateWorkOrder(workOrderForm, requestSession) {
|
export function updateWorkOrder(workOrderForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(`update WorkOrders
|
.prepare(`update WorkOrders
|
||||||
set workOrderNumber = ?,
|
set workOrderNumber = ?,
|
||||||
workOrderTypeId = ?,
|
workOrderTypeId = ?,
|
||||||
workOrderDescription = ?,
|
workOrderDescription = ?,
|
||||||
workOrderOpenDate = ?,
|
workOrderOpenDate = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and recordDelete_timeMillis is null`)
|
and recordDelete_timeMillis is null`)
|
||||||
.run(workOrderForm.workOrderNumber, workOrderForm.workOrderTypeId, workOrderForm.workOrderDescription, dateStringToInteger(workOrderForm.workOrderOpenDateString), requestSession.user.userName, rightNowMillis, workOrderForm.workOrderId);
|
.run(workOrderForm.workOrderNumber, workOrderForm.workOrderTypeId, workOrderForm.workOrderDescription, dateStringToInteger(workOrderForm.workOrderOpenDateString), requestSession.user.userName, rightNowMillis, workOrderForm.workOrderId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,51 @@
|
||||||
import { dateStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateStringToInteger } from '@cityssm/expressjs-server-js/dateTimeFns.js'
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateWorkOrderForm {
|
interface UpdateWorkOrderForm {
|
||||||
workOrderId: string;
|
workOrderId: string
|
||||||
workOrderNumber: string;
|
workOrderNumber: string
|
||||||
workOrderTypeId: string;
|
workOrderTypeId: string
|
||||||
workOrderDescription: string;
|
workOrderDescription: string
|
||||||
workOrderOpenDateString: string;
|
workOrderOpenDateString: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateWorkOrder(
|
export function updateWorkOrder(
|
||||||
workOrderForm: UpdateWorkOrderForm,
|
workOrderForm: UpdateWorkOrderForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrders
|
`update WorkOrders
|
||||||
set workOrderNumber = ?,
|
set workOrderNumber = ?,
|
||||||
workOrderTypeId = ?,
|
workOrderTypeId = ?,
|
||||||
workOrderDescription = ?,
|
workOrderDescription = ?,
|
||||||
workOrderOpenDate = ?,
|
workOrderOpenDate = ?,
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where workOrderId = ?
|
where workOrderId = ?
|
||||||
and recordDelete_timeMillis is null`
|
and recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
workOrderForm.workOrderNumber,
|
workOrderForm.workOrderNumber,
|
||||||
workOrderForm.workOrderTypeId,
|
workOrderForm.workOrderTypeId,
|
||||||
workOrderForm.workOrderDescription,
|
workOrderForm.workOrderDescription,
|
||||||
dateStringToInteger(workOrderForm.workOrderOpenDateString),
|
dateStringToInteger(workOrderForm.workOrderOpenDateString),
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
workOrderForm.workOrderId
|
workOrderForm.workOrderId
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateWorkOrder;
|
export default updateWorkOrder
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateWorkOrderCommentForm {
|
interface UpdateWorkOrderCommentForm {
|
||||||
workOrderCommentId: string | number;
|
workOrderCommentId: string | number;
|
||||||
workOrderCommentDateString: string;
|
workOrderCommentDateString: string;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { dateStringToInteger, timeStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateStringToInteger, timeStringToInteger } from '@cityssm/expressjs-server-js/dateTimeFns.js';
|
||||||
export function updateWorkOrderComment(commentForm, requestSession) {
|
export function updateWorkOrderComment(commentForm, requestSession) {
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now();
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,32 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
dateStringToInteger,
|
dateStringToInteger,
|
||||||
timeStringToInteger
|
timeStringToInteger
|
||||||
} from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
} from '@cityssm/expressjs-server-js/dateTimeFns.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateWorkOrderCommentForm {
|
interface UpdateWorkOrderCommentForm {
|
||||||
workOrderCommentId: string | number;
|
workOrderCommentId: string | number
|
||||||
workOrderCommentDateString: string;
|
workOrderCommentDateString: string
|
||||||
workOrderCommentTimeString: string;
|
workOrderCommentTimeString: string
|
||||||
workOrderComment: string;
|
workOrderComment: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateWorkOrderComment(
|
export function updateWorkOrderComment(
|
||||||
commentForm: UpdateWorkOrderCommentForm,
|
commentForm: UpdateWorkOrderCommentForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const rightNowMillis = Date.now();
|
const rightNowMillis = Date.now()
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderComments
|
`update WorkOrderComments
|
||||||
set workOrderCommentDate = ?,
|
set workOrderCommentDate = ?,
|
||||||
workOrderCommentTime = ?,
|
workOrderCommentTime = ?,
|
||||||
workOrderComment = ?,
|
workOrderComment = ?,
|
||||||
|
|
@ -34,19 +34,19 @@ export function updateWorkOrderComment(
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where recordDelete_timeMillis is null
|
where recordDelete_timeMillis is null
|
||||||
and workOrderCommentId = ?`
|
and workOrderCommentId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
dateStringToInteger(commentForm.workOrderCommentDateString),
|
dateStringToInteger(commentForm.workOrderCommentDateString),
|
||||||
timeStringToInteger(commentForm.workOrderCommentTimeString),
|
timeStringToInteger(commentForm.workOrderCommentTimeString),
|
||||||
commentForm.workOrderComment,
|
commentForm.workOrderComment,
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNowMillis,
|
rightNowMillis,
|
||||||
commentForm.workOrderCommentId
|
commentForm.workOrderCommentId
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateWorkOrderComment;
|
export default updateWorkOrderComment
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes';
|
||||||
interface UpdateWorkOrderMilestoneForm {
|
interface UpdateWorkOrderMilestoneForm {
|
||||||
workOrderMilestoneId: string | number;
|
workOrderMilestoneId: string | number;
|
||||||
workOrderMilestoneTypeId?: number | string;
|
workOrderMilestoneTypeId: number | string;
|
||||||
workOrderMilestoneDateString: string;
|
workOrderMilestoneDateString: string;
|
||||||
workOrderMilestoneTimeString?: string;
|
workOrderMilestoneTimeString?: string;
|
||||||
workOrderMilestoneDescription: string;
|
workOrderMilestoneDescription: string;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3';
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js';
|
||||||
import { dateStringToInteger, timeStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateStringToInteger, timeStringToInteger } from '@cityssm/expressjs-server-js/dateTimeFns.js';
|
||||||
export function updateWorkOrderMilestone(milestoneForm, requestSession) {
|
export function updateWorkOrderMilestone(milestoneForm, requestSession) {
|
||||||
const rightNow = new Date();
|
const rightNow = new Date();
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
@ -13,7 +13,7 @@ export function updateWorkOrderMilestone(milestoneForm, requestSession) {
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where workOrderMilestoneId = ?`)
|
where workOrderMilestoneId = ?`)
|
||||||
.run(milestoneForm.workOrderMilestoneTypeId || undefined, dateStringToInteger(milestoneForm.workOrderMilestoneDateString), milestoneForm.workOrderMilestoneTimeString
|
.run(milestoneForm.workOrderMilestoneTypeId === '' ? undefined : milestoneForm.workOrderMilestoneTypeId, dateStringToInteger(milestoneForm.workOrderMilestoneDateString), milestoneForm.workOrderMilestoneTimeString
|
||||||
? timeStringToInteger(milestoneForm.workOrderMilestoneTimeString)
|
? timeStringToInteger(milestoneForm.workOrderMilestoneTimeString)
|
||||||
: 0, milestoneForm.workOrderMilestoneDescription, requestSession.user.userName, rightNow.getTime(), milestoneForm.workOrderMilestoneId);
|
: 0, milestoneForm.workOrderMilestoneDescription, requestSession.user.userName, rightNow.getTime(), milestoneForm.workOrderMilestoneId);
|
||||||
database.close();
|
database.close();
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,33 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from 'better-sqlite3'
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from '../../data/databasePaths.js'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
dateStringToInteger,
|
dateStringToInteger,
|
||||||
timeStringToInteger
|
timeStringToInteger
|
||||||
} from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
} from '@cityssm/expressjs-server-js/dateTimeFns.js'
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from '../../types/recordTypes'
|
||||||
|
|
||||||
interface UpdateWorkOrderMilestoneForm {
|
interface UpdateWorkOrderMilestoneForm {
|
||||||
workOrderMilestoneId: string | number;
|
workOrderMilestoneId: string | number
|
||||||
workOrderMilestoneTypeId?: number | string;
|
workOrderMilestoneTypeId: number | string
|
||||||
workOrderMilestoneDateString: string;
|
workOrderMilestoneDateString: string
|
||||||
workOrderMilestoneTimeString?: string;
|
workOrderMilestoneTimeString?: string
|
||||||
workOrderMilestoneDescription: string;
|
workOrderMilestoneDescription: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateWorkOrderMilestone(
|
export function updateWorkOrderMilestone(
|
||||||
milestoneForm: UpdateWorkOrderMilestoneForm,
|
milestoneForm: UpdateWorkOrderMilestoneForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const rightNow = new Date();
|
const rightNow = new Date()
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath)
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderMilestones
|
`update WorkOrderMilestones
|
||||||
set workOrderMilestoneTypeId = ?,
|
set workOrderMilestoneTypeId = ?,
|
||||||
workOrderMilestoneDate = ?,
|
workOrderMilestoneDate = ?,
|
||||||
workOrderMilestoneTime = ?,
|
workOrderMilestoneTime = ?,
|
||||||
|
|
@ -35,23 +35,23 @@ export function updateWorkOrderMilestone(
|
||||||
recordUpdate_userName = ?,
|
recordUpdate_userName = ?,
|
||||||
recordUpdate_timeMillis = ?
|
recordUpdate_timeMillis = ?
|
||||||
where workOrderMilestoneId = ?`
|
where workOrderMilestoneId = ?`
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
milestoneForm.workOrderMilestoneTypeId || undefined,
|
milestoneForm.workOrderMilestoneTypeId === '' ? undefined : milestoneForm.workOrderMilestoneTypeId,
|
||||||
dateStringToInteger(milestoneForm.workOrderMilestoneDateString),
|
dateStringToInteger(milestoneForm.workOrderMilestoneDateString),
|
||||||
milestoneForm.workOrderMilestoneTimeString
|
milestoneForm.workOrderMilestoneTimeString
|
||||||
? timeStringToInteger(milestoneForm.workOrderMilestoneTimeString)
|
? timeStringToInteger(milestoneForm.workOrderMilestoneTimeString)
|
||||||
: 0,
|
: 0,
|
||||||
milestoneForm.workOrderMilestoneDescription,
|
milestoneForm.workOrderMilestoneDescription,
|
||||||
|
|
||||||
requestSession.user.userName,
|
requestSession.user!.userName,
|
||||||
rightNow.getTime(),
|
rightNow.getTime(),
|
||||||
milestoneForm.workOrderMilestoneId
|
milestoneForm.workOrderMilestoneId
|
||||||
);
|
)
|
||||||
|
|
||||||
database.close();
|
database.close()
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateWorkOrderMilestone;
|
export default updateWorkOrderMilestone
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import * as assert from "assert";
|
import * as assert from 'node:assert';
|
||||||
import { portNumber } from "./_globals.js";
|
import { portNumber } from './_globals.js';
|
||||||
import { exec } from "node:child_process";
|
import { exec } from 'node:child_process';
|
||||||
import * as http from "node:http";
|
import * as http from 'node:http';
|
||||||
import { app } from "../app.js";
|
import { app } from '../app.js';
|
||||||
describe("lot-occupancy-system", () => {
|
describe('lot-occupancy-system', () => {
|
||||||
const httpServer = http.createServer(app);
|
const httpServer = http.createServer(app);
|
||||||
let serverStarted = false;
|
let serverStarted = false;
|
||||||
before(() => {
|
before(() => {
|
||||||
httpServer.listen(portNumber);
|
httpServer.listen(portNumber);
|
||||||
httpServer.on("listening", () => {
|
httpServer.on('listening', () => {
|
||||||
serverStarted = true;
|
serverStarted = true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -19,24 +19,24 @@ describe("lot-occupancy-system", () => {
|
||||||
catch {
|
catch {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
it("Ensure server starts on port " + portNumber.toString(), () => {
|
it('Ensure server starts on port ' + portNumber.toString(), () => {
|
||||||
assert.ok(serverStarted);
|
assert.ok(serverStarted);
|
||||||
});
|
});
|
||||||
describe("Cypress tests", () => {
|
describe('Cypress tests', () => {
|
||||||
it("should run Cypress tests", (done) => {
|
it('should run Cypress tests', (done) => {
|
||||||
let cypressCommand = "cypress run --config-file cypress.config.ts --browser chrome";
|
let cypressCommand = 'cypress run --config-file cypress.config.ts --browser chrome';
|
||||||
if (process.env.CYPRESS_RECORD_KEY &&
|
if (process.env.CYPRESS_RECORD_KEY &&
|
||||||
process.env.CYPRESS_RECORD_KEY !== "") {
|
process.env.CYPRESS_RECORD_KEY !== '') {
|
||||||
cypressCommand += " --record";
|
cypressCommand += ' --record';
|
||||||
}
|
}
|
||||||
const childProcess = exec(cypressCommand);
|
const childProcess = exec(cypressCommand);
|
||||||
childProcess.stdout.on("data", (data) => {
|
childProcess.stdout.on('data', (data) => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
});
|
});
|
||||||
childProcess.stderr.on("data", (data) => {
|
childProcess.stderr.on('data', (data) => {
|
||||||
console.error(data);
|
console.error(data);
|
||||||
});
|
});
|
||||||
childProcess.on("exit", (code) => {
|
childProcess.on('exit', (code) => {
|
||||||
assert.ok(code === 0);
|
assert.ok(code === 0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,65 +1,65 @@
|
||||||
/* eslint-disable unicorn/filename-case */
|
/* eslint-disable unicorn/filename-case */
|
||||||
|
|
||||||
import * as assert from "assert";
|
import * as assert from 'node:assert'
|
||||||
|
|
||||||
import { portNumber } from "./_globals.js";
|
import { portNumber } from './_globals.js'
|
||||||
|
|
||||||
import { exec } from "node:child_process";
|
import { exec } from 'node:child_process'
|
||||||
|
|
||||||
import * as http from "node:http";
|
import * as http from 'node:http'
|
||||||
import { app } from "../app.js";
|
import { app } from '../app.js'
|
||||||
|
|
||||||
describe("lot-occupancy-system", () => {
|
describe('lot-occupancy-system', () => {
|
||||||
const httpServer = http.createServer(app);
|
const httpServer = http.createServer(app)
|
||||||
|
|
||||||
let serverStarted = false;
|
let serverStarted = false
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
httpServer.listen(portNumber);
|
httpServer.listen(portNumber)
|
||||||
|
|
||||||
httpServer.on("listening", () => {
|
httpServer.on('listening', () => {
|
||||||
serverStarted = true;
|
serverStarted = true
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
try {
|
try {
|
||||||
httpServer.close();
|
httpServer.close()
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
it("Ensure server starts on port " + portNumber.toString(), () => {
|
it('Ensure server starts on port ' + portNumber.toString(), () => {
|
||||||
assert.ok(serverStarted);
|
assert.ok(serverStarted)
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("Cypress tests", () => {
|
describe('Cypress tests', () => {
|
||||||
it("should run Cypress tests", (done) => {
|
it('should run Cypress tests', (done) => {
|
||||||
let cypressCommand =
|
let cypressCommand =
|
||||||
"cypress run --config-file cypress.config.ts --browser chrome";
|
'cypress run --config-file cypress.config.ts --browser chrome'
|
||||||
|
|
||||||
if (
|
if (
|
||||||
process.env.CYPRESS_RECORD_KEY &&
|
process.env.CYPRESS_RECORD_KEY &&
|
||||||
process.env.CYPRESS_RECORD_KEY !== ""
|
process.env.CYPRESS_RECORD_KEY !== ''
|
||||||
) {
|
) {
|
||||||
cypressCommand += " --record";
|
cypressCommand += ' --record'
|
||||||
}
|
}
|
||||||
|
|
||||||
const childProcess = exec(cypressCommand);
|
const childProcess = exec(cypressCommand)
|
||||||
|
|
||||||
childProcess.stdout.on("data", (data) => {
|
childProcess.stdout.on('data', (data) => {
|
||||||
console.log(data);
|
console.log(data)
|
||||||
});
|
})
|
||||||
|
|
||||||
childProcess.stderr.on("data", (data) => {
|
childProcess.stderr.on('data', (data) => {
|
||||||
console.error(data);
|
console.error(data)
|
||||||
});
|
})
|
||||||
|
|
||||||
childProcess.on("exit", (code) => {
|
childProcess.on('exit', (code) => {
|
||||||
assert.ok(code === 0);
|
assert.ok(code === 0)
|
||||||
done();
|
done()
|
||||||
});
|
})
|
||||||
}).timeout(30 * 60 * 60 * 1000);
|
}).timeout(30 * 60 * 60 * 1000)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,102 +1,102 @@
|
||||||
import * as assert from "assert";
|
import * as assert from 'node:assert';
|
||||||
import fs from "node:fs";
|
import fs from 'node:fs';
|
||||||
import * as userFunctions from "../helpers/functions.user.js";
|
import * as userFunctions from '../helpers/functions.user.js';
|
||||||
import * as sqlFilterFunctions from "../helpers/functions.sqlFilters.js";
|
import * as sqlFilterFunctions from '../helpers/functions.sqlFilters.js';
|
||||||
describe("functions.user", () => {
|
describe('functions.user', () => {
|
||||||
describe("unauthenticated, no user in session", () => {
|
describe('unauthenticated, no user in session', () => {
|
||||||
const noUserRequest = {
|
const noUserRequest = {
|
||||||
session: {}
|
session: {}
|
||||||
};
|
};
|
||||||
it("can not update", () => {
|
it('can not update', () => {
|
||||||
assert.strictEqual(userFunctions.userCanUpdate(noUserRequest), false);
|
assert.strictEqual(userFunctions.userCanUpdate(noUserRequest), false);
|
||||||
});
|
});
|
||||||
it("is not admin", () => {
|
it('is not admin', () => {
|
||||||
assert.strictEqual(userFunctions.userIsAdmin(noUserRequest), false);
|
assert.strictEqual(userFunctions.userIsAdmin(noUserRequest), false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("read only user, no update, no admin", () => {
|
describe('read only user, no update, no admin', () => {
|
||||||
const readOnlyRequest = {
|
const readOnlyRequest = {
|
||||||
session: {
|
session: {
|
||||||
user: {
|
user: {
|
||||||
userName: "*test",
|
userName: '*test',
|
||||||
userProperties: {
|
userProperties: {
|
||||||
canUpdate: false,
|
canUpdate: false,
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
apiKey: ""
|
apiKey: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
it("can not update", () => {
|
it('can not update', () => {
|
||||||
assert.strictEqual(userFunctions.userCanUpdate(readOnlyRequest), false);
|
assert.strictEqual(userFunctions.userCanUpdate(readOnlyRequest), false);
|
||||||
});
|
});
|
||||||
it("is not admin", () => {
|
it('is not admin', () => {
|
||||||
assert.strictEqual(userFunctions.userIsAdmin(readOnlyRequest), false);
|
assert.strictEqual(userFunctions.userIsAdmin(readOnlyRequest), false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("update only user, no admin", () => {
|
describe('update only user, no admin', () => {
|
||||||
const updateOnlyRequest = {
|
const updateOnlyRequest = {
|
||||||
session: {
|
session: {
|
||||||
user: {
|
user: {
|
||||||
userName: "*test",
|
userName: '*test',
|
||||||
userProperties: {
|
userProperties: {
|
||||||
canUpdate: true,
|
canUpdate: true,
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
apiKey: ""
|
apiKey: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
it("can update", () => {
|
it('can update', () => {
|
||||||
assert.strictEqual(userFunctions.userCanUpdate(updateOnlyRequest), true);
|
assert.strictEqual(userFunctions.userCanUpdate(updateOnlyRequest), true);
|
||||||
});
|
});
|
||||||
it("is not admin", () => {
|
it('is not admin', () => {
|
||||||
assert.strictEqual(userFunctions.userIsAdmin(updateOnlyRequest), false);
|
assert.strictEqual(userFunctions.userIsAdmin(updateOnlyRequest), false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("admin only user, no update", () => {
|
describe('admin only user, no update', () => {
|
||||||
const adminOnlyRequest = {
|
const adminOnlyRequest = {
|
||||||
session: {
|
session: {
|
||||||
user: {
|
user: {
|
||||||
userName: "*test",
|
userName: '*test',
|
||||||
userProperties: {
|
userProperties: {
|
||||||
canUpdate: false,
|
canUpdate: false,
|
||||||
isAdmin: true,
|
isAdmin: true,
|
||||||
apiKey: ""
|
apiKey: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
it("can not update", () => {
|
it('can not update', () => {
|
||||||
assert.strictEqual(userFunctions.userCanUpdate(adminOnlyRequest), false);
|
assert.strictEqual(userFunctions.userCanUpdate(adminOnlyRequest), false);
|
||||||
});
|
});
|
||||||
it("is admin", () => {
|
it('is admin', () => {
|
||||||
assert.strictEqual(userFunctions.userIsAdmin(adminOnlyRequest), true);
|
assert.strictEqual(userFunctions.userIsAdmin(adminOnlyRequest), true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("update admin user", () => {
|
describe('update admin user', () => {
|
||||||
const updateAdminRequest = {
|
const updateAdminRequest = {
|
||||||
session: {
|
session: {
|
||||||
user: {
|
user: {
|
||||||
userName: "*test",
|
userName: '*test',
|
||||||
userProperties: {
|
userProperties: {
|
||||||
canUpdate: true,
|
canUpdate: true,
|
||||||
isAdmin: true,
|
isAdmin: true,
|
||||||
apiKey: ""
|
apiKey: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
it("can update", () => {
|
it('can update', () => {
|
||||||
assert.strictEqual(userFunctions.userCanUpdate(updateAdminRequest), true);
|
assert.strictEqual(userFunctions.userCanUpdate(updateAdminRequest), true);
|
||||||
});
|
});
|
||||||
it("is admin", () => {
|
it('is admin', () => {
|
||||||
assert.strictEqual(userFunctions.userIsAdmin(updateAdminRequest), true);
|
assert.strictEqual(userFunctions.userIsAdmin(updateAdminRequest), true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("API key check", () => {
|
describe('API key check', () => {
|
||||||
it("authenticates with a valid API key", async () => {
|
it('authenticates with a valid API key', async () => {
|
||||||
const apiKeysJSON = JSON.parse(fs.readFileSync("data/apiKeys.json", "utf8"));
|
const apiKeysJSON = JSON.parse(fs.readFileSync('data/apiKeys.json', 'utf8'));
|
||||||
const apiKey = Object.values(apiKeysJSON)[0];
|
const apiKey = Object.values(apiKeysJSON)[0];
|
||||||
const apiRequest = {
|
const apiRequest = {
|
||||||
params: {
|
params: {
|
||||||
|
|
@ -105,15 +105,15 @@ describe("functions.user", () => {
|
||||||
};
|
};
|
||||||
assert.strictEqual(await userFunctions.apiKeyIsValid(apiRequest), true);
|
assert.strictEqual(await userFunctions.apiKeyIsValid(apiRequest), true);
|
||||||
});
|
});
|
||||||
it("fails to authenticate with an invalid API key", async () => {
|
it('fails to authenticate with an invalid API key', async () => {
|
||||||
const apiRequest = {
|
const apiRequest = {
|
||||||
params: {
|
params: {
|
||||||
apiKey: "badKey"
|
apiKey: 'badKey'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
assert.strictEqual(await userFunctions.apiKeyIsValid(apiRequest), false);
|
assert.strictEqual(await userFunctions.apiKeyIsValid(apiRequest), false);
|
||||||
});
|
});
|
||||||
it("fails to authenticate with no API key", async () => {
|
it('fails to authenticate with no API key', async () => {
|
||||||
const apiRequest = {
|
const apiRequest = {
|
||||||
params: {}
|
params: {}
|
||||||
};
|
};
|
||||||
|
|
@ -121,75 +121,75 @@ describe("functions.user", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("functions.sqlFilters", () => {
|
describe('functions.sqlFilters', () => {
|
||||||
describe("LotName filter", () => {
|
describe('LotName filter', () => {
|
||||||
it("returns startsWith filter", () => {
|
it('returns startsWith filter', () => {
|
||||||
const filter = sqlFilterFunctions.getLotNameWhereClause("TEST1 TEST2", "startsWith", "l");
|
const filter = sqlFilterFunctions.getLotNameWhereClause('TEST1 TEST2', 'startsWith', 'l');
|
||||||
assert.strictEqual(filter.sqlWhereClause, " and l.lotName like ? || '%'");
|
assert.strictEqual(filter.sqlWhereClause, " and l.lotName like ? || '%'");
|
||||||
assert.strictEqual(filter.sqlParameters.length, 1);
|
assert.strictEqual(filter.sqlParameters.length, 1);
|
||||||
assert.ok(filter.sqlParameters.includes("TEST1 TEST2"));
|
assert.ok(filter.sqlParameters.includes('TEST1 TEST2'));
|
||||||
});
|
});
|
||||||
it("returns endsWith filter", () => {
|
it('returns endsWith filter', () => {
|
||||||
const filter = sqlFilterFunctions.getLotNameWhereClause("TEST1 TEST2", "endsWith", "l");
|
const filter = sqlFilterFunctions.getLotNameWhereClause('TEST1 TEST2', 'endsWith', 'l');
|
||||||
assert.strictEqual(filter.sqlWhereClause, " and l.lotName like '%' || ?");
|
assert.strictEqual(filter.sqlWhereClause, " and l.lotName like '%' || ?");
|
||||||
assert.strictEqual(filter.sqlParameters.length, 1);
|
assert.strictEqual(filter.sqlParameters.length, 1);
|
||||||
assert.strictEqual(filter.sqlParameters[0], "TEST1 TEST2");
|
assert.strictEqual(filter.sqlParameters[0], 'TEST1 TEST2');
|
||||||
});
|
});
|
||||||
it("returns contains filter", () => {
|
it('returns contains filter', () => {
|
||||||
const filter = sqlFilterFunctions.getLotNameWhereClause("TEST1 TEST2", "", "l");
|
const filter = sqlFilterFunctions.getLotNameWhereClause('TEST1 TEST2', '', 'l');
|
||||||
assert.strictEqual(filter.sqlWhereClause, " and instr(lower(l.lotName), ?) and instr(lower(l.lotName), ?)");
|
assert.strictEqual(filter.sqlWhereClause, ' and instr(lower(l.lotName), ?) and instr(lower(l.lotName), ?)');
|
||||||
assert.ok(filter.sqlParameters.includes("test1"));
|
assert.ok(filter.sqlParameters.includes('test1'));
|
||||||
assert.ok(filter.sqlParameters.includes("test2"));
|
assert.ok(filter.sqlParameters.includes('test2'));
|
||||||
});
|
});
|
||||||
it("handles empty filter", () => {
|
it('handles empty filter', () => {
|
||||||
const filter = sqlFilterFunctions.getLotNameWhereClause("", "");
|
const filter = sqlFilterFunctions.getLotNameWhereClause('', '');
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
assert.strictEqual(filter.sqlWhereClause, '');
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
assert.strictEqual(filter.sqlParameters.length, 0);
|
||||||
});
|
});
|
||||||
it("handles undefined filter", () => {
|
it('handles undefined filter', () => {
|
||||||
const filter = sqlFilterFunctions.getLotNameWhereClause(undefined, undefined, "l");
|
const filter = sqlFilterFunctions.getLotNameWhereClause(undefined, undefined, 'l');
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
assert.strictEqual(filter.sqlWhereClause, '');
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
assert.strictEqual(filter.sqlParameters.length, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("OccupancyTime filter", () => {
|
describe('OccupancyTime filter', () => {
|
||||||
it("creates three different filters", () => {
|
it('creates three different filters', () => {
|
||||||
const currentFilter = sqlFilterFunctions.getOccupancyTimeWhereClause("current");
|
const currentFilter = sqlFilterFunctions.getOccupancyTimeWhereClause('current');
|
||||||
assert.notStrictEqual(currentFilter.sqlWhereClause, "");
|
assert.notStrictEqual(currentFilter.sqlWhereClause, '');
|
||||||
const pastFilter = sqlFilterFunctions.getOccupancyTimeWhereClause("past");
|
const pastFilter = sqlFilterFunctions.getOccupancyTimeWhereClause('past');
|
||||||
assert.notStrictEqual(pastFilter.sqlWhereClause, "");
|
assert.notStrictEqual(pastFilter.sqlWhereClause, '');
|
||||||
const futureFilter = sqlFilterFunctions.getOccupancyTimeWhereClause("future");
|
const futureFilter = sqlFilterFunctions.getOccupancyTimeWhereClause('future');
|
||||||
assert.notStrictEqual(futureFilter, "");
|
assert.notStrictEqual(futureFilter, '');
|
||||||
assert.notStrictEqual(currentFilter.sqlWhereClause, pastFilter.sqlWhereClause);
|
assert.notStrictEqual(currentFilter.sqlWhereClause, pastFilter.sqlWhereClause);
|
||||||
assert.notStrictEqual(currentFilter.sqlWhereClause, futureFilter.sqlWhereClause);
|
assert.notStrictEqual(currentFilter.sqlWhereClause, futureFilter.sqlWhereClause);
|
||||||
assert.notStrictEqual(pastFilter.sqlWhereClause, futureFilter.sqlWhereClause);
|
assert.notStrictEqual(pastFilter.sqlWhereClause, futureFilter.sqlWhereClause);
|
||||||
});
|
});
|
||||||
it("handles empty filter", () => {
|
it('handles empty filter', () => {
|
||||||
const filter = sqlFilterFunctions.getOccupancyTimeWhereClause("");
|
const filter = sqlFilterFunctions.getOccupancyTimeWhereClause('');
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
assert.strictEqual(filter.sqlWhereClause, '');
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
assert.strictEqual(filter.sqlParameters.length, 0);
|
||||||
});
|
});
|
||||||
it("handles undefined filter", () => {
|
it('handles undefined filter', () => {
|
||||||
const filter = sqlFilterFunctions.getOccupancyTimeWhereClause(undefined, "o");
|
const filter = sqlFilterFunctions.getOccupancyTimeWhereClause(undefined, 'o');
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
assert.strictEqual(filter.sqlWhereClause, '');
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
assert.strictEqual(filter.sqlParameters.length, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("OccupantName filter", () => {
|
describe('OccupantName filter', () => {
|
||||||
it("returns filter", () => {
|
it('returns filter', () => {
|
||||||
const filter = sqlFilterFunctions.getOccupantNameWhereClause("TEST1 TEST2", "o");
|
const filter = sqlFilterFunctions.getOccupantNameWhereClause('TEST1 TEST2', 'o');
|
||||||
assert.strictEqual(filter.sqlWhereClause, " and instr(lower(o.occupantName), ?) and instr(lower(o.occupantName), ?)");
|
assert.strictEqual(filter.sqlWhereClause, ' and instr(lower(o.occupantName), ?) and instr(lower(o.occupantName), ?)');
|
||||||
assert.ok(filter.sqlParameters.includes("test1"));
|
assert.ok(filter.sqlParameters.includes('test1'));
|
||||||
assert.ok(filter.sqlParameters.includes("test2"));
|
assert.ok(filter.sqlParameters.includes('test2'));
|
||||||
});
|
});
|
||||||
it("handles empty filter", () => {
|
it('handles empty filter', () => {
|
||||||
const filter = sqlFilterFunctions.getOccupantNameWhereClause("");
|
const filter = sqlFilterFunctions.getOccupantNameWhereClause('');
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
assert.strictEqual(filter.sqlWhereClause, '');
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
assert.strictEqual(filter.sqlParameters.length, 0);
|
||||||
});
|
});
|
||||||
it("handles undefined filter", () => {
|
it('handles undefined filter', () => {
|
||||||
const filter = sqlFilterFunctions.getOccupantNameWhereClause(undefined, "o");
|
const filter = sqlFilterFunctions.getOccupantNameWhereClause(undefined, 'o');
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
assert.strictEqual(filter.sqlWhereClause, '');
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
assert.strictEqual(filter.sqlParameters.length, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,256 +1,288 @@
|
||||||
import * as assert from "assert";
|
import * as assert from 'node:assert'
|
||||||
|
|
||||||
import fs from "node:fs";
|
import fs from 'node:fs'
|
||||||
|
|
||||||
import * as userFunctions from "../helpers/functions.user.js";
|
import * as userFunctions from '../helpers/functions.user.js'
|
||||||
import * as sqlFilterFunctions from "../helpers/functions.sqlFilters.js";
|
import * as sqlFilterFunctions from '../helpers/functions.sqlFilters.js'
|
||||||
|
|
||||||
describe("functions.user", () => {
|
describe('functions.user', () => {
|
||||||
describe("unauthenticated, no user in session", () => {
|
describe('unauthenticated, no user in session', () => {
|
||||||
const noUserRequest = {
|
const noUserRequest = {
|
||||||
session: {}
|
session: {}
|
||||||
};
|
}
|
||||||
|
|
||||||
it("can not update", () => {
|
it('can not update', () => {
|
||||||
assert.strictEqual(userFunctions.userCanUpdate(noUserRequest), false);
|
assert.strictEqual(userFunctions.userCanUpdate(noUserRequest), false)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("is not admin", () => {
|
it('is not admin', () => {
|
||||||
assert.strictEqual(userFunctions.userIsAdmin(noUserRequest), false);
|
assert.strictEqual(userFunctions.userIsAdmin(noUserRequest), false)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("read only user, no update, no admin", () => {
|
describe('read only user, no update, no admin', () => {
|
||||||
const readOnlyRequest: userFunctions.UserRequest = {
|
const readOnlyRequest: userFunctions.UserRequest = {
|
||||||
session: {
|
session: {
|
||||||
user: {
|
user: {
|
||||||
userName: "*test",
|
userName: '*test',
|
||||||
userProperties: {
|
userProperties: {
|
||||||
canUpdate: false,
|
canUpdate: false,
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
apiKey: ""
|
apiKey: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
it("can not update", () => {
|
it('can not update', () => {
|
||||||
assert.strictEqual(userFunctions.userCanUpdate(readOnlyRequest), false);
|
assert.strictEqual(userFunctions.userCanUpdate(readOnlyRequest), false)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("is not admin", () => {
|
it('is not admin', () => {
|
||||||
assert.strictEqual(userFunctions.userIsAdmin(readOnlyRequest), false);
|
assert.strictEqual(userFunctions.userIsAdmin(readOnlyRequest), false)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("update only user, no admin", () => {
|
describe('update only user, no admin', () => {
|
||||||
const updateOnlyRequest: userFunctions.UserRequest = {
|
const updateOnlyRequest: userFunctions.UserRequest = {
|
||||||
session: {
|
session: {
|
||||||
user: {
|
user: {
|
||||||
userName: "*test",
|
userName: '*test',
|
||||||
userProperties: {
|
userProperties: {
|
||||||
canUpdate: true,
|
canUpdate: true,
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
apiKey: ""
|
apiKey: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
it("can update", () => {
|
it('can update', () => {
|
||||||
assert.strictEqual(userFunctions.userCanUpdate(updateOnlyRequest), true);
|
assert.strictEqual(userFunctions.userCanUpdate(updateOnlyRequest), true)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("is not admin", () => {
|
it('is not admin', () => {
|
||||||
assert.strictEqual(userFunctions.userIsAdmin(updateOnlyRequest), false);
|
assert.strictEqual(userFunctions.userIsAdmin(updateOnlyRequest), false)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("admin only user, no update", () => {
|
describe('admin only user, no update', () => {
|
||||||
const adminOnlyRequest: userFunctions.UserRequest = {
|
const adminOnlyRequest: userFunctions.UserRequest = {
|
||||||
session: {
|
session: {
|
||||||
user: {
|
user: {
|
||||||
userName: "*test",
|
userName: '*test',
|
||||||
userProperties: {
|
userProperties: {
|
||||||
canUpdate: false,
|
canUpdate: false,
|
||||||
isAdmin: true,
|
isAdmin: true,
|
||||||
apiKey: ""
|
apiKey: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
it("can not update", () => {
|
it('can not update', () => {
|
||||||
assert.strictEqual(userFunctions.userCanUpdate(adminOnlyRequest), false);
|
assert.strictEqual(userFunctions.userCanUpdate(adminOnlyRequest), false)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("is admin", () => {
|
it('is admin', () => {
|
||||||
assert.strictEqual(userFunctions.userIsAdmin(adminOnlyRequest), true);
|
assert.strictEqual(userFunctions.userIsAdmin(adminOnlyRequest), true)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("update admin user", () => {
|
describe('update admin user', () => {
|
||||||
const updateAdminRequest: userFunctions.UserRequest = {
|
const updateAdminRequest: userFunctions.UserRequest = {
|
||||||
session: {
|
session: {
|
||||||
user: {
|
user: {
|
||||||
userName: "*test",
|
userName: '*test',
|
||||||
userProperties: {
|
userProperties: {
|
||||||
canUpdate: true,
|
canUpdate: true,
|
||||||
isAdmin: true,
|
isAdmin: true,
|
||||||
apiKey: ""
|
apiKey: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
it("can update", () => {
|
it('can update', () => {
|
||||||
assert.strictEqual(userFunctions.userCanUpdate(updateAdminRequest), true);
|
assert.strictEqual(userFunctions.userCanUpdate(updateAdminRequest), true)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("is admin", () => {
|
it('is admin', () => {
|
||||||
assert.strictEqual(userFunctions.userIsAdmin(updateAdminRequest), true);
|
assert.strictEqual(userFunctions.userIsAdmin(updateAdminRequest), true)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("API key check", () => {
|
describe('API key check', () => {
|
||||||
it("authenticates with a valid API key", async () => {
|
it('authenticates with a valid API key', async () => {
|
||||||
const apiKeysJSON: { [userName: string]: string } = JSON.parse(
|
const apiKeysJSON: Record<string, string> = JSON.parse(
|
||||||
fs.readFileSync("data/apiKeys.json", "utf8")
|
fs.readFileSync('data/apiKeys.json', 'utf8')
|
||||||
);
|
)
|
||||||
|
|
||||||
const apiKey = Object.values(apiKeysJSON)[0];
|
const apiKey = Object.values(apiKeysJSON)[0]
|
||||||
|
|
||||||
const apiRequest: userFunctions.APIRequest = {
|
const apiRequest: userFunctions.APIRequest = {
|
||||||
params: {
|
params: {
|
||||||
apiKey
|
apiKey
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
assert.strictEqual(await userFunctions.apiKeyIsValid(apiRequest), true);
|
assert.strictEqual(await userFunctions.apiKeyIsValid(apiRequest), true)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("fails to authenticate with an invalid API key", async () => {
|
it('fails to authenticate with an invalid API key', async () => {
|
||||||
const apiRequest: userFunctions.APIRequest = {
|
const apiRequest: userFunctions.APIRequest = {
|
||||||
params: {
|
params: {
|
||||||
apiKey: "badKey"
|
apiKey: 'badKey'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
assert.strictEqual(await userFunctions.apiKeyIsValid(apiRequest), false);
|
assert.strictEqual(await userFunctions.apiKeyIsValid(apiRequest), false)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("fails to authenticate with no API key", async () => {
|
it('fails to authenticate with no API key', async () => {
|
||||||
const apiRequest: userFunctions.APIRequest = {
|
const apiRequest: userFunctions.APIRequest = {
|
||||||
params: {}
|
params: {}
|
||||||
};
|
}
|
||||||
|
|
||||||
assert.strictEqual(await userFunctions.apiKeyIsValid(apiRequest), false);
|
assert.strictEqual(await userFunctions.apiKeyIsValid(apiRequest), false)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("functions.sqlFilters", () => {
|
describe('functions.sqlFilters', () => {
|
||||||
describe("LotName filter", () => {
|
describe('LotName filter', () => {
|
||||||
it("returns startsWith filter", () => {
|
it('returns startsWith filter', () => {
|
||||||
const filter = sqlFilterFunctions.getLotNameWhereClause(
|
const filter = sqlFilterFunctions.getLotNameWhereClause(
|
||||||
"TEST1 TEST2",
|
'TEST1 TEST2',
|
||||||
"startsWith",
|
'startsWith',
|
||||||
"l"
|
'l'
|
||||||
);
|
)
|
||||||
|
|
||||||
assert.strictEqual(filter.sqlWhereClause, " and l.lotName like ? || '%'");
|
assert.strictEqual(filter.sqlWhereClause, " and l.lotName like ? || '%'")
|
||||||
assert.strictEqual(filter.sqlParameters.length, 1);
|
assert.strictEqual(filter.sqlParameters.length, 1)
|
||||||
assert.ok(filter.sqlParameters.includes("TEST1 TEST2"));
|
assert.ok(filter.sqlParameters.includes('TEST1 TEST2'))
|
||||||
});
|
})
|
||||||
|
|
||||||
it("returns endsWith filter", () => {
|
it('returns endsWith filter', () => {
|
||||||
const filter = sqlFilterFunctions.getLotNameWhereClause("TEST1 TEST2", "endsWith", "l");
|
const filter = sqlFilterFunctions.getLotNameWhereClause(
|
||||||
|
'TEST1 TEST2',
|
||||||
|
'endsWith',
|
||||||
|
'l'
|
||||||
|
)
|
||||||
|
|
||||||
assert.strictEqual(filter.sqlWhereClause, " and l.lotName like '%' || ?");
|
assert.strictEqual(filter.sqlWhereClause, " and l.lotName like '%' || ?")
|
||||||
assert.strictEqual(filter.sqlParameters.length, 1);
|
assert.strictEqual(filter.sqlParameters.length, 1)
|
||||||
assert.strictEqual(filter.sqlParameters[0], "TEST1 TEST2");
|
assert.strictEqual(filter.sqlParameters[0], 'TEST1 TEST2')
|
||||||
});
|
})
|
||||||
|
|
||||||
it("returns contains filter", () => {
|
it('returns contains filter', () => {
|
||||||
const filter = sqlFilterFunctions.getLotNameWhereClause("TEST1 TEST2", "", "l");
|
const filter = sqlFilterFunctions.getLotNameWhereClause(
|
||||||
assert.strictEqual(
|
'TEST1 TEST2',
|
||||||
filter.sqlWhereClause,
|
'',
|
||||||
" and instr(lower(l.lotName), ?) and instr(lower(l.lotName), ?)"
|
'l'
|
||||||
);
|
)
|
||||||
|
assert.strictEqual(
|
||||||
|
filter.sqlWhereClause,
|
||||||
|
' and instr(lower(l.lotName), ?) and instr(lower(l.lotName), ?)'
|
||||||
|
)
|
||||||
|
|
||||||
assert.ok(filter.sqlParameters.includes("test1"));
|
assert.ok(filter.sqlParameters.includes('test1'))
|
||||||
assert.ok(filter.sqlParameters.includes("test2"));
|
assert.ok(filter.sqlParameters.includes('test2'))
|
||||||
});
|
})
|
||||||
|
|
||||||
it("handles empty filter", () => {
|
it('handles empty filter', () => {
|
||||||
const filter = sqlFilterFunctions.getLotNameWhereClause("", "");
|
const filter = sqlFilterFunctions.getLotNameWhereClause('', '')
|
||||||
|
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
assert.strictEqual(filter.sqlWhereClause, '')
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
assert.strictEqual(filter.sqlParameters.length, 0)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("handles undefined filter", () => {
|
it('handles undefined filter', () => {
|
||||||
const filter = sqlFilterFunctions.getLotNameWhereClause(undefined, undefined, "l");
|
const filter = sqlFilterFunctions.getLotNameWhereClause(
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
'l'
|
||||||
|
)
|
||||||
|
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
assert.strictEqual(filter.sqlWhereClause, '')
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
assert.strictEqual(filter.sqlParameters.length, 0)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
describe("OccupancyTime filter", () => {
|
describe('OccupancyTime filter', () => {
|
||||||
it("creates three different filters", () => {
|
it('creates three different filters', () => {
|
||||||
const currentFilter = sqlFilterFunctions.getOccupancyTimeWhereClause("current");
|
const currentFilter =
|
||||||
assert.notStrictEqual(currentFilter.sqlWhereClause, "");
|
sqlFilterFunctions.getOccupancyTimeWhereClause('current')
|
||||||
|
assert.notStrictEqual(currentFilter.sqlWhereClause, '')
|
||||||
|
|
||||||
const pastFilter = sqlFilterFunctions.getOccupancyTimeWhereClause("past");
|
const pastFilter = sqlFilterFunctions.getOccupancyTimeWhereClause('past')
|
||||||
assert.notStrictEqual(pastFilter.sqlWhereClause, "");
|
assert.notStrictEqual(pastFilter.sqlWhereClause, '')
|
||||||
|
|
||||||
const futureFilter = sqlFilterFunctions.getOccupancyTimeWhereClause("future");
|
const futureFilter =
|
||||||
assert.notStrictEqual(futureFilter, "");
|
sqlFilterFunctions.getOccupancyTimeWhereClause('future')
|
||||||
|
assert.notStrictEqual(futureFilter, '')
|
||||||
|
|
||||||
assert.notStrictEqual(currentFilter.sqlWhereClause, pastFilter.sqlWhereClause);
|
assert.notStrictEqual(
|
||||||
assert.notStrictEqual(currentFilter.sqlWhereClause, futureFilter.sqlWhereClause);
|
currentFilter.sqlWhereClause,
|
||||||
assert.notStrictEqual(pastFilter.sqlWhereClause, futureFilter.sqlWhereClause);
|
pastFilter.sqlWhereClause
|
||||||
});
|
)
|
||||||
|
assert.notStrictEqual(
|
||||||
|
currentFilter.sqlWhereClause,
|
||||||
|
futureFilter.sqlWhereClause
|
||||||
|
)
|
||||||
|
assert.notStrictEqual(
|
||||||
|
pastFilter.sqlWhereClause,
|
||||||
|
futureFilter.sqlWhereClause
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("handles empty filter", () => {
|
it('handles empty filter', () => {
|
||||||
const filter = sqlFilterFunctions.getOccupancyTimeWhereClause("");
|
const filter = sqlFilterFunctions.getOccupancyTimeWhereClause('')
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
assert.strictEqual(filter.sqlWhereClause, '')
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
assert.strictEqual(filter.sqlParameters.length, 0)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("handles undefined filter", () => {
|
it('handles undefined filter', () => {
|
||||||
const filter = sqlFilterFunctions.getOccupancyTimeWhereClause(undefined, "o");
|
const filter = sqlFilterFunctions.getOccupancyTimeWhereClause(
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
undefined,
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
'o'
|
||||||
});
|
)
|
||||||
});
|
assert.strictEqual(filter.sqlWhereClause, '')
|
||||||
|
assert.strictEqual(filter.sqlParameters.length, 0)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("OccupantName filter", () => {
|
describe('OccupantName filter', () => {
|
||||||
it("returns filter", () => {
|
it('returns filter', () => {
|
||||||
const filter = sqlFilterFunctions.getOccupantNameWhereClause("TEST1 TEST2", "o");
|
const filter = sqlFilterFunctions.getOccupantNameWhereClause(
|
||||||
|
'TEST1 TEST2',
|
||||||
|
'o'
|
||||||
|
)
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
filter.sqlWhereClause,
|
filter.sqlWhereClause,
|
||||||
" and instr(lower(o.occupantName), ?) and instr(lower(o.occupantName), ?)"
|
' and instr(lower(o.occupantName), ?) and instr(lower(o.occupantName), ?)'
|
||||||
);
|
)
|
||||||
|
|
||||||
assert.ok(filter.sqlParameters.includes("test1"));
|
assert.ok(filter.sqlParameters.includes('test1'))
|
||||||
assert.ok(filter.sqlParameters.includes("test2"));
|
assert.ok(filter.sqlParameters.includes('test2'))
|
||||||
});
|
})
|
||||||
|
|
||||||
it("handles empty filter", () => {
|
it('handles empty filter', () => {
|
||||||
const filter = sqlFilterFunctions.getOccupantNameWhereClause("");
|
const filter = sqlFilterFunctions.getOccupantNameWhereClause('')
|
||||||
|
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
assert.strictEqual(filter.sqlWhereClause, '')
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
assert.strictEqual(filter.sqlParameters.length, 0)
|
||||||
});
|
})
|
||||||
|
|
||||||
it("handles undefined filter", () => {
|
it('handles undefined filter', () => {
|
||||||
const filter = sqlFilterFunctions.getOccupantNameWhereClause(undefined, "o");
|
const filter = sqlFilterFunctions.getOccupantNameWhereClause(
|
||||||
|
undefined,
|
||||||
|
'o'
|
||||||
|
)
|
||||||
|
|
||||||
assert.strictEqual(filter.sqlWhereClause, "");
|
assert.strictEqual(filter.sqlWhereClause, '')
|
||||||
assert.strictEqual(filter.sqlParameters.length, 0);
|
assert.strictEqual(filter.sqlParameters.length, 0)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue