move code cleanup
parent
5e335c7926
commit
6d05ef2c9d
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
export declare function moveFeeDown(feeId: number | string): boolean;
|
||||
export declare function moveFeeDownToBottom(feeId: number | string): boolean;
|
||||
export default moveFeeDown;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
Loading…
Reference in New Issue