@7365admin1/core 3.20.0 → 3.21.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 +1 -1
- package/dist/index.js +149 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2152,7 +2152,7 @@ declare function useDahuaService(): {
|
|
|
2152
2152
|
end?: string;
|
|
2153
2153
|
owner?: string;
|
|
2154
2154
|
isOpenGate?: boolean;
|
|
2155
|
-
}) => Promise<
|
|
2155
|
+
}) => Promise<any>;
|
|
2156
2156
|
removePlateNumber: (value: {
|
|
2157
2157
|
host: string;
|
|
2158
2158
|
username: string;
|
package/dist/index.js
CHANGED
|
@@ -24136,7 +24136,14 @@ function useDahuaService() {
|
|
|
24136
24136
|
}
|
|
24137
24137
|
loggerDahua.info(`[${camera?.siteName}-${camera?.direction}] ANPR Listener stopped.`);
|
|
24138
24138
|
}
|
|
24139
|
+
function extractRecNo(responseText) {
|
|
24140
|
+
if (!responseText)
|
|
24141
|
+
return null;
|
|
24142
|
+
const match = responseText.match(/recno=(\d+)/i);
|
|
24143
|
+
return match ? match[1] : null;
|
|
24144
|
+
}
|
|
24139
24145
|
async function addPlateNumber(value) {
|
|
24146
|
+
let recno = null;
|
|
24140
24147
|
const validation = import_joi40.default.object({
|
|
24141
24148
|
host: import_joi40.default.string().required(),
|
|
24142
24149
|
username: import_joi40.default.string().required(),
|
|
@@ -24148,25 +24155,113 @@ function useDahuaService() {
|
|
|
24148
24155
|
owner: import_joi40.default.string().optional().allow("", null),
|
|
24149
24156
|
isOpenGate: import_joi40.default.boolean().optional().allow(null)
|
|
24150
24157
|
});
|
|
24151
|
-
const { error } = validation.validate(value);
|
|
24152
|
-
if (
|
|
24153
|
-
throw new import_node_server_utils72.BadRequestError(`Validation error: ${
|
|
24158
|
+
const { error: validationError } = validation.validate(value);
|
|
24159
|
+
if (validationError) {
|
|
24160
|
+
throw new import_node_server_utils72.BadRequestError(`Validation error: ${validationError.message}`);
|
|
24154
24161
|
}
|
|
24155
|
-
value.owner = String(value.owner ?? "").substring(0, 15) || "unknown";
|
|
24156
|
-
const _openGate = String(value.isOpenGate);
|
|
24157
|
-
const isOpenGateString = _openGate && _openGate !== "undefined" ? _openGate : "true";
|
|
24158
|
-
const endpoint = `/cgi-bin/recordUpdater.cgi?action=insert&name=${value.mode}&PlateNumber=${value.plateNumber}&BeginTime=${value.start}&CancelTime=${value.end}&+OpenGate=${isOpenGateString}&MasterOfCar=${value.owner}`;
|
|
24159
24162
|
try {
|
|
24160
|
-
|
|
24161
|
-
|
|
24162
|
-
|
|
24163
|
-
|
|
24164
|
-
|
|
24165
|
-
|
|
24166
|
-
|
|
24167
|
-
|
|
24168
|
-
|
|
24169
|
-
|
|
24163
|
+
value.owner = String(value.owner ?? "").substring(0, 15) || "unknown";
|
|
24164
|
+
const formatDahuaDate2 = (dateStr, fallbackYearsAhead = 0) => {
|
|
24165
|
+
const date = dateStr ? new Date(dateStr) : /* @__PURE__ */ new Date();
|
|
24166
|
+
if (!dateStr) {
|
|
24167
|
+
date.setMinutes(date.getMinutes() - 10);
|
|
24168
|
+
}
|
|
24169
|
+
if (fallbackYearsAhead > 0 && !dateStr) {
|
|
24170
|
+
date.setFullYear(date.getFullYear() + fallbackYearsAhead);
|
|
24171
|
+
}
|
|
24172
|
+
const pad = (num) => String(num).padStart(2, "0");
|
|
24173
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
24174
|
+
};
|
|
24175
|
+
const formattedStart = formatDahuaDate2(value.start);
|
|
24176
|
+
const formattedEnd = formatDahuaDate2(value.end, 10);
|
|
24177
|
+
const beginTime = encodeURIComponent(formattedStart);
|
|
24178
|
+
const cancelTime = encodeURIComponent(formattedEnd);
|
|
24179
|
+
const plateNumber = encodeURIComponent(value.plateNumber);
|
|
24180
|
+
const ownerName = encodeURIComponent(value.owner);
|
|
24181
|
+
const endpoint = `/cgi-bin/recordUpdater.cgi?action=insert&name=${value.mode}&PlateNumber=${plateNumber}&BeginTime=${beginTime}&CancelTime=${cancelTime}&MasterOfCar=${ownerName}`;
|
|
24182
|
+
try {
|
|
24183
|
+
const insertResponse = await useDahuaDigestWithRetry({
|
|
24184
|
+
host: value.host,
|
|
24185
|
+
username: value.username,
|
|
24186
|
+
password: value.password,
|
|
24187
|
+
endpoint,
|
|
24188
|
+
retries: 10,
|
|
24189
|
+
retryDelayMs: 0
|
|
24190
|
+
});
|
|
24191
|
+
const insertText = getDahuaResponseText(insertResponse);
|
|
24192
|
+
const insertedId = insertText.match(/\d+/)?.[0] || "unknown";
|
|
24193
|
+
return {
|
|
24194
|
+
...insertResponse,
|
|
24195
|
+
statusCode: 200,
|
|
24196
|
+
data: Buffer.from(`recno=${insertedId}`)
|
|
24197
|
+
};
|
|
24198
|
+
} catch (insertError) {
|
|
24199
|
+
const errorMessage = insertError?.message || String(insertError);
|
|
24200
|
+
if (/recno=/i.test(errorMessage)) {
|
|
24201
|
+
loggerDahua.info(`[${value.host}] Insert confirmed successfully via raw RecNo response text.`);
|
|
24202
|
+
const insertedId = errorMessage.match(/\d+/)?.[0] || "unknown";
|
|
24203
|
+
return {
|
|
24204
|
+
statusCode: 200,
|
|
24205
|
+
data: Buffer.from(`recno=${insertedId}`)
|
|
24206
|
+
};
|
|
24207
|
+
}
|
|
24208
|
+
if (errorMessage.includes("Bad Request") || errorMessage.includes("Dahua response: Error")) {
|
|
24209
|
+
loggerDahua.info(`[${value.host}] Insert failed (duplicate). Checking if plate ${value.plateNumber} already exists...`);
|
|
24210
|
+
const findEndpoint = `/cgi-bin/recordFinder.cgi?action=find&name=${value.mode}&condition.PlateNumber=${plateNumber}`;
|
|
24211
|
+
try {
|
|
24212
|
+
const findResponse = await useDahuaDigestWithRetry({
|
|
24213
|
+
host: value.host,
|
|
24214
|
+
username: value.username,
|
|
24215
|
+
password: value.password,
|
|
24216
|
+
endpoint: findEndpoint,
|
|
24217
|
+
retries: 5
|
|
24218
|
+
});
|
|
24219
|
+
const textData = getDahuaResponseText(findResponse);
|
|
24220
|
+
recno = extractRecNo(textData);
|
|
24221
|
+
} catch (findError) {
|
|
24222
|
+
const findErrorMessage = findError?.message || String(findError);
|
|
24223
|
+
recno = extractRecNo(findErrorMessage);
|
|
24224
|
+
if (!recno) {
|
|
24225
|
+
loggerDahua.error(`[${value.host}] Failed handling existing duplicate plate flow`, findError);
|
|
24226
|
+
}
|
|
24227
|
+
}
|
|
24228
|
+
if (recno) {
|
|
24229
|
+
loggerDahua.info(`[${value.host}] Found existing record ID: ${recno}. Updating registration instead...`);
|
|
24230
|
+
const updateEndpoint = `/cgi-bin/recordUpdater.cgi?action=update&name=${value.mode}&recno=${recno}&PlateNumber=${plateNumber}&BeginTime=${beginTime}&CancelTime=${cancelTime}&MasterOfCar=${ownerName}`;
|
|
24231
|
+
try {
|
|
24232
|
+
const updateResponse = await useDahuaDigestWithRetry({
|
|
24233
|
+
host: value.host,
|
|
24234
|
+
username: value.username,
|
|
24235
|
+
password: value.password,
|
|
24236
|
+
endpoint: updateEndpoint,
|
|
24237
|
+
retries: 5
|
|
24238
|
+
});
|
|
24239
|
+
return {
|
|
24240
|
+
...updateResponse,
|
|
24241
|
+
statusCode: 200,
|
|
24242
|
+
data: Buffer.from(`recno=${recno}`)
|
|
24243
|
+
};
|
|
24244
|
+
} catch (updateError) {
|
|
24245
|
+
const updateErrorMessage = updateError?.message || String(updateError);
|
|
24246
|
+
if (/recno=/i.test(updateErrorMessage) || /ok/i.test(updateErrorMessage)) {
|
|
24247
|
+
loggerDahua.info(`[${value.host}] Update confirmed successfully despite wrapper omission.`);
|
|
24248
|
+
if (!recno) {
|
|
24249
|
+
recno = extractRecNo(updateErrorMessage);
|
|
24250
|
+
}
|
|
24251
|
+
return {
|
|
24252
|
+
statusCode: 200,
|
|
24253
|
+
data: Buffer.from(`recno=${recno}`)
|
|
24254
|
+
};
|
|
24255
|
+
}
|
|
24256
|
+
throw updateError;
|
|
24257
|
+
}
|
|
24258
|
+
}
|
|
24259
|
+
}
|
|
24260
|
+
throw insertError;
|
|
24261
|
+
}
|
|
24262
|
+
} catch (finalError) {
|
|
24263
|
+
loggerDahua.error(`[${value.host}] Error adding plate number:`, finalError);
|
|
24264
|
+
throw new import_node_server_utils72.BadRequestError(`Failed to add plate number: ${finalError.message || finalError}`);
|
|
24170
24265
|
}
|
|
24171
24266
|
}
|
|
24172
24267
|
async function updatePlateNumber(value) {
|
|
@@ -27118,7 +27213,7 @@ function useVehicleService() {
|
|
|
27118
27213
|
const siteCameraReq = await _getAllSiteCameras({
|
|
27119
27214
|
site: siteId,
|
|
27120
27215
|
type: "anpr",
|
|
27121
|
-
direction: ["both", "entry"],
|
|
27216
|
+
direction: ["both", "entry", "residents"],
|
|
27122
27217
|
page,
|
|
27123
27218
|
limit
|
|
27124
27219
|
});
|
|
@@ -27142,11 +27237,14 @@ function useVehicleService() {
|
|
|
27142
27237
|
owner
|
|
27143
27238
|
};
|
|
27144
27239
|
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
27145
|
-
if (dahuaResponse?.statusCode
|
|
27240
|
+
if (dahuaResponse?.statusCode != 200) {
|
|
27241
|
+
console.log("dahuaResponse", dahuaResponse);
|
|
27242
|
+
console.log("approveVehicleById dahuaResponse dahuaResponse?.statusCode != 200", dahuaResponse?.statusCode);
|
|
27146
27243
|
throw new import_node_server_utils78.BadRequestError("Failed to add plate number to ANPR");
|
|
27147
27244
|
}
|
|
27148
27245
|
const responseData = dahuaResponse?.data.toString("utf-8");
|
|
27149
27246
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
27247
|
+
console.log("approveVehicleById recNo", value.recNo);
|
|
27150
27248
|
}
|
|
27151
27249
|
value.status = "active" /* ACTIVE */;
|
|
27152
27250
|
if (vehicle.peopleId && value.recNo) {
|
|
@@ -57765,6 +57863,26 @@ function useNewDashboardRepo() {
|
|
|
57765
57863
|
const siteIdObj = (0, import_node_server_utils200.toObjectId)(siteId);
|
|
57766
57864
|
const startOfToday = import_moment.default.tz("Asia/Singapore").startOf("day").toDate();
|
|
57767
57865
|
const endOfToday = import_moment.default.tz("Asia/Singapore").endOf("day").toDate();
|
|
57866
|
+
const localTodayStr = import_moment.default.tz("Asia/Singapore").format("YYYY-MM-DD");
|
|
57867
|
+
const facilityTodayStart = import_moment.default.utc(`${localTodayStr}T00:00:00.000Z`).toDate();
|
|
57868
|
+
const facilityTodayEnd = import_moment.default.utc(`${localTodayStr}T23:59:59.999Z`).toDate();
|
|
57869
|
+
const localYesterdayStr = import_moment.default.tz("Asia/Singapore").subtract(1, "day").format("YYYY-MM-DD");
|
|
57870
|
+
const facilityYesterdayStart = import_moment.default.utc(`${localYesterdayStr}T00:00:00.000Z`).toDate();
|
|
57871
|
+
const facilityYesterdayEnd = import_moment.default.utc(`${localYesterdayStr}T23:59:59.999Z`).toDate();
|
|
57872
|
+
let facilityPeriodRange = { $gte: facilityTodayStart, $lte: facilityTodayEnd };
|
|
57873
|
+
if (period === "thisWeek" /* THIS_WEEK */) {
|
|
57874
|
+
const startStr = import_moment.default.tz("Asia/Singapore").subtract(7, "days").format("YYYY-MM-DD");
|
|
57875
|
+
facilityPeriodRange = {
|
|
57876
|
+
$gte: import_moment.default.utc(`${startStr}T00:00:00.000Z`).toDate(),
|
|
57877
|
+
$lte: facilityTodayEnd
|
|
57878
|
+
};
|
|
57879
|
+
} else if (period === "thisMonth" /* THIS_MONTH */) {
|
|
57880
|
+
const startStr = import_moment.default.tz("Asia/Singapore").subtract(30, "days").format("YYYY-MM-DD");
|
|
57881
|
+
facilityPeriodRange = {
|
|
57882
|
+
$gte: import_moment.default.utc(`${startStr}T00:00:00.000Z`).toDate(),
|
|
57883
|
+
$lte: facilityTodayEnd
|
|
57884
|
+
};
|
|
57885
|
+
}
|
|
57768
57886
|
const upcomingEvents = await db.collection(events_namespace_collection).find({
|
|
57769
57887
|
site: { $in: [siteIdObj, siteId] },
|
|
57770
57888
|
status: { $nin: ["deleted", "Deleted"] },
|
|
@@ -57976,11 +58094,11 @@ function useNewDashboardRepo() {
|
|
|
57976
58094
|
site: { $in: [siteIdObj, siteId] },
|
|
57977
58095
|
...facilityMatchObj,
|
|
57978
58096
|
$or: [
|
|
57979
|
-
{
|
|
58097
|
+
{ date: facilityPeriodRange },
|
|
57980
58098
|
{
|
|
57981
|
-
|
|
57982
|
-
$gte:
|
|
57983
|
-
$lte:
|
|
58099
|
+
date: {
|
|
58100
|
+
$gte: facilityPeriodRange.$gte.toISOString(),
|
|
58101
|
+
$lte: facilityPeriodRange.$lte.toISOString()
|
|
57984
58102
|
}
|
|
57985
58103
|
}
|
|
57986
58104
|
],
|
|
@@ -58019,11 +58137,11 @@ function useNewDashboardRepo() {
|
|
|
58019
58137
|
site: { $in: [siteIdObj, siteId] },
|
|
58020
58138
|
...facilityMatchObj,
|
|
58021
58139
|
$or: [
|
|
58022
|
-
{
|
|
58140
|
+
{ date: { $gte: facilityYesterdayStart, $lte: facilityYesterdayEnd } },
|
|
58023
58141
|
{
|
|
58024
|
-
|
|
58025
|
-
$gte:
|
|
58026
|
-
$lte:
|
|
58142
|
+
date: {
|
|
58143
|
+
$gte: facilityYesterdayStart.toISOString(),
|
|
58144
|
+
$lte: facilityYesterdayEnd.toISOString()
|
|
58027
58145
|
}
|
|
58028
58146
|
}
|
|
58029
58147
|
],
|
|
@@ -58038,11 +58156,11 @@ function useNewDashboardRepo() {
|
|
|
58038
58156
|
site: { $in: [siteIdObj, siteId] },
|
|
58039
58157
|
...facilityMatchObj,
|
|
58040
58158
|
$or: [
|
|
58041
|
-
{
|
|
58159
|
+
{ date: { $gte: facilityTodayStart, $lte: facilityTodayEnd } },
|
|
58042
58160
|
{
|
|
58043
|
-
|
|
58044
|
-
$gte:
|
|
58045
|
-
$lte:
|
|
58161
|
+
date: {
|
|
58162
|
+
$gte: facilityTodayStart.toISOString(),
|
|
58163
|
+
$lte: facilityTodayEnd.toISOString()
|
|
58046
58164
|
}
|
|
58047
58165
|
}
|
|
58048
58166
|
],
|