attempt to reduce ordernumber select duplication
parent
75c8bde00a
commit
72cd3b803f
|
|
@ -18,6 +18,7 @@ export declare function getOccupancyTypeByOccupancyType(occupancyTypeString: str
|
||||||
export declare function getOccupancyTypePrintsById(occupancyTypeId: number): string[];
|
export declare function getOccupancyTypePrintsById(occupancyTypeId: number): string[];
|
||||||
export declare function clearOccupancyTypesCache(): void;
|
export declare function clearOccupancyTypesCache(): void;
|
||||||
export declare function getWorkOrderTypes(): recordTypes.WorkOrderType[];
|
export declare function getWorkOrderTypes(): recordTypes.WorkOrderType[];
|
||||||
|
export declare function getWorkOrderTypeById(workOrderTypeId: number): recordTypes.WorkOrderType;
|
||||||
export declare function clearWorkOrderTypesCache(): void;
|
export declare function clearWorkOrderTypesCache(): void;
|
||||||
export declare function getWorkOrderMilestoneTypes(): recordTypes.WorkOrderMilestoneType[];
|
export declare function getWorkOrderMilestoneTypes(): recordTypes.WorkOrderMilestoneType[];
|
||||||
export declare function getWorkOrderMilestoneTypeByWorkOrderMilestoneType(workOrderMilestoneTypeString: string): recordTypes.WorkOrderMilestoneType;
|
export declare function getWorkOrderMilestoneTypeByWorkOrderMilestoneType(workOrderMilestoneTypeString: string): recordTypes.WorkOrderMilestoneType;
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,12 @@ export function getWorkOrderTypes() {
|
||||||
}
|
}
|
||||||
return workOrderTypes;
|
return workOrderTypes;
|
||||||
}
|
}
|
||||||
|
export function getWorkOrderTypeById(workOrderTypeId) {
|
||||||
|
const cachedWorkOrderTypes = getWorkOrderTypes();
|
||||||
|
return cachedWorkOrderTypes.find((currentWorkOrderType) => {
|
||||||
|
return currentWorkOrderType.workOrderTypeId === workOrderTypeId;
|
||||||
|
});
|
||||||
|
}
|
||||||
export function clearWorkOrderTypesCache() {
|
export function clearWorkOrderTypesCache() {
|
||||||
workOrderTypes = undefined;
|
workOrderTypes = undefined;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,14 @@ export function getWorkOrderTypes() {
|
||||||
return workOrderTypes;
|
return workOrderTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getWorkOrderTypeById(workOrderTypeId: number) {
|
||||||
|
const cachedWorkOrderTypes = getWorkOrderTypes();
|
||||||
|
|
||||||
|
return cachedWorkOrderTypes.find((currentWorkOrderType) => {
|
||||||
|
return currentWorkOrderType.workOrderTypeId === workOrderTypeId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function clearWorkOrderTypesCache() {
|
export function clearWorkOrderTypesCache() {
|
||||||
workOrderTypes = undefined;
|
workOrderTypes = undefined;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
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 { getLotStatusById, clearLotStatusesCache } from "../functions.cache.js";
|
||||||
export function moveLotStatusDown(lotStatusId) {
|
export function moveLotStatusDown(lotStatusId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = getLotStatusById(typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId).orderNumber;
|
||||||
.prepare(`select orderNumber from LotStatuses where lotStatusId = ?`)
|
|
||||||
.get(lotStatusId).orderNumber;
|
|
||||||
database
|
database
|
||||||
.prepare(`update LotStatuses
|
.prepare(`update LotStatuses
|
||||||
set orderNumber = orderNumber - 1
|
set orderNumber = orderNumber - 1
|
||||||
|
|
@ -21,9 +19,7 @@ export function moveLotStatusDown(lotStatusId) {
|
||||||
}
|
}
|
||||||
export function moveLotStatusDownToBottom(lotStatusId) {
|
export function moveLotStatusDownToBottom(lotStatusId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = getLotStatusById(typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId).orderNumber;
|
||||||
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
|
||||||
.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
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@ 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 { getLotStatusById, clearLotStatusesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export function 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 = getLotStatusById(
|
||||||
.prepare(`select orderNumber from LotStatuses where lotStatusId = ?`)
|
typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId
|
||||||
.get(lotStatusId).orderNumber;
|
).orderNumber;
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
|
|
@ -34,9 +34,9 @@ export function moveLotStatusDown(lotStatusId: number | string): boolean {
|
||||||
export function 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 = getLotStatusById(
|
||||||
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId
|
||||||
.get(lotStatusId).orderNumber;
|
).orderNumber;
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
const maxOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
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 { getLotStatusById, clearLotStatusesCache } from "../functions.cache.js";
|
||||||
export function moveLotStatusUp(lotStatusId) {
|
export function moveLotStatusUp(lotStatusId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = getLotStatusById(typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId).orderNumber;
|
||||||
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
|
||||||
.get(lotStatusId).orderNumber;
|
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
database.close();
|
database.close();
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -25,9 +23,7 @@ export function moveLotStatusUp(lotStatusId) {
|
||||||
}
|
}
|
||||||
export function moveLotStatusUpToTop(lotStatusId) {
|
export function moveLotStatusUpToTop(lotStatusId) {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = getLotStatusById(typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId).orderNumber;
|
||||||
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
|
||||||
.get(lotStatusId).orderNumber;
|
|
||||||
if (currentOrderNumber > 0) {
|
if (currentOrderNumber > 0) {
|
||||||
database
|
database
|
||||||
.prepare("update LotStatuses set orderNumber = -1 where lotStatusId = ?")
|
.prepare("update LotStatuses set orderNumber = -1 where lotStatusId = ?")
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@ 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 { getLotStatusById, clearLotStatusesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export function 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 = getLotStatusById(
|
||||||
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId
|
||||||
.get(lotStatusId).orderNumber;
|
).orderNumber;
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
database.close();
|
database.close();
|
||||||
|
|
@ -39,9 +39,9 @@ export function moveLotStatusUp(lotStatusId: number | string): boolean {
|
||||||
export function 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 = getLotStatusById(
|
||||||
.prepare("select orderNumber from LotStatuses where lotStatusId = ?")
|
typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId
|
||||||
.get(lotStatusId).orderNumber;
|
).orderNumber;
|
||||||
|
|
||||||
if (currentOrderNumber > 0) {
|
if (currentOrderNumber > 0) {
|
||||||
database
|
database
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
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 { getLotTypeById, clearLotTypesCache } from "../functions.cache.js";
|
||||||
export function moveLotTypeDown(lotTypeId) {
|
export function moveLotTypeDown(lotTypeId) {
|
||||||
|
const currentOrderNumber = getLotTypeById(typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId).orderNumber;
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
|
||||||
.get(lotTypeId).orderNumber;
|
|
||||||
database
|
database
|
||||||
.prepare(`update LotTypes
|
.prepare(`update LotTypes
|
||||||
set orderNumber = orderNumber - 1
|
set orderNumber = orderNumber - 1
|
||||||
|
|
@ -20,10 +18,8 @@ export function moveLotTypeDown(lotTypeId) {
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
export function moveLotTypeDownToBottom(lotTypeId) {
|
export function moveLotTypeDownToBottom(lotTypeId) {
|
||||||
|
const currentOrderNumber = getLotTypeById(typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId).orderNumber;
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
|
||||||
.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
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@ 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 { getLotTypeById, clearLotTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export function moveLotTypeDown(lotTypeId: number | string): boolean {
|
export function moveLotTypeDown(lotTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber = getLotTypeById(
|
||||||
|
typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId
|
||||||
|
).orderNumber;
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const database = sqlite(databasePath);
|
||||||
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
|
||||||
.get(lotTypeId).orderNumber;
|
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
|
|
@ -32,11 +32,11 @@ export function moveLotTypeDown(lotTypeId: number | string): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveLotTypeDownToBottom(lotTypeId: number | string): boolean {
|
export function moveLotTypeDownToBottom(lotTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber = getLotTypeById(
|
||||||
|
typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId
|
||||||
|
).orderNumber;
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const database = sqlite(databasePath);
|
||||||
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
|
||||||
.get(lotTypeId).orderNumber;
|
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
const maxOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { clearLotTypesCache } from "../functions.cache.js";
|
import { getLotTypeById, clearLotTypesCache } from "../functions.cache.js";
|
||||||
export function moveLotTypeUp(lotTypeId) {
|
export function moveLotTypeUp(lotTypeId) {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber = getLotTypeById(typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId).orderNumber;
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
|
||||||
.get(lotTypeId).orderNumber;
|
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
database.close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
const database = sqlite(databasePath);
|
||||||
database
|
database
|
||||||
.prepare(`update LotTypes
|
.prepare(`update LotTypes
|
||||||
set orderNumber = orderNumber + 1
|
set orderNumber = orderNumber + 1
|
||||||
|
|
@ -24,10 +21,8 @@ export function moveLotTypeUp(lotTypeId) {
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
export function moveLotTypeUpToTop(lotTypeId) {
|
export function moveLotTypeUpToTop(lotTypeId) {
|
||||||
|
const currentOrderNumber = getLotTypeById(typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId).orderNumber;
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
|
||||||
.get(lotTypeId).orderNumber;
|
|
||||||
if (currentOrderNumber > 0) {
|
if (currentOrderNumber > 0) {
|
||||||
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
|
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
|
||||||
database
|
database
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,19 @@ 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 { getLotTypeById, clearLotTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export function moveLotTypeUp(lotTypeId: number | string): boolean {
|
export function moveLotTypeUp(lotTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber = getLotTypeById(
|
||||||
|
typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId
|
||||||
const currentOrderNumber: number = database
|
).orderNumber;
|
||||||
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
|
||||||
.get(lotTypeId).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
database.close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update LotTypes
|
`update LotTypes
|
||||||
|
|
@ -37,11 +36,11 @@ export function moveLotTypeUp(lotTypeId: number | string): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveLotTypeUpToTop(lotTypeId: number | string): boolean {
|
export function moveLotTypeUpToTop(lotTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber = getLotTypeById(
|
||||||
|
typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId
|
||||||
|
).orderNumber;
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const database = sqlite(databasePath);
|
||||||
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
|
||||||
.get(lotTypeId).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber > 0) {
|
if (currentOrderNumber > 0) {
|
||||||
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
|
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
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 { clearOccupancyTypesCache } from "../functions.cache.js";
|
import { getOccupancyTypeById, clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
export function moveOccupancyTypeDown(occupancyTypeId) {
|
export function moveOccupancyTypeDown(occupancyTypeId) {
|
||||||
|
const currentOrderNumber = getOccupancyTypeById(typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId).orderNumber;
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
|
||||||
database
|
database
|
||||||
.prepare(`update OccupancyTypes
|
.prepare(`update OccupancyTypes
|
||||||
set orderNumber = orderNumber - 1
|
set orderNumber = orderNumber - 1
|
||||||
|
|
@ -20,10 +18,8 @@ export function moveOccupancyTypeDown(occupancyTypeId) {
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
export function moveOccupancyTypeDownToBottom(occupancyTypeId) {
|
export function moveOccupancyTypeDownToBottom(occupancyTypeId) {
|
||||||
|
const currentOrderNumber = getOccupancyTypeById(typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId).orderNumber;
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
|
||||||
const maxOrderNumber = database
|
const maxOrderNumber = database
|
||||||
.prepare(`select max(orderNumber) as maxOrderNumber
|
.prepare(`select max(orderNumber) as maxOrderNumber
|
||||||
from OccupancyTypes
|
from OccupancyTypes
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@ import sqlite from "better-sqlite3";
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
import { getOccupancyTypeById, clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export function moveOccupancyTypeDown(occupancyTypeId: number | string): boolean {
|
export function moveOccupancyTypeDown(occupancyTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber: number = getOccupancyTypeById(
|
||||||
|
typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId
|
||||||
|
).orderNumber;
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const database = sqlite(databasePath);
|
||||||
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
|
|
@ -32,11 +32,11 @@ export function moveOccupancyTypeDown(occupancyTypeId: number | string): boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveOccupancyTypeDownToBottom(occupancyTypeId: number | string): boolean {
|
export function moveOccupancyTypeDownToBottom(occupancyTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber: number = getOccupancyTypeById(
|
||||||
|
typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId
|
||||||
|
).orderNumber;
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const database = sqlite(databasePath);
|
||||||
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
const maxOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
import { getOccupancyTypeById, clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
export function moveOccupancyTypeUp(occupancyTypeId) {
|
export function moveOccupancyTypeUp(occupancyTypeId) {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber = getOccupancyTypeById(typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId).orderNumber;
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
database.close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
const database = sqlite(databasePath);
|
||||||
database
|
database
|
||||||
.prepare(`update OccupancyTypes
|
.prepare(`update OccupancyTypes
|
||||||
set orderNumber = orderNumber + 1
|
set orderNumber = orderNumber + 1
|
||||||
|
|
@ -24,10 +21,8 @@ export function moveOccupancyTypeUp(occupancyTypeId) {
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
export function moveOccupancyTypeUpToTop(occupancyTypeId) {
|
export function moveOccupancyTypeUpToTop(occupancyTypeId) {
|
||||||
|
const currentOrderNumber = getOccupancyTypeById(typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId).orderNumber;
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
|
||||||
if (currentOrderNumber > 0) {
|
if (currentOrderNumber > 0) {
|
||||||
database
|
database
|
||||||
.prepare("update OccupancyTypes set orderNumber = -1 where occupancyTypeId = ?")
|
.prepare("update OccupancyTypes set orderNumber = -1 where occupancyTypeId = ?")
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,19 @@ import sqlite from "better-sqlite3";
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
import { getOccupancyTypeById, clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export function moveOccupancyTypeUp(occupancyTypeId: number | string): boolean {
|
export function moveOccupancyTypeUp(occupancyTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber: number = getOccupancyTypeById(
|
||||||
|
typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId
|
||||||
const currentOrderNumber: number = database
|
).orderNumber;
|
||||||
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
database.close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update OccupancyTypes
|
`update OccupancyTypes
|
||||||
|
|
@ -37,11 +36,11 @@ export function moveOccupancyTypeUp(occupancyTypeId: number | string): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveOccupancyTypeUpToTop(occupancyTypeId: number | string): boolean {
|
export function moveOccupancyTypeUpToTop(occupancyTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber: number = getOccupancyTypeById(
|
||||||
|
typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId
|
||||||
|
).orderNumber;
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const database = sqlite(databasePath);
|
||||||
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber > 0) {
|
if (currentOrderNumber > 0) {
|
||||||
database
|
database
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
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 { clearWorkOrderTypesCache } from "../functions.cache.js";
|
import { getWorkOrderTypeById, clearWorkOrderTypesCache } from "../functions.cache.js";
|
||||||
export function moveWorkOrderTypeDown(workOrderTypeId) {
|
export function moveWorkOrderTypeDown(workOrderTypeId) {
|
||||||
|
const currentOrderNumber = getWorkOrderTypeById(typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId).orderNumber;
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare("select orderNumber from WorkOrderTypes where workOrderTypeId = ?")
|
|
||||||
.get(workOrderTypeId).orderNumber;
|
|
||||||
database
|
database
|
||||||
.prepare(`update WorkOrderTypes
|
.prepare(`update WorkOrderTypes
|
||||||
set orderNumber = orderNumber - 1
|
set orderNumber = orderNumber - 1
|
||||||
|
|
@ -20,10 +18,8 @@ export function moveWorkOrderTypeDown(workOrderTypeId) {
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
export function moveWorkOrderTypeDownToBottom(workOrderTypeId) {
|
export function moveWorkOrderTypeDownToBottom(workOrderTypeId) {
|
||||||
|
const currentOrderNumber = getWorkOrderTypeById(typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId).orderNumber;
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare("select orderNumber from WorkOrderTypes where workOrderTypeId = ?")
|
|
||||||
.get(workOrderTypeId).orderNumber;
|
|
||||||
const maxOrderNumber = database
|
const maxOrderNumber = database
|
||||||
.prepare(`select max(orderNumber) as maxOrderNumber
|
.prepare(`select max(orderNumber) as maxOrderNumber
|
||||||
from WorkOrderTypes
|
from WorkOrderTypes
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@ import sqlite from "better-sqlite3";
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearWorkOrderTypesCache } from "../functions.cache.js";
|
import { getWorkOrderTypeById, clearWorkOrderTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export function moveWorkOrderTypeDown(workOrderTypeId: number | string): boolean {
|
export function moveWorkOrderTypeDown(workOrderTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber: number = getWorkOrderTypeById(
|
||||||
|
typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId
|
||||||
|
).orderNumber;
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const database = sqlite(databasePath);
|
||||||
.prepare("select orderNumber from WorkOrderTypes where workOrderTypeId = ?")
|
|
||||||
.get(workOrderTypeId).orderNumber;
|
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
|
|
@ -32,11 +32,11 @@ export function moveWorkOrderTypeDown(workOrderTypeId: number | string): boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveWorkOrderTypeDownToBottom(workOrderTypeId: number | string): boolean {
|
export function moveWorkOrderTypeDownToBottom(workOrderTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber: number = getWorkOrderTypeById(
|
||||||
|
typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId
|
||||||
|
).orderNumber;
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const database = sqlite(databasePath);
|
||||||
.prepare("select orderNumber from WorkOrderTypes where workOrderTypeId = ?")
|
|
||||||
.get(workOrderTypeId).orderNumber;
|
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
const maxOrderNumber: number = database
|
||||||
.prepare(
|
.prepare(
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { clearWorkOrderTypesCache } from "../functions.cache.js";
|
import { getWorkOrderTypeById, clearWorkOrderTypesCache } from "../functions.cache.js";
|
||||||
export function moveWorkOrderTypeUp(workOrderTypeId) {
|
export function moveWorkOrderTypeUp(workOrderTypeId) {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber = getWorkOrderTypeById(typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId).orderNumber;
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare(`select orderNumber from WorkOrderTypes where workOrderTypeId = ?`)
|
|
||||||
.get(workOrderTypeId).orderNumber;
|
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
database.close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
const database = sqlite(databasePath);
|
||||||
database
|
database
|
||||||
.prepare(`update WorkOrderTypes
|
.prepare(`update WorkOrderTypes
|
||||||
set orderNumber = orderNumber + 1
|
set orderNumber = orderNumber + 1
|
||||||
|
|
@ -24,10 +21,8 @@ export function moveWorkOrderTypeUp(workOrderTypeId) {
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
export function moveWorkOrderTypeUpToTop(workOrderTypeId) {
|
export function moveWorkOrderTypeUpToTop(workOrderTypeId) {
|
||||||
|
const currentOrderNumber = getWorkOrderTypeById(typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId).orderNumber;
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
|
||||||
.prepare("select orderNumber from WorkOrderTypes where workOrderTypeId = ?")
|
|
||||||
.get(workOrderTypeId).orderNumber;
|
|
||||||
if (currentOrderNumber > 0) {
|
if (currentOrderNumber > 0) {
|
||||||
database
|
database
|
||||||
.prepare("update WorkOrderTypes set orderNumber = -1 where workOrderTypeId = ?")
|
.prepare("update WorkOrderTypes set orderNumber = -1 where workOrderTypeId = ?")
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,19 @@ import sqlite from "better-sqlite3";
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearWorkOrderTypesCache } from "../functions.cache.js";
|
import { getWorkOrderTypeById, clearWorkOrderTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export function moveWorkOrderTypeUp(workOrderTypeId: number | string): boolean {
|
export function moveWorkOrderTypeUp(workOrderTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber: number = getWorkOrderTypeById(
|
||||||
|
typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId
|
||||||
const currentOrderNumber: number = database
|
).orderNumber;
|
||||||
.prepare(`select orderNumber from WorkOrderTypes where workOrderTypeId = ?`)
|
|
||||||
.get(workOrderTypeId).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
database.close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare(
|
||||||
`update WorkOrderTypes
|
`update WorkOrderTypes
|
||||||
|
|
@ -37,11 +36,11 @@ export function moveWorkOrderTypeUp(workOrderTypeId: number | string): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveWorkOrderTypeUpToTop(workOrderTypeId: number | string): boolean {
|
export function moveWorkOrderTypeUpToTop(workOrderTypeId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const currentOrderNumber: number = getWorkOrderTypeById(
|
||||||
|
typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId
|
||||||
|
).orderNumber;
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const database = sqlite(databasePath);
|
||||||
.prepare("select orderNumber from WorkOrderTypes where workOrderTypeId = ?")
|
|
||||||
.get(workOrderTypeId).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber > 0) {
|
if (currentOrderNumber > 0) {
|
||||||
database
|
database
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue