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