@7365admin1/core 2.48.0 → 2.50.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 +12 -0
- package/dist/index.d.ts +21 -8
- package/dist/index.js +429 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +428 -81
- 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");
|
|
@@ -14016,14 +14045,14 @@ function useVisitorTransactionRepo() {
|
|
|
14016
14045
|
);
|
|
14017
14046
|
}
|
|
14018
14047
|
}
|
|
14019
|
-
async function updateById(_id, value, session) {
|
|
14048
|
+
async function updateById(_id, value, session, isNotManualCheckOut = true) {
|
|
14020
14049
|
try {
|
|
14021
14050
|
_id = new import_mongodb40.ObjectId(_id);
|
|
14022
14051
|
} catch (error) {
|
|
14023
14052
|
throw new import_node_server_utils68.BadRequestError("Invalid visitor transaction ID format.");
|
|
14024
14053
|
}
|
|
14025
14054
|
value.updatedAt = /* @__PURE__ */ new Date();
|
|
14026
|
-
if (value.checkOut) {
|
|
14055
|
+
if (value.checkOut && isNotManualCheckOut) {
|
|
14027
14056
|
value.manualCheckout = true;
|
|
14028
14057
|
}
|
|
14029
14058
|
try {
|
|
@@ -14774,6 +14803,22 @@ function useVehicleRepo() {
|
|
|
14774
14803
|
throw error;
|
|
14775
14804
|
}
|
|
14776
14805
|
}
|
|
14806
|
+
async function getSpecificVehicleById(_id) {
|
|
14807
|
+
try {
|
|
14808
|
+
_id = new import_mongodb42.ObjectId(_id);
|
|
14809
|
+
} catch (error) {
|
|
14810
|
+
throw new import_node_server_utils70.BadRequestError("Invalid vehicle ID format.");
|
|
14811
|
+
}
|
|
14812
|
+
try {
|
|
14813
|
+
const result = await collection.findOne({ _id });
|
|
14814
|
+
if (!result) {
|
|
14815
|
+
throw new import_node_server_utils70.NotFoundError("Vehicle not found.");
|
|
14816
|
+
}
|
|
14817
|
+
return result;
|
|
14818
|
+
} catch (error) {
|
|
14819
|
+
throw error;
|
|
14820
|
+
}
|
|
14821
|
+
}
|
|
14777
14822
|
async function getByPlaceNumber(value) {
|
|
14778
14823
|
const { error } = import_joi38.default.string().required().validate(value);
|
|
14779
14824
|
if (error) {
|
|
@@ -15032,7 +15077,8 @@ function useVehicleRepo() {
|
|
|
15032
15077
|
deleteExpiredVehicles,
|
|
15033
15078
|
getAllVehiclesByUnitId,
|
|
15034
15079
|
getAllExpiredVehicles,
|
|
15035
|
-
bulkUpsertVehicles
|
|
15080
|
+
bulkUpsertVehicles,
|
|
15081
|
+
getSpecificVehicleById
|
|
15036
15082
|
};
|
|
15037
15083
|
}
|
|
15038
15084
|
|
|
@@ -15056,7 +15102,11 @@ function usePersonRepo() {
|
|
|
15056
15102
|
try {
|
|
15057
15103
|
await collection.createIndexes([
|
|
15058
15104
|
{ key: { contact: 1 } },
|
|
15059
|
-
{ key: { nric: 1 } }
|
|
15105
|
+
{ key: { nric: 1 } },
|
|
15106
|
+
{ key: { user: 1 } },
|
|
15107
|
+
{ key: { site: 1, status: 1 } },
|
|
15108
|
+
{ key: { "plates.plateNumber": 1, status: 1 } },
|
|
15109
|
+
{ key: { unit: 1, status: 1 } }
|
|
15060
15110
|
]);
|
|
15061
15111
|
} catch (error) {
|
|
15062
15112
|
throw new import_node_server_utils71.InternalServerError("Failed to create index on site people.");
|
|
@@ -17024,6 +17074,9 @@ function useVehicleService() {
|
|
|
17024
17074
|
const _end = vehicle.end;
|
|
17025
17075
|
const _recNo = plate.recNo;
|
|
17026
17076
|
const _type = value.type ? value.type : plate.type;
|
|
17077
|
+
if (value.peopleId) {
|
|
17078
|
+
value.peopleId = new import_mongodb46.ObjectId(value.peopleId);
|
|
17079
|
+
}
|
|
17027
17080
|
const { name, plateNumber, start, end, recNo, type, unit, site, ...rest } = value;
|
|
17028
17081
|
const startDahua = value.start ? formatDahuaDate(new Date(value.start)) : formatDahuaDate(new Date(_start));
|
|
17029
17082
|
const endDahua = value.end ? formatDahuaDate(new Date(value.end)) : formatDahuaDate(new Date(_end));
|
|
@@ -17087,6 +17140,17 @@ function useVehicleService() {
|
|
|
17087
17140
|
}
|
|
17088
17141
|
const responseData = dahuaResponse?.data?.toString("utf-8") ?? "";
|
|
17089
17142
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
17143
|
+
const normalizedPlateNumber = Array.isArray(plateNumber) ? plateNumber[0] : plateNumber;
|
|
17144
|
+
if (value.peopleId && value.recNo) {
|
|
17145
|
+
await _pushVehicleById(
|
|
17146
|
+
value.peopleId,
|
|
17147
|
+
{
|
|
17148
|
+
plateNumber: normalizedPlateNumber,
|
|
17149
|
+
recNo: value.recNo
|
|
17150
|
+
},
|
|
17151
|
+
session
|
|
17152
|
+
);
|
|
17153
|
+
}
|
|
17090
17154
|
} else {
|
|
17091
17155
|
const dahuaPayload = {
|
|
17092
17156
|
host,
|
|
@@ -17100,6 +17164,17 @@ function useVehicleService() {
|
|
|
17100
17164
|
owner: name ? name : _name
|
|
17101
17165
|
};
|
|
17102
17166
|
const dahuaResponse = await _updatePlateNumber(dahuaPayload);
|
|
17167
|
+
const normalizedPlateNumber = Array.isArray(plateNumber) ? plateNumber[0] : plateNumber;
|
|
17168
|
+
if (value.peopleId && value.recNo) {
|
|
17169
|
+
await _pushVehicleById(
|
|
17170
|
+
value.peopleId,
|
|
17171
|
+
{
|
|
17172
|
+
plateNumber: normalizedPlateNumber,
|
|
17173
|
+
recNo: _recNo
|
|
17174
|
+
},
|
|
17175
|
+
session
|
|
17176
|
+
);
|
|
17177
|
+
}
|
|
17103
17178
|
if (dahuaResponse?.statusCode !== 200) {
|
|
17104
17179
|
throw new import_node_server_utils74.BadRequestError(
|
|
17105
17180
|
"Failed to update plate number to ANPR"
|
|
@@ -17259,6 +17334,7 @@ var loggerDahua = winston.createLogger({
|
|
|
17259
17334
|
|
|
17260
17335
|
// src/services/dahua.service.ts
|
|
17261
17336
|
var cameraRegistry = /* @__PURE__ */ new Map();
|
|
17337
|
+
var _savedOnDetected;
|
|
17262
17338
|
function useDahuaDigest({
|
|
17263
17339
|
host = "",
|
|
17264
17340
|
username = "",
|
|
@@ -17294,7 +17370,7 @@ function useDahuaService() {
|
|
|
17294
17370
|
const { createFile: _createFile } = useFileService();
|
|
17295
17371
|
let currentTransactionId = null;
|
|
17296
17372
|
let currentSnapshotField = null;
|
|
17297
|
-
function useBufferQueue(boundary, site, gate, designation, host, username, password) {
|
|
17373
|
+
function useBufferQueue(boundary, site, gate, designation, host, username, password, onDetected) {
|
|
17298
17374
|
const queue = [];
|
|
17299
17375
|
let processing = false;
|
|
17300
17376
|
let plateNumber = null;
|
|
@@ -17323,11 +17399,11 @@ function useDahuaService() {
|
|
|
17323
17399
|
queue.push(buffer);
|
|
17324
17400
|
if (queue.length >= BACKPRESSURE_THRESHOLD && streamRef && !streamRef.isPaused()) {
|
|
17325
17401
|
loggerDahua.warn(
|
|
17326
|
-
`[${site}][${
|
|
17402
|
+
`[${site}][${host}] Queue at ${queue.length}/${MAX_QUEUE_SIZE}, pausing stream`
|
|
17327
17403
|
);
|
|
17328
17404
|
streamRef.pause();
|
|
17329
17405
|
}
|
|
17330
|
-
processNext();
|
|
17406
|
+
processNext(onDetected);
|
|
17331
17407
|
}
|
|
17332
17408
|
function destroy() {
|
|
17333
17409
|
queue.length = 0;
|
|
@@ -17340,33 +17416,33 @@ function useDahuaService() {
|
|
|
17340
17416
|
streamRef.resume();
|
|
17341
17417
|
}
|
|
17342
17418
|
loggerDahua.info(
|
|
17343
|
-
`[${site}][${
|
|
17419
|
+
`[${site}][${host}] BufferQueue destroyed. Processed=${processedChunks}, Dropped=${droppedChunks}`
|
|
17344
17420
|
);
|
|
17345
17421
|
}
|
|
17346
|
-
async function processNext() {
|
|
17422
|
+
async function processNext(onDetected2) {
|
|
17347
17423
|
if (processing || queue.length === 0)
|
|
17348
17424
|
return;
|
|
17349
17425
|
processing = true;
|
|
17350
17426
|
const buffer = queue.shift();
|
|
17351
17427
|
try {
|
|
17352
|
-
await handleBuffer(buffer);
|
|
17428
|
+
await handleBuffer(buffer, onDetected2);
|
|
17353
17429
|
processedChunks++;
|
|
17354
17430
|
if (queue.length <= RESUME_THRESHOLD && streamRef && streamRef.isPaused()) {
|
|
17355
17431
|
loggerDahua.info(
|
|
17356
|
-
`[${
|
|
17432
|
+
`[${host}]Queue at ${queue.length}/${MAX_QUEUE_SIZE}, resuming stream`
|
|
17357
17433
|
);
|
|
17358
17434
|
streamRef.resume();
|
|
17359
17435
|
}
|
|
17360
17436
|
} catch (err) {
|
|
17361
|
-
loggerDahua.error(`[${
|
|
17437
|
+
loggerDahua.error(`[${host}] Error processing buffer:`, err);
|
|
17362
17438
|
} finally {
|
|
17363
17439
|
processing = false;
|
|
17364
|
-
processNext();
|
|
17440
|
+
processNext(onDetected2);
|
|
17365
17441
|
}
|
|
17366
17442
|
}
|
|
17367
|
-
async function processVehicleTransaction() {
|
|
17443
|
+
async function processVehicleTransaction(onDetected2) {
|
|
17368
17444
|
loggerDahua.info(
|
|
17369
|
-
`[${
|
|
17445
|
+
`[${host}] Vehicle transaction: Plate=${plateNumber}, UTC=${UTCData}, UTCMs=${UTCMs}`
|
|
17370
17446
|
);
|
|
17371
17447
|
let org = "";
|
|
17372
17448
|
try {
|
|
@@ -17374,7 +17450,7 @@ function useDahuaService() {
|
|
|
17374
17450
|
org = theSite?.orgId.toString() || "unknown";
|
|
17375
17451
|
} catch (error) {
|
|
17376
17452
|
loggerDahua.error(
|
|
17377
|
-
`[${
|
|
17453
|
+
`[${host}] Error fetching site for orgId:`,
|
|
17378
17454
|
error
|
|
17379
17455
|
);
|
|
17380
17456
|
}
|
|
@@ -17388,13 +17464,13 @@ function useDahuaService() {
|
|
|
17388
17464
|
const transactionId = existingOpenTransaction?._id?.toString() || "";
|
|
17389
17465
|
if (existingOpenTransaction && !existingOpenTransaction.checkOut && transactionId) {
|
|
17390
17466
|
await updateById(transactionId, {
|
|
17391
|
-
checkOut:
|
|
17392
|
-
updatedAt:
|
|
17393
|
-
});
|
|
17467
|
+
checkOut: /* @__PURE__ */ new Date(),
|
|
17468
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
17469
|
+
}, void 0, false);
|
|
17394
17470
|
}
|
|
17395
17471
|
} catch (error) {
|
|
17396
17472
|
loggerDahua.error(
|
|
17397
|
-
`[${
|
|
17473
|
+
`[${host}] Error closing existing open transaction:`,
|
|
17398
17474
|
error
|
|
17399
17475
|
);
|
|
17400
17476
|
}
|
|
@@ -17444,9 +17520,13 @@ function useDahuaService() {
|
|
|
17444
17520
|
}
|
|
17445
17521
|
try {
|
|
17446
17522
|
await addPlateNumber(dahuaPayload);
|
|
17447
|
-
const
|
|
17448
|
-
|
|
17523
|
+
const result = await add(visitorTransaction, void 0, true);
|
|
17524
|
+
const transactionId = result?._id;
|
|
17525
|
+
currentTransactionId = transactionId?.toString();
|
|
17449
17526
|
currentSnapshotField = "snapshotEntryImage";
|
|
17527
|
+
if (onDetected2) {
|
|
17528
|
+
onDetected2({ _id: transactionId, site: result?.site?.toString(), plateNumber: result.plateNumber, host, direction });
|
|
17529
|
+
}
|
|
17450
17530
|
} catch (error) {
|
|
17451
17531
|
console.log("failed to create visitor transaction", error);
|
|
17452
17532
|
loggerDahua.error(
|
|
@@ -17454,8 +17534,7 @@ function useDahuaService() {
|
|
|
17454
17534
|
error
|
|
17455
17535
|
);
|
|
17456
17536
|
}
|
|
17457
|
-
}
|
|
17458
|
-
if (["exit", "both"].includes(designation) && direction.toLowerCase() === "leave" && plateNumber) {
|
|
17537
|
+
} else if (["exit", "both"].includes(designation) && direction.toLowerCase() === "leave" && plateNumber) {
|
|
17459
17538
|
const vehicle = await getVehicleByPlateNumber(plateNumber);
|
|
17460
17539
|
const existingOpenTransaction = await getOpenByPlateNumber(
|
|
17461
17540
|
plateNumber,
|
|
@@ -17477,10 +17556,13 @@ function useDahuaService() {
|
|
|
17477
17556
|
await removePlateNumber(dahuaPayload);
|
|
17478
17557
|
}
|
|
17479
17558
|
await closeOpenTransaction(plateNumber);
|
|
17559
|
+
if (onDetected2) {
|
|
17560
|
+
onDetected2({ reload: true, site: existingOpenTransaction?.site?.toString(), host, direction });
|
|
17561
|
+
}
|
|
17480
17562
|
}
|
|
17481
17563
|
}
|
|
17482
17564
|
}
|
|
17483
|
-
async function handleBuffer(chunk) {
|
|
17565
|
+
async function handleBuffer(chunk, onDetected2) {
|
|
17484
17566
|
partialBuffer = Buffer.concat([partialBuffer, chunk]);
|
|
17485
17567
|
while (true) {
|
|
17486
17568
|
const boundaryIndex = partialBuffer.indexOf(Buffer.from(boundary));
|
|
@@ -17506,7 +17588,7 @@ function useDahuaService() {
|
|
|
17506
17588
|
direction = line.split("=")[1].trim();
|
|
17507
17589
|
});
|
|
17508
17590
|
if (plateNumber && UTCData) {
|
|
17509
|
-
await processVehicleTransaction();
|
|
17591
|
+
await processVehicleTransaction(onDetected2);
|
|
17510
17592
|
}
|
|
17511
17593
|
} else if (part.includes("Content-Type: image/jpeg")) {
|
|
17512
17594
|
const [headers, ...imageParts] = part.split("\r\n\r\n");
|
|
@@ -17533,7 +17615,7 @@ function useDahuaService() {
|
|
|
17533
17615
|
try {
|
|
17534
17616
|
await import_fs.promises.mkdir(dir, { recursive: true });
|
|
17535
17617
|
await import_fs.promises.writeFile(snapFolder, accumulatedImageBuffer);
|
|
17536
|
-
loggerDahua.
|
|
17618
|
+
loggerDahua.info(`[${host}] Saved image locally: ${filename}`);
|
|
17537
17619
|
const fileId = await _createFile(
|
|
17538
17620
|
{
|
|
17539
17621
|
originalname: filename,
|
|
@@ -17543,7 +17625,7 @@ function useDahuaService() {
|
|
|
17543
17625
|
`anpr/${site}`
|
|
17544
17626
|
);
|
|
17545
17627
|
loggerDahua.info(
|
|
17546
|
-
`[${
|
|
17628
|
+
`[${host}] Created file record for image: ${fileId.toString()}`
|
|
17547
17629
|
);
|
|
17548
17630
|
if (currentTransactionId && currentSnapshotField) {
|
|
17549
17631
|
await updateById(currentTransactionId, {
|
|
@@ -17551,23 +17633,23 @@ function useDahuaService() {
|
|
|
17551
17633
|
});
|
|
17552
17634
|
}
|
|
17553
17635
|
loggerDahua.info(
|
|
17554
|
-
`[${
|
|
17636
|
+
`[${host}] Image stored with fileId: ${fileId.toString()}`
|
|
17555
17637
|
);
|
|
17556
17638
|
await import_fs.promises.unlink(snapFolder);
|
|
17557
|
-
loggerDahua.
|
|
17639
|
+
loggerDahua.info(`[${host}] Deleted local file: ${filename}`);
|
|
17558
17640
|
} catch (err) {
|
|
17559
17641
|
loggerDahua.error(
|
|
17560
|
-
`[${
|
|
17642
|
+
`[${host}] Failed to process image ${filename}:`,
|
|
17561
17643
|
err
|
|
17562
17644
|
);
|
|
17563
17645
|
try {
|
|
17564
17646
|
await import_fs.promises.unlink(snapFolder);
|
|
17565
|
-
loggerDahua.
|
|
17566
|
-
`[${
|
|
17647
|
+
loggerDahua.error(
|
|
17648
|
+
`[${host}] Cleaned up local file after error: ${filename}`
|
|
17567
17649
|
);
|
|
17568
17650
|
} catch (unlinkErr) {
|
|
17569
17651
|
loggerDahua.error(
|
|
17570
|
-
`[${
|
|
17652
|
+
`[${host}] Failed to clean up local file: ${filename}`,
|
|
17571
17653
|
unlinkErr
|
|
17572
17654
|
);
|
|
17573
17655
|
}
|
|
@@ -17607,10 +17689,13 @@ function useDahuaService() {
|
|
|
17607
17689
|
throw error;
|
|
17608
17690
|
}
|
|
17609
17691
|
}
|
|
17610
|
-
async function listenToCamera(camera) {
|
|
17692
|
+
async function listenToCamera(camera, onDetected) {
|
|
17693
|
+
if (onDetected) {
|
|
17694
|
+
_savedOnDetected = onDetected;
|
|
17695
|
+
}
|
|
17611
17696
|
if (!camera?._id) {
|
|
17612
17697
|
loggerDahua.error(`Camera _id is required to listen to camera.`);
|
|
17613
|
-
|
|
17698
|
+
return;
|
|
17614
17699
|
}
|
|
17615
17700
|
const cameraId = camera._id.toString();
|
|
17616
17701
|
if (cameraRegistry.has(cameraId)) {
|
|
@@ -17620,6 +17705,11 @@ function useDahuaService() {
|
|
|
17620
17705
|
}
|
|
17621
17706
|
const controller = new AbortController();
|
|
17622
17707
|
cameraRegistry.set(cameraId, controller);
|
|
17708
|
+
const onDetectedHandler = onDetected || _savedOnDetected;
|
|
17709
|
+
if (!onDetectedHandler) {
|
|
17710
|
+
loggerDahua.error(`No plate detection handler registered for camera ${cameraId}`);
|
|
17711
|
+
return;
|
|
17712
|
+
}
|
|
17623
17713
|
getTrafficJunction(
|
|
17624
17714
|
camera.host,
|
|
17625
17715
|
camera.username,
|
|
@@ -17628,10 +17718,11 @@ function useDahuaService() {
|
|
|
17628
17718
|
`guard-post-${camera.guardPost}`,
|
|
17629
17719
|
camera.direction,
|
|
17630
17720
|
cameraId,
|
|
17631
|
-
controller.signal
|
|
17721
|
+
controller.signal,
|
|
17722
|
+
onDetectedHandler
|
|
17632
17723
|
);
|
|
17633
17724
|
}
|
|
17634
|
-
async function
|
|
17725
|
+
async function getTrafficJunctionOld(host = "", username = "", password = "", site = "", gate = "", designation = "", cameraId, signal, onDetected) {
|
|
17635
17726
|
if (signal.aborted)
|
|
17636
17727
|
return;
|
|
17637
17728
|
try {
|
|
@@ -17654,7 +17745,8 @@ function useDahuaService() {
|
|
|
17654
17745
|
designation,
|
|
17655
17746
|
host,
|
|
17656
17747
|
username,
|
|
17657
|
-
password
|
|
17748
|
+
password,
|
|
17749
|
+
onDetected
|
|
17658
17750
|
);
|
|
17659
17751
|
bufferQueue.setStream(response.res);
|
|
17660
17752
|
const onAbort = () => {
|
|
@@ -17708,7 +17800,7 @@ function useDahuaService() {
|
|
|
17708
17800
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17709
17801
|
if (signal.aborted)
|
|
17710
17802
|
return;
|
|
17711
|
-
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17803
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal, onDetected);
|
|
17712
17804
|
};
|
|
17713
17805
|
response.res.on(
|
|
17714
17806
|
"end",
|
|
@@ -17732,9 +17824,106 @@ function useDahuaService() {
|
|
|
17732
17824
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17733
17825
|
if (signal.aborted)
|
|
17734
17826
|
return;
|
|
17735
|
-
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17827
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal, onDetected);
|
|
17736
17828
|
}
|
|
17737
17829
|
}
|
|
17830
|
+
async function getTrafficJunction(host = "", username = "", password = "", site = "", gate = "", designation = "", cameraId, signal, onDetected) {
|
|
17831
|
+
while (!signal.aborted) {
|
|
17832
|
+
let bufferQueue = null;
|
|
17833
|
+
let response = null;
|
|
17834
|
+
try {
|
|
17835
|
+
response = await useDahuaDigest({
|
|
17836
|
+
host,
|
|
17837
|
+
username,
|
|
17838
|
+
password,
|
|
17839
|
+
endpoint: "/cgi-bin/snapManager.cgi?action=attachFileProc&channel=1&heartbeat=5&Flags[0]=Event&Events=[TrafficJunction]",
|
|
17840
|
+
timeout: 2e4,
|
|
17841
|
+
streaming: true
|
|
17842
|
+
});
|
|
17843
|
+
if (response.statusCode === 401) {
|
|
17844
|
+
loggerDahua.error(`[${host}] 401 Unauthorized. Potential handshake or wrong credentials.`);
|
|
17845
|
+
continue;
|
|
17846
|
+
} else if ([400, 401, 403, 500].includes(response.statusCode)) {
|
|
17847
|
+
loggerDahua.error(`[${host}] Connection error: ${response.statusCode}`);
|
|
17848
|
+
return;
|
|
17849
|
+
}
|
|
17850
|
+
loggerDahua.info(`[${host}] Successfully connected to ANPR.`);
|
|
17851
|
+
const contentType = response.res.headers["content-type"];
|
|
17852
|
+
const boundaryMatch = contentType?.match(/boundary=(.*)$/i);
|
|
17853
|
+
const boundary = boundaryMatch ? `--${boundaryMatch[1]}` : "--myboundary";
|
|
17854
|
+
bufferQueue = useBufferQueue(
|
|
17855
|
+
boundary,
|
|
17856
|
+
site,
|
|
17857
|
+
gate,
|
|
17858
|
+
designation,
|
|
17859
|
+
host,
|
|
17860
|
+
username,
|
|
17861
|
+
password,
|
|
17862
|
+
onDetected
|
|
17863
|
+
);
|
|
17864
|
+
bufferQueue.setStream(response.res);
|
|
17865
|
+
await new Promise((resolve, reject) => {
|
|
17866
|
+
const onAbort = () => {
|
|
17867
|
+
loggerDahua.info(`[${site}]-[${host}] Abort triggered. Cleaning up...`);
|
|
17868
|
+
if (response.res && !response.res.destroyed) {
|
|
17869
|
+
response.res.destroy();
|
|
17870
|
+
}
|
|
17871
|
+
resolve("aborted");
|
|
17872
|
+
};
|
|
17873
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
17874
|
+
response.res.on("data", (chunk) => {
|
|
17875
|
+
if (signal.aborted) {
|
|
17876
|
+
response.res.destroy();
|
|
17877
|
+
return;
|
|
17878
|
+
}
|
|
17879
|
+
bufferQueue.enqueue(chunk);
|
|
17880
|
+
});
|
|
17881
|
+
response.res.on("end", () => {
|
|
17882
|
+
signal.removeEventListener("abort", onAbort);
|
|
17883
|
+
resolve("ended");
|
|
17884
|
+
});
|
|
17885
|
+
response.res.on("close", () => {
|
|
17886
|
+
signal.removeEventListener("abort", onAbort);
|
|
17887
|
+
resolve("closed");
|
|
17888
|
+
});
|
|
17889
|
+
response.res.on("error", (err) => {
|
|
17890
|
+
signal.removeEventListener("abort", onAbort);
|
|
17891
|
+
reject(err);
|
|
17892
|
+
});
|
|
17893
|
+
});
|
|
17894
|
+
} catch (error) {
|
|
17895
|
+
if (signal.aborted || error.name === "AbortError" || error.code === "UND_ERR_ABORTED") {
|
|
17896
|
+
loggerDahua.info(`[${host}] Connection closed by system (Abort).`);
|
|
17897
|
+
break;
|
|
17898
|
+
}
|
|
17899
|
+
loggerDahua.error(
|
|
17900
|
+
`[${host}] Connection lost or error: ${error.message || error}. Retrying in 5s...`
|
|
17901
|
+
);
|
|
17902
|
+
} finally {
|
|
17903
|
+
if (bufferQueue?.destroy) {
|
|
17904
|
+
try {
|
|
17905
|
+
bufferQueue.destroy();
|
|
17906
|
+
} catch (e) {
|
|
17907
|
+
loggerDahua.error(`[${host}] Error destroying buffer queue:`, e);
|
|
17908
|
+
}
|
|
17909
|
+
}
|
|
17910
|
+
if (response?.res && typeof response.res.destroy === "function" && !response.res.destroyed) {
|
|
17911
|
+
try {
|
|
17912
|
+
response.res.on("error", () => {
|
|
17913
|
+
loggerDahua.error(`[${host}] Stream error during cleanup, likely already closed.`);
|
|
17914
|
+
});
|
|
17915
|
+
response.res.destroy();
|
|
17916
|
+
} catch (err) {
|
|
17917
|
+
loggerDahua.debug(`Cleanup: stream already closing: ${err?.message}`);
|
|
17918
|
+
}
|
|
17919
|
+
}
|
|
17920
|
+
}
|
|
17921
|
+
if (!signal.aborted) {
|
|
17922
|
+
await new Promise((res) => setTimeout(res, 5e3));
|
|
17923
|
+
}
|
|
17924
|
+
}
|
|
17925
|
+
loggerDahua.info(`[${host}] ANPR Listener stopped.`);
|
|
17926
|
+
}
|
|
17738
17927
|
async function addPlateNumber(value) {
|
|
17739
17928
|
const validation = import_joi40.default.object({
|
|
17740
17929
|
host: import_joi40.default.string().required(),
|
|
@@ -17943,6 +18132,8 @@ function useSiteCameraRepo() {
|
|
|
17943
18132
|
try {
|
|
17944
18133
|
value = MSiteCamera(value);
|
|
17945
18134
|
const res = await collection.insertOne(value, { session });
|
|
18135
|
+
const { listenToCamera } = useDahuaService();
|
|
18136
|
+
await listenToCamera({ ...value, _id: res.insertedId });
|
|
17946
18137
|
delCachedData();
|
|
17947
18138
|
return res.insertedId;
|
|
17948
18139
|
} catch (error) {
|
|
@@ -19774,7 +19965,8 @@ function useVehicleController() {
|
|
|
19774
19965
|
getVehicles: _getVehicles,
|
|
19775
19966
|
getVehicleById: _getVehicleById,
|
|
19776
19967
|
getVehiclesByNRIC: _getVehiclesByNRIC,
|
|
19777
|
-
getAllVehiclesByUnitId: _getAllVehiclesByUnitId
|
|
19968
|
+
getAllVehiclesByUnitId: _getAllVehiclesByUnitId,
|
|
19969
|
+
getSpecificVehicleById: _getSpecificVehicleById
|
|
19778
19970
|
} = useVehicleRepo();
|
|
19779
19971
|
function normalizeRow(row) {
|
|
19780
19972
|
return Object.fromEntries(
|
|
@@ -19888,7 +20080,9 @@ function useVehicleController() {
|
|
|
19888
20080
|
return;
|
|
19889
20081
|
}
|
|
19890
20082
|
const headerRow = worksheet.getRow(1);
|
|
19891
|
-
const headers = (headerRow.values || []).slice(1).map(
|
|
20083
|
+
const headers = (headerRow.values || []).slice(1).map(
|
|
20084
|
+
(header) => String(header ?? "").trim().replace(/\(.*\)/, "").trim()
|
|
20085
|
+
);
|
|
19892
20086
|
worksheet.eachRow((row, rowNumber) => {
|
|
19893
20087
|
if (rowNumber === 1)
|
|
19894
20088
|
return;
|
|
@@ -19905,7 +20099,11 @@ function useVehicleController() {
|
|
|
19905
20099
|
} else if (lowerName.endsWith(".csv")) {
|
|
19906
20100
|
rows = await new Promise((resolve, reject) => {
|
|
19907
20101
|
const parsed = [];
|
|
19908
|
-
import_fs2.default.createReadStream(path4).pipe((0, import_csv_parser.default)()).on("
|
|
20102
|
+
import_fs2.default.createReadStream(path4).pipe((0, import_csv_parser.default)()).on("headers", (headers) => {
|
|
20103
|
+
headers = headers.map(
|
|
20104
|
+
(h) => h.trim().replace(/\(.*\)/, "").trim()
|
|
20105
|
+
);
|
|
20106
|
+
}).on("data", (row) => parsed.push(row)).on("end", () => resolve(parsed)).on("error", reject);
|
|
19909
20107
|
});
|
|
19910
20108
|
} else {
|
|
19911
20109
|
next(
|
|
@@ -20070,6 +20268,31 @@ function useVehicleController() {
|
|
|
20070
20268
|
return;
|
|
20071
20269
|
}
|
|
20072
20270
|
}
|
|
20271
|
+
async function getSpecificVehicleById(req, res, next) {
|
|
20272
|
+
const schema2 = import_joi46.default.object({
|
|
20273
|
+
_id: import_joi46.default.string().hex().length(24).required()
|
|
20274
|
+
});
|
|
20275
|
+
const { error, value } = schema2.validate(
|
|
20276
|
+
{ _id: req.params.id },
|
|
20277
|
+
{ abortEarly: false }
|
|
20278
|
+
);
|
|
20279
|
+
if (error) {
|
|
20280
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
20281
|
+
import_node_server_utils87.logger.log({ level: "error", message: messages });
|
|
20282
|
+
next(new import_node_server_utils87.BadRequestError(messages));
|
|
20283
|
+
return;
|
|
20284
|
+
}
|
|
20285
|
+
const { _id } = value;
|
|
20286
|
+
try {
|
|
20287
|
+
const site = await _getSpecificVehicleById(_id);
|
|
20288
|
+
res.json(site);
|
|
20289
|
+
return;
|
|
20290
|
+
} catch (error2) {
|
|
20291
|
+
import_node_server_utils87.logger.log({ level: "error", message: error2.message });
|
|
20292
|
+
next(error2);
|
|
20293
|
+
return;
|
|
20294
|
+
}
|
|
20295
|
+
}
|
|
20073
20296
|
async function updateVehicleById(req, res, next) {
|
|
20074
20297
|
try {
|
|
20075
20298
|
const schema2 = import_joi46.default.object({
|
|
@@ -20085,7 +20308,9 @@ function useVehicleController() {
|
|
|
20085
20308
|
start: import_joi46.default.string().isoDate().optional().allow(null, ""),
|
|
20086
20309
|
end: import_joi46.default.string().isoDate().optional().allow(null, ""),
|
|
20087
20310
|
recNo: import_joi46.default.string().optional().allow(null, ""),
|
|
20088
|
-
type: import_joi46.default.string().optional().valid(...Object.values(VehicleType)).allow(null, "")
|
|
20311
|
+
type: import_joi46.default.string().optional().valid(...Object.values(VehicleType)).allow(null, ""),
|
|
20312
|
+
peopleId: import_joi46.default.string().hex().length(24).optional().allow(null, ""),
|
|
20313
|
+
seasonPassType: import_joi46.default.string().optional().allow("", null)
|
|
20089
20314
|
});
|
|
20090
20315
|
const { error, value } = schema2.validate(
|
|
20091
20316
|
{
|
|
@@ -20287,7 +20512,8 @@ function useVehicleController() {
|
|
|
20287
20512
|
getVehiclesByNRIC,
|
|
20288
20513
|
reactivateVehicleById,
|
|
20289
20514
|
getAllVehiclesByUnitId,
|
|
20290
|
-
uploadSpreadsheetVehicles
|
|
20515
|
+
uploadSpreadsheetVehicles,
|
|
20516
|
+
getSpecificVehicleById
|
|
20291
20517
|
};
|
|
20292
20518
|
}
|
|
20293
20519
|
|
|
@@ -20319,7 +20545,7 @@ function useSiteCameraService() {
|
|
|
20319
20545
|
session.endSession();
|
|
20320
20546
|
}
|
|
20321
20547
|
}
|
|
20322
|
-
async function listenToCapturedPlateNumber() {
|
|
20548
|
+
async function listenToCapturedPlateNumber(onDetected) {
|
|
20323
20549
|
const siteCameras = [];
|
|
20324
20550
|
let page = 1;
|
|
20325
20551
|
let pages = 1;
|
|
@@ -20340,7 +20566,7 @@ function useSiteCameraService() {
|
|
|
20340
20566
|
for (let index = 0; index < siteCameras.length; index++) {
|
|
20341
20567
|
const siteCamera = siteCameras[index];
|
|
20342
20568
|
if (siteCamera && siteCamera.status === "active" && siteCamera.host && siteCamera.username && siteCamera.password && siteCamera.site && siteCamera.guardPost) {
|
|
20343
|
-
dahuaService.listenToCamera(siteCamera);
|
|
20569
|
+
dahuaService.listenToCamera(siteCamera, onDetected);
|
|
20344
20570
|
}
|
|
20345
20571
|
}
|
|
20346
20572
|
}
|
|
@@ -23390,6 +23616,12 @@ function useVisitorTransactionService() {
|
|
|
23390
23616
|
const parsed = new Date(value.checkOut);
|
|
23391
23617
|
value.checkOut = isNaN(parsed.getTime()) ? null : parsed;
|
|
23392
23618
|
}
|
|
23619
|
+
if (value.site) {
|
|
23620
|
+
value.site = typeof value.site === "string" ? new import_mongodb59.ObjectId(value.site) : value.site;
|
|
23621
|
+
}
|
|
23622
|
+
if (value.unit) {
|
|
23623
|
+
value.unit = typeof value.unit === "string" ? new import_mongodb59.ObjectId(value.unit) : value.unit;
|
|
23624
|
+
}
|
|
23393
23625
|
await _updateVisitorTansactionById(id, value, session);
|
|
23394
23626
|
await session?.commitTransaction();
|
|
23395
23627
|
return "Successfully updated visitor transaction.";
|
|
@@ -25435,11 +25667,7 @@ function usePatrolQuestionRepo() {
|
|
|
25435
25667
|
const { delNamespace, getCache, setCache } = (0, import_node_server_utils114.useCache)(namespace_collection);
|
|
25436
25668
|
async function createIndexes() {
|
|
25437
25669
|
try {
|
|
25438
|
-
await collection.createIndexes([
|
|
25439
|
-
{
|
|
25440
|
-
key: { site: 1 }
|
|
25441
|
-
}
|
|
25442
|
-
]);
|
|
25670
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
25443
25671
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
25444
25672
|
} catch (error) {
|
|
25445
25673
|
import_node_server_utils114.logger.log({
|
|
@@ -25875,6 +26103,24 @@ function usePatrolRouteRepo() {
|
|
|
25875
26103
|
const namespace_collection = "patrol.route";
|
|
25876
26104
|
const collection = db.collection(namespace_collection);
|
|
25877
26105
|
const { delNamespace, getCache, setCache } = (0, import_node_server_utils117.useCache)(namespace_collection);
|
|
26106
|
+
async function createIndexes() {
|
|
26107
|
+
try {
|
|
26108
|
+
await collection.createIndexes([
|
|
26109
|
+
{ key: { site: 1, status: 1 } },
|
|
26110
|
+
{ key: { site: 1, repeat: 1 } },
|
|
26111
|
+
{ key: { assignee: 1 } }
|
|
26112
|
+
]);
|
|
26113
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
26114
|
+
} catch (error) {
|
|
26115
|
+
import_node_server_utils117.logger.log({
|
|
26116
|
+
level: "error",
|
|
26117
|
+
message: error.message
|
|
26118
|
+
});
|
|
26119
|
+
throw new import_node_server_utils117.InternalServerError(
|
|
26120
|
+
"Failed to create general indexes on patrol routes."
|
|
26121
|
+
);
|
|
26122
|
+
}
|
|
26123
|
+
}
|
|
25878
26124
|
async function createTextIndex() {
|
|
25879
26125
|
try {
|
|
25880
26126
|
await collection.createIndex({
|
|
@@ -26172,7 +26418,7 @@ function usePatrolRouteRepo() {
|
|
|
26172
26418
|
id: "$_id",
|
|
26173
26419
|
start: startOfDay,
|
|
26174
26420
|
end: endOfDay,
|
|
26175
|
-
site: new import_mongodb67.ObjectId(site)
|
|
26421
|
+
site: import_mongodb67.ObjectId.isValid(site) ? new import_mongodb67.ObjectId(site) : null
|
|
26176
26422
|
},
|
|
26177
26423
|
pipeline: [
|
|
26178
26424
|
{
|
|
@@ -26203,10 +26449,8 @@ function usePatrolRouteRepo() {
|
|
|
26203
26449
|
{ $skip: page * limit },
|
|
26204
26450
|
{ $limit: limit }
|
|
26205
26451
|
];
|
|
26206
|
-
const
|
|
26207
|
-
|
|
26208
|
-
collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
|
|
26209
|
-
]);
|
|
26452
|
+
const items = await collection.aggregate(basePipeline, { session }).toArray();
|
|
26453
|
+
const countResult = await collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray();
|
|
26210
26454
|
const totalCount = countResult[0]?.total || 0;
|
|
26211
26455
|
const data = (0, import_node_server_utils117.paginate)(items, page, limit, totalCount);
|
|
26212
26456
|
setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils117.logger.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
@@ -26214,6 +26458,7 @@ function usePatrolRouteRepo() {
|
|
|
26214
26458
|
);
|
|
26215
26459
|
return data;
|
|
26216
26460
|
} catch (error) {
|
|
26461
|
+
console.error("[getScheduledRoute] ERROR:", error?.message, error?.stack);
|
|
26217
26462
|
throw error;
|
|
26218
26463
|
}
|
|
26219
26464
|
}
|
|
@@ -26248,7 +26493,8 @@ function usePatrolRouteRepo() {
|
|
|
26248
26493
|
updateById,
|
|
26249
26494
|
deleteById,
|
|
26250
26495
|
getScheduledRoute,
|
|
26251
|
-
getById
|
|
26496
|
+
getById,
|
|
26497
|
+
createIndexes
|
|
26252
26498
|
};
|
|
26253
26499
|
}
|
|
26254
26500
|
|
|
@@ -26499,6 +26745,7 @@ var schemaPatrolLog = import_joi65.default.object({
|
|
|
26499
26745
|
cameras: import_joi65.default.array().items(schemeLogCamera).required(),
|
|
26500
26746
|
status: import_joi65.default.array().items(import_joi65.default.string().valid("complete", "late", "incomplete")).required(),
|
|
26501
26747
|
incidentReport: incidentReportLog,
|
|
26748
|
+
platform: import_joi65.default.string().valid("web", "mobile").optional().allow(null, ""),
|
|
26502
26749
|
createdAt: import_joi65.default.date().optional(),
|
|
26503
26750
|
updatedAt: import_joi65.default.date().optional(),
|
|
26504
26751
|
deletedAt: import_joi65.default.date().optional()
|
|
@@ -26512,7 +26759,8 @@ var schemaUpdatePatrolLog = import_joi65.default.object({
|
|
|
26512
26759
|
end: import_joi65.default.string().optional().allow(null, ""),
|
|
26513
26760
|
cameras: import_joi65.default.array().items(schemeLogCamera).optional().allow(null, ""),
|
|
26514
26761
|
status: import_joi65.default.array().items(import_joi65.default.string().valid("complete", "late", "incomplete")).optional().allow(null, ""),
|
|
26515
|
-
incidentReport: incidentReportLog
|
|
26762
|
+
incidentReport: incidentReportLog,
|
|
26763
|
+
platform: import_joi65.default.string().valid("web", "mobile").optional().allow(null, "")
|
|
26516
26764
|
});
|
|
26517
26765
|
function MPatrolLog(value) {
|
|
26518
26766
|
const { error } = schemaPatrolLog.validate(value);
|
|
@@ -26566,6 +26814,7 @@ function MPatrolLog(value) {
|
|
|
26566
26814
|
status: value.status ?? [],
|
|
26567
26815
|
route: value.route,
|
|
26568
26816
|
incidentReport: value.incidentReport,
|
|
26817
|
+
platForm: value.platform ?? "",
|
|
26569
26818
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
26570
26819
|
updatedAt: value.updatedAt ?? "",
|
|
26571
26820
|
deletedAt: value.deletedAt ?? ""
|
|
@@ -26586,9 +26835,8 @@ function usePatrolLogRepo() {
|
|
|
26586
26835
|
async function createIndexes() {
|
|
26587
26836
|
try {
|
|
26588
26837
|
await collection.createIndexes([
|
|
26589
|
-
{
|
|
26590
|
-
|
|
26591
|
-
}
|
|
26838
|
+
{ key: { site: 1, createdAt: -1 } },
|
|
26839
|
+
{ key: { assignee: 1 } }
|
|
26592
26840
|
]);
|
|
26593
26841
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
26594
26842
|
} catch (error) {
|
|
@@ -26919,6 +27167,7 @@ function usePatrolLogService() {
|
|
|
26919
27167
|
}
|
|
26920
27168
|
}
|
|
26921
27169
|
}
|
|
27170
|
+
value.platform = value.platform === "web" ? "web" : "mobile";
|
|
26922
27171
|
const result = await _add(value, session);
|
|
26923
27172
|
await session.commitTransaction();
|
|
26924
27173
|
return result;
|
|
@@ -30415,6 +30664,20 @@ function useSiteBillingItemRepo() {
|
|
|
30415
30664
|
const namespace_collection = "site.billing.items";
|
|
30416
30665
|
const collection = db.collection(namespace_collection);
|
|
30417
30666
|
const { delNamespace, setCache, getCache } = (0, import_node_server_utils139.useCache)(namespace_collection);
|
|
30667
|
+
async function createIndexes() {
|
|
30668
|
+
try {
|
|
30669
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
30670
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
30671
|
+
} catch (error) {
|
|
30672
|
+
import_node_server_utils139.logger.log({
|
|
30673
|
+
level: "error",
|
|
30674
|
+
message: error.message
|
|
30675
|
+
});
|
|
30676
|
+
throw new import_node_server_utils139.InternalServerError(
|
|
30677
|
+
"Failed to create general indexes on billing item."
|
|
30678
|
+
);
|
|
30679
|
+
}
|
|
30680
|
+
}
|
|
30418
30681
|
async function createTextIndex() {
|
|
30419
30682
|
try {
|
|
30420
30683
|
await collection.createIndex({
|
|
@@ -30634,7 +30897,8 @@ function useSiteBillingItemRepo() {
|
|
|
30634
30897
|
getAll,
|
|
30635
30898
|
getById,
|
|
30636
30899
|
updateById,
|
|
30637
|
-
deleteById
|
|
30900
|
+
deleteById,
|
|
30901
|
+
createIndexes
|
|
30638
30902
|
};
|
|
30639
30903
|
}
|
|
30640
30904
|
|
|
@@ -30775,6 +31039,20 @@ function useSiteBillingConfigurationRepo() {
|
|
|
30775
31039
|
const namespace_collection = "site.billing.configuration";
|
|
30776
31040
|
const collection = db.collection(namespace_collection);
|
|
30777
31041
|
const { delNamespace, setCache, getCache } = (0, import_node_server_utils141.useCache)(namespace_collection);
|
|
31042
|
+
async function createIndexes() {
|
|
31043
|
+
try {
|
|
31044
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
31045
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
31046
|
+
} catch (error) {
|
|
31047
|
+
import_node_server_utils141.logger.log({
|
|
31048
|
+
level: "error",
|
|
31049
|
+
message: error.message
|
|
31050
|
+
});
|
|
31051
|
+
throw new import_node_server_utils141.InternalServerError(
|
|
31052
|
+
"Failed to create general indexes on billing configuration."
|
|
31053
|
+
);
|
|
31054
|
+
}
|
|
31055
|
+
}
|
|
30778
31056
|
async function createTextIndex() {
|
|
30779
31057
|
try {
|
|
30780
31058
|
await collection.createIndex({
|
|
@@ -30984,7 +31262,8 @@ function useSiteBillingConfigurationRepo() {
|
|
|
30984
31262
|
getAll,
|
|
30985
31263
|
getById,
|
|
30986
31264
|
updateById,
|
|
30987
|
-
deleteById
|
|
31265
|
+
deleteById,
|
|
31266
|
+
createIndexes
|
|
30988
31267
|
};
|
|
30989
31268
|
}
|
|
30990
31269
|
|
|
@@ -32265,6 +32544,25 @@ function useSiteUnitBillingRepo() {
|
|
|
32265
32544
|
const namespace_collection = "site.unit.billing";
|
|
32266
32545
|
const collection = db.collection(namespace_collection);
|
|
32267
32546
|
const { delNamespace, setCache, getCache } = (0, import_node_server_utils150.useCache)(namespace_collection);
|
|
32547
|
+
async function createIndexes() {
|
|
32548
|
+
try {
|
|
32549
|
+
await collection.createIndexes([
|
|
32550
|
+
{ key: { site: 1, status: 1, paymentStatus: 1 } },
|
|
32551
|
+
{ key: { site: 1, unitId: 1, status: 1, paymentStatus: 1 } },
|
|
32552
|
+
{ key: { site: 1, unitId: 1, issueDate: 1 } },
|
|
32553
|
+
{ key: { createdAt: -1 } }
|
|
32554
|
+
]);
|
|
32555
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
32556
|
+
} catch (error) {
|
|
32557
|
+
import_node_server_utils150.logger.log({
|
|
32558
|
+
level: "error",
|
|
32559
|
+
message: error.message
|
|
32560
|
+
});
|
|
32561
|
+
throw new import_node_server_utils150.InternalServerError(
|
|
32562
|
+
"Failed to create general indexes on unit billing."
|
|
32563
|
+
);
|
|
32564
|
+
}
|
|
32565
|
+
}
|
|
32268
32566
|
async function createTextIndex() {
|
|
32269
32567
|
try {
|
|
32270
32568
|
await collection.createIndex({
|
|
@@ -32818,7 +33116,8 @@ function useSiteUnitBillingRepo() {
|
|
|
32818
33116
|
deleteById,
|
|
32819
33117
|
getUnitBillingBySite,
|
|
32820
33118
|
getResidentUserBilling,
|
|
32821
|
-
getResidentUserUnsettledBilling
|
|
33119
|
+
getResidentUserUnsettledBilling,
|
|
33120
|
+
createIndexes
|
|
32822
33121
|
};
|
|
32823
33122
|
}
|
|
32824
33123
|
|
|
@@ -38632,6 +38931,22 @@ function useStatementOfAccountRepo() {
|
|
|
38632
38931
|
const namespace_collection = "site.statement-of-accounts";
|
|
38633
38932
|
const collection = db.collection(namespace_collection);
|
|
38634
38933
|
const { delNamespace, getCache, setCache } = (0, import_node_server_utils165.useCache)(namespace_collection);
|
|
38934
|
+
async function createIndexes() {
|
|
38935
|
+
try {
|
|
38936
|
+
await collection.createIndexes([
|
|
38937
|
+
{ key: { site: 1, status: 1 } },
|
|
38938
|
+
{ key: { site: 1, unitId: 1, status: 1 } },
|
|
38939
|
+
{ key: { createdAt: -1 } }
|
|
38940
|
+
]);
|
|
38941
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
38942
|
+
} catch (error) {
|
|
38943
|
+
import_node_server_utils165.logger.log({
|
|
38944
|
+
level: "error",
|
|
38945
|
+
message: error.message
|
|
38946
|
+
});
|
|
38947
|
+
throw new import_node_server_utils165.InternalServerError("Failed to create general indexes on SOA.");
|
|
38948
|
+
}
|
|
38949
|
+
}
|
|
38635
38950
|
async function createTextIndex() {
|
|
38636
38951
|
try {
|
|
38637
38952
|
await collection.createIndex({
|
|
@@ -38982,7 +39297,8 @@ function useStatementOfAccountRepo() {
|
|
|
38982
39297
|
deleteById,
|
|
38983
39298
|
updateStatusById,
|
|
38984
39299
|
getResidentUserSoa,
|
|
38985
|
-
reviewSOA
|
|
39300
|
+
reviewSOA,
|
|
39301
|
+
createIndexes
|
|
38986
39302
|
};
|
|
38987
39303
|
}
|
|
38988
39304
|
|
|
@@ -40914,6 +41230,7 @@ var schemaIncidentReport = import_joi99.default.object({
|
|
|
40914
41230
|
approvedBy: import_joi99.default.string().hex().allow(null, "").optional(),
|
|
40915
41231
|
approvedByName: import_joi99.default.string().optional().allow("", null),
|
|
40916
41232
|
remarks: import_joi99.default.string().optional().allow("", null),
|
|
41233
|
+
platform: import_joi99.default.string().valid("web", "mobile").optional().allow(null, ""),
|
|
40917
41234
|
status: import_joi99.default.string().valid("pending", "approved", "rejected").default("pending")
|
|
40918
41235
|
});
|
|
40919
41236
|
var schemaUpdateIncidentReport = import_joi99.default.object({
|
|
@@ -40994,6 +41311,7 @@ var schemaUpdateIncidentReport = import_joi99.default.object({
|
|
|
40994
41311
|
approvedBy: import_joi99.default.string().hex().allow(null, "").optional(),
|
|
40995
41312
|
approvedByName: import_joi99.default.string().optional().allow("", null),
|
|
40996
41313
|
remarks: import_joi99.default.string().optional().allow("", null),
|
|
41314
|
+
platform: import_joi99.default.string().valid("web", "mobile").optional().allow(null, ""),
|
|
40997
41315
|
status: import_joi99.default.string().valid("pending", "approved", "rejected").default("pending")
|
|
40998
41316
|
});
|
|
40999
41317
|
function MIncidentReport(value) {
|
|
@@ -41055,6 +41373,7 @@ function MIncidentReport(value) {
|
|
|
41055
41373
|
approvedByName: value.approvedByName ?? "",
|
|
41056
41374
|
remarks: value.remarks ?? null,
|
|
41057
41375
|
status: value.status ?? "pending",
|
|
41376
|
+
platForm: value.platform ?? "",
|
|
41058
41377
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
41059
41378
|
updatedAt: value.updatedAt,
|
|
41060
41379
|
deletedAt: value.deletedAt
|
|
@@ -41520,6 +41839,7 @@ function useIncidentReportService() {
|
|
|
41520
41839
|
}
|
|
41521
41840
|
}
|
|
41522
41841
|
}
|
|
41842
|
+
value.platform = value.platform === "web" ? "web" : "mobile";
|
|
41523
41843
|
const result = await _add(value, session);
|
|
41524
41844
|
await session?.commitTransaction();
|
|
41525
41845
|
return result;
|
|
@@ -42537,7 +42857,10 @@ function useOccurrenceEntryService() {
|
|
|
42537
42857
|
updateOccurrenceEntryById: _updateOccurrenceEntryById,
|
|
42538
42858
|
getOccurrenceEntryById: _getOccurrenceEntryById,
|
|
42539
42859
|
getOccurrenceEntryByBookId: _getOccurrenceEntryByBookId,
|
|
42540
|
-
updateOccurrenceEntryByBookId: _updateOccurrenceEntryByBookId
|
|
42860
|
+
updateOccurrenceEntryByBookId: _updateOccurrenceEntryByBookId,
|
|
42861
|
+
deleteOccurrenceEntryById: _deleteOccurrenceEntryById,
|
|
42862
|
+
getLatestSerialNumber: _getLatestSerialNumber,
|
|
42863
|
+
getLatestSerialNumberInGroup: _getLatestSerialNumberInGroup
|
|
42541
42864
|
} = useOccurrenceEntryRepo();
|
|
42542
42865
|
const {
|
|
42543
42866
|
getOccurrenceBookById: _getOccurrenceBookById,
|
|
@@ -42589,8 +42912,25 @@ function useOccurrenceEntryService() {
|
|
|
42589
42912
|
if (!occurrenceEntry) {
|
|
42590
42913
|
throw new Error("Occurrence entry not found.");
|
|
42591
42914
|
}
|
|
42592
|
-
|
|
42593
|
-
|
|
42915
|
+
if (value.incidentReportId) {
|
|
42916
|
+
await _updateOccurrenceEntryById(id, value, session);
|
|
42917
|
+
await session?.commitTransaction();
|
|
42918
|
+
return "Successfully updated occurrence entry (incident report).";
|
|
42919
|
+
}
|
|
42920
|
+
const entryCount = await _getLatestSerialNumberInGroup(
|
|
42921
|
+
occurrenceEntry.dailyOccurrenceBookId,
|
|
42922
|
+
Number(occurrenceEntry.serialNumber)
|
|
42923
|
+
);
|
|
42924
|
+
const currentSerial = Number(occurrenceEntry.serialNumber);
|
|
42925
|
+
const latestSerial = Number(entryCount);
|
|
42926
|
+
const currentGroup = Math.floor(currentSerial);
|
|
42927
|
+
const latestGroup = Math.floor(latestSerial);
|
|
42928
|
+
let updatedSerialNumber;
|
|
42929
|
+
if (currentGroup === latestGroup) {
|
|
42930
|
+
updatedSerialNumber = (latestSerial + 0.1).toFixed(1);
|
|
42931
|
+
} else {
|
|
42932
|
+
updatedSerialNumber = (currentSerial + 0.1).toFixed(1);
|
|
42933
|
+
}
|
|
42594
42934
|
const dobId = occurrenceEntry.dailyOccurrenceBookId;
|
|
42595
42935
|
const book = await _getOccurrenceBookById(dobId);
|
|
42596
42936
|
const subject = await _getOccurrenceSubjectById(
|
|
@@ -42609,6 +42949,8 @@ function useOccurrenceEntryService() {
|
|
|
42609
42949
|
value.date = value.date ? value.date : occurrenceEntry.date;
|
|
42610
42950
|
value.userName = value.userName ? value.userName : occurrenceEntry.signature.name;
|
|
42611
42951
|
value.createdByName = value.createdByName ? value.createdByName : occurrenceEntry.createdByName;
|
|
42952
|
+
if (occurrenceEntry.incidentReportId)
|
|
42953
|
+
value.incidentReportId = occurrenceEntry.incidentReportId;
|
|
42612
42954
|
await _updateOccurrenceBookById(dobId, {
|
|
42613
42955
|
totalInput: book.totalInput + 1
|
|
42614
42956
|
});
|
|
@@ -45049,7 +45391,9 @@ function useManpowerMonitoringRepo() {
|
|
|
45049
45391
|
{
|
|
45050
45392
|
key: { siteId: 1 }
|
|
45051
45393
|
},
|
|
45052
|
-
{ key: { createdAt: 1 } }
|
|
45394
|
+
{ key: { createdAt: 1 } },
|
|
45395
|
+
{ key: { siteId: 1, serviceProviderId: 1 } },
|
|
45396
|
+
{ key: { siteName: 1 } }
|
|
45053
45397
|
]);
|
|
45054
45398
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45055
45399
|
} catch (error) {
|
|
@@ -45308,7 +45652,9 @@ function useManpowerRemarksRepo() {
|
|
|
45308
45652
|
{
|
|
45309
45653
|
key: { siteId: 1 }
|
|
45310
45654
|
},
|
|
45311
|
-
{ key: { createdAt: 1 } }
|
|
45655
|
+
{ key: { createdAt: 1 } },
|
|
45656
|
+
{ key: { siteId: 1, serviceProviderId: 1, createdAtSGT: 1 } },
|
|
45657
|
+
{ key: { serviceProviderId: 1, status: 1, createdAtSGT: 1 } }
|
|
45312
45658
|
]);
|
|
45313
45659
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45314
45660
|
} catch (error) {
|
|
@@ -45737,7 +46083,8 @@ function useManpowerDesignationRepo() {
|
|
|
45737
46083
|
{
|
|
45738
46084
|
key: { siteId: 1 }
|
|
45739
46085
|
},
|
|
45740
|
-
{ key: { createdAt: 1 } }
|
|
46086
|
+
{ key: { createdAt: 1 } },
|
|
46087
|
+
{ key: { siteId: 1, serviceProviderId: 1 } }
|
|
45741
46088
|
]);
|
|
45742
46089
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45743
46090
|
} catch (error) {
|
|
@@ -51179,6 +51526,7 @@ function useRoleControllerV2() {
|
|
|
51179
51526
|
vehicles_namespace_collection,
|
|
51180
51527
|
visitors_namespace_collection,
|
|
51181
51528
|
workOrderSchema,
|
|
51529
|
+
work_orders2_namespace_collection,
|
|
51182
51530
|
work_orders_namespace_collection
|
|
51183
51531
|
});
|
|
51184
51532
|
//# sourceMappingURL=index.js.map
|