quick sorting lot types

deepsource-autofix-76c6eb20
Dan Gowans 2022-10-05 10:26:18 -04:00
parent d78232d852
commit a929d31ede
23 changed files with 304 additions and 55 deletions

View File

@ -1,7 +1,9 @@
import { moveLotTypeDown } from "../../helpers/lotOccupancyDB/moveLotTypeDown.js";
import { moveLotTypeDown, moveLotTypeDownToBottom } from "../../helpers/lotOccupancyDB/moveLotTypeDown.js";
import { getLotTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = moveLotTypeDown(request.body.lotTypeId);
const success = request.body.moveToBottom === "1"
? moveLotTypeDownToBottom(request.body.lotTypeId)
: moveLotTypeDown(request.body.lotTypeId);
const lotTypes = getLotTypes();
response.json({
success,

View File

@ -1,11 +1,17 @@
import type { RequestHandler } from "express";
import { moveLotTypeDown } from "../../helpers/lotOccupancyDB/moveLotTypeDown.js";
import {
moveLotTypeDown,
moveLotTypeDownToBottom
} from "../../helpers/lotOccupancyDB/moveLotTypeDown.js";
import { getLotTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success = moveLotTypeDown(request.body.lotTypeId);
const success =
request.body.moveToBottom === "1"
? moveLotTypeDownToBottom(request.body.lotTypeId)
: moveLotTypeDown(request.body.lotTypeId);
const lotTypes = getLotTypes();

View File

@ -1,7 +1,9 @@
import { moveLotTypeFieldDown } from "../../helpers/lotOccupancyDB/moveLotTypeFieldDown.js";
import { moveLotTypeFieldDown, moveLotTypeFieldDownToBottom } from "../../helpers/lotOccupancyDB/moveLotTypeFieldDown.js";
import { getLotTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = moveLotTypeFieldDown(request.body.lotTypeFieldId);
const success = request.body.moveToBottom === "1"
? moveLotTypeFieldDownToBottom(request.body.lotTypeFieldId)
: moveLotTypeFieldDown(request.body.lotTypeFieldId);
const lotTypes = getLotTypes();
response.json({
success,

View File

@ -1,11 +1,17 @@
import type { RequestHandler } from "express";
import { moveLotTypeFieldDown } from "../../helpers/lotOccupancyDB/moveLotTypeFieldDown.js";
import {
moveLotTypeFieldDown,
moveLotTypeFieldDownToBottom
} from "../../helpers/lotOccupancyDB/moveLotTypeFieldDown.js";
import { getLotTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success = moveLotTypeFieldDown(request.body.lotTypeFieldId);
const success =
request.body.moveToBottom === "1"
? moveLotTypeFieldDownToBottom(request.body.lotTypeFieldId)
: moveLotTypeFieldDown(request.body.lotTypeFieldId);
const lotTypes = getLotTypes();

View File

@ -1,7 +1,9 @@
import { moveLotTypeFieldUp } from "../../helpers/lotOccupancyDB/moveLotTypeFieldUp.js";
import { moveLotTypeFieldUp, moveLotTypeFieldUpToTop } from "../../helpers/lotOccupancyDB/moveLotTypeFieldUp.js";
import { getLotTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = moveLotTypeFieldUp(request.body.lotTypeFieldId);
const success = request.body.moveToTop === "1"
? moveLotTypeFieldUpToTop(request.body.lotTypeFieldId)
: moveLotTypeFieldUp(request.body.lotTypeFieldId);
const lotTypes = getLotTypes();
response.json({
success,

View File

@ -1,11 +1,17 @@
import type { RequestHandler } from "express";
import { moveLotTypeFieldUp } from "../../helpers/lotOccupancyDB/moveLotTypeFieldUp.js";
import {
moveLotTypeFieldUp,
moveLotTypeFieldUpToTop
} from "../../helpers/lotOccupancyDB/moveLotTypeFieldUp.js";
import { getLotTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success = moveLotTypeFieldUp(request.body.lotTypeFieldId);
const success =
request.body.moveToTop === "1"
? moveLotTypeFieldUpToTop(request.body.lotTypeFieldId)
: moveLotTypeFieldUp(request.body.lotTypeFieldId);
const lotTypes = getLotTypes();

View File

@ -1,7 +1,9 @@
import { moveLotTypeUp } from "../../helpers/lotOccupancyDB/moveLotTypeUp.js";
import { moveLotTypeUp, moveLotTypeUpToTop } from "../../helpers/lotOccupancyDB/moveLotTypeUp.js";
import { getLotTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = moveLotTypeUp(request.body.lotTypeId);
const success = request.body.moveToTop === "1"
? moveLotTypeUpToTop(request.body.lotTypeId)
: moveLotTypeUp(request.body.lotTypeId);
const lotTypes = getLotTypes();
response.json({
success,

View File

@ -1,11 +1,14 @@
import type { RequestHandler } from "express";
import { moveLotTypeUp } from "../../helpers/lotOccupancyDB/moveLotTypeUp.js";
import { moveLotTypeUp, moveLotTypeUpToTop } from "../../helpers/lotOccupancyDB/moveLotTypeUp.js";
import { getLotTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success = moveLotTypeUp(request.body.lotTypeId);
const success =
request.body.moveToTop === "1"
? moveLotTypeUpToTop(request.body.lotTypeId)
: moveLotTypeUp(request.body.lotTypeId);
const lotTypes = getLotTypes();

View File

@ -1,2 +1,3 @@
export declare const moveLotTypeDown: (lotTypeId: number | string) => boolean;
export declare const moveLotTypeDownToBottom: (lotTypeId: number | string) => boolean;
export default moveLotTypeDown;

View File

@ -4,7 +4,7 @@ import { clearLotTypesCache } from "../functions.cache.js";
export const moveLotTypeDown = (lotTypeId) => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare("select orderNumber" + " from LotTypes" + " where lotTypeId = ?")
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
.get(lotTypeId).orderNumber;
database
.prepare("update LotTypes" +
@ -13,10 +13,35 @@ export const moveLotTypeDown = (lotTypeId) => {
" and orderNumber = ? + 1")
.run(currentOrderNumber);
const result = database
.prepare("update LotTypes" + " set orderNumber = ? + 1" + " where lotTypeId = ?")
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
.run(currentOrderNumber, lotTypeId);
database.close();
clearLotTypesCache();
return result.changes > 0;
};
export const moveLotTypeDownToBottom = (lotTypeId) => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
.get(lotTypeId).orderNumber;
const maxOrderNumber = database
.prepare("select max(orderNumber) as maxOrderNumber" +
" from LotTypes" +
" 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();
return true;
};
export default moveLotTypeDown;

View File

@ -8,7 +8,7 @@ export const moveLotTypeDown = (lotTypeId: number | string): boolean => {
const database = sqlite(databasePath);
const currentOrderNumber: number = database
.prepare("select orderNumber" + " from LotTypes" + " where lotTypeId = ?")
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
.get(lotTypeId).orderNumber;
database
@ -21,7 +21,7 @@ export const moveLotTypeDown = (lotTypeId: number | string): boolean => {
.run(currentOrderNumber);
const result = database
.prepare("update LotTypes" + " set orderNumber = ? + 1" + " where lotTypeId = ?")
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
.run(currentOrderNumber, lotTypeId);
database.close();
@ -31,4 +31,41 @@ export const moveLotTypeDown = (lotTypeId: number | string): boolean => {
return result.changes > 0;
};
export const moveLotTypeDownToBottom = (lotTypeId: number | string): boolean => {
const database = sqlite(databasePath);
const currentOrderNumber: number = database
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
.get(lotTypeId).orderNumber;
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();
return true;
};
export default moveLotTypeDown;

View File

@ -1,2 +1,3 @@
export declare const moveLotTypeFieldDown: (lotTypeFieldId: number | string) => boolean;
export declare const moveLotTypeFieldDownToBottom: (lotTypeFieldId: number | string) => boolean;
export default moveLotTypeFieldDown;

View File

@ -20,4 +20,31 @@ export const moveLotTypeFieldDown = (lotTypeFieldId) => {
clearLotTypesCache();
return result.changes > 0;
};
export const moveLotTypeFieldDownToBottom = (lotTypeFieldId) => {
const database = sqlite(databasePath);
const currentField = database
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
.get(lotTypeFieldId);
const maxOrderNumber = database
.prepare("select max(orderNumber) as maxOrderNumber" +
" from LotTypeFields" +
" where recordDelete_timeMillis is null" +
" and lotTypeId = ?")
.get(currentField.lotTypeId).maxOrderNumber;
if (currentField.orderNumber !== maxOrderNumber) {
database
.prepare("update LotTypeFields set orderNumber = ? + 1 where lotTypeFieldId = ?")
.run(maxOrderNumber, lotTypeFieldId);
database
.prepare("update LotTypeFields" +
" set orderNumber = orderNumber - 1" +
" where recordDelete_timeMillis is null" +
" and lotTypeId = ?" +
" and orderNumber > ?")
.run(currentField.lotTypeId, currentField.orderNumber);
}
database.close();
clearLotTypesCache();
return true;
};
export default moveLotTypeFieldDown;

View File

@ -8,9 +8,7 @@ export const moveLotTypeFieldDown = (lotTypeFieldId: number | string): boolean =
const database = sqlite(databasePath);
const currentField: { lotTypeId?: number; orderNumber: number } = database
.prepare(
"select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?"
)
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
.get(lotTypeFieldId);
database
@ -34,4 +32,43 @@ export const moveLotTypeFieldDown = (lotTypeFieldId: number | string): boolean =
return result.changes > 0;
};
export const moveLotTypeFieldDownToBottom = (lotTypeFieldId: number | string): boolean => {
const database = sqlite(databasePath);
const currentField: { lotTypeId?: number; orderNumber: number } = database
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
.get(lotTypeFieldId);
const maxOrderNumber: number = database
.prepare(
"select max(orderNumber) as maxOrderNumber" +
" from LotTypeFields" +
" where recordDelete_timeMillis is null" +
" and lotTypeId = ?"
)
.get(currentField.lotTypeId).maxOrderNumber;
if (currentField.orderNumber !== maxOrderNumber) {
database
.prepare("update LotTypeFields set orderNumber = ? + 1 where lotTypeFieldId = ?")
.run(maxOrderNumber, lotTypeFieldId);
database
.prepare(
"update LotTypeFields" +
" set orderNumber = orderNumber - 1" +
" where recordDelete_timeMillis is null" +
" and lotTypeId = ?" +
" and orderNumber > ?"
)
.run(currentField.lotTypeId, currentField.orderNumber);
}
database.close();
clearLotTypesCache();
return true;
};
export default moveLotTypeFieldDown;

View File

@ -1,2 +1,3 @@
export declare const moveLotTypeFieldUp: (lotTypeFieldId: number | string) => boolean;
export declare const moveLotTypeFieldUpToTop: (lotTypeFieldId: number | string) => boolean;
export default moveLotTypeFieldUp;

View File

@ -24,4 +24,25 @@ export const moveLotTypeFieldUp = (lotTypeFieldId) => {
clearLotTypesCache();
return result.changes > 0;
};
export const moveLotTypeFieldUpToTop = (lotTypeFieldId) => {
const database = sqlite(databasePath);
const currentField = database
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
.get(lotTypeFieldId);
if (currentField.orderNumber > 0) {
database
.prepare("update LotTypeFields set orderNumber = -1 where lotTypeFieldId = ?")
.run(lotTypeFieldId);
database
.prepare("update LotTypeFields" +
" set orderNumber = orderNumber + 1" +
" where recordDelete_timeMillis is null" +
" and lotTypeId = ?" +
" and orderNumber < ?")
.run(currentField.lotTypeId, currentField.orderNumber);
}
database.close();
clearLotTypesCache();
return true;
};
export default moveLotTypeFieldUp;

View File

@ -37,4 +37,34 @@ export const moveLotTypeFieldUp = (lotTypeFieldId: number | string): boolean =>
return result.changes > 0;
};
export const moveLotTypeFieldUpToTop = (lotTypeFieldId: number | string): boolean => {
const database = sqlite(databasePath);
const currentField: { lotTypeId: number; orderNumber: number } = database
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
.get(lotTypeFieldId);
if (currentField.orderNumber > 0) {
database
.prepare("update LotTypeFields set orderNumber = -1 where lotTypeFieldId = ?")
.run(lotTypeFieldId);
database
.prepare(
"update LotTypeFields" +
" set orderNumber = orderNumber + 1" +
" where recordDelete_timeMillis is null" +
" and lotTypeId = ?" +
" and orderNumber < ?"
)
.run(currentField.lotTypeId, currentField.orderNumber);
}
database.close();
clearLotTypesCache();
return true;
};
export default moveLotTypeFieldUp;

View File

@ -1,2 +1,3 @@
export declare const moveLotTypeUp: (lotTypeId: number | string) => boolean;
export declare const moveLotTypeUpToTop: (lotTypeId: number | string) => boolean;
export default moveLotTypeUp;

View File

@ -4,9 +4,7 @@ import { clearLotTypesCache } from "../functions.cache.js";
export const moveLotTypeUp = (lotTypeId) => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare("select orderNumber" +
" from LotTypes" +
" where lotTypeId = ?")
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
.get(lotTypeId).orderNumber;
if (currentOrderNumber <= 0) {
database.close();
@ -19,12 +17,28 @@ export const moveLotTypeUp = (lotTypeId) => {
" and orderNumber = ? - 1")
.run(currentOrderNumber);
const result = database
.prepare("update LotTypes" +
" set orderNumber = ? - 1" +
" where lotTypeId = ?")
.prepare("update LotTypes set orderNumber = ? - 1 where lotTypeId = ?")
.run(currentOrderNumber, lotTypeId);
database.close();
clearLotTypesCache();
return result.changes > 0;
};
export const moveLotTypeUpToTop = (lotTypeId) => {
const database = sqlite(databasePath);
const currentOrderNumber = database
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
.get(lotTypeId).orderNumber;
if (currentOrderNumber > 0) {
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
database
.prepare("update LotTypes" +
" set orderNumber = orderNumber + 1" +
" where recordDelete_timeMillis is null" +
" and orderNumber < ?")
.run(currentOrderNumber);
}
database.close();
clearLotTypesCache();
return true;
};
export default moveLotTypeUp;

View File

@ -4,17 +4,11 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearLotTypesCache } from "../functions.cache.js";
export const moveLotTypeUp = (
lotTypeId: number | string
): boolean => {
export const moveLotTypeUp = (lotTypeId: number | string): boolean => {
const database = sqlite(databasePath);
const currentOrderNumber: number = database
.prepare(
"select orderNumber" +
" from LotTypes" +
" where lotTypeId = ?"
)
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
.get(lotTypeId).orderNumber;
if (currentOrderNumber <= 0) {
@ -32,11 +26,7 @@ export const moveLotTypeUp = (
.run(currentOrderNumber);
const result = database
.prepare(
"update LotTypes" +
" set orderNumber = ? - 1" +
" where lotTypeId = ?"
)
.prepare("update LotTypes set orderNumber = ? - 1 where lotTypeId = ?")
.run(currentOrderNumber, lotTypeId);
database.close();
@ -46,4 +36,31 @@ export const moveLotTypeUp = (
return result.changes > 0;
};
export const moveLotTypeUpToTop = (lotTypeId: number | string): boolean => {
const database = sqlite(databasePath);
const currentOrderNumber: number = database
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
.get(lotTypeId).orderNumber;
if (currentOrderNumber > 0) {
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
database
.prepare(
"update LotTypes" +
" set orderNumber = orderNumber + 1" +
" where recordDelete_timeMillis is null" +
" and orderNumber < ?"
)
.run(currentOrderNumber);
}
database.close();
clearLotTypesCache();
return true;
};
export default moveLotTypeUp;

View File

@ -127,14 +127,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
clickEvent.preventDefault();
const lotTypeId = clickEvent.currentTarget.closest(".container--lotType").dataset.lotTypeId;
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeUp", {
lotTypeId
lotTypeId,
moveToTop: clickEvent.shiftKey ? "1" : "0"
}, lotTypeResponseHandler);
};
const moveLotTypeDown = (clickEvent) => {
clickEvent.preventDefault();
const lotTypeId = clickEvent.currentTarget.closest(".container--lotType").dataset.lotTypeId;
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeDown", {
lotTypeId
lotTypeId,
moveToBottom: clickEvent.shiftKey ? "1" : "0"
}, lotTypeResponseHandler);
};
const openEditLotTypeField = (lotTypeId, lotTypeFieldId) => {
@ -239,14 +241,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
clickEvent.preventDefault();
const lotTypeFieldId = clickEvent.currentTarget.closest(".container--lotTypeField").dataset.lotTypeFieldId;
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeFieldUp", {
lotTypeFieldId
lotTypeFieldId,
moveToTop: clickEvent.shiftKey ? "1" : "0"
}, lotTypeResponseHandler);
};
const moveLotTypeFieldDown = (clickEvent) => {
clickEvent.preventDefault();
const lotTypeFieldId = clickEvent.currentTarget.closest(".container--lotTypeField").dataset.lotTypeFieldId;
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeFieldDown", {
lotTypeFieldId
lotTypeFieldId,
moveToBottom: clickEvent.shiftKey ? "1" : "0"
}, lotTypeResponseHandler);
};
const renderLotTypeFields = (panelElement, lotTypeId, lotTypeFields) => {

View File

@ -221,7 +221,7 @@ declare const bulmaJS: BulmaJS;
});
};
const moveLotTypeUp = (clickEvent: Event) => {
const moveLotTypeUp = (clickEvent: MouseEvent) => {
clickEvent.preventDefault();
const lotTypeId = (
@ -231,13 +231,14 @@ declare const bulmaJS: BulmaJS;
cityssm.postJSON(
urlPrefix + "/admin/doMoveLotTypeUp",
{
lotTypeId
lotTypeId,
moveToTop: clickEvent.shiftKey ? "1" : "0"
},
lotTypeResponseHandler
);
};
const moveLotTypeDown = (clickEvent: Event) => {
const moveLotTypeDown = (clickEvent: MouseEvent) => {
clickEvent.preventDefault();
const lotTypeId = (
@ -247,7 +248,8 @@ declare const bulmaJS: BulmaJS;
cityssm.postJSON(
urlPrefix + "/admin/doMoveLotTypeDown",
{
lotTypeId
lotTypeId,
moveToBottom: clickEvent.shiftKey ? "1" : "0"
},
lotTypeResponseHandler
);
@ -429,7 +431,7 @@ declare const bulmaJS: BulmaJS;
openEditLotTypeField(lotTypeId, lotTypeFieldId);
};
const moveLotTypeFieldUp = (clickEvent: Event) => {
const moveLotTypeFieldUp = (clickEvent: MouseEvent) => {
clickEvent.preventDefault();
const lotTypeFieldId = (
@ -441,13 +443,14 @@ declare const bulmaJS: BulmaJS;
cityssm.postJSON(
urlPrefix + "/admin/doMoveLotTypeFieldUp",
{
lotTypeFieldId
lotTypeFieldId,
moveToTop: clickEvent.shiftKey ? "1" : "0"
},
lotTypeResponseHandler
);
};
const moveLotTypeFieldDown = (clickEvent: Event) => {
const moveLotTypeFieldDown = (clickEvent: MouseEvent) => {
clickEvent.preventDefault();
const lotTypeFieldId = (
@ -459,7 +462,8 @@ declare const bulmaJS: BulmaJS;
cityssm.postJSON(
urlPrefix + "/admin/doMoveLotTypeFieldDown",
{
lotTypeFieldId
lotTypeFieldId,
moveToBottom: clickEvent.shiftKey ? "1" : "0"
},
lotTypeResponseHandler
);

File diff suppressed because one or more lines are too long