From 54e2d6c18878ea3697e423ea3352fd1fd975a623 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Mon, 2 Dec 2024 14:35:51 -0500 Subject: [PATCH] update pending records in admin --- .../database/getScannerRecords.js | 2 +- .../database/getScannerRecords.ts | 2 +- .../database/updateScannerRecord.d.ts | 12 +- .../database/updateScannerRecord.js | 10 +- .../database/updateScannerRecord.ts | 32 +- .../database/updateScannerRecordField.d.ts | 3 + .../database/updateScannerRecordField.js | 16 + .../database/updateScannerRecordField.ts | 30 ++ .../post-admin/doGetRepairRecords.d.ts | 6 + .../handlers/post-admin/doGetRepairRecords.js | 7 + .../handlers/post-admin/doGetRepairRecords.ts | 24 ++ .../post-admin/doUpdatePendingRecord.d.ts | 3 + .../post-admin/doUpdatePendingRecord.js | 7 + .../post-admin/doUpdatePendingRecord.ts | 21 ++ modules/inventoryScanner/handlers/router.js | 4 + modules/inventoryScanner/handlers/router.ts | 6 + .../updateRecordsFromValidation.js | 8 +- .../updateRecordsFromValidation.ts | 8 +- modules/inventoryScanner/types.js | 3 +- .../html/scannerRecordEdit.html | 130 +++++++- .../javascripts/adminInventory.js | 2 + .../javascripts/adminInventory.ts | 3 + .../javascripts/adminPending.js | 171 ++++++++++- .../javascripts/adminPending.ts | 282 +++++++++++++++++- .../inventoryScanner/javascripts/scanner.js | 2 + .../inventoryScanner/javascripts/scanner.ts | 3 + views/inventoryScanner/admin.ejs | 10 +- 27 files changed, 739 insertions(+), 68 deletions(-) create mode 100644 modules/inventoryScanner/database/updateScannerRecordField.d.ts create mode 100644 modules/inventoryScanner/database/updateScannerRecordField.js create mode 100644 modules/inventoryScanner/database/updateScannerRecordField.ts create mode 100644 modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.d.ts create mode 100644 modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.js create mode 100644 modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.ts create mode 100644 modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.d.ts create mode 100644 modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.js create mode 100644 modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.ts diff --git a/modules/inventoryScanner/database/getScannerRecords.js b/modules/inventoryScanner/database/getScannerRecords.js index 0e5518d..98e452f 100644 --- a/modules/inventoryScanner/database/getScannerRecords.js +++ b/modules/inventoryScanner/database/getScannerRecords.js @@ -64,7 +64,7 @@ export default function getScannerRecords(filters, userOptions = {}) { ${sqlWhereClause} order by s.scanDate desc, s.scanTime desc, s.recordId desc`; if (options.limit !== -1) { - sql += `limit ${options.limit.toString()}`; + sql += ` limit ${options.limit.toString()}`; } /* * Do Query diff --git a/modules/inventoryScanner/database/getScannerRecords.ts b/modules/inventoryScanner/database/getScannerRecords.ts index 4f2807e..d0ec32f 100644 --- a/modules/inventoryScanner/database/getScannerRecords.ts +++ b/modules/inventoryScanner/database/getScannerRecords.ts @@ -93,7 +93,7 @@ export default function getScannerRecords( order by s.scanDate desc, s.scanTime desc, s.recordId desc` if (options.limit !== -1) { - sql += `limit ${options.limit.toString()}` + sql += ` limit ${options.limit.toString()}` } /* diff --git a/modules/inventoryScanner/database/updateScannerRecord.d.ts b/modules/inventoryScanner/database/updateScannerRecord.d.ts index e5af198..8532e87 100644 --- a/modules/inventoryScanner/database/updateScannerRecord.d.ts +++ b/modules/inventoryScanner/database/updateScannerRecord.d.ts @@ -1,3 +1,9 @@ -type ScannerRecordUpdateField = 'repairId' | 'itemStoreroom' | 'unitPrice'; -export declare function updateScannerRecord(recordId: number, fieldToUpdate: ScannerRecordUpdateField, fieldValue: string | number, updateUserName: string): boolean; -export {}; +export interface UpdateScannerRecordForm { + recordId: string; + workOrderNumber: string; + repairId: string; + itemNumber: string; + quantity: string; + unitPrice: string; +} +export declare function updateScannerRecord(recordForm: UpdateScannerRecordForm, updateUser: FasterWebHelperSessionUser): boolean; diff --git a/modules/inventoryScanner/database/updateScannerRecord.js b/modules/inventoryScanner/database/updateScannerRecord.js index c73a3a9..e303ac6 100644 --- a/modules/inventoryScanner/database/updateScannerRecord.js +++ b/modules/inventoryScanner/database/updateScannerRecord.js @@ -1,16 +1,20 @@ import sqlite from 'better-sqlite3'; import { databasePath } from './helpers.database.js'; -export function updateScannerRecord(recordId, fieldToUpdate, fieldValue, updateUserName) { +export function updateScannerRecord(recordForm, updateUser) { const database = sqlite(databasePath); const result = database .prepare(`update InventoryScannerRecords - set ${fieldToUpdate} = ?, + set workOrderNumber = ?, + repairId = ?, + itemNumber = ?, + quantity = ?, + unitPrice = ?, recordUpdate_userName = ?, recordUpdate_timeMillis = ? where recordId = ? and recordDelete_timeMillis is null and recordSync_timeMillis is null`) - .run(fieldValue, updateUserName, Date.now(), recordId); + .run(recordForm.workOrderNumber, recordForm.repairId === '' ? undefined : recordForm.repairId, recordForm.itemNumber, recordForm.quantity, recordForm.unitPrice === '' ? undefined : recordForm.unitPrice, updateUser.userName, Date.now(), recordForm.recordId); database.close(); return result.changes > 0; } diff --git a/modules/inventoryScanner/database/updateScannerRecord.ts b/modules/inventoryScanner/database/updateScannerRecord.ts index fc92840..368ee0c 100644 --- a/modules/inventoryScanner/database/updateScannerRecord.ts +++ b/modules/inventoryScanner/database/updateScannerRecord.ts @@ -2,27 +2,45 @@ import sqlite from 'better-sqlite3' import { databasePath } from './helpers.database.js' -type ScannerRecordUpdateField = 'repairId' | 'itemStoreroom' | 'unitPrice' +export interface UpdateScannerRecordForm { + recordId: string + workOrderNumber: string + repairId: string + itemNumber: string + quantity: string + unitPrice: string +} export function updateScannerRecord( - recordId: number, - fieldToUpdate: ScannerRecordUpdateField, - fieldValue: string | number, - updateUserName: string + recordForm: UpdateScannerRecordForm, + updateUser: FasterWebHelperSessionUser ): boolean { const database = sqlite(databasePath) const result = database .prepare( `update InventoryScannerRecords - set ${fieldToUpdate} = ?, + set workOrderNumber = ?, + repairId = ?, + itemNumber = ?, + quantity = ?, + unitPrice = ?, recordUpdate_userName = ?, recordUpdate_timeMillis = ? where recordId = ? and recordDelete_timeMillis is null and recordSync_timeMillis is null` ) - .run(fieldValue, updateUserName, Date.now(), recordId) + .run( + recordForm.workOrderNumber, + recordForm.repairId === '' ? undefined : recordForm.repairId, + recordForm.itemNumber, + recordForm.quantity, + recordForm.unitPrice === '' ? undefined : recordForm.unitPrice, + updateUser.userName, + Date.now(), + recordForm.recordId + ) database.close() diff --git a/modules/inventoryScanner/database/updateScannerRecordField.d.ts b/modules/inventoryScanner/database/updateScannerRecordField.d.ts new file mode 100644 index 0000000..52d4ccf --- /dev/null +++ b/modules/inventoryScanner/database/updateScannerRecordField.d.ts @@ -0,0 +1,3 @@ +type ScannerRecordUpdateField = 'repairId' | 'itemStoreroom' | 'unitPrice'; +export declare function updateScannerRecordField(recordId: number, fieldToUpdate: ScannerRecordUpdateField, fieldValue: string | number, updateUserName: string): boolean; +export {}; diff --git a/modules/inventoryScanner/database/updateScannerRecordField.js b/modules/inventoryScanner/database/updateScannerRecordField.js new file mode 100644 index 0000000..3a44f5e --- /dev/null +++ b/modules/inventoryScanner/database/updateScannerRecordField.js @@ -0,0 +1,16 @@ +import sqlite from 'better-sqlite3'; +import { databasePath } from './helpers.database.js'; +export function updateScannerRecordField(recordId, fieldToUpdate, fieldValue, updateUserName) { + const database = sqlite(databasePath); + const result = database + .prepare(`update InventoryScannerRecords + set ${fieldToUpdate} = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where recordId = ? + and recordDelete_timeMillis is null + and recordSync_timeMillis is null`) + .run(fieldValue, updateUserName, Date.now(), recordId); + database.close(); + return result.changes > 0; +} diff --git a/modules/inventoryScanner/database/updateScannerRecordField.ts b/modules/inventoryScanner/database/updateScannerRecordField.ts new file mode 100644 index 0000000..07b0c3c --- /dev/null +++ b/modules/inventoryScanner/database/updateScannerRecordField.ts @@ -0,0 +1,30 @@ +import sqlite from 'better-sqlite3' + +import { databasePath } from './helpers.database.js' + +type ScannerRecordUpdateField = 'repairId' | 'itemStoreroom' | 'unitPrice' + +export function updateScannerRecordField( + recordId: number, + fieldToUpdate: ScannerRecordUpdateField, + fieldValue: string | number, + updateUserName: string +): boolean { + const database = sqlite(databasePath) + + const result = database + .prepare( + `update InventoryScannerRecords + set ${fieldToUpdate} = ?, + recordUpdate_userName = ?, + recordUpdate_timeMillis = ? + where recordId = ? + and recordDelete_timeMillis is null + and recordSync_timeMillis is null` + ) + .run(fieldValue, updateUserName, Date.now(), recordId) + + database.close() + + return result.changes > 0 +} diff --git a/modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.d.ts b/modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.d.ts new file mode 100644 index 0000000..64ca1e6 --- /dev/null +++ b/modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.d.ts @@ -0,0 +1,6 @@ +import type { Request, Response } from 'express'; +interface DoGetRepairIdsForm { + workOrderNumber: string; +} +export default function handler(request: Request, response: Response): void; +export {}; diff --git a/modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.js b/modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.js new file mode 100644 index 0000000..e4261a7 --- /dev/null +++ b/modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.js @@ -0,0 +1,7 @@ +import getWorkOrderValidationRecords from '../../database/getWorkOrderValidationRecords.js'; +import { getWorkOrderTypeFromWorkOrderNumber } from '../../helpers/workOrders.js'; +export default function handler(request, response) { + const workOrderType = getWorkOrderTypeFromWorkOrderNumber(request.body.workOrderNumber); + const records = getWorkOrderValidationRecords(request.body.workOrderNumber, workOrderType); + response.json({ records }); +} diff --git a/modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.ts b/modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.ts new file mode 100644 index 0000000..ffdf066 --- /dev/null +++ b/modules/inventoryScanner/handlers/post-admin/doGetRepairRecords.ts @@ -0,0 +1,24 @@ +import type { Request, Response } from 'express' + +import getWorkOrderValidationRecords from '../../database/getWorkOrderValidationRecords.js' +import { getWorkOrderTypeFromWorkOrderNumber } from '../../helpers/workOrders.js' + +interface DoGetRepairIdsForm { + workOrderNumber: string +} + +export default function handler( + request: Request, + response: Response +): void { + const workOrderType = getWorkOrderTypeFromWorkOrderNumber( + request.body.workOrderNumber + ) + + const records = getWorkOrderValidationRecords( + request.body.workOrderNumber, + workOrderType + ) + + response.json({ records }) +} diff --git a/modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.d.ts b/modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.d.ts new file mode 100644 index 0000000..5f65e4e --- /dev/null +++ b/modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.d.ts @@ -0,0 +1,3 @@ +import type { Request, Response } from 'express'; +import { type UpdateScannerRecordForm } from '../../database/updateScannerRecord.js'; +export default function handler(request: Request, response: Response): void; diff --git a/modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.js b/modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.js new file mode 100644 index 0000000..ebad632 --- /dev/null +++ b/modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.js @@ -0,0 +1,7 @@ +import getScannerRecords from '../../database/getScannerRecords.js'; +import { updateScannerRecord } from '../../database/updateScannerRecord.js'; +export default function handler(request, response) { + const success = updateScannerRecord(request.body, request.session.user); + const pendingRecords = getScannerRecords({ isSynced: false }, { limit: -1 }); + response.json({ success, pendingRecords }); +} diff --git a/modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.ts b/modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.ts new file mode 100644 index 0000000..156fe89 --- /dev/null +++ b/modules/inventoryScanner/handlers/post-admin/doUpdatePendingRecord.ts @@ -0,0 +1,21 @@ +import type { Request, Response } from 'express' + +import getScannerRecords from '../../database/getScannerRecords.js' +import { + type UpdateScannerRecordForm, + updateScannerRecord +} from '../../database/updateScannerRecord.js' + +export default function handler( + request: Request, + response: Response +): void { + const success = updateScannerRecord( + request.body, + request.session.user as FasterWebHelperSessionUser + ) + + const pendingRecords = getScannerRecords({ isSynced: false }, { limit: -1 }) + + response.json({ success, pendingRecords }) +} diff --git a/modules/inventoryScanner/handlers/router.js b/modules/inventoryScanner/handlers/router.js index 141697e..ec24e9b 100644 --- a/modules/inventoryScanner/handlers/router.js +++ b/modules/inventoryScanner/handlers/router.js @@ -2,8 +2,12 @@ import { Router } from 'express'; import handler_inventoryScanner from './get-admin/inventoryScanner.js'; import handler_doGetInventory from './post-admin/doGetInventory.js'; import handler_doGetPendingRecords from './post-admin/doGetPendingRecords.js'; +import handler_doGetRepairRecords from './post-admin/doGetRepairRecords.js'; +import handler_doUpdatePendingRecord from './post-admin/doUpdatePendingRecord.js'; export const router = Router(); router.get('/', handler_inventoryScanner); router.post('/doGetPendingRecords', handler_doGetPendingRecords); +router.post('/doGetRepairRecords', handler_doGetRepairRecords); +router.post('/doUpdatePendingRecord', handler_doUpdatePendingRecord); router.post('/doGetInventory', handler_doGetInventory); export default router; diff --git a/modules/inventoryScanner/handlers/router.ts b/modules/inventoryScanner/handlers/router.ts index 384a96c..c6fa5bd 100644 --- a/modules/inventoryScanner/handlers/router.ts +++ b/modules/inventoryScanner/handlers/router.ts @@ -3,6 +3,8 @@ import { Router } from 'express' import handler_inventoryScanner from './get-admin/inventoryScanner.js' import handler_doGetInventory from './post-admin/doGetInventory.js' import handler_doGetPendingRecords from './post-admin/doGetPendingRecords.js' +import handler_doGetRepairRecords from './post-admin/doGetRepairRecords.js' +import handler_doUpdatePendingRecord from './post-admin/doUpdatePendingRecord.js' export const router = Router() @@ -10,6 +12,10 @@ router.get('/', handler_inventoryScanner) router.post('/doGetPendingRecords', handler_doGetPendingRecords) +router.post('/doGetRepairRecords', handler_doGetRepairRecords) + +router.post('/doUpdatePendingRecord', handler_doUpdatePendingRecord) + router.post('/doGetInventory', handler_doGetInventory) export default router diff --git a/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.js b/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.js index 8792a49..a70d8ce 100644 --- a/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.js +++ b/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.js @@ -6,7 +6,7 @@ import schedule from 'node-schedule'; import { getItemValidationRecordsByItemNumber } from '../../database/getItemValidationRecords.js'; import getScannerRecords from '../../database/getScannerRecords.js'; import getWorkOrderValidationRecords from '../../database/getWorkOrderValidationRecords.js'; -import { updateScannerRecord } from '../../database/updateScannerRecord.js'; +import { updateScannerRecordField } from '../../database/updateScannerRecordField.js'; import { moduleName } from '../../helpers/module.js'; const minimumMillisBetweenRuns = minutesToMillis(2); const lastRunMillis = 0; @@ -30,7 +30,7 @@ function updateRecordsFromValidationTask() { if (workOrderValidationRecords.length > 0 && record.repairId === null) { for (const workOrderValidationRecord of workOrderValidationRecords) { if (workOrderValidationRecord.repairId !== null) { - updateScannerRecord(record.recordId, 'repairId', workOrderValidationRecord.repairId, taskUserName); + updateScannerRecordField(record.recordId, 'repairId', workOrderValidationRecord.repairId, taskUserName); break; } } @@ -40,10 +40,10 @@ function updateRecordsFromValidationTask() { : []; if (itemValidationRecords.length > 0) { if (record.itemStoreroom === null) { - updateScannerRecord(record.recordId, 'itemStoreroom', itemValidationRecords[0].itemStoreroom, taskUserName); + updateScannerRecordField(record.recordId, 'itemStoreroom', itemValidationRecords[0].itemStoreroom, taskUserName); } if (record.unitPrice === null) { - updateScannerRecord(record.recordId, 'unitPrice', itemValidationRecords[0].unitPrice, taskUserName); + updateScannerRecordField(record.recordId, 'unitPrice', itemValidationRecords[0].unitPrice, taskUserName); } } } diff --git a/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.ts b/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.ts index 71838e4..16647f6 100644 --- a/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.ts +++ b/modules/inventoryScanner/tasks/inventoryScanner/updateRecordsFromValidation.ts @@ -7,7 +7,7 @@ import schedule from 'node-schedule' import { getItemValidationRecordsByItemNumber } from '../../database/getItemValidationRecords.js' import getScannerRecords from '../../database/getScannerRecords.js' import getWorkOrderValidationRecords from '../../database/getWorkOrderValidationRecords.js' -import { updateScannerRecord } from '../../database/updateScannerRecord.js' +import { updateScannerRecordField } from '../../database/updateScannerRecordField.js' import { moduleName } from '../../helpers/module.js' const minimumMillisBetweenRuns = minutesToMillis(2) @@ -45,7 +45,7 @@ function updateRecordsFromValidationTask(): void { if (workOrderValidationRecords.length > 0 && record.repairId === null) { for (const workOrderValidationRecord of workOrderValidationRecords) { if (workOrderValidationRecord.repairId !== null) { - updateScannerRecord( + updateScannerRecordField( record.recordId, 'repairId', workOrderValidationRecord.repairId, @@ -63,7 +63,7 @@ function updateRecordsFromValidationTask(): void { if (itemValidationRecords.length > 0) { if (record.itemStoreroom === null) { - updateScannerRecord( + updateScannerRecordField( record.recordId, 'itemStoreroom', itemValidationRecords[0].itemStoreroom, @@ -72,7 +72,7 @@ function updateRecordsFromValidationTask(): void { } if (record.unitPrice === null) { - updateScannerRecord( + updateScannerRecordField( record.recordId, 'unitPrice', itemValidationRecords[0].unitPrice, diff --git a/modules/inventoryScanner/types.js b/modules/inventoryScanner/types.js index cb0ff5c..c8ad2e5 100644 --- a/modules/inventoryScanner/types.js +++ b/modules/inventoryScanner/types.js @@ -1 +1,2 @@ -export {}; +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/public/inventoryScanner/html/scannerRecordEdit.html b/public/inventoryScanner/html/scannerRecordEdit.html index 5619e61..7739c0d 100644 --- a/public/inventoryScanner/html/scannerRecordEdit.html +++ b/public/inventoryScanner/html/scannerRecordEdit.html @@ -16,25 +16,127 @@