remove duplicate update code
parent
19e3ecc0be
commit
992bb3c6b0
|
|
@ -1,7 +1,7 @@
|
|||
import { updateLotStatus } from "../../helpers/lotOccupancyDB/updateLotStatus.js";
|
||||
import { updateRecord } from "../../helpers/lotOccupancyDB/updateRecord.js";
|
||||
import { getLotStatuses } from "../../helpers/functions.cache.js";
|
||||
export const handler = async (request, response) => {
|
||||
const success = updateLotStatus(request.body, request.session);
|
||||
const success = updateRecord("LotStatuses", request.body.lotStatusId, request.body.lotStatus, request.session);
|
||||
const lotStatuses = getLotStatuses();
|
||||
response.json({
|
||||
success,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
import type { RequestHandler } from "express";
|
||||
|
||||
import { updateLotStatus } from "../../helpers/lotOccupancyDB/updateLotStatus.js";
|
||||
|
||||
import { updateRecord } from "../../helpers/lotOccupancyDB/updateRecord.js";
|
||||
import { getLotStatuses } from "../../helpers/functions.cache.js";
|
||||
|
||||
export const handler: RequestHandler = async (request, response) => {
|
||||
const success = updateLotStatus(request.body, request.session);
|
||||
const success = updateRecord(
|
||||
"LotStatuses",
|
||||
request.body.lotStatusId,
|
||||
request.body.lotStatus,
|
||||
request.session
|
||||
);
|
||||
|
||||
const lotStatuses = getLotStatuses();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { updateLotType } from "../../helpers/lotOccupancyDB/updateLotType.js";
|
||||
import { updateRecord } from "../../helpers/lotOccupancyDB/updateRecord.js";
|
||||
import { getLotTypes } from "../../helpers/functions.cache.js";
|
||||
export const handler = async (request, response) => {
|
||||
const success = updateLotType(request.body, request.session);
|
||||
const success = updateRecord("LotTypes", request.body.lotTypeId, request.body.lotType, request.session);
|
||||
const lotTypes = getLotTypes();
|
||||
response.json({
|
||||
success,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import type { RequestHandler } from "express";
|
||||
|
||||
import { updateLotType } from "../../helpers/lotOccupancyDB/updateLotType.js";
|
||||
|
||||
import { updateRecord } from "../../helpers/lotOccupancyDB/updateRecord.js";
|
||||
import { getLotTypes } from "../../helpers/functions.cache.js";
|
||||
|
||||
export const handler: RequestHandler = async (request, response) => {
|
||||
const success = updateLotType(request.body, request.session);
|
||||
const success = updateRecord("LotTypes", request.body.lotTypeId, request.body.lotType, request.session);
|
||||
|
||||
const lotTypes = getLotTypes();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { updateOccupancyType } from "../../helpers/lotOccupancyDB/updateOccupancyType.js";
|
||||
import { updateRecord } from "../../helpers/lotOccupancyDB/updateRecord.js";
|
||||
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||
export const handler = async (request, response) => {
|
||||
const success = updateOccupancyType(request.body, request.session);
|
||||
const success = updateRecord("OccupancyTypes", request.body.occupancyTypeId, request.body.occupancyType, request.session);
|
||||
const occupancyTypes = getOccupancyTypes();
|
||||
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
||||
response.json({
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
import type { RequestHandler } from "express";
|
||||
|
||||
import { updateOccupancyType } from "../../helpers/lotOccupancyDB/updateOccupancyType.js";
|
||||
|
||||
import { updateRecord } from "../../helpers/lotOccupancyDB/updateRecord.js";
|
||||
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||
|
||||
export const handler: RequestHandler = async (request, response) => {
|
||||
const success = updateOccupancyType(request.body, request.session);
|
||||
const success = updateRecord(
|
||||
"OccupancyTypes",
|
||||
request.body.occupancyTypeId,
|
||||
request.body.occupancyType,
|
||||
request.session
|
||||
);
|
||||
|
||||
const occupancyTypes = getOccupancyTypes();
|
||||
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { updateWorkOrderMilestoneType } from "../../helpers/lotOccupancyDB/updateWorkOrderMilestoneType.js";
|
||||
import { updateRecord } from "../../helpers/lotOccupancyDB/updateRecord.js";
|
||||
import { getWorkOrderMilestoneTypes } from "../../helpers/functions.cache.js";
|
||||
export const handler = async (request, response) => {
|
||||
const success = updateWorkOrderMilestoneType(request.body, request.session);
|
||||
const success = updateRecord("WorkOrderMilestoneTypes", request.body.workOrderMilestoneTypeId, request.body.workOrderMilestoneType, request.session);
|
||||
const workOrderMilestoneTypes = getWorkOrderMilestoneTypes();
|
||||
response.json({
|
||||
success,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
import type { RequestHandler } from "express";
|
||||
|
||||
import { updateWorkOrderMilestoneType } from "../../helpers/lotOccupancyDB/updateWorkOrderMilestoneType.js";
|
||||
|
||||
import { updateRecord } from "../../helpers/lotOccupancyDB/updateRecord.js";
|
||||
import { getWorkOrderMilestoneTypes } from "../../helpers/functions.cache.js";
|
||||
|
||||
export const handler: RequestHandler = async (request, response) => {
|
||||
const success = updateWorkOrderMilestoneType(request.body, request.session);
|
||||
const success = updateRecord(
|
||||
"WorkOrderMilestoneTypes",
|
||||
request.body.workOrderMilestoneTypeId,
|
||||
request.body.workOrderMilestoneType,
|
||||
request.session
|
||||
);
|
||||
|
||||
const workOrderMilestoneTypes = getWorkOrderMilestoneTypes();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { updateWorkOrderType } from "../../helpers/lotOccupancyDB/updateWorkOrderType.js";
|
||||
import { updateRecord } from "../../helpers/lotOccupancyDB/updateRecord.js";
|
||||
import { getWorkOrderTypes } from "../../helpers/functions.cache.js";
|
||||
export const handler = async (request, response) => {
|
||||
const success = updateWorkOrderType(request.body, request.session);
|
||||
const success = updateRecord("WorkOrderTypes", request.body.workOrderTypeId, request.body.workOrderType, request.session);
|
||||
const workOrderTypes = getWorkOrderTypes();
|
||||
response.json({
|
||||
success,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
import type { RequestHandler } from "express";
|
||||
|
||||
import { updateWorkOrderType } from "../../helpers/lotOccupancyDB/updateWorkOrderType.js";
|
||||
|
||||
import { updateRecord } from "../../helpers/lotOccupancyDB/updateRecord.js";
|
||||
import { getWorkOrderTypes } from "../../helpers/functions.cache.js";
|
||||
|
||||
export const handler: RequestHandler = async (request, response) => {
|
||||
const success = updateWorkOrderType(request.body, request.session);
|
||||
const success = updateRecord(
|
||||
"WorkOrderTypes",
|
||||
request.body.workOrderTypeId,
|
||||
request.body.workOrderType,
|
||||
request.session
|
||||
);
|
||||
|
||||
const workOrderTypes = getWorkOrderTypes();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
import type * as recordTypes from "../../types/recordTypes";
|
||||
interface UpdateLotStatusForm {
|
||||
lotStatusId: number | string;
|
||||
lotStatus: string;
|
||||
}
|
||||
export declare function updateLotStatus(lotStatusForm: UpdateLotStatusForm, requestSession: recordTypes.PartialSession): boolean;
|
||||
export default updateLotStatus;
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||
import { updateRecord } from "./updateRecord.js";
|
||||
export function updateLotStatus(lotStatusForm, requestSession) {
|
||||
const success = updateRecord("LotStatuses", lotStatusForm.lotStatusId, lotStatusForm.lotStatus, requestSession);
|
||||
clearLotStatusesCache();
|
||||
return success;
|
||||
}
|
||||
export default updateLotStatus;
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||
import { updateRecord } from "./updateRecord.js";
|
||||
|
||||
import type * as recordTypes from "../../types/recordTypes";
|
||||
|
||||
interface UpdateLotStatusForm {
|
||||
lotStatusId: number | string;
|
||||
lotStatus: string;
|
||||
}
|
||||
|
||||
export function updateLotStatus(
|
||||
lotStatusForm: UpdateLotStatusForm,
|
||||
requestSession: recordTypes.PartialSession
|
||||
): boolean {
|
||||
const success = updateRecord(
|
||||
"LotStatuses",
|
||||
lotStatusForm.lotStatusId,
|
||||
lotStatusForm.lotStatus,
|
||||
requestSession
|
||||
);
|
||||
|
||||
clearLotStatusesCache();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
export default updateLotStatus;
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import type * as recordTypes from "../../types/recordTypes";
|
||||
interface UpdateLotTypeForm {
|
||||
lotTypeId: number | string;
|
||||
lotType: string;
|
||||
}
|
||||
export declare function updateLotType(lotTypeForm: UpdateLotTypeForm, requestSession: recordTypes.PartialSession): boolean;
|
||||
export default updateLotType;
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import { clearLotTypesCache } from "../functions.cache.js";
|
||||
import { updateRecord } from "./updateRecord.js";
|
||||
export function updateLotType(lotTypeForm, requestSession) {
|
||||
const success = updateRecord("LotTypes", lotTypeForm.lotTypeId, lotTypeForm.lotType, requestSession);
|
||||
clearLotTypesCache();
|
||||
return success;
|
||||
}
|
||||
export default updateLotType;
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
import { clearLotTypesCache } from "../functions.cache.js";
|
||||
import { updateRecord } from "./updateRecord.js";
|
||||
|
||||
import type * as recordTypes from "../../types/recordTypes";
|
||||
|
||||
interface UpdateLotTypeForm {
|
||||
lotTypeId: number | string;
|
||||
lotType: string;
|
||||
}
|
||||
|
||||
export function updateLotType(
|
||||
lotTypeForm: UpdateLotTypeForm,
|
||||
requestSession: recordTypes.PartialSession
|
||||
): boolean {
|
||||
const success = updateRecord("LotTypes", lotTypeForm.lotTypeId, lotTypeForm.lotType, requestSession);
|
||||
|
||||
clearLotTypesCache();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
export default updateLotType;
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import type * as recordTypes from "../../types/recordTypes";
|
||||
interface UpdateOccupancyTypeForm {
|
||||
occupancyTypeId: number | string;
|
||||
occupancyType: string;
|
||||
}
|
||||
export declare function updateOccupancyType(occupancyTypeForm: UpdateOccupancyTypeForm, requestSession: recordTypes.PartialSession): boolean;
|
||||
export default updateOccupancyType;
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||
import { updateRecord } from "./updateRecord.js";
|
||||
export function updateOccupancyType(occupancyTypeForm, requestSession) {
|
||||
const success = updateRecord("OccupancyTypes", occupancyTypeForm.occupancyTypeId, occupancyTypeForm.occupancyType, requestSession);
|
||||
clearOccupancyTypesCache();
|
||||
return success;
|
||||
}
|
||||
export default updateOccupancyType;
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||
import { updateRecord } from "./updateRecord.js";
|
||||
|
||||
import type * as recordTypes from "../../types/recordTypes";
|
||||
|
||||
interface UpdateOccupancyTypeForm {
|
||||
occupancyTypeId: number | string;
|
||||
occupancyType: string;
|
||||
}
|
||||
|
||||
export function updateOccupancyType(
|
||||
occupancyTypeForm: UpdateOccupancyTypeForm,
|
||||
requestSession: recordTypes.PartialSession
|
||||
): boolean {
|
||||
const success = updateRecord(
|
||||
"OccupancyTypes",
|
||||
occupancyTypeForm.occupancyTypeId,
|
||||
occupancyTypeForm.occupancyType,
|
||||
requestSession
|
||||
);
|
||||
|
||||
clearOccupancyTypesCache();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
export default updateOccupancyType;
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import type * as recordTypes from "../../types/recordTypes";
|
||||
declare type RecordTable = "FeeCategories" | "LotStatuses" | "LotTypes" | "OccupancyTypes" | "WorkOrderMilestoneTypes" | "WorkOrderTypes";
|
||||
export declare const clearCacheFunctions: Map<RecordTable, () => void>;
|
||||
export declare function updateRecord(recordTable: RecordTable, recordId: number | string, recordName: string, requestSession: recordTypes.PartialSession): boolean;
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import sqlite from "better-sqlite3";
|
||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||
import * as cacheFunctions from "../functions.cache.js";
|
||||
const recordNameIdColumns = new Map();
|
||||
recordNameIdColumns.set("FeeCategories", ["feeCategory", "feeCategoryId"]);
|
||||
recordNameIdColumns.set("LotStatuses", ["lotStatus", "lotStatusId"]);
|
||||
|
|
@ -7,6 +8,12 @@ recordNameIdColumns.set("LotTypes", ["lotType", "lotTypeId"]);
|
|||
recordNameIdColumns.set("OccupancyTypes", ["occupancyType", "occupancyTypeId"]);
|
||||
recordNameIdColumns.set("WorkOrderMilestoneTypes", ["workOrderMilestoneType", "workOrderMilestoneTypeId"]);
|
||||
recordNameIdColumns.set("WorkOrderTypes", ["workOrderType", "workOrderTypeId"]);
|
||||
export const clearCacheFunctions = new Map();
|
||||
clearCacheFunctions.set("LotStatuses", cacheFunctions.clearLotStatusesCache);
|
||||
clearCacheFunctions.set("LotTypes", cacheFunctions.clearLotTypesCache);
|
||||
clearCacheFunctions.set("OccupancyTypes", cacheFunctions.clearOccupancyTypesCache);
|
||||
clearCacheFunctions.set("WorkOrderMilestoneTypes", cacheFunctions.clearWorkOrderMilestoneTypesCache);
|
||||
clearCacheFunctions.set("WorkOrderTypes", cacheFunctions.clearWorkOrderTypesCache);
|
||||
export function updateRecord(recordTable, recordId, recordName, requestSession) {
|
||||
const database = sqlite(databasePath);
|
||||
const rightNowMillis = Date.now();
|
||||
|
|
@ -19,5 +26,8 @@ export function updateRecord(recordTable, recordId, recordName, requestSession)
|
|||
and ${recordNameIdColumns.get(recordTable)[1]} = ?`)
|
||||
.run(recordName, requestSession.user.userName, rightNowMillis, recordId);
|
||||
database.close();
|
||||
if (clearCacheFunctions.has(recordTable)) {
|
||||
clearCacheFunctions.get(recordTable)();
|
||||
}
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import sqlite from "better-sqlite3";
|
|||
|
||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||
|
||||
import * as cacheFunctions from "../functions.cache.js";
|
||||
|
||||
import type * as recordTypes from "../../types/recordTypes";
|
||||
|
||||
type RecordTable =
|
||||
|
|
@ -20,6 +22,13 @@ recordNameIdColumns.set("OccupancyTypes", ["occupancyType", "occupancyTypeId"]);
|
|||
recordNameIdColumns.set("WorkOrderMilestoneTypes", ["workOrderMilestoneType", "workOrderMilestoneTypeId"]);
|
||||
recordNameIdColumns.set("WorkOrderTypes", ["workOrderType", "workOrderTypeId"]);
|
||||
|
||||
export const clearCacheFunctions: Map<RecordTable, () => void> = new Map();
|
||||
clearCacheFunctions.set("LotStatuses", cacheFunctions.clearLotStatusesCache);
|
||||
clearCacheFunctions.set("LotTypes", cacheFunctions.clearLotTypesCache);
|
||||
clearCacheFunctions.set("OccupancyTypes", cacheFunctions.clearOccupancyTypesCache);
|
||||
clearCacheFunctions.set("WorkOrderMilestoneTypes", cacheFunctions.clearWorkOrderMilestoneTypesCache);
|
||||
clearCacheFunctions.set("WorkOrderTypes", cacheFunctions.clearWorkOrderTypesCache);
|
||||
|
||||
export function updateRecord(
|
||||
recordTable: RecordTable,
|
||||
recordId: number | string,
|
||||
|
|
@ -43,5 +52,9 @@ export function updateRecord(
|
|||
|
||||
database.close();
|
||||
|
||||
if (clearCacheFunctions.has(recordTable)) {
|
||||
clearCacheFunctions.get(recordTable)();
|
||||
}
|
||||
|
||||
return result.changes > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
import type * as recordTypes from "../../types/recordTypes";
|
||||
interface UpdateWorkOrderMilestoneTypeForm {
|
||||
workOrderMilestoneTypeId: number | string;
|
||||
workOrderMilestoneType: string;
|
||||
}
|
||||
export declare function updateWorkOrderMilestoneType(workOrderMilestoneTypeForm: UpdateWorkOrderMilestoneTypeForm, requestSession: recordTypes.PartialSession): boolean;
|
||||
export default updateWorkOrderMilestoneType;
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import { clearWorkOrderMilestoneTypesCache } from "../functions.cache.js";
|
||||
import { updateRecord } from "./updateRecord.js";
|
||||
export function updateWorkOrderMilestoneType(workOrderMilestoneTypeForm, requestSession) {
|
||||
const success = updateRecord("WorkOrderMilestoneTypes", workOrderMilestoneTypeForm.workOrderMilestoneTypeId, workOrderMilestoneTypeForm.workOrderMilestoneType, requestSession);
|
||||
clearWorkOrderMilestoneTypesCache();
|
||||
return success;
|
||||
}
|
||||
export default updateWorkOrderMilestoneType;
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
import { clearWorkOrderMilestoneTypesCache } from "../functions.cache.js";
|
||||
import { updateRecord } from "./updateRecord.js";
|
||||
|
||||
import type * as recordTypes from "../../types/recordTypes";
|
||||
|
||||
interface UpdateWorkOrderMilestoneTypeForm {
|
||||
workOrderMilestoneTypeId: number | string;
|
||||
workOrderMilestoneType: string;
|
||||
}
|
||||
|
||||
export function updateWorkOrderMilestoneType(
|
||||
workOrderMilestoneTypeForm: UpdateWorkOrderMilestoneTypeForm,
|
||||
requestSession: recordTypes.PartialSession
|
||||
): boolean {
|
||||
const success = updateRecord(
|
||||
"WorkOrderMilestoneTypes",
|
||||
workOrderMilestoneTypeForm.workOrderMilestoneTypeId,
|
||||
workOrderMilestoneTypeForm.workOrderMilestoneType,
|
||||
requestSession
|
||||
);
|
||||
|
||||
clearWorkOrderMilestoneTypesCache();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
export default updateWorkOrderMilestoneType;
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import type * as recordTypes from "../../types/recordTypes";
|
||||
interface UpdateWorkOrderTypeForm {
|
||||
workOrderTypeId: number | string;
|
||||
workOrderType: string;
|
||||
}
|
||||
export declare function updateWorkOrderType(workOrderTypeForm: UpdateWorkOrderTypeForm, requestSession: recordTypes.PartialSession): boolean;
|
||||
export default updateWorkOrderType;
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import { clearWorkOrderTypesCache } from "../functions.cache.js";
|
||||
import { updateRecord } from "./updateRecord.js";
|
||||
export function updateWorkOrderType(workOrderTypeForm, requestSession) {
|
||||
const success = updateRecord("WorkOrderTypes", workOrderTypeForm.workOrderTypeId, workOrderTypeForm.workOrderType, requestSession);
|
||||
clearWorkOrderTypesCache();
|
||||
return success;
|
||||
}
|
||||
export default updateWorkOrderType;
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
import { clearWorkOrderTypesCache } from "../functions.cache.js";
|
||||
import { updateRecord } from "./updateRecord.js";
|
||||
|
||||
import type * as recordTypes from "../../types/recordTypes";
|
||||
|
||||
interface UpdateWorkOrderTypeForm {
|
||||
workOrderTypeId: number | string;
|
||||
workOrderType: string;
|
||||
}
|
||||
|
||||
export function updateWorkOrderType(
|
||||
workOrderTypeForm: UpdateWorkOrderTypeForm,
|
||||
requestSession: recordTypes.PartialSession
|
||||
): boolean {
|
||||
const success = updateRecord(
|
||||
"WorkOrderTypes",
|
||||
workOrderTypeForm.workOrderTypeId,
|
||||
workOrderTypeForm.workOrderType,
|
||||
requestSession
|
||||
);
|
||||
|
||||
clearWorkOrderTypesCache();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
export default updateWorkOrderType;
|
||||
Loading…
Reference in New Issue