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