@7365admin1/core 2.48.0 → 2.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +13 -6
- package/dist/index.js +307 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +306 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -452,6 +452,7 @@ __export(src_exports, {
|
|
|
452
452
|
vehicles_namespace_collection: () => vehicles_namespace_collection,
|
|
453
453
|
visitors_namespace_collection: () => visitors_namespace_collection,
|
|
454
454
|
workOrderSchema: () => workOrderSchema,
|
|
455
|
+
work_orders2_namespace_collection: () => work_orders2_namespace_collection,
|
|
455
456
|
work_orders_namespace_collection: () => work_orders_namespace_collection
|
|
456
457
|
});
|
|
457
458
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -1363,12 +1364,16 @@ function MWorkOrder(value) {
|
|
|
1363
1364
|
// src/repositories/work-order.repo.ts
|
|
1364
1365
|
var import_node_server_utils7 = require("@7365admin1/node-server-utils");
|
|
1365
1366
|
var work_orders_namespace_collection = "work-orders";
|
|
1367
|
+
var work_orders2_namespace_collection = "work-orders2";
|
|
1366
1368
|
function useWorkOrderRepo() {
|
|
1367
1369
|
const db = import_node_server_utils7.useAtlas.getDb();
|
|
1368
1370
|
if (!db) {
|
|
1369
1371
|
throw new import_node_server_utils7.InternalServerError("Unable to connect to server.");
|
|
1370
1372
|
}
|
|
1371
1373
|
const collection = db.collection(work_orders_namespace_collection);
|
|
1374
|
+
const workOrders2Collection = db.collection(
|
|
1375
|
+
work_orders2_namespace_collection
|
|
1376
|
+
);
|
|
1372
1377
|
async function createIndex() {
|
|
1373
1378
|
try {
|
|
1374
1379
|
await collection.createIndexes([
|
|
@@ -1400,6 +1405,12 @@ function useWorkOrderRepo() {
|
|
|
1400
1405
|
const { delNamespace, setCache, getCache, delCache } = (0, import_node_server_utils7.useCache)(
|
|
1401
1406
|
work_orders_namespace_collection
|
|
1402
1407
|
);
|
|
1408
|
+
const {
|
|
1409
|
+
delNamespace: delNamespaceWorkOrders2,
|
|
1410
|
+
setCache: setCacheWorkOrders2,
|
|
1411
|
+
getCache: getCacheWorkOrders2,
|
|
1412
|
+
delCache: delCacheWorkOrders2
|
|
1413
|
+
} = (0, import_node_server_utils7.useCache)(work_orders2_namespace_collection);
|
|
1403
1414
|
const { delNamespace: _delDashboardNameSpace } = (0, import_node_server_utils7.useCache)("dashboard");
|
|
1404
1415
|
async function createWorkOrder(value, session) {
|
|
1405
1416
|
try {
|
|
@@ -1801,7 +1812,7 @@ function useWorkOrderRepo() {
|
|
|
1801
1812
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
1802
1813
|
deletedAt: /* @__PURE__ */ new Date()
|
|
1803
1814
|
};
|
|
1804
|
-
const res = await
|
|
1815
|
+
const res = await workOrders2Collection.updateOne(
|
|
1805
1816
|
{ _id },
|
|
1806
1817
|
{ $set: updateValue },
|
|
1807
1818
|
{ session }
|
|
@@ -1809,13 +1820,13 @@ function useWorkOrderRepo() {
|
|
|
1809
1820
|
if (res.modifiedCount === 0) {
|
|
1810
1821
|
throw new import_node_server_utils7.InternalServerError("Unable to delete work order.");
|
|
1811
1822
|
}
|
|
1812
|
-
|
|
1823
|
+
delNamespaceWorkOrders2().then(() => {
|
|
1813
1824
|
import_node_server_utils7.logger.info(
|
|
1814
|
-
`Cache cleared for namespace: ${
|
|
1825
|
+
`Cache cleared for namespace: ${work_orders2_namespace_collection}`
|
|
1815
1826
|
);
|
|
1816
1827
|
}).catch((err) => {
|
|
1817
1828
|
import_node_server_utils7.logger.error(
|
|
1818
|
-
`Failed to clear cache for namespace: ${
|
|
1829
|
+
`Failed to clear cache for namespace: ${work_orders2_namespace_collection}`,
|
|
1819
1830
|
err
|
|
1820
1831
|
);
|
|
1821
1832
|
});
|
|
@@ -2445,7 +2456,7 @@ function useOccurrenceEntryRepo() {
|
|
|
2445
2456
|
import_node_server_utils8.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
2446
2457
|
return cached;
|
|
2447
2458
|
}
|
|
2448
|
-
const bookId = new import_mongodb7.ObjectId(dailyOccurrenceBookId);
|
|
2459
|
+
const bookId = typeof dailyOccurrenceBookId === "string" ? new import_mongodb7.ObjectId(dailyOccurrenceBookId) : dailyOccurrenceBookId;
|
|
2449
2460
|
const data = await collection.findOne(
|
|
2450
2461
|
{ dailyOccurrenceBookId: bookId },
|
|
2451
2462
|
{
|
|
@@ -2460,6 +2471,16 @@ function useOccurrenceEntryRepo() {
|
|
|
2460
2471
|
});
|
|
2461
2472
|
return serialNumber;
|
|
2462
2473
|
}
|
|
2474
|
+
async function getLatestSerialNumberInGroup(bookId, group) {
|
|
2475
|
+
const latestEntry = await collection.findOne(
|
|
2476
|
+
{
|
|
2477
|
+
dailyOccurrenceBookId: bookId,
|
|
2478
|
+
serialNumber: { $regex: `^${group}(\\.|$)` }
|
|
2479
|
+
},
|
|
2480
|
+
{ sort: { serialNumber: -1 } }
|
|
2481
|
+
);
|
|
2482
|
+
return latestEntry ? Number(latestEntry.serialNumber) : group;
|
|
2483
|
+
}
|
|
2463
2484
|
async function updateUserNameBySignatureId(_id, value, session) {
|
|
2464
2485
|
try {
|
|
2465
2486
|
const updateValue = {
|
|
@@ -2495,7 +2516,8 @@ function useOccurrenceEntryRepo() {
|
|
|
2495
2516
|
createIndexes,
|
|
2496
2517
|
createTextIndex,
|
|
2497
2518
|
getLatestSerialNumber,
|
|
2498
|
-
updateOccurrenceEntryByBookId
|
|
2519
|
+
updateOccurrenceEntryByBookId,
|
|
2520
|
+
getLatestSerialNumberInGroup
|
|
2499
2521
|
};
|
|
2500
2522
|
}
|
|
2501
2523
|
|
|
@@ -13721,11 +13743,18 @@ function useVisitorTransactionRepo() {
|
|
|
13721
13743
|
);
|
|
13722
13744
|
}
|
|
13723
13745
|
}
|
|
13724
|
-
async function add(value, session) {
|
|
13746
|
+
async function add(value, session, returnValue = false) {
|
|
13725
13747
|
try {
|
|
13726
13748
|
value = MVisitorTransaction(value);
|
|
13727
13749
|
const res = await collection.insertOne(value, { session });
|
|
13728
|
-
|
|
13750
|
+
if (returnValue) {
|
|
13751
|
+
return {
|
|
13752
|
+
...value,
|
|
13753
|
+
_id: res.insertedId
|
|
13754
|
+
};
|
|
13755
|
+
} else {
|
|
13756
|
+
return res.insertedId;
|
|
13757
|
+
}
|
|
13729
13758
|
} catch (error) {
|
|
13730
13759
|
console.log("Error in add visitor transaction:", error);
|
|
13731
13760
|
const isDuplicated = error.message.includes("duplicate");
|
|
@@ -15056,7 +15085,11 @@ function usePersonRepo() {
|
|
|
15056
15085
|
try {
|
|
15057
15086
|
await collection.createIndexes([
|
|
15058
15087
|
{ key: { contact: 1 } },
|
|
15059
|
-
{ key: { nric: 1 } }
|
|
15088
|
+
{ key: { nric: 1 } },
|
|
15089
|
+
{ key: { user: 1 } },
|
|
15090
|
+
{ key: { site: 1, status: 1 } },
|
|
15091
|
+
{ key: { "plates.plateNumber": 1, status: 1 } },
|
|
15092
|
+
{ key: { unit: 1, status: 1 } }
|
|
15060
15093
|
]);
|
|
15061
15094
|
} catch (error) {
|
|
15062
15095
|
throw new import_node_server_utils71.InternalServerError("Failed to create index on site people.");
|
|
@@ -17024,6 +17057,9 @@ function useVehicleService() {
|
|
|
17024
17057
|
const _end = vehicle.end;
|
|
17025
17058
|
const _recNo = plate.recNo;
|
|
17026
17059
|
const _type = value.type ? value.type : plate.type;
|
|
17060
|
+
if (value.peopleId) {
|
|
17061
|
+
value.peopleId = new import_mongodb46.ObjectId(value.peopleId);
|
|
17062
|
+
}
|
|
17027
17063
|
const { name, plateNumber, start, end, recNo, type, unit, site, ...rest } = value;
|
|
17028
17064
|
const startDahua = value.start ? formatDahuaDate(new Date(value.start)) : formatDahuaDate(new Date(_start));
|
|
17029
17065
|
const endDahua = value.end ? formatDahuaDate(new Date(value.end)) : formatDahuaDate(new Date(_end));
|
|
@@ -17087,6 +17123,17 @@ function useVehicleService() {
|
|
|
17087
17123
|
}
|
|
17088
17124
|
const responseData = dahuaResponse?.data?.toString("utf-8") ?? "";
|
|
17089
17125
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
17126
|
+
const normalizedPlateNumber = Array.isArray(plateNumber) ? plateNumber[0] : plateNumber;
|
|
17127
|
+
if (value.peopleId && value.recNo) {
|
|
17128
|
+
await _pushVehicleById(
|
|
17129
|
+
value.peopleId,
|
|
17130
|
+
{
|
|
17131
|
+
plateNumber: normalizedPlateNumber,
|
|
17132
|
+
recNo: value.recNo
|
|
17133
|
+
},
|
|
17134
|
+
session
|
|
17135
|
+
);
|
|
17136
|
+
}
|
|
17090
17137
|
} else {
|
|
17091
17138
|
const dahuaPayload = {
|
|
17092
17139
|
host,
|
|
@@ -17100,6 +17147,17 @@ function useVehicleService() {
|
|
|
17100
17147
|
owner: name ? name : _name
|
|
17101
17148
|
};
|
|
17102
17149
|
const dahuaResponse = await _updatePlateNumber(dahuaPayload);
|
|
17150
|
+
const normalizedPlateNumber = Array.isArray(plateNumber) ? plateNumber[0] : plateNumber;
|
|
17151
|
+
if (value.peopleId && value.recNo) {
|
|
17152
|
+
await _pushVehicleById(
|
|
17153
|
+
value.peopleId,
|
|
17154
|
+
{
|
|
17155
|
+
plateNumber: normalizedPlateNumber,
|
|
17156
|
+
recNo: _recNo
|
|
17157
|
+
},
|
|
17158
|
+
session
|
|
17159
|
+
);
|
|
17160
|
+
}
|
|
17103
17161
|
if (dahuaResponse?.statusCode !== 200) {
|
|
17104
17162
|
throw new import_node_server_utils74.BadRequestError(
|
|
17105
17163
|
"Failed to update plate number to ANPR"
|
|
@@ -17294,7 +17352,7 @@ function useDahuaService() {
|
|
|
17294
17352
|
const { createFile: _createFile } = useFileService();
|
|
17295
17353
|
let currentTransactionId = null;
|
|
17296
17354
|
let currentSnapshotField = null;
|
|
17297
|
-
function useBufferQueue(boundary, site, gate, designation, host, username, password) {
|
|
17355
|
+
function useBufferQueue(boundary, site, gate, designation, host, username, password, onDetected) {
|
|
17298
17356
|
const queue = [];
|
|
17299
17357
|
let processing = false;
|
|
17300
17358
|
let plateNumber = null;
|
|
@@ -17327,7 +17385,7 @@ function useDahuaService() {
|
|
|
17327
17385
|
);
|
|
17328
17386
|
streamRef.pause();
|
|
17329
17387
|
}
|
|
17330
|
-
processNext();
|
|
17388
|
+
processNext(onDetected);
|
|
17331
17389
|
}
|
|
17332
17390
|
function destroy() {
|
|
17333
17391
|
queue.length = 0;
|
|
@@ -17343,30 +17401,30 @@ function useDahuaService() {
|
|
|
17343
17401
|
`[${site}][${gate}] BufferQueue destroyed. Processed=${processedChunks}, Dropped=${droppedChunks}`
|
|
17344
17402
|
);
|
|
17345
17403
|
}
|
|
17346
|
-
async function processNext() {
|
|
17404
|
+
async function processNext(onDetected2) {
|
|
17347
17405
|
if (processing || queue.length === 0)
|
|
17348
17406
|
return;
|
|
17349
17407
|
processing = true;
|
|
17350
17408
|
const buffer = queue.shift();
|
|
17351
17409
|
try {
|
|
17352
|
-
await handleBuffer(buffer);
|
|
17410
|
+
await handleBuffer(buffer, onDetected2);
|
|
17353
17411
|
processedChunks++;
|
|
17354
17412
|
if (queue.length <= RESUME_THRESHOLD && streamRef && streamRef.isPaused()) {
|
|
17355
17413
|
loggerDahua.info(
|
|
17356
|
-
`[${
|
|
17414
|
+
`[${host}]Queue at ${queue.length}/${MAX_QUEUE_SIZE}, resuming stream`
|
|
17357
17415
|
);
|
|
17358
17416
|
streamRef.resume();
|
|
17359
17417
|
}
|
|
17360
17418
|
} catch (err) {
|
|
17361
|
-
loggerDahua.error(`[${
|
|
17419
|
+
loggerDahua.error(`[${host}] Error processing buffer:`, err);
|
|
17362
17420
|
} finally {
|
|
17363
17421
|
processing = false;
|
|
17364
|
-
processNext();
|
|
17422
|
+
processNext(onDetected2);
|
|
17365
17423
|
}
|
|
17366
17424
|
}
|
|
17367
|
-
async function processVehicleTransaction() {
|
|
17425
|
+
async function processVehicleTransaction(onDetected2) {
|
|
17368
17426
|
loggerDahua.info(
|
|
17369
|
-
`[${
|
|
17427
|
+
`[${host}] Vehicle transaction: Plate=${plateNumber}, UTC=${UTCData}, UTCMs=${UTCMs}`
|
|
17370
17428
|
);
|
|
17371
17429
|
let org = "";
|
|
17372
17430
|
try {
|
|
@@ -17374,7 +17432,7 @@ function useDahuaService() {
|
|
|
17374
17432
|
org = theSite?.orgId.toString() || "unknown";
|
|
17375
17433
|
} catch (error) {
|
|
17376
17434
|
loggerDahua.error(
|
|
17377
|
-
`[${
|
|
17435
|
+
`[${host}] Error fetching site for orgId:`,
|
|
17378
17436
|
error
|
|
17379
17437
|
);
|
|
17380
17438
|
}
|
|
@@ -17394,7 +17452,7 @@ function useDahuaService() {
|
|
|
17394
17452
|
}
|
|
17395
17453
|
} catch (error) {
|
|
17396
17454
|
loggerDahua.error(
|
|
17397
|
-
`[${
|
|
17455
|
+
`[${host}] Error closing existing open transaction:`,
|
|
17398
17456
|
error
|
|
17399
17457
|
);
|
|
17400
17458
|
}
|
|
@@ -17444,9 +17502,13 @@ function useDahuaService() {
|
|
|
17444
17502
|
}
|
|
17445
17503
|
try {
|
|
17446
17504
|
await addPlateNumber(dahuaPayload);
|
|
17447
|
-
const
|
|
17448
|
-
|
|
17505
|
+
const result = await add(visitorTransaction, void 0, true);
|
|
17506
|
+
const transactionId = result?._id;
|
|
17507
|
+
currentTransactionId = transactionId?.toString();
|
|
17449
17508
|
currentSnapshotField = "snapshotEntryImage";
|
|
17509
|
+
if (onDetected2) {
|
|
17510
|
+
onDetected2({ _id: transactionId, site: result?.site?.toString(), plateNumber: result.plateNumber });
|
|
17511
|
+
}
|
|
17450
17512
|
} catch (error) {
|
|
17451
17513
|
console.log("failed to create visitor transaction", error);
|
|
17452
17514
|
loggerDahua.error(
|
|
@@ -17480,7 +17542,7 @@ function useDahuaService() {
|
|
|
17480
17542
|
}
|
|
17481
17543
|
}
|
|
17482
17544
|
}
|
|
17483
|
-
async function handleBuffer(chunk) {
|
|
17545
|
+
async function handleBuffer(chunk, onDetected2) {
|
|
17484
17546
|
partialBuffer = Buffer.concat([partialBuffer, chunk]);
|
|
17485
17547
|
while (true) {
|
|
17486
17548
|
const boundaryIndex = partialBuffer.indexOf(Buffer.from(boundary));
|
|
@@ -17506,7 +17568,7 @@ function useDahuaService() {
|
|
|
17506
17568
|
direction = line.split("=")[1].trim();
|
|
17507
17569
|
});
|
|
17508
17570
|
if (plateNumber && UTCData) {
|
|
17509
|
-
await processVehicleTransaction();
|
|
17571
|
+
await processVehicleTransaction(onDetected2);
|
|
17510
17572
|
}
|
|
17511
17573
|
} else if (part.includes("Content-Type: image/jpeg")) {
|
|
17512
17574
|
const [headers, ...imageParts] = part.split("\r\n\r\n");
|
|
@@ -17533,7 +17595,7 @@ function useDahuaService() {
|
|
|
17533
17595
|
try {
|
|
17534
17596
|
await import_fs.promises.mkdir(dir, { recursive: true });
|
|
17535
17597
|
await import_fs.promises.writeFile(snapFolder, accumulatedImageBuffer);
|
|
17536
|
-
loggerDahua.debug(`[${
|
|
17598
|
+
loggerDahua.debug(`[${host}] Saved image locally: ${filename}`);
|
|
17537
17599
|
const fileId = await _createFile(
|
|
17538
17600
|
{
|
|
17539
17601
|
originalname: filename,
|
|
@@ -17543,7 +17605,7 @@ function useDahuaService() {
|
|
|
17543
17605
|
`anpr/${site}`
|
|
17544
17606
|
);
|
|
17545
17607
|
loggerDahua.info(
|
|
17546
|
-
`[${
|
|
17608
|
+
`[${host}] Created file record for image: ${fileId.toString()}`
|
|
17547
17609
|
);
|
|
17548
17610
|
if (currentTransactionId && currentSnapshotField) {
|
|
17549
17611
|
await updateById(currentTransactionId, {
|
|
@@ -17551,23 +17613,23 @@ function useDahuaService() {
|
|
|
17551
17613
|
});
|
|
17552
17614
|
}
|
|
17553
17615
|
loggerDahua.info(
|
|
17554
|
-
`[${
|
|
17616
|
+
`[${host}] Image stored with fileId: ${fileId.toString()}`
|
|
17555
17617
|
);
|
|
17556
17618
|
await import_fs.promises.unlink(snapFolder);
|
|
17557
|
-
loggerDahua.
|
|
17619
|
+
loggerDahua.info(`[${host}] Deleted local file: ${filename}`);
|
|
17558
17620
|
} catch (err) {
|
|
17559
17621
|
loggerDahua.error(
|
|
17560
|
-
`[${
|
|
17622
|
+
`[${host}] Failed to process image ${filename}:`,
|
|
17561
17623
|
err
|
|
17562
17624
|
);
|
|
17563
17625
|
try {
|
|
17564
17626
|
await import_fs.promises.unlink(snapFolder);
|
|
17565
|
-
loggerDahua.
|
|
17566
|
-
`[${
|
|
17627
|
+
loggerDahua.error(
|
|
17628
|
+
`[${host}] Cleaned up local file after error: ${filename}`
|
|
17567
17629
|
);
|
|
17568
17630
|
} catch (unlinkErr) {
|
|
17569
17631
|
loggerDahua.error(
|
|
17570
|
-
`[${
|
|
17632
|
+
`[${host}] Failed to clean up local file: ${filename}`,
|
|
17571
17633
|
unlinkErr
|
|
17572
17634
|
);
|
|
17573
17635
|
}
|
|
@@ -17607,7 +17669,7 @@ function useDahuaService() {
|
|
|
17607
17669
|
throw error;
|
|
17608
17670
|
}
|
|
17609
17671
|
}
|
|
17610
|
-
async function listenToCamera(camera) {
|
|
17672
|
+
async function listenToCamera(camera, onDetected) {
|
|
17611
17673
|
if (!camera?._id) {
|
|
17612
17674
|
loggerDahua.error(`Camera _id is required to listen to camera.`);
|
|
17613
17675
|
throw new import_node_server_utils75.BadRequestError("Camera _id is required to listen to camera.");
|
|
@@ -17628,10 +17690,11 @@ function useDahuaService() {
|
|
|
17628
17690
|
`guard-post-${camera.guardPost}`,
|
|
17629
17691
|
camera.direction,
|
|
17630
17692
|
cameraId,
|
|
17631
|
-
controller.signal
|
|
17693
|
+
controller.signal,
|
|
17694
|
+
onDetected
|
|
17632
17695
|
);
|
|
17633
17696
|
}
|
|
17634
|
-
async function
|
|
17697
|
+
async function getTrafficJunctionOld(host = "", username = "", password = "", site = "", gate = "", designation = "", cameraId, signal, onDetected) {
|
|
17635
17698
|
if (signal.aborted)
|
|
17636
17699
|
return;
|
|
17637
17700
|
try {
|
|
@@ -17654,7 +17717,8 @@ function useDahuaService() {
|
|
|
17654
17717
|
designation,
|
|
17655
17718
|
host,
|
|
17656
17719
|
username,
|
|
17657
|
-
password
|
|
17720
|
+
password,
|
|
17721
|
+
onDetected
|
|
17658
17722
|
);
|
|
17659
17723
|
bufferQueue.setStream(response.res);
|
|
17660
17724
|
const onAbort = () => {
|
|
@@ -17708,7 +17772,7 @@ function useDahuaService() {
|
|
|
17708
17772
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17709
17773
|
if (signal.aborted)
|
|
17710
17774
|
return;
|
|
17711
|
-
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17775
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal, onDetected);
|
|
17712
17776
|
};
|
|
17713
17777
|
response.res.on(
|
|
17714
17778
|
"end",
|
|
@@ -17732,8 +17796,87 @@ function useDahuaService() {
|
|
|
17732
17796
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17733
17797
|
if (signal.aborted)
|
|
17734
17798
|
return;
|
|
17735
|
-
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17799
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal, onDetected);
|
|
17800
|
+
}
|
|
17801
|
+
}
|
|
17802
|
+
async function getTrafficJunction(host = "", username = "", password = "", site = "", gate = "", designation = "", cameraId, signal, onDetected) {
|
|
17803
|
+
while (!signal.aborted) {
|
|
17804
|
+
let bufferQueue = null;
|
|
17805
|
+
let response = null;
|
|
17806
|
+
try {
|
|
17807
|
+
response = await useDahuaDigest({
|
|
17808
|
+
host,
|
|
17809
|
+
username,
|
|
17810
|
+
password,
|
|
17811
|
+
endpoint: "/cgi-bin/snapManager.cgi?action=attachFileProc&channel=1&heartbeat=5&Flags[0]=Event&Events=[TrafficJunction]",
|
|
17812
|
+
timeout: 2e4,
|
|
17813
|
+
streaming: true
|
|
17814
|
+
});
|
|
17815
|
+
if ([400, 401, 403, 500].includes(response.statusCode)) {
|
|
17816
|
+
loggerDahua.error(`[${host}] Connection error: ${response.statusCode}`);
|
|
17817
|
+
throw new Error(`Failed to connect to ANPR: ${response.statusCode}`);
|
|
17818
|
+
}
|
|
17819
|
+
loggerDahua.info(`[${host}] Successfully connected to ANPR.`);
|
|
17820
|
+
const contentType = response.res.headers["content-type"];
|
|
17821
|
+
const boundaryMatch = contentType?.match(/boundary=(.*)$/i);
|
|
17822
|
+
const boundary = boundaryMatch ? `--${boundaryMatch[1]}` : "--myboundary";
|
|
17823
|
+
bufferQueue = useBufferQueue(
|
|
17824
|
+
boundary,
|
|
17825
|
+
site,
|
|
17826
|
+
gate,
|
|
17827
|
+
designation,
|
|
17828
|
+
host,
|
|
17829
|
+
username,
|
|
17830
|
+
password,
|
|
17831
|
+
onDetected
|
|
17832
|
+
);
|
|
17833
|
+
bufferQueue.setStream(response.res);
|
|
17834
|
+
await new Promise((resolve, reject) => {
|
|
17835
|
+
const onAbort = () => {
|
|
17836
|
+
loggerDahua.info(`[${site}]-[${host}] Abort triggered. Cleaning up...`);
|
|
17837
|
+
if (response.res && !response.res.destroyed) {
|
|
17838
|
+
response.res.destroy();
|
|
17839
|
+
}
|
|
17840
|
+
resolve("aborted");
|
|
17841
|
+
};
|
|
17842
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
17843
|
+
response.res.on("data", (chunk) => {
|
|
17844
|
+
if (signal.aborted) {
|
|
17845
|
+
response.res.destroy();
|
|
17846
|
+
return;
|
|
17847
|
+
}
|
|
17848
|
+
bufferQueue.enqueue(chunk);
|
|
17849
|
+
});
|
|
17850
|
+
response.res.on("end", () => {
|
|
17851
|
+
signal.removeEventListener("abort", onAbort);
|
|
17852
|
+
resolve("ended");
|
|
17853
|
+
});
|
|
17854
|
+
response.res.on("close", () => {
|
|
17855
|
+
signal.removeEventListener("abort", onAbort);
|
|
17856
|
+
resolve("closed");
|
|
17857
|
+
});
|
|
17858
|
+
response.res.on("error", (err) => {
|
|
17859
|
+
signal.removeEventListener("abort", onAbort);
|
|
17860
|
+
reject(err);
|
|
17861
|
+
});
|
|
17862
|
+
});
|
|
17863
|
+
} catch (error) {
|
|
17864
|
+
if (signal.aborted)
|
|
17865
|
+
break;
|
|
17866
|
+
loggerDahua.error(
|
|
17867
|
+
`[${host}] Connection lost or error: ${error.message || error}. Retrying in 5s...`
|
|
17868
|
+
);
|
|
17869
|
+
} finally {
|
|
17870
|
+
if (bufferQueue?.destroy)
|
|
17871
|
+
bufferQueue.destroy();
|
|
17872
|
+
if (response?.res && !response.res.destroyed)
|
|
17873
|
+
response.res.destroy();
|
|
17874
|
+
}
|
|
17875
|
+
if (!signal.aborted) {
|
|
17876
|
+
await new Promise((res) => setTimeout(res, 5e3));
|
|
17877
|
+
}
|
|
17736
17878
|
}
|
|
17879
|
+
loggerDahua.info(`[${host}] ANPR Listener stopped.`);
|
|
17737
17880
|
}
|
|
17738
17881
|
async function addPlateNumber(value) {
|
|
17739
17882
|
const validation = import_joi40.default.object({
|
|
@@ -20085,7 +20228,9 @@ function useVehicleController() {
|
|
|
20085
20228
|
start: import_joi46.default.string().isoDate().optional().allow(null, ""),
|
|
20086
20229
|
end: import_joi46.default.string().isoDate().optional().allow(null, ""),
|
|
20087
20230
|
recNo: import_joi46.default.string().optional().allow(null, ""),
|
|
20088
|
-
type: import_joi46.default.string().optional().valid(...Object.values(VehicleType)).allow(null, "")
|
|
20231
|
+
type: import_joi46.default.string().optional().valid(...Object.values(VehicleType)).allow(null, ""),
|
|
20232
|
+
peopleId: import_joi46.default.string().hex().length(24).optional().allow(null, ""),
|
|
20233
|
+
seasonPassType: import_joi46.default.string().optional().allow("", null)
|
|
20089
20234
|
});
|
|
20090
20235
|
const { error, value } = schema2.validate(
|
|
20091
20236
|
{
|
|
@@ -20319,7 +20464,7 @@ function useSiteCameraService() {
|
|
|
20319
20464
|
session.endSession();
|
|
20320
20465
|
}
|
|
20321
20466
|
}
|
|
20322
|
-
async function listenToCapturedPlateNumber() {
|
|
20467
|
+
async function listenToCapturedPlateNumber(onDetected) {
|
|
20323
20468
|
const siteCameras = [];
|
|
20324
20469
|
let page = 1;
|
|
20325
20470
|
let pages = 1;
|
|
@@ -20340,7 +20485,7 @@ function useSiteCameraService() {
|
|
|
20340
20485
|
for (let index = 0; index < siteCameras.length; index++) {
|
|
20341
20486
|
const siteCamera = siteCameras[index];
|
|
20342
20487
|
if (siteCamera && siteCamera.status === "active" && siteCamera.host && siteCamera.username && siteCamera.password && siteCamera.site && siteCamera.guardPost) {
|
|
20343
|
-
dahuaService.listenToCamera(siteCamera);
|
|
20488
|
+
dahuaService.listenToCamera(siteCamera, onDetected);
|
|
20344
20489
|
}
|
|
20345
20490
|
}
|
|
20346
20491
|
}
|
|
@@ -25435,11 +25580,7 @@ function usePatrolQuestionRepo() {
|
|
|
25435
25580
|
const { delNamespace, getCache, setCache } = (0, import_node_server_utils114.useCache)(namespace_collection);
|
|
25436
25581
|
async function createIndexes() {
|
|
25437
25582
|
try {
|
|
25438
|
-
await collection.createIndexes([
|
|
25439
|
-
{
|
|
25440
|
-
key: { site: 1 }
|
|
25441
|
-
}
|
|
25442
|
-
]);
|
|
25583
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
25443
25584
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
25444
25585
|
} catch (error) {
|
|
25445
25586
|
import_node_server_utils114.logger.log({
|
|
@@ -25875,6 +26016,24 @@ function usePatrolRouteRepo() {
|
|
|
25875
26016
|
const namespace_collection = "patrol.route";
|
|
25876
26017
|
const collection = db.collection(namespace_collection);
|
|
25877
26018
|
const { delNamespace, getCache, setCache } = (0, import_node_server_utils117.useCache)(namespace_collection);
|
|
26019
|
+
async function createIndexes() {
|
|
26020
|
+
try {
|
|
26021
|
+
await collection.createIndexes([
|
|
26022
|
+
{ key: { site: 1, status: 1 } },
|
|
26023
|
+
{ key: { site: 1, repeat: 1 } },
|
|
26024
|
+
{ key: { assignee: 1 } }
|
|
26025
|
+
]);
|
|
26026
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
26027
|
+
} catch (error) {
|
|
26028
|
+
import_node_server_utils117.logger.log({
|
|
26029
|
+
level: "error",
|
|
26030
|
+
message: error.message
|
|
26031
|
+
});
|
|
26032
|
+
throw new import_node_server_utils117.InternalServerError(
|
|
26033
|
+
"Failed to create general indexes on patrol routes."
|
|
26034
|
+
);
|
|
26035
|
+
}
|
|
26036
|
+
}
|
|
25878
26037
|
async function createTextIndex() {
|
|
25879
26038
|
try {
|
|
25880
26039
|
await collection.createIndex({
|
|
@@ -26248,7 +26407,8 @@ function usePatrolRouteRepo() {
|
|
|
26248
26407
|
updateById,
|
|
26249
26408
|
deleteById,
|
|
26250
26409
|
getScheduledRoute,
|
|
26251
|
-
getById
|
|
26410
|
+
getById,
|
|
26411
|
+
createIndexes
|
|
26252
26412
|
};
|
|
26253
26413
|
}
|
|
26254
26414
|
|
|
@@ -26586,9 +26746,8 @@ function usePatrolLogRepo() {
|
|
|
26586
26746
|
async function createIndexes() {
|
|
26587
26747
|
try {
|
|
26588
26748
|
await collection.createIndexes([
|
|
26589
|
-
{
|
|
26590
|
-
|
|
26591
|
-
}
|
|
26749
|
+
{ key: { site: 1, createdAt: -1 } },
|
|
26750
|
+
{ key: { assignee: 1 } }
|
|
26592
26751
|
]);
|
|
26593
26752
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
26594
26753
|
} catch (error) {
|
|
@@ -30415,6 +30574,20 @@ function useSiteBillingItemRepo() {
|
|
|
30415
30574
|
const namespace_collection = "site.billing.items";
|
|
30416
30575
|
const collection = db.collection(namespace_collection);
|
|
30417
30576
|
const { delNamespace, setCache, getCache } = (0, import_node_server_utils139.useCache)(namespace_collection);
|
|
30577
|
+
async function createIndexes() {
|
|
30578
|
+
try {
|
|
30579
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
30580
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
30581
|
+
} catch (error) {
|
|
30582
|
+
import_node_server_utils139.logger.log({
|
|
30583
|
+
level: "error",
|
|
30584
|
+
message: error.message
|
|
30585
|
+
});
|
|
30586
|
+
throw new import_node_server_utils139.InternalServerError(
|
|
30587
|
+
"Failed to create general indexes on billing item."
|
|
30588
|
+
);
|
|
30589
|
+
}
|
|
30590
|
+
}
|
|
30418
30591
|
async function createTextIndex() {
|
|
30419
30592
|
try {
|
|
30420
30593
|
await collection.createIndex({
|
|
@@ -30634,7 +30807,8 @@ function useSiteBillingItemRepo() {
|
|
|
30634
30807
|
getAll,
|
|
30635
30808
|
getById,
|
|
30636
30809
|
updateById,
|
|
30637
|
-
deleteById
|
|
30810
|
+
deleteById,
|
|
30811
|
+
createIndexes
|
|
30638
30812
|
};
|
|
30639
30813
|
}
|
|
30640
30814
|
|
|
@@ -30775,6 +30949,20 @@ function useSiteBillingConfigurationRepo() {
|
|
|
30775
30949
|
const namespace_collection = "site.billing.configuration";
|
|
30776
30950
|
const collection = db.collection(namespace_collection);
|
|
30777
30951
|
const { delNamespace, setCache, getCache } = (0, import_node_server_utils141.useCache)(namespace_collection);
|
|
30952
|
+
async function createIndexes() {
|
|
30953
|
+
try {
|
|
30954
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
30955
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
30956
|
+
} catch (error) {
|
|
30957
|
+
import_node_server_utils141.logger.log({
|
|
30958
|
+
level: "error",
|
|
30959
|
+
message: error.message
|
|
30960
|
+
});
|
|
30961
|
+
throw new import_node_server_utils141.InternalServerError(
|
|
30962
|
+
"Failed to create general indexes on billing configuration."
|
|
30963
|
+
);
|
|
30964
|
+
}
|
|
30965
|
+
}
|
|
30778
30966
|
async function createTextIndex() {
|
|
30779
30967
|
try {
|
|
30780
30968
|
await collection.createIndex({
|
|
@@ -30984,7 +31172,8 @@ function useSiteBillingConfigurationRepo() {
|
|
|
30984
31172
|
getAll,
|
|
30985
31173
|
getById,
|
|
30986
31174
|
updateById,
|
|
30987
|
-
deleteById
|
|
31175
|
+
deleteById,
|
|
31176
|
+
createIndexes
|
|
30988
31177
|
};
|
|
30989
31178
|
}
|
|
30990
31179
|
|
|
@@ -32265,6 +32454,25 @@ function useSiteUnitBillingRepo() {
|
|
|
32265
32454
|
const namespace_collection = "site.unit.billing";
|
|
32266
32455
|
const collection = db.collection(namespace_collection);
|
|
32267
32456
|
const { delNamespace, setCache, getCache } = (0, import_node_server_utils150.useCache)(namespace_collection);
|
|
32457
|
+
async function createIndexes() {
|
|
32458
|
+
try {
|
|
32459
|
+
await collection.createIndexes([
|
|
32460
|
+
{ key: { site: 1, status: 1, paymentStatus: 1 } },
|
|
32461
|
+
{ key: { site: 1, unitId: 1, status: 1, paymentStatus: 1 } },
|
|
32462
|
+
{ key: { site: 1, unitId: 1, issueDate: 1 } },
|
|
32463
|
+
{ key: { createdAt: -1 } }
|
|
32464
|
+
]);
|
|
32465
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
32466
|
+
} catch (error) {
|
|
32467
|
+
import_node_server_utils150.logger.log({
|
|
32468
|
+
level: "error",
|
|
32469
|
+
message: error.message
|
|
32470
|
+
});
|
|
32471
|
+
throw new import_node_server_utils150.InternalServerError(
|
|
32472
|
+
"Failed to create general indexes on unit billing."
|
|
32473
|
+
);
|
|
32474
|
+
}
|
|
32475
|
+
}
|
|
32268
32476
|
async function createTextIndex() {
|
|
32269
32477
|
try {
|
|
32270
32478
|
await collection.createIndex({
|
|
@@ -32818,7 +33026,8 @@ function useSiteUnitBillingRepo() {
|
|
|
32818
33026
|
deleteById,
|
|
32819
33027
|
getUnitBillingBySite,
|
|
32820
33028
|
getResidentUserBilling,
|
|
32821
|
-
getResidentUserUnsettledBilling
|
|
33029
|
+
getResidentUserUnsettledBilling,
|
|
33030
|
+
createIndexes
|
|
32822
33031
|
};
|
|
32823
33032
|
}
|
|
32824
33033
|
|
|
@@ -38632,6 +38841,22 @@ function useStatementOfAccountRepo() {
|
|
|
38632
38841
|
const namespace_collection = "site.statement-of-accounts";
|
|
38633
38842
|
const collection = db.collection(namespace_collection);
|
|
38634
38843
|
const { delNamespace, getCache, setCache } = (0, import_node_server_utils165.useCache)(namespace_collection);
|
|
38844
|
+
async function createIndexes() {
|
|
38845
|
+
try {
|
|
38846
|
+
await collection.createIndexes([
|
|
38847
|
+
{ key: { site: 1, status: 1 } },
|
|
38848
|
+
{ key: { site: 1, unitId: 1, status: 1 } },
|
|
38849
|
+
{ key: { createdAt: -1 } }
|
|
38850
|
+
]);
|
|
38851
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
38852
|
+
} catch (error) {
|
|
38853
|
+
import_node_server_utils165.logger.log({
|
|
38854
|
+
level: "error",
|
|
38855
|
+
message: error.message
|
|
38856
|
+
});
|
|
38857
|
+
throw new import_node_server_utils165.InternalServerError("Failed to create general indexes on SOA.");
|
|
38858
|
+
}
|
|
38859
|
+
}
|
|
38635
38860
|
async function createTextIndex() {
|
|
38636
38861
|
try {
|
|
38637
38862
|
await collection.createIndex({
|
|
@@ -38982,7 +39207,8 @@ function useStatementOfAccountRepo() {
|
|
|
38982
39207
|
deleteById,
|
|
38983
39208
|
updateStatusById,
|
|
38984
39209
|
getResidentUserSoa,
|
|
38985
|
-
reviewSOA
|
|
39210
|
+
reviewSOA,
|
|
39211
|
+
createIndexes
|
|
38986
39212
|
};
|
|
38987
39213
|
}
|
|
38988
39214
|
|
|
@@ -42537,7 +42763,10 @@ function useOccurrenceEntryService() {
|
|
|
42537
42763
|
updateOccurrenceEntryById: _updateOccurrenceEntryById,
|
|
42538
42764
|
getOccurrenceEntryById: _getOccurrenceEntryById,
|
|
42539
42765
|
getOccurrenceEntryByBookId: _getOccurrenceEntryByBookId,
|
|
42540
|
-
updateOccurrenceEntryByBookId: _updateOccurrenceEntryByBookId
|
|
42766
|
+
updateOccurrenceEntryByBookId: _updateOccurrenceEntryByBookId,
|
|
42767
|
+
deleteOccurrenceEntryById: _deleteOccurrenceEntryById,
|
|
42768
|
+
getLatestSerialNumber: _getLatestSerialNumber,
|
|
42769
|
+
getLatestSerialNumberInGroup: _getLatestSerialNumberInGroup
|
|
42541
42770
|
} = useOccurrenceEntryRepo();
|
|
42542
42771
|
const {
|
|
42543
42772
|
getOccurrenceBookById: _getOccurrenceBookById,
|
|
@@ -42589,8 +42818,20 @@ function useOccurrenceEntryService() {
|
|
|
42589
42818
|
if (!occurrenceEntry) {
|
|
42590
42819
|
throw new Error("Occurrence entry not found.");
|
|
42591
42820
|
}
|
|
42592
|
-
const
|
|
42593
|
-
|
|
42821
|
+
const entryCount = await _getLatestSerialNumberInGroup(
|
|
42822
|
+
occurrenceEntry.dailyOccurrenceBookId,
|
|
42823
|
+
Number(occurrenceEntry.serialNumber)
|
|
42824
|
+
);
|
|
42825
|
+
const currentSerial = Number(occurrenceEntry.serialNumber);
|
|
42826
|
+
const latestSerial = Number(entryCount);
|
|
42827
|
+
const currentGroup = Math.floor(currentSerial);
|
|
42828
|
+
const latestGroup = Math.floor(latestSerial);
|
|
42829
|
+
let updatedSerialNumber;
|
|
42830
|
+
if (currentGroup === latestGroup) {
|
|
42831
|
+
updatedSerialNumber = (latestSerial + 0.1).toFixed(1);
|
|
42832
|
+
} else {
|
|
42833
|
+
updatedSerialNumber = (currentSerial + 0.1).toFixed(1);
|
|
42834
|
+
}
|
|
42594
42835
|
const dobId = occurrenceEntry.dailyOccurrenceBookId;
|
|
42595
42836
|
const book = await _getOccurrenceBookById(dobId);
|
|
42596
42837
|
const subject = await _getOccurrenceSubjectById(
|
|
@@ -45049,7 +45290,9 @@ function useManpowerMonitoringRepo() {
|
|
|
45049
45290
|
{
|
|
45050
45291
|
key: { siteId: 1 }
|
|
45051
45292
|
},
|
|
45052
|
-
{ key: { createdAt: 1 } }
|
|
45293
|
+
{ key: { createdAt: 1 } },
|
|
45294
|
+
{ key: { siteId: 1, serviceProviderId: 1 } },
|
|
45295
|
+
{ key: { siteName: 1 } }
|
|
45053
45296
|
]);
|
|
45054
45297
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45055
45298
|
} catch (error) {
|
|
@@ -45308,7 +45551,9 @@ function useManpowerRemarksRepo() {
|
|
|
45308
45551
|
{
|
|
45309
45552
|
key: { siteId: 1 }
|
|
45310
45553
|
},
|
|
45311
|
-
{ key: { createdAt: 1 } }
|
|
45554
|
+
{ key: { createdAt: 1 } },
|
|
45555
|
+
{ key: { siteId: 1, serviceProviderId: 1, createdAtSGT: 1 } },
|
|
45556
|
+
{ key: { serviceProviderId: 1, status: 1, createdAtSGT: 1 } }
|
|
45312
45557
|
]);
|
|
45313
45558
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45314
45559
|
} catch (error) {
|
|
@@ -45737,7 +45982,8 @@ function useManpowerDesignationRepo() {
|
|
|
45737
45982
|
{
|
|
45738
45983
|
key: { siteId: 1 }
|
|
45739
45984
|
},
|
|
45740
|
-
{ key: { createdAt: 1 } }
|
|
45985
|
+
{ key: { createdAt: 1 } },
|
|
45986
|
+
{ key: { siteId: 1, serviceProviderId: 1 } }
|
|
45741
45987
|
]);
|
|
45742
45988
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45743
45989
|
} catch (error) {
|
|
@@ -51179,6 +51425,7 @@ function useRoleControllerV2() {
|
|
|
51179
51425
|
vehicles_namespace_collection,
|
|
51180
51426
|
visitors_namespace_collection,
|
|
51181
51427
|
workOrderSchema,
|
|
51428
|
+
work_orders2_namespace_collection,
|
|
51182
51429
|
work_orders_namespace_collection
|
|
51183
51430
|
});
|
|
51184
51431
|
//# sourceMappingURL=index.js.map
|