diff --git a/handlers/admin-post/doMoveFeeDown.js b/handlers/admin-post/doMoveFeeDown.js index 29f4c482..1e0173b1 100644 --- a/handlers/admin-post/doMoveFeeDown.js +++ b/handlers/admin-post/doMoveFeeDown.js @@ -1,4 +1,4 @@ -import { moveFeeDown, moveFeeDownToBottom } from "../../helpers/lotOccupancyDB/moveFeeDown.js"; +import { moveFeeDown, moveFeeDownToBottom } from "../../helpers/lotOccupancyDB/moveFee.js"; import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js"; export const handler = async (request, response) => { const success = request.body.moveToEnd === "1" diff --git a/handlers/admin-post/doMoveFeeDown.ts b/handlers/admin-post/doMoveFeeDown.ts index 4a550fdf..a34b5b99 100644 --- a/handlers/admin-post/doMoveFeeDown.ts +++ b/handlers/admin-post/doMoveFeeDown.ts @@ -1,6 +1,6 @@ import type { RequestHandler } from "express"; -import { moveFeeDown, moveFeeDownToBottom } from "../../helpers/lotOccupancyDB/moveFeeDown.js"; +import { moveFeeDown, moveFeeDownToBottom } from "../../helpers/lotOccupancyDB/moveFee.js"; import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js"; diff --git a/handlers/admin-post/doMoveFeeUp.js b/handlers/admin-post/doMoveFeeUp.js index fb911669..1e04076c 100644 --- a/handlers/admin-post/doMoveFeeUp.js +++ b/handlers/admin-post/doMoveFeeUp.js @@ -1,4 +1,4 @@ -import { moveFeeUp, moveFeeUpToTop } from "../../helpers/lotOccupancyDB/moveFeeUp.js"; +import { moveFeeUp, moveFeeUpToTop } from "../../helpers/lotOccupancyDB/moveFee.js"; import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js"; export const handler = async (request, response) => { const success = request.body.moveToEnd === "1" diff --git a/handlers/admin-post/doMoveFeeUp.ts b/handlers/admin-post/doMoveFeeUp.ts index 8071b415..b8cd1ec9 100644 --- a/handlers/admin-post/doMoveFeeUp.ts +++ b/handlers/admin-post/doMoveFeeUp.ts @@ -1,6 +1,6 @@ import type { RequestHandler } from "express"; -import { moveFeeUp, moveFeeUpToTop } from "../../helpers/lotOccupancyDB/moveFeeUp.js"; +import { moveFeeUp, moveFeeUpToTop } from "../../helpers/lotOccupancyDB/moveFee.js"; import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js"; diff --git a/helpers/lotOccupancyDB/moveFeeUp.d.ts b/helpers/lotOccupancyDB/moveFee.d.ts similarity index 51% rename from helpers/lotOccupancyDB/moveFeeUp.d.ts rename to helpers/lotOccupancyDB/moveFee.d.ts index 5d3e5834..1b6b7bee 100644 --- a/helpers/lotOccupancyDB/moveFeeUp.d.ts +++ b/helpers/lotOccupancyDB/moveFee.d.ts @@ -1,3 +1,5 @@ +export declare function moveFeeDown(feeId: number | string): boolean; +export declare function moveFeeDownToBottom(feeId: number | string): boolean; export declare function moveFeeUp(feeId: number): boolean; export declare function moveFeeUpToTop(feeId: number | string): boolean; export default moveFeeUp; diff --git a/helpers/lotOccupancyDB/moveFeeDown.js b/helpers/lotOccupancyDB/moveFee.js similarity index 56% rename from helpers/lotOccupancyDB/moveFeeDown.js rename to helpers/lotOccupancyDB/moveFee.js index 5ed1380f..a7a52e23 100644 --- a/helpers/lotOccupancyDB/moveFeeDown.js +++ b/helpers/lotOccupancyDB/moveFee.js @@ -37,4 +37,38 @@ export function moveFeeDownToBottom(feeId) { database.close(); return true; } -export default moveFeeDown; +export function moveFeeUp(feeId) { + const database = sqlite(databasePath); + const currentFee = getFee(feeId, database); + if (currentFee.orderNumber <= 0) { + database.close(); + return true; + } + database + .prepare(`update Fees + set orderNumber = orderNumber + 1 + where recordDelete_timeMillis is null + and feeCategoryId = ? + and orderNumber = ? - 1`) + .run(currentFee.feeCategoryId, currentFee.orderNumber); + const success = updateRecordOrderNumber("Fees", feeId, currentFee.orderNumber - 1, database); + database.close(); + return success; +} +export function moveFeeUpToTop(feeId) { + const database = sqlite(databasePath); + const currentFee = getFee(feeId, database); + if (currentFee.orderNumber > 0) { + updateRecordOrderNumber("Fees", feeId, -1, database); + database + .prepare(`update Fees + set orderNumber = orderNumber + 1 + where recordDelete_timeMillis is null + and feeCategoryId = ? + and orderNumber < ?`) + .run(currentFee.feeCategoryId, currentFee.orderNumber); + } + database.close(); + return true; +} +export default moveFeeUp; diff --git a/helpers/lotOccupancyDB/moveFeeDown.ts b/helpers/lotOccupancyDB/moveFee.ts similarity index 56% rename from helpers/lotOccupancyDB/moveFeeDown.ts rename to helpers/lotOccupancyDB/moveFee.ts index 319dc43b..bc186f5d 100644 --- a/helpers/lotOccupancyDB/moveFeeDown.ts +++ b/helpers/lotOccupancyDB/moveFee.ts @@ -59,4 +59,55 @@ export function moveFeeDownToBottom(feeId: number | string): boolean { return true; } -export default moveFeeDown; +export function moveFeeUp(feeId: number): boolean { + const database = sqlite(databasePath); + + const currentFee = getFee(feeId, database); + + if (currentFee.orderNumber <= 0) { + database.close(); + return true; + } + + database + .prepare( + `update Fees + set orderNumber = orderNumber + 1 + where recordDelete_timeMillis is null + and feeCategoryId = ? + and orderNumber = ? - 1` + ) + .run(currentFee.feeCategoryId, currentFee.orderNumber); + + const success = updateRecordOrderNumber("Fees", feeId, currentFee.orderNumber - 1, database); + + database.close(); + + return success; +} + +export function moveFeeUpToTop(feeId: number | string): boolean { + const database = sqlite(databasePath); + + const currentFee = getFee(feeId, database); + + if (currentFee.orderNumber > 0) { + updateRecordOrderNumber("Fees", feeId, -1, database); + + database + .prepare( + `update Fees + set orderNumber = orderNumber + 1 + where recordDelete_timeMillis is null + and feeCategoryId = ? + and orderNumber < ?` + ) + .run(currentFee.feeCategoryId, currentFee.orderNumber); + } + + database.close(); + + return true; +} + +export default moveFeeUp; diff --git a/helpers/lotOccupancyDB/moveFeeDown.d.ts b/helpers/lotOccupancyDB/moveFeeDown.d.ts deleted file mode 100644 index 3ffbe432..00000000 --- a/helpers/lotOccupancyDB/moveFeeDown.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export declare function moveFeeDown(feeId: number | string): boolean; -export declare function moveFeeDownToBottom(feeId: number | string): boolean; -export default moveFeeDown; diff --git a/helpers/lotOccupancyDB/moveFeeUp.js b/helpers/lotOccupancyDB/moveFeeUp.js deleted file mode 100644 index d3a8efd7..00000000 --- a/helpers/lotOccupancyDB/moveFeeUp.js +++ /dev/null @@ -1,39 +0,0 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { getFee } from "./getFee.js"; -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; -export function moveFeeUp(feeId) { - const database = sqlite(databasePath); - const currentFee = getFee(feeId, database); - if (currentFee.orderNumber <= 0) { - database.close(); - return true; - } - database - .prepare(`update Fees - set orderNumber = orderNumber + 1 - where recordDelete_timeMillis is null - and feeCategoryId = ? - and orderNumber = ? - 1`) - .run(currentFee.feeCategoryId, currentFee.orderNumber); - const success = updateRecordOrderNumber("Fees", feeId, currentFee.orderNumber - 1, database); - database.close(); - return success; -} -export function moveFeeUpToTop(feeId) { - const database = sqlite(databasePath); - const currentFee = getFee(feeId, database); - if (currentFee.orderNumber > 0) { - updateRecordOrderNumber("Fees", feeId, -1, database); - database - .prepare(`update Fees - set orderNumber = orderNumber + 1 - where recordDelete_timeMillis is null - and feeCategoryId = ? - and orderNumber < ?`) - .run(currentFee.feeCategoryId, currentFee.orderNumber); - } - database.close(); - return true; -} -export default moveFeeUp; diff --git a/helpers/lotOccupancyDB/moveFeeUp.ts b/helpers/lotOccupancyDB/moveFeeUp.ts deleted file mode 100644 index 3412811b..00000000 --- a/helpers/lotOccupancyDB/moveFeeUp.ts +++ /dev/null @@ -1,59 +0,0 @@ -import sqlite from "better-sqlite3"; - -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; - -import { getFee } from "./getFee.js"; -import { updateRecordOrderNumber } from "./updateRecordOrderNumber.js"; - -export function moveFeeUp(feeId: number): boolean { - const database = sqlite(databasePath); - - const currentFee = getFee(feeId, database); - - if (currentFee.orderNumber <= 0) { - database.close(); - return true; - } - - database - .prepare( - `update Fees - set orderNumber = orderNumber + 1 - where recordDelete_timeMillis is null - and feeCategoryId = ? - and orderNumber = ? - 1` - ) - .run(currentFee.feeCategoryId, currentFee.orderNumber); - - const success = updateRecordOrderNumber("Fees", feeId, currentFee.orderNumber - 1, database); - - database.close(); - - return success; -} - -export function moveFeeUpToTop(feeId: number | string): boolean { - const database = sqlite(databasePath); - - const currentFee = getFee(feeId, database); - - if (currentFee.orderNumber > 0) { - updateRecordOrderNumber("Fees", feeId, -1, database); - - database - .prepare( - `update Fees - set orderNumber = orderNumber + 1 - where recordDelete_timeMillis is null - and feeCategoryId = ? - and orderNumber < ?` - ) - .run(currentFee.feeCategoryId, currentFee.orderNumber); - } - - database.close(); - - return true; -} - -export default moveFeeUp;