@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.mjs
CHANGED
|
@@ -940,12 +940,16 @@ import {
|
|
|
940
940
|
makeCacheKey as makeCacheKey3
|
|
941
941
|
} from "@7365admin1/node-server-utils";
|
|
942
942
|
var work_orders_namespace_collection = "work-orders";
|
|
943
|
+
var work_orders2_namespace_collection = "work-orders2";
|
|
943
944
|
function useWorkOrderRepo() {
|
|
944
945
|
const db = useAtlas3.getDb();
|
|
945
946
|
if (!db) {
|
|
946
947
|
throw new InternalServerError3("Unable to connect to server.");
|
|
947
948
|
}
|
|
948
949
|
const collection = db.collection(work_orders_namespace_collection);
|
|
950
|
+
const workOrders2Collection = db.collection(
|
|
951
|
+
work_orders2_namespace_collection
|
|
952
|
+
);
|
|
949
953
|
async function createIndex() {
|
|
950
954
|
try {
|
|
951
955
|
await collection.createIndexes([
|
|
@@ -977,6 +981,12 @@ function useWorkOrderRepo() {
|
|
|
977
981
|
const { delNamespace, setCache, getCache, delCache } = useCache3(
|
|
978
982
|
work_orders_namespace_collection
|
|
979
983
|
);
|
|
984
|
+
const {
|
|
985
|
+
delNamespace: delNamespaceWorkOrders2,
|
|
986
|
+
setCache: setCacheWorkOrders2,
|
|
987
|
+
getCache: getCacheWorkOrders2,
|
|
988
|
+
delCache: delCacheWorkOrders2
|
|
989
|
+
} = useCache3(work_orders2_namespace_collection);
|
|
980
990
|
const { delNamespace: _delDashboardNameSpace } = useCache3("dashboard");
|
|
981
991
|
async function createWorkOrder(value, session) {
|
|
982
992
|
try {
|
|
@@ -1378,7 +1388,7 @@ function useWorkOrderRepo() {
|
|
|
1378
1388
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
1379
1389
|
deletedAt: /* @__PURE__ */ new Date()
|
|
1380
1390
|
};
|
|
1381
|
-
const res = await
|
|
1391
|
+
const res = await workOrders2Collection.updateOne(
|
|
1382
1392
|
{ _id },
|
|
1383
1393
|
{ $set: updateValue },
|
|
1384
1394
|
{ session }
|
|
@@ -1386,13 +1396,13 @@ function useWorkOrderRepo() {
|
|
|
1386
1396
|
if (res.modifiedCount === 0) {
|
|
1387
1397
|
throw new InternalServerError3("Unable to delete work order.");
|
|
1388
1398
|
}
|
|
1389
|
-
|
|
1399
|
+
delNamespaceWorkOrders2().then(() => {
|
|
1390
1400
|
logger5.info(
|
|
1391
|
-
`Cache cleared for namespace: ${
|
|
1401
|
+
`Cache cleared for namespace: ${work_orders2_namespace_collection}`
|
|
1392
1402
|
);
|
|
1393
1403
|
}).catch((err) => {
|
|
1394
1404
|
logger5.error(
|
|
1395
|
-
`Failed to clear cache for namespace: ${
|
|
1405
|
+
`Failed to clear cache for namespace: ${work_orders2_namespace_collection}`,
|
|
1396
1406
|
err
|
|
1397
1407
|
);
|
|
1398
1408
|
});
|
|
@@ -2031,7 +2041,7 @@ function useOccurrenceEntryRepo() {
|
|
|
2031
2041
|
logger6.info(`Cache hit for key: ${cacheKey}`);
|
|
2032
2042
|
return cached;
|
|
2033
2043
|
}
|
|
2034
|
-
const bookId = new ObjectId7(dailyOccurrenceBookId);
|
|
2044
|
+
const bookId = typeof dailyOccurrenceBookId === "string" ? new ObjectId7(dailyOccurrenceBookId) : dailyOccurrenceBookId;
|
|
2035
2045
|
const data = await collection.findOne(
|
|
2036
2046
|
{ dailyOccurrenceBookId: bookId },
|
|
2037
2047
|
{
|
|
@@ -2046,6 +2056,16 @@ function useOccurrenceEntryRepo() {
|
|
|
2046
2056
|
});
|
|
2047
2057
|
return serialNumber;
|
|
2048
2058
|
}
|
|
2059
|
+
async function getLatestSerialNumberInGroup(bookId, group) {
|
|
2060
|
+
const latestEntry = await collection.findOne(
|
|
2061
|
+
{
|
|
2062
|
+
dailyOccurrenceBookId: bookId,
|
|
2063
|
+
serialNumber: { $regex: `^${group}(\\.|$)` }
|
|
2064
|
+
},
|
|
2065
|
+
{ sort: { serialNumber: -1 } }
|
|
2066
|
+
);
|
|
2067
|
+
return latestEntry ? Number(latestEntry.serialNumber) : group;
|
|
2068
|
+
}
|
|
2049
2069
|
async function updateUserNameBySignatureId(_id, value, session) {
|
|
2050
2070
|
try {
|
|
2051
2071
|
const updateValue = {
|
|
@@ -2081,7 +2101,8 @@ function useOccurrenceEntryRepo() {
|
|
|
2081
2101
|
createIndexes,
|
|
2082
2102
|
createTextIndex,
|
|
2083
2103
|
getLatestSerialNumber,
|
|
2084
|
-
updateOccurrenceEntryByBookId
|
|
2104
|
+
updateOccurrenceEntryByBookId,
|
|
2105
|
+
getLatestSerialNumberInGroup
|
|
2085
2106
|
};
|
|
2086
2107
|
}
|
|
2087
2108
|
|
|
@@ -13508,11 +13529,18 @@ function useVisitorTransactionRepo() {
|
|
|
13508
13529
|
);
|
|
13509
13530
|
}
|
|
13510
13531
|
}
|
|
13511
|
-
async function add(value, session) {
|
|
13532
|
+
async function add(value, session, returnValue = false) {
|
|
13512
13533
|
try {
|
|
13513
13534
|
value = MVisitorTransaction(value);
|
|
13514
13535
|
const res = await collection.insertOne(value, { session });
|
|
13515
|
-
|
|
13536
|
+
if (returnValue) {
|
|
13537
|
+
return {
|
|
13538
|
+
...value,
|
|
13539
|
+
_id: res.insertedId
|
|
13540
|
+
};
|
|
13541
|
+
} else {
|
|
13542
|
+
return res.insertedId;
|
|
13543
|
+
}
|
|
13516
13544
|
} catch (error) {
|
|
13517
13545
|
console.log("Error in add visitor transaction:", error);
|
|
13518
13546
|
const isDuplicated = error.message.includes("duplicate");
|
|
@@ -14866,7 +14894,11 @@ function usePersonRepo() {
|
|
|
14866
14894
|
try {
|
|
14867
14895
|
await collection.createIndexes([
|
|
14868
14896
|
{ key: { contact: 1 } },
|
|
14869
|
-
{ key: { nric: 1 } }
|
|
14897
|
+
{ key: { nric: 1 } },
|
|
14898
|
+
{ key: { user: 1 } },
|
|
14899
|
+
{ key: { site: 1, status: 1 } },
|
|
14900
|
+
{ key: { "plates.plateNumber": 1, status: 1 } },
|
|
14901
|
+
{ key: { unit: 1, status: 1 } }
|
|
14870
14902
|
]);
|
|
14871
14903
|
} catch (error) {
|
|
14872
14904
|
throw new InternalServerError26("Failed to create index on site people.");
|
|
@@ -16844,6 +16876,9 @@ function useVehicleService() {
|
|
|
16844
16876
|
const _end = vehicle.end;
|
|
16845
16877
|
const _recNo = plate.recNo;
|
|
16846
16878
|
const _type = value.type ? value.type : plate.type;
|
|
16879
|
+
if (value.peopleId) {
|
|
16880
|
+
value.peopleId = new ObjectId46(value.peopleId);
|
|
16881
|
+
}
|
|
16847
16882
|
const { name, plateNumber, start, end, recNo, type, unit, site, ...rest } = value;
|
|
16848
16883
|
const startDahua = value.start ? formatDahuaDate(new Date(value.start)) : formatDahuaDate(new Date(_start));
|
|
16849
16884
|
const endDahua = value.end ? formatDahuaDate(new Date(value.end)) : formatDahuaDate(new Date(_end));
|
|
@@ -16907,6 +16942,17 @@ function useVehicleService() {
|
|
|
16907
16942
|
}
|
|
16908
16943
|
const responseData = dahuaResponse?.data?.toString("utf-8") ?? "";
|
|
16909
16944
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
16945
|
+
const normalizedPlateNumber = Array.isArray(plateNumber) ? plateNumber[0] : plateNumber;
|
|
16946
|
+
if (value.peopleId && value.recNo) {
|
|
16947
|
+
await _pushVehicleById(
|
|
16948
|
+
value.peopleId,
|
|
16949
|
+
{
|
|
16950
|
+
plateNumber: normalizedPlateNumber,
|
|
16951
|
+
recNo: value.recNo
|
|
16952
|
+
},
|
|
16953
|
+
session
|
|
16954
|
+
);
|
|
16955
|
+
}
|
|
16910
16956
|
} else {
|
|
16911
16957
|
const dahuaPayload = {
|
|
16912
16958
|
host,
|
|
@@ -16920,6 +16966,17 @@ function useVehicleService() {
|
|
|
16920
16966
|
owner: name ? name : _name
|
|
16921
16967
|
};
|
|
16922
16968
|
const dahuaResponse = await _updatePlateNumber(dahuaPayload);
|
|
16969
|
+
const normalizedPlateNumber = Array.isArray(plateNumber) ? plateNumber[0] : plateNumber;
|
|
16970
|
+
if (value.peopleId && value.recNo) {
|
|
16971
|
+
await _pushVehicleById(
|
|
16972
|
+
value.peopleId,
|
|
16973
|
+
{
|
|
16974
|
+
plateNumber: normalizedPlateNumber,
|
|
16975
|
+
recNo: _recNo
|
|
16976
|
+
},
|
|
16977
|
+
session
|
|
16978
|
+
);
|
|
16979
|
+
}
|
|
16923
16980
|
if (dahuaResponse?.statusCode !== 200) {
|
|
16924
16981
|
throw new BadRequestError72(
|
|
16925
16982
|
"Failed to update plate number to ANPR"
|
|
@@ -17114,7 +17171,7 @@ function useDahuaService() {
|
|
|
17114
17171
|
const { createFile: _createFile } = useFileService();
|
|
17115
17172
|
let currentTransactionId = null;
|
|
17116
17173
|
let currentSnapshotField = null;
|
|
17117
|
-
function useBufferQueue(boundary, site, gate, designation, host, username, password) {
|
|
17174
|
+
function useBufferQueue(boundary, site, gate, designation, host, username, password, onDetected) {
|
|
17118
17175
|
const queue = [];
|
|
17119
17176
|
let processing = false;
|
|
17120
17177
|
let plateNumber = null;
|
|
@@ -17147,7 +17204,7 @@ function useDahuaService() {
|
|
|
17147
17204
|
);
|
|
17148
17205
|
streamRef.pause();
|
|
17149
17206
|
}
|
|
17150
|
-
processNext();
|
|
17207
|
+
processNext(onDetected);
|
|
17151
17208
|
}
|
|
17152
17209
|
function destroy() {
|
|
17153
17210
|
queue.length = 0;
|
|
@@ -17163,30 +17220,30 @@ function useDahuaService() {
|
|
|
17163
17220
|
`[${site}][${gate}] BufferQueue destroyed. Processed=${processedChunks}, Dropped=${droppedChunks}`
|
|
17164
17221
|
);
|
|
17165
17222
|
}
|
|
17166
|
-
async function processNext() {
|
|
17223
|
+
async function processNext(onDetected2) {
|
|
17167
17224
|
if (processing || queue.length === 0)
|
|
17168
17225
|
return;
|
|
17169
17226
|
processing = true;
|
|
17170
17227
|
const buffer = queue.shift();
|
|
17171
17228
|
try {
|
|
17172
|
-
await handleBuffer(buffer);
|
|
17229
|
+
await handleBuffer(buffer, onDetected2);
|
|
17173
17230
|
processedChunks++;
|
|
17174
17231
|
if (queue.length <= RESUME_THRESHOLD && streamRef && streamRef.isPaused()) {
|
|
17175
17232
|
loggerDahua.info(
|
|
17176
|
-
`[${
|
|
17233
|
+
`[${host}]Queue at ${queue.length}/${MAX_QUEUE_SIZE}, resuming stream`
|
|
17177
17234
|
);
|
|
17178
17235
|
streamRef.resume();
|
|
17179
17236
|
}
|
|
17180
17237
|
} catch (err) {
|
|
17181
|
-
loggerDahua.error(`[${
|
|
17238
|
+
loggerDahua.error(`[${host}] Error processing buffer:`, err);
|
|
17182
17239
|
} finally {
|
|
17183
17240
|
processing = false;
|
|
17184
|
-
processNext();
|
|
17241
|
+
processNext(onDetected2);
|
|
17185
17242
|
}
|
|
17186
17243
|
}
|
|
17187
|
-
async function processVehicleTransaction() {
|
|
17244
|
+
async function processVehicleTransaction(onDetected2) {
|
|
17188
17245
|
loggerDahua.info(
|
|
17189
|
-
`[${
|
|
17246
|
+
`[${host}] Vehicle transaction: Plate=${plateNumber}, UTC=${UTCData}, UTCMs=${UTCMs}`
|
|
17190
17247
|
);
|
|
17191
17248
|
let org = "";
|
|
17192
17249
|
try {
|
|
@@ -17194,7 +17251,7 @@ function useDahuaService() {
|
|
|
17194
17251
|
org = theSite?.orgId.toString() || "unknown";
|
|
17195
17252
|
} catch (error) {
|
|
17196
17253
|
loggerDahua.error(
|
|
17197
|
-
`[${
|
|
17254
|
+
`[${host}] Error fetching site for orgId:`,
|
|
17198
17255
|
error
|
|
17199
17256
|
);
|
|
17200
17257
|
}
|
|
@@ -17214,7 +17271,7 @@ function useDahuaService() {
|
|
|
17214
17271
|
}
|
|
17215
17272
|
} catch (error) {
|
|
17216
17273
|
loggerDahua.error(
|
|
17217
|
-
`[${
|
|
17274
|
+
`[${host}] Error closing existing open transaction:`,
|
|
17218
17275
|
error
|
|
17219
17276
|
);
|
|
17220
17277
|
}
|
|
@@ -17264,9 +17321,13 @@ function useDahuaService() {
|
|
|
17264
17321
|
}
|
|
17265
17322
|
try {
|
|
17266
17323
|
await addPlateNumber(dahuaPayload);
|
|
17267
|
-
const
|
|
17268
|
-
|
|
17324
|
+
const result = await add(visitorTransaction, void 0, true);
|
|
17325
|
+
const transactionId = result?._id;
|
|
17326
|
+
currentTransactionId = transactionId?.toString();
|
|
17269
17327
|
currentSnapshotField = "snapshotEntryImage";
|
|
17328
|
+
if (onDetected2) {
|
|
17329
|
+
onDetected2({ _id: transactionId, site: result?.site?.toString(), plateNumber: result.plateNumber });
|
|
17330
|
+
}
|
|
17270
17331
|
} catch (error) {
|
|
17271
17332
|
console.log("failed to create visitor transaction", error);
|
|
17272
17333
|
loggerDahua.error(
|
|
@@ -17300,7 +17361,7 @@ function useDahuaService() {
|
|
|
17300
17361
|
}
|
|
17301
17362
|
}
|
|
17302
17363
|
}
|
|
17303
|
-
async function handleBuffer(chunk) {
|
|
17364
|
+
async function handleBuffer(chunk, onDetected2) {
|
|
17304
17365
|
partialBuffer = Buffer.concat([partialBuffer, chunk]);
|
|
17305
17366
|
while (true) {
|
|
17306
17367
|
const boundaryIndex = partialBuffer.indexOf(Buffer.from(boundary));
|
|
@@ -17326,7 +17387,7 @@ function useDahuaService() {
|
|
|
17326
17387
|
direction = line.split("=")[1].trim();
|
|
17327
17388
|
});
|
|
17328
17389
|
if (plateNumber && UTCData) {
|
|
17329
|
-
await processVehicleTransaction();
|
|
17390
|
+
await processVehicleTransaction(onDetected2);
|
|
17330
17391
|
}
|
|
17331
17392
|
} else if (part.includes("Content-Type: image/jpeg")) {
|
|
17332
17393
|
const [headers, ...imageParts] = part.split("\r\n\r\n");
|
|
@@ -17353,7 +17414,7 @@ function useDahuaService() {
|
|
|
17353
17414
|
try {
|
|
17354
17415
|
await fsAsync.mkdir(dir, { recursive: true });
|
|
17355
17416
|
await fsAsync.writeFile(snapFolder, accumulatedImageBuffer);
|
|
17356
|
-
loggerDahua.debug(`[${
|
|
17417
|
+
loggerDahua.debug(`[${host}] Saved image locally: ${filename}`);
|
|
17357
17418
|
const fileId = await _createFile(
|
|
17358
17419
|
{
|
|
17359
17420
|
originalname: filename,
|
|
@@ -17363,7 +17424,7 @@ function useDahuaService() {
|
|
|
17363
17424
|
`anpr/${site}`
|
|
17364
17425
|
);
|
|
17365
17426
|
loggerDahua.info(
|
|
17366
|
-
`[${
|
|
17427
|
+
`[${host}] Created file record for image: ${fileId.toString()}`
|
|
17367
17428
|
);
|
|
17368
17429
|
if (currentTransactionId && currentSnapshotField) {
|
|
17369
17430
|
await updateById(currentTransactionId, {
|
|
@@ -17371,23 +17432,23 @@ function useDahuaService() {
|
|
|
17371
17432
|
});
|
|
17372
17433
|
}
|
|
17373
17434
|
loggerDahua.info(
|
|
17374
|
-
`[${
|
|
17435
|
+
`[${host}] Image stored with fileId: ${fileId.toString()}`
|
|
17375
17436
|
);
|
|
17376
17437
|
await fsAsync.unlink(snapFolder);
|
|
17377
|
-
loggerDahua.
|
|
17438
|
+
loggerDahua.info(`[${host}] Deleted local file: ${filename}`);
|
|
17378
17439
|
} catch (err) {
|
|
17379
17440
|
loggerDahua.error(
|
|
17380
|
-
`[${
|
|
17441
|
+
`[${host}] Failed to process image ${filename}:`,
|
|
17381
17442
|
err
|
|
17382
17443
|
);
|
|
17383
17444
|
try {
|
|
17384
17445
|
await fsAsync.unlink(snapFolder);
|
|
17385
|
-
loggerDahua.
|
|
17386
|
-
`[${
|
|
17446
|
+
loggerDahua.error(
|
|
17447
|
+
`[${host}] Cleaned up local file after error: ${filename}`
|
|
17387
17448
|
);
|
|
17388
17449
|
} catch (unlinkErr) {
|
|
17389
17450
|
loggerDahua.error(
|
|
17390
|
-
`[${
|
|
17451
|
+
`[${host}] Failed to clean up local file: ${filename}`,
|
|
17391
17452
|
unlinkErr
|
|
17392
17453
|
);
|
|
17393
17454
|
}
|
|
@@ -17427,7 +17488,7 @@ function useDahuaService() {
|
|
|
17427
17488
|
throw error;
|
|
17428
17489
|
}
|
|
17429
17490
|
}
|
|
17430
|
-
async function listenToCamera(camera) {
|
|
17491
|
+
async function listenToCamera(camera, onDetected) {
|
|
17431
17492
|
if (!camera?._id) {
|
|
17432
17493
|
loggerDahua.error(`Camera _id is required to listen to camera.`);
|
|
17433
17494
|
throw new BadRequestError73("Camera _id is required to listen to camera.");
|
|
@@ -17448,10 +17509,11 @@ function useDahuaService() {
|
|
|
17448
17509
|
`guard-post-${camera.guardPost}`,
|
|
17449
17510
|
camera.direction,
|
|
17450
17511
|
cameraId,
|
|
17451
|
-
controller.signal
|
|
17512
|
+
controller.signal,
|
|
17513
|
+
onDetected
|
|
17452
17514
|
);
|
|
17453
17515
|
}
|
|
17454
|
-
async function
|
|
17516
|
+
async function getTrafficJunctionOld(host = "", username = "", password = "", site = "", gate = "", designation = "", cameraId, signal, onDetected) {
|
|
17455
17517
|
if (signal.aborted)
|
|
17456
17518
|
return;
|
|
17457
17519
|
try {
|
|
@@ -17474,7 +17536,8 @@ function useDahuaService() {
|
|
|
17474
17536
|
designation,
|
|
17475
17537
|
host,
|
|
17476
17538
|
username,
|
|
17477
|
-
password
|
|
17539
|
+
password,
|
|
17540
|
+
onDetected
|
|
17478
17541
|
);
|
|
17479
17542
|
bufferQueue.setStream(response.res);
|
|
17480
17543
|
const onAbort = () => {
|
|
@@ -17528,7 +17591,7 @@ function useDahuaService() {
|
|
|
17528
17591
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17529
17592
|
if (signal.aborted)
|
|
17530
17593
|
return;
|
|
17531
|
-
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17594
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal, onDetected);
|
|
17532
17595
|
};
|
|
17533
17596
|
response.res.on(
|
|
17534
17597
|
"end",
|
|
@@ -17552,8 +17615,87 @@ function useDahuaService() {
|
|
|
17552
17615
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17553
17616
|
if (signal.aborted)
|
|
17554
17617
|
return;
|
|
17555
|
-
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17618
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal, onDetected);
|
|
17619
|
+
}
|
|
17620
|
+
}
|
|
17621
|
+
async function getTrafficJunction(host = "", username = "", password = "", site = "", gate = "", designation = "", cameraId, signal, onDetected) {
|
|
17622
|
+
while (!signal.aborted) {
|
|
17623
|
+
let bufferQueue = null;
|
|
17624
|
+
let response = null;
|
|
17625
|
+
try {
|
|
17626
|
+
response = await useDahuaDigest({
|
|
17627
|
+
host,
|
|
17628
|
+
username,
|
|
17629
|
+
password,
|
|
17630
|
+
endpoint: "/cgi-bin/snapManager.cgi?action=attachFileProc&channel=1&heartbeat=5&Flags[0]=Event&Events=[TrafficJunction]",
|
|
17631
|
+
timeout: 2e4,
|
|
17632
|
+
streaming: true
|
|
17633
|
+
});
|
|
17634
|
+
if ([400, 401, 403, 500].includes(response.statusCode)) {
|
|
17635
|
+
loggerDahua.error(`[${host}] Connection error: ${response.statusCode}`);
|
|
17636
|
+
throw new Error(`Failed to connect to ANPR: ${response.statusCode}`);
|
|
17637
|
+
}
|
|
17638
|
+
loggerDahua.info(`[${host}] Successfully connected to ANPR.`);
|
|
17639
|
+
const contentType = response.res.headers["content-type"];
|
|
17640
|
+
const boundaryMatch = contentType?.match(/boundary=(.*)$/i);
|
|
17641
|
+
const boundary = boundaryMatch ? `--${boundaryMatch[1]}` : "--myboundary";
|
|
17642
|
+
bufferQueue = useBufferQueue(
|
|
17643
|
+
boundary,
|
|
17644
|
+
site,
|
|
17645
|
+
gate,
|
|
17646
|
+
designation,
|
|
17647
|
+
host,
|
|
17648
|
+
username,
|
|
17649
|
+
password,
|
|
17650
|
+
onDetected
|
|
17651
|
+
);
|
|
17652
|
+
bufferQueue.setStream(response.res);
|
|
17653
|
+
await new Promise((resolve, reject) => {
|
|
17654
|
+
const onAbort = () => {
|
|
17655
|
+
loggerDahua.info(`[${site}]-[${host}] Abort triggered. Cleaning up...`);
|
|
17656
|
+
if (response.res && !response.res.destroyed) {
|
|
17657
|
+
response.res.destroy();
|
|
17658
|
+
}
|
|
17659
|
+
resolve("aborted");
|
|
17660
|
+
};
|
|
17661
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
17662
|
+
response.res.on("data", (chunk) => {
|
|
17663
|
+
if (signal.aborted) {
|
|
17664
|
+
response.res.destroy();
|
|
17665
|
+
return;
|
|
17666
|
+
}
|
|
17667
|
+
bufferQueue.enqueue(chunk);
|
|
17668
|
+
});
|
|
17669
|
+
response.res.on("end", () => {
|
|
17670
|
+
signal.removeEventListener("abort", onAbort);
|
|
17671
|
+
resolve("ended");
|
|
17672
|
+
});
|
|
17673
|
+
response.res.on("close", () => {
|
|
17674
|
+
signal.removeEventListener("abort", onAbort);
|
|
17675
|
+
resolve("closed");
|
|
17676
|
+
});
|
|
17677
|
+
response.res.on("error", (err) => {
|
|
17678
|
+
signal.removeEventListener("abort", onAbort);
|
|
17679
|
+
reject(err);
|
|
17680
|
+
});
|
|
17681
|
+
});
|
|
17682
|
+
} catch (error) {
|
|
17683
|
+
if (signal.aborted)
|
|
17684
|
+
break;
|
|
17685
|
+
loggerDahua.error(
|
|
17686
|
+
`[${host}] Connection lost or error: ${error.message || error}. Retrying in 5s...`
|
|
17687
|
+
);
|
|
17688
|
+
} finally {
|
|
17689
|
+
if (bufferQueue?.destroy)
|
|
17690
|
+
bufferQueue.destroy();
|
|
17691
|
+
if (response?.res && !response.res.destroyed)
|
|
17692
|
+
response.res.destroy();
|
|
17693
|
+
}
|
|
17694
|
+
if (!signal.aborted) {
|
|
17695
|
+
await new Promise((res) => setTimeout(res, 5e3));
|
|
17696
|
+
}
|
|
17556
17697
|
}
|
|
17698
|
+
loggerDahua.info(`[${host}] ANPR Listener stopped.`);
|
|
17557
17699
|
}
|
|
17558
17700
|
async function addPlateNumber(value) {
|
|
17559
17701
|
const validation = Joi40.object({
|
|
@@ -19929,7 +20071,9 @@ function useVehicleController() {
|
|
|
19929
20071
|
start: Joi46.string().isoDate().optional().allow(null, ""),
|
|
19930
20072
|
end: Joi46.string().isoDate().optional().allow(null, ""),
|
|
19931
20073
|
recNo: Joi46.string().optional().allow(null, ""),
|
|
19932
|
-
type: Joi46.string().optional().valid(...Object.values(VehicleType)).allow(null, "")
|
|
20074
|
+
type: Joi46.string().optional().valid(...Object.values(VehicleType)).allow(null, ""),
|
|
20075
|
+
peopleId: Joi46.string().hex().length(24).optional().allow(null, ""),
|
|
20076
|
+
seasonPassType: Joi46.string().optional().allow("", null)
|
|
19933
20077
|
});
|
|
19934
20078
|
const { error, value } = schema2.validate(
|
|
19935
20079
|
{
|
|
@@ -20166,7 +20310,7 @@ function useSiteCameraService() {
|
|
|
20166
20310
|
session.endSession();
|
|
20167
20311
|
}
|
|
20168
20312
|
}
|
|
20169
|
-
async function listenToCapturedPlateNumber() {
|
|
20313
|
+
async function listenToCapturedPlateNumber(onDetected) {
|
|
20170
20314
|
const siteCameras = [];
|
|
20171
20315
|
let page = 1;
|
|
20172
20316
|
let pages = 1;
|
|
@@ -20187,7 +20331,7 @@ function useSiteCameraService() {
|
|
|
20187
20331
|
for (let index = 0; index < siteCameras.length; index++) {
|
|
20188
20332
|
const siteCamera = siteCameras[index];
|
|
20189
20333
|
if (siteCamera && siteCamera.status === "active" && siteCamera.host && siteCamera.username && siteCamera.password && siteCamera.site && siteCamera.guardPost) {
|
|
20190
|
-
dahuaService.listenToCamera(siteCamera);
|
|
20334
|
+
dahuaService.listenToCamera(siteCamera, onDetected);
|
|
20191
20335
|
}
|
|
20192
20336
|
}
|
|
20193
20337
|
}
|
|
@@ -25356,11 +25500,7 @@ function usePatrolQuestionRepo() {
|
|
|
25356
25500
|
const { delNamespace, getCache, setCache } = useCache34(namespace_collection);
|
|
25357
25501
|
async function createIndexes() {
|
|
25358
25502
|
try {
|
|
25359
|
-
await collection.createIndexes([
|
|
25360
|
-
{
|
|
25361
|
-
key: { site: 1 }
|
|
25362
|
-
}
|
|
25363
|
-
]);
|
|
25503
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
25364
25504
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
25365
25505
|
} catch (error) {
|
|
25366
25506
|
logger87.log({
|
|
@@ -25805,6 +25945,24 @@ function usePatrolRouteRepo() {
|
|
|
25805
25945
|
const namespace_collection = "patrol.route";
|
|
25806
25946
|
const collection = db.collection(namespace_collection);
|
|
25807
25947
|
const { delNamespace, getCache, setCache } = useCache35(namespace_collection);
|
|
25948
|
+
async function createIndexes() {
|
|
25949
|
+
try {
|
|
25950
|
+
await collection.createIndexes([
|
|
25951
|
+
{ key: { site: 1, status: 1 } },
|
|
25952
|
+
{ key: { site: 1, repeat: 1 } },
|
|
25953
|
+
{ key: { assignee: 1 } }
|
|
25954
|
+
]);
|
|
25955
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
25956
|
+
} catch (error) {
|
|
25957
|
+
logger90.log({
|
|
25958
|
+
level: "error",
|
|
25959
|
+
message: error.message
|
|
25960
|
+
});
|
|
25961
|
+
throw new InternalServerError36(
|
|
25962
|
+
"Failed to create general indexes on patrol routes."
|
|
25963
|
+
);
|
|
25964
|
+
}
|
|
25965
|
+
}
|
|
25808
25966
|
async function createTextIndex() {
|
|
25809
25967
|
try {
|
|
25810
25968
|
await collection.createIndex({
|
|
@@ -26178,7 +26336,8 @@ function usePatrolRouteRepo() {
|
|
|
26178
26336
|
updateById,
|
|
26179
26337
|
deleteById,
|
|
26180
26338
|
getScheduledRoute,
|
|
26181
|
-
getById
|
|
26339
|
+
getById,
|
|
26340
|
+
createIndexes
|
|
26182
26341
|
};
|
|
26183
26342
|
}
|
|
26184
26343
|
|
|
@@ -26525,9 +26684,8 @@ function usePatrolLogRepo() {
|
|
|
26525
26684
|
async function createIndexes() {
|
|
26526
26685
|
try {
|
|
26527
26686
|
await collection.createIndexes([
|
|
26528
|
-
{
|
|
26529
|
-
|
|
26530
|
-
}
|
|
26687
|
+
{ key: { site: 1, createdAt: -1 } },
|
|
26688
|
+
{ key: { assignee: 1 } }
|
|
26531
26689
|
]);
|
|
26532
26690
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
26533
26691
|
} catch (error) {
|
|
@@ -30418,6 +30576,20 @@ function useSiteBillingItemRepo() {
|
|
|
30418
30576
|
const namespace_collection = "site.billing.items";
|
|
30419
30577
|
const collection = db.collection(namespace_collection);
|
|
30420
30578
|
const { delNamespace, setCache, getCache } = useCache42(namespace_collection);
|
|
30579
|
+
async function createIndexes() {
|
|
30580
|
+
try {
|
|
30581
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
30582
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
30583
|
+
} catch (error) {
|
|
30584
|
+
logger107.log({
|
|
30585
|
+
level: "error",
|
|
30586
|
+
message: error.message
|
|
30587
|
+
});
|
|
30588
|
+
throw new InternalServerError43(
|
|
30589
|
+
"Failed to create general indexes on billing item."
|
|
30590
|
+
);
|
|
30591
|
+
}
|
|
30592
|
+
}
|
|
30421
30593
|
async function createTextIndex() {
|
|
30422
30594
|
try {
|
|
30423
30595
|
await collection.createIndex({
|
|
@@ -30637,7 +30809,8 @@ function useSiteBillingItemRepo() {
|
|
|
30637
30809
|
getAll,
|
|
30638
30810
|
getById,
|
|
30639
30811
|
updateById,
|
|
30640
|
-
deleteById
|
|
30812
|
+
deleteById,
|
|
30813
|
+
createIndexes
|
|
30641
30814
|
};
|
|
30642
30815
|
}
|
|
30643
30816
|
|
|
@@ -30791,6 +30964,20 @@ function useSiteBillingConfigurationRepo() {
|
|
|
30791
30964
|
const namespace_collection = "site.billing.configuration";
|
|
30792
30965
|
const collection = db.collection(namespace_collection);
|
|
30793
30966
|
const { delNamespace, setCache, getCache } = useCache43(namespace_collection);
|
|
30967
|
+
async function createIndexes() {
|
|
30968
|
+
try {
|
|
30969
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
30970
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
30971
|
+
} catch (error) {
|
|
30972
|
+
logger109.log({
|
|
30973
|
+
level: "error",
|
|
30974
|
+
message: error.message
|
|
30975
|
+
});
|
|
30976
|
+
throw new InternalServerError44(
|
|
30977
|
+
"Failed to create general indexes on billing configuration."
|
|
30978
|
+
);
|
|
30979
|
+
}
|
|
30980
|
+
}
|
|
30794
30981
|
async function createTextIndex() {
|
|
30795
30982
|
try {
|
|
30796
30983
|
await collection.createIndex({
|
|
@@ -31000,7 +31187,8 @@ function useSiteBillingConfigurationRepo() {
|
|
|
31000
31187
|
getAll,
|
|
31001
31188
|
getById,
|
|
31002
31189
|
updateById,
|
|
31003
|
-
deleteById
|
|
31190
|
+
deleteById,
|
|
31191
|
+
createIndexes
|
|
31004
31192
|
};
|
|
31005
31193
|
}
|
|
31006
31194
|
|
|
@@ -32303,6 +32491,25 @@ function useSiteUnitBillingRepo() {
|
|
|
32303
32491
|
const namespace_collection = "site.unit.billing";
|
|
32304
32492
|
const collection = db.collection(namespace_collection);
|
|
32305
32493
|
const { delNamespace, setCache, getCache } = useCache45(namespace_collection);
|
|
32494
|
+
async function createIndexes() {
|
|
32495
|
+
try {
|
|
32496
|
+
await collection.createIndexes([
|
|
32497
|
+
{ key: { site: 1, status: 1, paymentStatus: 1 } },
|
|
32498
|
+
{ key: { site: 1, unitId: 1, status: 1, paymentStatus: 1 } },
|
|
32499
|
+
{ key: { site: 1, unitId: 1, issueDate: 1 } },
|
|
32500
|
+
{ key: { createdAt: -1 } }
|
|
32501
|
+
]);
|
|
32502
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
32503
|
+
} catch (error) {
|
|
32504
|
+
logger117.log({
|
|
32505
|
+
level: "error",
|
|
32506
|
+
message: error.message
|
|
32507
|
+
});
|
|
32508
|
+
throw new InternalServerError46(
|
|
32509
|
+
"Failed to create general indexes on unit billing."
|
|
32510
|
+
);
|
|
32511
|
+
}
|
|
32512
|
+
}
|
|
32306
32513
|
async function createTextIndex() {
|
|
32307
32514
|
try {
|
|
32308
32515
|
await collection.createIndex({
|
|
@@ -32856,7 +33063,8 @@ function useSiteUnitBillingRepo() {
|
|
|
32856
33063
|
deleteById,
|
|
32857
33064
|
getUnitBillingBySite,
|
|
32858
33065
|
getResidentUserBilling,
|
|
32859
|
-
getResidentUserUnsettledBilling
|
|
33066
|
+
getResidentUserUnsettledBilling,
|
|
33067
|
+
createIndexes
|
|
32860
33068
|
};
|
|
32861
33069
|
}
|
|
32862
33070
|
|
|
@@ -38714,6 +38922,22 @@ function useStatementOfAccountRepo() {
|
|
|
38714
38922
|
const namespace_collection = "site.statement-of-accounts";
|
|
38715
38923
|
const collection = db.collection(namespace_collection);
|
|
38716
38924
|
const { delNamespace, getCache, setCache } = useCache50(namespace_collection);
|
|
38925
|
+
async function createIndexes() {
|
|
38926
|
+
try {
|
|
38927
|
+
await collection.createIndexes([
|
|
38928
|
+
{ key: { site: 1, status: 1 } },
|
|
38929
|
+
{ key: { site: 1, unitId: 1, status: 1 } },
|
|
38930
|
+
{ key: { createdAt: -1 } }
|
|
38931
|
+
]);
|
|
38932
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
38933
|
+
} catch (error) {
|
|
38934
|
+
logger128.log({
|
|
38935
|
+
level: "error",
|
|
38936
|
+
message: error.message
|
|
38937
|
+
});
|
|
38938
|
+
throw new InternalServerError51("Failed to create general indexes on SOA.");
|
|
38939
|
+
}
|
|
38940
|
+
}
|
|
38717
38941
|
async function createTextIndex() {
|
|
38718
38942
|
try {
|
|
38719
38943
|
await collection.createIndex({
|
|
@@ -39064,7 +39288,8 @@ function useStatementOfAccountRepo() {
|
|
|
39064
39288
|
deleteById,
|
|
39065
39289
|
updateStatusById,
|
|
39066
39290
|
getResidentUserSoa,
|
|
39067
|
-
reviewSOA
|
|
39291
|
+
reviewSOA,
|
|
39292
|
+
createIndexes
|
|
39068
39293
|
};
|
|
39069
39294
|
}
|
|
39070
39295
|
|
|
@@ -42689,7 +42914,10 @@ function useOccurrenceEntryService() {
|
|
|
42689
42914
|
updateOccurrenceEntryById: _updateOccurrenceEntryById,
|
|
42690
42915
|
getOccurrenceEntryById: _getOccurrenceEntryById,
|
|
42691
42916
|
getOccurrenceEntryByBookId: _getOccurrenceEntryByBookId,
|
|
42692
|
-
updateOccurrenceEntryByBookId: _updateOccurrenceEntryByBookId
|
|
42917
|
+
updateOccurrenceEntryByBookId: _updateOccurrenceEntryByBookId,
|
|
42918
|
+
deleteOccurrenceEntryById: _deleteOccurrenceEntryById,
|
|
42919
|
+
getLatestSerialNumber: _getLatestSerialNumber,
|
|
42920
|
+
getLatestSerialNumberInGroup: _getLatestSerialNumberInGroup
|
|
42693
42921
|
} = useOccurrenceEntryRepo();
|
|
42694
42922
|
const {
|
|
42695
42923
|
getOccurrenceBookById: _getOccurrenceBookById,
|
|
@@ -42741,8 +42969,20 @@ function useOccurrenceEntryService() {
|
|
|
42741
42969
|
if (!occurrenceEntry) {
|
|
42742
42970
|
throw new Error("Occurrence entry not found.");
|
|
42743
42971
|
}
|
|
42744
|
-
const
|
|
42745
|
-
|
|
42972
|
+
const entryCount = await _getLatestSerialNumberInGroup(
|
|
42973
|
+
occurrenceEntry.dailyOccurrenceBookId,
|
|
42974
|
+
Number(occurrenceEntry.serialNumber)
|
|
42975
|
+
);
|
|
42976
|
+
const currentSerial = Number(occurrenceEntry.serialNumber);
|
|
42977
|
+
const latestSerial = Number(entryCount);
|
|
42978
|
+
const currentGroup = Math.floor(currentSerial);
|
|
42979
|
+
const latestGroup = Math.floor(latestSerial);
|
|
42980
|
+
let updatedSerialNumber;
|
|
42981
|
+
if (currentGroup === latestGroup) {
|
|
42982
|
+
updatedSerialNumber = (latestSerial + 0.1).toFixed(1);
|
|
42983
|
+
} else {
|
|
42984
|
+
updatedSerialNumber = (currentSerial + 0.1).toFixed(1);
|
|
42985
|
+
}
|
|
42746
42986
|
const dobId = occurrenceEntry.dailyOccurrenceBookId;
|
|
42747
42987
|
const book = await _getOccurrenceBookById(dobId);
|
|
42748
42988
|
const subject = await _getOccurrenceSubjectById(
|
|
@@ -45237,7 +45477,9 @@ function useManpowerMonitoringRepo() {
|
|
|
45237
45477
|
{
|
|
45238
45478
|
key: { siteId: 1 }
|
|
45239
45479
|
},
|
|
45240
|
-
{ key: { createdAt: 1 } }
|
|
45480
|
+
{ key: { createdAt: 1 } },
|
|
45481
|
+
{ key: { siteId: 1, serviceProviderId: 1 } },
|
|
45482
|
+
{ key: { siteName: 1 } }
|
|
45241
45483
|
]);
|
|
45242
45484
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45243
45485
|
} catch (error) {
|
|
@@ -45506,7 +45748,9 @@ function useManpowerRemarksRepo() {
|
|
|
45506
45748
|
{
|
|
45507
45749
|
key: { siteId: 1 }
|
|
45508
45750
|
},
|
|
45509
|
-
{ key: { createdAt: 1 } }
|
|
45751
|
+
{ key: { createdAt: 1 } },
|
|
45752
|
+
{ key: { siteId: 1, serviceProviderId: 1, createdAtSGT: 1 } },
|
|
45753
|
+
{ key: { serviceProviderId: 1, status: 1, createdAtSGT: 1 } }
|
|
45510
45754
|
]);
|
|
45511
45755
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45512
45756
|
} catch (error) {
|
|
@@ -45939,7 +46183,8 @@ function useManpowerDesignationRepo() {
|
|
|
45939
46183
|
{
|
|
45940
46184
|
key: { siteId: 1 }
|
|
45941
46185
|
},
|
|
45942
|
-
{ key: { createdAt: 1 } }
|
|
46186
|
+
{ key: { createdAt: 1 } },
|
|
46187
|
+
{ key: { siteId: 1, serviceProviderId: 1 } }
|
|
45943
46188
|
]);
|
|
45944
46189
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45945
46190
|
} catch (error) {
|
|
@@ -51458,6 +51703,7 @@ export {
|
|
|
51458
51703
|
vehicles_namespace_collection,
|
|
51459
51704
|
visitors_namespace_collection,
|
|
51460
51705
|
workOrderSchema,
|
|
51706
|
+
work_orders2_namespace_collection,
|
|
51461
51707
|
work_orders_namespace_collection
|
|
51462
51708
|
};
|
|
51463
51709
|
//# sourceMappingURL=index.mjs.map
|