reduce move duplication
parent
3bab486146
commit
3fea6dead7
|
|
@ -1,44 +1,10 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { moveRecordDown, moveRecordDownToBottom } from "./moveRecord.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
export function moveFeeCategoryDown(feeCategoryId) {
|
export function moveFeeCategoryDown(feeCategoryId) {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordDown("FeeCategories", feeCategoryId);
|
||||||
const currentOrderNumber = database
|
return success;
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
|
||||||
.get(feeCategoryId).orderNumber;
|
|
||||||
database
|
|
||||||
.prepare(`update FeeCategories
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? + 1`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
const result = database
|
|
||||||
.prepare("update FeeCategories set orderNumber = ? + 1 where feeCategoryId = ?")
|
|
||||||
.run(currentOrderNumber, feeCategoryId);
|
|
||||||
database.close();
|
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
export function moveFeeCategoryDownToBottom(feeCategoryId) {
|
export function moveFeeCategoryDownToBottom(feeCategoryId) {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordDownToBottom("FeeCategories", feeCategoryId);
|
||||||
const currentOrderNumber = database
|
return success;
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
|
||||||
.get(feeCategoryId).orderNumber;
|
|
||||||
const maxOrderNumber = database
|
|
||||||
.prepare(`select max(orderNumber) as maxOrderNumber
|
|
||||||
from FeeCategories
|
|
||||||
where recordDelete_timeMillis is null`)
|
|
||||||
.get().maxOrderNumber;
|
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
|
||||||
database
|
|
||||||
.prepare("update FeeCategories set orderNumber = ? + 1 where feeCategoryId = ?")
|
|
||||||
.run(maxOrderNumber, feeCategoryId);
|
|
||||||
database
|
|
||||||
.prepare(`update FeeCategories
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null and
|
|
||||||
orderNumber > ?`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
}
|
|
||||||
database.close();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
export default moveFeeCategoryDown;
|
export default moveFeeCategoryDown;
|
||||||
|
|
|
||||||
|
|
@ -1,65 +1,13 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { moveRecordDown, moveRecordDownToBottom } from "./moveRecord.js";
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
export function moveFeeCategoryDown(feeCategoryId: number | string): boolean {
|
export function moveFeeCategoryDown(feeCategoryId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordDown("FeeCategories", feeCategoryId);
|
||||||
|
return success;
|
||||||
const currentOrderNumber: number = database
|
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
|
||||||
.get(feeCategoryId).orderNumber;
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update FeeCategories
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? + 1`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare("update FeeCategories set orderNumber = ? + 1 where feeCategoryId = ?")
|
|
||||||
.run(currentOrderNumber, feeCategoryId);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveFeeCategoryDownToBottom(feeCategoryId: number | string): boolean {
|
export function moveFeeCategoryDownToBottom(feeCategoryId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordDownToBottom("FeeCategories", feeCategoryId);
|
||||||
|
return success;
|
||||||
const currentOrderNumber: number = database
|
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
|
||||||
.get(feeCategoryId).orderNumber;
|
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
|
||||||
.prepare(
|
|
||||||
`select max(orderNumber) as maxOrderNumber
|
|
||||||
from FeeCategories
|
|
||||||
where recordDelete_timeMillis is null`
|
|
||||||
)
|
|
||||||
.get().maxOrderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
|
||||||
database
|
|
||||||
.prepare("update FeeCategories set orderNumber = ? + 1 where feeCategoryId = ?")
|
|
||||||
.run(maxOrderNumber, feeCategoryId);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update FeeCategories
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null and
|
|
||||||
orderNumber > ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveFeeCategoryDown;
|
export default moveFeeCategoryDown;
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,10 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
export function moveFeeCategoryUp(feeCategoryId) {
|
export function moveFeeCategoryUp(feeCategoryId) {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordUp("FeeCategories", feeCategoryId);
|
||||||
const currentOrderNumber = database
|
return success;
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
|
||||||
.get(feeCategoryId).orderNumber;
|
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
database.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
database
|
|
||||||
.prepare(`update FeeCategories
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
const result = database
|
|
||||||
.prepare("update FeeCategories set orderNumber = ? - 1 where feeCategoryId = ?")
|
|
||||||
.run(currentOrderNumber, feeCategoryId);
|
|
||||||
database.close();
|
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
export function moveFeeCategoryUpToTop(feeCategoryId) {
|
export function moveFeeCategoryUpToTop(feeCategoryId) {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordUpToTop("FeeCategories", feeCategoryId);
|
||||||
const currentOrderNumber = database
|
return success;
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
|
||||||
.get(feeCategoryId).orderNumber;
|
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
database
|
|
||||||
.prepare("update FeeCategories set orderNumber = -1 where feeCategoryId = ?")
|
|
||||||
.run(feeCategoryId);
|
|
||||||
database
|
|
||||||
.prepare(`update FeeCategories
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
}
|
|
||||||
database.close();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
export default moveFeeCategoryUp;
|
export default moveFeeCategoryUp;
|
||||||
|
|
|
||||||
|
|
@ -1,62 +1,13 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
export function moveFeeCategoryUp(feeCategoryId: number | string): boolean {
|
export function moveFeeCategoryUp(feeCategoryId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordUp("FeeCategories", feeCategoryId);
|
||||||
|
return success;
|
||||||
const currentOrderNumber: number = database
|
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
|
||||||
.get(feeCategoryId).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
database.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update FeeCategories
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare("update FeeCategories set orderNumber = ? - 1 where feeCategoryId = ?")
|
|
||||||
.run(currentOrderNumber, feeCategoryId);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveFeeCategoryUpToTop(feeCategoryId: number | string): boolean {
|
export function moveFeeCategoryUpToTop(feeCategoryId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordUpToTop("FeeCategories", feeCategoryId);
|
||||||
|
return success;
|
||||||
const currentOrderNumber: number = database
|
|
||||||
.prepare("select orderNumber from FeeCategories where feeCategoryId = ?")
|
|
||||||
.get(feeCategoryId).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
database
|
|
||||||
.prepare("update FeeCategories set orderNumber = -1 where feeCategoryId = ?")
|
|
||||||
.run(feeCategoryId);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update FeeCategories
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveFeeCategoryUp;
|
export default moveFeeCategoryUp;
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,13 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotOccupantTypesCache } from "../functions.cache.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { moveRecordDown, moveRecordDownToBottom } from "./moveRecord.js";
|
||||||
import { getLotOccupantTypeById, clearLotOccupantTypesCache } from "../functions.cache.js";
|
|
||||||
export function moveLotOccupantTypeDown(lotOccupantTypeId) {
|
export function moveLotOccupantTypeDown(lotOccupantTypeId) {
|
||||||
const currentOrderNumber = getLotOccupantTypeById(typeof lotOccupantTypeId === "string"
|
const success = moveRecordDown("LotOccupantTypes", lotOccupantTypeId);
|
||||||
? Number.parseInt(lotOccupantTypeId)
|
|
||||||
: lotOccupantTypeId).orderNumber;
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare(`update LotOccupantTypes
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? + 1`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
const result = database
|
|
||||||
.prepare(`update LotOccupantTypes set orderNumber = ? + 1 where lotOccupantTypeId = ?`)
|
|
||||||
.run(currentOrderNumber, lotOccupantTypeId);
|
|
||||||
database.close();
|
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export function moveLotOccupantTypeDownToBottom(lotOccupantTypeId) {
|
export function moveLotOccupantTypeDownToBottom(lotOccupantTypeId) {
|
||||||
const currentOrderNumber = getLotOccupantTypeById(typeof lotOccupantTypeId === "string"
|
const success = moveRecordDownToBottom("LotOccupantTypes", lotOccupantTypeId);
|
||||||
? Number.parseInt(lotOccupantTypeId)
|
|
||||||
: lotOccupantTypeId).orderNumber;
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
const maxOrderNumber = database
|
|
||||||
.prepare(`select max(orderNumber) as maxOrderNumber
|
|
||||||
from LotOccupantTypes
|
|
||||||
where recordDelete_timeMillis is null`)
|
|
||||||
.get().maxOrderNumber;
|
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
|
||||||
database
|
|
||||||
.prepare("update LotOccupantTypes set orderNumber = ? + 1 where lotOccupantTypeId = ?")
|
|
||||||
.run(maxOrderNumber, lotOccupantTypeId);
|
|
||||||
database
|
|
||||||
.prepare(`update LotOccupantTypes
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber > ?`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
}
|
|
||||||
database.close();
|
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
return true;
|
return success;
|
||||||
}
|
}
|
||||||
export default moveLotOccupantTypeDown;
|
export default moveLotOccupantTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,75 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotOccupantTypesCache } from "../functions.cache.js";
|
||||||
|
import { moveRecordDown, moveRecordDownToBottom } from "./moveRecord.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import { getLotOccupantTypeById, clearLotOccupantTypesCache } from "../functions.cache.js";
|
|
||||||
|
|
||||||
export function moveLotOccupantTypeDown(lotOccupantTypeId: number | string): boolean {
|
export function moveLotOccupantTypeDown(lotOccupantTypeId: number | string): boolean {
|
||||||
const currentOrderNumber: number = getLotOccupantTypeById(
|
const success = moveRecordDown("LotOccupantTypes", lotOccupantTypeId);
|
||||||
typeof lotOccupantTypeId === "string"
|
|
||||||
? Number.parseInt(lotOccupantTypeId)
|
|
||||||
: lotOccupantTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotOccupantTypes
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? + 1`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(`update LotOccupantTypes set orderNumber = ? + 1 where lotOccupantTypeId = ?`)
|
|
||||||
.run(currentOrderNumber, lotOccupantTypeId);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
|
return success;
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveLotOccupantTypeDownToBottom(lotOccupantTypeId: number | string): boolean {
|
export function moveLotOccupantTypeDownToBottom(lotOccupantTypeId: number | string): boolean {
|
||||||
const currentOrderNumber: number = getLotOccupantTypeById(
|
const success = moveRecordDownToBottom("LotOccupantTypes", lotOccupantTypeId);
|
||||||
typeof lotOccupantTypeId === "string"
|
|
||||||
? Number.parseInt(lotOccupantTypeId)
|
|
||||||
: lotOccupantTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
|
||||||
.prepare(
|
|
||||||
`select max(orderNumber) as maxOrderNumber
|
|
||||||
from LotOccupantTypes
|
|
||||||
where recordDelete_timeMillis is null`
|
|
||||||
)
|
|
||||||
.get().maxOrderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
|
||||||
database
|
|
||||||
.prepare("update LotOccupantTypes set orderNumber = ? + 1 where lotOccupantTypeId = ?")
|
|
||||||
.run(maxOrderNumber, lotOccupantTypeId);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotOccupantTypes
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber > ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
|
return success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveLotOccupantTypeDown;
|
export default moveLotOccupantTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,13 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotOccupantTypesCache } from "../functions.cache.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { getLotOccupantTypeById, clearLotOccupantTypesCache } from "../functions.cache.js";
|
|
||||||
export function moveLotOccupantTypeUp(lotOccupantTypeId) {
|
export function moveLotOccupantTypeUp(lotOccupantTypeId) {
|
||||||
const currentOrderNumber = getLotOccupantTypeById(typeof lotOccupantTypeId === "string"
|
const success = moveRecordUp("LotOccupantTypes", lotOccupantTypeId);
|
||||||
? Number.parseInt(lotOccupantTypeId)
|
|
||||||
: lotOccupantTypeId).orderNumber;
|
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare(`update LotOccupantTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
const result = database
|
|
||||||
.prepare(`update LotOccupantTypes
|
|
||||||
set orderNumber = ? - 1
|
|
||||||
where lotOccupantTypeId = ?`)
|
|
||||||
.run(currentOrderNumber, lotOccupantTypeId);
|
|
||||||
database.close();
|
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export function moveLotOccupantTypeUpToTop(lotOccupantTypeId) {
|
export function moveLotOccupantTypeUpToTop(lotOccupantTypeId) {
|
||||||
const currentOrderNumber = getLotOccupantTypeById(typeof lotOccupantTypeId === "string"
|
const success = moveRecordUpToTop("LotOccupantTypes", lotOccupantTypeId);
|
||||||
? Number.parseInt(lotOccupantTypeId)
|
|
||||||
: lotOccupantTypeId).orderNumber;
|
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare("update LotOccupantTypes set orderNumber = -1 where lotOccupantTypeId = ?")
|
|
||||||
.run(lotOccupantTypeId);
|
|
||||||
database
|
|
||||||
.prepare(`update LotOccupantTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
database.close();
|
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
}
|
return success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
export default moveLotOccupantTypeUp;
|
export default moveLotOccupantTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,75 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotOccupantTypesCache } from "../functions.cache.js";
|
||||||
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import { getLotOccupantTypeById, clearLotOccupantTypesCache } from "../functions.cache.js";
|
|
||||||
|
|
||||||
export function moveLotOccupantTypeUp(lotOccupantTypeId: number | string): boolean {
|
export function moveLotOccupantTypeUp(lotOccupantTypeId: number | string): boolean {
|
||||||
const currentOrderNumber: number = getLotOccupantTypeById(
|
const success = moveRecordUp("LotOccupantTypes", lotOccupantTypeId);
|
||||||
typeof lotOccupantTypeId === "string"
|
|
||||||
? Number.parseInt(lotOccupantTypeId)
|
|
||||||
: lotOccupantTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotOccupantTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(
|
|
||||||
`update LotOccupantTypes
|
|
||||||
set orderNumber = ? - 1
|
|
||||||
where lotOccupantTypeId = ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber, lotOccupantTypeId);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
|
return success;
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveLotOccupantTypeUpToTop(lotOccupantTypeId: number | string): boolean {
|
export function moveLotOccupantTypeUpToTop(lotOccupantTypeId: number | string): boolean {
|
||||||
const currentOrderNumber: number = getLotOccupantTypeById(
|
const success = moveRecordUpToTop("LotOccupantTypes", lotOccupantTypeId);
|
||||||
typeof lotOccupantTypeId === "string"
|
|
||||||
? Number.parseInt(lotOccupantTypeId)
|
|
||||||
: lotOccupantTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare("update LotOccupantTypes set orderNumber = -1 where lotOccupantTypeId = ?")
|
|
||||||
.run(lotOccupantTypeId);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotOccupantTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotOccupantTypesCache();
|
clearLotOccupantTypesCache();
|
||||||
}
|
return success;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveLotOccupantTypeUp;
|
export default moveLotOccupantTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,13 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { moveRecordDown, moveRecordDownToBottom } from "./moveRecord.js";
|
||||||
import { getLotStatusById, clearLotStatusesCache } from "../functions.cache.js";
|
|
||||||
export function moveLotStatusDown(lotStatusId) {
|
export function moveLotStatusDown(lotStatusId) {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordDown("LotStatuses", lotStatusId);
|
||||||
const currentOrderNumber = getLotStatusById(typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId).orderNumber;
|
|
||||||
database
|
|
||||||
.prepare(`update LotStatuses
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? + 1`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
const result = database
|
|
||||||
.prepare(`update LotStatuses set orderNumber = ? + 1 where lotStatusId = ?`)
|
|
||||||
.run(currentOrderNumber, lotStatusId);
|
|
||||||
database.close();
|
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export function moveLotStatusDownToBottom(lotStatusId) {
|
export function moveLotStatusDownToBottom(lotStatusId) {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordDownToBottom("LotStatuses", lotStatusId);
|
||||||
const currentOrderNumber = getLotStatusById(typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId).orderNumber;
|
|
||||||
const maxOrderNumber = database
|
|
||||||
.prepare(`select max(orderNumber) as maxOrderNumber
|
|
||||||
from LotStatuses
|
|
||||||
where recordDelete_timeMillis is null`)
|
|
||||||
.get().maxOrderNumber;
|
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
|
||||||
database
|
|
||||||
.prepare("update LotStatuses set orderNumber = ? + 1 where lotStatusId = ?")
|
|
||||||
.run(maxOrderNumber, lotStatusId);
|
|
||||||
database
|
|
||||||
.prepare(`update LotStatuses
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber > ?`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
}
|
|
||||||
database.close();
|
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
return true;
|
return success;
|
||||||
}
|
}
|
||||||
export default moveLotStatusDown;
|
export default moveLotStatusDown;
|
||||||
|
|
|
||||||
|
|
@ -1,71 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||||
|
import { moveRecordDown, moveRecordDownToBottom } from "./moveRecord.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.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 success = moveRecordDown("LotStatuses", lotStatusId);
|
||||||
|
|
||||||
const currentOrderNumber: number = getLotStatusById(
|
|
||||||
typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotStatuses
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? + 1`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(`update LotStatuses set orderNumber = ? + 1 where lotStatusId = ?`)
|
|
||||||
.run(currentOrderNumber, lotStatusId);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
|
return success;
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveLotStatusDownToBottom(lotStatusId: number | string): boolean {
|
export function moveLotStatusDownToBottom(lotStatusId: number | string): boolean {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordDownToBottom("LotStatuses", lotStatusId);
|
||||||
|
|
||||||
const currentOrderNumber: number = getLotStatusById(
|
|
||||||
typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
|
||||||
.prepare(
|
|
||||||
`select max(orderNumber) as maxOrderNumber
|
|
||||||
from LotStatuses
|
|
||||||
where recordDelete_timeMillis is null`
|
|
||||||
)
|
|
||||||
.get().maxOrderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
|
||||||
database
|
|
||||||
.prepare("update LotStatuses set orderNumber = ? + 1 where lotStatusId = ?")
|
|
||||||
.run(maxOrderNumber, lotStatusId);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotStatuses
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber > ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
|
return success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveLotStatusDown;
|
export default moveLotStatusDown;
|
||||||
|
|
|
||||||
|
|
@ -1,42 +1,13 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { getLotStatusById, clearLotStatusesCache } from "../functions.cache.js";
|
|
||||||
export function moveLotStatusUp(lotStatusId) {
|
export function moveLotStatusUp(lotStatusId) {
|
||||||
const database = sqlite(databasePath);
|
const success = moveRecordUp("LotStatuses", lotStatusId);
|
||||||
const currentOrderNumber = getLotStatusById(typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId).orderNumber;
|
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
database.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
database
|
|
||||||
.prepare(`update LotStatuses
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
const result = database
|
|
||||||
.prepare("update LotStatuses set orderNumber = ? - 1 where lotStatusId = ?")
|
|
||||||
.run(currentOrderNumber, lotStatusId);
|
|
||||||
database.close();
|
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export function moveLotStatusUpToTop(lotStatusId) {
|
export function moveLotStatusUpToTop(lotStatusId) {
|
||||||
const currentOrderNumber = getLotStatusById(typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId).orderNumber;
|
const success = moveRecordUpToTop("LotStatuses", lotStatusId);
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare("update LotStatuses set orderNumber = -1 where lotStatusId = ?")
|
|
||||||
.run(lotStatusId);
|
|
||||||
database
|
|
||||||
.prepare(`update LotStatuses
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
database.close();
|
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
}
|
return success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
export default moveLotStatusUp;
|
export default moveLotStatusUp;
|
||||||
|
|
|
||||||
|
|
@ -1,68 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||||
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.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 success = moveRecordUp("LotStatuses", lotStatusId);
|
||||||
|
|
||||||
const currentOrderNumber: number = getLotStatusById(
|
|
||||||
typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
database.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotStatuses
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare("update LotStatuses set orderNumber = ? - 1 where lotStatusId = ?")
|
|
||||||
.run(currentOrderNumber, lotStatusId);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
|
return success;
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveLotStatusUpToTop(lotStatusId: number | string): boolean {
|
export function moveLotStatusUpToTop(lotStatusId: number | string): boolean {
|
||||||
const currentOrderNumber: number = getLotStatusById(
|
const success = moveRecordUpToTop("LotStatuses", lotStatusId);
|
||||||
typeof lotStatusId === "string" ? Number.parseInt(lotStatusId) : lotStatusId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare("update LotStatuses set orderNumber = -1 where lotStatusId = ?")
|
|
||||||
.run(lotStatusId);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotStatuses
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
}
|
return success;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveLotStatusUp;
|
export default moveLotStatusUp;
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,13 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { moveRecordDown, moveRecordDownToBottom } from "./moveRecord.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 success = moveRecordDown("LotTypes", lotTypeId);
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare(`update LotTypes
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? + 1`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
const result = database
|
|
||||||
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
|
||||||
.run(currentOrderNumber, lotTypeId);
|
|
||||||
database.close();
|
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export function moveLotTypeDownToBottom(lotTypeId) {
|
export function moveLotTypeDownToBottom(lotTypeId) {
|
||||||
const currentOrderNumber = getLotTypeById(typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId).orderNumber;
|
const success = moveRecordDownToBottom("LotTypes", lotTypeId);
|
||||||
const database = sqlite(databasePath);
|
|
||||||
const maxOrderNumber = database
|
|
||||||
.prepare(`select max(orderNumber) as maxOrderNumber
|
|
||||||
from LotTypes
|
|
||||||
where recordDelete_timeMillis is null`)
|
|
||||||
.get().maxOrderNumber;
|
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
|
||||||
database
|
|
||||||
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
|
||||||
.run(maxOrderNumber, lotTypeId);
|
|
||||||
database
|
|
||||||
.prepare(`update LotTypes
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber > ?`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
}
|
|
||||||
database.close();
|
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return true;
|
return success;
|
||||||
}
|
}
|
||||||
export default moveLotTypeDown;
|
export default moveLotTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,71 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
|
import { moveRecordDown, moveRecordDownToBottom } from "./moveRecord.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import { getLotTypeById, clearLotTypesCache } from "../functions.cache.js";
|
|
||||||
|
|
||||||
export function moveLotTypeDown(lotTypeId: number | string): boolean {
|
export function moveLotTypeDown(lotTypeId: number | string): boolean {
|
||||||
const currentOrderNumber = getLotTypeById(
|
const success = moveRecordDown("LotTypes", lotTypeId);
|
||||||
typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotTypes
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? + 1`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
|
||||||
.run(currentOrderNumber, lotTypeId);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
|
return success;
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveLotTypeDownToBottom(lotTypeId: number | string): boolean {
|
export function moveLotTypeDownToBottom(lotTypeId: number | string): boolean {
|
||||||
const currentOrderNumber = getLotTypeById(
|
const success = moveRecordDownToBottom("LotTypes", lotTypeId);
|
||||||
typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
const maxOrderNumber: number = database
|
|
||||||
.prepare(
|
|
||||||
`select max(orderNumber) as maxOrderNumber
|
|
||||||
from LotTypes
|
|
||||||
where recordDelete_timeMillis is null`
|
|
||||||
)
|
|
||||||
.get().maxOrderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber !== maxOrderNumber) {
|
|
||||||
database
|
|
||||||
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
|
||||||
.run(maxOrderNumber, lotTypeId);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotTypes
|
|
||||||
set orderNumber = orderNumber - 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber > ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
|
return success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveLotTypeDown;
|
export default moveLotTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,13 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { getLotTypeById, clearLotTypesCache } from "../functions.cache.js";
|
|
||||||
export function moveLotTypeUp(lotTypeId) {
|
export function moveLotTypeUp(lotTypeId) {
|
||||||
const currentOrderNumber = getLotTypeById(typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId).orderNumber;
|
const success = moveRecordUp("LotTypes", lotTypeId);
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare(`update LotTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
const result = database
|
|
||||||
.prepare("update LotTypes set orderNumber = ? - 1 where lotTypeId = ?")
|
|
||||||
.run(currentOrderNumber, lotTypeId);
|
|
||||||
database.close();
|
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export function moveLotTypeUpToTop(lotTypeId) {
|
export function moveLotTypeUpToTop(lotTypeId) {
|
||||||
const currentOrderNumber = getLotTypeById(typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId).orderNumber;
|
const success = moveRecordUpToTop("LotTypes", lotTypeId);
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
|
|
||||||
database
|
|
||||||
.prepare(`update LotTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
database.close();
|
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
}
|
return success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
export default moveLotTypeUp;
|
export default moveLotTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,64 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import { getLotTypeById, clearLotTypesCache } from "../functions.cache.js";
|
|
||||||
|
|
||||||
export function moveLotTypeUp(lotTypeId: number | string): boolean {
|
export function moveLotTypeUp(lotTypeId: number | string): boolean {
|
||||||
const currentOrderNumber = getLotTypeById(
|
const success = moveRecordUp("LotTypes", lotTypeId);
|
||||||
typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare("update LotTypes set orderNumber = ? - 1 where lotTypeId = ?")
|
|
||||||
.run(currentOrderNumber, lotTypeId);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
|
return success;
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveLotTypeUpToTop(lotTypeId: number | string): boolean {
|
export function moveLotTypeUpToTop(lotTypeId: number | string): boolean {
|
||||||
const currentOrderNumber = getLotTypeById(
|
const success = moveRecordUpToTop("LotTypes", lotTypeId);
|
||||||
typeof lotTypeId === "string" ? Number.parseInt(lotTypeId) : lotTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update LotTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
}
|
return success;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveLotTypeUp;
|
export default moveLotTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,13 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { getOccupancyTypeById, clearOccupancyTypesCache } from "../functions.cache.js";
|
|
||||||
export function moveOccupancyTypeUp(occupancyTypeId) {
|
export function moveOccupancyTypeUp(occupancyTypeId) {
|
||||||
const currentOrderNumber = getOccupancyTypeById(typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId).orderNumber;
|
const success = moveRecordUp("OccupancyTypes", occupancyTypeId);
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare(`update OccupancyTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
const result = database
|
|
||||||
.prepare("update OccupancyTypes set orderNumber = ? - 1 where occupancyTypeId = ?")
|
|
||||||
.run(currentOrderNumber, occupancyTypeId);
|
|
||||||
database.close();
|
|
||||||
clearOccupancyTypesCache();
|
clearOccupancyTypesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export function moveOccupancyTypeUpToTop(occupancyTypeId) {
|
export function moveOccupancyTypeUpToTop(occupancyTypeId) {
|
||||||
const currentOrderNumber = getOccupancyTypeById(typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId).orderNumber;
|
const success = moveRecordUpToTop("OccupancyTypes", occupancyTypeId);
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare("update OccupancyTypes set orderNumber = -1 where occupancyTypeId = ?")
|
|
||||||
.run(occupancyTypeId);
|
|
||||||
database
|
|
||||||
.prepare(`update OccupancyTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
database.close();
|
|
||||||
clearOccupancyTypesCache();
|
clearOccupancyTypesCache();
|
||||||
}
|
return success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
export default moveOccupancyTypeUp;
|
export default moveOccupancyTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,67 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import { getOccupancyTypeById, clearOccupancyTypesCache } from "../functions.cache.js";
|
|
||||||
|
|
||||||
export function moveOccupancyTypeUp(occupancyTypeId: number | string): boolean {
|
export function moveOccupancyTypeUp(occupancyTypeId: number | string): boolean {
|
||||||
const currentOrderNumber: number = getOccupancyTypeById(
|
const success = moveRecordUp("OccupancyTypes", occupancyTypeId);
|
||||||
typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update OccupancyTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare("update OccupancyTypes set orderNumber = ? - 1 where occupancyTypeId = ?")
|
|
||||||
.run(currentOrderNumber, occupancyTypeId);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearOccupancyTypesCache();
|
clearOccupancyTypesCache();
|
||||||
|
return success;
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveOccupancyTypeUpToTop(occupancyTypeId: number | string): boolean {
|
export function moveOccupancyTypeUpToTop(occupancyTypeId: number | string): boolean {
|
||||||
const currentOrderNumber: number = getOccupancyTypeById(
|
const success = moveRecordUpToTop("OccupancyTypes", occupancyTypeId);
|
||||||
typeof occupancyTypeId === "string" ? Number.parseInt(occupancyTypeId) : occupancyTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare("update OccupancyTypes set orderNumber = -1 where occupancyTypeId = ?")
|
|
||||||
.run(occupancyTypeId);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update OccupancyTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearOccupancyTypesCache();
|
clearOccupancyTypesCache();
|
||||||
}
|
return success;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveOccupancyTypeUp;
|
export default moveOccupancyTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
declare type RecordTable = "OccupancyTypes" | "WorkOrderMilestoneTypes" | "WorkOrderTypes";
|
declare type RecordTable = "FeeCategories" | "LotOccupantTypes" | "LotStatuses" | "LotTypes" | "OccupancyTypes" | "WorkOrderMilestoneTypes" | "WorkOrderTypes";
|
||||||
export declare function moveRecordDown(recordTable: RecordTable, recordId: number | string): boolean;
|
export declare function moveRecordDown(recordTable: RecordTable, recordId: number | string): boolean;
|
||||||
export declare function moveRecordDownToBottom(recordTable: RecordTable, recordId: number | string): boolean;
|
export declare function moveRecordDownToBottom(recordTable: RecordTable, recordId: number | string): boolean;
|
||||||
|
export declare function moveRecordUp(recordTable: RecordTable, recordId: number | string): boolean;
|
||||||
|
export declare function moveRecordUpToTop(recordTable: RecordTable, recordId: number | string): boolean;
|
||||||
export {};
|
export {};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
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";
|
||||||
const recordIdColumns = new Map();
|
const recordIdColumns = new Map();
|
||||||
|
recordIdColumns.set("FeeCategories", "feeCategoryId");
|
||||||
|
recordIdColumns.set("LotOccupantTypes", "lotOccupantTypeId");
|
||||||
|
recordIdColumns.set("LotStatuses", "lotStatusId");
|
||||||
|
recordIdColumns.set("LotTypes", "lotTypeId");
|
||||||
recordIdColumns.set("OccupancyTypes", "occupancyTypeId");
|
recordIdColumns.set("OccupancyTypes", "occupancyTypeId");
|
||||||
recordIdColumns.set("WorkOrderMilestoneTypes", "workOrderMilestoneTypeId");
|
recordIdColumns.set("WorkOrderMilestoneTypes", "workOrderMilestoneTypeId");
|
||||||
recordIdColumns.set("WorkOrderTypes", "workOrderTypeId");
|
recordIdColumns.set("WorkOrderTypes", "workOrderTypeId");
|
||||||
|
|
@ -51,3 +55,41 @@ export function moveRecordDownToBottom(recordTable, recordId) {
|
||||||
database.close();
|
database.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
export function moveRecordUp(recordTable, recordId) {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
const currentOrderNumber = getCurrentOrderNumber(recordTable, recordId, database);
|
||||||
|
if (currentOrderNumber <= 0) {
|
||||||
|
database.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
database
|
||||||
|
.prepare(`update ${recordTable}
|
||||||
|
set orderNumber = orderNumber + 1
|
||||||
|
where recordDelete_timeMillis is null
|
||||||
|
and orderNumber = ? - 1`)
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
const result = database
|
||||||
|
.prepare(`update ${recordTable}
|
||||||
|
set orderNumber = ? - 1
|
||||||
|
where ${recordIdColumns.get(recordTable)} = ?`)
|
||||||
|
.run(currentOrderNumber, recordId);
|
||||||
|
database.close();
|
||||||
|
return result.changes > 0;
|
||||||
|
}
|
||||||
|
export function moveRecordUpToTop(recordTable, recordId) {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
const currentOrderNumber = getCurrentOrderNumber(recordTable, recordId, database);
|
||||||
|
if (currentOrderNumber > 0) {
|
||||||
|
database
|
||||||
|
.prepare(`update ${recordTable} set orderNumber = -1 where ${recordIdColumns.get(recordTable)} = ?`)
|
||||||
|
.run(recordId);
|
||||||
|
database
|
||||||
|
.prepare(`update ${recordTable}
|
||||||
|
set orderNumber = orderNumber + 1
|
||||||
|
where recordDelete_timeMillis is null
|
||||||
|
and orderNumber < ?`)
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
}
|
||||||
|
database.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,20 @@ import sqlite from "better-sqlite3";
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
type RecordTable = "OccupancyTypes" | "WorkOrderMilestoneTypes" | "WorkOrderTypes";
|
type RecordTable =
|
||||||
|
| "FeeCategories"
|
||||||
|
| "LotOccupantTypes"
|
||||||
|
| "LotStatuses"
|
||||||
|
| "LotTypes"
|
||||||
|
| "OccupancyTypes"
|
||||||
|
| "WorkOrderMilestoneTypes"
|
||||||
|
| "WorkOrderTypes";
|
||||||
|
|
||||||
const recordIdColumns: Map<RecordTable, string> = new Map();
|
const recordIdColumns: Map<RecordTable, string> = new Map();
|
||||||
|
recordIdColumns.set("FeeCategories", "feeCategoryId");
|
||||||
|
recordIdColumns.set("LotOccupantTypes", "lotOccupantTypeId");
|
||||||
|
recordIdColumns.set("LotStatuses", "lotStatusId");
|
||||||
|
recordIdColumns.set("LotTypes", "lotTypeId");
|
||||||
recordIdColumns.set("OccupancyTypes", "occupancyTypeId");
|
recordIdColumns.set("OccupancyTypes", "occupancyTypeId");
|
||||||
recordIdColumns.set("WorkOrderMilestoneTypes", "workOrderMilestoneTypeId");
|
recordIdColumns.set("WorkOrderMilestoneTypes", "workOrderMilestoneTypeId");
|
||||||
recordIdColumns.set("WorkOrderTypes", "workOrderTypeId");
|
recordIdColumns.set("WorkOrderTypes", "workOrderTypeId");
|
||||||
|
|
@ -53,7 +64,6 @@ export function moveRecordDown(recordTable: RecordTable, recordId: number | stri
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveRecordDownToBottom(recordTable: RecordTable, recordId: number | string): boolean {
|
export function moveRecordDownToBottom(recordTable: RecordTable, recordId: number | string): boolean {
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber = getCurrentOrderNumber(recordTable, recordId, database);
|
const currentOrderNumber = getCurrentOrderNumber(recordTable, recordId, database);
|
||||||
|
|
@ -87,3 +97,62 @@ export function moveRecordDownToBottom(recordTable: RecordTable, recordId: numbe
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function moveRecordUp(recordTable: RecordTable, recordId: number | string): boolean {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
|
const currentOrderNumber = getCurrentOrderNumber(recordTable, recordId, database);
|
||||||
|
|
||||||
|
if (currentOrderNumber <= 0) {
|
||||||
|
database.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
`update ${recordTable}
|
||||||
|
set orderNumber = orderNumber + 1
|
||||||
|
where recordDelete_timeMillis is null
|
||||||
|
and orderNumber = ? - 1`
|
||||||
|
)
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
|
const result = database
|
||||||
|
.prepare(
|
||||||
|
`update ${recordTable}
|
||||||
|
set orderNumber = ? - 1
|
||||||
|
where ${recordIdColumns.get(recordTable)} = ?`
|
||||||
|
)
|
||||||
|
.run(currentOrderNumber, recordId);
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
return result.changes > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function moveRecordUpToTop(recordTable: RecordTable, recordId: number | string): boolean {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
|
const currentOrderNumber = getCurrentOrderNumber(recordTable, recordId, database);
|
||||||
|
|
||||||
|
if (currentOrderNumber > 0) {
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
`update ${recordTable} set orderNumber = -1 where ${recordIdColumns.get(recordTable)} = ?`
|
||||||
|
)
|
||||||
|
.run(recordId);
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
`update ${recordTable}
|
||||||
|
set orderNumber = orderNumber + 1
|
||||||
|
where recordDelete_timeMillis is null
|
||||||
|
and orderNumber < ?`
|
||||||
|
)
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { clearWorkOrderMilestoneTypesCache } from "../functions.cache.js";
|
import { clearWorkOrderMilestoneTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
import { moveRecordDown, moveRecordDownToBottom } from "./moveRecord.js";
|
import { moveRecordDown, moveRecordDownToBottom } from "./moveRecord.js";
|
||||||
|
|
||||||
export function moveWorkOrderMilestoneTypeDown(workOrderMilestoneTypeId: number | string): boolean {
|
export function moveWorkOrderMilestoneTypeDown(workOrderMilestoneTypeId: number | string): boolean {
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,13 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearWorkOrderMilestoneTypesCache } from "../functions.cache.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { getWorkOrderMilestoneTypeByWorkOrderMilestoneTypeId, clearWorkOrderMilestoneTypesCache } from "../functions.cache.js";
|
|
||||||
export function moveWorkOrderMilestoneTypeUp(workOrderMilestoneTypeId) {
|
export function moveWorkOrderMilestoneTypeUp(workOrderMilestoneTypeId) {
|
||||||
const currentOrderNumber = getWorkOrderMilestoneTypeByWorkOrderMilestoneTypeId(typeof workOrderMilestoneTypeId === "string"
|
const success = moveRecordUp("WorkOrderMilestoneTypes", workOrderMilestoneTypeId);
|
||||||
? Number.parseInt(workOrderMilestoneTypeId)
|
|
||||||
: workOrderMilestoneTypeId).orderNumber;
|
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare(`update WorkOrderMilestoneTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
const result = database
|
|
||||||
.prepare(`update WorkOrderMilestoneTypes
|
|
||||||
set orderNumber = ? - 1
|
|
||||||
where workOrderMilestoneTypeId = ?`)
|
|
||||||
.run(currentOrderNumber, workOrderMilestoneTypeId);
|
|
||||||
database.close();
|
|
||||||
clearWorkOrderMilestoneTypesCache();
|
clearWorkOrderMilestoneTypesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export function moveWorkOrderMilestoneTypeUpToTop(workOrderMilestoneTypeId) {
|
export function moveWorkOrderMilestoneTypeUpToTop(workOrderMilestoneTypeId) {
|
||||||
const currentOrderNumber = getWorkOrderMilestoneTypeByWorkOrderMilestoneTypeId(typeof workOrderMilestoneTypeId === "string"
|
const success = moveRecordUpToTop("WorkOrderMilestoneTypes", workOrderMilestoneTypeId);
|
||||||
? Number.parseInt(workOrderMilestoneTypeId)
|
|
||||||
: workOrderMilestoneTypeId).orderNumber;
|
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare("update WorkOrderMilestoneTypes set orderNumber = -1 where workOrderMilestoneTypeId = ?")
|
|
||||||
.run(workOrderMilestoneTypeId);
|
|
||||||
database
|
|
||||||
.prepare(`update WorkOrderMilestoneTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
database.close();
|
|
||||||
clearWorkOrderMilestoneTypesCache();
|
clearWorkOrderMilestoneTypesCache();
|
||||||
}
|
return success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
export default moveWorkOrderMilestoneTypeUp;
|
export default moveWorkOrderMilestoneTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,82 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearWorkOrderMilestoneTypesCache } from "../functions.cache.js";
|
||||||
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import {
|
|
||||||
getWorkOrderMilestoneTypeByWorkOrderMilestoneTypeId,
|
|
||||||
clearWorkOrderMilestoneTypesCache
|
|
||||||
} from "../functions.cache.js";
|
|
||||||
|
|
||||||
export function moveWorkOrderMilestoneTypeUp(workOrderMilestoneTypeId: number | string): boolean {
|
export function moveWorkOrderMilestoneTypeUp(workOrderMilestoneTypeId: number | string): boolean {
|
||||||
const currentOrderNumber: number = getWorkOrderMilestoneTypeByWorkOrderMilestoneTypeId(
|
const success = moveRecordUp("WorkOrderMilestoneTypes", workOrderMilestoneTypeId);
|
||||||
typeof workOrderMilestoneTypeId === "string"
|
|
||||||
? Number.parseInt(workOrderMilestoneTypeId)
|
|
||||||
: workOrderMilestoneTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update WorkOrderMilestoneTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(
|
|
||||||
`update WorkOrderMilestoneTypes
|
|
||||||
set orderNumber = ? - 1
|
|
||||||
where workOrderMilestoneTypeId = ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber, workOrderMilestoneTypeId);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearWorkOrderMilestoneTypesCache();
|
clearWorkOrderMilestoneTypesCache();
|
||||||
|
return success;
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveWorkOrderMilestoneTypeUpToTop(
|
export function moveWorkOrderMilestoneTypeUpToTop(workOrderMilestoneTypeId: number | string): boolean {
|
||||||
workOrderMilestoneTypeId: number | string
|
const success = moveRecordUpToTop("WorkOrderMilestoneTypes", workOrderMilestoneTypeId);
|
||||||
): boolean {
|
|
||||||
const currentOrderNumber: number = getWorkOrderMilestoneTypeByWorkOrderMilestoneTypeId(
|
|
||||||
typeof workOrderMilestoneTypeId === "string"
|
|
||||||
? Number.parseInt(workOrderMilestoneTypeId)
|
|
||||||
: workOrderMilestoneTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
"update WorkOrderMilestoneTypes set orderNumber = -1 where workOrderMilestoneTypeId = ?"
|
|
||||||
)
|
|
||||||
.run(workOrderMilestoneTypeId);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update WorkOrderMilestoneTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearWorkOrderMilestoneTypesCache();
|
clearWorkOrderMilestoneTypesCache();
|
||||||
}
|
return success;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveWorkOrderMilestoneTypeUp;
|
export default moveWorkOrderMilestoneTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,13 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearWorkOrderTypesCache } from "../functions.cache.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { getWorkOrderTypeById, clearWorkOrderTypesCache } from "../functions.cache.js";
|
|
||||||
export function moveWorkOrderTypeUp(workOrderTypeId) {
|
export function moveWorkOrderTypeUp(workOrderTypeId) {
|
||||||
const currentOrderNumber = getWorkOrderTypeById(typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId).orderNumber;
|
const success = moveRecordUp("WorkOrderTypes", workOrderTypeId);
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare(`update WorkOrderTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
const result = database
|
|
||||||
.prepare(`update WorkOrderTypes set orderNumber = ? - 1 where workOrderTypeId = ?`)
|
|
||||||
.run(currentOrderNumber, workOrderTypeId);
|
|
||||||
database.close();
|
|
||||||
clearWorkOrderTypesCache();
|
clearWorkOrderTypesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export function moveWorkOrderTypeUpToTop(workOrderTypeId) {
|
export function moveWorkOrderTypeUpToTop(workOrderTypeId) {
|
||||||
const currentOrderNumber = getWorkOrderTypeById(typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId).orderNumber;
|
const success = moveRecordUpToTop("WorkOrderTypes", workOrderTypeId);
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
database
|
|
||||||
.prepare("update WorkOrderTypes set orderNumber = -1 where workOrderTypeId = ?")
|
|
||||||
.run(workOrderTypeId);
|
|
||||||
database
|
|
||||||
.prepare(`update WorkOrderTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
database.close();
|
|
||||||
clearWorkOrderTypesCache();
|
clearWorkOrderTypesCache();
|
||||||
}
|
return success;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
export default moveWorkOrderTypeUp;
|
export default moveWorkOrderTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -1,67 +1,16 @@
|
||||||
import sqlite from "better-sqlite3";
|
import { clearWorkOrderTypesCache } from "../functions.cache.js";
|
||||||
|
import { moveRecordUp, moveRecordUpToTop } from "./moveRecord.js";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import { getWorkOrderTypeById, clearWorkOrderTypesCache } from "../functions.cache.js";
|
|
||||||
|
|
||||||
export function moveWorkOrderTypeUp(workOrderTypeId: number | string): boolean {
|
export function moveWorkOrderTypeUp(workOrderTypeId: number | string): boolean {
|
||||||
const currentOrderNumber: number = getWorkOrderTypeById(
|
const success = moveRecordUp("WorkOrderTypes", workOrderTypeId);
|
||||||
typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update WorkOrderTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber = ? - 1`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(`update WorkOrderTypes set orderNumber = ? - 1 where workOrderTypeId = ?`)
|
|
||||||
.run(currentOrderNumber, workOrderTypeId);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearWorkOrderTypesCache();
|
clearWorkOrderTypesCache();
|
||||||
|
return success;
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveWorkOrderTypeUpToTop(workOrderTypeId: number | string): boolean {
|
export function moveWorkOrderTypeUpToTop(workOrderTypeId: number | string): boolean {
|
||||||
const currentOrderNumber: number = getWorkOrderTypeById(
|
const success = moveRecordUpToTop("WorkOrderTypes", workOrderTypeId);
|
||||||
typeof workOrderTypeId === "string" ? Number.parseInt(workOrderTypeId) : workOrderTypeId
|
|
||||||
).orderNumber;
|
|
||||||
|
|
||||||
if (currentOrderNumber > 0) {
|
|
||||||
const database = sqlite(databasePath);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare("update WorkOrderTypes set orderNumber = -1 where workOrderTypeId = ?")
|
|
||||||
.run(workOrderTypeId);
|
|
||||||
|
|
||||||
database
|
|
||||||
.prepare(
|
|
||||||
`update WorkOrderTypes
|
|
||||||
set orderNumber = orderNumber + 1
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and orderNumber < ?`
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearWorkOrderTypesCache();
|
clearWorkOrderTypesCache();
|
||||||
}
|
return success;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default moveWorkOrderTypeUp;
|
export default moveWorkOrderTypeUp;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue