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