reduce update record duplication
parent
941bd571a6
commit
e9b86a86e1
|
|
@ -1,18 +1,9 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
export function updateFeeCategory(feeCategoryForm, requestSession) {
|
export function updateFeeCategory(feeCategoryForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord("FeeCategories", feeCategoryForm.feeCategoryId, feeCategoryForm.feeCategory, requestSession);
|
||||||
const rightNowMillis = Date.now();
|
return success;
|
||||||
const result = database
|
|
||||||
.prepare(`update FeeCategories
|
|
||||||
set feeCategory = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and feeCategoryId = ?`)
|
|
||||||
.run(feeCategoryForm.feeCategory, requestSession.user.userName, rightNowMillis, feeCategoryForm.feeCategoryId);
|
|
||||||
database.close();
|
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
export function updateFeeCategoryOrderNumber(feeCategoryId, orderNumber, connectedDatabase) {
|
export function updateFeeCategoryOrderNumber(feeCategoryId, orderNumber, connectedDatabase) {
|
||||||
const database = connectedDatabase ||
|
const database = connectedDatabase ||
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
|
||||||
|
|
@ -13,29 +14,13 @@ export function updateFeeCategory(
|
||||||
feeCategoryForm: UpdateFeeCategoryForm,
|
feeCategoryForm: UpdateFeeCategoryForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord(
|
||||||
|
"FeeCategories",
|
||||||
const rightNowMillis = Date.now();
|
feeCategoryForm.feeCategoryId,
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(
|
|
||||||
`update FeeCategories
|
|
||||||
set feeCategory = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where recordDelete_timeMillis is null
|
|
||||||
and feeCategoryId = ?`
|
|
||||||
)
|
|
||||||
.run(
|
|
||||||
feeCategoryForm.feeCategory,
|
feeCategoryForm.feeCategory,
|
||||||
requestSession.user.userName,
|
requestSession
|
||||||
rightNowMillis,
|
|
||||||
feeCategoryForm.feeCategoryId
|
|
||||||
);
|
);
|
||||||
|
return success;
|
||||||
database.close();
|
|
||||||
|
|
||||||
return result.changes > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateFeeCategoryOrderNumber(
|
export function updateFeeCategoryOrderNumber(
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,8 @@
|
||||||
import sqlite from "better-sqlite3";
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
import { clearLotStatusesCache } from "../functions.cache.js";
|
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
export function updateLotStatus(lotStatusForm, requestSession) {
|
export function updateLotStatus(lotStatusForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord("LotStatuses", lotStatusForm.lotStatusId, lotStatusForm.lotStatus, requestSession);
|
||||||
const rightNowMillis = Date.now();
|
|
||||||
const result = database
|
|
||||||
.prepare(`update LotStatuses
|
|
||||||
set lotStatus = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where lotStatusId = ?
|
|
||||||
and recordDelete_timeMillis is null`)
|
|
||||||
.run(lotStatusForm.lotStatus, requestSession.user.userName, rightNowMillis, lotStatusForm.lotStatusId);
|
|
||||||
database.close();
|
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export default updateLotStatus;
|
export default updateLotStatus;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
import sqlite from "better-sqlite3";
|
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import { clearLotStatusesCache } from "../functions.cache.js";
|
import { clearLotStatusesCache } from "../functions.cache.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
|
||||||
|
|
@ -15,31 +12,16 @@ export function updateLotStatus(
|
||||||
lotStatusForm: UpdateLotStatusForm,
|
lotStatusForm: UpdateLotStatusForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord(
|
||||||
|
"LotStatuses",
|
||||||
const rightNowMillis = Date.now();
|
lotStatusForm.lotStatusId,
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(
|
|
||||||
`update LotStatuses
|
|
||||||
set lotStatus = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where lotStatusId = ?
|
|
||||||
and recordDelete_timeMillis is null`
|
|
||||||
)
|
|
||||||
.run(
|
|
||||||
lotStatusForm.lotStatus,
|
lotStatusForm.lotStatus,
|
||||||
requestSession.user.userName,
|
requestSession
|
||||||
rightNowMillis,
|
|
||||||
lotStatusForm.lotStatusId
|
|
||||||
);
|
);
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotStatusesCache();
|
clearLotStatusesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateLotStatus;
|
export default updateLotStatus;
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,8 @@
|
||||||
import sqlite from "better-sqlite3";
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
import { clearLotTypesCache } from "../functions.cache.js";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
export function updateLotType(lotTypeForm, requestSession) {
|
export function updateLotType(lotTypeForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord("LotTypes", lotTypeForm.lotTypeId, lotTypeForm.lotType, requestSession);
|
||||||
const rightNowMillis = Date.now();
|
|
||||||
const result = database
|
|
||||||
.prepare(`update LotTypes
|
|
||||||
set lotType = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where lotTypeId = ?
|
|
||||||
and recordDelete_timeMillis is null`)
|
|
||||||
.run(lotTypeForm.lotType, requestSession.user.userName, rightNowMillis, lotTypeForm.lotTypeId);
|
|
||||||
database.close();
|
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export default updateLotType;
|
export default updateLotType;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
import sqlite from "better-sqlite3";
|
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import { clearLotTypesCache } from "../functions.cache.js";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
|
||||||
|
|
@ -15,31 +12,11 @@ export function updateLotType(
|
||||||
lotTypeForm: UpdateLotTypeForm,
|
lotTypeForm: UpdateLotTypeForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord("LotTypes", lotTypeForm.lotTypeId, lotTypeForm.lotType, requestSession);
|
||||||
|
|
||||||
const rightNowMillis = Date.now();
|
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(
|
|
||||||
`update LotTypes
|
|
||||||
set lotType = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where lotTypeId = ?
|
|
||||||
and recordDelete_timeMillis is null`
|
|
||||||
)
|
|
||||||
.run(
|
|
||||||
lotTypeForm.lotType,
|
|
||||||
requestSession.user.userName,
|
|
||||||
rightNowMillis,
|
|
||||||
lotTypeForm.lotTypeId
|
|
||||||
);
|
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateLotType;
|
export default updateLotType;
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,8 @@
|
||||||
import sqlite from "better-sqlite3";
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
export function updateOccupancyType(occupancyTypeForm, requestSession) {
|
export function updateOccupancyType(occupancyTypeForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord("OccupancyTypes", occupancyTypeForm.occupancyTypeId, occupancyTypeForm.occupancyType, requestSession);
|
||||||
const rightNowMillis = Date.now();
|
|
||||||
const result = database
|
|
||||||
.prepare(`update OccupancyTypes
|
|
||||||
set occupancyType = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where occupancyTypeId = ?
|
|
||||||
and recordDelete_timeMillis is null`)
|
|
||||||
.run(occupancyTypeForm.occupancyType, requestSession.user.userName, rightNowMillis, occupancyTypeForm.occupancyTypeId);
|
|
||||||
database.close();
|
|
||||||
clearOccupancyTypesCache();
|
clearOccupancyTypesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export default updateOccupancyType;
|
export default updateOccupancyType;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
import sqlite from "better-sqlite3";
|
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
|
||||||
|
|
@ -15,31 +12,16 @@ export function updateOccupancyType(
|
||||||
occupancyTypeForm: UpdateOccupancyTypeForm,
|
occupancyTypeForm: UpdateOccupancyTypeForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord(
|
||||||
|
"OccupancyTypes",
|
||||||
const rightNowMillis = Date.now();
|
occupancyTypeForm.occupancyTypeId,
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(
|
|
||||||
`update OccupancyTypes
|
|
||||||
set occupancyType = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where occupancyTypeId = ?
|
|
||||||
and recordDelete_timeMillis is null`
|
|
||||||
)
|
|
||||||
.run(
|
|
||||||
occupancyTypeForm.occupancyType,
|
occupancyTypeForm.occupancyType,
|
||||||
requestSession.user.userName,
|
requestSession
|
||||||
rightNowMillis,
|
|
||||||
occupancyTypeForm.occupancyTypeId
|
|
||||||
);
|
);
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearOccupancyTypesCache();
|
clearOccupancyTypesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateOccupancyType;
|
export default updateOccupancyType;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
declare type RecordTable = "FeeCategories" | "LotStatuses" | "LotTypes" | "OccupancyTypes" | "WorkOrderMilestoneTypes" | "WorkOrderTypes";
|
||||||
|
export declare function updateRecord(recordTable: RecordTable, recordId: number | string, recordName: string, requestSession: recordTypes.PartialSession): boolean;
|
||||||
|
export {};
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
import sqlite from "better-sqlite3";
|
||||||
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
const recordNameIdColumns = new Map();
|
||||||
|
recordNameIdColumns.set("FeeCategories", ["feeCategory", "feeCategoryId"]);
|
||||||
|
recordNameIdColumns.set("LotStatuses", ["lotStatus", "lotStatusId"]);
|
||||||
|
recordNameIdColumns.set("LotTypes", ["lotType", "lotTypeId"]);
|
||||||
|
recordNameIdColumns.set("OccupancyTypes", ["occupancyType", "occupancyTypeId"]);
|
||||||
|
recordNameIdColumns.set("WorkOrderMilestoneTypes", ["workOrderMilestoneType", "workOrderMilestoneTypeId"]);
|
||||||
|
recordNameIdColumns.set("WorkOrderTypes", ["workOrderType", "workOrderTypeId"]);
|
||||||
|
export function updateRecord(recordTable, recordId, recordName, requestSession) {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
const rightNowMillis = Date.now();
|
||||||
|
const result = database
|
||||||
|
.prepare(`update ${recordTable}
|
||||||
|
set ${recordNameIdColumns.get(recordTable)[0]} = ?,
|
||||||
|
recordUpdate_userName = ?,
|
||||||
|
recordUpdate_timeMillis = ?
|
||||||
|
where recordDelete_timeMillis is null
|
||||||
|
and ${recordNameIdColumns.get(recordTable)[1]} = ?`)
|
||||||
|
.run(recordName, requestSession.user.userName, rightNowMillis, recordId);
|
||||||
|
database.close();
|
||||||
|
return result.changes > 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
import sqlite from "better-sqlite3";
|
||||||
|
|
||||||
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
|
||||||
|
type RecordTable =
|
||||||
|
| "FeeCategories"
|
||||||
|
| "LotStatuses"
|
||||||
|
| "LotTypes"
|
||||||
|
| "OccupancyTypes"
|
||||||
|
| "WorkOrderMilestoneTypes"
|
||||||
|
| "WorkOrderTypes";
|
||||||
|
|
||||||
|
const recordNameIdColumns: Map<RecordTable, string[]> = new Map();
|
||||||
|
recordNameIdColumns.set("FeeCategories", ["feeCategory", "feeCategoryId"]);
|
||||||
|
recordNameIdColumns.set("LotStatuses", ["lotStatus", "lotStatusId"]);
|
||||||
|
recordNameIdColumns.set("LotTypes", ["lotType", "lotTypeId"]);
|
||||||
|
recordNameIdColumns.set("OccupancyTypes", ["occupancyType", "occupancyTypeId"]);
|
||||||
|
recordNameIdColumns.set("WorkOrderMilestoneTypes", ["workOrderMilestoneType", "workOrderMilestoneTypeId"]);
|
||||||
|
recordNameIdColumns.set("WorkOrderTypes", ["workOrderType", "workOrderTypeId"]);
|
||||||
|
|
||||||
|
export function updateRecord(
|
||||||
|
recordTable: RecordTable,
|
||||||
|
recordId: number | string,
|
||||||
|
recordName: string,
|
||||||
|
requestSession: recordTypes.PartialSession
|
||||||
|
): boolean {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
|
const rightNowMillis = Date.now();
|
||||||
|
|
||||||
|
const result = database
|
||||||
|
.prepare(
|
||||||
|
`update ${recordTable}
|
||||||
|
set ${recordNameIdColumns.get(recordTable)[0]} = ?,
|
||||||
|
recordUpdate_userName = ?,
|
||||||
|
recordUpdate_timeMillis = ?
|
||||||
|
where recordDelete_timeMillis is null
|
||||||
|
and ${recordNameIdColumns.get(recordTable)[1]} = ?`
|
||||||
|
)
|
||||||
|
.run(recordName, requestSession.user.userName, rightNowMillis, recordId);
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
return result.changes > 0;
|
||||||
|
}
|
||||||
|
|
@ -1,19 +1,8 @@
|
||||||
import sqlite from "better-sqlite3";
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
import { clearWorkOrderMilestoneTypesCache } from "../functions.cache.js";
|
import { clearWorkOrderMilestoneTypesCache } from "../functions.cache.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
export function updateWorkOrderMilestoneType(workOrderMilestoneTypeForm, requestSession) {
|
export function updateWorkOrderMilestoneType(workOrderMilestoneTypeForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord("WorkOrderMilestoneTypes", workOrderMilestoneTypeForm.workOrderMilestoneTypeId, workOrderMilestoneTypeForm.workOrderMilestoneType, requestSession);
|
||||||
const rightNowMillis = Date.now();
|
|
||||||
const result = database
|
|
||||||
.prepare(`update WorkOrderMilestoneTypes
|
|
||||||
set workOrderMilestoneType = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where workOrderMilestoneTypeId = ?
|
|
||||||
and recordDelete_timeMillis is null`)
|
|
||||||
.run(workOrderMilestoneTypeForm.workOrderMilestoneType, requestSession.user.userName, rightNowMillis, workOrderMilestoneTypeForm.workOrderMilestoneTypeId);
|
|
||||||
database.close();
|
|
||||||
clearWorkOrderMilestoneTypesCache();
|
clearWorkOrderMilestoneTypesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export default updateWorkOrderMilestoneType;
|
export default updateWorkOrderMilestoneType;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
import sqlite from "better-sqlite3";
|
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import { clearWorkOrderMilestoneTypesCache } from "../functions.cache.js";
|
import { clearWorkOrderMilestoneTypesCache } from "../functions.cache.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
|
||||||
|
|
@ -15,31 +12,16 @@ export function updateWorkOrderMilestoneType(
|
||||||
workOrderMilestoneTypeForm: UpdateWorkOrderMilestoneTypeForm,
|
workOrderMilestoneTypeForm: UpdateWorkOrderMilestoneTypeForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord(
|
||||||
|
"WorkOrderMilestoneTypes",
|
||||||
const rightNowMillis = Date.now();
|
workOrderMilestoneTypeForm.workOrderMilestoneTypeId,
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(
|
|
||||||
`update WorkOrderMilestoneTypes
|
|
||||||
set workOrderMilestoneType = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where workOrderMilestoneTypeId = ?
|
|
||||||
and recordDelete_timeMillis is null`
|
|
||||||
)
|
|
||||||
.run(
|
|
||||||
workOrderMilestoneTypeForm.workOrderMilestoneType,
|
workOrderMilestoneTypeForm.workOrderMilestoneType,
|
||||||
requestSession.user.userName,
|
requestSession
|
||||||
rightNowMillis,
|
|
||||||
workOrderMilestoneTypeForm.workOrderMilestoneTypeId
|
|
||||||
);
|
);
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearWorkOrderMilestoneTypesCache();
|
clearWorkOrderMilestoneTypesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateWorkOrderMilestoneType;
|
export default updateWorkOrderMilestoneType;
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,8 @@
|
||||||
import sqlite from "better-sqlite3";
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
import { clearWorkOrderTypesCache } from "../functions.cache.js";
|
import { clearWorkOrderTypesCache } from "../functions.cache.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
export function updateWorkOrderType(workOrderTypeForm, requestSession) {
|
export function updateWorkOrderType(workOrderTypeForm, requestSession) {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord("WorkOrderTypes", workOrderTypeForm.workOrderTypeId, workOrderTypeForm.workOrderType, requestSession);
|
||||||
const rightNowMillis = Date.now();
|
|
||||||
const result = database
|
|
||||||
.prepare(`update WorkOrderTypes
|
|
||||||
set workOrderType = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where workOrderTypeId = ?
|
|
||||||
and recordDelete_timeMillis is null`)
|
|
||||||
.run(workOrderTypeForm.workOrderType, requestSession.user.userName, rightNowMillis, workOrderTypeForm.workOrderTypeId);
|
|
||||||
database.close();
|
|
||||||
clearWorkOrderTypesCache();
|
clearWorkOrderTypesCache();
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
export default updateWorkOrderType;
|
export default updateWorkOrderType;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
import sqlite from "better-sqlite3";
|
|
||||||
|
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
|
||||||
|
|
||||||
import { clearWorkOrderTypesCache } from "../functions.cache.js";
|
import { clearWorkOrderTypesCache } from "../functions.cache.js";
|
||||||
|
import { updateRecord } from "./updateRecord.js";
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
|
||||||
|
|
@ -15,31 +12,16 @@ export function updateWorkOrderType(
|
||||||
workOrderTypeForm: UpdateWorkOrderTypeForm,
|
workOrderTypeForm: UpdateWorkOrderTypeForm,
|
||||||
requestSession: recordTypes.PartialSession
|
requestSession: recordTypes.PartialSession
|
||||||
): boolean {
|
): boolean {
|
||||||
const database = sqlite(databasePath);
|
const success = updateRecord(
|
||||||
|
"WorkOrderTypes",
|
||||||
const rightNowMillis = Date.now();
|
workOrderTypeForm.workOrderTypeId,
|
||||||
|
|
||||||
const result = database
|
|
||||||
.prepare(
|
|
||||||
`update WorkOrderTypes
|
|
||||||
set workOrderType = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where workOrderTypeId = ?
|
|
||||||
and recordDelete_timeMillis is null`
|
|
||||||
)
|
|
||||||
.run(
|
|
||||||
workOrderTypeForm.workOrderType,
|
workOrderTypeForm.workOrderType,
|
||||||
requestSession.user.userName,
|
requestSession
|
||||||
rightNowMillis,
|
|
||||||
workOrderTypeForm.workOrderTypeId
|
|
||||||
);
|
);
|
||||||
|
|
||||||
database.close();
|
|
||||||
|
|
||||||
clearWorkOrderTypesCache();
|
clearWorkOrderTypesCache();
|
||||||
|
|
||||||
return result.changes > 0;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default updateWorkOrderType;
|
export default updateWorkOrderType;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue