@7365admin1/core 2.49.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 +6 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +132 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +132 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2187,6 +2187,7 @@ declare function useVehicleRepo(): {
|
|
|
2187
2187
|
[key: number]: any;
|
|
2188
2188
|
};
|
|
2189
2189
|
}>;
|
|
2190
|
+
getSpecificVehicleById: (_id: string | ObjectId) => Promise<mongodb.WithId<bson.Document>>;
|
|
2190
2191
|
};
|
|
2191
2192
|
|
|
2192
2193
|
declare function formatDahuaDate(date: Date): string;
|
|
@@ -2233,6 +2234,7 @@ declare function useVehicleController(): {
|
|
|
2233
2234
|
reactivateVehicleById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2234
2235
|
getAllVehiclesByUnitId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2235
2236
|
uploadSpreadsheetVehicles: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2237
|
+
getSpecificVehicleById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
2236
2238
|
};
|
|
2237
2239
|
|
|
2238
2240
|
declare function useSiteCameraRepo(): {
|
|
@@ -2701,7 +2703,7 @@ declare function useVisitorTransactionRepo(): {
|
|
|
2701
2703
|
pageRange: string;
|
|
2702
2704
|
}>;
|
|
2703
2705
|
getOpenByPlateNumber: (plateNumber: string, site: string | ObjectId) => Promise<TVisitorTransaction | null>;
|
|
2704
|
-
updateById: (_id: string | ObjectId, value: Partial<TVisitorTransaction>, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
2706
|
+
updateById: (_id: string | ObjectId, value: Partial<TVisitorTransaction>, session?: ClientSession, isNotManualCheckOut?: boolean) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
2705
2707
|
deleteVisitorTransaction: (_id: string | ObjectId) => Promise<number>;
|
|
2706
2708
|
createTextIndex: () => Promise<void>;
|
|
2707
2709
|
getDeliveryPickupTransactions: () => Promise<mongodb.WithId<bson.Document>[]>;
|
|
@@ -3114,6 +3116,7 @@ type TPatrolLog = {
|
|
|
3114
3116
|
cameras: Array<logCamera>;
|
|
3115
3117
|
status: Array<string>;
|
|
3116
3118
|
incidentReport: incidentReport;
|
|
3119
|
+
platform?: string;
|
|
3117
3120
|
createdAt?: Date | string;
|
|
3118
3121
|
updatedAt?: Date | string;
|
|
3119
3122
|
deletedAt?: Date | string;
|
|
@@ -3133,6 +3136,7 @@ declare function MPatrolLog(value: TPatrolLog): {
|
|
|
3133
3136
|
status: string[];
|
|
3134
3137
|
route: string | ObjectId | undefined;
|
|
3135
3138
|
incidentReport: incidentReport;
|
|
3139
|
+
platForm: string;
|
|
3136
3140
|
createdAt: string | Date;
|
|
3137
3141
|
updatedAt: string | Date;
|
|
3138
3142
|
deletedAt: string | Date;
|
|
@@ -5300,6 +5304,7 @@ type TIncidentReport = {
|
|
|
5300
5304
|
approvedByName?: string;
|
|
5301
5305
|
remarks?: string | null;
|
|
5302
5306
|
status: "pending" | "approved" | "rejected";
|
|
5307
|
+
platform?: string;
|
|
5303
5308
|
createdAt?: string | Date;
|
|
5304
5309
|
updatedAt?: string | Date;
|
|
5305
5310
|
deletedAt?: string | Date;
|
|
@@ -5321,6 +5326,7 @@ declare function MIncidentReport(value: TIncidentReport): {
|
|
|
5321
5326
|
approvedByName: string;
|
|
5322
5327
|
remarks: string | null;
|
|
5323
5328
|
status: "pending" | "approved" | "rejected";
|
|
5329
|
+
platForm: string;
|
|
5324
5330
|
createdAt: string | Date;
|
|
5325
5331
|
updatedAt: string | Date | undefined;
|
|
5326
5332
|
deletedAt: string | Date | undefined;
|
|
@@ -5502,7 +5508,7 @@ declare function useOccurrenceEntryRepo(): {
|
|
|
5502
5508
|
|
|
5503
5509
|
declare function useOccurrenceEntryService(): {
|
|
5504
5510
|
add: (value: TOccurrenceEntry) => Promise<string>;
|
|
5505
|
-
updateOccurrenceEntryById: (id: string | ObjectId, value: TOccurrenceEntry) => Promise<
|
|
5511
|
+
updateOccurrenceEntryById: (id: string | ObjectId, value: TOccurrenceEntry) => Promise<"Successfully updated occurrence entry (incident report)." | "Successfully updated daily occurrence entry.">;
|
|
5506
5512
|
};
|
|
5507
5513
|
|
|
5508
5514
|
declare function useOccurrenceEntryController(): {
|
package/dist/index.js
CHANGED
|
@@ -14045,14 +14045,14 @@ function useVisitorTransactionRepo() {
|
|
|
14045
14045
|
);
|
|
14046
14046
|
}
|
|
14047
14047
|
}
|
|
14048
|
-
async function updateById(_id, value, session) {
|
|
14048
|
+
async function updateById(_id, value, session, isNotManualCheckOut = true) {
|
|
14049
14049
|
try {
|
|
14050
14050
|
_id = new import_mongodb40.ObjectId(_id);
|
|
14051
14051
|
} catch (error) {
|
|
14052
14052
|
throw new import_node_server_utils68.BadRequestError("Invalid visitor transaction ID format.");
|
|
14053
14053
|
}
|
|
14054
14054
|
value.updatedAt = /* @__PURE__ */ new Date();
|
|
14055
|
-
if (value.checkOut) {
|
|
14055
|
+
if (value.checkOut && isNotManualCheckOut) {
|
|
14056
14056
|
value.manualCheckout = true;
|
|
14057
14057
|
}
|
|
14058
14058
|
try {
|
|
@@ -14803,6 +14803,22 @@ function useVehicleRepo() {
|
|
|
14803
14803
|
throw error;
|
|
14804
14804
|
}
|
|
14805
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
|
+
}
|
|
14806
14822
|
async function getByPlaceNumber(value) {
|
|
14807
14823
|
const { error } = import_joi38.default.string().required().validate(value);
|
|
14808
14824
|
if (error) {
|
|
@@ -15061,7 +15077,8 @@ function useVehicleRepo() {
|
|
|
15061
15077
|
deleteExpiredVehicles,
|
|
15062
15078
|
getAllVehiclesByUnitId,
|
|
15063
15079
|
getAllExpiredVehicles,
|
|
15064
|
-
bulkUpsertVehicles
|
|
15080
|
+
bulkUpsertVehicles,
|
|
15081
|
+
getSpecificVehicleById
|
|
15065
15082
|
};
|
|
15066
15083
|
}
|
|
15067
15084
|
|
|
@@ -17317,6 +17334,7 @@ var loggerDahua = winston.createLogger({
|
|
|
17317
17334
|
|
|
17318
17335
|
// src/services/dahua.service.ts
|
|
17319
17336
|
var cameraRegistry = /* @__PURE__ */ new Map();
|
|
17337
|
+
var _savedOnDetected;
|
|
17320
17338
|
function useDahuaDigest({
|
|
17321
17339
|
host = "",
|
|
17322
17340
|
username = "",
|
|
@@ -17381,7 +17399,7 @@ function useDahuaService() {
|
|
|
17381
17399
|
queue.push(buffer);
|
|
17382
17400
|
if (queue.length >= BACKPRESSURE_THRESHOLD && streamRef && !streamRef.isPaused()) {
|
|
17383
17401
|
loggerDahua.warn(
|
|
17384
|
-
`[${site}][${
|
|
17402
|
+
`[${site}][${host}] Queue at ${queue.length}/${MAX_QUEUE_SIZE}, pausing stream`
|
|
17385
17403
|
);
|
|
17386
17404
|
streamRef.pause();
|
|
17387
17405
|
}
|
|
@@ -17398,7 +17416,7 @@ function useDahuaService() {
|
|
|
17398
17416
|
streamRef.resume();
|
|
17399
17417
|
}
|
|
17400
17418
|
loggerDahua.info(
|
|
17401
|
-
`[${site}][${
|
|
17419
|
+
`[${site}][${host}] BufferQueue destroyed. Processed=${processedChunks}, Dropped=${droppedChunks}`
|
|
17402
17420
|
);
|
|
17403
17421
|
}
|
|
17404
17422
|
async function processNext(onDetected2) {
|
|
@@ -17446,9 +17464,9 @@ function useDahuaService() {
|
|
|
17446
17464
|
const transactionId = existingOpenTransaction?._id?.toString() || "";
|
|
17447
17465
|
if (existingOpenTransaction && !existingOpenTransaction.checkOut && transactionId) {
|
|
17448
17466
|
await updateById(transactionId, {
|
|
17449
|
-
checkOut:
|
|
17450
|
-
updatedAt:
|
|
17451
|
-
});
|
|
17467
|
+
checkOut: /* @__PURE__ */ new Date(),
|
|
17468
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
17469
|
+
}, void 0, false);
|
|
17452
17470
|
}
|
|
17453
17471
|
} catch (error) {
|
|
17454
17472
|
loggerDahua.error(
|
|
@@ -17507,7 +17525,7 @@ function useDahuaService() {
|
|
|
17507
17525
|
currentTransactionId = transactionId?.toString();
|
|
17508
17526
|
currentSnapshotField = "snapshotEntryImage";
|
|
17509
17527
|
if (onDetected2) {
|
|
17510
|
-
onDetected2({ _id: transactionId, site: result?.site?.toString(), plateNumber: result.plateNumber });
|
|
17528
|
+
onDetected2({ _id: transactionId, site: result?.site?.toString(), plateNumber: result.plateNumber, host, direction });
|
|
17511
17529
|
}
|
|
17512
17530
|
} catch (error) {
|
|
17513
17531
|
console.log("failed to create visitor transaction", error);
|
|
@@ -17516,8 +17534,7 @@ function useDahuaService() {
|
|
|
17516
17534
|
error
|
|
17517
17535
|
);
|
|
17518
17536
|
}
|
|
17519
|
-
}
|
|
17520
|
-
if (["exit", "both"].includes(designation) && direction.toLowerCase() === "leave" && plateNumber) {
|
|
17537
|
+
} else if (["exit", "both"].includes(designation) && direction.toLowerCase() === "leave" && plateNumber) {
|
|
17521
17538
|
const vehicle = await getVehicleByPlateNumber(plateNumber);
|
|
17522
17539
|
const existingOpenTransaction = await getOpenByPlateNumber(
|
|
17523
17540
|
plateNumber,
|
|
@@ -17539,6 +17556,9 @@ function useDahuaService() {
|
|
|
17539
17556
|
await removePlateNumber(dahuaPayload);
|
|
17540
17557
|
}
|
|
17541
17558
|
await closeOpenTransaction(plateNumber);
|
|
17559
|
+
if (onDetected2) {
|
|
17560
|
+
onDetected2({ reload: true, site: existingOpenTransaction?.site?.toString(), host, direction });
|
|
17561
|
+
}
|
|
17542
17562
|
}
|
|
17543
17563
|
}
|
|
17544
17564
|
}
|
|
@@ -17595,7 +17615,7 @@ function useDahuaService() {
|
|
|
17595
17615
|
try {
|
|
17596
17616
|
await import_fs.promises.mkdir(dir, { recursive: true });
|
|
17597
17617
|
await import_fs.promises.writeFile(snapFolder, accumulatedImageBuffer);
|
|
17598
|
-
loggerDahua.
|
|
17618
|
+
loggerDahua.info(`[${host}] Saved image locally: ${filename}`);
|
|
17599
17619
|
const fileId = await _createFile(
|
|
17600
17620
|
{
|
|
17601
17621
|
originalname: filename,
|
|
@@ -17670,9 +17690,12 @@ function useDahuaService() {
|
|
|
17670
17690
|
}
|
|
17671
17691
|
}
|
|
17672
17692
|
async function listenToCamera(camera, onDetected) {
|
|
17693
|
+
if (onDetected) {
|
|
17694
|
+
_savedOnDetected = onDetected;
|
|
17695
|
+
}
|
|
17673
17696
|
if (!camera?._id) {
|
|
17674
17697
|
loggerDahua.error(`Camera _id is required to listen to camera.`);
|
|
17675
|
-
|
|
17698
|
+
return;
|
|
17676
17699
|
}
|
|
17677
17700
|
const cameraId = camera._id.toString();
|
|
17678
17701
|
if (cameraRegistry.has(cameraId)) {
|
|
@@ -17682,6 +17705,11 @@ function useDahuaService() {
|
|
|
17682
17705
|
}
|
|
17683
17706
|
const controller = new AbortController();
|
|
17684
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
|
+
}
|
|
17685
17713
|
getTrafficJunction(
|
|
17686
17714
|
camera.host,
|
|
17687
17715
|
camera.username,
|
|
@@ -17691,7 +17719,7 @@ function useDahuaService() {
|
|
|
17691
17719
|
camera.direction,
|
|
17692
17720
|
cameraId,
|
|
17693
17721
|
controller.signal,
|
|
17694
|
-
|
|
17722
|
+
onDetectedHandler
|
|
17695
17723
|
);
|
|
17696
17724
|
}
|
|
17697
17725
|
async function getTrafficJunctionOld(host = "", username = "", password = "", site = "", gate = "", designation = "", cameraId, signal, onDetected) {
|
|
@@ -17812,9 +17840,12 @@ function useDahuaService() {
|
|
|
17812
17840
|
timeout: 2e4,
|
|
17813
17841
|
streaming: true
|
|
17814
17842
|
});
|
|
17815
|
-
if (
|
|
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)) {
|
|
17816
17847
|
loggerDahua.error(`[${host}] Connection error: ${response.statusCode}`);
|
|
17817
|
-
|
|
17848
|
+
return;
|
|
17818
17849
|
}
|
|
17819
17850
|
loggerDahua.info(`[${host}] Successfully connected to ANPR.`);
|
|
17820
17851
|
const contentType = response.res.headers["content-type"];
|
|
@@ -17861,16 +17892,31 @@ function useDahuaService() {
|
|
|
17861
17892
|
});
|
|
17862
17893
|
});
|
|
17863
17894
|
} catch (error) {
|
|
17864
|
-
if (signal.aborted)
|
|
17895
|
+
if (signal.aborted || error.name === "AbortError" || error.code === "UND_ERR_ABORTED") {
|
|
17896
|
+
loggerDahua.info(`[${host}] Connection closed by system (Abort).`);
|
|
17865
17897
|
break;
|
|
17898
|
+
}
|
|
17866
17899
|
loggerDahua.error(
|
|
17867
17900
|
`[${host}] Connection lost or error: ${error.message || error}. Retrying in 5s...`
|
|
17868
17901
|
);
|
|
17869
17902
|
} finally {
|
|
17870
|
-
if (bufferQueue?.destroy)
|
|
17871
|
-
|
|
17872
|
-
|
|
17873
|
-
|
|
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
|
+
}
|
|
17874
17920
|
}
|
|
17875
17921
|
if (!signal.aborted) {
|
|
17876
17922
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
@@ -18086,6 +18132,8 @@ function useSiteCameraRepo() {
|
|
|
18086
18132
|
try {
|
|
18087
18133
|
value = MSiteCamera(value);
|
|
18088
18134
|
const res = await collection.insertOne(value, { session });
|
|
18135
|
+
const { listenToCamera } = useDahuaService();
|
|
18136
|
+
await listenToCamera({ ...value, _id: res.insertedId });
|
|
18089
18137
|
delCachedData();
|
|
18090
18138
|
return res.insertedId;
|
|
18091
18139
|
} catch (error) {
|
|
@@ -19917,7 +19965,8 @@ function useVehicleController() {
|
|
|
19917
19965
|
getVehicles: _getVehicles,
|
|
19918
19966
|
getVehicleById: _getVehicleById,
|
|
19919
19967
|
getVehiclesByNRIC: _getVehiclesByNRIC,
|
|
19920
|
-
getAllVehiclesByUnitId: _getAllVehiclesByUnitId
|
|
19968
|
+
getAllVehiclesByUnitId: _getAllVehiclesByUnitId,
|
|
19969
|
+
getSpecificVehicleById: _getSpecificVehicleById
|
|
19921
19970
|
} = useVehicleRepo();
|
|
19922
19971
|
function normalizeRow(row) {
|
|
19923
19972
|
return Object.fromEntries(
|
|
@@ -20031,7 +20080,9 @@ function useVehicleController() {
|
|
|
20031
20080
|
return;
|
|
20032
20081
|
}
|
|
20033
20082
|
const headerRow = worksheet.getRow(1);
|
|
20034
|
-
const headers = (headerRow.values || []).slice(1).map(
|
|
20083
|
+
const headers = (headerRow.values || []).slice(1).map(
|
|
20084
|
+
(header) => String(header ?? "").trim().replace(/\(.*\)/, "").trim()
|
|
20085
|
+
);
|
|
20035
20086
|
worksheet.eachRow((row, rowNumber) => {
|
|
20036
20087
|
if (rowNumber === 1)
|
|
20037
20088
|
return;
|
|
@@ -20048,7 +20099,11 @@ function useVehicleController() {
|
|
|
20048
20099
|
} else if (lowerName.endsWith(".csv")) {
|
|
20049
20100
|
rows = await new Promise((resolve, reject) => {
|
|
20050
20101
|
const parsed = [];
|
|
20051
|
-
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);
|
|
20052
20107
|
});
|
|
20053
20108
|
} else {
|
|
20054
20109
|
next(
|
|
@@ -20213,6 +20268,31 @@ function useVehicleController() {
|
|
|
20213
20268
|
return;
|
|
20214
20269
|
}
|
|
20215
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
|
+
}
|
|
20216
20296
|
async function updateVehicleById(req, res, next) {
|
|
20217
20297
|
try {
|
|
20218
20298
|
const schema2 = import_joi46.default.object({
|
|
@@ -20432,7 +20512,8 @@ function useVehicleController() {
|
|
|
20432
20512
|
getVehiclesByNRIC,
|
|
20433
20513
|
reactivateVehicleById,
|
|
20434
20514
|
getAllVehiclesByUnitId,
|
|
20435
|
-
uploadSpreadsheetVehicles
|
|
20515
|
+
uploadSpreadsheetVehicles,
|
|
20516
|
+
getSpecificVehicleById
|
|
20436
20517
|
};
|
|
20437
20518
|
}
|
|
20438
20519
|
|
|
@@ -23535,6 +23616,12 @@ function useVisitorTransactionService() {
|
|
|
23535
23616
|
const parsed = new Date(value.checkOut);
|
|
23536
23617
|
value.checkOut = isNaN(parsed.getTime()) ? null : parsed;
|
|
23537
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
|
+
}
|
|
23538
23625
|
await _updateVisitorTansactionById(id, value, session);
|
|
23539
23626
|
await session?.commitTransaction();
|
|
23540
23627
|
return "Successfully updated visitor transaction.";
|
|
@@ -26331,7 +26418,7 @@ function usePatrolRouteRepo() {
|
|
|
26331
26418
|
id: "$_id",
|
|
26332
26419
|
start: startOfDay,
|
|
26333
26420
|
end: endOfDay,
|
|
26334
|
-
site: new import_mongodb67.ObjectId(site)
|
|
26421
|
+
site: import_mongodb67.ObjectId.isValid(site) ? new import_mongodb67.ObjectId(site) : null
|
|
26335
26422
|
},
|
|
26336
26423
|
pipeline: [
|
|
26337
26424
|
{
|
|
@@ -26362,10 +26449,8 @@ function usePatrolRouteRepo() {
|
|
|
26362
26449
|
{ $skip: page * limit },
|
|
26363
26450
|
{ $limit: limit }
|
|
26364
26451
|
];
|
|
26365
|
-
const
|
|
26366
|
-
|
|
26367
|
-
collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
|
|
26368
|
-
]);
|
|
26452
|
+
const items = await collection.aggregate(basePipeline, { session }).toArray();
|
|
26453
|
+
const countResult = await collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray();
|
|
26369
26454
|
const totalCount = countResult[0]?.total || 0;
|
|
26370
26455
|
const data = (0, import_node_server_utils117.paginate)(items, page, limit, totalCount);
|
|
26371
26456
|
setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils117.logger.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
@@ -26373,6 +26458,7 @@ function usePatrolRouteRepo() {
|
|
|
26373
26458
|
);
|
|
26374
26459
|
return data;
|
|
26375
26460
|
} catch (error) {
|
|
26461
|
+
console.error("[getScheduledRoute] ERROR:", error?.message, error?.stack);
|
|
26376
26462
|
throw error;
|
|
26377
26463
|
}
|
|
26378
26464
|
}
|
|
@@ -26659,6 +26745,7 @@ var schemaPatrolLog = import_joi65.default.object({
|
|
|
26659
26745
|
cameras: import_joi65.default.array().items(schemeLogCamera).required(),
|
|
26660
26746
|
status: import_joi65.default.array().items(import_joi65.default.string().valid("complete", "late", "incomplete")).required(),
|
|
26661
26747
|
incidentReport: incidentReportLog,
|
|
26748
|
+
platform: import_joi65.default.string().valid("web", "mobile").optional().allow(null, ""),
|
|
26662
26749
|
createdAt: import_joi65.default.date().optional(),
|
|
26663
26750
|
updatedAt: import_joi65.default.date().optional(),
|
|
26664
26751
|
deletedAt: import_joi65.default.date().optional()
|
|
@@ -26672,7 +26759,8 @@ var schemaUpdatePatrolLog = import_joi65.default.object({
|
|
|
26672
26759
|
end: import_joi65.default.string().optional().allow(null, ""),
|
|
26673
26760
|
cameras: import_joi65.default.array().items(schemeLogCamera).optional().allow(null, ""),
|
|
26674
26761
|
status: import_joi65.default.array().items(import_joi65.default.string().valid("complete", "late", "incomplete")).optional().allow(null, ""),
|
|
26675
|
-
incidentReport: incidentReportLog
|
|
26762
|
+
incidentReport: incidentReportLog,
|
|
26763
|
+
platform: import_joi65.default.string().valid("web", "mobile").optional().allow(null, "")
|
|
26676
26764
|
});
|
|
26677
26765
|
function MPatrolLog(value) {
|
|
26678
26766
|
const { error } = schemaPatrolLog.validate(value);
|
|
@@ -26726,6 +26814,7 @@ function MPatrolLog(value) {
|
|
|
26726
26814
|
status: value.status ?? [],
|
|
26727
26815
|
route: value.route,
|
|
26728
26816
|
incidentReport: value.incidentReport,
|
|
26817
|
+
platForm: value.platform ?? "",
|
|
26729
26818
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
26730
26819
|
updatedAt: value.updatedAt ?? "",
|
|
26731
26820
|
deletedAt: value.deletedAt ?? ""
|
|
@@ -27078,6 +27167,7 @@ function usePatrolLogService() {
|
|
|
27078
27167
|
}
|
|
27079
27168
|
}
|
|
27080
27169
|
}
|
|
27170
|
+
value.platform = value.platform === "web" ? "web" : "mobile";
|
|
27081
27171
|
const result = await _add(value, session);
|
|
27082
27172
|
await session.commitTransaction();
|
|
27083
27173
|
return result;
|
|
@@ -41140,6 +41230,7 @@ var schemaIncidentReport = import_joi99.default.object({
|
|
|
41140
41230
|
approvedBy: import_joi99.default.string().hex().allow(null, "").optional(),
|
|
41141
41231
|
approvedByName: import_joi99.default.string().optional().allow("", null),
|
|
41142
41232
|
remarks: import_joi99.default.string().optional().allow("", null),
|
|
41233
|
+
platform: import_joi99.default.string().valid("web", "mobile").optional().allow(null, ""),
|
|
41143
41234
|
status: import_joi99.default.string().valid("pending", "approved", "rejected").default("pending")
|
|
41144
41235
|
});
|
|
41145
41236
|
var schemaUpdateIncidentReport = import_joi99.default.object({
|
|
@@ -41220,6 +41311,7 @@ var schemaUpdateIncidentReport = import_joi99.default.object({
|
|
|
41220
41311
|
approvedBy: import_joi99.default.string().hex().allow(null, "").optional(),
|
|
41221
41312
|
approvedByName: import_joi99.default.string().optional().allow("", null),
|
|
41222
41313
|
remarks: import_joi99.default.string().optional().allow("", null),
|
|
41314
|
+
platform: import_joi99.default.string().valid("web", "mobile").optional().allow(null, ""),
|
|
41223
41315
|
status: import_joi99.default.string().valid("pending", "approved", "rejected").default("pending")
|
|
41224
41316
|
});
|
|
41225
41317
|
function MIncidentReport(value) {
|
|
@@ -41281,6 +41373,7 @@ function MIncidentReport(value) {
|
|
|
41281
41373
|
approvedByName: value.approvedByName ?? "",
|
|
41282
41374
|
remarks: value.remarks ?? null,
|
|
41283
41375
|
status: value.status ?? "pending",
|
|
41376
|
+
platForm: value.platform ?? "",
|
|
41284
41377
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
41285
41378
|
updatedAt: value.updatedAt,
|
|
41286
41379
|
deletedAt: value.deletedAt
|
|
@@ -41746,6 +41839,7 @@ function useIncidentReportService() {
|
|
|
41746
41839
|
}
|
|
41747
41840
|
}
|
|
41748
41841
|
}
|
|
41842
|
+
value.platform = value.platform === "web" ? "web" : "mobile";
|
|
41749
41843
|
const result = await _add(value, session);
|
|
41750
41844
|
await session?.commitTransaction();
|
|
41751
41845
|
return result;
|
|
@@ -42818,6 +42912,11 @@ function useOccurrenceEntryService() {
|
|
|
42818
42912
|
if (!occurrenceEntry) {
|
|
42819
42913
|
throw new Error("Occurrence entry not found.");
|
|
42820
42914
|
}
|
|
42915
|
+
if (value.incidentReportId) {
|
|
42916
|
+
await _updateOccurrenceEntryById(id, value, session);
|
|
42917
|
+
await session?.commitTransaction();
|
|
42918
|
+
return "Successfully updated occurrence entry (incident report).";
|
|
42919
|
+
}
|
|
42821
42920
|
const entryCount = await _getLatestSerialNumberInGroup(
|
|
42822
42921
|
occurrenceEntry.dailyOccurrenceBookId,
|
|
42823
42922
|
Number(occurrenceEntry.serialNumber)
|
|
@@ -42850,6 +42949,8 @@ function useOccurrenceEntryService() {
|
|
|
42850
42949
|
value.date = value.date ? value.date : occurrenceEntry.date;
|
|
42851
42950
|
value.userName = value.userName ? value.userName : occurrenceEntry.signature.name;
|
|
42852
42951
|
value.createdByName = value.createdByName ? value.createdByName : occurrenceEntry.createdByName;
|
|
42952
|
+
if (occurrenceEntry.incidentReportId)
|
|
42953
|
+
value.incidentReportId = occurrenceEntry.incidentReportId;
|
|
42853
42954
|
await _updateOccurrenceBookById(dobId, {
|
|
42854
42955
|
totalInput: book.totalInput + 1
|
|
42855
42956
|
});
|