refactoring
parent
0e64daaf53
commit
f641e01f7f
|
|
@ -5,7 +5,7 @@ import exitHook from "exit-hook";
|
||||||
import ntfyPublish from "@cityssm/ntfy-publish";
|
import ntfyPublish from "@cityssm/ntfy-publish";
|
||||||
import Debug from "debug";
|
import Debug from "debug";
|
||||||
const debug = Debug("lot-occupancy-system:www");
|
const debug = Debug("lot-occupancy-system:www");
|
||||||
const onError = (error) => {
|
function onError(error) {
|
||||||
if (error.syscall !== "listen") {
|
if (error.syscall !== "listen") {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
@ -22,14 +22,14 @@ const onError = (error) => {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
const onListening = (server) => {
|
function onListening(server) {
|
||||||
const addr = server.address();
|
const addr = server.address();
|
||||||
if (addr) {
|
if (addr) {
|
||||||
const bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port.toString();
|
const bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port.toString();
|
||||||
debug("Listening on " + bind);
|
debug("Listening on " + bind);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
const ntfyStartupConfig = configFunctions.getProperty("application.ntfyStartup");
|
const ntfyStartupConfig = configFunctions.getProperty("application.ntfyStartup");
|
||||||
const httpPort = configFunctions.getProperty("application.httpPort");
|
const httpPort = configFunctions.getProperty("application.httpPort");
|
||||||
const httpServer = http.createServer(app);
|
const httpServer = http.createServer(app);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ interface ServerError extends Error {
|
||||||
code: string;
|
code: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const onError = (error: ServerError) => {
|
function onError(error: ServerError) {
|
||||||
if (error.syscall !== "listen") {
|
if (error.syscall !== "listen") {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
@ -45,16 +45,16 @@ const onError = (error: ServerError) => {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
const onListening = (server: http.Server) => {
|
function onListening(server: http.Server) {
|
||||||
const addr = server.address();
|
const addr = server.address();
|
||||||
|
|
||||||
if (addr) {
|
if (addr) {
|
||||||
const bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port.toString();
|
const bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port.toString();
|
||||||
debug("Listening on " + bind);
|
debug("Listening on " + bind);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize HTTP
|
* Initialize HTTP
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import * as recordTypes from "../types/recordTypes";
|
import * as recordTypes from "../types/recordTypes";
|
||||||
export declare const regenerateApiKey: (userName: string) => Promise<void>;
|
export declare function regenerateApiKey(userName: string): Promise<void>;
|
||||||
export declare const getApiKey: (userName: string) => Promise<string>;
|
export declare function getApiKey(userName: string): Promise<string>;
|
||||||
export declare const getApiKeyFromSession: (session: recordTypes.PartialSession) => Promise<string>;
|
export declare function getApiKeyFromSession(session: recordTypes.PartialSession): Promise<string>;
|
||||||
export declare const getUserNameFromApiKey: (apiKey: string) => Promise<string>;
|
export declare function getUserNameFromApiKey(apiKey: string): Promise<string>;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import Debug from "debug";
|
||||||
const debug = Debug("lot-occupancy-system:functions.api");
|
const debug = Debug("lot-occupancy-system:functions.api");
|
||||||
const apiKeyPath = "data/apiKeys.json";
|
const apiKeyPath = "data/apiKeys.json";
|
||||||
let apiKeys;
|
let apiKeys;
|
||||||
const loadApiKeys = async () => {
|
async function loadApiKeys() {
|
||||||
try {
|
try {
|
||||||
const fileData = await fs.readFile(apiKeyPath, "utf8");
|
const fileData = await fs.readFile(apiKeyPath, "utf8");
|
||||||
apiKeys = JSON.parse(fileData);
|
apiKeys = JSON.parse(fileData);
|
||||||
|
|
@ -13,23 +13,23 @@ const loadApiKeys = async () => {
|
||||||
debug(error);
|
debug(error);
|
||||||
apiKeys = {};
|
apiKeys = {};
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
const saveApiKeys = async () => {
|
async function saveApiKeys() {
|
||||||
try {
|
try {
|
||||||
await fs.writeFile(apiKeyPath, JSON.stringify(apiKeys), "utf8");
|
await fs.writeFile(apiKeyPath, JSON.stringify(apiKeys), "utf8");
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
debug(error);
|
debug(error);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
const generateApiKey = (apiKeyPrefix) => {
|
function generateApiKey(apiKeyPrefix) {
|
||||||
return apiKeyPrefix + "-" + uuidv4() + "-" + Date.now();
|
return apiKeyPrefix + "-" + uuidv4() + "-" + Date.now();
|
||||||
};
|
}
|
||||||
export const regenerateApiKey = async (userName) => {
|
export async function regenerateApiKey(userName) {
|
||||||
apiKeys[userName] = generateApiKey(userName);
|
apiKeys[userName] = generateApiKey(userName);
|
||||||
await saveApiKeys();
|
await saveApiKeys();
|
||||||
};
|
}
|
||||||
export const getApiKey = async (userName) => {
|
export async function getApiKey(userName) {
|
||||||
if (!apiKeys) {
|
if (!apiKeys) {
|
||||||
await loadApiKeys();
|
await loadApiKeys();
|
||||||
}
|
}
|
||||||
|
|
@ -37,11 +37,11 @@ export const getApiKey = async (userName) => {
|
||||||
await regenerateApiKey(userName);
|
await regenerateApiKey(userName);
|
||||||
}
|
}
|
||||||
return apiKeys[userName];
|
return apiKeys[userName];
|
||||||
};
|
}
|
||||||
export const getApiKeyFromSession = async (session) => {
|
export async function getApiKeyFromSession(session) {
|
||||||
return await getApiKey(session.user.userName);
|
return await getApiKey(session.user.userName);
|
||||||
};
|
}
|
||||||
export const getUserNameFromApiKey = async (apiKey) => {
|
export async function getUserNameFromApiKey(apiKey) {
|
||||||
if (!apiKeys) {
|
if (!apiKeys) {
|
||||||
await loadApiKeys();
|
await loadApiKeys();
|
||||||
}
|
}
|
||||||
|
|
@ -50,4 +50,4 @@ export const getUserNameFromApiKey = async (apiKey) => {
|
||||||
return userName;
|
return userName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ const debug = Debug("lot-occupancy-system:functions.api");
|
||||||
const apiKeyPath = "data/apiKeys.json";
|
const apiKeyPath = "data/apiKeys.json";
|
||||||
let apiKeys: { [userName: string]: string };
|
let apiKeys: { [userName: string]: string };
|
||||||
|
|
||||||
const loadApiKeys = async () => {
|
async function loadApiKeys() {
|
||||||
try {
|
try {
|
||||||
const fileData = await fs.readFile(apiKeyPath, "utf8");
|
const fileData = await fs.readFile(apiKeyPath, "utf8");
|
||||||
apiKeys = JSON.parse(fileData);
|
apiKeys = JSON.parse(fileData);
|
||||||
|
|
@ -18,26 +18,26 @@ const loadApiKeys = async () => {
|
||||||
debug(error);
|
debug(error);
|
||||||
apiKeys = {};
|
apiKeys = {};
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
const saveApiKeys = async () => {
|
async function saveApiKeys() {
|
||||||
try {
|
try {
|
||||||
await fs.writeFile(apiKeyPath, JSON.stringify(apiKeys), "utf8");
|
await fs.writeFile(apiKeyPath, JSON.stringify(apiKeys), "utf8");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
debug(error);
|
debug(error);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
const generateApiKey = (apiKeyPrefix: string) => {
|
function generateApiKey(apiKeyPrefix: string) {
|
||||||
return apiKeyPrefix + "-" + uuidv4() + "-" + Date.now();
|
return apiKeyPrefix + "-" + uuidv4() + "-" + Date.now();
|
||||||
};
|
}
|
||||||
|
|
||||||
export const regenerateApiKey = async (userName: string) => {
|
export async function regenerateApiKey(userName: string) {
|
||||||
apiKeys[userName] = generateApiKey(userName);
|
apiKeys[userName] = generateApiKey(userName);
|
||||||
await saveApiKeys();
|
await saveApiKeys();
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getApiKey = async (userName: string) => {
|
export async function getApiKey(userName: string) {
|
||||||
if (!apiKeys) {
|
if (!apiKeys) {
|
||||||
await loadApiKeys();
|
await loadApiKeys();
|
||||||
}
|
}
|
||||||
|
|
@ -47,13 +47,13 @@ export const getApiKey = async (userName: string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return apiKeys[userName];
|
return apiKeys[userName];
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getApiKeyFromSession = async (session: recordTypes.PartialSession) => {
|
export async function getApiKeyFromSession(session: recordTypes.PartialSession) {
|
||||||
return await getApiKey(session.user.userName);
|
return await getApiKey(session.user.userName);
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getUserNameFromApiKey = async (apiKey: string) => {
|
export async function getUserNameFromApiKey(apiKey: string) {
|
||||||
if (!apiKeys) {
|
if (!apiKeys) {
|
||||||
await loadApiKeys();
|
await loadApiKeys();
|
||||||
}
|
}
|
||||||
|
|
@ -63,4 +63,4 @@ export const getUserNameFromApiKey = async (apiKey: string) => {
|
||||||
return userName;
|
return userName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
export declare const authenticate: (userName: string, password: string) => Promise<boolean>;
|
export declare function authenticate(userName: string, password: string): Promise<boolean>;
|
||||||
export declare const getSafeRedirectURL: (possibleRedirectURL?: string) => string;
|
export declare function getSafeRedirectURL(possibleRedirectURL?: string): string;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import * as configFunctions from "./functions.config.js";
|
||||||
import ActiveDirectory from "activedirectory2";
|
import ActiveDirectory from "activedirectory2";
|
||||||
const userDomain = configFunctions.getProperty("application.userDomain");
|
const userDomain = configFunctions.getProperty("application.userDomain");
|
||||||
const activeDirectoryConfig = configFunctions.getProperty("activeDirectory");
|
const activeDirectoryConfig = configFunctions.getProperty("activeDirectory");
|
||||||
const authenticateViaActiveDirectory = async (userName, password) => {
|
async function authenticateViaActiveDirectory(userName, password) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
try {
|
try {
|
||||||
const ad = new ActiveDirectory(activeDirectoryConfig);
|
const ad = new ActiveDirectory(activeDirectoryConfig);
|
||||||
|
|
@ -17,13 +17,13 @@ const authenticateViaActiveDirectory = async (userName, password) => {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
export const authenticate = async (userName, password) => {
|
export async function authenticate(userName, password) {
|
||||||
if (!userName || userName === "" || !password || password === "") {
|
if (!userName || userName === "" || !password || password === "") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return await authenticateViaActiveDirectory(userName, password);
|
return await authenticateViaActiveDirectory(userName, password);
|
||||||
};
|
}
|
||||||
const safeRedirects = new Set([
|
const safeRedirects = new Set([
|
||||||
"/admin/cleanup",
|
"/admin/cleanup",
|
||||||
"/admin/fees",
|
"/admin/fees",
|
||||||
|
|
@ -42,7 +42,7 @@ const safeRedirects = new Set([
|
||||||
"/workorders/outlook",
|
"/workorders/outlook",
|
||||||
"/reports"
|
"/reports"
|
||||||
]);
|
]);
|
||||||
export const getSafeRedirectURL = (possibleRedirectURL = "") => {
|
export function getSafeRedirectURL(possibleRedirectURL = "") {
|
||||||
const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix");
|
const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix");
|
||||||
if (typeof possibleRedirectURL === "string") {
|
if (typeof possibleRedirectURL === "string") {
|
||||||
const urlToCheck = possibleRedirectURL.startsWith(urlPrefix)
|
const urlToCheck = possibleRedirectURL.startsWith(urlPrefix)
|
||||||
|
|
@ -59,4 +59,4 @@ export const getSafeRedirectURL = (possibleRedirectURL = "") => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return urlPrefix + "/dashboard";
|
return urlPrefix + "/dashboard";
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ const userDomain = configFunctions.getProperty("application.userDomain");
|
||||||
|
|
||||||
const activeDirectoryConfig = configFunctions.getProperty("activeDirectory");
|
const activeDirectoryConfig = configFunctions.getProperty("activeDirectory");
|
||||||
|
|
||||||
const authenticateViaActiveDirectory = async (
|
async function authenticateViaActiveDirectory(
|
||||||
userName: string,
|
userName: string,
|
||||||
password: string
|
password: string
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
try {
|
try {
|
||||||
const ad = new ActiveDirectory(activeDirectoryConfig);
|
const ad = new ActiveDirectory(activeDirectoryConfig);
|
||||||
|
|
@ -25,15 +25,15 @@ const authenticateViaActiveDirectory = async (
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
export const authenticate = async (userName: string, password: string): Promise<boolean> => {
|
export async function authenticate(userName: string, password: string): Promise<boolean> {
|
||||||
if (!userName || userName === "" || !password || password === "") {
|
if (!userName || userName === "" || !password || password === "") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await authenticateViaActiveDirectory(userName, password);
|
return await authenticateViaActiveDirectory(userName, password);
|
||||||
};
|
}
|
||||||
|
|
||||||
const safeRedirects = new Set([
|
const safeRedirects = new Set([
|
||||||
"/admin/cleanup",
|
"/admin/cleanup",
|
||||||
|
|
@ -54,7 +54,7 @@ const safeRedirects = new Set([
|
||||||
"/reports"
|
"/reports"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const getSafeRedirectURL = (possibleRedirectURL = "") => {
|
export function getSafeRedirectURL(possibleRedirectURL = "") {
|
||||||
const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix");
|
const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix");
|
||||||
|
|
||||||
if (typeof possibleRedirectURL === "string") {
|
if (typeof possibleRedirectURL === "string") {
|
||||||
|
|
@ -77,4 +77,4 @@ export const getSafeRedirectURL = (possibleRedirectURL = "") => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return urlPrefix + "/dashboard";
|
return urlPrefix + "/dashboard";
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,6 @@ export function getOccupancyTypeByOccupancyType(occupancyTypeString: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getOccupancyTypePrintsById(occupancyTypeId: number): string[] {
|
export function getOccupancyTypePrintsById(occupancyTypeId: number): string[] {
|
||||||
|
|
||||||
const occupancyType = getOccupancyTypeById(occupancyTypeId);
|
const occupancyType = getOccupancyTypeById(occupancyTypeId);
|
||||||
|
|
||||||
if (!occupancyType || occupancyType.occupancyTypePrints.length === 0) {
|
if (!occupancyType || occupancyType.occupancyTypePrints.length === 0) {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import * as recordTypes from "../types/recordTypes";
|
import * as recordTypes from "../types/recordTypes";
|
||||||
export declare const calculateFeeAmount: (fee: recordTypes.Fee, lotOccupancy: recordTypes.LotOccupancy) => number;
|
export declare const calculateFeeAmount: (fee: recordTypes.Fee, lotOccupancy: recordTypes.LotOccupancy) => number;
|
||||||
export declare const calculateTaxAmount: (fee: recordTypes.Fee, feeAmount: number) => number;
|
export declare function calculateTaxAmount(fee: recordTypes.Fee, feeAmount: number): number;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
export const calculateFeeAmount = (fee, lotOccupancy) => {
|
export const calculateFeeAmount = (fee, lotOccupancy) => {
|
||||||
return fee.feeFunction ? 0 : fee.feeAmount || 0;
|
return fee.feeFunction ? 0 : fee.feeAmount || 0;
|
||||||
};
|
};
|
||||||
export const calculateTaxAmount = (fee, feeAmount) => {
|
export function calculateTaxAmount(fee, feeAmount) {
|
||||||
return fee.taxPercentage
|
return fee.taxPercentage ? feeAmount * (fee.taxPercentage / 100) : fee.taxAmount || 0;
|
||||||
? feeAmount * (fee.taxPercentage / 100)
|
}
|
||||||
: fee.taxAmount || 0;
|
|
||||||
};
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ export const calculateFeeAmount = (
|
||||||
return fee.feeFunction ? 0 : fee.feeAmount || 0;
|
return fee.feeFunction ? 0 : fee.feeAmount || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const calculateTaxAmount = (fee: recordTypes.Fee, feeAmount: number) => {
|
export function calculateTaxAmount(fee: recordTypes.Fee, feeAmount: number) {
|
||||||
return fee.taxPercentage
|
return fee.taxPercentage ? feeAmount * (fee.taxPercentage / 100) : fee.taxAmount || 0;
|
||||||
? feeAmount * (fee.taxPercentage / 100)
|
}
|
||||||
: fee.taxAmount || 0;
|
|
||||||
};
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
export declare const getSolidIconClasses: () => Promise<string[]>;
|
export declare function getSolidIconClasses(): Promise<string[]>;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import faIcons from "font-awesome-v5-icons";
|
import faIcons from "font-awesome-v5-icons";
|
||||||
let solidIcons = [];
|
let solidIcons = [];
|
||||||
export const getSolidIconClasses = async () => {
|
export async function getSolidIconClasses() {
|
||||||
if (solidIcons.length === 0) {
|
if (solidIcons.length === 0) {
|
||||||
const allIcons = await faIcons.getListByKeys(["name", "styles"]);
|
const allIcons = await faIcons.getListByKeys(["name", "styles"]);
|
||||||
const list = [];
|
const list = [];
|
||||||
|
|
@ -12,4 +12,4 @@ export const getSolidIconClasses = async () => {
|
||||||
solidIcons = list;
|
solidIcons = list;
|
||||||
}
|
}
|
||||||
return solidIcons;
|
return solidIcons;
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import faIcons from "font-awesome-v5-icons";
|
||||||
|
|
||||||
let solidIcons: string[] = [];
|
let solidIcons: string[] = [];
|
||||||
|
|
||||||
export const getSolidIconClasses = async () => {
|
export async function getSolidIconClasses() {
|
||||||
if (solidIcons.length === 0) {
|
if (solidIcons.length === 0) {
|
||||||
const allIcons = await faIcons.getListByKeys(["name", "styles"]);
|
const allIcons = await faIcons.getListByKeys(["name", "styles"]);
|
||||||
|
|
||||||
|
|
@ -18,4 +18,4 @@ export const getSolidIconClasses = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return solidIcons;
|
return solidIcons;
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type * as recordTypes from "../types/recordTypes";
|
import type * as recordTypes from "../types/recordTypes";
|
||||||
export declare const filterOccupantsByLotOccupantType: (lotOccupancy: recordTypes.LotOccupancy, lotOccupantType: string) => recordTypes.LotOccupancyOccupant[];
|
export declare function filterOccupantsByLotOccupantType(lotOccupancy: recordTypes.LotOccupancy, lotOccupantType: string): recordTypes.LotOccupancyOccupant[];
|
||||||
export declare const getFieldValueByOccupancyTypeField: (lotOccupancy: recordTypes.LotOccupancy, occupancyTypeField: string) => string | undefined;
|
export declare function getFieldValueByOccupancyTypeField(lotOccupancy: recordTypes.LotOccupancy, occupancyTypeField: string): string | undefined;
|
||||||
export declare const getFeesByFeeCategory: (lotOccupancy: recordTypes.LotOccupancy, feeCategory: string, feeCategoryContains?: boolean) => recordTypes.LotOccupancyFee[];
|
export declare function getFeesByFeeCategory(lotOccupancy: recordTypes.LotOccupancy, feeCategory: string, feeCategoryContains?: boolean): recordTypes.LotOccupancyFee[];
|
||||||
export declare const getTransactionTotal: (lotOccupancy: recordTypes.LotOccupancy) => number;
|
export declare function getTransactionTotal(lotOccupancy: recordTypes.LotOccupancy): number;
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,22 @@
|
||||||
export const filterOccupantsByLotOccupantType = (lotOccupancy, lotOccupantType) => {
|
export function filterOccupantsByLotOccupantType(lotOccupancy, lotOccupantType) {
|
||||||
const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase();
|
const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase();
|
||||||
const occupants = (lotOccupancy.lotOccupancyOccupants || []).filter((possibleOccupant) => {
|
const occupants = (lotOccupancy.lotOccupancyOccupants || []).filter((possibleOccupant) => {
|
||||||
return (possibleOccupant.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase);
|
return (possibleOccupant.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase);
|
||||||
});
|
});
|
||||||
return occupants;
|
return occupants;
|
||||||
};
|
}
|
||||||
export const getFieldValueByOccupancyTypeField = (lotOccupancy, occupancyTypeField) => {
|
export function getFieldValueByOccupancyTypeField(lotOccupancy, occupancyTypeField) {
|
||||||
const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase();
|
const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase();
|
||||||
const field = (lotOccupancy.lotOccupancyFields || []).find((possibleField) => {
|
const field = (lotOccupancy.lotOccupancyFields || []).find((possibleField) => {
|
||||||
return possibleField.occupancyTypeField.toLowerCase() === occupancyTypeFieldLowerCase;
|
return (possibleField.occupancyTypeField.toLowerCase() ===
|
||||||
|
occupancyTypeFieldLowerCase);
|
||||||
});
|
});
|
||||||
if (field) {
|
if (field) {
|
||||||
return field.lotOccupancyFieldValue;
|
return field.lotOccupancyFieldValue;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
}
|
||||||
export const getFeesByFeeCategory = (lotOccupancy, feeCategory, feeCategoryContains = false) => {
|
export function getFeesByFeeCategory(lotOccupancy, feeCategory, feeCategoryContains = false) {
|
||||||
const feeCategoryLowerCase = feeCategory.toLowerCase();
|
const feeCategoryLowerCase = feeCategory.toLowerCase();
|
||||||
const fees = (lotOccupancy.lotOccupancyFees || []).filter((possibleFee) => {
|
const fees = (lotOccupancy.lotOccupancyFees || []).filter((possibleFee) => {
|
||||||
return feeCategoryContains
|
return feeCategoryContains
|
||||||
|
|
@ -23,11 +24,11 @@ export const getFeesByFeeCategory = (lotOccupancy, feeCategory, feeCategoryConta
|
||||||
: possibleFee.feeCategory.toLowerCase() === feeCategoryLowerCase;
|
: possibleFee.feeCategory.toLowerCase() === feeCategoryLowerCase;
|
||||||
});
|
});
|
||||||
return fees;
|
return fees;
|
||||||
};
|
}
|
||||||
export const getTransactionTotal = (lotOccupancy) => {
|
export function getTransactionTotal(lotOccupancy) {
|
||||||
let transactionTotal = 0;
|
let transactionTotal = 0;
|
||||||
for (const transaction of (lotOccupancy.lotOccupancyTransactions || [])) {
|
for (const transaction of lotOccupancy.lotOccupancyTransactions || []) {
|
||||||
transactionTotal += transaction.transactionAmount;
|
transactionTotal += transaction.transactionAmount;
|
||||||
}
|
}
|
||||||
return transactionTotal;
|
return transactionTotal;
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import type * as recordTypes from "../types/recordTypes";
|
import type * as recordTypes from "../types/recordTypes";
|
||||||
|
|
||||||
export const filterOccupantsByLotOccupantType = (
|
export function filterOccupantsByLotOccupantType(
|
||||||
lotOccupancy: recordTypes.LotOccupancy,
|
lotOccupancy: recordTypes.LotOccupancy,
|
||||||
lotOccupantType: string
|
lotOccupantType: string
|
||||||
): recordTypes.LotOccupancyOccupant[] => {
|
): recordTypes.LotOccupancyOccupant[] {
|
||||||
const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase();
|
const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase();
|
||||||
|
|
||||||
const occupants = (lotOccupancy.lotOccupancyOccupants || []).filter((possibleOccupant) => {
|
const occupants = (lotOccupancy.lotOccupancyOccupants || []).filter((possibleOccupant) => {
|
||||||
|
|
@ -13,16 +13,19 @@ export const filterOccupantsByLotOccupantType = (
|
||||||
});
|
});
|
||||||
|
|
||||||
return occupants;
|
return occupants;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getFieldValueByOccupancyTypeField = (
|
export function getFieldValueByOccupancyTypeField(
|
||||||
lotOccupancy: recordTypes.LotOccupancy,
|
lotOccupancy: recordTypes.LotOccupancy,
|
||||||
occupancyTypeField: string
|
occupancyTypeField: string
|
||||||
): string | undefined => {
|
): string | undefined {
|
||||||
const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase();
|
const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase();
|
||||||
|
|
||||||
const field = (lotOccupancy.lotOccupancyFields || []).find((possibleField) => {
|
const field = (lotOccupancy.lotOccupancyFields || []).find((possibleField) => {
|
||||||
return (possibleField.occupancyTypeField as string).toLowerCase() === occupancyTypeFieldLowerCase;
|
return (
|
||||||
|
(possibleField.occupancyTypeField as string).toLowerCase() ===
|
||||||
|
occupancyTypeFieldLowerCase
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (field) {
|
if (field) {
|
||||||
|
|
@ -30,13 +33,13 @@ export const getFieldValueByOccupancyTypeField = (
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getFeesByFeeCategory = (
|
export function getFeesByFeeCategory(
|
||||||
lotOccupancy: recordTypes.LotOccupancy,
|
lotOccupancy: recordTypes.LotOccupancy,
|
||||||
feeCategory: string,
|
feeCategory: string,
|
||||||
feeCategoryContains = false
|
feeCategoryContains = false
|
||||||
) => {
|
) {
|
||||||
const feeCategoryLowerCase = feeCategory.toLowerCase();
|
const feeCategoryLowerCase = feeCategory.toLowerCase();
|
||||||
|
|
||||||
const fees = (lotOccupancy.lotOccupancyFees || []).filter((possibleFee) => {
|
const fees = (lotOccupancy.lotOccupancyFees || []).filter((possibleFee) => {
|
||||||
|
|
@ -46,14 +49,14 @@ export const getFeesByFeeCategory = (
|
||||||
});
|
});
|
||||||
|
|
||||||
return fees;
|
return fees;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getTransactionTotal = (lotOccupancy: recordTypes.LotOccupancy) => {
|
export function getTransactionTotal(lotOccupancy: recordTypes.LotOccupancy) {
|
||||||
let transactionTotal = 0;
|
let transactionTotal = 0;
|
||||||
|
|
||||||
for (const transaction of (lotOccupancy.lotOccupancyTransactions || [])) {
|
for (const transaction of lotOccupancy.lotOccupancyTransactions || []) {
|
||||||
transactionTotal += transaction.transactionAmount;
|
transactionTotal += transaction.transactionAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
return transactionTotal;
|
return transactionTotal;
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import fs from "node:fs/promises";
|
||||||
|
|
||||||
let mapSVGs: string[];
|
let mapSVGs: string[];
|
||||||
|
|
||||||
export async function getMapSVGs() {
|
export async function getMapSVGs(): Promise<string[]> {
|
||||||
if (!mapSVGs) {
|
if (!mapSVGs) {
|
||||||
const files = await fs.readdir("./public/images/maps/");
|
const files = await fs.readdir("./public/images/maps/");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ interface PrintConfig {
|
||||||
title: string;
|
title: string;
|
||||||
params: string[];
|
params: string[];
|
||||||
}
|
}
|
||||||
export declare const getScreenPrintConfig: (printName: string) => PrintConfig;
|
export declare function getScreenPrintConfig(printName: string): PrintConfig;
|
||||||
export declare const getPdfPrintConfig: (printName: string) => PrintConfig;
|
export declare function getPdfPrintConfig(printName: string): PrintConfig;
|
||||||
export declare const getPrintConfig: (screenOrPdf_printName: string) => PrintConfig | undefined;
|
export declare function getPrintConfig(screenOrPdf_printName: string): PrintConfig | undefined;
|
||||||
export declare const getReportData: (printConfig: PrintConfig, requestQuery: {
|
export declare function getReportData(printConfig: PrintConfig, requestQuery: {
|
||||||
[paramName: string]: unknown;
|
[paramName: string]: unknown;
|
||||||
}) => {
|
}): {
|
||||||
[dataName: string]: unknown;
|
[dataName: string]: unknown;
|
||||||
};
|
};
|
||||||
export {};
|
export {};
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ const screenPrintConfigs = {
|
||||||
params: ["lotOccupancyId"]
|
params: ["lotOccupancyId"]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const getScreenPrintConfig = (printName) => {
|
export function getScreenPrintConfig(printName) {
|
||||||
return screenPrintConfigs[printName];
|
return screenPrintConfigs[printName];
|
||||||
};
|
}
|
||||||
const pdfPrintConfigs = {
|
const pdfPrintConfigs = {
|
||||||
workOrder: {
|
workOrder: {
|
||||||
title: "Work Order Field Sheet",
|
title: "Work Order Field Sheet",
|
||||||
|
|
@ -32,10 +32,10 @@ const pdfPrintConfigs = {
|
||||||
params: ["lotOccupancyId"]
|
params: ["lotOccupancyId"]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const getPdfPrintConfig = (printName) => {
|
export function getPdfPrintConfig(printName) {
|
||||||
return pdfPrintConfigs[printName];
|
return pdfPrintConfigs[printName];
|
||||||
};
|
}
|
||||||
export const getPrintConfig = (screenOrPdf_printName) => {
|
export function getPrintConfig(screenOrPdf_printName) {
|
||||||
const printNameSplit = screenOrPdf_printName.split("/");
|
const printNameSplit = screenOrPdf_printName.split("/");
|
||||||
switch (printNameSplit[0]) {
|
switch (printNameSplit[0]) {
|
||||||
case "screen": {
|
case "screen": {
|
||||||
|
|
@ -46,8 +46,8 @@ export const getPrintConfig = (screenOrPdf_printName) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
}
|
||||||
export const getReportData = (printConfig, requestQuery) => {
|
export function getReportData(printConfig, requestQuery) {
|
||||||
const reportData = {
|
const reportData = {
|
||||||
headTitle: printConfig.title
|
headTitle: printConfig.title
|
||||||
};
|
};
|
||||||
|
|
@ -68,4 +68,4 @@ export const getReportData = (printConfig, requestQuery) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return reportData;
|
return reportData;
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ const screenPrintConfigs: { [printName: string]: PrintConfig } = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getScreenPrintConfig = (printName: string): PrintConfig => {
|
export function getScreenPrintConfig(printName: string): PrintConfig {
|
||||||
return screenPrintConfigs[printName];
|
return screenPrintConfigs[printName];
|
||||||
};
|
}
|
||||||
|
|
||||||
const pdfPrintConfigs: { [printName: string]: PrintConfig } = {
|
const pdfPrintConfigs: { [printName: string]: PrintConfig } = {
|
||||||
workOrder: {
|
workOrder: {
|
||||||
|
|
@ -45,11 +45,11 @@ const pdfPrintConfigs: { [printName: string]: PrintConfig } = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPdfPrintConfig = (printName: string): PrintConfig => {
|
export function getPdfPrintConfig(printName: string): PrintConfig {
|
||||||
return pdfPrintConfigs[printName];
|
return pdfPrintConfigs[printName];
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getPrintConfig = (screenOrPdf_printName: string): PrintConfig | undefined => {
|
export function getPrintConfig(screenOrPdf_printName: string): PrintConfig | undefined {
|
||||||
const printNameSplit = screenOrPdf_printName.split("/");
|
const printNameSplit = screenOrPdf_printName.split("/");
|
||||||
|
|
||||||
switch (printNameSplit[0]) {
|
switch (printNameSplit[0]) {
|
||||||
|
|
@ -62,12 +62,12 @@ export const getPrintConfig = (screenOrPdf_printName: string): PrintConfig | und
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getReportData = (
|
export function getReportData(
|
||||||
printConfig: PrintConfig,
|
printConfig: PrintConfig,
|
||||||
requestQuery: { [paramName: string]: unknown }
|
requestQuery: { [paramName: string]: unknown }
|
||||||
) => {
|
) {
|
||||||
const reportData: { [dataName: string]: unknown } = {
|
const reportData: { [dataName: string]: unknown } = {
|
||||||
headTitle: printConfig.title
|
headTitle: printConfig.title
|
||||||
};
|
};
|
||||||
|
|
@ -97,4 +97,4 @@ export const getReportData = (
|
||||||
}
|
}
|
||||||
|
|
||||||
return reportData;
|
return reportData;
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
declare type LotNameSearchType = "startsWith" | "endsWith" | "";
|
declare type LotNameSearchType = "startsWith" | "endsWith" | "";
|
||||||
export declare const getLotNameWhereClause: (lotName: string, lotNameSearchType: LotNameSearchType, lotsTableAlias?: string) => {
|
export declare function getLotNameWhereClause(lotName: string, lotNameSearchType: LotNameSearchType, lotsTableAlias?: string): {
|
||||||
sqlWhereClause: string;
|
sqlWhereClause: string;
|
||||||
sqlParameters: any[];
|
sqlParameters: any[];
|
||||||
};
|
};
|
||||||
declare type OccupancyTime = "" | "current" | "past" | "future";
|
declare type OccupancyTime = "" | "current" | "past" | "future";
|
||||||
export declare const getOccupancyTimeWhereClause: (occupancyTime: OccupancyTime, lotOccupanciesTableAlias?: string) => {
|
export declare function getOccupancyTimeWhereClause(occupancyTime: OccupancyTime, lotOccupanciesTableAlias?: string): {
|
||||||
sqlWhereClause: string;
|
sqlWhereClause: string;
|
||||||
sqlParameters: any[];
|
sqlParameters: any[];
|
||||||
};
|
};
|
||||||
export declare const getOccupantNameWhereClause: (occupantName: string, tableAlias?: string) => {
|
export declare function getOccupantNameWhereClause(occupantName: string, tableAlias?: string): {
|
||||||
sqlWhereClause: string;
|
sqlWhereClause: string;
|
||||||
sqlParameters: any[];
|
sqlParameters: any[];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||||
export const getLotNameWhereClause = (lotName, lotNameSearchType, lotsTableAlias = "l") => {
|
export function getLotNameWhereClause(lotName, lotNameSearchType, lotsTableAlias = "l") {
|
||||||
let sqlWhereClause = "";
|
let sqlWhereClause = "";
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
if (lotName) {
|
if (lotName) {
|
||||||
|
|
@ -27,8 +27,8 @@ export const getLotNameWhereClause = (lotName, lotNameSearchType, lotsTableAlias
|
||||||
sqlWhereClause,
|
sqlWhereClause,
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
export const getOccupancyTimeWhereClause = (occupancyTime, lotOccupanciesTableAlias = "o") => {
|
export function getOccupancyTimeWhereClause(occupancyTime, lotOccupanciesTableAlias = "o") {
|
||||||
let sqlWhereClause = "";
|
let sqlWhereClause = "";
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
if (occupancyTime) {
|
if (occupancyTime) {
|
||||||
|
|
@ -62,8 +62,8 @@ export const getOccupancyTimeWhereClause = (occupancyTime, lotOccupanciesTableAl
|
||||||
sqlWhereClause,
|
sqlWhereClause,
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
export const getOccupantNameWhereClause = (occupantName, tableAlias = "o") => {
|
export function getOccupantNameWhereClause(occupantName, tableAlias = "o") {
|
||||||
let sqlWhereClause = "";
|
let sqlWhereClause = "";
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
if (occupantName) {
|
if (occupantName) {
|
||||||
|
|
@ -77,4 +77,4 @@ export const getOccupantNameWhereClause = (occupantName, tableAlias = "o") => {
|
||||||
sqlWhereClause,
|
sqlWhereClause,
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||||
|
|
||||||
type LotNameSearchType = "startsWith" | "endsWith" | "";
|
type LotNameSearchType = "startsWith" | "endsWith" | "";
|
||||||
|
|
||||||
export const getLotNameWhereClause = (
|
export function getLotNameWhereClause(
|
||||||
lotName: string,
|
lotName: string,
|
||||||
lotNameSearchType: LotNameSearchType,
|
lotNameSearchType: LotNameSearchType,
|
||||||
lotsTableAlias = "l"
|
lotsTableAlias = "l"
|
||||||
) => {
|
) {
|
||||||
let sqlWhereClause = "";
|
let sqlWhereClause = "";
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
|
|
||||||
|
|
@ -36,14 +36,14 @@ export const getLotNameWhereClause = (
|
||||||
sqlWhereClause,
|
sqlWhereClause,
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
type OccupancyTime = "" | "current" | "past" | "future";
|
type OccupancyTime = "" | "current" | "past" | "future";
|
||||||
|
|
||||||
export const getOccupancyTimeWhereClause = (
|
export function getOccupancyTimeWhereClause(
|
||||||
occupancyTime: OccupancyTime,
|
occupancyTime: OccupancyTime,
|
||||||
lotOccupanciesTableAlias = "o"
|
lotOccupanciesTableAlias = "o"
|
||||||
) => {
|
) {
|
||||||
let sqlWhereClause = "";
|
let sqlWhereClause = "";
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
|
|
||||||
|
|
@ -82,9 +82,9 @@ export const getOccupancyTimeWhereClause = (
|
||||||
sqlWhereClause,
|
sqlWhereClause,
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getOccupantNameWhereClause = (occupantName: string, tableAlias = "o") => {
|
export function getOccupantNameWhereClause(occupantName: string, tableAlias = "o") {
|
||||||
let sqlWhereClause = "";
|
let sqlWhereClause = "";
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
|
|
||||||
|
|
@ -100,4 +100,4 @@ export const getOccupantNameWhereClause = (occupantName: string, tableAlias = "o
|
||||||
sqlWhereClause,
|
sqlWhereClause,
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,6 @@ export interface APIRequest {
|
||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export declare const userIsAdmin: (request: UserRequest) => boolean;
|
export declare function userIsAdmin(request: UserRequest): boolean;
|
||||||
export declare const userCanUpdate: (request: UserRequest) => boolean;
|
export declare function userCanUpdate(request: UserRequest): boolean;
|
||||||
export declare const apiKeyIsValid: (request: APIRequest) => Promise<boolean>;
|
export declare function apiKeyIsValid(request: APIRequest): Promise<boolean>;
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
import { getUserNameFromApiKey } from "./functions.api.js";
|
import { getUserNameFromApiKey } from "./functions.api.js";
|
||||||
import * as configFunctions from "./functions.config.js";
|
import * as configFunctions from "./functions.config.js";
|
||||||
export const userIsAdmin = (request) => {
|
export function userIsAdmin(request) {
|
||||||
var _a;
|
var _a;
|
||||||
const user = (_a = request.session) === null || _a === void 0 ? void 0 : _a.user;
|
const user = (_a = request.session) === null || _a === void 0 ? void 0 : _a.user;
|
||||||
if (!user || !user.userProperties) {
|
if (!user || !user.userProperties) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return user.userProperties.isAdmin;
|
return user.userProperties.isAdmin;
|
||||||
};
|
}
|
||||||
export const userCanUpdate = (request) => {
|
export function userCanUpdate(request) {
|
||||||
var _a;
|
var _a;
|
||||||
const user = (_a = request.session) === null || _a === void 0 ? void 0 : _a.user;
|
const user = (_a = request.session) === null || _a === void 0 ? void 0 : _a.user;
|
||||||
if (!user || !user.userProperties) {
|
if (!user || !user.userProperties) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return user.userProperties.canUpdate;
|
return user.userProperties.canUpdate;
|
||||||
};
|
}
|
||||||
export const apiKeyIsValid = async (request) => {
|
export async function apiKeyIsValid(request) {
|
||||||
var _a;
|
var _a;
|
||||||
const apiKey = (_a = request.params) === null || _a === void 0 ? void 0 : _a.apiKey;
|
const apiKey = (_a = request.params) === null || _a === void 0 ? void 0 : _a.apiKey;
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
|
|
@ -26,10 +26,8 @@ export const apiKeyIsValid = async (request) => {
|
||||||
if (!userName) {
|
if (!userName) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const canLogin = configFunctions
|
const canLogin = configFunctions.getProperty("users.canLogin").some((currentUserName) => {
|
||||||
.getProperty("users.canLogin")
|
|
||||||
.some((currentUserName) => {
|
|
||||||
return userName === currentUserName.toLowerCase();
|
return userName === currentUserName.toLowerCase();
|
||||||
});
|
});
|
||||||
return canLogin;
|
return canLogin;
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,16 @@ import type { User } from "../types/recordTypes";
|
||||||
export interface UserRequest {
|
export interface UserRequest {
|
||||||
session?: {
|
session?: {
|
||||||
user?: User;
|
user?: User;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface APIRequest {
|
export interface APIRequest {
|
||||||
params?: {
|
params?: {
|
||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const userIsAdmin = (request: UserRequest): boolean => {
|
export function userIsAdmin(request: UserRequest): boolean {
|
||||||
const user = request.session?.user;
|
const user = request.session?.user;
|
||||||
|
|
||||||
if (!user || !user.userProperties) {
|
if (!user || !user.userProperties) {
|
||||||
|
|
@ -23,9 +23,9 @@ export const userIsAdmin = (request: UserRequest): boolean => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return user.userProperties.isAdmin;
|
return user.userProperties.isAdmin;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const userCanUpdate = (request: UserRequest): boolean => {
|
export function userCanUpdate(request: UserRequest): boolean {
|
||||||
const user = request.session?.user;
|
const user = request.session?.user;
|
||||||
|
|
||||||
if (!user || !user.userProperties) {
|
if (!user || !user.userProperties) {
|
||||||
|
|
@ -33,9 +33,9 @@ export const userCanUpdate = (request: UserRequest): boolean => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return user.userProperties.canUpdate;
|
return user.userProperties.canUpdate;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const apiKeyIsValid = async (request: APIRequest): Promise<boolean> => {
|
export async function apiKeyIsValid(request: APIRequest): Promise<boolean> {
|
||||||
const apiKey = request.params?.apiKey;
|
const apiKey = request.params?.apiKey;
|
||||||
|
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
|
|
@ -48,11 +48,9 @@ export const apiKeyIsValid = async (request: APIRequest): Promise<boolean> => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const canLogin = configFunctions
|
const canLogin = configFunctions.getProperty("users.canLogin").some((currentUserName) => {
|
||||||
.getProperty("users.canLogin")
|
|
||||||
.some((currentUserName) => {
|
|
||||||
return userName === currentUserName.toLowerCase();
|
return userName === currentUserName.toLowerCase();
|
||||||
});
|
});
|
||||||
|
|
||||||
return canLogin;
|
return canLogin;
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ const session = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const initializeCemeteryDatabase = () => {
|
function initializeCemeteryDatabase() {
|
||||||
debug("Checking for " + databasePath + "...");
|
debug("Checking for " + databasePath + "...");
|
||||||
const databaseInitialized = initializeDatabase();
|
const databaseInitialized = initializeDatabase();
|
||||||
if (!databaseInitialized) {
|
if (!databaseInitialized) {
|
||||||
|
|
@ -207,5 +207,5 @@ const initializeCemeteryDatabase = () => {
|
||||||
feeCategory: "Additional Services",
|
feeCategory: "Additional Services",
|
||||||
orderNumber: 5
|
orderNumber: 5
|
||||||
}, session);
|
}, session);
|
||||||
};
|
}
|
||||||
initializeCemeteryDatabase();
|
initializeCemeteryDatabase();
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,10 @@ const session: PartialSession = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const initializeCemeteryDatabase = () => {
|
function initializeCemeteryDatabase() {
|
||||||
/*
|
/*
|
||||||
* Ensure database does not already exist
|
* Ensure database does not already exist
|
||||||
*/
|
*/
|
||||||
|
|
||||||
debug("Checking for " + databasePath + "...");
|
debug("Checking for " + databasePath + "...");
|
||||||
|
|
||||||
const databaseInitialized = initializeDatabase();
|
const databaseInitialized = initializeDatabase();
|
||||||
|
|
@ -52,7 +51,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
/*
|
/*
|
||||||
* Lot Types
|
* Lot Types
|
||||||
*/
|
*/
|
||||||
|
|
||||||
addLotType(
|
addLotType(
|
||||||
{
|
{
|
||||||
lotType: "Casket Grave",
|
lotType: "Casket Grave",
|
||||||
|
|
@ -104,7 +102,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
/*
|
/*
|
||||||
* Lot Statuses
|
* Lot Statuses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
addLotStatus(
|
addLotStatus(
|
||||||
{
|
{
|
||||||
lotStatus: "Available",
|
lotStatus: "Available",
|
||||||
|
|
@ -132,7 +129,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
/*
|
/*
|
||||||
* Lot Occupant Types
|
* Lot Occupant Types
|
||||||
*/
|
*/
|
||||||
|
|
||||||
addLotOccupantType(
|
addLotOccupantType(
|
||||||
{
|
{
|
||||||
lotOccupantType: "Deceased",
|
lotOccupantType: "Deceased",
|
||||||
|
|
@ -168,7 +164,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
/*
|
/*
|
||||||
* Occupancy Types
|
* Occupancy Types
|
||||||
*/
|
*/
|
||||||
|
|
||||||
addOccupancyType(
|
addOccupancyType(
|
||||||
{
|
{
|
||||||
occupancyType: "Preneed",
|
occupancyType: "Preneed",
|
||||||
|
|
@ -194,7 +189,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Death Date
|
// Death Date
|
||||||
|
|
||||||
const deathDateField = {
|
const deathDateField = {
|
||||||
occupancyTypeId: intermentOccupancyTypeId,
|
occupancyTypeId: intermentOccupancyTypeId,
|
||||||
occupancyTypeField: "Death Date",
|
occupancyTypeField: "Death Date",
|
||||||
|
|
@ -214,7 +208,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Death Age
|
// Death Age
|
||||||
|
|
||||||
const deathAgeField = {
|
const deathAgeField = {
|
||||||
occupancyTypeId: intermentOccupancyTypeId,
|
occupancyTypeId: intermentOccupancyTypeId,
|
||||||
occupancyTypeField: "Death Age",
|
occupancyTypeField: "Death Age",
|
||||||
|
|
@ -234,7 +227,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Death Age Period
|
// Death Age Period
|
||||||
|
|
||||||
const deathAgePeriod = {
|
const deathAgePeriod = {
|
||||||
occupancyTypeId: intermentOccupancyTypeId,
|
occupancyTypeId: intermentOccupancyTypeId,
|
||||||
occupancyTypeField: "Death Age Period",
|
occupancyTypeField: "Death Age Period",
|
||||||
|
|
@ -254,7 +246,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Death Place
|
// Death Place
|
||||||
|
|
||||||
const deathPlace = {
|
const deathPlace = {
|
||||||
occupancyTypeId: intermentOccupancyTypeId,
|
occupancyTypeId: intermentOccupancyTypeId,
|
||||||
occupancyTypeField: "Death Place",
|
occupancyTypeField: "Death Place",
|
||||||
|
|
@ -274,7 +265,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Funeral Home
|
// Funeral Home
|
||||||
|
|
||||||
const funeralHome = {
|
const funeralHome = {
|
||||||
occupancyTypeId: intermentOccupancyTypeId,
|
occupancyTypeId: intermentOccupancyTypeId,
|
||||||
occupancyTypeField: "Funeral Home",
|
occupancyTypeField: "Funeral Home",
|
||||||
|
|
@ -294,7 +284,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Funeral Date
|
// Funeral Date
|
||||||
|
|
||||||
const funeralDate = {
|
const funeralDate = {
|
||||||
occupancyTypeId: intermentOccupancyTypeId,
|
occupancyTypeId: intermentOccupancyTypeId,
|
||||||
occupancyTypeField: "Funeral Date",
|
occupancyTypeField: "Funeral Date",
|
||||||
|
|
@ -314,7 +303,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Container Type
|
// Container Type
|
||||||
|
|
||||||
const containerType = {
|
const containerType = {
|
||||||
occupancyTypeId: intermentOccupancyTypeId,
|
occupancyTypeId: intermentOccupancyTypeId,
|
||||||
occupancyTypeField: "Container Type",
|
occupancyTypeField: "Container Type",
|
||||||
|
|
@ -334,7 +322,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Committal Type
|
// Committal Type
|
||||||
|
|
||||||
const committalType = {
|
const committalType = {
|
||||||
occupancyTypeId: intermentOccupancyTypeId,
|
occupancyTypeId: intermentOccupancyTypeId,
|
||||||
occupancyTypeField: "Committal Type",
|
occupancyTypeField: "Committal Type",
|
||||||
|
|
@ -356,7 +343,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
/*
|
/*
|
||||||
* Fee Categories
|
* Fee Categories
|
||||||
*/
|
*/
|
||||||
|
|
||||||
addFeeCategory(
|
addFeeCategory(
|
||||||
{
|
{
|
||||||
feeCategory: "Interment Rights",
|
feeCategory: "Interment Rights",
|
||||||
|
|
@ -396,6 +382,6 @@ const initializeCemeteryDatabase = () => {
|
||||||
},
|
},
|
||||||
session
|
session
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
initializeCemeteryDatabase();
|
initializeCemeteryDatabase();
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
export declare const initializeDatabase: () => boolean;
|
export declare function initializeDatabase(): boolean;
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../data/databasePaths.js";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
const debugSQL = debug("lot-occupancy-system:databaseInitializer");
|
const debugSQL = debug("lot-occupancy-system:databaseInitializer");
|
||||||
const recordColumns = " recordCreate_userName varchar(30) not null," +
|
const recordColumns = ` recordCreate_userName varchar(30) not null,
|
||||||
" recordCreate_timeMillis integer not null," +
|
recordCreate_timeMillis integer not null,
|
||||||
" recordUpdate_userName varchar(30) not null," +
|
recordUpdate_userName varchar(30) not null,
|
||||||
" recordUpdate_timeMillis integer not null," +
|
recordUpdate_timeMillis integer not null,
|
||||||
" recordDelete_userName varchar(30)," +
|
recordDelete_userName varchar(30),
|
||||||
" recordDelete_timeMillis integer";
|
recordDelete_timeMillis integer`;
|
||||||
export const initializeDatabase = () => {
|
export function initializeDatabase() {
|
||||||
const lotOccupancyDB = sqlite(databasePath);
|
const lotOccupancyDB = sqlite(databasePath);
|
||||||
const row = lotOccupancyDB
|
const row = lotOccupancyDB
|
||||||
.prepare("select name from sqlite_master where type = 'table' and name = 'WorkOrderMilestones'")
|
.prepare("select name from sqlite_master where type = 'table' and name = 'WorkOrderMilestones'")
|
||||||
|
|
@ -402,4 +402,4 @@ export const initializeDatabase = () => {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,14 @@ import { lotOccupancyDB as databasePath } from "../data/databasePaths.js";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
const debugSQL = debug("lot-occupancy-system:databaseInitializer");
|
const debugSQL = debug("lot-occupancy-system:databaseInitializer");
|
||||||
|
|
||||||
const recordColumns =
|
const recordColumns = ` recordCreate_userName varchar(30) not null,
|
||||||
" recordCreate_userName varchar(30) not null," +
|
recordCreate_timeMillis integer not null,
|
||||||
" recordCreate_timeMillis integer not null," +
|
recordUpdate_userName varchar(30) not null,
|
||||||
" recordUpdate_userName varchar(30) not null," +
|
recordUpdate_timeMillis integer not null,
|
||||||
" recordUpdate_timeMillis integer not null," +
|
recordDelete_userName varchar(30),
|
||||||
" recordDelete_userName varchar(30)," +
|
recordDelete_timeMillis integer`;
|
||||||
" recordDelete_timeMillis integer";
|
|
||||||
|
|
||||||
export const initializeDatabase = (): boolean => {
|
export function initializeDatabase(): boolean {
|
||||||
const lotOccupancyDB = sqlite(databasePath);
|
const lotOccupancyDB = sqlite(databasePath);
|
||||||
|
|
||||||
const row = lotOccupancyDB
|
const row = lotOccupancyDB
|
||||||
|
|
@ -26,7 +25,6 @@ export const initializeDatabase = (): boolean => {
|
||||||
debugSQL("Creating " + databasePath);
|
debugSQL("Creating " + databasePath);
|
||||||
|
|
||||||
// Lot Types
|
// Lot Types
|
||||||
|
|
||||||
lotOccupancyDB
|
lotOccupancyDB
|
||||||
.prepare(
|
.prepare(
|
||||||
"create table if not exists LotTypes (" +
|
"create table if not exists LotTypes (" +
|
||||||
|
|
@ -90,7 +88,6 @@ export const initializeDatabase = (): boolean => {
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
// Maps and Lots
|
// Maps and Lots
|
||||||
|
|
||||||
lotOccupancyDB
|
lotOccupancyDB
|
||||||
.prepare(
|
.prepare(
|
||||||
"create table if not exists Maps (" +
|
"create table if not exists Maps (" +
|
||||||
|
|
@ -169,7 +166,6 @@ export const initializeDatabase = (): boolean => {
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
// Occupancies
|
// Occupancies
|
||||||
|
|
||||||
lotOccupancyDB
|
lotOccupancyDB
|
||||||
.prepare(
|
.prepare(
|
||||||
"create table if not exists OccupancyTypes (" +
|
"create table if not exists OccupancyTypes (" +
|
||||||
|
|
@ -332,7 +328,6 @@ export const initializeDatabase = (): boolean => {
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
// Occupancy Fees and Transactions
|
// Occupancy Fees and Transactions
|
||||||
|
|
||||||
lotOccupancyDB
|
lotOccupancyDB
|
||||||
.prepare(
|
.prepare(
|
||||||
"create table if not exists FeeCategories (" +
|
"create table if not exists FeeCategories (" +
|
||||||
|
|
@ -420,7 +415,6 @@ export const initializeDatabase = (): boolean => {
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
// Work Orders
|
// Work Orders
|
||||||
|
|
||||||
lotOccupancyDB
|
lotOccupancyDB
|
||||||
.prepare(
|
.prepare(
|
||||||
"create table if not exists WorkOrderTypes (" +
|
"create table if not exists WorkOrderTypes (" +
|
||||||
|
|
@ -541,4 +535,4 @@ export const initializeDatabase = (): boolean => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
export declare const getOccupancyTypePrints: (occupancyTypeId: number, connectedDatabase?: sqlite.Database) => string[];
|
export declare function getOccupancyTypePrints(occupancyTypeId: number, connectedDatabase?: sqlite.Database): string[];
|
||||||
export default getOccupancyTypePrints;
|
export default getOccupancyTypePrints;
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,16 @@ const userFunction_configContainsPrintEJS = (printEJS) => {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
export const getOccupancyTypePrints = (occupancyTypeId, connectedDatabase) => {
|
export function getOccupancyTypePrints(occupancyTypeId, connectedDatabase) {
|
||||||
const database = connectedDatabase || sqlite(databasePath);
|
const database = connectedDatabase || sqlite(databasePath);
|
||||||
database.function("userFn_configContainsPrintEJS", userFunction_configContainsPrintEJS);
|
database.function("userFn_configContainsPrintEJS", userFunction_configContainsPrintEJS);
|
||||||
const results = database
|
const results = database
|
||||||
.prepare("select printEJS, orderNumber" +
|
.prepare(`select printEJS, orderNumber
|
||||||
" from OccupancyTypePrints" +
|
from OccupancyTypePrints
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and occupancyTypeId = ?" +
|
and occupancyTypeId = ?
|
||||||
" and userFn_configContainsPrintEJS(printEJS) = 1" +
|
and userFn_configContainsPrintEJS(printEJS) = 1
|
||||||
" order by orderNumber, printEJS")
|
order by orderNumber, printEJS`)
|
||||||
.all(occupancyTypeId);
|
.all(occupancyTypeId);
|
||||||
let expectedOrderNumber = -1;
|
let expectedOrderNumber = -1;
|
||||||
const prints = [];
|
const prints = [];
|
||||||
|
|
@ -25,10 +25,10 @@ export const getOccupancyTypePrints = (occupancyTypeId, connectedDatabase) => {
|
||||||
expectedOrderNumber += 1;
|
expectedOrderNumber += 1;
|
||||||
if (result.orderNumber !== expectedOrderNumber) {
|
if (result.orderNumber !== expectedOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare("update OccupancyTypePrints" +
|
.prepare(`update OccupancyTypePrints
|
||||||
" set orderNumber = ?" +
|
set orderNumber = ?
|
||||||
" where occupancyTypeId = ?" +
|
where occupancyTypeId = ?
|
||||||
" and printEJS = ?")
|
and printEJS = ?`)
|
||||||
.run(expectedOrderNumber, occupancyTypeId, result.printEJS);
|
.run(expectedOrderNumber, occupancyTypeId, result.printEJS);
|
||||||
}
|
}
|
||||||
prints.push(result.printEJS);
|
prints.push(result.printEJS);
|
||||||
|
|
@ -37,5 +37,5 @@ export const getOccupancyTypePrints = (occupancyTypeId, connectedDatabase) => {
|
||||||
database.close();
|
database.close();
|
||||||
}
|
}
|
||||||
return prints;
|
return prints;
|
||||||
};
|
}
|
||||||
export default getOccupancyTypePrints;
|
export default getOccupancyTypePrints;
|
||||||
|
|
|
||||||
|
|
@ -13,22 +13,22 @@ const userFunction_configContainsPrintEJS = (printEJS: string): number => {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getOccupancyTypePrints = (
|
export function getOccupancyTypePrints(
|
||||||
occupancyTypeId: number,
|
occupancyTypeId: number,
|
||||||
connectedDatabase?: sqlite.Database
|
connectedDatabase?: sqlite.Database
|
||||||
): string[] => {
|
): string[] {
|
||||||
const database = connectedDatabase || sqlite(databasePath);
|
const database = connectedDatabase || sqlite(databasePath);
|
||||||
|
|
||||||
database.function("userFn_configContainsPrintEJS", userFunction_configContainsPrintEJS);
|
database.function("userFn_configContainsPrintEJS", userFunction_configContainsPrintEJS);
|
||||||
|
|
||||||
const results: { printEJS: string; orderNumber: number }[] = database
|
const results: { printEJS: string; orderNumber: number }[] = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select printEJS, orderNumber" +
|
`select printEJS, orderNumber
|
||||||
" from OccupancyTypePrints" +
|
from OccupancyTypePrints
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and occupancyTypeId = ?" +
|
and occupancyTypeId = ?
|
||||||
" and userFn_configContainsPrintEJS(printEJS) = 1" +
|
and userFn_configContainsPrintEJS(printEJS) = 1
|
||||||
" order by orderNumber, printEJS"
|
order by orderNumber, printEJS`
|
||||||
)
|
)
|
||||||
.all(occupancyTypeId);
|
.all(occupancyTypeId);
|
||||||
|
|
||||||
|
|
@ -42,10 +42,10 @@ export const getOccupancyTypePrints = (
|
||||||
if (result.orderNumber !== expectedOrderNumber) {
|
if (result.orderNumber !== expectedOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update OccupancyTypePrints" +
|
`update OccupancyTypePrints
|
||||||
" set orderNumber = ?" +
|
set orderNumber = ?
|
||||||
" where occupancyTypeId = ?" +
|
where occupancyTypeId = ?
|
||||||
" and printEJS = ?"
|
and printEJS = ?`
|
||||||
)
|
)
|
||||||
.run(expectedOrderNumber, occupancyTypeId, result.printEJS);
|
.run(expectedOrderNumber, occupancyTypeId, result.printEJS);
|
||||||
}
|
}
|
||||||
|
|
@ -58,6 +58,6 @@ export const getOccupancyTypePrints = (
|
||||||
}
|
}
|
||||||
|
|
||||||
return prints;
|
return prints;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getOccupancyTypePrints;
|
export default getOccupancyTypePrints;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
export declare const getOccupancyTypes: () => recordTypes.OccupancyType[];
|
export declare function getOccupancyTypes(): recordTypes.OccupancyType[];
|
||||||
export default getOccupancyTypes;
|
export default getOccupancyTypes;
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,20 @@ import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { getOccupancyTypeFields } from "./getOccupancyTypeFields.js";
|
import { getOccupancyTypeFields } from "./getOccupancyTypeFields.js";
|
||||||
import { getOccupancyTypePrints } from "./getOccupancyTypePrints.js";
|
import { getOccupancyTypePrints } from "./getOccupancyTypePrints.js";
|
||||||
export const getOccupancyTypes = () => {
|
export function getOccupancyTypes() {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const occupancyTypes = database
|
const occupancyTypes = database
|
||||||
.prepare("select occupancyTypeId, occupancyType, orderNumber" +
|
.prepare(`select occupancyTypeId, occupancyType, orderNumber
|
||||||
" from OccupancyTypes" +
|
from OccupancyTypes
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" order by orderNumber, occupancyType")
|
order by orderNumber, occupancyType`)
|
||||||
.all();
|
.all();
|
||||||
let expectedTypeOrderNumber = -1;
|
let expectedTypeOrderNumber = -1;
|
||||||
for (const occupancyType of occupancyTypes) {
|
for (const occupancyType of occupancyTypes) {
|
||||||
expectedTypeOrderNumber += 1;
|
expectedTypeOrderNumber += 1;
|
||||||
if (occupancyType.orderNumber !== expectedTypeOrderNumber) {
|
if (occupancyType.orderNumber !== expectedTypeOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare("update OccupancyTypes" + " set orderNumber = ?" + " where occupancyTypeId = ?")
|
.prepare("update OccupancyTypes set orderNumber = ? where occupancyTypeId = ?")
|
||||||
.run(expectedTypeOrderNumber, occupancyType.occupancyTypeId);
|
.run(expectedTypeOrderNumber, occupancyType.occupancyTypeId);
|
||||||
occupancyType.orderNumber = expectedTypeOrderNumber;
|
occupancyType.orderNumber = expectedTypeOrderNumber;
|
||||||
}
|
}
|
||||||
|
|
@ -26,9 +26,7 @@ export const getOccupancyTypes = () => {
|
||||||
expectedFieldOrderNumber += 1;
|
expectedFieldOrderNumber += 1;
|
||||||
if (occupancyTypeField.orderNumber !== expectedFieldOrderNumber) {
|
if (occupancyTypeField.orderNumber !== expectedFieldOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare("update OccupancyTypeFields" +
|
.prepare(`update OccupancyTypeFields set orderNumber = ? where occupancyTypeFieldId = ?`)
|
||||||
" set orderNumber = ?" +
|
|
||||||
" where occupancyTypeFieldId = ?")
|
|
||||||
.run(expectedFieldOrderNumber, occupancyTypeField.occupancyTypeFieldId);
|
.run(expectedFieldOrderNumber, occupancyTypeField.occupancyTypeFieldId);
|
||||||
occupancyTypeField.orderNumber = expectedFieldOrderNumber;
|
occupancyTypeField.orderNumber = expectedFieldOrderNumber;
|
||||||
}
|
}
|
||||||
|
|
@ -36,5 +34,5 @@ export const getOccupancyTypes = () => {
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
return occupancyTypes;
|
return occupancyTypes;
|
||||||
};
|
}
|
||||||
export default getOccupancyTypes;
|
export default getOccupancyTypes;
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,15 @@ import { getOccupancyTypePrints } from "./getOccupancyTypePrints.js";
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
|
||||||
export const getOccupancyTypes = (): recordTypes.OccupancyType[] => {
|
export function getOccupancyTypes(): recordTypes.OccupancyType[] {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const occupancyTypes: recordTypes.OccupancyType[] = database
|
const occupancyTypes: recordTypes.OccupancyType[] = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select occupancyTypeId, occupancyType, orderNumber" +
|
`select occupancyTypeId, occupancyType, orderNumber
|
||||||
" from OccupancyTypes" +
|
from OccupancyTypes
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" order by orderNumber, occupancyType"
|
order by orderNumber, occupancyType`
|
||||||
)
|
)
|
||||||
.all();
|
.all();
|
||||||
|
|
||||||
|
|
@ -26,9 +26,7 @@ export const getOccupancyTypes = (): recordTypes.OccupancyType[] => {
|
||||||
|
|
||||||
if (occupancyType.orderNumber !== expectedTypeOrderNumber) {
|
if (occupancyType.orderNumber !== expectedTypeOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare("update OccupancyTypes set orderNumber = ? where occupancyTypeId = ?")
|
||||||
"update OccupancyTypes" + " set orderNumber = ?" + " where occupancyTypeId = ?"
|
|
||||||
)
|
|
||||||
.run(expectedTypeOrderNumber, occupancyType.occupancyTypeId);
|
.run(expectedTypeOrderNumber, occupancyType.occupancyTypeId);
|
||||||
|
|
||||||
occupancyType.orderNumber = expectedTypeOrderNumber;
|
occupancyType.orderNumber = expectedTypeOrderNumber;
|
||||||
|
|
@ -52,9 +50,7 @@ export const getOccupancyTypes = (): recordTypes.OccupancyType[] => {
|
||||||
if (occupancyTypeField.orderNumber !== expectedFieldOrderNumber) {
|
if (occupancyTypeField.orderNumber !== expectedFieldOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update OccupancyTypeFields" +
|
`update OccupancyTypeFields set orderNumber = ? where occupancyTypeFieldId = ?`
|
||||||
" set orderNumber = ?" +
|
|
||||||
" where occupancyTypeFieldId = ?"
|
|
||||||
)
|
)
|
||||||
.run(expectedFieldOrderNumber, occupancyTypeField.occupancyTypeFieldId);
|
.run(expectedFieldOrderNumber, occupancyTypeField.occupancyTypeFieldId);
|
||||||
|
|
||||||
|
|
@ -66,6 +62,6 @@ export const getOccupancyTypes = (): recordTypes.OccupancyType[] => {
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return occupancyTypes;
|
return occupancyTypes;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getOccupancyTypes;
|
export default getOccupancyTypes;
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,5 @@ interface GetPastLotOccupancyOccupantsFilters {
|
||||||
interface GetPastLotOccupancyOccupantsOptions {
|
interface GetPastLotOccupancyOccupantsOptions {
|
||||||
limit: number;
|
limit: number;
|
||||||
}
|
}
|
||||||
export declare const getPastLotOccupancyOccupants: (filters: GetPastLotOccupancyOccupantsFilters, options: GetPastLotOccupancyOccupantsOptions) => recordTypes.LotOccupancyOccupant[];
|
export declare function getPastLotOccupancyOccupants(filters: GetPastLotOccupancyOccupantsFilters, options: GetPastLotOccupancyOccupantsOptions): recordTypes.LotOccupancyOccupant[];
|
||||||
export default getPastLotOccupancyOccupants;
|
export default getPastLotOccupancyOccupants;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
export const getPastLotOccupancyOccupants = (filters, options) => {
|
export function getPastLotOccupancyOccupants(filters, options) {
|
||||||
const database = sqlite(databasePath, {
|
const database = sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
});
|
});
|
||||||
|
|
@ -36,5 +36,5 @@ export const getPastLotOccupancyOccupants = (filters, options) => {
|
||||||
.all(sqlParameters);
|
.all(sqlParameters);
|
||||||
database.close();
|
database.close();
|
||||||
return lotOccupancyOccupants;
|
return lotOccupancyOccupants;
|
||||||
};
|
}
|
||||||
export default getPastLotOccupancyOccupants;
|
export default getPastLotOccupancyOccupants;
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ interface GetPastLotOccupancyOccupantsOptions {
|
||||||
limit: number;
|
limit: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getPastLotOccupancyOccupants = (
|
export function getPastLotOccupancyOccupants(
|
||||||
filters: GetPastLotOccupancyOccupantsFilters,
|
filters: GetPastLotOccupancyOccupantsFilters,
|
||||||
options: GetPastLotOccupancyOccupantsOptions
|
options: GetPastLotOccupancyOccupantsOptions
|
||||||
): recordTypes.LotOccupancyOccupant[] => {
|
): recordTypes.LotOccupancyOccupant[] {
|
||||||
const database = sqlite(databasePath, {
|
const database = sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
});
|
});
|
||||||
|
|
@ -67,6 +67,6 @@ export const getPastLotOccupancyOccupants = (
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return lotOccupancyOccupants;
|
return lotOccupancyOccupants;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getPastLotOccupancyOccupants;
|
export default getPastLotOccupancyOccupants;
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
export declare const getPreviousLotId: (lotId: number | string) => number | undefined;
|
export declare function getPreviousLotId(lotId: number | string): number | undefined;
|
||||||
export default getPreviousLotId;
|
export default getPreviousLotId;
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import * as configFunctions from "../functions.config.js";
|
import * as configFunctions from "../functions.config.js";
|
||||||
export const getPreviousLotId = (lotId) => {
|
export function getPreviousLotId(lotId) {
|
||||||
const database = sqlite(databasePath, {
|
const database = sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
});
|
});
|
||||||
database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction"));
|
database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction"));
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("select lotId from Lots" +
|
.prepare(`select lotId from Lots
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and userFn_lotNameSortName(lotName) < (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)" +
|
and userFn_lotNameSortName(lotName) < (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)
|
||||||
" order by userFn_lotNameSortName(lotName) desc" +
|
order by userFn_lotNameSortName(lotName) desc
|
||||||
" limit 1")
|
limit 1`)
|
||||||
.get(lotId);
|
.get(lotId);
|
||||||
database.close();
|
database.close();
|
||||||
if (result) {
|
if (result) {
|
||||||
return result.lotId;
|
return result.lotId;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
}
|
||||||
export default getPreviousLotId;
|
export default getPreviousLotId;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import * as configFunctions from "../functions.config.js";
|
import * as configFunctions from "../functions.config.js";
|
||||||
|
|
||||||
export const getPreviousLotId = (lotId: number | string): number | undefined => {
|
export function getPreviousLotId(lotId: number | string): number | undefined {
|
||||||
const database = sqlite(databasePath, {
|
const database = sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
});
|
});
|
||||||
|
|
@ -18,11 +18,11 @@ export const getPreviousLotId = (lotId: number | string): number | undefined =>
|
||||||
lotId: number;
|
lotId: number;
|
||||||
} = database
|
} = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select lotId from Lots" +
|
`select lotId from Lots
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and userFn_lotNameSortName(lotName) < (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)" +
|
and userFn_lotNameSortName(lotName) < (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)
|
||||||
" order by userFn_lotNameSortName(lotName) desc" +
|
order by userFn_lotNameSortName(lotName) desc
|
||||||
" limit 1"
|
limit 1`
|
||||||
)
|
)
|
||||||
.get(lotId);
|
.get(lotId);
|
||||||
|
|
||||||
|
|
@ -33,6 +33,6 @@ export const getPreviousLotId = (lotId: number | string): number | undefined =>
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getPreviousLotId;
|
export default getPreviousLotId;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
export interface ReportParameters {
|
export interface ReportParameters {
|
||||||
[parameterName: string]: string | number;
|
[parameterName: string]: string | number;
|
||||||
}
|
}
|
||||||
export declare const getReportData: (reportName: string, reportParameters?: ReportParameters) => unknown[] | undefined;
|
export declare function getReportData(reportName: string, reportParameters?: ReportParameters): unknown[] | undefined;
|
||||||
export default getReportData;
|
export default getReportData;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ const lotOccupancyIdAlias = occupancyCamelCase + "Id";
|
||||||
const occupancyTypeAlias = occupancyCamelCase + "Type";
|
const occupancyTypeAlias = occupancyCamelCase + "Type";
|
||||||
const occupancyStartDateAlias = occupancyCamelCase + "StartDate";
|
const occupancyStartDateAlias = occupancyCamelCase + "StartDate";
|
||||||
const occupancyEndDateAlias = occupancyCamelCase + "EndDate";
|
const occupancyEndDateAlias = occupancyCamelCase + "EndDate";
|
||||||
export const getReportData = (reportName, reportParameters) => {
|
export function getReportData(reportName, reportParameters) {
|
||||||
let sql;
|
let sql;
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
switch (reportName) {
|
switch (reportName) {
|
||||||
|
|
@ -276,5 +276,5 @@ export const getReportData = (reportName, reportParameters) => {
|
||||||
const rows = database.prepare(sql).all(sqlParameters);
|
const rows = database.prepare(sql).all(sqlParameters);
|
||||||
database.close();
|
database.close();
|
||||||
return rows;
|
return rows;
|
||||||
};
|
}
|
||||||
export default getReportData;
|
export default getReportData;
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,10 @@ const occupancyTypeAlias = occupancyCamelCase + "Type";
|
||||||
const occupancyStartDateAlias = occupancyCamelCase + "StartDate";
|
const occupancyStartDateAlias = occupancyCamelCase + "StartDate";
|
||||||
const occupancyEndDateAlias = occupancyCamelCase + "EndDate";
|
const occupancyEndDateAlias = occupancyCamelCase + "EndDate";
|
||||||
|
|
||||||
export const getReportData = (
|
export function getReportData(
|
||||||
reportName: string,
|
reportName: string,
|
||||||
reportParameters?: ReportParameters
|
reportParameters?: ReportParameters
|
||||||
): unknown[] | undefined => {
|
): unknown[] | undefined {
|
||||||
let sql: string;
|
let sql: string;
|
||||||
const sqlParameters: unknown[] = [];
|
const sqlParameters: unknown[] = [];
|
||||||
|
|
||||||
|
|
@ -343,6 +343,6 @@ export const getReportData = (
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return rows;
|
return rows;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getReportData;
|
export default getReportData;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@ interface WorkOrderOptions {
|
||||||
includeComments: boolean;
|
includeComments: boolean;
|
||||||
includeMilestones: boolean;
|
includeMilestones: boolean;
|
||||||
}
|
}
|
||||||
export declare const getWorkOrderByWorkOrderNumber: (workOrderNumber: string) => recordTypes.WorkOrder;
|
export declare function getWorkOrderByWorkOrderNumber(workOrderNumber: string): recordTypes.WorkOrder;
|
||||||
export declare const getWorkOrder: (workOrderId: number | string, options: WorkOrderOptions, connectedDatabase?: sqlite.Database) => recordTypes.WorkOrder;
|
export declare function getWorkOrder(workOrderId: number | string, options: WorkOrderOptions, connectedDatabase?: sqlite.Database): recordTypes.WorkOrder;
|
||||||
export default getWorkOrder;
|
export default getWorkOrder;
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,16 @@ import { getLots } from "./getLots.js";
|
||||||
import { getLotOccupancies } from "./getLotOccupancies.js";
|
import { getLotOccupancies } from "./getLotOccupancies.js";
|
||||||
import { getWorkOrderComments } from "./getWorkOrderComments.js";
|
import { getWorkOrderComments } from "./getWorkOrderComments.js";
|
||||||
import { getWorkOrderMilestones } from "./getWorkOrderMilestones.js";
|
import { getWorkOrderMilestones } from "./getWorkOrderMilestones.js";
|
||||||
const baseSQL = "select w.workOrderId," +
|
const baseSQL = `select w.workOrderId,
|
||||||
" w.workOrderTypeId, t.workOrderType," +
|
w.workOrderTypeId, t.workOrderType,
|
||||||
" w.workOrderNumber, w.workOrderDescription," +
|
w.workOrderNumber, w.workOrderDescription,
|
||||||
" w.workOrderOpenDate, userFn_dateIntegerToString(w.workOrderOpenDate) as workOrderOpenDateString," +
|
w.workOrderOpenDate, userFn_dateIntegerToString(w.workOrderOpenDate) as workOrderOpenDateString,
|
||||||
" w.workOrderCloseDate, userFn_dateIntegerToString(w.workOrderCloseDate) as workOrderCloseDateString," +
|
w.workOrderCloseDate, userFn_dateIntegerToString(w.workOrderCloseDate) as workOrderCloseDateString,
|
||||||
" w.recordCreate_timeMillis, w.recordUpdate_timeMillis" +
|
w.recordCreate_timeMillis, w.recordUpdate_timeMillis
|
||||||
" from WorkOrders w" +
|
from WorkOrders w
|
||||||
" left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId" +
|
left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId
|
||||||
" where w.recordDelete_timeMillis is null";
|
where w.recordDelete_timeMillis is null`;
|
||||||
const _getWorkOrder = (sql, workOrderId_or_workOrderNumber, options, connectedDatabase) => {
|
function _getWorkOrder(sql, workOrderId_or_workOrderNumber, options, connectedDatabase) {
|
||||||
const database = connectedDatabase ||
|
const database = connectedDatabase ||
|
||||||
sqlite(databasePath, {
|
sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
|
|
@ -55,15 +55,15 @@ const _getWorkOrder = (sql, workOrderId_or_workOrderNumber, options, connectedDa
|
||||||
database.close();
|
database.close();
|
||||||
}
|
}
|
||||||
return workOrder;
|
return workOrder;
|
||||||
};
|
}
|
||||||
export const getWorkOrderByWorkOrderNumber = (workOrderNumber) => {
|
export function getWorkOrderByWorkOrderNumber(workOrderNumber) {
|
||||||
return _getWorkOrder(baseSQL + " and w.workOrderNumber = ?", workOrderNumber, {
|
return _getWorkOrder(baseSQL + " and w.workOrderNumber = ?", workOrderNumber, {
|
||||||
includeLotsAndLotOccupancies: true,
|
includeLotsAndLotOccupancies: true,
|
||||||
includeComments: true,
|
includeComments: true,
|
||||||
includeMilestones: true
|
includeMilestones: true
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
export const getWorkOrder = (workOrderId, options, connectedDatabase) => {
|
export function getWorkOrder(workOrderId, options, connectedDatabase) {
|
||||||
return _getWorkOrder(baseSQL + " and w.workOrderId = ?", workOrderId, options, connectedDatabase);
|
return _getWorkOrder(baseSQL + " and w.workOrderId = ?", workOrderId, options, connectedDatabase);
|
||||||
};
|
}
|
||||||
export default getWorkOrder;
|
export default getWorkOrder;
|
||||||
|
|
|
||||||
|
|
@ -20,23 +20,22 @@ interface WorkOrderOptions {
|
||||||
includeMilestones: boolean;
|
includeMilestones: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseSQL =
|
const baseSQL = `select w.workOrderId,
|
||||||
"select w.workOrderId," +
|
w.workOrderTypeId, t.workOrderType,
|
||||||
" w.workOrderTypeId, t.workOrderType," +
|
w.workOrderNumber, w.workOrderDescription,
|
||||||
" w.workOrderNumber, w.workOrderDescription," +
|
w.workOrderOpenDate, userFn_dateIntegerToString(w.workOrderOpenDate) as workOrderOpenDateString,
|
||||||
" w.workOrderOpenDate, userFn_dateIntegerToString(w.workOrderOpenDate) as workOrderOpenDateString," +
|
w.workOrderCloseDate, userFn_dateIntegerToString(w.workOrderCloseDate) as workOrderCloseDateString,
|
||||||
" w.workOrderCloseDate, userFn_dateIntegerToString(w.workOrderCloseDate) as workOrderCloseDateString," +
|
w.recordCreate_timeMillis, w.recordUpdate_timeMillis
|
||||||
" w.recordCreate_timeMillis, w.recordUpdate_timeMillis" +
|
from WorkOrders w
|
||||||
" from WorkOrders w" +
|
left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId
|
||||||
" left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId" +
|
where w.recordDelete_timeMillis is null`;
|
||||||
" where w.recordDelete_timeMillis is null";
|
|
||||||
|
|
||||||
const _getWorkOrder = (
|
function _getWorkOrder(
|
||||||
sql: string,
|
sql: string,
|
||||||
workOrderId_or_workOrderNumber: number | string,
|
workOrderId_or_workOrderNumber: number | string,
|
||||||
options: WorkOrderOptions,
|
options: WorkOrderOptions,
|
||||||
connectedDatabase?: sqlite.Database
|
connectedDatabase?: sqlite.Database
|
||||||
): recordTypes.WorkOrder => {
|
): recordTypes.WorkOrder {
|
||||||
const database =
|
const database =
|
||||||
connectedDatabase ||
|
connectedDatabase ||
|
||||||
sqlite(databasePath, {
|
sqlite(databasePath, {
|
||||||
|
|
@ -101,33 +100,27 @@ const _getWorkOrder = (
|
||||||
}
|
}
|
||||||
|
|
||||||
return workOrder;
|
return workOrder;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getWorkOrderByWorkOrderNumber = (
|
export function getWorkOrderByWorkOrderNumber(workOrderNumber: string): recordTypes.WorkOrder {
|
||||||
workOrderNumber: string
|
return _getWorkOrder(baseSQL + " and w.workOrderNumber = ?", workOrderNumber, {
|
||||||
): recordTypes.WorkOrder => {
|
|
||||||
return _getWorkOrder(
|
|
||||||
baseSQL + " and w.workOrderNumber = ?",
|
|
||||||
workOrderNumber,
|
|
||||||
{
|
|
||||||
includeLotsAndLotOccupancies: true,
|
includeLotsAndLotOccupancies: true,
|
||||||
includeComments: true,
|
includeComments: true,
|
||||||
includeMilestones: true
|
includeMilestones: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getWorkOrder = (
|
export function getWorkOrder(
|
||||||
workOrderId: number | string,
|
workOrderId: number | string,
|
||||||
options: WorkOrderOptions,
|
options: WorkOrderOptions,
|
||||||
connectedDatabase?: sqlite.Database
|
connectedDatabase?: sqlite.Database
|
||||||
): recordTypes.WorkOrder => {
|
): recordTypes.WorkOrder {
|
||||||
return _getWorkOrder(
|
return _getWorkOrder(
|
||||||
baseSQL + " and w.workOrderId = ?",
|
baseSQL + " and w.workOrderId = ?",
|
||||||
workOrderId,
|
workOrderId,
|
||||||
options,
|
options,
|
||||||
connectedDatabase
|
connectedDatabase
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getWorkOrder;
|
export default getWorkOrder;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
export declare const getWorkOrderComments: (workOrderId: number | string, connectedDatabase?: sqlite.Database) => recordTypes.WorkOrderComment[];
|
export declare function getWorkOrderComments(workOrderId: number | string, connectedDatabase?: sqlite.Database): recordTypes.WorkOrderComment[];
|
||||||
export default getWorkOrderComments;
|
export default getWorkOrderComments;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { dateIntegerToString, timeIntegerToString } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateIntegerToString, timeIntegerToString } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||||
export const getWorkOrderComments = (workOrderId, connectedDatabase) => {
|
export function getWorkOrderComments(workOrderId, connectedDatabase) {
|
||||||
const database = connectedDatabase ||
|
const database = connectedDatabase ||
|
||||||
sqlite(databasePath, {
|
sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
|
|
@ -9,19 +9,19 @@ export const getWorkOrderComments = (workOrderId, connectedDatabase) => {
|
||||||
database.function("userFn_dateIntegerToString", dateIntegerToString);
|
database.function("userFn_dateIntegerToString", dateIntegerToString);
|
||||||
database.function("userFn_timeIntegerToString", timeIntegerToString);
|
database.function("userFn_timeIntegerToString", timeIntegerToString);
|
||||||
const workOrderComments = database
|
const workOrderComments = database
|
||||||
.prepare("select workOrderCommentId," +
|
.prepare(`select workOrderCommentId,
|
||||||
" workOrderCommentDate, userFn_dateIntegerToString(workOrderCommentDate) as workOrderCommentDateString," +
|
workOrderCommentDate, userFn_dateIntegerToString(workOrderCommentDate) as workOrderCommentDateString,
|
||||||
" workOrderCommentTime, userFn_timeIntegerToString(workOrderCommentTime) as workOrderCommentTimeString," +
|
workOrderCommentTime, userFn_timeIntegerToString(workOrderCommentTime) as workOrderCommentTimeString,
|
||||||
" workOrderComment," +
|
workOrderComment,
|
||||||
" recordCreate_userName, recordUpdate_userName" +
|
recordCreate_userName, recordUpdate_userName
|
||||||
" from WorkOrderComments" +
|
from WorkOrderComments
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and workOrderId = ?" +
|
and workOrderId = ?
|
||||||
" order by workOrderCommentDate desc, workOrderCommentTime desc, workOrderCommentId desc")
|
order by workOrderCommentDate desc, workOrderCommentTime desc, workOrderCommentId desc`)
|
||||||
.all(workOrderId);
|
.all(workOrderId);
|
||||||
if (!connectedDatabase) {
|
if (!connectedDatabase) {
|
||||||
database.close();
|
database.close();
|
||||||
}
|
}
|
||||||
return workOrderComments;
|
return workOrderComments;
|
||||||
};
|
}
|
||||||
export default getWorkOrderComments;
|
export default getWorkOrderComments;
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ import {
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
|
||||||
export const getWorkOrderComments = (
|
export function getWorkOrderComments(
|
||||||
workOrderId: number | string,
|
workOrderId: number | string,
|
||||||
connectedDatabase?: sqlite.Database
|
connectedDatabase?: sqlite.Database
|
||||||
): recordTypes.WorkOrderComment[] => {
|
): recordTypes.WorkOrderComment[] {
|
||||||
const database =
|
const database =
|
||||||
connectedDatabase ||
|
connectedDatabase ||
|
||||||
sqlite(databasePath, {
|
sqlite(databasePath, {
|
||||||
|
|
@ -24,15 +24,15 @@ export const getWorkOrderComments = (
|
||||||
|
|
||||||
const workOrderComments = database
|
const workOrderComments = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select workOrderCommentId," +
|
`select workOrderCommentId,
|
||||||
" workOrderCommentDate, userFn_dateIntegerToString(workOrderCommentDate) as workOrderCommentDateString," +
|
workOrderCommentDate, userFn_dateIntegerToString(workOrderCommentDate) as workOrderCommentDateString,
|
||||||
" workOrderCommentTime, userFn_timeIntegerToString(workOrderCommentTime) as workOrderCommentTimeString," +
|
workOrderCommentTime, userFn_timeIntegerToString(workOrderCommentTime) as workOrderCommentTimeString,
|
||||||
" workOrderComment," +
|
workOrderComment,
|
||||||
" recordCreate_userName, recordUpdate_userName" +
|
recordCreate_userName, recordUpdate_userName
|
||||||
" from WorkOrderComments" +
|
from WorkOrderComments
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and workOrderId = ?" +
|
and workOrderId = ?
|
||||||
" order by workOrderCommentDate desc, workOrderCommentTime desc, workOrderCommentId desc"
|
order by workOrderCommentDate desc, workOrderCommentTime desc, workOrderCommentId desc`
|
||||||
)
|
)
|
||||||
.all(workOrderId);
|
.all(workOrderId);
|
||||||
|
|
||||||
|
|
@ -41,6 +41,6 @@ export const getWorkOrderComments = (
|
||||||
}
|
}
|
||||||
|
|
||||||
return workOrderComments;
|
return workOrderComments;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getWorkOrderComments;
|
export default getWorkOrderComments;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
export declare const getWorkOrderMilestoneTypes: () => recordTypes.WorkOrderMilestoneType[];
|
export declare function getWorkOrderMilestoneTypes(): recordTypes.WorkOrderMilestoneType[];
|
||||||
export default getWorkOrderMilestoneTypes;
|
export default getWorkOrderMilestoneTypes;
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
export const getWorkOrderMilestoneTypes = () => {
|
export function getWorkOrderMilestoneTypes() {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const workOrderMilestoneTypes = database
|
const workOrderMilestoneTypes = database
|
||||||
.prepare("select workOrderMilestoneTypeId, workOrderMilestoneType, orderNumber" +
|
.prepare(`select workOrderMilestoneTypeId, workOrderMilestoneType, orderNumber
|
||||||
" from WorkOrderMilestoneTypes" +
|
from WorkOrderMilestoneTypes
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" order by orderNumber, workOrderMilestoneType")
|
order by orderNumber, workOrderMilestoneType`)
|
||||||
.all();
|
.all();
|
||||||
let expectedOrderNumber = 0;
|
let expectedOrderNumber = 0;
|
||||||
for (const workOrderMilestoneType of workOrderMilestoneTypes) {
|
for (const workOrderMilestoneType of workOrderMilestoneTypes) {
|
||||||
if (workOrderMilestoneType.orderNumber !== expectedOrderNumber) {
|
if (workOrderMilestoneType.orderNumber !== expectedOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare("update WorkOrderMilestoneTypes" +
|
.prepare(`update WorkOrderMilestoneTypes
|
||||||
" set orderNumber = ?" +
|
set orderNumber = ?
|
||||||
" where workOrderMilestoneTypeId = ?")
|
where workOrderMilestoneTypeId = ?`)
|
||||||
.run(expectedOrderNumber, workOrderMilestoneType.workOrderMilestoneTypeId);
|
.run(expectedOrderNumber, workOrderMilestoneType.workOrderMilestoneTypeId);
|
||||||
workOrderMilestoneType.orderNumber = expectedOrderNumber;
|
workOrderMilestoneType.orderNumber = expectedOrderNumber;
|
||||||
}
|
}
|
||||||
|
|
@ -22,5 +22,5 @@ export const getWorkOrderMilestoneTypes = () => {
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
return workOrderMilestoneTypes;
|
return workOrderMilestoneTypes;
|
||||||
};
|
}
|
||||||
export default getWorkOrderMilestoneTypes;
|
export default getWorkOrderMilestoneTypes;
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,15 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
|
||||||
export const getWorkOrderMilestoneTypes = (): recordTypes.WorkOrderMilestoneType[] => {
|
export function getWorkOrderMilestoneTypes(): recordTypes.WorkOrderMilestoneType[] {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const workOrderMilestoneTypes: recordTypes.WorkOrderMilestoneType[] = database
|
const workOrderMilestoneTypes: recordTypes.WorkOrderMilestoneType[] = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select workOrderMilestoneTypeId, workOrderMilestoneType, orderNumber" +
|
`select workOrderMilestoneTypeId, workOrderMilestoneType, orderNumber
|
||||||
" from WorkOrderMilestoneTypes" +
|
from WorkOrderMilestoneTypes
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" order by orderNumber, workOrderMilestoneType"
|
order by orderNumber, workOrderMilestoneType`
|
||||||
)
|
)
|
||||||
.all();
|
.all();
|
||||||
|
|
||||||
|
|
@ -22,9 +22,9 @@ export const getWorkOrderMilestoneTypes = (): recordTypes.WorkOrderMilestoneType
|
||||||
if (workOrderMilestoneType.orderNumber !== expectedOrderNumber) {
|
if (workOrderMilestoneType.orderNumber !== expectedOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update WorkOrderMilestoneTypes" +
|
`update WorkOrderMilestoneTypes
|
||||||
" set orderNumber = ?" +
|
set orderNumber = ?
|
||||||
" where workOrderMilestoneTypeId = ?"
|
where workOrderMilestoneTypeId = ?`
|
||||||
)
|
)
|
||||||
.run(expectedOrderNumber, workOrderMilestoneType.workOrderMilestoneTypeId);
|
.run(expectedOrderNumber, workOrderMilestoneType.workOrderMilestoneTypeId);
|
||||||
|
|
||||||
|
|
@ -37,6 +37,6 @@ export const getWorkOrderMilestoneTypes = (): recordTypes.WorkOrderMilestoneType
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return workOrderMilestoneTypes;
|
return workOrderMilestoneTypes;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getWorkOrderMilestoneTypes;
|
export default getWorkOrderMilestoneTypes;
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ interface WorkOrderMilestoneOptions {
|
||||||
includeWorkOrders?: boolean;
|
includeWorkOrders?: boolean;
|
||||||
orderBy: "completion" | "date";
|
orderBy: "completion" | "date";
|
||||||
}
|
}
|
||||||
export declare const getWorkOrderMilestones: (filters: WorkOrderMilestoneFilters, options: WorkOrderMilestoneOptions, connectedDatabase?: sqlite.Database) => recordTypes.WorkOrderMilestone[];
|
export declare function getWorkOrderMilestones(filters: WorkOrderMilestoneFilters, options: WorkOrderMilestoneOptions, connectedDatabase?: sqlite.Database): recordTypes.WorkOrderMilestone[];
|
||||||
export default getWorkOrderMilestones;
|
export default getWorkOrderMilestones;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import * as configFunctions from "../functions.config.js";
|
||||||
import { getLots } from "./getLots.js";
|
import { getLots } from "./getLots.js";
|
||||||
import { getLotOccupancies } from "./getLotOccupancies.js";
|
import { getLotOccupancies } from "./getLotOccupancies.js";
|
||||||
const commaSeparatedNumbersRegex = /^\d+(,\d+)*$/;
|
const commaSeparatedNumbersRegex = /^\d+(,\d+)*$/;
|
||||||
const buildWhereClause = (filters) => {
|
function buildWhereClause(filters) {
|
||||||
let sqlWhereClause = " where m.recordDelete_timeMillis is null and w.recordDelete_timeMillis is null";
|
let sqlWhereClause = " where m.recordDelete_timeMillis is null and w.recordDelete_timeMillis is null";
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
if (filters.workOrderId) {
|
if (filters.workOrderId) {
|
||||||
|
|
@ -51,8 +51,8 @@ const buildWhereClause = (filters) => {
|
||||||
sqlWhereClause,
|
sqlWhereClause,
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
export const getWorkOrderMilestones = (filters, options, connectedDatabase) => {
|
export function getWorkOrderMilestones(filters, options, connectedDatabase) {
|
||||||
const database = connectedDatabase ||
|
const database = connectedDatabase ||
|
||||||
sqlite(databasePath, {
|
sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
|
|
@ -122,5 +122,5 @@ export const getWorkOrderMilestones = (filters, options, connectedDatabase) => {
|
||||||
database.close();
|
database.close();
|
||||||
}
|
}
|
||||||
return workOrderMilestones;
|
return workOrderMilestones;
|
||||||
};
|
}
|
||||||
export default getWorkOrderMilestones;
|
export default getWorkOrderMilestones;
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,10 @@ interface WorkOrderMilestoneOptions {
|
||||||
|
|
||||||
const commaSeparatedNumbersRegex = /^\d+(,\d+)*$/;
|
const commaSeparatedNumbersRegex = /^\d+(,\d+)*$/;
|
||||||
|
|
||||||
const buildWhereClause = (
|
function buildWhereClause(filters: WorkOrderMilestoneFilters): {
|
||||||
filters: WorkOrderMilestoneFilters
|
sqlWhereClause: string;
|
||||||
): { sqlWhereClause: string; sqlParameters: unknown[] } => {
|
sqlParameters: unknown[];
|
||||||
|
} {
|
||||||
let sqlWhereClause =
|
let sqlWhereClause =
|
||||||
" where m.recordDelete_timeMillis is null and w.recordDelete_timeMillis is null";
|
" where m.recordDelete_timeMillis is null and w.recordDelete_timeMillis is null";
|
||||||
const sqlParameters: unknown[] = [];
|
const sqlParameters: unknown[] = [];
|
||||||
|
|
@ -102,13 +103,13 @@ const buildWhereClause = (
|
||||||
sqlWhereClause,
|
sqlWhereClause,
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getWorkOrderMilestones = (
|
export function getWorkOrderMilestones(
|
||||||
filters: WorkOrderMilestoneFilters,
|
filters: WorkOrderMilestoneFilters,
|
||||||
options: WorkOrderMilestoneOptions,
|
options: WorkOrderMilestoneOptions,
|
||||||
connectedDatabase?: sqlite.Database
|
connectedDatabase?: sqlite.Database
|
||||||
): recordTypes.WorkOrderMilestone[] => {
|
): recordTypes.WorkOrderMilestone[] {
|
||||||
const database =
|
const database =
|
||||||
connectedDatabase ||
|
connectedDatabase ||
|
||||||
sqlite(databasePath, {
|
sqlite(databasePath, {
|
||||||
|
|
@ -119,11 +120,9 @@ export const getWorkOrderMilestones = (
|
||||||
database.function("userFn_timeIntegerToString", timeIntegerToString);
|
database.function("userFn_timeIntegerToString", timeIntegerToString);
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
|
|
||||||
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
const { sqlWhereClause, sqlParameters } = buildWhereClause(filters);
|
||||||
|
|
||||||
// Order By
|
// Order By
|
||||||
|
|
||||||
let orderByClause = "";
|
let orderByClause = "";
|
||||||
|
|
||||||
switch (options.orderBy) {
|
switch (options.orderBy) {
|
||||||
|
|
@ -145,7 +144,6 @@ export const getWorkOrderMilestones = (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query
|
// Query
|
||||||
|
|
||||||
const sql =
|
const sql =
|
||||||
"select m.workOrderMilestoneId," +
|
"select m.workOrderMilestoneId," +
|
||||||
" m.workOrderMilestoneTypeId, t.workOrderMilestoneType," +
|
" m.workOrderMilestoneTypeId, t.workOrderMilestoneType," +
|
||||||
|
|
@ -205,6 +203,6 @@ export const getWorkOrderMilestones = (
|
||||||
}
|
}
|
||||||
|
|
||||||
return workOrderMilestones;
|
return workOrderMilestones;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getWorkOrderMilestones;
|
export default getWorkOrderMilestones;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
export declare const getWorkOrderTypes: () => recordTypes.WorkOrderType[];
|
export declare function getWorkOrderTypes(): recordTypes.WorkOrderType[];
|
||||||
export default getWorkOrderTypes;
|
export default getWorkOrderTypes;
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
export const getWorkOrderTypes = () => {
|
export function getWorkOrderTypes() {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const workOrderTypes = database
|
const workOrderTypes = database
|
||||||
.prepare("select workOrderTypeId, workOrderType, orderNumber" +
|
.prepare(`select workOrderTypeId, workOrderType, orderNumber
|
||||||
" from WorkOrderTypes" +
|
from WorkOrderTypes
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" order by orderNumber, workOrderType")
|
order by orderNumber, workOrderType`)
|
||||||
.all();
|
.all();
|
||||||
let expectedOrderNumber = 0;
|
let expectedOrderNumber = 0;
|
||||||
for (const workOrderType of workOrderTypes) {
|
for (const workOrderType of workOrderTypes) {
|
||||||
if (workOrderType.orderNumber !== expectedOrderNumber) {
|
if (workOrderType.orderNumber !== expectedOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare("update WorkOrderTypes" +
|
.prepare(`update WorkOrderTypes set orderNumber = ? where workOrderTypeId = ?`)
|
||||||
" set orderNumber = ?" +
|
|
||||||
" where workOrderTypeId = ?")
|
|
||||||
.run(expectedOrderNumber, workOrderType.workOrderTypeId);
|
.run(expectedOrderNumber, workOrderType.workOrderTypeId);
|
||||||
workOrderType.orderNumber = expectedOrderNumber;
|
workOrderType.orderNumber = expectedOrderNumber;
|
||||||
}
|
}
|
||||||
|
|
@ -22,5 +20,5 @@ export const getWorkOrderTypes = () => {
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
return workOrderTypes;
|
return workOrderTypes;
|
||||||
};
|
}
|
||||||
export default getWorkOrderTypes;
|
export default getWorkOrderTypes;
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,15 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
|
||||||
export const getWorkOrderTypes = (): recordTypes.WorkOrderType[] => {
|
export function getWorkOrderTypes(): recordTypes.WorkOrderType[] {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const workOrderTypes: recordTypes.WorkOrderType[] = database
|
const workOrderTypes: recordTypes.WorkOrderType[] = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select workOrderTypeId, workOrderType, orderNumber" +
|
`select workOrderTypeId, workOrderType, orderNumber
|
||||||
" from WorkOrderTypes" +
|
from WorkOrderTypes
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" order by orderNumber, workOrderType"
|
order by orderNumber, workOrderType`
|
||||||
)
|
)
|
||||||
.all();
|
.all();
|
||||||
|
|
||||||
|
|
@ -21,11 +21,7 @@ export const getWorkOrderTypes = (): recordTypes.WorkOrderType[] => {
|
||||||
for (const workOrderType of workOrderTypes) {
|
for (const workOrderType of workOrderTypes) {
|
||||||
if (workOrderType.orderNumber !== expectedOrderNumber) {
|
if (workOrderType.orderNumber !== expectedOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(`update WorkOrderTypes set orderNumber = ? where workOrderTypeId = ?`)
|
||||||
"update WorkOrderTypes" +
|
|
||||||
" set orderNumber = ?" +
|
|
||||||
" where workOrderTypeId = ?"
|
|
||||||
)
|
|
||||||
.run(expectedOrderNumber, workOrderType.workOrderTypeId);
|
.run(expectedOrderNumber, workOrderType.workOrderTypeId);
|
||||||
|
|
||||||
workOrderType.orderNumber = expectedOrderNumber;
|
workOrderType.orderNumber = expectedOrderNumber;
|
||||||
|
|
@ -37,6 +33,6 @@ export const getWorkOrderTypes = (): recordTypes.WorkOrderType[] => {
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return workOrderTypes;
|
return workOrderTypes;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getWorkOrderTypes;
|
export default getWorkOrderTypes;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ interface GetWorkOrdersOptions {
|
||||||
includeComments?: boolean;
|
includeComments?: boolean;
|
||||||
includeMilestones?: boolean;
|
includeMilestones?: boolean;
|
||||||
}
|
}
|
||||||
export declare const getWorkOrders: (filters: GetWorkOrdersFilters, options?: GetWorkOrdersOptions, connectedDatabase?: sqlite.Database) => {
|
export declare function getWorkOrders(filters: GetWorkOrdersFilters, options?: GetWorkOrdersOptions, connectedDatabase?: sqlite.Database): {
|
||||||
count: number;
|
count: number;
|
||||||
workOrders: recordTypes.WorkOrder[];
|
workOrders: recordTypes.WorkOrder[];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { getLots } from "./getLots.js";
|
||||||
import { getLotOccupancies } from "./getLotOccupancies.js";
|
import { getLotOccupancies } from "./getLotOccupancies.js";
|
||||||
import { getWorkOrderMilestones } from "./getWorkOrderMilestones.js";
|
import { getWorkOrderMilestones } from "./getWorkOrderMilestones.js";
|
||||||
import { getLotNameWhereClause, getOccupantNameWhereClause } from "../functions.sqlFilters.js";
|
import { getLotNameWhereClause, getOccupantNameWhereClause } from "../functions.sqlFilters.js";
|
||||||
const buildWhereClause = (filters) => {
|
function buildWhereClause(filters) {
|
||||||
let sqlWhereClause = " where w.recordDelete_timeMillis is null";
|
let sqlWhereClause = " where w.recordDelete_timeMillis is null";
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
if (filters.workOrderTypeId) {
|
if (filters.workOrderTypeId) {
|
||||||
|
|
@ -55,8 +55,8 @@ const buildWhereClause = (filters) => {
|
||||||
sqlWhereClause,
|
sqlWhereClause,
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
export const getWorkOrders = (filters, options, connectedDatabase) => {
|
export function getWorkOrders(filters, options, connectedDatabase) {
|
||||||
const database = connectedDatabase ||
|
const database = connectedDatabase ||
|
||||||
sqlite(databasePath, {
|
sqlite(databasePath, {
|
||||||
readonly: true
|
readonly: true
|
||||||
|
|
@ -128,5 +128,5 @@ export const getWorkOrders = (filters, options, connectedDatabase) => {
|
||||||
count,
|
count,
|
||||||
workOrders
|
workOrders
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
export default getWorkOrders;
|
export default getWorkOrders;
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,10 @@ interface GetWorkOrdersOptions {
|
||||||
includeMilestones?: boolean;
|
includeMilestones?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildWhereClause = (
|
function buildWhereClause(filters: GetWorkOrdersFilters): {
|
||||||
filters: GetWorkOrdersFilters
|
sqlWhereClause: string;
|
||||||
): { sqlWhereClause: string; sqlParameters: unknown[] } => {
|
sqlParameters: unknown[];
|
||||||
|
} {
|
||||||
let sqlWhereClause = " where w.recordDelete_timeMillis is null";
|
let sqlWhereClause = " where w.recordDelete_timeMillis is null";
|
||||||
const sqlParameters: unknown[] = [];
|
const sqlParameters: unknown[] = [];
|
||||||
|
|
||||||
|
|
@ -89,16 +90,16 @@ const buildWhereClause = (
|
||||||
sqlWhereClause,
|
sqlWhereClause,
|
||||||
sqlParameters
|
sqlParameters
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getWorkOrders = (
|
export function getWorkOrders(
|
||||||
filters: GetWorkOrdersFilters,
|
filters: GetWorkOrdersFilters,
|
||||||
options?: GetWorkOrdersOptions,
|
options?: GetWorkOrdersOptions,
|
||||||
connectedDatabase?: sqlite.Database
|
connectedDatabase?: sqlite.Database
|
||||||
): {
|
): {
|
||||||
count: number;
|
count: number;
|
||||||
workOrders: recordTypes.WorkOrder[];
|
workOrders: recordTypes.WorkOrder[];
|
||||||
} => {
|
} {
|
||||||
const database =
|
const database =
|
||||||
connectedDatabase ||
|
connectedDatabase ||
|
||||||
sqlite(databasePath, {
|
sqlite(databasePath, {
|
||||||
|
|
@ -201,6 +202,6 @@ export const getWorkOrders = (
|
||||||
count,
|
count,
|
||||||
workOrders
|
workOrders
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
export default getWorkOrders;
|
export default getWorkOrders;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveFeeCategoryDown: (feeCategoryId: number | string) => boolean;
|
export declare function moveFeeCategoryDown(feeCategoryId: number | string): boolean;
|
||||||
export declare const moveFeeCategoryDownToBottom: (feeCategoryId: number | string) => boolean;
|
export declare function moveFeeCategoryDownToBottom(feeCategoryId: number | string): boolean;
|
||||||
export default moveFeeCategoryDown;
|
export default moveFeeCategoryDown;
|
||||||
|
|
|
||||||
|
|
@ -1,44 +1,44 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
export const moveFeeCategoryDown = (feeCategoryId) => {
|
export function moveFeeCategoryDown(feeCategoryId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
||||||
.get(feeCategoryId).orderNumber;
|
.get(feeCategoryId).orderNumber;
|
||||||
database
|
database
|
||||||
.prepare("update FeeCategories" +
|
.prepare(`update FeeCategories
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? + 1")
|
and orderNumber = ? + 1`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update FeeCategories set orderNumber = ? + 1 where feeCategoryId = ?")
|
.prepare("update FeeCategories set orderNumber = ? + 1 where feeCategoryId = ?")
|
||||||
.run(currentOrderNumber, feeCategoryId);
|
.run(currentOrderNumber, feeCategoryId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
export const moveFeeCategoryDownToBottom = (feeCategoryId) => {
|
export function moveFeeCategoryDownToBottom(feeCategoryId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
||||||
.get(feeCategoryId).orderNumber;
|
.get(feeCategoryId).orderNumber;
|
||||||
const maxOrderNumber = database
|
const maxOrderNumber = database
|
||||||
.prepare("select max(orderNumber) as maxOrderNumber" +
|
.prepare(`select max(orderNumber) as maxOrderNumber
|
||||||
" from FeeCategories" +
|
from FeeCategories
|
||||||
" where recordDelete_timeMillis is null")
|
where recordDelete_timeMillis is null`)
|
||||||
.get().maxOrderNumber;
|
.get().maxOrderNumber;
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
if (currentOrderNumber !== maxOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare("update FeeCategories set orderNumber = ? + 1 where feeCategoryId = ?")
|
.prepare("update FeeCategories set orderNumber = ? + 1 where feeCategoryId = ?")
|
||||||
.run(maxOrderNumber, feeCategoryId);
|
.run(maxOrderNumber, feeCategoryId);
|
||||||
database
|
database
|
||||||
.prepare("update FeeCategories" +
|
.prepare(`update FeeCategories
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null and
|
||||||
" and orderNumber > ?")
|
orderNumber > ?`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export default moveFeeCategoryDown;
|
export default moveFeeCategoryDown;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import sqlite from "better-sqlite3";
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
export const moveFeeCategoryDown = (feeCategoryId: number | string): boolean => {
|
export function moveFeeCategoryDown(feeCategoryId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
|
|
@ -11,10 +11,10 @@ export const moveFeeCategoryDown = (feeCategoryId: number | string): boolean =>
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update FeeCategories" +
|
`update FeeCategories
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? + 1"
|
and orderNumber = ? + 1`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
|
|
@ -25,9 +25,9 @@ export const moveFeeCategoryDown = (feeCategoryId: number | string): boolean =>
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const moveFeeCategoryDownToBottom = (feeCategoryId: number | string): boolean => {
|
export function moveFeeCategoryDownToBottom(feeCategoryId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
|
|
@ -36,9 +36,9 @@ export const moveFeeCategoryDownToBottom = (feeCategoryId: number | string): boo
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
const maxOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select max(orderNumber) as maxOrderNumber" +
|
`select max(orderNumber) as maxOrderNumber
|
||||||
" from FeeCategories" +
|
from FeeCategories
|
||||||
" where recordDelete_timeMillis is null"
|
where recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.get().maxOrderNumber;
|
.get().maxOrderNumber;
|
||||||
|
|
||||||
|
|
@ -49,10 +49,10 @@ export const moveFeeCategoryDownToBottom = (feeCategoryId: number | string): boo
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update FeeCategories" +
|
`update FeeCategories
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null and
|
||||||
" and orderNumber > ?"
|
orderNumber > ?`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -60,6 +60,6 @@ export const moveFeeCategoryDownToBottom = (feeCategoryId: number | string): boo
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default moveFeeCategoryDown;
|
export default moveFeeCategoryDown;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveFeeCategoryUp: (feeCategoryId: number | string) => boolean;
|
export declare function moveFeeCategoryUp(feeCategoryId: number | string): boolean;
|
||||||
export declare const moveFeeCategoryUpToTop: (feeCategoryId: number | string) => boolean;
|
export declare function moveFeeCategoryUpToTop(feeCategoryId: number | string): boolean;
|
||||||
export default moveFeeCategoryUp;
|
export default moveFeeCategoryUp;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
export const moveFeeCategoryUp = (feeCategoryId) => {
|
export function moveFeeCategoryUp(feeCategoryId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
||||||
|
|
@ -10,18 +10,18 @@ export const moveFeeCategoryUp = (feeCategoryId) => {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
database
|
database
|
||||||
.prepare("update FeeCategories" +
|
.prepare(`update FeeCategories
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? - 1")
|
and orderNumber = ? - 1`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update FeeCategories set orderNumber = ? - 1 where feeCategoryId = ?")
|
.prepare("update FeeCategories set orderNumber = ? - 1 where feeCategoryId = ?")
|
||||||
.run(currentOrderNumber, feeCategoryId);
|
.run(currentOrderNumber, feeCategoryId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
export const moveFeeCategoryUpToTop = (feeCategoryId) => {
|
export function moveFeeCategoryUpToTop(feeCategoryId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
||||||
|
|
@ -31,13 +31,13 @@ export const moveFeeCategoryUpToTop = (feeCategoryId) => {
|
||||||
.prepare("update FeeCategories set orderNumber = -1 where feeCategoryId = ?")
|
.prepare("update FeeCategories set orderNumber = -1 where feeCategoryId = ?")
|
||||||
.run(feeCategoryId);
|
.run(feeCategoryId);
|
||||||
database
|
database
|
||||||
.prepare("update FeeCategories" +
|
.prepare(`update FeeCategories
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber < ?")
|
and orderNumber < ?`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export default moveFeeCategoryUp;
|
export default moveFeeCategoryUp;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import sqlite from "better-sqlite3";
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
export const moveFeeCategoryUp = (feeCategoryId: number | string): boolean => {
|
export function moveFeeCategoryUp(feeCategoryId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
|
|
@ -16,10 +16,10 @@ export const moveFeeCategoryUp = (feeCategoryId: number | string): boolean => {
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update FeeCategories" +
|
`update FeeCategories
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? - 1"
|
and orderNumber = ? - 1`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
|
|
@ -30,9 +30,9 @@ export const moveFeeCategoryUp = (feeCategoryId: number | string): boolean => {
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const moveFeeCategoryUpToTop = (feeCategoryId: number | string): boolean => {
|
export function moveFeeCategoryUpToTop(feeCategoryId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
|
|
@ -46,10 +46,10 @@ export const moveFeeCategoryUpToTop = (feeCategoryId: number | string): boolean
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update FeeCategories" +
|
`update FeeCategories
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber < ?"
|
and orderNumber < ?`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -57,6 +57,6 @@ export const moveFeeCategoryUpToTop = (feeCategoryId: number | string): boolean
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default moveFeeCategoryUp;
|
export default moveFeeCategoryUp;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveFeeDown: (feeId: number | string) => boolean;
|
export declare function moveFeeDown(feeId: number | string): boolean;
|
||||||
export declare const moveFeeDownToBottom: (feeId: number | string) => boolean;
|
export declare function moveFeeDownToBottom(feeId: number | string): boolean;
|
||||||
export default moveFeeDown;
|
export default moveFeeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,44 +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 { getFee } from "./getFee.js";
|
import { getFee } from "./getFee.js";
|
||||||
export const moveFeeDown = (feeId) => {
|
export function moveFeeDown(feeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database);
|
||||||
database
|
database
|
||||||
.prepare("update Fees" +
|
.prepare(`update Fees
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and feeCategoryId = ?" +
|
and feeCategoryId = ?
|
||||||
" and orderNumber = ? + 1")
|
and orderNumber = ? + 1`)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update Fees set orderNumber = ? + 1 where feeId = ?")
|
.prepare("update Fees set orderNumber = ? + 1 where feeId = ?")
|
||||||
.run(currentFee.orderNumber, feeId);
|
.run(currentFee.orderNumber, feeId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
export const moveFeeDownToBottom = (feeId) => {
|
export function moveFeeDownToBottom(feeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database);
|
||||||
const maxOrderNumber = database
|
const maxOrderNumber = database
|
||||||
.prepare("select max(orderNumber) as maxOrderNumber" +
|
.prepare(`select max(orderNumber) as maxOrderNumber
|
||||||
" from Fees" +
|
from Fees
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and feeCategoryId = ?")
|
and feeCategoryId = ?`)
|
||||||
.get(currentFee.feeCategoryId).maxOrderNumber;
|
.get(currentFee.feeCategoryId).maxOrderNumber;
|
||||||
if (currentFee.orderNumber !== maxOrderNumber) {
|
if (currentFee.orderNumber !== maxOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare("update Fees set orderNumber = ? + 1 where feeId = ?")
|
.prepare("update Fees set orderNumber = ? + 1 where feeId = ?")
|
||||||
.run(maxOrderNumber, feeId);
|
.run(maxOrderNumber, feeId);
|
||||||
database
|
database
|
||||||
.prepare("update Fees" +
|
.prepare(`update Fees
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and feeCategoryId = ?" +
|
and feeCategoryId = ? and orderNumber > ?`)
|
||||||
" and orderNumber > ?")
|
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export default moveFeeDown;
|
export default moveFeeDown;
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,18 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { getFee } from "./getFee.js";
|
import { getFee } from "./getFee.js";
|
||||||
|
|
||||||
export const moveFeeDown = (feeId: number | string): boolean => {
|
export function moveFeeDown(feeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database);
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update Fees" +
|
`update Fees
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and feeCategoryId = ?" +
|
and feeCategoryId = ?
|
||||||
" and orderNumber = ? + 1"
|
and orderNumber = ? + 1`
|
||||||
)
|
)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
||||||
|
|
||||||
|
|
@ -26,19 +26,19 @@ export const moveFeeDown = (feeId: number | string): boolean => {
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const moveFeeDownToBottom = (feeId: number | string): boolean => {
|
export function moveFeeDownToBottom(feeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database);
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
const maxOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select max(orderNumber) as maxOrderNumber" +
|
`select max(orderNumber) as maxOrderNumber
|
||||||
" from Fees" +
|
from Fees
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and feeCategoryId = ?"
|
and feeCategoryId = ?`
|
||||||
)
|
)
|
||||||
.get(currentFee.feeCategoryId).maxOrderNumber;
|
.get(currentFee.feeCategoryId).maxOrderNumber;
|
||||||
|
|
||||||
|
|
@ -49,11 +49,10 @@ export const moveFeeDownToBottom = (feeId: number | string): boolean => {
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update Fees" +
|
`update Fees
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and feeCategoryId = ?" +
|
and feeCategoryId = ? and orderNumber > ?`
|
||||||
" and orderNumber > ?"
|
|
||||||
)
|
)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -61,6 +60,6 @@ export const moveFeeDownToBottom = (feeId: number | string): boolean => {
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default moveFeeDown;
|
export default moveFeeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveFeeUp: (feeId: number | string) => boolean;
|
export declare function moveFeeUp(feeId: number | string): boolean;
|
||||||
export declare const moveFeeUpToTop: (feeId: number | string) => boolean;
|
export declare function moveFeeUpToTop(feeId: number | string): boolean;
|
||||||
export default moveFeeUp;
|
export default moveFeeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { getFee } from "./getFee.js";
|
import { getFee } from "./getFee.js";
|
||||||
export const moveFeeUp = (feeId) => {
|
export function moveFeeUp(feeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database);
|
||||||
if (currentFee.orderNumber <= 0) {
|
if (currentFee.orderNumber <= 0) {
|
||||||
|
|
@ -9,32 +9,32 @@ export const moveFeeUp = (feeId) => {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
database
|
database
|
||||||
.prepare("update Fees" +
|
.prepare(`update Fees
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and feeCategoryId = ?" +
|
and feeCategoryId = ?
|
||||||
" and orderNumber = ? - 1")
|
and orderNumber = ? - 1`)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update Fees set orderNumber = ? - 1 where feeId = ?")
|
.prepare("update Fees set orderNumber = ? - 1 where feeId = ?")
|
||||||
.run(currentFee.orderNumber, feeId);
|
.run(currentFee.orderNumber, feeId);
|
||||||
database.close();
|
database.close();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
export const moveFeeUpToTop = (feeId) => {
|
export function moveFeeUpToTop(feeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database);
|
||||||
if (currentFee.orderNumber > 0) {
|
if (currentFee.orderNumber > 0) {
|
||||||
database.prepare("update Fees set orderNumber = -1 where feeId = ?").run(feeId);
|
database.prepare("update Fees set orderNumber = -1 where feeId = ?").run(feeId);
|
||||||
database
|
database
|
||||||
.prepare("update Fees" +
|
.prepare(`update Fees
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and feeCategoryId = ?" +
|
and feeCategoryId = ?
|
||||||
" and orderNumber < ?")
|
and orderNumber < ?`)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export default moveFeeUp;
|
export default moveFeeUp;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { getFee } from "./getFee.js";
|
import { getFee } from "./getFee.js";
|
||||||
|
|
||||||
export const moveFeeUp = (feeId: number | string): boolean => {
|
export function moveFeeUp(feeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database);
|
||||||
|
|
@ -16,11 +16,11 @@ export const moveFeeUp = (feeId: number | string): boolean => {
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update Fees" +
|
`update Fees
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and feeCategoryId = ?" +
|
and feeCategoryId = ?
|
||||||
" and orderNumber = ? - 1"
|
and orderNumber = ? - 1`
|
||||||
)
|
)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
||||||
|
|
||||||
|
|
@ -31,9 +31,9 @@ export const moveFeeUp = (feeId: number | string): boolean => {
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const moveFeeUpToTop = (feeId: number | string): boolean => {
|
export function moveFeeUpToTop(feeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentFee = getFee(feeId, database);
|
const currentFee = getFee(feeId, database);
|
||||||
|
|
@ -43,11 +43,11 @@ export const moveFeeUpToTop = (feeId: number | string): boolean => {
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update Fees" +
|
`update Fees
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and feeCategoryId = ?" +
|
and feeCategoryId = ?
|
||||||
" and orderNumber < ?"
|
and orderNumber < ?`
|
||||||
)
|
)
|
||||||
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
.run(currentFee.feeCategoryId, currentFee.orderNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -55,6 +55,6 @@ export const moveFeeUpToTop = (feeId: number | string): boolean => {
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default moveFeeUp;
|
export default moveFeeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveLotOccupantTypeDown: (lotOccupantTypeId: number | string) => boolean;
|
export declare function moveLotOccupantTypeDown(lotOccupantTypeId: number | string): boolean;
|
||||||
export declare const moveLotOccupantTypeDownToBottom: (lotOccupantTypeId: number | string) => boolean;
|
export declare function moveLotOccupantTypeDownToBottom(lotOccupantTypeId: number | string): boolean;
|
||||||
export default moveLotOccupantTypeDown;
|
export default moveLotOccupantTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,47 @@
|
||||||
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 { clearLotOccupantTypesCache } from "../functions.cache.js";
|
import { clearLotOccupantTypesCache } from "../functions.cache.js";
|
||||||
export const moveLotOccupantTypeDown = (lotOccupantTypeId) => {
|
export function moveLotOccupantTypeDown(lotOccupantTypeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber" +
|
.prepare(`select orderNumber from LotOccupantTypes where lotOccupantTypeId = ?`)
|
||||||
" from LotOccupantTypes" +
|
|
||||||
" where lotOccupantTypeId = ?")
|
|
||||||
.get(lotOccupantTypeId).orderNumber;
|
.get(lotOccupantTypeId).orderNumber;
|
||||||
database
|
database
|
||||||
.prepare("update LotOccupantTypes" +
|
.prepare(`update LotOccupantTypes
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? + 1")
|
and orderNumber = ? + 1`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update LotOccupantTypes" +
|
.prepare(`update LotOccupantTypes set orderNumber = ? + 1 where lotOccupantTypeId = ?`)
|
||||||
" set orderNumber = ? + 1" +
|
|
||||||
" where lotOccupantTypeId = ?")
|
|
||||||
.run(currentOrderNumber, lotOccupantTypeId);
|
.run(currentOrderNumber, lotOccupantTypeId);
|
||||||
database.close();
|
database.close();
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
export const moveLotOccupantTypeDownToBottom = (lotOccupantTypeId) => {
|
export function moveLotOccupantTypeDownToBottom(lotOccupantTypeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber from LotOccupantTypes where lotOccupantTypeId = ?")
|
.prepare("select orderNumber from LotOccupantTypes where lotOccupantTypeId = ?")
|
||||||
.get(lotOccupantTypeId).orderNumber;
|
.get(lotOccupantTypeId).orderNumber;
|
||||||
const maxOrderNumber = database
|
const maxOrderNumber = database
|
||||||
.prepare("select max(orderNumber) as maxOrderNumber" +
|
.prepare(`select max(orderNumber) as maxOrderNumber
|
||||||
" from LotOccupantTypes" +
|
from LotOccupantTypes
|
||||||
" where recordDelete_timeMillis is null")
|
where recordDelete_timeMillis is null`)
|
||||||
.get().maxOrderNumber;
|
.get().maxOrderNumber;
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
if (currentOrderNumber !== maxOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare("update LotOccupantTypes set orderNumber = ? + 1 where lotOccupantTypeId = ?")
|
.prepare("update LotOccupantTypes set orderNumber = ? + 1 where lotOccupantTypeId = ?")
|
||||||
.run(maxOrderNumber, lotOccupantTypeId);
|
.run(maxOrderNumber, lotOccupantTypeId);
|
||||||
database
|
database
|
||||||
.prepare("update LotOccupantTypes" +
|
.prepare(`update LotOccupantTypes
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber > ?")
|
and orderNumber > ?`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export default moveLotOccupantTypeDown;
|
export default moveLotOccupantTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -4,34 +4,24 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearLotOccupantTypesCache } from "../functions.cache.js";
|
import { clearLotOccupantTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export const moveLotOccupantTypeDown = (
|
export function moveLotOccupantTypeDown(lotOccupantTypeId: number | string): boolean {
|
||||||
lotOccupantTypeId: number | string
|
|
||||||
): boolean => {
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(`select orderNumber from LotOccupantTypes where lotOccupantTypeId = ?`)
|
||||||
"select orderNumber" +
|
|
||||||
" from LotOccupantTypes" +
|
|
||||||
" where lotOccupantTypeId = ?"
|
|
||||||
)
|
|
||||||
.get(lotOccupantTypeId).orderNumber;
|
.get(lotOccupantTypeId).orderNumber;
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotOccupantTypes" +
|
`update LotOccupantTypes
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? + 1"
|
and orderNumber = ? + 1`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(`update LotOccupantTypes set orderNumber = ? + 1 where lotOccupantTypeId = ?`)
|
||||||
"update LotOccupantTypes" +
|
|
||||||
" set orderNumber = ? + 1" +
|
|
||||||
" where lotOccupantTypeId = ?"
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber, lotOccupantTypeId);
|
.run(currentOrderNumber, lotOccupantTypeId);
|
||||||
|
|
||||||
database.close();
|
database.close();
|
||||||
|
|
@ -39,10 +29,9 @@ export const moveLotOccupantTypeDown = (
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export function moveLotOccupantTypeDownToBottom(lotOccupantTypeId: number | string): boolean {
|
||||||
export const moveLotOccupantTypeDownToBottom = (lotOccupantTypeId: number | string): boolean => {
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
|
|
@ -51,9 +40,9 @@ export const moveLotOccupantTypeDownToBottom = (lotOccupantTypeId: number | stri
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
const maxOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select max(orderNumber) as maxOrderNumber" +
|
`select max(orderNumber) as maxOrderNumber
|
||||||
" from LotOccupantTypes" +
|
from LotOccupantTypes
|
||||||
" where recordDelete_timeMillis is null"
|
where recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.get().maxOrderNumber;
|
.get().maxOrderNumber;
|
||||||
|
|
||||||
|
|
@ -64,10 +53,10 @@ export const moveLotOccupantTypeDownToBottom = (lotOccupantTypeId: number | stri
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotOccupantTypes" +
|
`update LotOccupantTypes
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber > ?"
|
and orderNumber > ?`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -77,5 +66,6 @@ export const moveLotOccupantTypeDownToBottom = (lotOccupantTypeId: number | stri
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default moveLotOccupantTypeDown;
|
export default moveLotOccupantTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveLotOccupantTypeUp: (lotOccupantTypeId: number | string) => boolean;
|
export declare function moveLotOccupantTypeUp(lotOccupantTypeId: number | string): boolean;
|
||||||
export declare const moveLotOccupantTypeUpToTop: (lotOccupantTypeId: number | string) => boolean;
|
export declare function moveLotOccupantTypeUpToTop(lotOccupantTypeId: number | string): boolean;
|
||||||
export default moveLotOccupantTypeUp;
|
export default moveLotOccupantTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,33 +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 { clearLotOccupantTypesCache } from "../functions.cache.js";
|
import { clearLotOccupantTypesCache } from "../functions.cache.js";
|
||||||
export const moveLotOccupantTypeUp = (lotOccupantTypeId) => {
|
export function moveLotOccupantTypeUp(lotOccupantTypeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber" +
|
.prepare(`select orderNumber from LotOccupantTypes where lotOccupantTypeId = ?`)
|
||||||
" from LotOccupantTypes" +
|
|
||||||
" where lotOccupantTypeId = ?")
|
|
||||||
.get(lotOccupantTypeId).orderNumber;
|
.get(lotOccupantTypeId).orderNumber;
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
database.close();
|
database.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
database
|
database
|
||||||
.prepare("update LotOccupantTypes" +
|
.prepare(`update LotOccupantTypes
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? - 1")
|
and orderNumber = ? - 1`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update LotOccupantTypes" +
|
.prepare(`update LotOccupantTypes
|
||||||
" set orderNumber = ? - 1" +
|
set orderNumber = ? - 1
|
||||||
" where lotOccupantTypeId = ?")
|
where lotOccupantTypeId = ?`)
|
||||||
.run(currentOrderNumber, lotOccupantTypeId);
|
.run(currentOrderNumber, lotOccupantTypeId);
|
||||||
database.close();
|
database.close();
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
export const moveLotOccupantTypeUpToTop = (lotOccupantTypeId) => {
|
export function moveLotOccupantTypeUpToTop(lotOccupantTypeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber from LotOccupantTypes where lotOccupantTypeId = ?")
|
.prepare("select orderNumber from LotOccupantTypes where lotOccupantTypeId = ?")
|
||||||
|
|
@ -37,14 +35,14 @@ export const moveLotOccupantTypeUpToTop = (lotOccupantTypeId) => {
|
||||||
.prepare("update LotOccupantTypes set orderNumber = -1 where lotOccupantTypeId = ?")
|
.prepare("update LotOccupantTypes set orderNumber = -1 where lotOccupantTypeId = ?")
|
||||||
.run(lotOccupantTypeId);
|
.run(lotOccupantTypeId);
|
||||||
database
|
database
|
||||||
.prepare("update LotOccupantTypes" +
|
.prepare(`update LotOccupantTypes
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber < ?")
|
and orderNumber < ?`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export default moveLotOccupantTypeUp;
|
export default moveLotOccupantTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,11 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearLotOccupantTypesCache } from "../functions.cache.js";
|
import { clearLotOccupantTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export const moveLotOccupantTypeUp = (
|
export function moveLotOccupantTypeUp(lotOccupantTypeId: number | string): boolean {
|
||||||
lotOccupantTypeId: number | string
|
|
||||||
): boolean => {
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(`select orderNumber from LotOccupantTypes where lotOccupantTypeId = ?`)
|
||||||
"select orderNumber" +
|
|
||||||
" from LotOccupantTypes" +
|
|
||||||
" where lotOccupantTypeId = ?"
|
|
||||||
)
|
|
||||||
.get(lotOccupantTypeId).orderNumber;
|
.get(lotOccupantTypeId).orderNumber;
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
|
|
@ -24,18 +18,18 @@ export const moveLotOccupantTypeUp = (
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotOccupantTypes" +
|
`update LotOccupantTypes
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? - 1"
|
and orderNumber = ? - 1`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotOccupantTypes" +
|
`update LotOccupantTypes
|
||||||
" set orderNumber = ? - 1" +
|
set orderNumber = ? - 1
|
||||||
" where lotOccupantTypeId = ?"
|
where lotOccupantTypeId = ?`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber, lotOccupantTypeId);
|
.run(currentOrderNumber, lotOccupantTypeId);
|
||||||
|
|
||||||
|
|
@ -44,9 +38,9 @@ export const moveLotOccupantTypeUp = (
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const moveLotOccupantTypeUpToTop = (lotOccupantTypeId: number | string): boolean => {
|
export function moveLotOccupantTypeUpToTop(lotOccupantTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
|
|
@ -60,10 +54,10 @@ export const moveLotOccupantTypeUpToTop = (lotOccupantTypeId: number | string):
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotOccupantTypes" +
|
`update LotOccupantTypes
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber < ?"
|
and orderNumber < ?`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -73,6 +67,6 @@ export const moveLotOccupantTypeUpToTop = (lotOccupantTypeId: number | string):
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default moveLotOccupantTypeUp;
|
export default moveLotOccupantTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveLotStatusDown: (lotStatusId: number | string) => boolean;
|
export declare function moveLotStatusDown(lotStatusId: number | string): boolean;
|
||||||
export declare const moveLotStatusDownToBottom: (lotStatusId: number | string) => boolean;
|
export declare function moveLotStatusDownToBottom(lotStatusId: number | string): boolean;
|
||||||
export default moveLotStatusDown;
|
export default moveLotStatusDown;
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,47 @@
|
||||||
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 { clearLotStatusesCache } from "../functions.cache.js";
|
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||||
export const moveLotStatusDown = (lotStatusId) => {
|
export function moveLotStatusDown(lotStatusId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber" +
|
.prepare(`select orderNumber from LotStatuses where lotStatusId = ?`)
|
||||||
" from LotStatuses" +
|
|
||||||
" where lotStatusId = ?")
|
|
||||||
.get(lotStatusId).orderNumber;
|
.get(lotStatusId).orderNumber;
|
||||||
database
|
database
|
||||||
.prepare("update LotStatuses" +
|
.prepare(`update LotStatuses
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? + 1")
|
and orderNumber = ? + 1`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update LotStatuses" +
|
.prepare(`update LotStatuses set orderNumber = ? + 1 where lotStatusId = ?`)
|
||||||
" set orderNumber = ? + 1" +
|
|
||||||
" where lotStatusId = ?")
|
|
||||||
.run(currentOrderNumber, lotStatusId);
|
.run(currentOrderNumber, lotStatusId);
|
||||||
database.close();
|
database.close();
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
export const moveLotStatusDownToBottom = (lotStatusId) => {
|
export function moveLotStatusDownToBottom(lotStatusId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
||||||
.get(lotStatusId).orderNumber;
|
.get(lotStatusId).orderNumber;
|
||||||
const maxOrderNumber = database
|
const maxOrderNumber = database
|
||||||
.prepare("select max(orderNumber) as maxOrderNumber" +
|
.prepare(`select max(orderNumber) as maxOrderNumber
|
||||||
" from LotStatuses" +
|
from LotStatuses
|
||||||
" where recordDelete_timeMillis is null")
|
where recordDelete_timeMillis is null`)
|
||||||
.get().maxOrderNumber;
|
.get().maxOrderNumber;
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
if (currentOrderNumber !== maxOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare("update LotStatuses set orderNumber = ? + 1 where lotStatusId = ?")
|
.prepare("update LotStatuses set orderNumber = ? + 1 where lotStatusId = ?")
|
||||||
.run(maxOrderNumber, lotStatusId);
|
.run(maxOrderNumber, lotStatusId);
|
||||||
database
|
database
|
||||||
.prepare("update LotStatuses" +
|
.prepare(`update LotStatuses
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber > ?")
|
and orderNumber > ?`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export default moveLotStatusDown;
|
export default moveLotStatusDown;
|
||||||
|
|
|
||||||
|
|
@ -4,32 +4,24 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearLotStatusesCache } from "../functions.cache.js";
|
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export const moveLotStatusDown = (lotStatusId: number | string): boolean => {
|
export function moveLotStatusDown(lotStatusId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(`select orderNumber from LotStatuses where lotStatusId = ?`)
|
||||||
"select orderNumber" +
|
|
||||||
" from LotStatuses" +
|
|
||||||
" where lotStatusId = ?"
|
|
||||||
)
|
|
||||||
.get(lotStatusId).orderNumber;
|
.get(lotStatusId).orderNumber;
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotStatuses" +
|
`update LotStatuses
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? + 1"
|
and orderNumber = ? + 1`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare(`update LotStatuses set orderNumber = ? + 1 where lotStatusId = ?`)
|
||||||
"update LotStatuses" +
|
|
||||||
" set orderNumber = ? + 1" +
|
|
||||||
" where lotStatusId = ?"
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber, lotStatusId);
|
.run(currentOrderNumber, lotStatusId);
|
||||||
|
|
||||||
database.close();
|
database.close();
|
||||||
|
|
@ -37,9 +29,9 @@ export const moveLotStatusDown = (lotStatusId: number | string): boolean => {
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const moveLotStatusDownToBottom = (lotStatusId: number | string): boolean => {
|
export function moveLotStatusDownToBottom(lotStatusId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
|
|
@ -48,9 +40,9 @@ export const moveLotStatusDownToBottom = (lotStatusId: number | string): boolean
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
const maxOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select max(orderNumber) as maxOrderNumber" +
|
`select max(orderNumber) as maxOrderNumber
|
||||||
" from LotStatuses" +
|
from LotStatuses
|
||||||
" where recordDelete_timeMillis is null"
|
where recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.get().maxOrderNumber;
|
.get().maxOrderNumber;
|
||||||
|
|
||||||
|
|
@ -61,10 +53,10 @@ export const moveLotStatusDownToBottom = (lotStatusId: number | string): boolean
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotStatuses" +
|
`update LotStatuses
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber > ?"
|
and orderNumber > ?`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -74,6 +66,6 @@ export const moveLotStatusDownToBottom = (lotStatusId: number | string): boolean
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default moveLotStatusDown;
|
export default moveLotStatusDown;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveLotStatusUp: (lotStatusId: number | string) => boolean;
|
export declare function moveLotStatusUp(lotStatusId: number | string): boolean;
|
||||||
export declare const moveLotStatusUpToTop: (lotStatusId: number | string) => boolean;
|
export declare function moveLotStatusUpToTop(lotStatusId: number | string): boolean;
|
||||||
export default moveLotStatusUp;
|
export default moveLotStatusUp;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { clearLotStatusesCache } from "../functions.cache.js";
|
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||||
export const moveLotStatusUp = (lotStatusId) => {
|
export function moveLotStatusUp(lotStatusId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
||||||
|
|
@ -11,10 +11,10 @@ export const moveLotStatusUp = (lotStatusId) => {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
database
|
database
|
||||||
.prepare("update LotStatuses" +
|
.prepare(`update LotStatuses
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? - 1")
|
and orderNumber = ? - 1`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update LotStatuses set orderNumber = ? - 1 where lotStatusId = ?")
|
.prepare("update LotStatuses set orderNumber = ? - 1 where lotStatusId = ?")
|
||||||
|
|
@ -22,8 +22,8 @@ export const moveLotStatusUp = (lotStatusId) => {
|
||||||
database.close();
|
database.close();
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
export const moveLotStatusUpToTop = (lotStatusId) => {
|
export function moveLotStatusUpToTop(lotStatusId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
||||||
|
|
@ -33,14 +33,14 @@ export const moveLotStatusUpToTop = (lotStatusId) => {
|
||||||
.prepare("update LotStatuses set orderNumber = -1 where lotStatusId = ?")
|
.prepare("update LotStatuses set orderNumber = -1 where lotStatusId = ?")
|
||||||
.run(lotStatusId);
|
.run(lotStatusId);
|
||||||
database
|
database
|
||||||
.prepare("update LotStatuses" +
|
.prepare(`update LotStatuses
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber < ?")
|
and orderNumber < ?`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export default moveLotStatusUp;
|
export default moveLotStatusUp;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearLotStatusesCache } from "../functions.cache.js";
|
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export const moveLotStatusUp = (lotStatusId: number | string): boolean => {
|
export function moveLotStatusUp(lotStatusId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
|
|
@ -18,10 +18,10 @@ export const moveLotStatusUp = (lotStatusId: number | string): boolean => {
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotStatuses" +
|
`update LotStatuses
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? - 1"
|
and orderNumber = ? - 1`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
|
|
@ -34,9 +34,9 @@ export const moveLotStatusUp = (lotStatusId: number | string): boolean => {
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const moveLotStatusUpToTop = (lotStatusId: number | string): boolean => {
|
export function moveLotStatusUpToTop(lotStatusId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
|
|
@ -50,10 +50,10 @@ export const moveLotStatusUpToTop = (lotStatusId: number | string): boolean => {
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotStatuses" +
|
`update LotStatuses
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber < ?"
|
and orderNumber < ?`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -63,6 +63,6 @@ export const moveLotStatusUpToTop = (lotStatusId: number | string): boolean => {
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default moveLotStatusUp;
|
export default moveLotStatusUp;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveLotTypeDown: (lotTypeId: number | string) => boolean;
|
export declare function moveLotTypeDown(lotTypeId: number | string): boolean;
|
||||||
export declare const moveLotTypeDownToBottom: (lotTypeId: number | string) => boolean;
|
export declare function moveLotTypeDownToBottom(lotTypeId: number | string): boolean;
|
||||||
export default moveLotTypeDown;
|
export default moveLotTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { clearLotTypesCache } from "../functions.cache.js";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
export const moveLotTypeDown = (lotTypeId) => {
|
export function moveLotTypeDown(lotTypeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
||||||
.get(lotTypeId).orderNumber;
|
.get(lotTypeId).orderNumber;
|
||||||
database
|
database
|
||||||
.prepare("update LotTypes" +
|
.prepare(`update LotTypes
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? + 1")
|
and orderNumber = ? + 1`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
||||||
|
|
@ -18,30 +18,30 @@ export const moveLotTypeDown = (lotTypeId) => {
|
||||||
database.close();
|
database.close();
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
export const moveLotTypeDownToBottom = (lotTypeId) => {
|
export function moveLotTypeDownToBottom(lotTypeId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
||||||
.get(lotTypeId).orderNumber;
|
.get(lotTypeId).orderNumber;
|
||||||
const maxOrderNumber = database
|
const maxOrderNumber = database
|
||||||
.prepare("select max(orderNumber) as maxOrderNumber" +
|
.prepare(`select max(orderNumber) as maxOrderNumber
|
||||||
" from LotTypes" +
|
from LotTypes
|
||||||
" where recordDelete_timeMillis is null")
|
where recordDelete_timeMillis is null`)
|
||||||
.get().maxOrderNumber;
|
.get().maxOrderNumber;
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
if (currentOrderNumber !== maxOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
||||||
.run(maxOrderNumber, lotTypeId);
|
.run(maxOrderNumber, lotTypeId);
|
||||||
database
|
database
|
||||||
.prepare("update LotTypes" +
|
.prepare(`update LotTypes
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber > ?")
|
and orderNumber > ?`)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export default moveLotTypeDown;
|
export default moveLotTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearLotTypesCache } from "../functions.cache.js";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export const moveLotTypeDown = (lotTypeId: number | string): boolean => {
|
export function moveLotTypeDown(lotTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
|
|
@ -13,10 +13,10 @@ export const moveLotTypeDown = (lotTypeId: number | string): boolean => {
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotTypes" +
|
`update LotTypes
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber = ? + 1"
|
and orderNumber = ? + 1`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
|
|
@ -29,9 +29,9 @@ export const moveLotTypeDown = (lotTypeId: number | string): boolean => {
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const moveLotTypeDownToBottom = (lotTypeId: number | string): boolean => {
|
export function moveLotTypeDownToBottom(lotTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
|
|
@ -40,9 +40,9 @@ export const moveLotTypeDownToBottom = (lotTypeId: number | string): boolean =>
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
const maxOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select max(orderNumber) as maxOrderNumber" +
|
`select max(orderNumber) as maxOrderNumber
|
||||||
" from LotTypes" +
|
from LotTypes
|
||||||
" where recordDelete_timeMillis is null"
|
where recordDelete_timeMillis is null`
|
||||||
)
|
)
|
||||||
.get().maxOrderNumber;
|
.get().maxOrderNumber;
|
||||||
|
|
||||||
|
|
@ -53,10 +53,10 @@ export const moveLotTypeDownToBottom = (lotTypeId: number | string): boolean =>
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotTypes" +
|
`update LotTypes
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and orderNumber > ?"
|
and orderNumber > ?`
|
||||||
)
|
)
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -66,6 +66,6 @@ export const moveLotTypeDownToBottom = (lotTypeId: number | string): boolean =>
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default moveLotTypeDown;
|
export default moveLotTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveLotTypeFieldDown: (lotTypeFieldId: number | string) => boolean;
|
export declare function moveLotTypeFieldDown(lotTypeFieldId: number | string): boolean;
|
||||||
export declare const moveLotTypeFieldDownToBottom: (lotTypeFieldId: number | string) => boolean;
|
export declare function moveLotTypeFieldDownToBottom(lotTypeFieldId: number | string): boolean;
|
||||||
export default moveLotTypeFieldDown;
|
export default moveLotTypeFieldDown;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { clearLotTypesCache } from "../functions.cache.js";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
export const moveLotTypeFieldDown = (lotTypeFieldId) => {
|
export function moveLotTypeFieldDown(lotTypeFieldId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentField = database
|
const currentField = database
|
||||||
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
||||||
.get(lotTypeFieldId);
|
.get(lotTypeFieldId);
|
||||||
database
|
database
|
||||||
.prepare("update LotTypeFields" +
|
.prepare(`update LotTypeFields
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and lotTypeId = ?" +
|
and lotTypeId = ? and orderNumber = ? + 1`)
|
||||||
" and orderNumber = ? + 1")
|
|
||||||
.run(currentField.lotTypeId, currentField.orderNumber);
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update LotTypeFields set orderNumber = ? + 1 where lotTypeFieldId = ?")
|
.prepare("update LotTypeFields set orderNumber = ? + 1 where lotTypeFieldId = ?")
|
||||||
|
|
@ -19,32 +18,32 @@ export const moveLotTypeFieldDown = (lotTypeFieldId) => {
|
||||||
database.close();
|
database.close();
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
export const moveLotTypeFieldDownToBottom = (lotTypeFieldId) => {
|
export function moveLotTypeFieldDownToBottom(lotTypeFieldId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentField = database
|
const currentField = database
|
||||||
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
||||||
.get(lotTypeFieldId);
|
.get(lotTypeFieldId);
|
||||||
const maxOrderNumber = database
|
const maxOrderNumber = database
|
||||||
.prepare("select max(orderNumber) as maxOrderNumber" +
|
.prepare(`select max(orderNumber) as maxOrderNumber
|
||||||
" from LotTypeFields" +
|
from LotTypeFields
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and lotTypeId = ?")
|
and lotTypeId = ?`)
|
||||||
.get(currentField.lotTypeId).maxOrderNumber;
|
.get(currentField.lotTypeId).maxOrderNumber;
|
||||||
if (currentField.orderNumber !== maxOrderNumber) {
|
if (currentField.orderNumber !== maxOrderNumber) {
|
||||||
database
|
database
|
||||||
.prepare("update LotTypeFields set orderNumber = ? + 1 where lotTypeFieldId = ?")
|
.prepare("update LotTypeFields set orderNumber = ? + 1 where lotTypeFieldId = ?")
|
||||||
.run(maxOrderNumber, lotTypeFieldId);
|
.run(maxOrderNumber, lotTypeFieldId);
|
||||||
database
|
database
|
||||||
.prepare("update LotTypeFields" +
|
.prepare(`update LotTypeFields
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and lotTypeId = ?" +
|
and lotTypeId = ?
|
||||||
" and orderNumber > ?")
|
and orderNumber > ?`)
|
||||||
.run(currentField.lotTypeId, currentField.orderNumber);
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export default moveLotTypeFieldDown;
|
export default moveLotTypeFieldDown;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearLotTypesCache } from "../functions.cache.js";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export const moveLotTypeFieldDown = (lotTypeFieldId: number | string): boolean => {
|
export function moveLotTypeFieldDown(lotTypeFieldId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentField: { lotTypeId?: number; orderNumber: number } = database
|
const currentField: { lotTypeId?: number; orderNumber: number } = database
|
||||||
|
|
@ -13,11 +13,10 @@ export const moveLotTypeFieldDown = (lotTypeFieldId: number | string): boolean =
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotTypeFields" +
|
`update LotTypeFields
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and lotTypeId = ?" +
|
and lotTypeId = ? and orderNumber = ? + 1`
|
||||||
" and orderNumber = ? + 1"
|
|
||||||
)
|
)
|
||||||
.run(currentField.lotTypeId, currentField.orderNumber);
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
|
|
||||||
|
|
@ -30,9 +29,9 @@ export const moveLotTypeFieldDown = (lotTypeFieldId: number | string): boolean =
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const moveLotTypeFieldDownToBottom = (lotTypeFieldId: number | string): boolean => {
|
export function moveLotTypeFieldDownToBottom(lotTypeFieldId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentField: { lotTypeId?: number; orderNumber: number } = database
|
const currentField: { lotTypeId?: number; orderNumber: number } = database
|
||||||
|
|
@ -41,10 +40,10 @@ export const moveLotTypeFieldDownToBottom = (lotTypeFieldId: number | string): b
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
const maxOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(
|
||||||
"select max(orderNumber) as maxOrderNumber" +
|
`select max(orderNumber) as maxOrderNumber
|
||||||
" from LotTypeFields" +
|
from LotTypeFields
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and lotTypeId = ?"
|
and lotTypeId = ?`
|
||||||
)
|
)
|
||||||
.get(currentField.lotTypeId).maxOrderNumber;
|
.get(currentField.lotTypeId).maxOrderNumber;
|
||||||
|
|
||||||
|
|
@ -55,11 +54,11 @@ export const moveLotTypeFieldDownToBottom = (lotTypeFieldId: number | string): b
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotTypeFields" +
|
`update LotTypeFields
|
||||||
" set orderNumber = orderNumber - 1" +
|
set orderNumber = orderNumber - 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and lotTypeId = ?" +
|
and lotTypeId = ?
|
||||||
" and orderNumber > ?"
|
and orderNumber > ?`
|
||||||
)
|
)
|
||||||
.run(currentField.lotTypeId, currentField.orderNumber);
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -69,6 +68,6 @@ export const moveLotTypeFieldDownToBottom = (lotTypeFieldId: number | string): b
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default moveLotTypeFieldDown;
|
export default moveLotTypeFieldDown;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveLotTypeFieldUp: (lotTypeFieldId: number | string) => boolean;
|
export declare function moveLotTypeFieldUp(lotTypeFieldId: number | string): boolean;
|
||||||
export declare const moveLotTypeFieldUpToTop: (lotTypeFieldId: number | string) => boolean;
|
export declare function moveLotTypeFieldUpToTop(lotTypeFieldId: number | string): boolean;
|
||||||
export default moveLotTypeFieldUp;
|
export default moveLotTypeFieldUp;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { clearLotTypesCache } from "../functions.cache.js";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
export const moveLotTypeFieldUp = (lotTypeFieldId) => {
|
export function moveLotTypeFieldUp(lotTypeFieldId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentField = database
|
const currentField = database
|
||||||
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
||||||
|
|
@ -11,11 +11,11 @@ export const moveLotTypeFieldUp = (lotTypeFieldId) => {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
database
|
database
|
||||||
.prepare("update LotTypeFields" +
|
.prepare(`update LotTypeFields
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and lotTypeId = ?" +
|
and lotTypeId = ?
|
||||||
" and orderNumber = ? - 1")
|
and orderNumber = ? - 1`)
|
||||||
.run(currentField.lotTypeId, currentField.orderNumber);
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update LotTypeFields set orderNumber = ? - 1 where lotTypeFieldId = ?")
|
.prepare("update LotTypeFields set orderNumber = ? - 1 where lotTypeFieldId = ?")
|
||||||
|
|
@ -23,8 +23,8 @@ export const moveLotTypeFieldUp = (lotTypeFieldId) => {
|
||||||
database.close();
|
database.close();
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
export const moveLotTypeFieldUpToTop = (lotTypeFieldId) => {
|
export function moveLotTypeFieldUpToTop(lotTypeFieldId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentField = database
|
const currentField = database
|
||||||
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
||||||
|
|
@ -34,15 +34,15 @@ export const moveLotTypeFieldUpToTop = (lotTypeFieldId) => {
|
||||||
.prepare("update LotTypeFields set orderNumber = -1 where lotTypeFieldId = ?")
|
.prepare("update LotTypeFields set orderNumber = -1 where lotTypeFieldId = ?")
|
||||||
.run(lotTypeFieldId);
|
.run(lotTypeFieldId);
|
||||||
database
|
database
|
||||||
.prepare("update LotTypeFields" +
|
.prepare(`update LotTypeFields
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and lotTypeId = ?" +
|
and lotTypeId = ?
|
||||||
" and orderNumber < ?")
|
and orderNumber < ?`)
|
||||||
.run(currentField.lotTypeId, currentField.orderNumber);
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
}
|
}
|
||||||
database.close();
|
database.close();
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export default moveLotTypeFieldUp;
|
export default moveLotTypeFieldUp;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearLotTypesCache } from "../functions.cache.js";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export const moveLotTypeFieldUp = (lotTypeFieldId: number | string): boolean => {
|
export function moveLotTypeFieldUp(lotTypeFieldId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentField: { lotTypeId: number; orderNumber: number } = database
|
const currentField: { lotTypeId: number; orderNumber: number } = database
|
||||||
|
|
@ -18,11 +18,11 @@ export const moveLotTypeFieldUp = (lotTypeFieldId: number | string): boolean =>
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotTypeFields" +
|
`update LotTypeFields
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and lotTypeId = ?" +
|
and lotTypeId = ?
|
||||||
" and orderNumber = ? - 1"
|
and orderNumber = ? - 1`
|
||||||
)
|
)
|
||||||
.run(currentField.lotTypeId, currentField.orderNumber);
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
|
|
||||||
|
|
@ -35,9 +35,9 @@ export const moveLotTypeFieldUp = (lotTypeFieldId: number | string): boolean =>
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
export const moveLotTypeFieldUpToTop = (lotTypeFieldId: number | string): boolean => {
|
export function moveLotTypeFieldUpToTop(lotTypeFieldId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentField: { lotTypeId: number; orderNumber: number } = database
|
const currentField: { lotTypeId: number; orderNumber: number } = database
|
||||||
|
|
@ -51,11 +51,11 @@ export const moveLotTypeFieldUpToTop = (lotTypeFieldId: number | string): boolea
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
"update LotTypeFields" +
|
`update LotTypeFields
|
||||||
" set orderNumber = orderNumber + 1" +
|
set orderNumber = orderNumber + 1
|
||||||
" where recordDelete_timeMillis is null" +
|
where recordDelete_timeMillis is null
|
||||||
" and lotTypeId = ?" +
|
and lotTypeId = ?
|
||||||
" and orderNumber < ?"
|
and orderNumber < ?`
|
||||||
)
|
)
|
||||||
.run(currentField.lotTypeId, currentField.orderNumber);
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -65,6 +65,6 @@ export const moveLotTypeFieldUpToTop = (lotTypeFieldId: number | string): boolea
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
export default moveLotTypeFieldUp;
|
export default moveLotTypeFieldUp;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export declare const moveLotTypeUp: (lotTypeId: number | string) => boolean;
|
export declare function moveLotTypeUp(lotTypeId: number | string): boolean;
|
||||||
export declare const moveLotTypeUpToTop: (lotTypeId: number | string) => boolean;
|
export declare function moveLotTypeUpToTop(lotTypeId: number | string): boolean;
|
||||||
export default moveLotTypeUp;
|
export default moveLotTypeUp;
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue