@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.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");
|
|
@@ -13803,14 +13831,14 @@ function useVisitorTransactionRepo() {
|
|
|
13803
13831
|
);
|
|
13804
13832
|
}
|
|
13805
13833
|
}
|
|
13806
|
-
async function updateById(_id, value, session) {
|
|
13834
|
+
async function updateById(_id, value, session, isNotManualCheckOut = true) {
|
|
13807
13835
|
try {
|
|
13808
13836
|
_id = new ObjectId40(_id);
|
|
13809
13837
|
} catch (error) {
|
|
13810
13838
|
throw new BadRequestError66("Invalid visitor transaction ID format.");
|
|
13811
13839
|
}
|
|
13812
13840
|
value.updatedAt = /* @__PURE__ */ new Date();
|
|
13813
|
-
if (value.checkOut) {
|
|
13841
|
+
if (value.checkOut && isNotManualCheckOut) {
|
|
13814
13842
|
value.manualCheckout = true;
|
|
13815
13843
|
}
|
|
13816
13844
|
try {
|
|
@@ -14570,6 +14598,22 @@ function useVehicleRepo() {
|
|
|
14570
14598
|
throw error;
|
|
14571
14599
|
}
|
|
14572
14600
|
}
|
|
14601
|
+
async function getSpecificVehicleById(_id) {
|
|
14602
|
+
try {
|
|
14603
|
+
_id = new ObjectId42(_id);
|
|
14604
|
+
} catch (error) {
|
|
14605
|
+
throw new BadRequestError68("Invalid vehicle ID format.");
|
|
14606
|
+
}
|
|
14607
|
+
try {
|
|
14608
|
+
const result = await collection.findOne({ _id });
|
|
14609
|
+
if (!result) {
|
|
14610
|
+
throw new NotFoundError17("Vehicle not found.");
|
|
14611
|
+
}
|
|
14612
|
+
return result;
|
|
14613
|
+
} catch (error) {
|
|
14614
|
+
throw error;
|
|
14615
|
+
}
|
|
14616
|
+
}
|
|
14573
14617
|
async function getByPlaceNumber(value) {
|
|
14574
14618
|
const { error } = Joi38.string().required().validate(value);
|
|
14575
14619
|
if (error) {
|
|
@@ -14828,7 +14872,8 @@ function useVehicleRepo() {
|
|
|
14828
14872
|
deleteExpiredVehicles,
|
|
14829
14873
|
getAllVehiclesByUnitId,
|
|
14830
14874
|
getAllExpiredVehicles,
|
|
14831
|
-
bulkUpsertVehicles
|
|
14875
|
+
bulkUpsertVehicles,
|
|
14876
|
+
getSpecificVehicleById
|
|
14832
14877
|
};
|
|
14833
14878
|
}
|
|
14834
14879
|
|
|
@@ -14866,7 +14911,11 @@ function usePersonRepo() {
|
|
|
14866
14911
|
try {
|
|
14867
14912
|
await collection.createIndexes([
|
|
14868
14913
|
{ key: { contact: 1 } },
|
|
14869
|
-
{ key: { nric: 1 } }
|
|
14914
|
+
{ key: { nric: 1 } },
|
|
14915
|
+
{ key: { user: 1 } },
|
|
14916
|
+
{ key: { site: 1, status: 1 } },
|
|
14917
|
+
{ key: { "plates.plateNumber": 1, status: 1 } },
|
|
14918
|
+
{ key: { unit: 1, status: 1 } }
|
|
14870
14919
|
]);
|
|
14871
14920
|
} catch (error) {
|
|
14872
14921
|
throw new InternalServerError26("Failed to create index on site people.");
|
|
@@ -16844,6 +16893,9 @@ function useVehicleService() {
|
|
|
16844
16893
|
const _end = vehicle.end;
|
|
16845
16894
|
const _recNo = plate.recNo;
|
|
16846
16895
|
const _type = value.type ? value.type : plate.type;
|
|
16896
|
+
if (value.peopleId) {
|
|
16897
|
+
value.peopleId = new ObjectId46(value.peopleId);
|
|
16898
|
+
}
|
|
16847
16899
|
const { name, plateNumber, start, end, recNo, type, unit, site, ...rest } = value;
|
|
16848
16900
|
const startDahua = value.start ? formatDahuaDate(new Date(value.start)) : formatDahuaDate(new Date(_start));
|
|
16849
16901
|
const endDahua = value.end ? formatDahuaDate(new Date(value.end)) : formatDahuaDate(new Date(_end));
|
|
@@ -16907,6 +16959,17 @@ function useVehicleService() {
|
|
|
16907
16959
|
}
|
|
16908
16960
|
const responseData = dahuaResponse?.data?.toString("utf-8") ?? "";
|
|
16909
16961
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
16962
|
+
const normalizedPlateNumber = Array.isArray(plateNumber) ? plateNumber[0] : plateNumber;
|
|
16963
|
+
if (value.peopleId && value.recNo) {
|
|
16964
|
+
await _pushVehicleById(
|
|
16965
|
+
value.peopleId,
|
|
16966
|
+
{
|
|
16967
|
+
plateNumber: normalizedPlateNumber,
|
|
16968
|
+
recNo: value.recNo
|
|
16969
|
+
},
|
|
16970
|
+
session
|
|
16971
|
+
);
|
|
16972
|
+
}
|
|
16910
16973
|
} else {
|
|
16911
16974
|
const dahuaPayload = {
|
|
16912
16975
|
host,
|
|
@@ -16920,6 +16983,17 @@ function useVehicleService() {
|
|
|
16920
16983
|
owner: name ? name : _name
|
|
16921
16984
|
};
|
|
16922
16985
|
const dahuaResponse = await _updatePlateNumber(dahuaPayload);
|
|
16986
|
+
const normalizedPlateNumber = Array.isArray(plateNumber) ? plateNumber[0] : plateNumber;
|
|
16987
|
+
if (value.peopleId && value.recNo) {
|
|
16988
|
+
await _pushVehicleById(
|
|
16989
|
+
value.peopleId,
|
|
16990
|
+
{
|
|
16991
|
+
plateNumber: normalizedPlateNumber,
|
|
16992
|
+
recNo: _recNo
|
|
16993
|
+
},
|
|
16994
|
+
session
|
|
16995
|
+
);
|
|
16996
|
+
}
|
|
16923
16997
|
if (dahuaResponse?.statusCode !== 200) {
|
|
16924
16998
|
throw new BadRequestError72(
|
|
16925
16999
|
"Failed to update plate number to ANPR"
|
|
@@ -17079,6 +17153,7 @@ var loggerDahua = winston.createLogger({
|
|
|
17079
17153
|
|
|
17080
17154
|
// src/services/dahua.service.ts
|
|
17081
17155
|
var cameraRegistry = /* @__PURE__ */ new Map();
|
|
17156
|
+
var _savedOnDetected;
|
|
17082
17157
|
function useDahuaDigest({
|
|
17083
17158
|
host = "",
|
|
17084
17159
|
username = "",
|
|
@@ -17114,7 +17189,7 @@ function useDahuaService() {
|
|
|
17114
17189
|
const { createFile: _createFile } = useFileService();
|
|
17115
17190
|
let currentTransactionId = null;
|
|
17116
17191
|
let currentSnapshotField = null;
|
|
17117
|
-
function useBufferQueue(boundary, site, gate, designation, host, username, password) {
|
|
17192
|
+
function useBufferQueue(boundary, site, gate, designation, host, username, password, onDetected) {
|
|
17118
17193
|
const queue = [];
|
|
17119
17194
|
let processing = false;
|
|
17120
17195
|
let plateNumber = null;
|
|
@@ -17143,11 +17218,11 @@ function useDahuaService() {
|
|
|
17143
17218
|
queue.push(buffer);
|
|
17144
17219
|
if (queue.length >= BACKPRESSURE_THRESHOLD && streamRef && !streamRef.isPaused()) {
|
|
17145
17220
|
loggerDahua.warn(
|
|
17146
|
-
`[${site}][${
|
|
17221
|
+
`[${site}][${host}] Queue at ${queue.length}/${MAX_QUEUE_SIZE}, pausing stream`
|
|
17147
17222
|
);
|
|
17148
17223
|
streamRef.pause();
|
|
17149
17224
|
}
|
|
17150
|
-
processNext();
|
|
17225
|
+
processNext(onDetected);
|
|
17151
17226
|
}
|
|
17152
17227
|
function destroy() {
|
|
17153
17228
|
queue.length = 0;
|
|
@@ -17160,33 +17235,33 @@ function useDahuaService() {
|
|
|
17160
17235
|
streamRef.resume();
|
|
17161
17236
|
}
|
|
17162
17237
|
loggerDahua.info(
|
|
17163
|
-
`[${site}][${
|
|
17238
|
+
`[${site}][${host}] BufferQueue destroyed. Processed=${processedChunks}, Dropped=${droppedChunks}`
|
|
17164
17239
|
);
|
|
17165
17240
|
}
|
|
17166
|
-
async function processNext() {
|
|
17241
|
+
async function processNext(onDetected2) {
|
|
17167
17242
|
if (processing || queue.length === 0)
|
|
17168
17243
|
return;
|
|
17169
17244
|
processing = true;
|
|
17170
17245
|
const buffer = queue.shift();
|
|
17171
17246
|
try {
|
|
17172
|
-
await handleBuffer(buffer);
|
|
17247
|
+
await handleBuffer(buffer, onDetected2);
|
|
17173
17248
|
processedChunks++;
|
|
17174
17249
|
if (queue.length <= RESUME_THRESHOLD && streamRef && streamRef.isPaused()) {
|
|
17175
17250
|
loggerDahua.info(
|
|
17176
|
-
`[${
|
|
17251
|
+
`[${host}]Queue at ${queue.length}/${MAX_QUEUE_SIZE}, resuming stream`
|
|
17177
17252
|
);
|
|
17178
17253
|
streamRef.resume();
|
|
17179
17254
|
}
|
|
17180
17255
|
} catch (err) {
|
|
17181
|
-
loggerDahua.error(`[${
|
|
17256
|
+
loggerDahua.error(`[${host}] Error processing buffer:`, err);
|
|
17182
17257
|
} finally {
|
|
17183
17258
|
processing = false;
|
|
17184
|
-
processNext();
|
|
17259
|
+
processNext(onDetected2);
|
|
17185
17260
|
}
|
|
17186
17261
|
}
|
|
17187
|
-
async function processVehicleTransaction() {
|
|
17262
|
+
async function processVehicleTransaction(onDetected2) {
|
|
17188
17263
|
loggerDahua.info(
|
|
17189
|
-
`[${
|
|
17264
|
+
`[${host}] Vehicle transaction: Plate=${plateNumber}, UTC=${UTCData}, UTCMs=${UTCMs}`
|
|
17190
17265
|
);
|
|
17191
17266
|
let org = "";
|
|
17192
17267
|
try {
|
|
@@ -17194,7 +17269,7 @@ function useDahuaService() {
|
|
|
17194
17269
|
org = theSite?.orgId.toString() || "unknown";
|
|
17195
17270
|
} catch (error) {
|
|
17196
17271
|
loggerDahua.error(
|
|
17197
|
-
`[${
|
|
17272
|
+
`[${host}] Error fetching site for orgId:`,
|
|
17198
17273
|
error
|
|
17199
17274
|
);
|
|
17200
17275
|
}
|
|
@@ -17208,13 +17283,13 @@ function useDahuaService() {
|
|
|
17208
17283
|
const transactionId = existingOpenTransaction?._id?.toString() || "";
|
|
17209
17284
|
if (existingOpenTransaction && !existingOpenTransaction.checkOut && transactionId) {
|
|
17210
17285
|
await updateById(transactionId, {
|
|
17211
|
-
checkOut:
|
|
17212
|
-
updatedAt:
|
|
17213
|
-
});
|
|
17286
|
+
checkOut: /* @__PURE__ */ new Date(),
|
|
17287
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
17288
|
+
}, void 0, false);
|
|
17214
17289
|
}
|
|
17215
17290
|
} catch (error) {
|
|
17216
17291
|
loggerDahua.error(
|
|
17217
|
-
`[${
|
|
17292
|
+
`[${host}] Error closing existing open transaction:`,
|
|
17218
17293
|
error
|
|
17219
17294
|
);
|
|
17220
17295
|
}
|
|
@@ -17264,9 +17339,13 @@ function useDahuaService() {
|
|
|
17264
17339
|
}
|
|
17265
17340
|
try {
|
|
17266
17341
|
await addPlateNumber(dahuaPayload);
|
|
17267
|
-
const
|
|
17268
|
-
|
|
17342
|
+
const result = await add(visitorTransaction, void 0, true);
|
|
17343
|
+
const transactionId = result?._id;
|
|
17344
|
+
currentTransactionId = transactionId?.toString();
|
|
17269
17345
|
currentSnapshotField = "snapshotEntryImage";
|
|
17346
|
+
if (onDetected2) {
|
|
17347
|
+
onDetected2({ _id: transactionId, site: result?.site?.toString(), plateNumber: result.plateNumber, host, direction });
|
|
17348
|
+
}
|
|
17270
17349
|
} catch (error) {
|
|
17271
17350
|
console.log("failed to create visitor transaction", error);
|
|
17272
17351
|
loggerDahua.error(
|
|
@@ -17274,8 +17353,7 @@ function useDahuaService() {
|
|
|
17274
17353
|
error
|
|
17275
17354
|
);
|
|
17276
17355
|
}
|
|
17277
|
-
}
|
|
17278
|
-
if (["exit", "both"].includes(designation) && direction.toLowerCase() === "leave" && plateNumber) {
|
|
17356
|
+
} else if (["exit", "both"].includes(designation) && direction.toLowerCase() === "leave" && plateNumber) {
|
|
17279
17357
|
const vehicle = await getVehicleByPlateNumber(plateNumber);
|
|
17280
17358
|
const existingOpenTransaction = await getOpenByPlateNumber(
|
|
17281
17359
|
plateNumber,
|
|
@@ -17297,10 +17375,13 @@ function useDahuaService() {
|
|
|
17297
17375
|
await removePlateNumber(dahuaPayload);
|
|
17298
17376
|
}
|
|
17299
17377
|
await closeOpenTransaction(plateNumber);
|
|
17378
|
+
if (onDetected2) {
|
|
17379
|
+
onDetected2({ reload: true, site: existingOpenTransaction?.site?.toString(), host, direction });
|
|
17380
|
+
}
|
|
17300
17381
|
}
|
|
17301
17382
|
}
|
|
17302
17383
|
}
|
|
17303
|
-
async function handleBuffer(chunk) {
|
|
17384
|
+
async function handleBuffer(chunk, onDetected2) {
|
|
17304
17385
|
partialBuffer = Buffer.concat([partialBuffer, chunk]);
|
|
17305
17386
|
while (true) {
|
|
17306
17387
|
const boundaryIndex = partialBuffer.indexOf(Buffer.from(boundary));
|
|
@@ -17326,7 +17407,7 @@ function useDahuaService() {
|
|
|
17326
17407
|
direction = line.split("=")[1].trim();
|
|
17327
17408
|
});
|
|
17328
17409
|
if (plateNumber && UTCData) {
|
|
17329
|
-
await processVehicleTransaction();
|
|
17410
|
+
await processVehicleTransaction(onDetected2);
|
|
17330
17411
|
}
|
|
17331
17412
|
} else if (part.includes("Content-Type: image/jpeg")) {
|
|
17332
17413
|
const [headers, ...imageParts] = part.split("\r\n\r\n");
|
|
@@ -17353,7 +17434,7 @@ function useDahuaService() {
|
|
|
17353
17434
|
try {
|
|
17354
17435
|
await fsAsync.mkdir(dir, { recursive: true });
|
|
17355
17436
|
await fsAsync.writeFile(snapFolder, accumulatedImageBuffer);
|
|
17356
|
-
loggerDahua.
|
|
17437
|
+
loggerDahua.info(`[${host}] Saved image locally: ${filename}`);
|
|
17357
17438
|
const fileId = await _createFile(
|
|
17358
17439
|
{
|
|
17359
17440
|
originalname: filename,
|
|
@@ -17363,7 +17444,7 @@ function useDahuaService() {
|
|
|
17363
17444
|
`anpr/${site}`
|
|
17364
17445
|
);
|
|
17365
17446
|
loggerDahua.info(
|
|
17366
|
-
`[${
|
|
17447
|
+
`[${host}] Created file record for image: ${fileId.toString()}`
|
|
17367
17448
|
);
|
|
17368
17449
|
if (currentTransactionId && currentSnapshotField) {
|
|
17369
17450
|
await updateById(currentTransactionId, {
|
|
@@ -17371,23 +17452,23 @@ function useDahuaService() {
|
|
|
17371
17452
|
});
|
|
17372
17453
|
}
|
|
17373
17454
|
loggerDahua.info(
|
|
17374
|
-
`[${
|
|
17455
|
+
`[${host}] Image stored with fileId: ${fileId.toString()}`
|
|
17375
17456
|
);
|
|
17376
17457
|
await fsAsync.unlink(snapFolder);
|
|
17377
|
-
loggerDahua.
|
|
17458
|
+
loggerDahua.info(`[${host}] Deleted local file: ${filename}`);
|
|
17378
17459
|
} catch (err) {
|
|
17379
17460
|
loggerDahua.error(
|
|
17380
|
-
`[${
|
|
17461
|
+
`[${host}] Failed to process image ${filename}:`,
|
|
17381
17462
|
err
|
|
17382
17463
|
);
|
|
17383
17464
|
try {
|
|
17384
17465
|
await fsAsync.unlink(snapFolder);
|
|
17385
|
-
loggerDahua.
|
|
17386
|
-
`[${
|
|
17466
|
+
loggerDahua.error(
|
|
17467
|
+
`[${host}] Cleaned up local file after error: ${filename}`
|
|
17387
17468
|
);
|
|
17388
17469
|
} catch (unlinkErr) {
|
|
17389
17470
|
loggerDahua.error(
|
|
17390
|
-
`[${
|
|
17471
|
+
`[${host}] Failed to clean up local file: ${filename}`,
|
|
17391
17472
|
unlinkErr
|
|
17392
17473
|
);
|
|
17393
17474
|
}
|
|
@@ -17427,10 +17508,13 @@ function useDahuaService() {
|
|
|
17427
17508
|
throw error;
|
|
17428
17509
|
}
|
|
17429
17510
|
}
|
|
17430
|
-
async function listenToCamera(camera) {
|
|
17511
|
+
async function listenToCamera(camera, onDetected) {
|
|
17512
|
+
if (onDetected) {
|
|
17513
|
+
_savedOnDetected = onDetected;
|
|
17514
|
+
}
|
|
17431
17515
|
if (!camera?._id) {
|
|
17432
17516
|
loggerDahua.error(`Camera _id is required to listen to camera.`);
|
|
17433
|
-
|
|
17517
|
+
return;
|
|
17434
17518
|
}
|
|
17435
17519
|
const cameraId = camera._id.toString();
|
|
17436
17520
|
if (cameraRegistry.has(cameraId)) {
|
|
@@ -17440,6 +17524,11 @@ function useDahuaService() {
|
|
|
17440
17524
|
}
|
|
17441
17525
|
const controller = new AbortController();
|
|
17442
17526
|
cameraRegistry.set(cameraId, controller);
|
|
17527
|
+
const onDetectedHandler = onDetected || _savedOnDetected;
|
|
17528
|
+
if (!onDetectedHandler) {
|
|
17529
|
+
loggerDahua.error(`No plate detection handler registered for camera ${cameraId}`);
|
|
17530
|
+
return;
|
|
17531
|
+
}
|
|
17443
17532
|
getTrafficJunction(
|
|
17444
17533
|
camera.host,
|
|
17445
17534
|
camera.username,
|
|
@@ -17448,10 +17537,11 @@ function useDahuaService() {
|
|
|
17448
17537
|
`guard-post-${camera.guardPost}`,
|
|
17449
17538
|
camera.direction,
|
|
17450
17539
|
cameraId,
|
|
17451
|
-
controller.signal
|
|
17540
|
+
controller.signal,
|
|
17541
|
+
onDetectedHandler
|
|
17452
17542
|
);
|
|
17453
17543
|
}
|
|
17454
|
-
async function
|
|
17544
|
+
async function getTrafficJunctionOld(host = "", username = "", password = "", site = "", gate = "", designation = "", cameraId, signal, onDetected) {
|
|
17455
17545
|
if (signal.aborted)
|
|
17456
17546
|
return;
|
|
17457
17547
|
try {
|
|
@@ -17474,7 +17564,8 @@ function useDahuaService() {
|
|
|
17474
17564
|
designation,
|
|
17475
17565
|
host,
|
|
17476
17566
|
username,
|
|
17477
|
-
password
|
|
17567
|
+
password,
|
|
17568
|
+
onDetected
|
|
17478
17569
|
);
|
|
17479
17570
|
bufferQueue.setStream(response.res);
|
|
17480
17571
|
const onAbort = () => {
|
|
@@ -17528,7 +17619,7 @@ function useDahuaService() {
|
|
|
17528
17619
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17529
17620
|
if (signal.aborted)
|
|
17530
17621
|
return;
|
|
17531
|
-
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17622
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal, onDetected);
|
|
17532
17623
|
};
|
|
17533
17624
|
response.res.on(
|
|
17534
17625
|
"end",
|
|
@@ -17552,9 +17643,106 @@ function useDahuaService() {
|
|
|
17552
17643
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17553
17644
|
if (signal.aborted)
|
|
17554
17645
|
return;
|
|
17555
|
-
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17646
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal, onDetected);
|
|
17556
17647
|
}
|
|
17557
17648
|
}
|
|
17649
|
+
async function getTrafficJunction(host = "", username = "", password = "", site = "", gate = "", designation = "", cameraId, signal, onDetected) {
|
|
17650
|
+
while (!signal.aborted) {
|
|
17651
|
+
let bufferQueue = null;
|
|
17652
|
+
let response = null;
|
|
17653
|
+
try {
|
|
17654
|
+
response = await useDahuaDigest({
|
|
17655
|
+
host,
|
|
17656
|
+
username,
|
|
17657
|
+
password,
|
|
17658
|
+
endpoint: "/cgi-bin/snapManager.cgi?action=attachFileProc&channel=1&heartbeat=5&Flags[0]=Event&Events=[TrafficJunction]",
|
|
17659
|
+
timeout: 2e4,
|
|
17660
|
+
streaming: true
|
|
17661
|
+
});
|
|
17662
|
+
if (response.statusCode === 401) {
|
|
17663
|
+
loggerDahua.error(`[${host}] 401 Unauthorized. Potential handshake or wrong credentials.`);
|
|
17664
|
+
continue;
|
|
17665
|
+
} else if ([400, 401, 403, 500].includes(response.statusCode)) {
|
|
17666
|
+
loggerDahua.error(`[${host}] Connection error: ${response.statusCode}`);
|
|
17667
|
+
return;
|
|
17668
|
+
}
|
|
17669
|
+
loggerDahua.info(`[${host}] Successfully connected to ANPR.`);
|
|
17670
|
+
const contentType = response.res.headers["content-type"];
|
|
17671
|
+
const boundaryMatch = contentType?.match(/boundary=(.*)$/i);
|
|
17672
|
+
const boundary = boundaryMatch ? `--${boundaryMatch[1]}` : "--myboundary";
|
|
17673
|
+
bufferQueue = useBufferQueue(
|
|
17674
|
+
boundary,
|
|
17675
|
+
site,
|
|
17676
|
+
gate,
|
|
17677
|
+
designation,
|
|
17678
|
+
host,
|
|
17679
|
+
username,
|
|
17680
|
+
password,
|
|
17681
|
+
onDetected
|
|
17682
|
+
);
|
|
17683
|
+
bufferQueue.setStream(response.res);
|
|
17684
|
+
await new Promise((resolve, reject) => {
|
|
17685
|
+
const onAbort = () => {
|
|
17686
|
+
loggerDahua.info(`[${site}]-[${host}] Abort triggered. Cleaning up...`);
|
|
17687
|
+
if (response.res && !response.res.destroyed) {
|
|
17688
|
+
response.res.destroy();
|
|
17689
|
+
}
|
|
17690
|
+
resolve("aborted");
|
|
17691
|
+
};
|
|
17692
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
17693
|
+
response.res.on("data", (chunk) => {
|
|
17694
|
+
if (signal.aborted) {
|
|
17695
|
+
response.res.destroy();
|
|
17696
|
+
return;
|
|
17697
|
+
}
|
|
17698
|
+
bufferQueue.enqueue(chunk);
|
|
17699
|
+
});
|
|
17700
|
+
response.res.on("end", () => {
|
|
17701
|
+
signal.removeEventListener("abort", onAbort);
|
|
17702
|
+
resolve("ended");
|
|
17703
|
+
});
|
|
17704
|
+
response.res.on("close", () => {
|
|
17705
|
+
signal.removeEventListener("abort", onAbort);
|
|
17706
|
+
resolve("closed");
|
|
17707
|
+
});
|
|
17708
|
+
response.res.on("error", (err) => {
|
|
17709
|
+
signal.removeEventListener("abort", onAbort);
|
|
17710
|
+
reject(err);
|
|
17711
|
+
});
|
|
17712
|
+
});
|
|
17713
|
+
} catch (error) {
|
|
17714
|
+
if (signal.aborted || error.name === "AbortError" || error.code === "UND_ERR_ABORTED") {
|
|
17715
|
+
loggerDahua.info(`[${host}] Connection closed by system (Abort).`);
|
|
17716
|
+
break;
|
|
17717
|
+
}
|
|
17718
|
+
loggerDahua.error(
|
|
17719
|
+
`[${host}] Connection lost or error: ${error.message || error}. Retrying in 5s...`
|
|
17720
|
+
);
|
|
17721
|
+
} finally {
|
|
17722
|
+
if (bufferQueue?.destroy) {
|
|
17723
|
+
try {
|
|
17724
|
+
bufferQueue.destroy();
|
|
17725
|
+
} catch (e) {
|
|
17726
|
+
loggerDahua.error(`[${host}] Error destroying buffer queue:`, e);
|
|
17727
|
+
}
|
|
17728
|
+
}
|
|
17729
|
+
if (response?.res && typeof response.res.destroy === "function" && !response.res.destroyed) {
|
|
17730
|
+
try {
|
|
17731
|
+
response.res.on("error", () => {
|
|
17732
|
+
loggerDahua.error(`[${host}] Stream error during cleanup, likely already closed.`);
|
|
17733
|
+
});
|
|
17734
|
+
response.res.destroy();
|
|
17735
|
+
} catch (err) {
|
|
17736
|
+
loggerDahua.debug(`Cleanup: stream already closing: ${err?.message}`);
|
|
17737
|
+
}
|
|
17738
|
+
}
|
|
17739
|
+
}
|
|
17740
|
+
if (!signal.aborted) {
|
|
17741
|
+
await new Promise((res) => setTimeout(res, 5e3));
|
|
17742
|
+
}
|
|
17743
|
+
}
|
|
17744
|
+
loggerDahua.info(`[${host}] ANPR Listener stopped.`);
|
|
17745
|
+
}
|
|
17558
17746
|
async function addPlateNumber(value) {
|
|
17559
17747
|
const validation = Joi40.object({
|
|
17560
17748
|
host: Joi40.string().required(),
|
|
@@ -17763,6 +17951,8 @@ function useSiteCameraRepo() {
|
|
|
17763
17951
|
try {
|
|
17764
17952
|
value = MSiteCamera(value);
|
|
17765
17953
|
const res = await collection.insertOne(value, { session });
|
|
17954
|
+
const { listenToCamera } = useDahuaService();
|
|
17955
|
+
await listenToCamera({ ...value, _id: res.insertedId });
|
|
17766
17956
|
delCachedData();
|
|
17767
17957
|
return res.insertedId;
|
|
17768
17958
|
} catch (error) {
|
|
@@ -19618,7 +19808,8 @@ function useVehicleController() {
|
|
|
19618
19808
|
getVehicles: _getVehicles,
|
|
19619
19809
|
getVehicleById: _getVehicleById,
|
|
19620
19810
|
getVehiclesByNRIC: _getVehiclesByNRIC,
|
|
19621
|
-
getAllVehiclesByUnitId: _getAllVehiclesByUnitId
|
|
19811
|
+
getAllVehiclesByUnitId: _getAllVehiclesByUnitId,
|
|
19812
|
+
getSpecificVehicleById: _getSpecificVehicleById
|
|
19622
19813
|
} = useVehicleRepo();
|
|
19623
19814
|
function normalizeRow(row) {
|
|
19624
19815
|
return Object.fromEntries(
|
|
@@ -19732,7 +19923,9 @@ function useVehicleController() {
|
|
|
19732
19923
|
return;
|
|
19733
19924
|
}
|
|
19734
19925
|
const headerRow = worksheet.getRow(1);
|
|
19735
|
-
const headers = (headerRow.values || []).slice(1).map(
|
|
19926
|
+
const headers = (headerRow.values || []).slice(1).map(
|
|
19927
|
+
(header) => String(header ?? "").trim().replace(/\(.*\)/, "").trim()
|
|
19928
|
+
);
|
|
19736
19929
|
worksheet.eachRow((row, rowNumber) => {
|
|
19737
19930
|
if (rowNumber === 1)
|
|
19738
19931
|
return;
|
|
@@ -19749,7 +19942,11 @@ function useVehicleController() {
|
|
|
19749
19942
|
} else if (lowerName.endsWith(".csv")) {
|
|
19750
19943
|
rows = await new Promise((resolve, reject) => {
|
|
19751
19944
|
const parsed = [];
|
|
19752
|
-
fs.createReadStream(path4).pipe(csv()).on("
|
|
19945
|
+
fs.createReadStream(path4).pipe(csv()).on("headers", (headers) => {
|
|
19946
|
+
headers = headers.map(
|
|
19947
|
+
(h) => h.trim().replace(/\(.*\)/, "").trim()
|
|
19948
|
+
);
|
|
19949
|
+
}).on("data", (row) => parsed.push(row)).on("end", () => resolve(parsed)).on("error", reject);
|
|
19753
19950
|
});
|
|
19754
19951
|
} else {
|
|
19755
19952
|
next(
|
|
@@ -19914,6 +20111,31 @@ function useVehicleController() {
|
|
|
19914
20111
|
return;
|
|
19915
20112
|
}
|
|
19916
20113
|
}
|
|
20114
|
+
async function getSpecificVehicleById(req, res, next) {
|
|
20115
|
+
const schema2 = Joi46.object({
|
|
20116
|
+
_id: Joi46.string().hex().length(24).required()
|
|
20117
|
+
});
|
|
20118
|
+
const { error, value } = schema2.validate(
|
|
20119
|
+
{ _id: req.params.id },
|
|
20120
|
+
{ abortEarly: false }
|
|
20121
|
+
);
|
|
20122
|
+
if (error) {
|
|
20123
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
20124
|
+
logger65.log({ level: "error", message: messages });
|
|
20125
|
+
next(new BadRequestError84(messages));
|
|
20126
|
+
return;
|
|
20127
|
+
}
|
|
20128
|
+
const { _id } = value;
|
|
20129
|
+
try {
|
|
20130
|
+
const site = await _getSpecificVehicleById(_id);
|
|
20131
|
+
res.json(site);
|
|
20132
|
+
return;
|
|
20133
|
+
} catch (error2) {
|
|
20134
|
+
logger65.log({ level: "error", message: error2.message });
|
|
20135
|
+
next(error2);
|
|
20136
|
+
return;
|
|
20137
|
+
}
|
|
20138
|
+
}
|
|
19917
20139
|
async function updateVehicleById(req, res, next) {
|
|
19918
20140
|
try {
|
|
19919
20141
|
const schema2 = Joi46.object({
|
|
@@ -19929,7 +20151,9 @@ function useVehicleController() {
|
|
|
19929
20151
|
start: Joi46.string().isoDate().optional().allow(null, ""),
|
|
19930
20152
|
end: Joi46.string().isoDate().optional().allow(null, ""),
|
|
19931
20153
|
recNo: Joi46.string().optional().allow(null, ""),
|
|
19932
|
-
type: Joi46.string().optional().valid(...Object.values(VehicleType)).allow(null, "")
|
|
20154
|
+
type: Joi46.string().optional().valid(...Object.values(VehicleType)).allow(null, ""),
|
|
20155
|
+
peopleId: Joi46.string().hex().length(24).optional().allow(null, ""),
|
|
20156
|
+
seasonPassType: Joi46.string().optional().allow("", null)
|
|
19933
20157
|
});
|
|
19934
20158
|
const { error, value } = schema2.validate(
|
|
19935
20159
|
{
|
|
@@ -20131,7 +20355,8 @@ function useVehicleController() {
|
|
|
20131
20355
|
getVehiclesByNRIC,
|
|
20132
20356
|
reactivateVehicleById,
|
|
20133
20357
|
getAllVehiclesByUnitId,
|
|
20134
|
-
uploadSpreadsheetVehicles
|
|
20358
|
+
uploadSpreadsheetVehicles,
|
|
20359
|
+
getSpecificVehicleById
|
|
20135
20360
|
};
|
|
20136
20361
|
}
|
|
20137
20362
|
|
|
@@ -20166,7 +20391,7 @@ function useSiteCameraService() {
|
|
|
20166
20391
|
session.endSession();
|
|
20167
20392
|
}
|
|
20168
20393
|
}
|
|
20169
|
-
async function listenToCapturedPlateNumber() {
|
|
20394
|
+
async function listenToCapturedPlateNumber(onDetected) {
|
|
20170
20395
|
const siteCameras = [];
|
|
20171
20396
|
let page = 1;
|
|
20172
20397
|
let pages = 1;
|
|
@@ -20187,7 +20412,7 @@ function useSiteCameraService() {
|
|
|
20187
20412
|
for (let index = 0; index < siteCameras.length; index++) {
|
|
20188
20413
|
const siteCamera = siteCameras[index];
|
|
20189
20414
|
if (siteCamera && siteCamera.status === "active" && siteCamera.host && siteCamera.username && siteCamera.password && siteCamera.site && siteCamera.guardPost) {
|
|
20190
|
-
dahuaService.listenToCamera(siteCamera);
|
|
20415
|
+
dahuaService.listenToCamera(siteCamera, onDetected);
|
|
20191
20416
|
}
|
|
20192
20417
|
}
|
|
20193
20418
|
}
|
|
@@ -23277,6 +23502,12 @@ function useVisitorTransactionService() {
|
|
|
23277
23502
|
const parsed = new Date(value.checkOut);
|
|
23278
23503
|
value.checkOut = isNaN(parsed.getTime()) ? null : parsed;
|
|
23279
23504
|
}
|
|
23505
|
+
if (value.site) {
|
|
23506
|
+
value.site = typeof value.site === "string" ? new ObjectId59(value.site) : value.site;
|
|
23507
|
+
}
|
|
23508
|
+
if (value.unit) {
|
|
23509
|
+
value.unit = typeof value.unit === "string" ? new ObjectId59(value.unit) : value.unit;
|
|
23510
|
+
}
|
|
23280
23511
|
await _updateVisitorTansactionById(id, value, session);
|
|
23281
23512
|
await session?.commitTransaction();
|
|
23282
23513
|
return "Successfully updated visitor transaction.";
|
|
@@ -25356,11 +25587,7 @@ function usePatrolQuestionRepo() {
|
|
|
25356
25587
|
const { delNamespace, getCache, setCache } = useCache34(namespace_collection);
|
|
25357
25588
|
async function createIndexes() {
|
|
25358
25589
|
try {
|
|
25359
|
-
await collection.createIndexes([
|
|
25360
|
-
{
|
|
25361
|
-
key: { site: 1 }
|
|
25362
|
-
}
|
|
25363
|
-
]);
|
|
25590
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
25364
25591
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
25365
25592
|
} catch (error) {
|
|
25366
25593
|
logger87.log({
|
|
@@ -25805,6 +26032,24 @@ function usePatrolRouteRepo() {
|
|
|
25805
26032
|
const namespace_collection = "patrol.route";
|
|
25806
26033
|
const collection = db.collection(namespace_collection);
|
|
25807
26034
|
const { delNamespace, getCache, setCache } = useCache35(namespace_collection);
|
|
26035
|
+
async function createIndexes() {
|
|
26036
|
+
try {
|
|
26037
|
+
await collection.createIndexes([
|
|
26038
|
+
{ key: { site: 1, status: 1 } },
|
|
26039
|
+
{ key: { site: 1, repeat: 1 } },
|
|
26040
|
+
{ key: { assignee: 1 } }
|
|
26041
|
+
]);
|
|
26042
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
26043
|
+
} catch (error) {
|
|
26044
|
+
logger90.log({
|
|
26045
|
+
level: "error",
|
|
26046
|
+
message: error.message
|
|
26047
|
+
});
|
|
26048
|
+
throw new InternalServerError36(
|
|
26049
|
+
"Failed to create general indexes on patrol routes."
|
|
26050
|
+
);
|
|
26051
|
+
}
|
|
26052
|
+
}
|
|
25808
26053
|
async function createTextIndex() {
|
|
25809
26054
|
try {
|
|
25810
26055
|
await collection.createIndex({
|
|
@@ -26102,7 +26347,7 @@ function usePatrolRouteRepo() {
|
|
|
26102
26347
|
id: "$_id",
|
|
26103
26348
|
start: startOfDay,
|
|
26104
26349
|
end: endOfDay,
|
|
26105
|
-
site: new ObjectId67(site)
|
|
26350
|
+
site: ObjectId67.isValid(site) ? new ObjectId67(site) : null
|
|
26106
26351
|
},
|
|
26107
26352
|
pipeline: [
|
|
26108
26353
|
{
|
|
@@ -26133,10 +26378,8 @@ function usePatrolRouteRepo() {
|
|
|
26133
26378
|
{ $skip: page * limit },
|
|
26134
26379
|
{ $limit: limit }
|
|
26135
26380
|
];
|
|
26136
|
-
const
|
|
26137
|
-
|
|
26138
|
-
collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
|
|
26139
|
-
]);
|
|
26381
|
+
const items = await collection.aggregate(basePipeline, { session }).toArray();
|
|
26382
|
+
const countResult = await collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray();
|
|
26140
26383
|
const totalCount = countResult[0]?.total || 0;
|
|
26141
26384
|
const data = paginate28(items, page, limit, totalCount);
|
|
26142
26385
|
setCache(cacheKey, data, 15 * 60).then(() => logger90.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
@@ -26144,6 +26387,7 @@ function usePatrolRouteRepo() {
|
|
|
26144
26387
|
);
|
|
26145
26388
|
return data;
|
|
26146
26389
|
} catch (error) {
|
|
26390
|
+
console.error("[getScheduledRoute] ERROR:", error?.message, error?.stack);
|
|
26147
26391
|
throw error;
|
|
26148
26392
|
}
|
|
26149
26393
|
}
|
|
@@ -26178,7 +26422,8 @@ function usePatrolRouteRepo() {
|
|
|
26178
26422
|
updateById,
|
|
26179
26423
|
deleteById,
|
|
26180
26424
|
getScheduledRoute,
|
|
26181
|
-
getById
|
|
26425
|
+
getById,
|
|
26426
|
+
createIndexes
|
|
26182
26427
|
};
|
|
26183
26428
|
}
|
|
26184
26429
|
|
|
@@ -26429,6 +26674,7 @@ var schemaPatrolLog = Joi65.object({
|
|
|
26429
26674
|
cameras: Joi65.array().items(schemeLogCamera).required(),
|
|
26430
26675
|
status: Joi65.array().items(Joi65.string().valid("complete", "late", "incomplete")).required(),
|
|
26431
26676
|
incidentReport: incidentReportLog,
|
|
26677
|
+
platform: Joi65.string().valid("web", "mobile").optional().allow(null, ""),
|
|
26432
26678
|
createdAt: Joi65.date().optional(),
|
|
26433
26679
|
updatedAt: Joi65.date().optional(),
|
|
26434
26680
|
deletedAt: Joi65.date().optional()
|
|
@@ -26442,7 +26688,8 @@ var schemaUpdatePatrolLog = Joi65.object({
|
|
|
26442
26688
|
end: Joi65.string().optional().allow(null, ""),
|
|
26443
26689
|
cameras: Joi65.array().items(schemeLogCamera).optional().allow(null, ""),
|
|
26444
26690
|
status: Joi65.array().items(Joi65.string().valid("complete", "late", "incomplete")).optional().allow(null, ""),
|
|
26445
|
-
incidentReport: incidentReportLog
|
|
26691
|
+
incidentReport: incidentReportLog,
|
|
26692
|
+
platform: Joi65.string().valid("web", "mobile").optional().allow(null, "")
|
|
26446
26693
|
});
|
|
26447
26694
|
function MPatrolLog(value) {
|
|
26448
26695
|
const { error } = schemaPatrolLog.validate(value);
|
|
@@ -26496,6 +26743,7 @@ function MPatrolLog(value) {
|
|
|
26496
26743
|
status: value.status ?? [],
|
|
26497
26744
|
route: value.route,
|
|
26498
26745
|
incidentReport: value.incidentReport,
|
|
26746
|
+
platForm: value.platform ?? "",
|
|
26499
26747
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
26500
26748
|
updatedAt: value.updatedAt ?? "",
|
|
26501
26749
|
deletedAt: value.deletedAt ?? ""
|
|
@@ -26525,9 +26773,8 @@ function usePatrolLogRepo() {
|
|
|
26525
26773
|
async function createIndexes() {
|
|
26526
26774
|
try {
|
|
26527
26775
|
await collection.createIndexes([
|
|
26528
|
-
{
|
|
26529
|
-
|
|
26530
|
-
}
|
|
26776
|
+
{ key: { site: 1, createdAt: -1 } },
|
|
26777
|
+
{ key: { assignee: 1 } }
|
|
26531
26778
|
]);
|
|
26532
26779
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
26533
26780
|
} catch (error) {
|
|
@@ -26863,6 +27110,7 @@ function usePatrolLogService() {
|
|
|
26863
27110
|
}
|
|
26864
27111
|
}
|
|
26865
27112
|
}
|
|
27113
|
+
value.platform = value.platform === "web" ? "web" : "mobile";
|
|
26866
27114
|
const result = await _add(value, session);
|
|
26867
27115
|
await session.commitTransaction();
|
|
26868
27116
|
return result;
|
|
@@ -30418,6 +30666,20 @@ function useSiteBillingItemRepo() {
|
|
|
30418
30666
|
const namespace_collection = "site.billing.items";
|
|
30419
30667
|
const collection = db.collection(namespace_collection);
|
|
30420
30668
|
const { delNamespace, setCache, getCache } = useCache42(namespace_collection);
|
|
30669
|
+
async function createIndexes() {
|
|
30670
|
+
try {
|
|
30671
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
30672
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
30673
|
+
} catch (error) {
|
|
30674
|
+
logger107.log({
|
|
30675
|
+
level: "error",
|
|
30676
|
+
message: error.message
|
|
30677
|
+
});
|
|
30678
|
+
throw new InternalServerError43(
|
|
30679
|
+
"Failed to create general indexes on billing item."
|
|
30680
|
+
);
|
|
30681
|
+
}
|
|
30682
|
+
}
|
|
30421
30683
|
async function createTextIndex() {
|
|
30422
30684
|
try {
|
|
30423
30685
|
await collection.createIndex({
|
|
@@ -30637,7 +30899,8 @@ function useSiteBillingItemRepo() {
|
|
|
30637
30899
|
getAll,
|
|
30638
30900
|
getById,
|
|
30639
30901
|
updateById,
|
|
30640
|
-
deleteById
|
|
30902
|
+
deleteById,
|
|
30903
|
+
createIndexes
|
|
30641
30904
|
};
|
|
30642
30905
|
}
|
|
30643
30906
|
|
|
@@ -30791,6 +31054,20 @@ function useSiteBillingConfigurationRepo() {
|
|
|
30791
31054
|
const namespace_collection = "site.billing.configuration";
|
|
30792
31055
|
const collection = db.collection(namespace_collection);
|
|
30793
31056
|
const { delNamespace, setCache, getCache } = useCache43(namespace_collection);
|
|
31057
|
+
async function createIndexes() {
|
|
31058
|
+
try {
|
|
31059
|
+
await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
|
|
31060
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
31061
|
+
} catch (error) {
|
|
31062
|
+
logger109.log({
|
|
31063
|
+
level: "error",
|
|
31064
|
+
message: error.message
|
|
31065
|
+
});
|
|
31066
|
+
throw new InternalServerError44(
|
|
31067
|
+
"Failed to create general indexes on billing configuration."
|
|
31068
|
+
);
|
|
31069
|
+
}
|
|
31070
|
+
}
|
|
30794
31071
|
async function createTextIndex() {
|
|
30795
31072
|
try {
|
|
30796
31073
|
await collection.createIndex({
|
|
@@ -31000,7 +31277,8 @@ function useSiteBillingConfigurationRepo() {
|
|
|
31000
31277
|
getAll,
|
|
31001
31278
|
getById,
|
|
31002
31279
|
updateById,
|
|
31003
|
-
deleteById
|
|
31280
|
+
deleteById,
|
|
31281
|
+
createIndexes
|
|
31004
31282
|
};
|
|
31005
31283
|
}
|
|
31006
31284
|
|
|
@@ -32303,6 +32581,25 @@ function useSiteUnitBillingRepo() {
|
|
|
32303
32581
|
const namespace_collection = "site.unit.billing";
|
|
32304
32582
|
const collection = db.collection(namespace_collection);
|
|
32305
32583
|
const { delNamespace, setCache, getCache } = useCache45(namespace_collection);
|
|
32584
|
+
async function createIndexes() {
|
|
32585
|
+
try {
|
|
32586
|
+
await collection.createIndexes([
|
|
32587
|
+
{ key: { site: 1, status: 1, paymentStatus: 1 } },
|
|
32588
|
+
{ key: { site: 1, unitId: 1, status: 1, paymentStatus: 1 } },
|
|
32589
|
+
{ key: { site: 1, unitId: 1, issueDate: 1 } },
|
|
32590
|
+
{ key: { createdAt: -1 } }
|
|
32591
|
+
]);
|
|
32592
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
32593
|
+
} catch (error) {
|
|
32594
|
+
logger117.log({
|
|
32595
|
+
level: "error",
|
|
32596
|
+
message: error.message
|
|
32597
|
+
});
|
|
32598
|
+
throw new InternalServerError46(
|
|
32599
|
+
"Failed to create general indexes on unit billing."
|
|
32600
|
+
);
|
|
32601
|
+
}
|
|
32602
|
+
}
|
|
32306
32603
|
async function createTextIndex() {
|
|
32307
32604
|
try {
|
|
32308
32605
|
await collection.createIndex({
|
|
@@ -32856,7 +33153,8 @@ function useSiteUnitBillingRepo() {
|
|
|
32856
33153
|
deleteById,
|
|
32857
33154
|
getUnitBillingBySite,
|
|
32858
33155
|
getResidentUserBilling,
|
|
32859
|
-
getResidentUserUnsettledBilling
|
|
33156
|
+
getResidentUserUnsettledBilling,
|
|
33157
|
+
createIndexes
|
|
32860
33158
|
};
|
|
32861
33159
|
}
|
|
32862
33160
|
|
|
@@ -38714,6 +39012,22 @@ function useStatementOfAccountRepo() {
|
|
|
38714
39012
|
const namespace_collection = "site.statement-of-accounts";
|
|
38715
39013
|
const collection = db.collection(namespace_collection);
|
|
38716
39014
|
const { delNamespace, getCache, setCache } = useCache50(namespace_collection);
|
|
39015
|
+
async function createIndexes() {
|
|
39016
|
+
try {
|
|
39017
|
+
await collection.createIndexes([
|
|
39018
|
+
{ key: { site: 1, status: 1 } },
|
|
39019
|
+
{ key: { site: 1, unitId: 1, status: 1 } },
|
|
39020
|
+
{ key: { createdAt: -1 } }
|
|
39021
|
+
]);
|
|
39022
|
+
return `Successfully created indexes for ${namespace_collection}.`;
|
|
39023
|
+
} catch (error) {
|
|
39024
|
+
logger128.log({
|
|
39025
|
+
level: "error",
|
|
39026
|
+
message: error.message
|
|
39027
|
+
});
|
|
39028
|
+
throw new InternalServerError51("Failed to create general indexes on SOA.");
|
|
39029
|
+
}
|
|
39030
|
+
}
|
|
38717
39031
|
async function createTextIndex() {
|
|
38718
39032
|
try {
|
|
38719
39033
|
await collection.createIndex({
|
|
@@ -39064,7 +39378,8 @@ function useStatementOfAccountRepo() {
|
|
|
39064
39378
|
deleteById,
|
|
39065
39379
|
updateStatusById,
|
|
39066
39380
|
getResidentUserSoa,
|
|
39067
|
-
reviewSOA
|
|
39381
|
+
reviewSOA,
|
|
39382
|
+
createIndexes
|
|
39068
39383
|
};
|
|
39069
39384
|
}
|
|
39070
39385
|
|
|
@@ -41032,6 +41347,7 @@ var schemaIncidentReport = Joi99.object({
|
|
|
41032
41347
|
approvedBy: Joi99.string().hex().allow(null, "").optional(),
|
|
41033
41348
|
approvedByName: Joi99.string().optional().allow("", null),
|
|
41034
41349
|
remarks: Joi99.string().optional().allow("", null),
|
|
41350
|
+
platform: Joi99.string().valid("web", "mobile").optional().allow(null, ""),
|
|
41035
41351
|
status: Joi99.string().valid("pending", "approved", "rejected").default("pending")
|
|
41036
41352
|
});
|
|
41037
41353
|
var schemaUpdateIncidentReport = Joi99.object({
|
|
@@ -41112,6 +41428,7 @@ var schemaUpdateIncidentReport = Joi99.object({
|
|
|
41112
41428
|
approvedBy: Joi99.string().hex().allow(null, "").optional(),
|
|
41113
41429
|
approvedByName: Joi99.string().optional().allow("", null),
|
|
41114
41430
|
remarks: Joi99.string().optional().allow("", null),
|
|
41431
|
+
platform: Joi99.string().valid("web", "mobile").optional().allow(null, ""),
|
|
41115
41432
|
status: Joi99.string().valid("pending", "approved", "rejected").default("pending")
|
|
41116
41433
|
});
|
|
41117
41434
|
function MIncidentReport(value) {
|
|
@@ -41173,6 +41490,7 @@ function MIncidentReport(value) {
|
|
|
41173
41490
|
approvedByName: value.approvedByName ?? "",
|
|
41174
41491
|
remarks: value.remarks ?? null,
|
|
41175
41492
|
status: value.status ?? "pending",
|
|
41493
|
+
platForm: value.platform ?? "",
|
|
41176
41494
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
41177
41495
|
updatedAt: value.updatedAt,
|
|
41178
41496
|
deletedAt: value.deletedAt
|
|
@@ -41651,6 +41969,7 @@ function useIncidentReportService() {
|
|
|
41651
41969
|
}
|
|
41652
41970
|
}
|
|
41653
41971
|
}
|
|
41972
|
+
value.platform = value.platform === "web" ? "web" : "mobile";
|
|
41654
41973
|
const result = await _add(value, session);
|
|
41655
41974
|
await session?.commitTransaction();
|
|
41656
41975
|
return result;
|
|
@@ -42689,7 +43008,10 @@ function useOccurrenceEntryService() {
|
|
|
42689
43008
|
updateOccurrenceEntryById: _updateOccurrenceEntryById,
|
|
42690
43009
|
getOccurrenceEntryById: _getOccurrenceEntryById,
|
|
42691
43010
|
getOccurrenceEntryByBookId: _getOccurrenceEntryByBookId,
|
|
42692
|
-
updateOccurrenceEntryByBookId: _updateOccurrenceEntryByBookId
|
|
43011
|
+
updateOccurrenceEntryByBookId: _updateOccurrenceEntryByBookId,
|
|
43012
|
+
deleteOccurrenceEntryById: _deleteOccurrenceEntryById,
|
|
43013
|
+
getLatestSerialNumber: _getLatestSerialNumber,
|
|
43014
|
+
getLatestSerialNumberInGroup: _getLatestSerialNumberInGroup
|
|
42693
43015
|
} = useOccurrenceEntryRepo();
|
|
42694
43016
|
const {
|
|
42695
43017
|
getOccurrenceBookById: _getOccurrenceBookById,
|
|
@@ -42741,8 +43063,25 @@ function useOccurrenceEntryService() {
|
|
|
42741
43063
|
if (!occurrenceEntry) {
|
|
42742
43064
|
throw new Error("Occurrence entry not found.");
|
|
42743
43065
|
}
|
|
42744
|
-
|
|
42745
|
-
|
|
43066
|
+
if (value.incidentReportId) {
|
|
43067
|
+
await _updateOccurrenceEntryById(id, value, session);
|
|
43068
|
+
await session?.commitTransaction();
|
|
43069
|
+
return "Successfully updated occurrence entry (incident report).";
|
|
43070
|
+
}
|
|
43071
|
+
const entryCount = await _getLatestSerialNumberInGroup(
|
|
43072
|
+
occurrenceEntry.dailyOccurrenceBookId,
|
|
43073
|
+
Number(occurrenceEntry.serialNumber)
|
|
43074
|
+
);
|
|
43075
|
+
const currentSerial = Number(occurrenceEntry.serialNumber);
|
|
43076
|
+
const latestSerial = Number(entryCount);
|
|
43077
|
+
const currentGroup = Math.floor(currentSerial);
|
|
43078
|
+
const latestGroup = Math.floor(latestSerial);
|
|
43079
|
+
let updatedSerialNumber;
|
|
43080
|
+
if (currentGroup === latestGroup) {
|
|
43081
|
+
updatedSerialNumber = (latestSerial + 0.1).toFixed(1);
|
|
43082
|
+
} else {
|
|
43083
|
+
updatedSerialNumber = (currentSerial + 0.1).toFixed(1);
|
|
43084
|
+
}
|
|
42746
43085
|
const dobId = occurrenceEntry.dailyOccurrenceBookId;
|
|
42747
43086
|
const book = await _getOccurrenceBookById(dobId);
|
|
42748
43087
|
const subject = await _getOccurrenceSubjectById(
|
|
@@ -42761,6 +43100,8 @@ function useOccurrenceEntryService() {
|
|
|
42761
43100
|
value.date = value.date ? value.date : occurrenceEntry.date;
|
|
42762
43101
|
value.userName = value.userName ? value.userName : occurrenceEntry.signature.name;
|
|
42763
43102
|
value.createdByName = value.createdByName ? value.createdByName : occurrenceEntry.createdByName;
|
|
43103
|
+
if (occurrenceEntry.incidentReportId)
|
|
43104
|
+
value.incidentReportId = occurrenceEntry.incidentReportId;
|
|
42764
43105
|
await _updateOccurrenceBookById(dobId, {
|
|
42765
43106
|
totalInput: book.totalInput + 1
|
|
42766
43107
|
});
|
|
@@ -45237,7 +45578,9 @@ function useManpowerMonitoringRepo() {
|
|
|
45237
45578
|
{
|
|
45238
45579
|
key: { siteId: 1 }
|
|
45239
45580
|
},
|
|
45240
|
-
{ key: { createdAt: 1 } }
|
|
45581
|
+
{ key: { createdAt: 1 } },
|
|
45582
|
+
{ key: { siteId: 1, serviceProviderId: 1 } },
|
|
45583
|
+
{ key: { siteName: 1 } }
|
|
45241
45584
|
]);
|
|
45242
45585
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45243
45586
|
} catch (error) {
|
|
@@ -45506,7 +45849,9 @@ function useManpowerRemarksRepo() {
|
|
|
45506
45849
|
{
|
|
45507
45850
|
key: { siteId: 1 }
|
|
45508
45851
|
},
|
|
45509
|
-
{ key: { createdAt: 1 } }
|
|
45852
|
+
{ key: { createdAt: 1 } },
|
|
45853
|
+
{ key: { siteId: 1, serviceProviderId: 1, createdAtSGT: 1 } },
|
|
45854
|
+
{ key: { serviceProviderId: 1, status: 1, createdAtSGT: 1 } }
|
|
45510
45855
|
]);
|
|
45511
45856
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45512
45857
|
} catch (error) {
|
|
@@ -45939,7 +46284,8 @@ function useManpowerDesignationRepo() {
|
|
|
45939
46284
|
{
|
|
45940
46285
|
key: { siteId: 1 }
|
|
45941
46286
|
},
|
|
45942
|
-
{ key: { createdAt: 1 } }
|
|
46287
|
+
{ key: { createdAt: 1 } },
|
|
46288
|
+
{ key: { siteId: 1, serviceProviderId: 1 } }
|
|
45943
46289
|
]);
|
|
45944
46290
|
return `Successfully created indexes for ${namespace_collection}.`;
|
|
45945
46291
|
} catch (error) {
|
|
@@ -51458,6 +51804,7 @@ export {
|
|
|
51458
51804
|
vehicles_namespace_collection,
|
|
51459
51805
|
visitors_namespace_collection,
|
|
51460
51806
|
workOrderSchema,
|
|
51807
|
+
work_orders2_namespace_collection,
|
|
51461
51808
|
work_orders_namespace_collection
|
|
51462
51809
|
};
|
|
51463
51810
|
//# sourceMappingURL=index.mjs.map
|