@7365admin1/core 2.45.0 → 2.47.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 +89 -48
- package/dist/index.js +1325 -927
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2518 -2123
- package/dist/index.mjs.map +1 -1
- package/dist/public/handlebars/resident-remarks-email.hbs +38 -0
- package/dist/public/icons/approved-icon.png +0 -0
- package/dist/public/icons/deleted-icon.png +0 -0
- package/dist/public/icons/resubmission-icon.png +0 -0
- package/dist/public/images/seven-365.svg +17 -0
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
AccessTypeProps: () => AccessTypeProps,
|
|
35
35
|
AppServiceType: () => AppServiceType,
|
|
36
36
|
BuildingStatus: () => BuildingStatus,
|
|
37
|
+
BulletinOrder: () => BulletinOrder,
|
|
37
38
|
BulletinRecipient: () => BulletinRecipient,
|
|
38
39
|
BulletinSort: () => BulletinSort,
|
|
39
40
|
BulletinStatus: () => BulletinStatus,
|
|
@@ -48,6 +49,10 @@ __export(src_exports, {
|
|
|
48
49
|
EmailSender: () => EmailSender,
|
|
49
50
|
EntryOrder: () => EntryOrder,
|
|
50
51
|
EntrySort: () => EntrySort,
|
|
52
|
+
EventOrder: () => EventOrder,
|
|
53
|
+
EventSort: () => EventSort,
|
|
54
|
+
EventStatus: () => EventStatus,
|
|
55
|
+
EventType: () => EventType,
|
|
51
56
|
FacilitySort: () => FacilitySort,
|
|
52
57
|
FacilityStatus: () => FacilityStatus,
|
|
53
58
|
GuestSort: () => GuestSort,
|
|
@@ -160,6 +165,7 @@ __export(src_exports, {
|
|
|
160
165
|
events_namespace_collection: () => events_namespace_collection,
|
|
161
166
|
facility_bookings_namespace_collection: () => facility_bookings_namespace_collection,
|
|
162
167
|
feedbackSchema: () => feedbackSchema,
|
|
168
|
+
feedbacks2_namespace_collection: () => feedbacks2_namespace_collection,
|
|
163
169
|
feedbacks_namespace_collection: () => feedbacks_namespace_collection,
|
|
164
170
|
formatDahuaDate: () => formatDahuaDate,
|
|
165
171
|
getPeriodRangeWithPrevious: () => getPeriodRangeWithPrevious,
|
|
@@ -715,15 +721,22 @@ function MFeedback(value) {
|
|
|
715
721
|
// src/repositories/feedback.repo.ts
|
|
716
722
|
var import_node_server_utils5 = require("@7365admin1/node-server-utils");
|
|
717
723
|
var feedbacks_namespace_collection = "feedbacks";
|
|
724
|
+
var feedbacks2_namespace_collection = "feedbacks2";
|
|
718
725
|
function useFeedbackRepo() {
|
|
719
726
|
const db = import_node_server_utils5.useAtlas.getDb();
|
|
720
727
|
if (!db) {
|
|
721
728
|
throw new import_node_server_utils5.InternalServerError("Unable to connect to server.");
|
|
722
729
|
}
|
|
723
730
|
const collection = db.collection(feedbacks_namespace_collection);
|
|
731
|
+
const feedbacks2Collection = db.collection(feedbacks2_namespace_collection);
|
|
724
732
|
const { delNamespace, getCache, setCache } = (0, import_node_server_utils5.useCache)(
|
|
725
733
|
feedbacks_namespace_collection
|
|
726
734
|
);
|
|
735
|
+
const {
|
|
736
|
+
delNamespace: delNamespaceFeedbacks2,
|
|
737
|
+
getCache: getCacheFeedbacks2,
|
|
738
|
+
setCache: setCacheFeedbacks2
|
|
739
|
+
} = (0, import_node_server_utils5.useCache)(feedbacks2_namespace_collection);
|
|
727
740
|
const { delNamespace: _delDashboardNameSpace } = (0, import_node_server_utils5.useCache)("dashboard");
|
|
728
741
|
async function createIndex() {
|
|
729
742
|
try {
|
|
@@ -1184,7 +1197,7 @@ function useFeedbackRepo() {
|
|
|
1184
1197
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
1185
1198
|
deletedAt: /* @__PURE__ */ new Date()
|
|
1186
1199
|
};
|
|
1187
|
-
const res = await
|
|
1200
|
+
const res = await feedbacks2Collection.updateOne(
|
|
1188
1201
|
{ _id },
|
|
1189
1202
|
{ $set: updateValue },
|
|
1190
1203
|
{ session }
|
|
@@ -1192,13 +1205,13 @@ function useFeedbackRepo() {
|
|
|
1192
1205
|
if (res.modifiedCount === 0) {
|
|
1193
1206
|
throw new import_node_server_utils5.InternalServerError("Unable to delete feedback.");
|
|
1194
1207
|
}
|
|
1195
|
-
|
|
1208
|
+
delNamespaceFeedbacks2().then(() => {
|
|
1196
1209
|
import_node_server_utils5.logger.info(
|
|
1197
|
-
`Cache cleared for namespace: ${
|
|
1210
|
+
`Cache cleared for namespace: ${feedbacks2_namespace_collection}`
|
|
1198
1211
|
);
|
|
1199
1212
|
}).catch((err) => {
|
|
1200
1213
|
import_node_server_utils5.logger.error(
|
|
1201
|
-
`Failed to clear cache for namespace: ${
|
|
1214
|
+
`Failed to clear cache for namespace: ${feedbacks2_namespace_collection}`,
|
|
1202
1215
|
err
|
|
1203
1216
|
);
|
|
1204
1217
|
});
|
|
@@ -5897,6 +5910,13 @@ var MRole = class {
|
|
|
5897
5910
|
throw new import_node_server_utils22.BadRequestError("Invalid org ID format.");
|
|
5898
5911
|
}
|
|
5899
5912
|
}
|
|
5913
|
+
if (typeof value.site === "string" && value.site.length === 24) {
|
|
5914
|
+
try {
|
|
5915
|
+
value.site = new import_mongodb19.ObjectId(value.site);
|
|
5916
|
+
} catch (error) {
|
|
5917
|
+
throw new import_node_server_utils22.BadRequestError("Invalid site ID format.");
|
|
5918
|
+
}
|
|
5919
|
+
}
|
|
5900
5920
|
if (value.createdBy) {
|
|
5901
5921
|
try {
|
|
5902
5922
|
value.createdBy = new import_mongodb19.ObjectId(value.createdBy);
|
|
@@ -5910,6 +5930,8 @@ var MRole = class {
|
|
|
5910
5930
|
this.permissions = value.permissions ?? [];
|
|
5911
5931
|
this.type = value.type ? value.type : "account";
|
|
5912
5932
|
this.org = value.org ?? "";
|
|
5933
|
+
this.site = value.site ?? "";
|
|
5934
|
+
this.platform = value.platform ?? "website";
|
|
5913
5935
|
this.default = value.default ?? false;
|
|
5914
5936
|
this.status = value.status ?? "active";
|
|
5915
5937
|
this.createdBy = value.createdBy ?? "";
|
|
@@ -7193,7 +7215,9 @@ function useRoleController() {
|
|
|
7193
7215
|
name: import_joi14.default.string().required(),
|
|
7194
7216
|
permissions: import_joi14.default.array().items(import_joi14.default.string()).required(),
|
|
7195
7217
|
type: import_joi14.default.string().optional().allow("", null),
|
|
7196
|
-
org: import_joi14.default.string().hex().optional().allow("", null)
|
|
7218
|
+
org: import_joi14.default.string().hex().optional().allow("", null),
|
|
7219
|
+
site: import_joi14.default.string().hex().optional().allow("", null),
|
|
7220
|
+
platform: import_joi14.default.string().valid("website", "mobile").optional().default("website")
|
|
7197
7221
|
});
|
|
7198
7222
|
const payload = { ...req.body };
|
|
7199
7223
|
const { error } = validation.validate(payload);
|
|
@@ -13038,7 +13062,7 @@ function useCustomerController() {
|
|
|
13038
13062
|
var import_node_server_utils77 = require("@7365admin1/node-server-utils");
|
|
13039
13063
|
|
|
13040
13064
|
// src/repositories/site-camera.repo.ts
|
|
13041
|
-
var
|
|
13065
|
+
var import_node_server_utils76 = require("@7365admin1/node-server-utils");
|
|
13042
13066
|
|
|
13043
13067
|
// src/models/site-camera.model.ts
|
|
13044
13068
|
var import_node_server_utils66 = require("@7365admin1/node-server-utils");
|
|
@@ -13103,406 +13127,26 @@ function MSiteCamera(value) {
|
|
|
13103
13127
|
}
|
|
13104
13128
|
|
|
13105
13129
|
// src/repositories/site-camera.repo.ts
|
|
13106
|
-
var
|
|
13107
|
-
function useSiteCameraRepo() {
|
|
13108
|
-
const db = import_node_server_utils67.useAtlas.getDb();
|
|
13109
|
-
if (!db) {
|
|
13110
|
-
throw new Error("Unable to connect to server.");
|
|
13111
|
-
}
|
|
13112
|
-
const namespace_collection = "site.cameras";
|
|
13113
|
-
const collection = db.collection(namespace_collection);
|
|
13114
|
-
const { delNamespace, getCache, setCache } = (0, import_node_server_utils67.useCache)(namespace_collection);
|
|
13115
|
-
async function createIndexes() {
|
|
13116
|
-
try {
|
|
13117
|
-
await collection.createIndexes([
|
|
13118
|
-
{
|
|
13119
|
-
key: { site: 1 }
|
|
13120
|
-
},
|
|
13121
|
-
{
|
|
13122
|
-
key: { type: 1 }
|
|
13123
|
-
},
|
|
13124
|
-
{
|
|
13125
|
-
key: { host: 1, type: 1, status: 1 },
|
|
13126
|
-
unique: true,
|
|
13127
|
-
partialFilterExpression: { status: "active" }
|
|
13128
|
-
}
|
|
13129
|
-
]);
|
|
13130
|
-
return `Successfully created ${namespace_collection} indexes.`;
|
|
13131
|
-
} catch (error) {
|
|
13132
|
-
import_node_server_utils67.logger.log({
|
|
13133
|
-
level: "error",
|
|
13134
|
-
message: error.message
|
|
13135
|
-
});
|
|
13136
|
-
}
|
|
13137
|
-
}
|
|
13138
|
-
async function add(value, session) {
|
|
13139
|
-
try {
|
|
13140
|
-
value = MSiteCamera(value);
|
|
13141
|
-
const res = await collection.insertOne(value, { session });
|
|
13142
|
-
delCachedData();
|
|
13143
|
-
return res.insertedId;
|
|
13144
|
-
} catch (error) {
|
|
13145
|
-
import_node_server_utils67.logger.log({
|
|
13146
|
-
level: "error",
|
|
13147
|
-
message: error.message
|
|
13148
|
-
});
|
|
13149
|
-
const isDuplicated = error.message.includes("duplicate");
|
|
13150
|
-
if (isDuplicated) {
|
|
13151
|
-
throw new import_node_server_utils67.BadRequestError("ANPR already exist.");
|
|
13152
|
-
}
|
|
13153
|
-
if (error instanceof import_node_server_utils67.AppError) {
|
|
13154
|
-
throw error;
|
|
13155
|
-
} else {
|
|
13156
|
-
throw new Error("Failed to create ANPR.");
|
|
13157
|
-
}
|
|
13158
|
-
}
|
|
13159
|
-
}
|
|
13160
|
-
async function getAll(value) {
|
|
13161
|
-
value.page = value.page ? value.page - 1 : 0;
|
|
13162
|
-
value.limit = value.limit || 10;
|
|
13163
|
-
const cacheKeyOptions = {
|
|
13164
|
-
type: value.type,
|
|
13165
|
-
page: value.page,
|
|
13166
|
-
limit: value.limit,
|
|
13167
|
-
...value.direction && { direction: value.direction }
|
|
13168
|
-
};
|
|
13169
|
-
const query = {
|
|
13170
|
-
type: value.type,
|
|
13171
|
-
...value.direction && {
|
|
13172
|
-
direction: {
|
|
13173
|
-
$in: Array.isArray(value.direction) ? value.direction : [value.direction]
|
|
13174
|
-
}
|
|
13175
|
-
}
|
|
13176
|
-
};
|
|
13177
|
-
if (value.site) {
|
|
13178
|
-
cacheKeyOptions.site = value.site;
|
|
13179
|
-
try {
|
|
13180
|
-
value.site = new import_mongodb38.ObjectId(value.site);
|
|
13181
|
-
query.site = value.site;
|
|
13182
|
-
} catch (error) {
|
|
13183
|
-
throw new import_node_server_utils67.BadRequestError("Invalid site ID format");
|
|
13184
|
-
}
|
|
13185
|
-
}
|
|
13186
|
-
const cacheKey = (0, import_node_server_utils67.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
13187
|
-
const cachedData = await getCache(cacheKey);
|
|
13188
|
-
if (cachedData) {
|
|
13189
|
-
return cachedData;
|
|
13190
|
-
}
|
|
13191
|
-
try {
|
|
13192
|
-
const items = await collection.aggregate([
|
|
13193
|
-
{
|
|
13194
|
-
$match: query
|
|
13195
|
-
},
|
|
13196
|
-
{
|
|
13197
|
-
$skip: value.page * value.limit
|
|
13198
|
-
},
|
|
13199
|
-
{
|
|
13200
|
-
$limit: value.limit
|
|
13201
|
-
},
|
|
13202
|
-
{
|
|
13203
|
-
$project: {
|
|
13204
|
-
password: 0
|
|
13205
|
-
}
|
|
13206
|
-
}
|
|
13207
|
-
]).toArray();
|
|
13208
|
-
const length = await collection.countDocuments(query);
|
|
13209
|
-
const data = (0, import_node_server_utils67.paginate)(items, value.page, value.limit, length);
|
|
13210
|
-
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
13211
|
-
import_node_server_utils67.logger.info(`Cache set for key: ${cacheKey}`);
|
|
13212
|
-
}).catch((err) => {
|
|
13213
|
-
import_node_server_utils67.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
13214
|
-
});
|
|
13215
|
-
return data;
|
|
13216
|
-
} catch (error) {
|
|
13217
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13218
|
-
throw error;
|
|
13219
|
-
}
|
|
13220
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13221
|
-
}
|
|
13222
|
-
}
|
|
13223
|
-
async function findSiteCameras({ site, type }) {
|
|
13224
|
-
const pipeline = [];
|
|
13225
|
-
const cacheObject = {};
|
|
13226
|
-
if (type) {
|
|
13227
|
-
cacheObject.type = type;
|
|
13228
|
-
pipeline.push({ $match: { "anprs.type": type } });
|
|
13229
|
-
}
|
|
13230
|
-
if (site) {
|
|
13231
|
-
const _site = new import_mongodb38.ObjectId(site);
|
|
13232
|
-
cacheObject.site = site;
|
|
13233
|
-
pipeline.push({ $match: { site: _site } });
|
|
13234
|
-
}
|
|
13235
|
-
pipeline.push({
|
|
13236
|
-
$project: {
|
|
13237
|
-
_id: 1,
|
|
13238
|
-
site: 1,
|
|
13239
|
-
cameras: 1
|
|
13240
|
-
}
|
|
13241
|
-
});
|
|
13242
|
-
try {
|
|
13243
|
-
const items = await collection.aggregate(pipeline).toArray();
|
|
13244
|
-
return items;
|
|
13245
|
-
} catch (error) {
|
|
13246
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13247
|
-
throw error;
|
|
13248
|
-
}
|
|
13249
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13250
|
-
}
|
|
13251
|
-
}
|
|
13252
|
-
function delCachedData() {
|
|
13253
|
-
delNamespace().then(() => {
|
|
13254
|
-
import_node_server_utils67.logger.log({
|
|
13255
|
-
level: "info",
|
|
13256
|
-
message: `Cache namespace cleared for ${namespace_collection}`
|
|
13257
|
-
});
|
|
13258
|
-
}).catch((err) => {
|
|
13259
|
-
import_node_server_utils67.logger.log({
|
|
13260
|
-
level: "error",
|
|
13261
|
-
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
13262
|
-
});
|
|
13263
|
-
});
|
|
13264
|
-
}
|
|
13265
|
-
async function getBySite(site, options = {}) {
|
|
13266
|
-
const _site = (0, import_node_server_utils67.toObjectId)(site);
|
|
13267
|
-
const cacheKeyOptions = {
|
|
13268
|
-
site,
|
|
13269
|
-
tag: "get-by-site",
|
|
13270
|
-
...options.category && { category: options.category },
|
|
13271
|
-
...options.type && { type: options.type },
|
|
13272
|
-
...options.guardPost && { guardPost: options.guardPost }
|
|
13273
|
-
};
|
|
13274
|
-
const cacheKey = (0, import_node_server_utils67.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
13275
|
-
const cachedData = await getCache(cacheKey);
|
|
13276
|
-
if (cachedData) {
|
|
13277
|
-
return cachedData;
|
|
13278
|
-
}
|
|
13279
|
-
try {
|
|
13280
|
-
delete cacheKeyOptions.tag;
|
|
13281
|
-
cacheKeyOptions.site = _site;
|
|
13282
|
-
const item = await collection.findOne(cacheKeyOptions);
|
|
13283
|
-
setCache(cacheKey, item, 15 * 60).then(() => {
|
|
13284
|
-
import_node_server_utils67.logger.log({
|
|
13285
|
-
level: "info",
|
|
13286
|
-
message: `Cache set for getBySite: ${cacheKey}`
|
|
13287
|
-
});
|
|
13288
|
-
}).catch((err) => {
|
|
13289
|
-
import_node_server_utils67.logger.log({
|
|
13290
|
-
level: "error",
|
|
13291
|
-
message: `Failed to set cache for getBySite: ${err.message}`
|
|
13292
|
-
});
|
|
13293
|
-
});
|
|
13294
|
-
return item;
|
|
13295
|
-
} catch (error) {
|
|
13296
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13297
|
-
throw error;
|
|
13298
|
-
}
|
|
13299
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13300
|
-
}
|
|
13301
|
-
}
|
|
13302
|
-
async function getBySiteGuardPost(site, guardPost) {
|
|
13303
|
-
try {
|
|
13304
|
-
site = new import_mongodb38.ObjectId(site);
|
|
13305
|
-
} catch (error) {
|
|
13306
|
-
throw new import_node_server_utils67.BadRequestError("Invalid site ID format");
|
|
13307
|
-
}
|
|
13308
|
-
const cacheKeyOptions = {
|
|
13309
|
-
site,
|
|
13310
|
-
guardPost,
|
|
13311
|
-
tag: "get-by-site"
|
|
13312
|
-
};
|
|
13313
|
-
const cacheKey = (0, import_node_server_utils67.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
13314
|
-
const cachedData = await getCache(cacheKey);
|
|
13315
|
-
if (cachedData) {
|
|
13316
|
-
return cachedData;
|
|
13317
|
-
}
|
|
13318
|
-
try {
|
|
13319
|
-
delete cacheKeyOptions.tag;
|
|
13320
|
-
const item = await collection.findOne({
|
|
13321
|
-
site,
|
|
13322
|
-
guardPost: { $gt: guardPost }
|
|
13323
|
-
});
|
|
13324
|
-
setCache(cacheKey, item, 15 * 60).then(() => {
|
|
13325
|
-
import_node_server_utils67.logger.log({
|
|
13326
|
-
level: "info",
|
|
13327
|
-
message: `Cache set for getBySite: ${cacheKey}`
|
|
13328
|
-
});
|
|
13329
|
-
}).catch((err) => {
|
|
13330
|
-
import_node_server_utils67.logger.log({
|
|
13331
|
-
level: "error",
|
|
13332
|
-
message: `Failed to set cache for getBySite: ${err.message}`
|
|
13333
|
-
});
|
|
13334
|
-
});
|
|
13335
|
-
return item;
|
|
13336
|
-
} catch (error) {
|
|
13337
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13338
|
-
throw error;
|
|
13339
|
-
}
|
|
13340
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13341
|
-
}
|
|
13342
|
-
}
|
|
13343
|
-
async function getBySites(site, options = {}) {
|
|
13344
|
-
try {
|
|
13345
|
-
site = new import_mongodb38.ObjectId(site);
|
|
13346
|
-
} catch (error) {
|
|
13347
|
-
throw new import_node_server_utils67.BadRequestError("Invalid site ID format");
|
|
13348
|
-
}
|
|
13349
|
-
const cacheKeyOptions = { site };
|
|
13350
|
-
if (options.category) {
|
|
13351
|
-
cacheKeyOptions.category = options.category;
|
|
13352
|
-
}
|
|
13353
|
-
if (options.type) {
|
|
13354
|
-
cacheKeyOptions.type = options.type;
|
|
13355
|
-
}
|
|
13356
|
-
if (options.direction) {
|
|
13357
|
-
cacheKeyOptions.direction = options.direction;
|
|
13358
|
-
}
|
|
13359
|
-
const cacheKey = (0, import_node_server_utils67.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
13360
|
-
const cachedData = await getCache(cacheKey);
|
|
13361
|
-
if (cachedData) {
|
|
13362
|
-
return cachedData;
|
|
13363
|
-
}
|
|
13364
|
-
try {
|
|
13365
|
-
const items = await collection.find(cacheKeyOptions);
|
|
13366
|
-
setCache(cacheKey, items, 15 * 60).then(() => {
|
|
13367
|
-
import_node_server_utils67.logger.log({
|
|
13368
|
-
level: "info",
|
|
13369
|
-
message: `Cache set for getBySite: ${cacheKey}`
|
|
13370
|
-
});
|
|
13371
|
-
}).catch((err) => {
|
|
13372
|
-
import_node_server_utils67.logger.log({
|
|
13373
|
-
level: "error",
|
|
13374
|
-
message: `Failed to set cache for getBySite: ${err.message}`
|
|
13375
|
-
});
|
|
13376
|
-
});
|
|
13377
|
-
return items;
|
|
13378
|
-
} catch (error) {
|
|
13379
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13380
|
-
throw error;
|
|
13381
|
-
}
|
|
13382
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13383
|
-
}
|
|
13384
|
-
}
|
|
13385
|
-
async function updateById(_id, value, session) {
|
|
13386
|
-
const { error } = schemaUpdateSiteCamera.validate(value);
|
|
13387
|
-
if (error) {
|
|
13388
|
-
import_node_server_utils67.logger.info(`Site Camera Management: ${error.message}`);
|
|
13389
|
-
throw new import_node_server_utils67.BadRequestError(error.message);
|
|
13390
|
-
}
|
|
13391
|
-
try {
|
|
13392
|
-
_id = new import_mongodb38.ObjectId(_id);
|
|
13393
|
-
} catch (error2) {
|
|
13394
|
-
throw new import_node_server_utils67.BadRequestError("Invalid camera ID format");
|
|
13395
|
-
}
|
|
13396
|
-
try {
|
|
13397
|
-
await collection.updateOne({ _id }, { $set: value }, { session });
|
|
13398
|
-
delCachedData();
|
|
13399
|
-
return "Successfully updated site camera.";
|
|
13400
|
-
} catch (error2) {
|
|
13401
|
-
import_node_server_utils67.logger.log({
|
|
13402
|
-
level: "error",
|
|
13403
|
-
message: error2.message
|
|
13404
|
-
});
|
|
13405
|
-
const isDuplicated = error2.message.includes("duplicate");
|
|
13406
|
-
if (isDuplicated) {
|
|
13407
|
-
throw new import_node_server_utils67.BadRequestError("ANPR already exist.");
|
|
13408
|
-
}
|
|
13409
|
-
if (error2 instanceof import_node_server_utils67.AppError) {
|
|
13410
|
-
throw error2;
|
|
13411
|
-
}
|
|
13412
|
-
throw new Error("Failed to update ANPR.");
|
|
13413
|
-
}
|
|
13414
|
-
}
|
|
13415
|
-
async function deleteById(_id, session) {
|
|
13416
|
-
try {
|
|
13417
|
-
_id = new import_mongodb38.ObjectId(_id);
|
|
13418
|
-
} catch (error) {
|
|
13419
|
-
throw new import_node_server_utils67.BadRequestError("Invalid camera ID format");
|
|
13420
|
-
}
|
|
13421
|
-
try {
|
|
13422
|
-
await collection.deleteOne({ _id }, { session });
|
|
13423
|
-
delCachedData();
|
|
13424
|
-
return "Successfully deleted site camera.";
|
|
13425
|
-
} catch (error) {
|
|
13426
|
-
import_node_server_utils67.logger.log({
|
|
13427
|
-
level: "error",
|
|
13428
|
-
message: error.message
|
|
13429
|
-
});
|
|
13430
|
-
if (error instanceof import_node_server_utils67.AppError) {
|
|
13431
|
-
throw error;
|
|
13432
|
-
}
|
|
13433
|
-
throw new Error("Failed to delete site camera.");
|
|
13434
|
-
}
|
|
13435
|
-
}
|
|
13436
|
-
async function getAllCameraWithPassword(value) {
|
|
13437
|
-
value.page = value.page ? value.page - 1 : 0;
|
|
13438
|
-
value.limit = value.limit || 10;
|
|
13439
|
-
const query = {
|
|
13440
|
-
type: value.type,
|
|
13441
|
-
...value.direction && {
|
|
13442
|
-
direction: {
|
|
13443
|
-
$in: Array.isArray(value.direction) ? value.direction : [value.direction]
|
|
13444
|
-
}
|
|
13445
|
-
}
|
|
13446
|
-
};
|
|
13447
|
-
if (value.site) {
|
|
13448
|
-
try {
|
|
13449
|
-
value.site = new import_mongodb38.ObjectId(value.site);
|
|
13450
|
-
query.site = value.site;
|
|
13451
|
-
} catch (error) {
|
|
13452
|
-
throw new import_node_server_utils67.BadRequestError("Invalid site ID format");
|
|
13453
|
-
}
|
|
13454
|
-
}
|
|
13455
|
-
try {
|
|
13456
|
-
const items = await collection.aggregate([
|
|
13457
|
-
{
|
|
13458
|
-
$match: query
|
|
13459
|
-
},
|
|
13460
|
-
{
|
|
13461
|
-
$skip: value.page * value.limit
|
|
13462
|
-
},
|
|
13463
|
-
{
|
|
13464
|
-
$limit: value.limit
|
|
13465
|
-
}
|
|
13466
|
-
]).toArray();
|
|
13467
|
-
const length = await collection.countDocuments(query);
|
|
13468
|
-
const data = (0, import_node_server_utils67.paginate)(items, value.page, value.limit, length);
|
|
13469
|
-
return data;
|
|
13470
|
-
} catch (error) {
|
|
13471
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13472
|
-
throw error;
|
|
13473
|
-
}
|
|
13474
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13475
|
-
}
|
|
13476
|
-
}
|
|
13477
|
-
return {
|
|
13478
|
-
createIndexes,
|
|
13479
|
-
add,
|
|
13480
|
-
getAll,
|
|
13481
|
-
findSiteCameras,
|
|
13482
|
-
getBySite,
|
|
13483
|
-
getBySites,
|
|
13484
|
-
delCachedData,
|
|
13485
|
-
getBySiteGuardPost,
|
|
13486
|
-
updateById,
|
|
13487
|
-
deleteById,
|
|
13488
|
-
getAllCameraWithPassword
|
|
13489
|
-
};
|
|
13490
|
-
}
|
|
13130
|
+
var import_mongodb47 = require("mongodb");
|
|
13491
13131
|
|
|
13492
|
-
// src/services/
|
|
13493
|
-
var
|
|
13132
|
+
// src/services/dahua.service.ts
|
|
13133
|
+
var import_node_server_utils75 = require("@7365admin1/node-server-utils");
|
|
13134
|
+
var import_fs = require("fs");
|
|
13135
|
+
var import_joi40 = __toESM(require("joi"));
|
|
13136
|
+
var path = __toESM(require("path"));
|
|
13137
|
+
var import_urllib = require("urllib");
|
|
13494
13138
|
|
|
13495
13139
|
// src/repositories/visitor-transaction.repo.ts
|
|
13496
|
-
var
|
|
13140
|
+
var import_node_server_utils68 = require("@7365admin1/node-server-utils");
|
|
13497
13141
|
|
|
13498
13142
|
// src/models/visitor-transactions.model.ts
|
|
13499
13143
|
var import_joi36 = __toESM(require("joi"));
|
|
13500
|
-
var
|
|
13144
|
+
var import_mongodb39 = require("mongodb");
|
|
13501
13145
|
|
|
13502
13146
|
// src/models/person.model.ts
|
|
13503
|
-
var
|
|
13147
|
+
var import_node_server_utils67 = require("@7365admin1/node-server-utils");
|
|
13504
13148
|
var import_joi35 = __toESM(require("joi"));
|
|
13505
|
-
var
|
|
13149
|
+
var import_mongodb38 = require("mongodb");
|
|
13506
13150
|
var PersonTypes = /* @__PURE__ */ ((PersonTypes3) => {
|
|
13507
13151
|
PersonTypes3["WALK_IN"] = "walk-in";
|
|
13508
13152
|
PersonTypes3["DROP_OFF"] = "drop-off";
|
|
@@ -13595,25 +13239,25 @@ var schemaUpdatePerson = import_joi35.default.object({
|
|
|
13595
13239
|
function MPerson(value) {
|
|
13596
13240
|
const { error } = schemaPerson.validate(value);
|
|
13597
13241
|
if (error) {
|
|
13598
|
-
throw new
|
|
13242
|
+
throw new import_node_server_utils67.BadRequestError(error.details[0].message);
|
|
13599
13243
|
}
|
|
13600
13244
|
if (value._id && typeof value._id === "string") {
|
|
13601
13245
|
try {
|
|
13602
|
-
value._id = new
|
|
13246
|
+
value._id = new import_mongodb38.ObjectId(value._id);
|
|
13603
13247
|
} catch (error2) {
|
|
13604
13248
|
throw new Error("Invalid ID.");
|
|
13605
13249
|
}
|
|
13606
13250
|
}
|
|
13607
13251
|
if (value.org && typeof value.org === "string") {
|
|
13608
13252
|
try {
|
|
13609
|
-
value.org = new
|
|
13253
|
+
value.org = new import_mongodb38.ObjectId(value.org);
|
|
13610
13254
|
} catch (error2) {
|
|
13611
13255
|
throw new Error("Invalid org ID.");
|
|
13612
13256
|
}
|
|
13613
13257
|
}
|
|
13614
13258
|
if (value.site && typeof value.site === "string") {
|
|
13615
13259
|
try {
|
|
13616
|
-
value.site = new
|
|
13260
|
+
value.site = new import_mongodb38.ObjectId(value.site);
|
|
13617
13261
|
} catch (error2) {
|
|
13618
13262
|
throw new Error("Invalid site ID.");
|
|
13619
13263
|
}
|
|
@@ -13622,9 +13266,9 @@ function MPerson(value) {
|
|
|
13622
13266
|
value.files = value.files.map((file) => {
|
|
13623
13267
|
if (file.id && typeof file.id === "string") {
|
|
13624
13268
|
try {
|
|
13625
|
-
file.id = new
|
|
13269
|
+
file.id = new import_mongodb38.ObjectId(file.id);
|
|
13626
13270
|
} catch {
|
|
13627
|
-
throw new
|
|
13271
|
+
throw new import_node_server_utils67.BadRequestError("Invalid file id format");
|
|
13628
13272
|
}
|
|
13629
13273
|
}
|
|
13630
13274
|
return file;
|
|
@@ -13632,7 +13276,7 @@ function MPerson(value) {
|
|
|
13632
13276
|
}
|
|
13633
13277
|
if (value.user && typeof value.user === "string") {
|
|
13634
13278
|
try {
|
|
13635
|
-
value.user = new
|
|
13279
|
+
value.user = new import_mongodb38.ObjectId(value.user);
|
|
13636
13280
|
} catch (error2) {
|
|
13637
13281
|
throw new Error("Invalid user ID.");
|
|
13638
13282
|
}
|
|
@@ -13802,28 +13446,28 @@ function MVisitorTransaction(value) {
|
|
|
13802
13446
|
}
|
|
13803
13447
|
if (value._id && typeof value._id === "string") {
|
|
13804
13448
|
try {
|
|
13805
|
-
value._id = new
|
|
13449
|
+
value._id = new import_mongodb39.ObjectId(value._id);
|
|
13806
13450
|
} catch (error2) {
|
|
13807
13451
|
throw new Error("Invalid ID.");
|
|
13808
13452
|
}
|
|
13809
13453
|
}
|
|
13810
13454
|
if (value.org && typeof value.org === "string") {
|
|
13811
13455
|
try {
|
|
13812
|
-
value.org = new
|
|
13456
|
+
value.org = new import_mongodb39.ObjectId(value.org);
|
|
13813
13457
|
} catch (error2) {
|
|
13814
13458
|
throw new Error("Invalid org ID.");
|
|
13815
13459
|
}
|
|
13816
13460
|
}
|
|
13817
13461
|
if (value.site && typeof value.site === "string") {
|
|
13818
13462
|
try {
|
|
13819
|
-
value.site = new
|
|
13463
|
+
value.site = new import_mongodb39.ObjectId(value.site);
|
|
13820
13464
|
} catch (error2) {
|
|
13821
13465
|
throw new Error("Invalid site ID.");
|
|
13822
13466
|
}
|
|
13823
13467
|
}
|
|
13824
13468
|
if (value.unit && typeof value.unit === "string") {
|
|
13825
13469
|
try {
|
|
13826
|
-
value.unit = new
|
|
13470
|
+
value.unit = new import_mongodb39.ObjectId(value.unit);
|
|
13827
13471
|
} catch (error2) {
|
|
13828
13472
|
throw new Error("Invalid unit ID.");
|
|
13829
13473
|
}
|
|
@@ -13838,9 +13482,9 @@ function MVisitorTransaction(value) {
|
|
|
13838
13482
|
if (value.visitorPass && Array.isArray(value.visitorPass) && value.visitorPass.length > 0) {
|
|
13839
13483
|
value.visitorPass = value.visitorPass.map((v) => {
|
|
13840
13484
|
if (typeof v === "string")
|
|
13841
|
-
return { keyId: new
|
|
13485
|
+
return { keyId: new import_mongodb39.ObjectId(v) };
|
|
13842
13486
|
if (v?.keyId && typeof v.keyId === "string") {
|
|
13843
|
-
return { keyId: new
|
|
13487
|
+
return { keyId: new import_mongodb39.ObjectId(v.keyId) };
|
|
13844
13488
|
}
|
|
13845
13489
|
return v;
|
|
13846
13490
|
});
|
|
@@ -13848,16 +13492,16 @@ function MVisitorTransaction(value) {
|
|
|
13848
13492
|
if (value.passKeys && Array.isArray(value.passKeys) && value.passKeys.length > 0) {
|
|
13849
13493
|
value.passKeys = value.passKeys.map((p) => {
|
|
13850
13494
|
if (typeof p === "string")
|
|
13851
|
-
return { keyId: new
|
|
13495
|
+
return { keyId: new import_mongodb39.ObjectId(p) };
|
|
13852
13496
|
if (p?.keyId && typeof p.keyId === "string") {
|
|
13853
|
-
return { keyId: new
|
|
13497
|
+
return { keyId: new import_mongodb39.ObjectId(p.keyId) };
|
|
13854
13498
|
}
|
|
13855
13499
|
return p;
|
|
13856
13500
|
});
|
|
13857
13501
|
}
|
|
13858
13502
|
if (value.inviterId && typeof value.inviterId === "string") {
|
|
13859
13503
|
try {
|
|
13860
|
-
value.inviterId = new
|
|
13504
|
+
value.inviterId = new import_mongodb39.ObjectId(value.inviterId);
|
|
13861
13505
|
} catch (error2) {
|
|
13862
13506
|
throw new Error("Invalid inviter ID.");
|
|
13863
13507
|
}
|
|
@@ -13914,12 +13558,12 @@ function MVisitorTransaction(value) {
|
|
|
13914
13558
|
}
|
|
13915
13559
|
|
|
13916
13560
|
// src/repositories/visitor-transaction.repo.ts
|
|
13917
|
-
var
|
|
13561
|
+
var import_mongodb40 = require("mongodb");
|
|
13918
13562
|
var visitors_namespace_collection = "visitor.transactions";
|
|
13919
13563
|
function useVisitorTransactionRepo() {
|
|
13920
|
-
const db =
|
|
13564
|
+
const db = import_node_server_utils68.useAtlas.getDb();
|
|
13921
13565
|
if (!db) {
|
|
13922
|
-
throw new
|
|
13566
|
+
throw new import_node_server_utils68.InternalServerError("Unable to connect to server.");
|
|
13923
13567
|
}
|
|
13924
13568
|
const collection = db.collection(visitors_namespace_collection);
|
|
13925
13569
|
async function createTextIndex() {
|
|
@@ -13933,7 +13577,7 @@ function useVisitorTransactionRepo() {
|
|
|
13933
13577
|
contact: "text"
|
|
13934
13578
|
});
|
|
13935
13579
|
} catch (error) {
|
|
13936
|
-
throw new
|
|
13580
|
+
throw new import_node_server_utils68.InternalServerError(
|
|
13937
13581
|
"Failed to create text index on visitor transaction."
|
|
13938
13582
|
);
|
|
13939
13583
|
}
|
|
@@ -13947,7 +13591,7 @@ function useVisitorTransactionRepo() {
|
|
|
13947
13591
|
console.log("Error in add visitor transaction:", error);
|
|
13948
13592
|
const isDuplicated = error.message.includes("duplicate");
|
|
13949
13593
|
if (isDuplicated) {
|
|
13950
|
-
throw new
|
|
13594
|
+
throw new import_node_server_utils68.BadRequestError("Visitor already exists.");
|
|
13951
13595
|
}
|
|
13952
13596
|
throw error;
|
|
13953
13597
|
}
|
|
@@ -13983,8 +13627,8 @@ function useVisitorTransactionRepo() {
|
|
|
13983
13627
|
expectedCheckInFilter.$lte = new Date(dateTo);
|
|
13984
13628
|
}
|
|
13985
13629
|
const query = {
|
|
13986
|
-
...
|
|
13987
|
-
...
|
|
13630
|
+
...import_mongodb40.ObjectId.isValid(org) && { org: new import_mongodb40.ObjectId(org) },
|
|
13631
|
+
...import_mongodb40.ObjectId.isValid(site) && { site: new import_mongodb40.ObjectId(site) },
|
|
13988
13632
|
...Object.keys(checkInFilter).length > 0 && { checkIn: checkInFilter },
|
|
13989
13633
|
...Object.keys(expectedCheckInFilter).length > 0 && {
|
|
13990
13634
|
expectedCheckIn: expectedCheckInFilter
|
|
@@ -14169,14 +13813,14 @@ function useVisitorTransactionRepo() {
|
|
|
14169
13813
|
collection.aggregate([...basePipeline, { $count: "total" }]).toArray()
|
|
14170
13814
|
]);
|
|
14171
13815
|
const totalCount = countResult[0]?.total || 0;
|
|
14172
|
-
const data = (0,
|
|
13816
|
+
const data = (0, import_node_server_utils68.paginate)(items, page, limit, totalCount);
|
|
14173
13817
|
return data;
|
|
14174
13818
|
} catch (error) {
|
|
14175
13819
|
throw error;
|
|
14176
13820
|
}
|
|
14177
13821
|
}
|
|
14178
13822
|
async function getVisitorTransactionById(id) {
|
|
14179
|
-
const _id = (0,
|
|
13823
|
+
const _id = (0, import_node_server_utils68.toObjectId)(id);
|
|
14180
13824
|
try {
|
|
14181
13825
|
const basePipeline = [{ $match: { _id } }];
|
|
14182
13826
|
const [result] = await collection.aggregate([
|
|
@@ -14218,7 +13862,7 @@ function useVisitorTransactionRepo() {
|
|
|
14218
13862
|
}
|
|
14219
13863
|
}
|
|
14220
13864
|
async function getOpenByPlateNumber(plateNumber, site) {
|
|
14221
|
-
const _site = typeof site === "string" ? (0,
|
|
13865
|
+
const _site = typeof site === "string" ? (0, import_node_server_utils68.toObjectId)(site) : site;
|
|
14222
13866
|
const query = {
|
|
14223
13867
|
plateNumber,
|
|
14224
13868
|
site: _site,
|
|
@@ -14228,16 +13872,16 @@ function useVisitorTransactionRepo() {
|
|
|
14228
13872
|
const data = await collection.findOne(query);
|
|
14229
13873
|
return data;
|
|
14230
13874
|
} catch (error) {
|
|
14231
|
-
throw new
|
|
13875
|
+
throw new import_node_server_utils68.InternalServerError(
|
|
14232
13876
|
"Failed to fetch visitor transaction by plate number."
|
|
14233
13877
|
);
|
|
14234
13878
|
}
|
|
14235
13879
|
}
|
|
14236
13880
|
async function updateById(_id, value, session) {
|
|
14237
13881
|
try {
|
|
14238
|
-
_id = new
|
|
13882
|
+
_id = new import_mongodb40.ObjectId(_id);
|
|
14239
13883
|
} catch (error) {
|
|
14240
|
-
throw new
|
|
13884
|
+
throw new import_node_server_utils68.BadRequestError("Invalid visitor transaction ID format.");
|
|
14241
13885
|
}
|
|
14242
13886
|
value.updatedAt = /* @__PURE__ */ new Date();
|
|
14243
13887
|
if (value.checkOut) {
|
|
@@ -14256,9 +13900,9 @@ function useVisitorTransactionRepo() {
|
|
|
14256
13900
|
}
|
|
14257
13901
|
async function deleteVisitorTransaction(_id) {
|
|
14258
13902
|
try {
|
|
14259
|
-
_id = new
|
|
13903
|
+
_id = new import_mongodb40.ObjectId(_id);
|
|
14260
13904
|
} catch (error) {
|
|
14261
|
-
throw new
|
|
13905
|
+
throw new import_node_server_utils68.BadRequestError("Invalid customer ID format.");
|
|
14262
13906
|
}
|
|
14263
13907
|
try {
|
|
14264
13908
|
const updateValue = {
|
|
@@ -14268,7 +13912,7 @@ function useVisitorTransactionRepo() {
|
|
|
14268
13912
|
};
|
|
14269
13913
|
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
14270
13914
|
if (res.modifiedCount === 0) {
|
|
14271
|
-
throw new
|
|
13915
|
+
throw new import_node_server_utils68.InternalServerError("Unable to delete visitor transaction.");
|
|
14272
13916
|
}
|
|
14273
13917
|
return res.modifiedCount;
|
|
14274
13918
|
} catch (error) {
|
|
@@ -14302,7 +13946,7 @@ function useVisitorTransactionRepo() {
|
|
|
14302
13946
|
}
|
|
14303
13947
|
}
|
|
14304
13948
|
async function getExpiredCheckedOutTransactionsBySite(siteId) {
|
|
14305
|
-
const site = (0,
|
|
13949
|
+
const site = (0, import_node_server_utils68.toObjectId)(siteId);
|
|
14306
13950
|
try {
|
|
14307
13951
|
const now = /* @__PURE__ */ new Date();
|
|
14308
13952
|
const expiredTransactions = await collection.find({
|
|
@@ -14323,7 +13967,7 @@ function useVisitorTransactionRepo() {
|
|
|
14323
13967
|
async function updateManyDahuaSyncStatus(ids, dahuaSyncStatus, session) {
|
|
14324
13968
|
try {
|
|
14325
13969
|
const objectIds = ids.map(
|
|
14326
|
-
(id) => typeof id === "string" ? new
|
|
13970
|
+
(id) => typeof id === "string" ? new import_mongodb40.ObjectId(id) : id
|
|
14327
13971
|
);
|
|
14328
13972
|
const res = await collection.updateMany(
|
|
14329
13973
|
{ _id: { $in: objectIds } },
|
|
@@ -14354,10 +13998,13 @@ function useVisitorTransactionRepo() {
|
|
|
14354
13998
|
};
|
|
14355
13999
|
}
|
|
14356
14000
|
|
|
14357
|
-
// src/
|
|
14001
|
+
// src/repositories/vehicle.repo.ts
|
|
14358
14002
|
var import_node_server_utils70 = require("@7365admin1/node-server-utils");
|
|
14003
|
+
|
|
14004
|
+
// src/models/vehicle.model.ts
|
|
14005
|
+
var import_node_server_utils69 = require("@7365admin1/node-server-utils");
|
|
14359
14006
|
var import_joi37 = __toESM(require("joi"));
|
|
14360
|
-
var
|
|
14007
|
+
var import_mongodb41 = require("mongodb");
|
|
14361
14008
|
var VehicleType = /* @__PURE__ */ ((VehicleType2) => {
|
|
14362
14009
|
VehicleType2["WHITELIST"] = "whitelist";
|
|
14363
14010
|
VehicleType2["BLOCKLIST"] = "blocklist";
|
|
@@ -14434,35 +14081,35 @@ var vehicleSchema = import_joi37.default.object({
|
|
|
14434
14081
|
function MVehicle(value) {
|
|
14435
14082
|
const { error } = vehicleSchema.validate(value);
|
|
14436
14083
|
if (error) {
|
|
14437
|
-
|
|
14438
|
-
throw new
|
|
14084
|
+
import_node_server_utils69.logger.log({ level: "error", message: error.message });
|
|
14085
|
+
throw new import_node_server_utils69.BadRequestError(error.message);
|
|
14439
14086
|
}
|
|
14440
14087
|
if (value.org) {
|
|
14441
14088
|
try {
|
|
14442
|
-
value.org = new
|
|
14089
|
+
value.org = new import_mongodb41.ObjectId(value.org);
|
|
14443
14090
|
} catch (error2) {
|
|
14444
|
-
throw new
|
|
14091
|
+
throw new import_node_server_utils69.BadRequestError("Invalid org ID format.");
|
|
14445
14092
|
}
|
|
14446
14093
|
}
|
|
14447
14094
|
if (value.site) {
|
|
14448
14095
|
try {
|
|
14449
|
-
value.site = new
|
|
14096
|
+
value.site = new import_mongodb41.ObjectId(value.site);
|
|
14450
14097
|
} catch (error2) {
|
|
14451
|
-
throw new
|
|
14098
|
+
throw new import_node_server_utils69.BadRequestError("Invalid site ID format.");
|
|
14452
14099
|
}
|
|
14453
14100
|
}
|
|
14454
14101
|
if (value.unit) {
|
|
14455
14102
|
try {
|
|
14456
|
-
value.unit = new
|
|
14103
|
+
value.unit = new import_mongodb41.ObjectId(value.unit);
|
|
14457
14104
|
} catch (error2) {
|
|
14458
|
-
throw new
|
|
14105
|
+
throw new import_node_server_utils69.BadRequestError("Invalid building unit ID format.");
|
|
14459
14106
|
}
|
|
14460
14107
|
}
|
|
14461
14108
|
if (value.peopleId) {
|
|
14462
14109
|
try {
|
|
14463
|
-
value.peopleId = new
|
|
14110
|
+
value.peopleId = new import_mongodb41.ObjectId(value.peopleId);
|
|
14464
14111
|
} catch (error2) {
|
|
14465
|
-
throw new
|
|
14112
|
+
throw new import_node_server_utils69.BadRequestError("Invalid building unit ID format.");
|
|
14466
14113
|
}
|
|
14467
14114
|
}
|
|
14468
14115
|
const createdAtDate = value.createdAt ? new Date(value.createdAt) : /* @__PURE__ */ new Date();
|
|
@@ -14510,20 +14157,20 @@ var schemaVehicleTransaction = import_joi37.default.object({
|
|
|
14510
14157
|
function MVehicleTransaction(value) {
|
|
14511
14158
|
const { error } = schemaVehicleTransaction.validate(value);
|
|
14512
14159
|
if (error) {
|
|
14513
|
-
|
|
14514
|
-
throw new
|
|
14160
|
+
import_node_server_utils69.logger.log({ level: "error", message: error.message });
|
|
14161
|
+
throw new import_node_server_utils69.BadRequestError(error.message);
|
|
14515
14162
|
}
|
|
14516
14163
|
if (value._id) {
|
|
14517
14164
|
try {
|
|
14518
|
-
value._id = new
|
|
14165
|
+
value._id = new import_mongodb41.ObjectId(value._id);
|
|
14519
14166
|
} catch (error2) {
|
|
14520
|
-
throw new
|
|
14167
|
+
throw new import_node_server_utils69.BadRequestError("Invalid ID.");
|
|
14521
14168
|
}
|
|
14522
14169
|
}
|
|
14523
14170
|
try {
|
|
14524
|
-
value.site = new
|
|
14171
|
+
value.site = new import_mongodb41.ObjectId(value.site);
|
|
14525
14172
|
} catch (error2) {
|
|
14526
|
-
throw new
|
|
14173
|
+
throw new import_node_server_utils69.BadRequestError("Invalid site ID.");
|
|
14527
14174
|
}
|
|
14528
14175
|
return {
|
|
14529
14176
|
_id: value._id,
|
|
@@ -14539,23 +14186,15 @@ function MVehicleTransaction(value) {
|
|
|
14539
14186
|
};
|
|
14540
14187
|
}
|
|
14541
14188
|
|
|
14542
|
-
// src/services/dahua.service.ts
|
|
14543
|
-
var import_node_server_utils76 = require("@7365admin1/node-server-utils");
|
|
14544
|
-
var import_fs = require("fs");
|
|
14545
|
-
var import_joi40 = __toESM(require("joi"));
|
|
14546
|
-
var path = __toESM(require("path"));
|
|
14547
|
-
var import_urllib = require("urllib");
|
|
14548
|
-
|
|
14549
14189
|
// src/repositories/vehicle.repo.ts
|
|
14550
|
-
var
|
|
14551
|
-
var import_mongodb43 = require("mongodb");
|
|
14190
|
+
var import_mongodb42 = require("mongodb");
|
|
14552
14191
|
var import_joi38 = __toESM(require("joi"));
|
|
14553
14192
|
var vehicles_namespace_collection = "vehicles";
|
|
14554
14193
|
function useVehicleRepo() {
|
|
14555
14194
|
vehicles_namespace_collection;
|
|
14556
|
-
const db =
|
|
14195
|
+
const db = import_node_server_utils70.useAtlas.getDb();
|
|
14557
14196
|
if (!db) {
|
|
14558
|
-
throw new
|
|
14197
|
+
throw new import_node_server_utils70.InternalServerError("Unable to connect to server.");
|
|
14559
14198
|
}
|
|
14560
14199
|
const collection = db.collection(vehicles_namespace_collection);
|
|
14561
14200
|
async function createIndex() {
|
|
@@ -14566,7 +14205,7 @@ function useVehicleRepo() {
|
|
|
14566
14205
|
{ key: { category: 1 } }
|
|
14567
14206
|
]);
|
|
14568
14207
|
} catch (error) {
|
|
14569
|
-
throw new
|
|
14208
|
+
throw new import_node_server_utils70.InternalServerError("Failed to create index on vehicle.");
|
|
14570
14209
|
}
|
|
14571
14210
|
}
|
|
14572
14211
|
async function createTextIndex() {
|
|
@@ -14580,7 +14219,7 @@ function useVehicleRepo() {
|
|
|
14580
14219
|
nric: "text"
|
|
14581
14220
|
});
|
|
14582
14221
|
} catch (error) {
|
|
14583
|
-
throw new
|
|
14222
|
+
throw new import_node_server_utils70.InternalServerError(
|
|
14584
14223
|
"Failed to create text index on visitor transaction."
|
|
14585
14224
|
);
|
|
14586
14225
|
}
|
|
@@ -14591,11 +14230,11 @@ function useVehicleRepo() {
|
|
|
14591
14230
|
const res = await collection.insertOne(value, { session });
|
|
14592
14231
|
return res.insertedId;
|
|
14593
14232
|
} catch (error) {
|
|
14594
|
-
|
|
14233
|
+
import_node_server_utils70.logger.log({
|
|
14595
14234
|
level: "error",
|
|
14596
14235
|
message: error.message
|
|
14597
14236
|
});
|
|
14598
|
-
if (error instanceof
|
|
14237
|
+
if (error instanceof import_node_server_utils70.AppError) {
|
|
14599
14238
|
throw error;
|
|
14600
14239
|
} else {
|
|
14601
14240
|
throw new Error("Failed to create vehicle.");
|
|
@@ -14776,7 +14415,7 @@ function useVehicleRepo() {
|
|
|
14776
14415
|
const regexCountResult = await collection.aggregate(buildGroupedCountPipeline(regexQuery)).toArray();
|
|
14777
14416
|
length = regexCountResult[0]?.total || 0;
|
|
14778
14417
|
}
|
|
14779
|
-
const data = (0,
|
|
14418
|
+
const data = (0, import_node_server_utils70.paginate)(items, page, limit, length);
|
|
14780
14419
|
return data;
|
|
14781
14420
|
} catch (error) {
|
|
14782
14421
|
throw error;
|
|
@@ -14784,9 +14423,9 @@ function useVehicleRepo() {
|
|
|
14784
14423
|
}
|
|
14785
14424
|
async function getSeasonPassTypes(site) {
|
|
14786
14425
|
try {
|
|
14787
|
-
site = new
|
|
14426
|
+
site = new import_mongodb42.ObjectId(site);
|
|
14788
14427
|
} catch (error) {
|
|
14789
|
-
throw new
|
|
14428
|
+
throw new import_node_server_utils70.BadRequestError("Invalid site ID format.");
|
|
14790
14429
|
}
|
|
14791
14430
|
try {
|
|
14792
14431
|
const categories = await collection.aggregate([
|
|
@@ -14809,17 +14448,17 @@ function useVehicleRepo() {
|
|
|
14809
14448
|
]).toArray();
|
|
14810
14449
|
return categories;
|
|
14811
14450
|
} catch (error) {
|
|
14812
|
-
if (error instanceof
|
|
14451
|
+
if (error instanceof import_node_server_utils70.BadRequestError) {
|
|
14813
14452
|
throw error;
|
|
14814
14453
|
}
|
|
14815
|
-
throw new
|
|
14454
|
+
throw new import_node_server_utils70.BadRequestError("Failed to retrieve season pass types.");
|
|
14816
14455
|
}
|
|
14817
14456
|
}
|
|
14818
14457
|
async function getVehicleById(_id) {
|
|
14819
14458
|
try {
|
|
14820
|
-
_id = new
|
|
14459
|
+
_id = new import_mongodb42.ObjectId(_id);
|
|
14821
14460
|
} catch (error) {
|
|
14822
|
-
throw new
|
|
14461
|
+
throw new import_node_server_utils70.BadRequestError("Invalid vehicle ID format.");
|
|
14823
14462
|
}
|
|
14824
14463
|
try {
|
|
14825
14464
|
const data = await collection.aggregate([
|
|
@@ -14988,7 +14627,7 @@ function useVehicleRepo() {
|
|
|
14988
14627
|
}
|
|
14989
14628
|
]).toArray();
|
|
14990
14629
|
if (!data || !data.length) {
|
|
14991
|
-
throw new
|
|
14630
|
+
throw new import_node_server_utils70.NotFoundError("Vehicle not found.");
|
|
14992
14631
|
}
|
|
14993
14632
|
const result = data[0];
|
|
14994
14633
|
return result;
|
|
@@ -14999,7 +14638,7 @@ function useVehicleRepo() {
|
|
|
14999
14638
|
async function getByPlaceNumber(value) {
|
|
15000
14639
|
const { error } = import_joi38.default.string().required().validate(value);
|
|
15001
14640
|
if (error) {
|
|
15002
|
-
throw new
|
|
14641
|
+
throw new import_node_server_utils70.BadRequestError(error.details[0].message);
|
|
15003
14642
|
}
|
|
15004
14643
|
try {
|
|
15005
14644
|
const data = await collection.findOne({
|
|
@@ -15007,7 +14646,7 @@ function useVehicleRepo() {
|
|
|
15007
14646
|
status: "active"
|
|
15008
14647
|
});
|
|
15009
14648
|
if (!data) {
|
|
15010
|
-
throw new
|
|
14649
|
+
throw new import_node_server_utils70.NotFoundError("Vehicle not found.");
|
|
15011
14650
|
}
|
|
15012
14651
|
return data;
|
|
15013
14652
|
} catch (error2) {
|
|
@@ -15016,14 +14655,14 @@ function useVehicleRepo() {
|
|
|
15016
14655
|
}
|
|
15017
14656
|
async function updateVehicleById(_id, value, session) {
|
|
15018
14657
|
try {
|
|
15019
|
-
_id = new
|
|
14658
|
+
_id = new import_mongodb42.ObjectId(_id);
|
|
15020
14659
|
} catch (error) {
|
|
15021
|
-
throw new
|
|
14660
|
+
throw new import_node_server_utils70.BadRequestError("Invalid vehicle ID format.");
|
|
15022
14661
|
}
|
|
15023
14662
|
try {
|
|
15024
14663
|
const updateValue = {
|
|
15025
14664
|
...value,
|
|
15026
|
-
updatedAt:
|
|
14665
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
15027
14666
|
};
|
|
15028
14667
|
const res = await collection.updateOne(
|
|
15029
14668
|
{ _id },
|
|
@@ -15031,7 +14670,7 @@ function useVehicleRepo() {
|
|
|
15031
14670
|
{ session }
|
|
15032
14671
|
);
|
|
15033
14672
|
if (res.modifiedCount === 0) {
|
|
15034
|
-
throw new
|
|
14673
|
+
throw new import_node_server_utils70.InternalServerError("Unable to update vehicle.");
|
|
15035
14674
|
}
|
|
15036
14675
|
return res.modifiedCount;
|
|
15037
14676
|
} catch (error) {
|
|
@@ -15040,9 +14679,9 @@ function useVehicleRepo() {
|
|
|
15040
14679
|
}
|
|
15041
14680
|
async function deleteVehicle(_id, session) {
|
|
15042
14681
|
try {
|
|
15043
|
-
_id = new
|
|
14682
|
+
_id = new import_mongodb42.ObjectId(_id);
|
|
15044
14683
|
} catch (error) {
|
|
15045
|
-
throw new
|
|
14684
|
+
throw new import_node_server_utils70.BadRequestError("Invalid vehicle ID format.");
|
|
15046
14685
|
}
|
|
15047
14686
|
try {
|
|
15048
14687
|
const updateValue = {
|
|
@@ -15055,7 +14694,7 @@ function useVehicleRepo() {
|
|
|
15055
14694
|
{ session }
|
|
15056
14695
|
);
|
|
15057
14696
|
if (res.modifiedCount === 0)
|
|
15058
|
-
throw new
|
|
14697
|
+
throw new import_node_server_utils70.InternalServerError("Unable to delete vehicle.");
|
|
15059
14698
|
return res.modifiedCount;
|
|
15060
14699
|
} catch (error) {
|
|
15061
14700
|
throw error;
|
|
@@ -15064,7 +14703,7 @@ function useVehicleRepo() {
|
|
|
15064
14703
|
async function getVehicleByPlateNumber(plateNumber) {
|
|
15065
14704
|
const { error } = import_joi38.default.string().required().validate(plateNumber);
|
|
15066
14705
|
if (error) {
|
|
15067
|
-
throw new
|
|
14706
|
+
throw new import_node_server_utils70.BadRequestError(error.details[0].message);
|
|
15068
14707
|
}
|
|
15069
14708
|
try {
|
|
15070
14709
|
const data = await collection.findOne(
|
|
@@ -15073,7 +14712,7 @@ function useVehicleRepo() {
|
|
|
15073
14712
|
);
|
|
15074
14713
|
return data;
|
|
15075
14714
|
} catch (error2) {
|
|
15076
|
-
throw new
|
|
14715
|
+
throw new import_node_server_utils70.InternalServerError(
|
|
15077
14716
|
"Failed to fetch individual by plate number."
|
|
15078
14717
|
);
|
|
15079
14718
|
}
|
|
@@ -15086,7 +14725,7 @@ function useVehicleRepo() {
|
|
|
15086
14725
|
}) {
|
|
15087
14726
|
page = page > 0 ? page - 1 : 0;
|
|
15088
14727
|
if (!nric) {
|
|
15089
|
-
throw new
|
|
14728
|
+
throw new import_node_server_utils70.BadRequestError("NRIC is required.");
|
|
15090
14729
|
}
|
|
15091
14730
|
const _nric = nric.trim();
|
|
15092
14731
|
const query = {
|
|
@@ -15113,7 +14752,7 @@ function useVehicleRepo() {
|
|
|
15113
14752
|
}
|
|
15114
14753
|
]).toArray();
|
|
15115
14754
|
const length = await collection.countDocuments(query);
|
|
15116
|
-
const data = (0,
|
|
14755
|
+
const data = (0, import_node_server_utils70.paginate)(items, page, limit, length);
|
|
15117
14756
|
return data;
|
|
15118
14757
|
} catch (error) {
|
|
15119
14758
|
throw error;
|
|
@@ -15145,7 +14784,7 @@ function useVehicleRepo() {
|
|
|
15145
14784
|
page = page > 0 ? page - 1 : 0;
|
|
15146
14785
|
const skip = page * limit;
|
|
15147
14786
|
try {
|
|
15148
|
-
const unit = (0,
|
|
14787
|
+
const unit = (0, import_node_server_utils70.toObjectId)(unitId);
|
|
15149
14788
|
const query = {
|
|
15150
14789
|
unit
|
|
15151
14790
|
};
|
|
@@ -15160,7 +14799,7 @@ function useVehicleRepo() {
|
|
|
15160
14799
|
limit
|
|
15161
14800
|
}).toArray();
|
|
15162
14801
|
const length = await collection.countDocuments(query);
|
|
15163
|
-
const data = (0,
|
|
14802
|
+
const data = (0, import_node_server_utils70.paginate)(items, page, limit, length);
|
|
15164
14803
|
return data;
|
|
15165
14804
|
} catch (error) {
|
|
15166
14805
|
throw error;
|
|
@@ -15196,7 +14835,7 @@ function useVehicleRepo() {
|
|
|
15196
14835
|
return {
|
|
15197
14836
|
updateOne: {
|
|
15198
14837
|
filter: {
|
|
15199
|
-
site: new
|
|
14838
|
+
site: new import_mongodb42.ObjectId(vehicle.site),
|
|
15200
14839
|
plateNumber,
|
|
15201
14840
|
$or: [
|
|
15202
14841
|
{ deletedAt: "" },
|
|
@@ -15207,9 +14846,9 @@ function useVehicleRepo() {
|
|
|
15207
14846
|
update: {
|
|
15208
14847
|
$set: {
|
|
15209
14848
|
...rest,
|
|
15210
|
-
site: new
|
|
15211
|
-
unit: vehicle.unit ? new
|
|
15212
|
-
org: vehicle.org ? new
|
|
14849
|
+
site: new import_mongodb42.ObjectId(vehicle.site),
|
|
14850
|
+
unit: vehicle.unit ? new import_mongodb42.ObjectId(vehicle.unit) : null,
|
|
14851
|
+
org: vehicle.org ? new import_mongodb42.ObjectId(vehicle.org) : null,
|
|
15213
14852
|
plateNumber,
|
|
15214
14853
|
updatedAt: now
|
|
15215
14854
|
},
|
|
@@ -15229,11 +14868,11 @@ function useVehicleRepo() {
|
|
|
15229
14868
|
upsertedIds: res.upsertedIds
|
|
15230
14869
|
};
|
|
15231
14870
|
} catch (error) {
|
|
15232
|
-
|
|
14871
|
+
import_node_server_utils70.logger.log({
|
|
15233
14872
|
level: "error",
|
|
15234
14873
|
message: error.message
|
|
15235
14874
|
});
|
|
15236
|
-
if (error instanceof
|
|
14875
|
+
if (error instanceof import_node_server_utils70.AppError) {
|
|
15237
14876
|
throw error;
|
|
15238
14877
|
}
|
|
15239
14878
|
throw new Error("Failed to bulk upsert vehicles.");
|
|
@@ -15259,19 +14898,19 @@ function useVehicleRepo() {
|
|
|
15259
14898
|
}
|
|
15260
14899
|
|
|
15261
14900
|
// src/services/vehicle.service.ts
|
|
15262
|
-
var
|
|
14901
|
+
var import_node_server_utils74 = require("@7365admin1/node-server-utils");
|
|
15263
14902
|
|
|
15264
14903
|
// src/repositories/person.repo.ts
|
|
15265
|
-
var
|
|
15266
|
-
var
|
|
14904
|
+
var import_node_server_utils71 = require("@7365admin1/node-server-utils");
|
|
14905
|
+
var import_mongodb43 = require("mongodb");
|
|
15267
14906
|
var site_people_namespace_collection = "site.people";
|
|
15268
14907
|
function usePersonRepo() {
|
|
15269
|
-
const db =
|
|
14908
|
+
const db = import_node_server_utils71.useAtlas.getDb();
|
|
15270
14909
|
if (!db) {
|
|
15271
|
-
throw new
|
|
14910
|
+
throw new import_node_server_utils71.InternalServerError("Unable to connect to server.");
|
|
15272
14911
|
}
|
|
15273
14912
|
const collection = db.collection(site_people_namespace_collection);
|
|
15274
|
-
const { delNamespace, getCache, setCache } = (0,
|
|
14913
|
+
const { delNamespace, getCache, setCache } = (0, import_node_server_utils71.useCache)(
|
|
15275
14914
|
site_people_namespace_collection
|
|
15276
14915
|
);
|
|
15277
14916
|
async function createIndexes() {
|
|
@@ -15281,7 +14920,7 @@ function usePersonRepo() {
|
|
|
15281
14920
|
{ key: { nric: 1 } }
|
|
15282
14921
|
]);
|
|
15283
14922
|
} catch (error) {
|
|
15284
|
-
throw new
|
|
14923
|
+
throw new import_node_server_utils71.InternalServerError("Failed to create index on site people.");
|
|
15285
14924
|
}
|
|
15286
14925
|
}
|
|
15287
14926
|
async function createTextIndex() {
|
|
@@ -15295,7 +14934,7 @@ function usePersonRepo() {
|
|
|
15295
14934
|
contact: "text"
|
|
15296
14935
|
});
|
|
15297
14936
|
} catch (error) {
|
|
15298
|
-
throw new
|
|
14937
|
+
throw new import_node_server_utils71.InternalServerError(
|
|
15299
14938
|
"Failed to create text index on site people."
|
|
15300
14939
|
);
|
|
15301
14940
|
}
|
|
@@ -15305,11 +14944,11 @@ function usePersonRepo() {
|
|
|
15305
14944
|
value = MPerson(value);
|
|
15306
14945
|
const res = await collection.insertOne(value, { session });
|
|
15307
14946
|
delNamespace().then(() => {
|
|
15308
|
-
|
|
14947
|
+
import_node_server_utils71.logger.info(
|
|
15309
14948
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
15310
14949
|
);
|
|
15311
14950
|
}).catch((err) => {
|
|
15312
|
-
|
|
14951
|
+
import_node_server_utils71.logger.error(
|
|
15313
14952
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
15314
14953
|
err
|
|
15315
14954
|
);
|
|
@@ -15318,7 +14957,7 @@ function usePersonRepo() {
|
|
|
15318
14957
|
} catch (error) {
|
|
15319
14958
|
const isDuplicated = error.message.includes("duplicate");
|
|
15320
14959
|
if (isDuplicated) {
|
|
15321
|
-
throw new
|
|
14960
|
+
throw new import_node_server_utils71.BadRequestError("Person already exists.");
|
|
15322
14961
|
}
|
|
15323
14962
|
throw error;
|
|
15324
14963
|
}
|
|
@@ -15355,8 +14994,8 @@ function usePersonRepo() {
|
|
|
15355
14994
|
{ "plates.plateNumber": { $regex: search, $options: "i" } }
|
|
15356
14995
|
]
|
|
15357
14996
|
},
|
|
15358
|
-
...
|
|
15359
|
-
...
|
|
14997
|
+
...import_mongodb43.ObjectId.isValid(org) && { org: new import_mongodb43.ObjectId(org) },
|
|
14998
|
+
...import_mongodb43.ObjectId.isValid(site) && { site: new import_mongodb43.ObjectId(site) },
|
|
15360
14999
|
...PERSON_TYPES.includes(type) && { type }
|
|
15361
15000
|
};
|
|
15362
15001
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
@@ -15372,13 +15011,13 @@ function usePersonRepo() {
|
|
|
15372
15011
|
...query.site && { site: query.site.toString() },
|
|
15373
15012
|
...PERSON_TYPES.includes(type) && { type }
|
|
15374
15013
|
};
|
|
15375
|
-
const cacheKey = (0,
|
|
15014
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(
|
|
15376
15015
|
site_people_namespace_collection,
|
|
15377
15016
|
cacheOptions
|
|
15378
15017
|
);
|
|
15379
15018
|
const cachedData = await getCache(cacheKey);
|
|
15380
15019
|
if (cachedData) {
|
|
15381
|
-
|
|
15020
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15382
15021
|
return cachedData;
|
|
15383
15022
|
}
|
|
15384
15023
|
try {
|
|
@@ -15410,9 +15049,9 @@ function usePersonRepo() {
|
|
|
15410
15049
|
collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
|
|
15411
15050
|
]);
|
|
15412
15051
|
const totalCount = countResult[0]?.total || 0;
|
|
15413
|
-
const data = (0,
|
|
15414
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
15415
|
-
(err) =>
|
|
15052
|
+
const data = (0, import_node_server_utils71.paginate)(items, page, limit, totalCount);
|
|
15053
|
+
setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
15054
|
+
(err) => import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
15416
15055
|
);
|
|
15417
15056
|
return data;
|
|
15418
15057
|
} catch (error) {
|
|
@@ -15421,9 +15060,9 @@ function usePersonRepo() {
|
|
|
15421
15060
|
}
|
|
15422
15061
|
async function updateById(_id, value, session) {
|
|
15423
15062
|
try {
|
|
15424
|
-
_id = new
|
|
15063
|
+
_id = new import_mongodb43.ObjectId(_id);
|
|
15425
15064
|
} catch (error) {
|
|
15426
|
-
throw new
|
|
15065
|
+
throw new import_node_server_utils71.BadRequestError("Invalid person transaction ID format.");
|
|
15427
15066
|
}
|
|
15428
15067
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
15429
15068
|
try {
|
|
@@ -15433,11 +15072,11 @@ function usePersonRepo() {
|
|
|
15433
15072
|
{ session }
|
|
15434
15073
|
);
|
|
15435
15074
|
delNamespace().then(() => {
|
|
15436
|
-
|
|
15075
|
+
import_node_server_utils71.logger.info(
|
|
15437
15076
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
15438
15077
|
);
|
|
15439
15078
|
}).catch((err) => {
|
|
15440
|
-
|
|
15079
|
+
import_node_server_utils71.logger.error(
|
|
15441
15080
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
15442
15081
|
err
|
|
15443
15082
|
);
|
|
@@ -15449,9 +15088,9 @@ function usePersonRepo() {
|
|
|
15449
15088
|
}
|
|
15450
15089
|
async function deleteById(_id) {
|
|
15451
15090
|
try {
|
|
15452
|
-
_id = new
|
|
15091
|
+
_id = new import_mongodb43.ObjectId(_id);
|
|
15453
15092
|
} catch (error) {
|
|
15454
|
-
throw new
|
|
15093
|
+
throw new import_node_server_utils71.BadRequestError("Invalid customer ID format.");
|
|
15455
15094
|
}
|
|
15456
15095
|
try {
|
|
15457
15096
|
const updateValue = {
|
|
@@ -15461,14 +15100,14 @@ function usePersonRepo() {
|
|
|
15461
15100
|
};
|
|
15462
15101
|
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
15463
15102
|
if (res.modifiedCount === 0) {
|
|
15464
|
-
throw new
|
|
15103
|
+
throw new import_node_server_utils71.InternalServerError("Unable to delete visitor transaction.");
|
|
15465
15104
|
}
|
|
15466
15105
|
delNamespace().then(() => {
|
|
15467
|
-
|
|
15106
|
+
import_node_server_utils71.logger.info(
|
|
15468
15107
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
15469
15108
|
);
|
|
15470
15109
|
}).catch((err) => {
|
|
15471
|
-
|
|
15110
|
+
import_node_server_utils71.logger.error(
|
|
15472
15111
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
15473
15112
|
err
|
|
15474
15113
|
);
|
|
@@ -15480,17 +15119,17 @@ function usePersonRepo() {
|
|
|
15480
15119
|
}
|
|
15481
15120
|
async function getById(_id) {
|
|
15482
15121
|
try {
|
|
15483
|
-
_id = new
|
|
15122
|
+
_id = new import_mongodb43.ObjectId(_id);
|
|
15484
15123
|
} catch (error) {
|
|
15485
|
-
throw new
|
|
15124
|
+
throw new import_node_server_utils71.BadRequestError("Invalid person ID.");
|
|
15486
15125
|
}
|
|
15487
|
-
const cacheKey = (0,
|
|
15126
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15488
15127
|
_id: String(_id)
|
|
15489
15128
|
});
|
|
15490
15129
|
try {
|
|
15491
15130
|
const cached = await getCache(cacheKey);
|
|
15492
15131
|
if (cached) {
|
|
15493
|
-
|
|
15132
|
+
import_node_server_utils71.logger.log({
|
|
15494
15133
|
level: "info",
|
|
15495
15134
|
message: `Cache hit for getById person: ${cacheKey}`
|
|
15496
15135
|
});
|
|
@@ -15500,34 +15139,34 @@ function usePersonRepo() {
|
|
|
15500
15139
|
_id
|
|
15501
15140
|
});
|
|
15502
15141
|
setCache(cacheKey, result, 300).then(() => {
|
|
15503
|
-
|
|
15142
|
+
import_node_server_utils71.logger.log({
|
|
15504
15143
|
level: "info",
|
|
15505
15144
|
message: `Cache set for person by id: ${cacheKey}`
|
|
15506
15145
|
});
|
|
15507
15146
|
}).catch((err) => {
|
|
15508
|
-
|
|
15147
|
+
import_node_server_utils71.logger.log({
|
|
15509
15148
|
level: "error",
|
|
15510
15149
|
message: `Failed to set cache for person by id: ${err.message}`
|
|
15511
15150
|
});
|
|
15512
15151
|
});
|
|
15513
15152
|
return result;
|
|
15514
15153
|
} catch (error) {
|
|
15515
|
-
if (error instanceof
|
|
15154
|
+
if (error instanceof import_node_server_utils71.AppError) {
|
|
15516
15155
|
throw error;
|
|
15517
15156
|
} else {
|
|
15518
|
-
throw new
|
|
15157
|
+
throw new import_node_server_utils71.InternalServerError("Failed to get person by id.");
|
|
15519
15158
|
}
|
|
15520
15159
|
}
|
|
15521
15160
|
}
|
|
15522
15161
|
async function getPersonByPlateNumber(plateNumber) {
|
|
15523
|
-
const cacheKey = (0,
|
|
15162
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15524
15163
|
plateNumber,
|
|
15525
15164
|
key: "get-person-plate-number"
|
|
15526
15165
|
});
|
|
15527
15166
|
try {
|
|
15528
15167
|
const cacheData = await getCache(cacheKey);
|
|
15529
15168
|
if (cacheData) {
|
|
15530
|
-
|
|
15169
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15531
15170
|
return cacheData;
|
|
15532
15171
|
}
|
|
15533
15172
|
const data = await collection.findOne(
|
|
@@ -15535,57 +15174,57 @@ function usePersonRepo() {
|
|
|
15535
15174
|
{ sort: { _id: -1 } }
|
|
15536
15175
|
);
|
|
15537
15176
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15538
|
-
|
|
15177
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15539
15178
|
}).catch((err) => {
|
|
15540
|
-
|
|
15179
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15541
15180
|
});
|
|
15542
15181
|
return data;
|
|
15543
15182
|
} catch (error) {
|
|
15544
|
-
throw new
|
|
15183
|
+
throw new import_node_server_utils71.InternalServerError(
|
|
15545
15184
|
"Failed to fetch individual by plate number."
|
|
15546
15185
|
);
|
|
15547
15186
|
}
|
|
15548
15187
|
}
|
|
15549
15188
|
async function getByNRIC(value) {
|
|
15550
15189
|
try {
|
|
15551
|
-
const cacheKey = (0,
|
|
15190
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15552
15191
|
nric: value
|
|
15553
15192
|
});
|
|
15554
15193
|
const cachedData = await getCache(cacheKey);
|
|
15555
15194
|
if (cachedData) {
|
|
15556
|
-
|
|
15195
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15557
15196
|
return cachedData;
|
|
15558
15197
|
}
|
|
15559
15198
|
const data = await collection.findOne({ nric: value });
|
|
15560
15199
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15561
|
-
|
|
15200
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15562
15201
|
}).catch((err) => {
|
|
15563
|
-
|
|
15202
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15564
15203
|
});
|
|
15565
15204
|
return data;
|
|
15566
15205
|
} catch (error) {
|
|
15567
|
-
throw new
|
|
15206
|
+
throw new import_node_server_utils71.InternalServerError("Failed to retrieve person by NRIC.");
|
|
15568
15207
|
}
|
|
15569
15208
|
}
|
|
15570
15209
|
async function getPersonByPhoneNumber(value) {
|
|
15571
15210
|
try {
|
|
15572
|
-
const cacheKey = (0,
|
|
15211
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15573
15212
|
contact: value
|
|
15574
15213
|
});
|
|
15575
15214
|
const cachedData = await getCache(cacheKey);
|
|
15576
15215
|
if (cachedData) {
|
|
15577
|
-
|
|
15216
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15578
15217
|
return cachedData;
|
|
15579
15218
|
}
|
|
15580
15219
|
const data = await collection.findOne({ contact: value });
|
|
15581
15220
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15582
|
-
|
|
15221
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15583
15222
|
}).catch((err) => {
|
|
15584
|
-
|
|
15223
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15585
15224
|
});
|
|
15586
15225
|
return data;
|
|
15587
15226
|
} catch (error) {
|
|
15588
|
-
throw new
|
|
15227
|
+
throw new import_node_server_utils71.InternalServerError(
|
|
15589
15228
|
"Failed to retrieve person by Phone Number."
|
|
15590
15229
|
);
|
|
15591
15230
|
}
|
|
@@ -15595,7 +15234,7 @@ function usePersonRepo() {
|
|
|
15595
15234
|
type = [],
|
|
15596
15235
|
unit
|
|
15597
15236
|
}, session) {
|
|
15598
|
-
const cacheKey = (0,
|
|
15237
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15599
15238
|
unit: JSON.stringify(unit),
|
|
15600
15239
|
status,
|
|
15601
15240
|
type,
|
|
@@ -15603,7 +15242,7 @@ function usePersonRepo() {
|
|
|
15603
15242
|
});
|
|
15604
15243
|
const cacheData = await getCache(cacheKey);
|
|
15605
15244
|
if (cacheData) {
|
|
15606
|
-
|
|
15245
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15607
15246
|
return cacheData;
|
|
15608
15247
|
}
|
|
15609
15248
|
try {
|
|
@@ -15616,25 +15255,25 @@ function usePersonRepo() {
|
|
|
15616
15255
|
};
|
|
15617
15256
|
const data = await collection.find(query).sort({ _id: -1 }).toArray();
|
|
15618
15257
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15619
|
-
|
|
15258
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15620
15259
|
}).catch((err) => {
|
|
15621
|
-
|
|
15260
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15622
15261
|
});
|
|
15623
15262
|
return data;
|
|
15624
15263
|
} catch (error) {
|
|
15625
|
-
throw new
|
|
15264
|
+
throw new import_node_server_utils71.InternalServerError(
|
|
15626
15265
|
"Failed to fetch people type residents by unit."
|
|
15627
15266
|
);
|
|
15628
15267
|
}
|
|
15629
15268
|
}
|
|
15630
15269
|
async function getCompany(search) {
|
|
15631
15270
|
try {
|
|
15632
|
-
const cacheKey = (0,
|
|
15271
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15633
15272
|
company: search
|
|
15634
15273
|
});
|
|
15635
15274
|
const cachedData = await getCache(cacheKey);
|
|
15636
15275
|
if (cachedData) {
|
|
15637
|
-
|
|
15276
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15638
15277
|
return cachedData;
|
|
15639
15278
|
}
|
|
15640
15279
|
const baseQuery = {
|
|
@@ -15678,24 +15317,24 @@ function usePersonRepo() {
|
|
|
15678
15317
|
]).toArray();
|
|
15679
15318
|
}
|
|
15680
15319
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15681
|
-
|
|
15320
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15682
15321
|
}).catch((err) => {
|
|
15683
|
-
|
|
15322
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15684
15323
|
});
|
|
15685
15324
|
return data;
|
|
15686
15325
|
} catch (error) {
|
|
15687
|
-
throw new
|
|
15326
|
+
throw new import_node_server_utils71.InternalServerError("Failed to fetch visitor by company.");
|
|
15688
15327
|
}
|
|
15689
15328
|
}
|
|
15690
15329
|
async function getPeopleByPlateNumber(plateNumber) {
|
|
15691
|
-
const cacheKey = (0,
|
|
15330
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15692
15331
|
plateNumber,
|
|
15693
15332
|
key: "get-people-plate-number"
|
|
15694
15333
|
});
|
|
15695
15334
|
try {
|
|
15696
15335
|
const cacheData = await getCache(cacheKey);
|
|
15697
15336
|
if (cacheData) {
|
|
15698
|
-
|
|
15337
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15699
15338
|
return cacheData;
|
|
15700
15339
|
}
|
|
15701
15340
|
const data = await collection.find(
|
|
@@ -15703,13 +15342,13 @@ function usePersonRepo() {
|
|
|
15703
15342
|
{ sort: { _id: -1 } }
|
|
15704
15343
|
).toArray();
|
|
15705
15344
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15706
|
-
|
|
15345
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15707
15346
|
}).catch((err) => {
|
|
15708
|
-
|
|
15347
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15709
15348
|
});
|
|
15710
15349
|
return data;
|
|
15711
15350
|
} catch (error) {
|
|
15712
|
-
throw new
|
|
15351
|
+
throw new import_node_server_utils71.InternalServerError("Failed to fetch people by plate number.");
|
|
15713
15352
|
}
|
|
15714
15353
|
}
|
|
15715
15354
|
async function getPeopleByNRIC({
|
|
@@ -15724,7 +15363,7 @@ function usePersonRepo() {
|
|
|
15724
15363
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
15725
15364
|
const query = {
|
|
15726
15365
|
...nric && { nric: normalizedNric },
|
|
15727
|
-
site: typeof site === "string" ? new
|
|
15366
|
+
site: typeof site === "string" ? new import_mongodb43.ObjectId(site) : site
|
|
15728
15367
|
};
|
|
15729
15368
|
const cacheOptions = {
|
|
15730
15369
|
site,
|
|
@@ -15734,32 +15373,32 @@ function usePersonRepo() {
|
|
|
15734
15373
|
sort: JSON.stringify(sort)
|
|
15735
15374
|
};
|
|
15736
15375
|
try {
|
|
15737
|
-
const cacheKey = (0,
|
|
15376
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(
|
|
15738
15377
|
site_people_namespace_collection,
|
|
15739
15378
|
cacheOptions
|
|
15740
15379
|
);
|
|
15741
15380
|
const cachedData = await getCache(cacheKey);
|
|
15742
15381
|
if (cachedData) {
|
|
15743
|
-
|
|
15382
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15744
15383
|
return cachedData;
|
|
15745
15384
|
}
|
|
15746
15385
|
const items = await collection.find(query).sort(sort).skip(page * limit).limit(limit).toArray();
|
|
15747
15386
|
const length = await collection.countDocuments(query);
|
|
15748
|
-
const data = (0,
|
|
15387
|
+
const data = (0, import_node_server_utils71.paginate)(items, page, limit, length);
|
|
15749
15388
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15750
|
-
|
|
15389
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15751
15390
|
}).catch((err) => {
|
|
15752
|
-
|
|
15391
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15753
15392
|
});
|
|
15754
15393
|
return data;
|
|
15755
15394
|
} catch (error) {
|
|
15756
|
-
throw new
|
|
15395
|
+
throw new import_node_server_utils71.InternalServerError("Failed to retrieve person by NRIC.");
|
|
15757
15396
|
}
|
|
15758
15397
|
}
|
|
15759
15398
|
async function pushVehicleById(id, plate, session) {
|
|
15760
15399
|
const { plateNumber, recNo } = plate;
|
|
15761
15400
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
15762
|
-
const _id = (0,
|
|
15401
|
+
const _id = (0, import_node_server_utils71.toObjectId)(id);
|
|
15763
15402
|
try {
|
|
15764
15403
|
const updateExisting = await collection.updateOne(
|
|
15765
15404
|
{
|
|
@@ -15792,7 +15431,7 @@ function usePersonRepo() {
|
|
|
15792
15431
|
);
|
|
15793
15432
|
}
|
|
15794
15433
|
} catch (error) {
|
|
15795
|
-
throw new
|
|
15434
|
+
throw new import_node_server_utils71.InternalServerError("Failed to push vehicle plates by nric.");
|
|
15796
15435
|
}
|
|
15797
15436
|
}
|
|
15798
15437
|
async function pullVehicleByRecNo(recNo, session) {
|
|
@@ -15813,18 +15452,18 @@ function usePersonRepo() {
|
|
|
15813
15452
|
{ session }
|
|
15814
15453
|
);
|
|
15815
15454
|
} catch (error) {
|
|
15816
|
-
throw new
|
|
15455
|
+
throw new import_node_server_utils71.InternalServerError("Failed to pull vehicle plates by nric.");
|
|
15817
15456
|
}
|
|
15818
15457
|
}
|
|
15819
15458
|
async function getByUserId(userId) {
|
|
15820
|
-
const user = (0,
|
|
15821
|
-
const cacheKey = (0,
|
|
15459
|
+
const user = (0, import_node_server_utils71.toObjectId)(userId);
|
|
15460
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15822
15461
|
user: userId
|
|
15823
15462
|
});
|
|
15824
15463
|
try {
|
|
15825
15464
|
const cached = await getCache(cacheKey);
|
|
15826
15465
|
if (cached) {
|
|
15827
|
-
|
|
15466
|
+
import_node_server_utils71.logger.log({
|
|
15828
15467
|
level: "info",
|
|
15829
15468
|
message: `Cache hit for getByUserId person: ${cacheKey}`
|
|
15830
15469
|
});
|
|
@@ -15834,31 +15473,31 @@ function usePersonRepo() {
|
|
|
15834
15473
|
user
|
|
15835
15474
|
});
|
|
15836
15475
|
setCache(cacheKey, result, 15 * 60).then(() => {
|
|
15837
|
-
|
|
15476
|
+
import_node_server_utils71.logger.log({
|
|
15838
15477
|
level: "info",
|
|
15839
15478
|
message: `Cache set for person by user: ${cacheKey}`
|
|
15840
15479
|
});
|
|
15841
15480
|
}).catch((err) => {
|
|
15842
|
-
|
|
15481
|
+
import_node_server_utils71.logger.log({
|
|
15843
15482
|
level: "error",
|
|
15844
15483
|
message: `Failed to set cache for person by user: ${err.message}`
|
|
15845
15484
|
});
|
|
15846
15485
|
});
|
|
15847
15486
|
return result;
|
|
15848
15487
|
} catch (error) {
|
|
15849
|
-
if (error instanceof
|
|
15488
|
+
if (error instanceof import_node_server_utils71.AppError) {
|
|
15850
15489
|
throw error;
|
|
15851
15490
|
} else {
|
|
15852
|
-
throw new
|
|
15491
|
+
throw new import_node_server_utils71.InternalServerError("Failed to get person by user.");
|
|
15853
15492
|
}
|
|
15854
15493
|
}
|
|
15855
15494
|
}
|
|
15856
15495
|
async function reviewResidentPerson(_id, value, session) {
|
|
15857
15496
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
15858
15497
|
try {
|
|
15859
|
-
_id = new
|
|
15498
|
+
_id = new import_mongodb43.ObjectId(_id);
|
|
15860
15499
|
} catch (error) {
|
|
15861
|
-
throw new
|
|
15500
|
+
throw new import_node_server_utils71.BadRequestError("Invalid ID format.");
|
|
15862
15501
|
}
|
|
15863
15502
|
try {
|
|
15864
15503
|
const res = await collection.updateOne(
|
|
@@ -15867,14 +15506,14 @@ function usePersonRepo() {
|
|
|
15867
15506
|
{ session }
|
|
15868
15507
|
);
|
|
15869
15508
|
if (res.modifiedCount === 0) {
|
|
15870
|
-
throw new
|
|
15509
|
+
throw new import_node_server_utils71.InternalServerError(`Unable to ${value.status} person.`);
|
|
15871
15510
|
}
|
|
15872
15511
|
delNamespace().then(() => {
|
|
15873
|
-
|
|
15512
|
+
import_node_server_utils71.logger.info(
|
|
15874
15513
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
15875
15514
|
);
|
|
15876
15515
|
}).catch((err) => {
|
|
15877
|
-
|
|
15516
|
+
import_node_server_utils71.logger.error(
|
|
15878
15517
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
15879
15518
|
err
|
|
15880
15519
|
);
|
|
@@ -15907,15 +15546,15 @@ function usePersonRepo() {
|
|
|
15907
15546
|
}
|
|
15908
15547
|
|
|
15909
15548
|
// src/services/vehicle.service.ts
|
|
15910
|
-
var
|
|
15549
|
+
var import_mongodb46 = require("mongodb");
|
|
15911
15550
|
|
|
15912
15551
|
// src/repositories/building-unit.repository.ts
|
|
15913
|
-
var
|
|
15552
|
+
var import_node_server_utils73 = require("@7365admin1/node-server-utils");
|
|
15914
15553
|
|
|
15915
15554
|
// src/models/building.model.ts
|
|
15916
|
-
var
|
|
15555
|
+
var import_node_server_utils72 = require("@7365admin1/node-server-utils");
|
|
15917
15556
|
var import_joi39 = __toESM(require("joi"));
|
|
15918
|
-
var
|
|
15557
|
+
var import_mongodb44 = require("mongodb");
|
|
15919
15558
|
var SortFields = /* @__PURE__ */ ((SortFields2) => {
|
|
15920
15559
|
SortFields2["ID"] = "_id";
|
|
15921
15560
|
SortFields2["CREATED_AT"] = "createdAt";
|
|
@@ -16004,20 +15643,20 @@ var schemaUpdateOptions = import_joi39.default.object({
|
|
|
16004
15643
|
function MBuilding(value) {
|
|
16005
15644
|
const { error } = schemaBuilding.validate(value);
|
|
16006
15645
|
if (error) {
|
|
16007
|
-
|
|
16008
|
-
throw new
|
|
15646
|
+
import_node_server_utils72.logger.info(`Building Model: ${error.message}`);
|
|
15647
|
+
throw new import_node_server_utils72.BadRequestError(error.message);
|
|
16009
15648
|
}
|
|
16010
15649
|
if (value._id && typeof value._id === "string") {
|
|
16011
15650
|
try {
|
|
16012
|
-
value._id = new
|
|
15651
|
+
value._id = new import_mongodb44.ObjectId(value._id);
|
|
16013
15652
|
} catch (error2) {
|
|
16014
|
-
throw new
|
|
15653
|
+
throw new import_node_server_utils72.BadRequestError("Invalid _id format");
|
|
16015
15654
|
}
|
|
16016
15655
|
}
|
|
16017
15656
|
try {
|
|
16018
|
-
value.site = new
|
|
15657
|
+
value.site = new import_mongodb44.ObjectId(value.site);
|
|
16019
15658
|
} catch (error2) {
|
|
16020
|
-
throw new
|
|
15659
|
+
throw new import_node_server_utils72.BadRequestError("Invalid site format");
|
|
16021
15660
|
}
|
|
16022
15661
|
return {
|
|
16023
15662
|
_id: value._id ?? void 0,
|
|
@@ -16036,40 +15675,40 @@ function MBuilding(value) {
|
|
|
16036
15675
|
function MBuildingUnit(value) {
|
|
16037
15676
|
const { error } = schemaBuildingUnit.validate(value);
|
|
16038
15677
|
if (error) {
|
|
16039
|
-
|
|
16040
|
-
throw new
|
|
15678
|
+
import_node_server_utils72.logger.info(`Building Unit Model: ${error.message}`);
|
|
15679
|
+
throw new import_node_server_utils72.BadRequestError(error.message);
|
|
16041
15680
|
}
|
|
16042
15681
|
if (value._id && typeof value._id === "string") {
|
|
16043
15682
|
try {
|
|
16044
|
-
value._id = new
|
|
15683
|
+
value._id = new import_mongodb44.ObjectId(value._id);
|
|
16045
15684
|
} catch (error2) {
|
|
16046
|
-
throw new
|
|
15685
|
+
throw new import_node_server_utils72.BadRequestError("Invalid ID");
|
|
16047
15686
|
}
|
|
16048
15687
|
}
|
|
16049
15688
|
try {
|
|
16050
|
-
value.site = new
|
|
15689
|
+
value.site = new import_mongodb44.ObjectId(value.site);
|
|
16051
15690
|
} catch (error2) {
|
|
16052
|
-
throw new
|
|
15691
|
+
throw new import_node_server_utils72.BadRequestError("Invalid site ID");
|
|
16053
15692
|
}
|
|
16054
15693
|
try {
|
|
16055
|
-
value.building = new
|
|
15694
|
+
value.building = new import_mongodb44.ObjectId(value.building);
|
|
16056
15695
|
} catch (error2) {
|
|
16057
|
-
throw new
|
|
15696
|
+
throw new import_node_server_utils72.BadRequestError("Invalid building ID");
|
|
16058
15697
|
}
|
|
16059
15698
|
if (value.owner && typeof value.owner === "string") {
|
|
16060
15699
|
try {
|
|
16061
|
-
value.owner = new
|
|
15700
|
+
value.owner = new import_mongodb44.ObjectId(value.owner);
|
|
16062
15701
|
} catch (error2) {
|
|
16063
|
-
throw new
|
|
15702
|
+
throw new import_node_server_utils72.BadRequestError("Invalid Owner ID");
|
|
16064
15703
|
}
|
|
16065
15704
|
}
|
|
16066
15705
|
if (value.billing && Array.isArray(value.billing)) {
|
|
16067
15706
|
value.billing = value.billing.map((billing) => {
|
|
16068
15707
|
if (billing._id && typeof billing._id === "string") {
|
|
16069
15708
|
try {
|
|
16070
|
-
billing._id = new
|
|
15709
|
+
billing._id = new import_mongodb44.ObjectId(billing._id);
|
|
16071
15710
|
} catch {
|
|
16072
|
-
throw new
|
|
15711
|
+
throw new import_node_server_utils72.BadRequestError("Invalid billing id format");
|
|
16073
15712
|
}
|
|
16074
15713
|
}
|
|
16075
15714
|
return billing;
|
|
@@ -16101,15 +15740,15 @@ function MBuildingUnit(value) {
|
|
|
16101
15740
|
}
|
|
16102
15741
|
|
|
16103
15742
|
// src/repositories/building-unit.repository.ts
|
|
16104
|
-
var
|
|
15743
|
+
var import_mongodb45 = require("mongodb");
|
|
16105
15744
|
function useBuildingUnitRepo() {
|
|
16106
|
-
const db =
|
|
15745
|
+
const db = import_node_server_utils73.useAtlas.getDb();
|
|
16107
15746
|
if (!db) {
|
|
16108
15747
|
throw new Error("Unable to connect to server.");
|
|
16109
15748
|
}
|
|
16110
15749
|
const namespace_collection = "building-units";
|
|
16111
15750
|
const collection = db.collection(namespace_collection);
|
|
16112
|
-
const { getCache, setCache, delNamespace, delCache } = (0,
|
|
15751
|
+
const { getCache, setCache, delNamespace, delCache } = (0, import_node_server_utils73.useCache)(namespace_collection);
|
|
16113
15752
|
async function createIndexes() {
|
|
16114
15753
|
try {
|
|
16115
15754
|
await collection.createIndexes([
|
|
@@ -16133,12 +15772,12 @@ function useBuildingUnitRepo() {
|
|
|
16133
15772
|
}
|
|
16134
15773
|
function delCachedData() {
|
|
16135
15774
|
delNamespace().then(() => {
|
|
16136
|
-
|
|
15775
|
+
import_node_server_utils73.logger.log({
|
|
16137
15776
|
level: "info",
|
|
16138
15777
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
16139
15778
|
});
|
|
16140
15779
|
}).catch((err) => {
|
|
16141
|
-
|
|
15780
|
+
import_node_server_utils73.logger.log({
|
|
16142
15781
|
level: "error",
|
|
16143
15782
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
16144
15783
|
});
|
|
@@ -16163,15 +15802,15 @@ function useBuildingUnitRepo() {
|
|
|
16163
15802
|
delCachedData();
|
|
16164
15803
|
return res.insertedId;
|
|
16165
15804
|
} catch (error) {
|
|
16166
|
-
|
|
15805
|
+
import_node_server_utils73.logger.log({
|
|
16167
15806
|
level: "error",
|
|
16168
15807
|
message: error.message
|
|
16169
15808
|
});
|
|
16170
15809
|
const isDuplicated = error.message.includes("duplicate");
|
|
16171
15810
|
if (isDuplicated) {
|
|
16172
|
-
throw new
|
|
15811
|
+
throw new import_node_server_utils73.BadRequestError("Building unit already exists.");
|
|
16173
15812
|
}
|
|
16174
|
-
if (error instanceof
|
|
15813
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16175
15814
|
throw error;
|
|
16176
15815
|
} else {
|
|
16177
15816
|
throw new Error("Failed to create building unit.");
|
|
@@ -16181,27 +15820,27 @@ function useBuildingUnitRepo() {
|
|
|
16181
15820
|
async function updateById(_id, value, session) {
|
|
16182
15821
|
const { error } = schemaUpdateOptions.validate(value);
|
|
16183
15822
|
if (error) {
|
|
16184
|
-
throw new
|
|
15823
|
+
throw new import_node_server_utils73.BadRequestError(error.message);
|
|
16185
15824
|
}
|
|
16186
15825
|
try {
|
|
16187
|
-
_id = new
|
|
15826
|
+
_id = new import_mongodb45.ObjectId(_id);
|
|
16188
15827
|
} catch (error2) {
|
|
16189
|
-
throw new
|
|
15828
|
+
throw new import_node_server_utils73.BadRequestError("Invalid ID.");
|
|
16190
15829
|
}
|
|
16191
15830
|
if (value.billing && Array.isArray(value.billing)) {
|
|
16192
15831
|
value.billing = value.billing.map((billing) => {
|
|
16193
15832
|
if (billing._id && typeof billing._id === "string") {
|
|
16194
15833
|
try {
|
|
16195
|
-
billing._id = new
|
|
15834
|
+
billing._id = new import_mongodb45.ObjectId(billing._id);
|
|
16196
15835
|
} catch {
|
|
16197
|
-
throw new
|
|
15836
|
+
throw new import_node_server_utils73.BadRequestError("Invalid billing id format");
|
|
16198
15837
|
}
|
|
16199
15838
|
}
|
|
16200
15839
|
return billing;
|
|
16201
15840
|
});
|
|
16202
15841
|
}
|
|
16203
15842
|
if (value.owner) {
|
|
16204
|
-
value.owner = new
|
|
15843
|
+
value.owner = new import_mongodb45.ObjectId(value.owner);
|
|
16205
15844
|
}
|
|
16206
15845
|
try {
|
|
16207
15846
|
const res = await collection.updateOne(
|
|
@@ -16212,15 +15851,15 @@ function useBuildingUnitRepo() {
|
|
|
16212
15851
|
delCachedData();
|
|
16213
15852
|
return res;
|
|
16214
15853
|
} catch (error2) {
|
|
16215
|
-
|
|
15854
|
+
import_node_server_utils73.logger.log({
|
|
16216
15855
|
level: "error",
|
|
16217
15856
|
message: error2.message
|
|
16218
15857
|
});
|
|
16219
15858
|
const isDuplicated = error2.message.includes("duplicate");
|
|
16220
15859
|
if (isDuplicated) {
|
|
16221
|
-
throw new
|
|
15860
|
+
throw new import_node_server_utils73.BadRequestError("Building unit already exists.");
|
|
16222
15861
|
}
|
|
16223
|
-
if (error2 instanceof
|
|
15862
|
+
if (error2 instanceof import_node_server_utils73.AppError) {
|
|
16224
15863
|
throw error2;
|
|
16225
15864
|
} else {
|
|
16226
15865
|
throw new Error("Failed to create building unit.");
|
|
@@ -16230,12 +15869,12 @@ function useBuildingUnitRepo() {
|
|
|
16230
15869
|
async function updateByBuildingId(building, value, session) {
|
|
16231
15870
|
const { error } = schemaUpdateOptions.validate(value);
|
|
16232
15871
|
if (error) {
|
|
16233
|
-
throw new
|
|
15872
|
+
throw new import_node_server_utils73.BadRequestError(error.message);
|
|
16234
15873
|
}
|
|
16235
15874
|
try {
|
|
16236
|
-
building = new
|
|
15875
|
+
building = new import_mongodb45.ObjectId(building);
|
|
16237
15876
|
} catch (error2) {
|
|
16238
|
-
throw new
|
|
15877
|
+
throw new import_node_server_utils73.BadRequestError("Invalid building ID.");
|
|
16239
15878
|
}
|
|
16240
15879
|
try {
|
|
16241
15880
|
const res = await collection.updateMany(
|
|
@@ -16246,15 +15885,15 @@ function useBuildingUnitRepo() {
|
|
|
16246
15885
|
delCachedData();
|
|
16247
15886
|
return res;
|
|
16248
15887
|
} catch (error2) {
|
|
16249
|
-
|
|
15888
|
+
import_node_server_utils73.logger.log({
|
|
16250
15889
|
level: "error",
|
|
16251
15890
|
message: error2.message
|
|
16252
15891
|
});
|
|
16253
15892
|
const isDuplicated = error2.message.includes("duplicate");
|
|
16254
15893
|
if (isDuplicated) {
|
|
16255
|
-
throw new
|
|
15894
|
+
throw new import_node_server_utils73.BadRequestError("Building unit already exists.");
|
|
16256
15895
|
}
|
|
16257
|
-
if (error2 instanceof
|
|
15896
|
+
if (error2 instanceof import_node_server_utils73.AppError) {
|
|
16258
15897
|
throw error2;
|
|
16259
15898
|
} else {
|
|
16260
15899
|
throw new Error("Failed to create building unit.");
|
|
@@ -16274,8 +15913,8 @@ function useBuildingUnitRepo() {
|
|
|
16274
15913
|
const query = {
|
|
16275
15914
|
status,
|
|
16276
15915
|
...search && { $text: { $search: search } },
|
|
16277
|
-
...site && { site: (0,
|
|
16278
|
-
...building && { building: (0,
|
|
15916
|
+
...site && { site: (0, import_node_server_utils73.toObjectId)(site) },
|
|
15917
|
+
...building && { building: (0, import_node_server_utils73.toObjectId)(building) }
|
|
16279
15918
|
};
|
|
16280
15919
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
16281
15920
|
const cacheParams = {
|
|
@@ -16287,15 +15926,15 @@ function useBuildingUnitRepo() {
|
|
|
16287
15926
|
...building && { building },
|
|
16288
15927
|
...status && { status }
|
|
16289
15928
|
};
|
|
16290
|
-
const cacheKey = (0,
|
|
16291
|
-
|
|
15929
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, cacheParams);
|
|
15930
|
+
import_node_server_utils73.logger.log({
|
|
16292
15931
|
level: "info",
|
|
16293
15932
|
message: `Cache key for getAll building units: ${cacheKey}`
|
|
16294
15933
|
});
|
|
16295
15934
|
try {
|
|
16296
15935
|
const cached = await getCache(cacheKey);
|
|
16297
15936
|
if (cached) {
|
|
16298
|
-
|
|
15937
|
+
import_node_server_utils73.logger.log({
|
|
16299
15938
|
level: "info",
|
|
16300
15939
|
message: `Cache hit for getAll building units: ${cacheKey}`
|
|
16301
15940
|
});
|
|
@@ -16334,35 +15973,35 @@ function useBuildingUnitRepo() {
|
|
|
16334
15973
|
{ $limit: limit }
|
|
16335
15974
|
]).toArray();
|
|
16336
15975
|
const length = await collection.countDocuments(query);
|
|
16337
|
-
const data = (0,
|
|
15976
|
+
const data = (0, import_node_server_utils73.paginate)(items, page, limit, length);
|
|
16338
15977
|
setCache(cacheKey, data, 600).then(() => {
|
|
16339
|
-
|
|
15978
|
+
import_node_server_utils73.logger.log({
|
|
16340
15979
|
level: "info",
|
|
16341
15980
|
message: `Cache set for getAll building units: ${cacheKey}`
|
|
16342
15981
|
});
|
|
16343
15982
|
}).catch((err) => {
|
|
16344
|
-
|
|
15983
|
+
import_node_server_utils73.logger.log({
|
|
16345
15984
|
level: "error",
|
|
16346
15985
|
message: `Failed to set cache for getAll building units: ${err.message}`
|
|
16347
15986
|
});
|
|
16348
15987
|
});
|
|
16349
15988
|
return data;
|
|
16350
15989
|
} catch (error) {
|
|
16351
|
-
|
|
15990
|
+
import_node_server_utils73.logger.log({ level: "error", message: `${error}` });
|
|
16352
15991
|
throw error;
|
|
16353
15992
|
}
|
|
16354
15993
|
}
|
|
16355
15994
|
async function getById(_id, session) {
|
|
16356
15995
|
try {
|
|
16357
|
-
_id = new
|
|
15996
|
+
_id = new import_mongodb45.ObjectId(_id);
|
|
16358
15997
|
} catch (error) {
|
|
16359
|
-
throw new
|
|
15998
|
+
throw new import_node_server_utils73.BadRequestError("Invalid ID.");
|
|
16360
15999
|
}
|
|
16361
|
-
const cacheKey = (0,
|
|
16000
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
16362
16001
|
try {
|
|
16363
16002
|
const cached = await getCache(cacheKey);
|
|
16364
16003
|
if (cached) {
|
|
16365
|
-
|
|
16004
|
+
import_node_server_utils73.logger.log({
|
|
16366
16005
|
level: "info",
|
|
16367
16006
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
16368
16007
|
});
|
|
@@ -16373,42 +16012,42 @@ function useBuildingUnitRepo() {
|
|
|
16373
16012
|
deletedAt: { $in: ["", null] }
|
|
16374
16013
|
});
|
|
16375
16014
|
if (!result) {
|
|
16376
|
-
throw new
|
|
16015
|
+
throw new import_node_server_utils73.BadRequestError("Building unit not found.");
|
|
16377
16016
|
}
|
|
16378
16017
|
setCache(cacheKey, result, 300).then(() => {
|
|
16379
|
-
|
|
16018
|
+
import_node_server_utils73.logger.log({
|
|
16380
16019
|
level: "info",
|
|
16381
16020
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
16382
16021
|
});
|
|
16383
16022
|
}).catch((err) => {
|
|
16384
|
-
|
|
16023
|
+
import_node_server_utils73.logger.log({
|
|
16385
16024
|
level: "error",
|
|
16386
16025
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
16387
16026
|
});
|
|
16388
16027
|
});
|
|
16389
16028
|
return result;
|
|
16390
16029
|
} catch (error) {
|
|
16391
|
-
if (error instanceof
|
|
16030
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16392
16031
|
throw error;
|
|
16393
16032
|
} else {
|
|
16394
|
-
throw new
|
|
16033
|
+
throw new import_node_server_utils73.InternalServerError("Failed to get building unit.");
|
|
16395
16034
|
}
|
|
16396
16035
|
}
|
|
16397
16036
|
}
|
|
16398
16037
|
async function getByBuildingLevel(building, level) {
|
|
16399
16038
|
try {
|
|
16400
|
-
building = new
|
|
16039
|
+
building = new import_mongodb45.ObjectId(building);
|
|
16401
16040
|
} catch (error) {
|
|
16402
|
-
throw new
|
|
16041
|
+
throw new import_node_server_utils73.BadRequestError("Invalid building ID.");
|
|
16403
16042
|
}
|
|
16404
|
-
const cacheKey = (0,
|
|
16043
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, {
|
|
16405
16044
|
building: String(building),
|
|
16406
16045
|
level
|
|
16407
16046
|
});
|
|
16408
16047
|
try {
|
|
16409
16048
|
const cached = await getCache(cacheKey);
|
|
16410
16049
|
if (cached) {
|
|
16411
|
-
|
|
16050
|
+
import_node_server_utils73.logger.log({
|
|
16412
16051
|
level: "info",
|
|
16413
16052
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
16414
16053
|
});
|
|
@@ -16420,30 +16059,30 @@ function useBuildingUnitRepo() {
|
|
|
16420
16059
|
status: "active"
|
|
16421
16060
|
});
|
|
16422
16061
|
setCache(cacheKey, result, 300).then(() => {
|
|
16423
|
-
|
|
16062
|
+
import_node_server_utils73.logger.log({
|
|
16424
16063
|
level: "info",
|
|
16425
16064
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
16426
16065
|
});
|
|
16427
16066
|
}).catch((err) => {
|
|
16428
|
-
|
|
16067
|
+
import_node_server_utils73.logger.log({
|
|
16429
16068
|
level: "error",
|
|
16430
16069
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
16431
16070
|
});
|
|
16432
16071
|
});
|
|
16433
16072
|
return result;
|
|
16434
16073
|
} catch (error) {
|
|
16435
|
-
if (error instanceof
|
|
16074
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16436
16075
|
throw error;
|
|
16437
16076
|
} else {
|
|
16438
|
-
throw new
|
|
16077
|
+
throw new import_node_server_utils73.InternalServerError("Failed to get building unit.");
|
|
16439
16078
|
}
|
|
16440
16079
|
}
|
|
16441
16080
|
}
|
|
16442
16081
|
async function updateLevelByBuildingLevel(building, level, newLevel, session) {
|
|
16443
16082
|
try {
|
|
16444
|
-
building = new
|
|
16083
|
+
building = new import_mongodb45.ObjectId(building);
|
|
16445
16084
|
} catch (error) {
|
|
16446
|
-
throw new
|
|
16085
|
+
throw new import_node_server_utils73.BadRequestError("Invalid building ID.");
|
|
16447
16086
|
}
|
|
16448
16087
|
try {
|
|
16449
16088
|
const result = await collection.updateMany(
|
|
@@ -16462,26 +16101,26 @@ function useBuildingUnitRepo() {
|
|
|
16462
16101
|
delCachedData();
|
|
16463
16102
|
return result;
|
|
16464
16103
|
} catch (error) {
|
|
16465
|
-
if (error instanceof
|
|
16104
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16466
16105
|
throw error;
|
|
16467
16106
|
} else {
|
|
16468
|
-
throw new
|
|
16107
|
+
throw new import_node_server_utils73.InternalServerError("Failed to update building unit level.");
|
|
16469
16108
|
}
|
|
16470
16109
|
}
|
|
16471
16110
|
}
|
|
16472
16111
|
async function getByBuilding(building) {
|
|
16473
16112
|
try {
|
|
16474
|
-
building = new
|
|
16113
|
+
building = new import_mongodb45.ObjectId(building);
|
|
16475
16114
|
} catch (error) {
|
|
16476
|
-
throw new
|
|
16115
|
+
throw new import_node_server_utils73.BadRequestError("Invalid building ID.");
|
|
16477
16116
|
}
|
|
16478
|
-
const cacheKey = (0,
|
|
16117
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, {
|
|
16479
16118
|
building: String(building)
|
|
16480
16119
|
});
|
|
16481
16120
|
try {
|
|
16482
16121
|
const cached = await getCache(cacheKey);
|
|
16483
16122
|
if (cached) {
|
|
16484
|
-
|
|
16123
|
+
import_node_server_utils73.logger.log({
|
|
16485
16124
|
level: "info",
|
|
16486
16125
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
16487
16126
|
});
|
|
@@ -16492,30 +16131,30 @@ function useBuildingUnitRepo() {
|
|
|
16492
16131
|
status: "active"
|
|
16493
16132
|
});
|
|
16494
16133
|
setCache(cacheKey, result, 300).then(() => {
|
|
16495
|
-
|
|
16134
|
+
import_node_server_utils73.logger.log({
|
|
16496
16135
|
level: "info",
|
|
16497
16136
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
16498
16137
|
});
|
|
16499
16138
|
}).catch((err) => {
|
|
16500
|
-
|
|
16139
|
+
import_node_server_utils73.logger.log({
|
|
16501
16140
|
level: "error",
|
|
16502
16141
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
16503
16142
|
});
|
|
16504
16143
|
});
|
|
16505
16144
|
return result;
|
|
16506
16145
|
} catch (error) {
|
|
16507
|
-
if (error instanceof
|
|
16146
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16508
16147
|
throw error;
|
|
16509
16148
|
} else {
|
|
16510
|
-
throw new
|
|
16149
|
+
throw new import_node_server_utils73.InternalServerError("Failed to get building unit.");
|
|
16511
16150
|
}
|
|
16512
16151
|
}
|
|
16513
16152
|
}
|
|
16514
16153
|
async function deleteById(_id, session) {
|
|
16515
16154
|
try {
|
|
16516
|
-
_id = new
|
|
16155
|
+
_id = new import_mongodb45.ObjectId(_id);
|
|
16517
16156
|
} catch (error) {
|
|
16518
|
-
throw new
|
|
16157
|
+
throw new import_node_server_utils73.BadRequestError("Invalid ID.");
|
|
16519
16158
|
}
|
|
16520
16159
|
try {
|
|
16521
16160
|
const res = await collection.updateOne(
|
|
@@ -16526,11 +16165,11 @@ function useBuildingUnitRepo() {
|
|
|
16526
16165
|
delCachedData();
|
|
16527
16166
|
return "Room/Facility deleted successfully.";
|
|
16528
16167
|
} catch (error) {
|
|
16529
|
-
|
|
16168
|
+
import_node_server_utils73.logger.log({
|
|
16530
16169
|
level: "error",
|
|
16531
16170
|
message: error.message
|
|
16532
16171
|
});
|
|
16533
|
-
if (error instanceof
|
|
16172
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16534
16173
|
throw error;
|
|
16535
16174
|
} else {
|
|
16536
16175
|
throw new Error("Failed to deleted room/facility.");
|
|
@@ -16539,9 +16178,9 @@ function useBuildingUnitRepo() {
|
|
|
16539
16178
|
}
|
|
16540
16179
|
async function getBuildingUnits(site, block, level) {
|
|
16541
16180
|
try {
|
|
16542
|
-
site = new
|
|
16181
|
+
site = new import_mongodb45.ObjectId(site);
|
|
16543
16182
|
} catch (error) {
|
|
16544
|
-
throw new
|
|
16183
|
+
throw new import_node_server_utils73.BadRequestError("Invalid site ID format.");
|
|
16545
16184
|
}
|
|
16546
16185
|
const query = { site, block, level };
|
|
16547
16186
|
const cacheOptions = {
|
|
@@ -16549,33 +16188,33 @@ function useBuildingUnitRepo() {
|
|
|
16549
16188
|
block,
|
|
16550
16189
|
level
|
|
16551
16190
|
};
|
|
16552
|
-
const cacheKey = (0,
|
|
16191
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, cacheOptions);
|
|
16553
16192
|
const cachedData = await getCache(cacheKey);
|
|
16554
16193
|
if (cachedData) {
|
|
16555
|
-
|
|
16194
|
+
import_node_server_utils73.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
16556
16195
|
return cachedData;
|
|
16557
16196
|
}
|
|
16558
16197
|
try {
|
|
16559
16198
|
const data = await collection.aggregate([{ $match: query }, { $project: { name: 1 } }]).toArray();
|
|
16560
16199
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
16561
|
-
|
|
16200
|
+
import_node_server_utils73.logger.info(`Cache set for key: ${cacheKey}`);
|
|
16562
16201
|
}).catch((err) => {
|
|
16563
|
-
|
|
16202
|
+
import_node_server_utils73.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
16564
16203
|
});
|
|
16565
16204
|
return data;
|
|
16566
16205
|
} catch (error) {
|
|
16567
|
-
if (error instanceof
|
|
16206
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16568
16207
|
throw error;
|
|
16569
16208
|
} else {
|
|
16570
|
-
throw new
|
|
16209
|
+
throw new import_node_server_utils73.InternalServerError("Failed to get building units.");
|
|
16571
16210
|
}
|
|
16572
16211
|
}
|
|
16573
16212
|
}
|
|
16574
16213
|
async function getBuildingUnitsWithOwner(site, unitIds) {
|
|
16575
16214
|
try {
|
|
16576
|
-
site = new
|
|
16215
|
+
site = new import_mongodb45.ObjectId(site);
|
|
16577
16216
|
} catch (error) {
|
|
16578
|
-
throw new
|
|
16217
|
+
throw new import_node_server_utils73.BadRequestError("Invalid site ID format.");
|
|
16579
16218
|
}
|
|
16580
16219
|
const query = {
|
|
16581
16220
|
site,
|
|
@@ -16587,25 +16226,25 @@ function useBuildingUnitRepo() {
|
|
|
16587
16226
|
const cacheOptions = {
|
|
16588
16227
|
site: site.toString()
|
|
16589
16228
|
};
|
|
16590
|
-
const cacheKey = (0,
|
|
16229
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, cacheOptions);
|
|
16591
16230
|
const cachedData = await getCache(cacheKey);
|
|
16592
16231
|
if (cachedData) {
|
|
16593
|
-
|
|
16232
|
+
import_node_server_utils73.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
16594
16233
|
return cachedData;
|
|
16595
16234
|
}
|
|
16596
16235
|
try {
|
|
16597
16236
|
const data = await collection.aggregate([{ $match: query }]).toArray();
|
|
16598
16237
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
16599
|
-
|
|
16238
|
+
import_node_server_utils73.logger.info(`Cache set for key: ${cacheKey}`);
|
|
16600
16239
|
}).catch((err) => {
|
|
16601
|
-
|
|
16240
|
+
import_node_server_utils73.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
16602
16241
|
});
|
|
16603
16242
|
return data;
|
|
16604
16243
|
} catch (error) {
|
|
16605
|
-
if (error instanceof
|
|
16244
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16606
16245
|
throw error;
|
|
16607
16246
|
} else {
|
|
16608
|
-
throw new
|
|
16247
|
+
throw new import_node_server_utils73.InternalServerError(
|
|
16609
16248
|
"Failed to get building units with owner."
|
|
16610
16249
|
);
|
|
16611
16250
|
}
|
|
@@ -16614,9 +16253,9 @@ function useBuildingUnitRepo() {
|
|
|
16614
16253
|
async function getUnitByBlockLevelUnitNumber(block, level, unitNumber, site, session) {
|
|
16615
16254
|
let _site;
|
|
16616
16255
|
try {
|
|
16617
|
-
_site = new
|
|
16256
|
+
_site = new import_mongodb45.ObjectId(site);
|
|
16618
16257
|
} catch (error) {
|
|
16619
|
-
throw new
|
|
16258
|
+
throw new import_node_server_utils73.BadRequestError("Invalid ID.");
|
|
16620
16259
|
}
|
|
16621
16260
|
const cacheOptions = {
|
|
16622
16261
|
block,
|
|
@@ -16635,11 +16274,11 @@ function useBuildingUnitRepo() {
|
|
|
16635
16274
|
{ deletedAt: "" }
|
|
16636
16275
|
]
|
|
16637
16276
|
};
|
|
16638
|
-
const cacheKey = (0,
|
|
16277
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, cacheOptions);
|
|
16639
16278
|
try {
|
|
16640
16279
|
const cached = await getCache(cacheKey);
|
|
16641
16280
|
if (cached) {
|
|
16642
|
-
|
|
16281
|
+
import_node_server_utils73.logger.log({
|
|
16643
16282
|
level: "info",
|
|
16644
16283
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
16645
16284
|
});
|
|
@@ -16649,25 +16288,25 @@ function useBuildingUnitRepo() {
|
|
|
16649
16288
|
session
|
|
16650
16289
|
});
|
|
16651
16290
|
if (!result) {
|
|
16652
|
-
throw new
|
|
16291
|
+
throw new import_node_server_utils73.BadRequestError("Building unit not found.");
|
|
16653
16292
|
}
|
|
16654
16293
|
setCache(cacheKey, result, 300).then(() => {
|
|
16655
|
-
|
|
16294
|
+
import_node_server_utils73.logger.log({
|
|
16656
16295
|
level: "info",
|
|
16657
16296
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
16658
16297
|
});
|
|
16659
16298
|
}).catch((err) => {
|
|
16660
|
-
|
|
16299
|
+
import_node_server_utils73.logger.log({
|
|
16661
16300
|
level: "error",
|
|
16662
16301
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
16663
16302
|
});
|
|
16664
16303
|
});
|
|
16665
16304
|
return result;
|
|
16666
16305
|
} catch (error) {
|
|
16667
|
-
if (error instanceof
|
|
16306
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16668
16307
|
throw error;
|
|
16669
16308
|
} else {
|
|
16670
|
-
throw new
|
|
16309
|
+
throw new import_node_server_utils73.InternalServerError("Failed to get building unit.");
|
|
16671
16310
|
}
|
|
16672
16311
|
}
|
|
16673
16312
|
}
|
|
@@ -16736,7 +16375,7 @@ function useVehicleService() {
|
|
|
16736
16375
|
async function add(value, session) {
|
|
16737
16376
|
const isExternalSession = !!session;
|
|
16738
16377
|
if (!session) {
|
|
16739
|
-
session = await
|
|
16378
|
+
session = await import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
16740
16379
|
if (!session) {
|
|
16741
16380
|
throw new Error("Unable to start session for vehicle service.");
|
|
16742
16381
|
}
|
|
@@ -16747,11 +16386,11 @@ function useVehicleService() {
|
|
|
16747
16386
|
_getById(value.org)
|
|
16748
16387
|
]);
|
|
16749
16388
|
if (!org)
|
|
16750
|
-
throw new
|
|
16389
|
+
throw new import_node_server_utils74.BadRequestError("Org not found");
|
|
16751
16390
|
if (existingPlateNumber)
|
|
16752
|
-
throw new
|
|
16391
|
+
throw new import_node_server_utils74.BadRequestError("Vehicle plate number already exists");
|
|
16753
16392
|
if (!Object.values(OrgNature).includes(org.nature)) {
|
|
16754
|
-
throw new
|
|
16393
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
16755
16394
|
"This organization is not allowed to add vehicles."
|
|
16756
16395
|
);
|
|
16757
16396
|
}
|
|
@@ -16818,7 +16457,7 @@ function useVehicleService() {
|
|
|
16818
16457
|
page++;
|
|
16819
16458
|
} while (page <= pages);
|
|
16820
16459
|
if (!siteCameras.length) {
|
|
16821
|
-
throw new
|
|
16460
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
16822
16461
|
}
|
|
16823
16462
|
}
|
|
16824
16463
|
for (const plateNumber of plateNumbers) {
|
|
@@ -16854,7 +16493,7 @@ function useVehicleService() {
|
|
|
16854
16493
|
};
|
|
16855
16494
|
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
16856
16495
|
if (dahuaResponse?.statusCode !== 200) {
|
|
16857
|
-
throw new
|
|
16496
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
16858
16497
|
`Failed to add plate number to ANPR ${_type}`
|
|
16859
16498
|
);
|
|
16860
16499
|
}
|
|
@@ -16875,7 +16514,7 @@ function useVehicleService() {
|
|
|
16875
16514
|
};
|
|
16876
16515
|
const dahuaResponse = await _updatePlateNumber(dahuaPayload);
|
|
16877
16516
|
if (dahuaResponse?.statusCode !== 200) {
|
|
16878
|
-
throw new
|
|
16517
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
16879
16518
|
`Failed to update plate number to ANPR ${_type}`
|
|
16880
16519
|
);
|
|
16881
16520
|
}
|
|
@@ -16901,7 +16540,7 @@ function useVehicleService() {
|
|
|
16901
16540
|
}
|
|
16902
16541
|
return message;
|
|
16903
16542
|
} catch (error) {
|
|
16904
|
-
|
|
16543
|
+
import_node_server_utils74.logger.error("Error in vehicle service add:", error);
|
|
16905
16544
|
if (!isExternalSession) {
|
|
16906
16545
|
await session.abortTransaction();
|
|
16907
16546
|
}
|
|
@@ -16913,7 +16552,7 @@ function useVehicleService() {
|
|
|
16913
16552
|
}
|
|
16914
16553
|
}
|
|
16915
16554
|
async function deleteVehicle(_id, recno, site, type, bypass = false) {
|
|
16916
|
-
const session =
|
|
16555
|
+
const session = import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
16917
16556
|
if (!session) {
|
|
16918
16557
|
throw new Error("Unable to start session for vehicle service.");
|
|
16919
16558
|
}
|
|
@@ -16936,7 +16575,7 @@ function useVehicleService() {
|
|
|
16936
16575
|
page++;
|
|
16937
16576
|
} while (page < pages);
|
|
16938
16577
|
if (!siteCameras.length) {
|
|
16939
|
-
throw new
|
|
16578
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
16940
16579
|
}
|
|
16941
16580
|
for (const camera of siteCameras) {
|
|
16942
16581
|
const host = camera.host;
|
|
@@ -16951,7 +16590,7 @@ function useVehicleService() {
|
|
|
16951
16590
|
};
|
|
16952
16591
|
const dahuaResponse = await _removePlateNumber(dahuaPayload);
|
|
16953
16592
|
if (!bypass && dahuaResponse?.statusCode !== 200) {
|
|
16954
|
-
throw new
|
|
16593
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
16955
16594
|
`Failed to remove plate number to ANPR from ${type}`
|
|
16956
16595
|
);
|
|
16957
16596
|
}
|
|
@@ -16963,7 +16602,7 @@ function useVehicleService() {
|
|
|
16963
16602
|
await session.commitTransaction();
|
|
16964
16603
|
return `Vehicle plate number deleted from ${type} record successfully.`;
|
|
16965
16604
|
} catch (error) {
|
|
16966
|
-
|
|
16605
|
+
import_node_server_utils74.logger.error("Error in vehicle service delete:", error);
|
|
16967
16606
|
await session.abortTransaction();
|
|
16968
16607
|
throw error;
|
|
16969
16608
|
} finally {
|
|
@@ -16971,16 +16610,16 @@ function useVehicleService() {
|
|
|
16971
16610
|
}
|
|
16972
16611
|
}
|
|
16973
16612
|
async function approveVehicleById(id, orgId, siteId) {
|
|
16974
|
-
const session =
|
|
16613
|
+
const session = import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
16975
16614
|
if (!session) {
|
|
16976
16615
|
throw new Error("Unable to start session for vehicle service.");
|
|
16977
16616
|
}
|
|
16978
16617
|
const org = await _getById(orgId);
|
|
16979
16618
|
if (!org)
|
|
16980
|
-
throw new
|
|
16619
|
+
throw new import_node_server_utils74.BadRequestError("Org not found");
|
|
16981
16620
|
const allowedNatures2 = "property_management_agency" /* PROPERTY_MANAGEMENT_AGENCY */;
|
|
16982
16621
|
if (!allowedNatures2.includes(org.nature)) {
|
|
16983
|
-
throw new
|
|
16622
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
16984
16623
|
"Only property management can approve vehicles."
|
|
16985
16624
|
);
|
|
16986
16625
|
}
|
|
@@ -16988,7 +16627,7 @@ function useVehicleService() {
|
|
|
16988
16627
|
const plate = vehicle.plates.find((p) => p._id.toString() === id);
|
|
16989
16628
|
const _plateNumber = plate?.plateNumber;
|
|
16990
16629
|
if (!vehicle) {
|
|
16991
|
-
throw new
|
|
16630
|
+
throw new import_node_server_utils74.BadRequestError("Vehicle not found");
|
|
16992
16631
|
}
|
|
16993
16632
|
const owner = vehicle.name;
|
|
16994
16633
|
const hasStart = typeof vehicle.start === "string" ? vehicle.start.trim() !== "" : !!vehicle.start;
|
|
@@ -17000,11 +16639,14 @@ function useVehicleService() {
|
|
|
17000
16639
|
endDate = new Date(startDate);
|
|
17001
16640
|
endDate.setFullYear(endDate.getFullYear() + 10);
|
|
17002
16641
|
} else {
|
|
17003
|
-
startDate = hasStart ? new Date(vehicle.start) :
|
|
17004
|
-
|
|
16642
|
+
startDate = hasStart ? new Date(vehicle.start) : /* @__PURE__ */ new Date();
|
|
16643
|
+
if (hasEnd) {
|
|
16644
|
+
endDate = new Date(vehicle.end);
|
|
16645
|
+
} else {
|
|
16646
|
+
endDate = new Date(startDate);
|
|
16647
|
+
endDate.setFullYear(endDate.getFullYear() + 10);
|
|
16648
|
+
}
|
|
17005
16649
|
}
|
|
17006
|
-
const startIso = startDate ? startDate.toISOString() : "";
|
|
17007
|
-
const endIso = endDate ? endDate.toISOString() : "";
|
|
17008
16650
|
const startDahua = startDate ? formatDahuaDate(startDate) : "";
|
|
17009
16651
|
const endDahua = endDate ? formatDahuaDate(endDate) : "";
|
|
17010
16652
|
try {
|
|
@@ -17027,7 +16669,7 @@ function useVehicleService() {
|
|
|
17027
16669
|
page++;
|
|
17028
16670
|
} while (page < pages);
|
|
17029
16671
|
if (!siteCameras.length) {
|
|
17030
|
-
throw new
|
|
16672
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
17031
16673
|
}
|
|
17032
16674
|
for (const camera of siteCameras) {
|
|
17033
16675
|
const { host, username, password } = camera;
|
|
@@ -17043,7 +16685,7 @@ function useVehicleService() {
|
|
|
17043
16685
|
};
|
|
17044
16686
|
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
17045
16687
|
if (dahuaResponse?.statusCode !== 200) {
|
|
17046
|
-
throw new
|
|
16688
|
+
throw new import_node_server_utils74.BadRequestError("Failed to add plate number to ANPR");
|
|
17047
16689
|
}
|
|
17048
16690
|
const responseData = dahuaResponse?.data.toString("utf-8");
|
|
17049
16691
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
@@ -17061,14 +16703,14 @@ function useVehicleService() {
|
|
|
17061
16703
|
}
|
|
17062
16704
|
const formattedValue = {
|
|
17063
16705
|
...value,
|
|
17064
|
-
start:
|
|
17065
|
-
end:
|
|
16706
|
+
start: startDate,
|
|
16707
|
+
end: endDate
|
|
17066
16708
|
};
|
|
17067
16709
|
await _updateVehicleById(id, formattedValue, session);
|
|
17068
16710
|
await session.commitTransaction();
|
|
17069
16711
|
return "Vehicle plate number approved and added successfully.";
|
|
17070
16712
|
} catch (error) {
|
|
17071
|
-
|
|
16713
|
+
import_node_server_utils74.logger.error("Error in vehicle service approving and adding:", error);
|
|
17072
16714
|
await session.abortTransaction();
|
|
17073
16715
|
throw error;
|
|
17074
16716
|
} finally {
|
|
@@ -17076,7 +16718,7 @@ function useVehicleService() {
|
|
|
17076
16718
|
}
|
|
17077
16719
|
}
|
|
17078
16720
|
async function processDeletingExpiredVehicles() {
|
|
17079
|
-
const session =
|
|
16721
|
+
const session = import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
17080
16722
|
if (!session) {
|
|
17081
16723
|
throw new Error("Unable to start session for vehicle service.");
|
|
17082
16724
|
}
|
|
@@ -17103,7 +16745,7 @@ function useVehicleService() {
|
|
|
17103
16745
|
page++;
|
|
17104
16746
|
} while (page < pages);
|
|
17105
16747
|
if (!siteCameras.length) {
|
|
17106
|
-
throw new
|
|
16748
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
17107
16749
|
}
|
|
17108
16750
|
for (const camera of siteCameras) {
|
|
17109
16751
|
const host = camera.host;
|
|
@@ -17123,7 +16765,7 @@ function useVehicleService() {
|
|
|
17123
16765
|
await session.commitTransaction();
|
|
17124
16766
|
return `Expired Vehicle plate numbers deleted successfully.`;
|
|
17125
16767
|
} catch (error) {
|
|
17126
|
-
|
|
16768
|
+
import_node_server_utils74.logger.error(
|
|
17127
16769
|
"Error in vehicle service process deleting expired vehicles:",
|
|
17128
16770
|
error
|
|
17129
16771
|
);
|
|
@@ -17134,16 +16776,16 @@ function useVehicleService() {
|
|
|
17134
16776
|
}
|
|
17135
16777
|
}
|
|
17136
16778
|
async function reactivateVehicleById(id, orgId, siteId) {
|
|
17137
|
-
const session =
|
|
16779
|
+
const session = import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
17138
16780
|
if (!session) {
|
|
17139
16781
|
throw new Error("Unable to start session for vehicle service.");
|
|
17140
16782
|
}
|
|
17141
16783
|
const org = await _getById(orgId);
|
|
17142
16784
|
if (!org)
|
|
17143
|
-
throw new
|
|
16785
|
+
throw new import_node_server_utils74.BadRequestError("Org not found");
|
|
17144
16786
|
const allowedNatures2 = "property_management_agency" /* PROPERTY_MANAGEMENT_AGENCY */;
|
|
17145
16787
|
if (!allowedNatures2.includes(org.nature)) {
|
|
17146
|
-
throw new
|
|
16788
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
17147
16789
|
"Only property management can reactivate vehicles."
|
|
17148
16790
|
);
|
|
17149
16791
|
}
|
|
@@ -17151,7 +16793,7 @@ function useVehicleService() {
|
|
|
17151
16793
|
const plate = vehicle.plates.find((p) => p._id.toString() === id);
|
|
17152
16794
|
const _plateNumber = plate?.plateNumber;
|
|
17153
16795
|
if (!vehicle) {
|
|
17154
|
-
throw new
|
|
16796
|
+
throw new import_node_server_utils74.BadRequestError("Vehicle not found");
|
|
17155
16797
|
}
|
|
17156
16798
|
const owner = vehicle.name;
|
|
17157
16799
|
let startDate = /* @__PURE__ */ new Date();
|
|
@@ -17181,7 +16823,7 @@ function useVehicleService() {
|
|
|
17181
16823
|
page++;
|
|
17182
16824
|
} while (page < pages);
|
|
17183
16825
|
if (!siteCameras.length) {
|
|
17184
|
-
throw new
|
|
16826
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
17185
16827
|
}
|
|
17186
16828
|
for (const camera of siteCameras) {
|
|
17187
16829
|
const { host, username, password } = camera;
|
|
@@ -17197,7 +16839,7 @@ function useVehicleService() {
|
|
|
17197
16839
|
};
|
|
17198
16840
|
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
17199
16841
|
if (dahuaResponse?.statusCode !== 200) {
|
|
17200
|
-
throw new
|
|
16842
|
+
throw new import_node_server_utils74.BadRequestError("Failed to add plate number to ANPR");
|
|
17201
16843
|
}
|
|
17202
16844
|
const responseData = dahuaResponse?.data.toString("utf-8");
|
|
17203
16845
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
@@ -17223,7 +16865,7 @@ function useVehicleService() {
|
|
|
17223
16865
|
await session.commitTransaction();
|
|
17224
16866
|
return "Vehicle reactivated successfully.";
|
|
17225
16867
|
} catch (error) {
|
|
17226
|
-
|
|
16868
|
+
import_node_server_utils74.logger.error("Error in vehicle service reactivation:", error);
|
|
17227
16869
|
await session.abortTransaction();
|
|
17228
16870
|
throw error;
|
|
17229
16871
|
} finally {
|
|
@@ -17231,7 +16873,7 @@ function useVehicleService() {
|
|
|
17231
16873
|
}
|
|
17232
16874
|
}
|
|
17233
16875
|
async function updateVehicleById(_id, value) {
|
|
17234
|
-
const session =
|
|
16876
|
+
const session = import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
17235
16877
|
if (!session) {
|
|
17236
16878
|
throw new Error("Unable to start session for vehicle service.");
|
|
17237
16879
|
}
|
|
@@ -17266,7 +16908,7 @@ function useVehicleService() {
|
|
|
17266
16908
|
page++;
|
|
17267
16909
|
} while (page < pages);
|
|
17268
16910
|
if (!siteCameras.length) {
|
|
17269
|
-
throw new
|
|
16911
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
17270
16912
|
}
|
|
17271
16913
|
for (const camera of siteCameras) {
|
|
17272
16914
|
const { host, username, password } = camera;
|
|
@@ -17283,7 +16925,7 @@ function useVehicleService() {
|
|
|
17283
16925
|
removePlateNumber
|
|
17284
16926
|
);
|
|
17285
16927
|
if (responseForDeletion?.statusCode !== 200) {
|
|
17286
|
-
throw new
|
|
16928
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
17287
16929
|
"Failed to delete plate number to ANPR"
|
|
17288
16930
|
);
|
|
17289
16931
|
}
|
|
@@ -17300,7 +16942,7 @@ function useVehicleService() {
|
|
|
17300
16942
|
};
|
|
17301
16943
|
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
17302
16944
|
if (dahuaResponse?.statusCode !== 200) {
|
|
17303
|
-
throw new
|
|
16945
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
17304
16946
|
"Failed to update plate number to ANPR"
|
|
17305
16947
|
);
|
|
17306
16948
|
}
|
|
@@ -17320,7 +16962,7 @@ function useVehicleService() {
|
|
|
17320
16962
|
};
|
|
17321
16963
|
const dahuaResponse = await _updatePlateNumber(dahuaPayload);
|
|
17322
16964
|
if (dahuaResponse?.statusCode !== 200) {
|
|
17323
|
-
throw new
|
|
16965
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
17324
16966
|
"Failed to update plate number to ANPR"
|
|
17325
16967
|
);
|
|
17326
16968
|
}
|
|
@@ -17334,7 +16976,7 @@ function useVehicleService() {
|
|
|
17334
16976
|
...start && { start },
|
|
17335
16977
|
...end && { end },
|
|
17336
16978
|
...unit && {
|
|
17337
|
-
unit: typeof unit === "string" ? new
|
|
16979
|
+
unit: typeof unit === "string" ? new import_mongodb46.ObjectId(unit) : unit
|
|
17338
16980
|
},
|
|
17339
16981
|
...value.recNo && { recNo: value.recNo },
|
|
17340
16982
|
...type && { type: value.type }
|
|
@@ -17342,7 +16984,7 @@ function useVehicleService() {
|
|
|
17342
16984
|
await _updateVehicleById(_id, formattedValue, session);
|
|
17343
16985
|
await session.commitTransaction();
|
|
17344
16986
|
} catch (error) {
|
|
17345
|
-
|
|
16987
|
+
import_node_server_utils74.logger.error("Error in vehicle service update:", error);
|
|
17346
16988
|
await session.abortTransaction();
|
|
17347
16989
|
throw error;
|
|
17348
16990
|
} finally {
|
|
@@ -17364,7 +17006,7 @@ function useVehicleService() {
|
|
|
17364
17006
|
item.unit,
|
|
17365
17007
|
site
|
|
17366
17008
|
);
|
|
17367
|
-
const unitId = unit && unit._id &&
|
|
17009
|
+
const unitId = unit && unit._id && import_mongodb46.ObjectId.isValid(unit._id) ? unit._id.toString() : unit?._id;
|
|
17368
17010
|
return {
|
|
17369
17011
|
...item,
|
|
17370
17012
|
org,
|
|
@@ -17442,7 +17084,42 @@ function useVehicleService() {
|
|
|
17442
17084
|
};
|
|
17443
17085
|
}
|
|
17444
17086
|
|
|
17087
|
+
// src/utils/logger-dahua.ts
|
|
17088
|
+
var winston = __toESM(require("winston"));
|
|
17089
|
+
var import_winston_daily_rotate_file = __toESM(require("winston-daily-rotate-file"));
|
|
17090
|
+
var loggerDahua = winston.createLogger({
|
|
17091
|
+
level: "info",
|
|
17092
|
+
format: winston.format.combine(
|
|
17093
|
+
winston.format.timestamp(),
|
|
17094
|
+
winston.format.json()
|
|
17095
|
+
),
|
|
17096
|
+
transports: [
|
|
17097
|
+
// 1. Daily Error Logs - Using the class directly
|
|
17098
|
+
new import_winston_daily_rotate_file.default({
|
|
17099
|
+
filename: "logs/dahua/error-%DATE%.log",
|
|
17100
|
+
datePattern: "YYYY-MM-DD",
|
|
17101
|
+
level: "error",
|
|
17102
|
+
zippedArchive: true,
|
|
17103
|
+
maxSize: "20m",
|
|
17104
|
+
maxFiles: "14d"
|
|
17105
|
+
}),
|
|
17106
|
+
// 2. Daily Combined Logs - Using the class directly
|
|
17107
|
+
new import_winston_daily_rotate_file.default({
|
|
17108
|
+
filename: "logs/dahua/combined-%DATE%.log",
|
|
17109
|
+
datePattern: "YYYY-MM-DD",
|
|
17110
|
+
zippedArchive: true,
|
|
17111
|
+
maxSize: "20m",
|
|
17112
|
+
maxFiles: "14d"
|
|
17113
|
+
}),
|
|
17114
|
+
// 3. Console logging (Optional)
|
|
17115
|
+
new winston.transports.Console({
|
|
17116
|
+
format: winston.format.simple()
|
|
17117
|
+
})
|
|
17118
|
+
]
|
|
17119
|
+
});
|
|
17120
|
+
|
|
17445
17121
|
// src/services/dahua.service.ts
|
|
17122
|
+
var cameraRegistry = /* @__PURE__ */ new Map();
|
|
17446
17123
|
function useDahuaDigest({
|
|
17447
17124
|
host = "",
|
|
17448
17125
|
username = "",
|
|
@@ -17499,14 +17176,14 @@ function useDahuaService() {
|
|
|
17499
17176
|
function enqueue(buffer) {
|
|
17500
17177
|
if (queue.length >= MAX_QUEUE_SIZE) {
|
|
17501
17178
|
droppedChunks++;
|
|
17502
|
-
|
|
17179
|
+
loggerDahua.error(
|
|
17503
17180
|
`[${site}][${gate}] Queue overflow. Dropped: ${droppedChunks}`
|
|
17504
17181
|
);
|
|
17505
17182
|
return;
|
|
17506
17183
|
}
|
|
17507
17184
|
queue.push(buffer);
|
|
17508
17185
|
if (queue.length >= BACKPRESSURE_THRESHOLD && streamRef && !streamRef.isPaused()) {
|
|
17509
|
-
|
|
17186
|
+
loggerDahua.warn(
|
|
17510
17187
|
`[${site}][${gate}] Queue at ${queue.length}/${MAX_QUEUE_SIZE}, pausing stream`
|
|
17511
17188
|
);
|
|
17512
17189
|
streamRef.pause();
|
|
@@ -17523,7 +17200,7 @@ function useDahuaService() {
|
|
|
17523
17200
|
if (streamRef && streamRef.isPaused()) {
|
|
17524
17201
|
streamRef.resume();
|
|
17525
17202
|
}
|
|
17526
|
-
|
|
17203
|
+
loggerDahua.info(
|
|
17527
17204
|
`[${site}][${gate}] BufferQueue destroyed. Processed=${processedChunks}, Dropped=${droppedChunks}`
|
|
17528
17205
|
);
|
|
17529
17206
|
}
|
|
@@ -17536,20 +17213,20 @@ function useDahuaService() {
|
|
|
17536
17213
|
await handleBuffer(buffer);
|
|
17537
17214
|
processedChunks++;
|
|
17538
17215
|
if (queue.length <= RESUME_THRESHOLD && streamRef && streamRef.isPaused()) {
|
|
17539
|
-
|
|
17216
|
+
loggerDahua.info(
|
|
17540
17217
|
`[${site}][${gate}] Queue at ${queue.length}/${MAX_QUEUE_SIZE}, resuming stream`
|
|
17541
17218
|
);
|
|
17542
17219
|
streamRef.resume();
|
|
17543
17220
|
}
|
|
17544
17221
|
} catch (err) {
|
|
17545
|
-
|
|
17222
|
+
loggerDahua.error(`[${site}][${gate}] Error processing buffer:`, err);
|
|
17546
17223
|
} finally {
|
|
17547
17224
|
processing = false;
|
|
17548
17225
|
processNext();
|
|
17549
17226
|
}
|
|
17550
17227
|
}
|
|
17551
17228
|
async function processVehicleTransaction() {
|
|
17552
|
-
|
|
17229
|
+
loggerDahua.info(
|
|
17553
17230
|
`[${site}][${gate}] Vehicle transaction: Plate=${plateNumber}, UTC=${UTCData}, UTCMs=${UTCMs}`
|
|
17554
17231
|
);
|
|
17555
17232
|
let org = "";
|
|
@@ -17557,7 +17234,7 @@ function useDahuaService() {
|
|
|
17557
17234
|
const theSite = await getSiteById(site);
|
|
17558
17235
|
org = theSite?.orgId.toString() || "unknown";
|
|
17559
17236
|
} catch (error) {
|
|
17560
|
-
|
|
17237
|
+
loggerDahua.error(
|
|
17561
17238
|
`[${site}][${gate}] Error fetching site for orgId:`,
|
|
17562
17239
|
error
|
|
17563
17240
|
);
|
|
@@ -17577,7 +17254,7 @@ function useDahuaService() {
|
|
|
17577
17254
|
});
|
|
17578
17255
|
}
|
|
17579
17256
|
} catch (error) {
|
|
17580
|
-
|
|
17257
|
+
loggerDahua.error(
|
|
17581
17258
|
`[${site}][${gate}] Error closing existing open transaction:`,
|
|
17582
17259
|
error
|
|
17583
17260
|
);
|
|
@@ -17633,7 +17310,7 @@ function useDahuaService() {
|
|
|
17633
17310
|
currentSnapshotField = "snapshotEntryImage";
|
|
17634
17311
|
} catch (error) {
|
|
17635
17312
|
console.log("failed to create visitor transaction", error);
|
|
17636
|
-
|
|
17313
|
+
loggerDahua.error(
|
|
17637
17314
|
`[${site}][${gate}] Error creating visitor transaction:`,
|
|
17638
17315
|
error
|
|
17639
17316
|
);
|
|
@@ -17717,7 +17394,7 @@ function useDahuaService() {
|
|
|
17717
17394
|
try {
|
|
17718
17395
|
await import_fs.promises.mkdir(dir, { recursive: true });
|
|
17719
17396
|
await import_fs.promises.writeFile(snapFolder, accumulatedImageBuffer);
|
|
17720
|
-
|
|
17397
|
+
loggerDahua.debug(`[${site}][${gate}] Saved image locally: ${filename}`);
|
|
17721
17398
|
const fileId = await _createFile(
|
|
17722
17399
|
{
|
|
17723
17400
|
originalname: filename,
|
|
@@ -17726,7 +17403,7 @@ function useDahuaService() {
|
|
|
17726
17403
|
},
|
|
17727
17404
|
`anpr/${site}`
|
|
17728
17405
|
);
|
|
17729
|
-
|
|
17406
|
+
loggerDahua.info(
|
|
17730
17407
|
`[${site}][${gate}] Created file record for image: ${fileId.toString()}`
|
|
17731
17408
|
);
|
|
17732
17409
|
if (currentTransactionId && currentSnapshotField) {
|
|
@@ -17734,23 +17411,23 @@ function useDahuaService() {
|
|
|
17734
17411
|
[currentSnapshotField]: fileId.toString()
|
|
17735
17412
|
});
|
|
17736
17413
|
}
|
|
17737
|
-
|
|
17414
|
+
loggerDahua.info(
|
|
17738
17415
|
`[${site}][${gate}] Image stored with fileId: ${fileId.toString()}`
|
|
17739
17416
|
);
|
|
17740
17417
|
await import_fs.promises.unlink(snapFolder);
|
|
17741
|
-
|
|
17418
|
+
loggerDahua.debug(`[${site}][${gate}] Deleted local file: ${filename}`);
|
|
17742
17419
|
} catch (err) {
|
|
17743
|
-
|
|
17420
|
+
loggerDahua.error(
|
|
17744
17421
|
`[${site}][${gate}] Failed to process image ${filename}:`,
|
|
17745
17422
|
err
|
|
17746
17423
|
);
|
|
17747
17424
|
try {
|
|
17748
17425
|
await import_fs.promises.unlink(snapFolder);
|
|
17749
|
-
|
|
17426
|
+
loggerDahua.debug(
|
|
17750
17427
|
`[${site}][${gate}] Cleaned up local file after error: ${filename}`
|
|
17751
17428
|
);
|
|
17752
17429
|
} catch (unlinkErr) {
|
|
17753
|
-
|
|
17430
|
+
loggerDahua.error(
|
|
17754
17431
|
`[${site}][${gate}] Failed to clean up local file: ${filename}`,
|
|
17755
17432
|
unlinkErr
|
|
17756
17433
|
);
|
|
@@ -17785,13 +17462,39 @@ function useDahuaService() {
|
|
|
17785
17462
|
},
|
|
17786
17463
|
"snapshots"
|
|
17787
17464
|
);
|
|
17788
|
-
|
|
17465
|
+
loggerDahua.info(`Successfully saved snapshot fileId: ${fileId.toString()}`);
|
|
17789
17466
|
return fileId;
|
|
17790
17467
|
} catch (error) {
|
|
17791
17468
|
throw error;
|
|
17792
17469
|
}
|
|
17793
17470
|
}
|
|
17794
|
-
async function
|
|
17471
|
+
async function listenToCamera(camera) {
|
|
17472
|
+
if (!camera?._id) {
|
|
17473
|
+
loggerDahua.error(`Camera _id is required to listen to camera.`);
|
|
17474
|
+
throw new import_node_server_utils75.BadRequestError("Camera _id is required to listen to camera.");
|
|
17475
|
+
}
|
|
17476
|
+
const cameraId = camera._id.toString();
|
|
17477
|
+
if (cameraRegistry.has(cameraId)) {
|
|
17478
|
+
loggerDahua.info(`[${camera.host}] Stopping existing connection for update.`);
|
|
17479
|
+
cameraRegistry.get(cameraId)?.abort();
|
|
17480
|
+
cameraRegistry.delete(cameraId);
|
|
17481
|
+
}
|
|
17482
|
+
const controller = new AbortController();
|
|
17483
|
+
cameraRegistry.set(cameraId, controller);
|
|
17484
|
+
getTrafficJunction(
|
|
17485
|
+
camera.host,
|
|
17486
|
+
camera.username,
|
|
17487
|
+
camera.password,
|
|
17488
|
+
camera.site.toString(),
|
|
17489
|
+
`guard-post-${camera.guardPost}`,
|
|
17490
|
+
camera.direction,
|
|
17491
|
+
cameraId,
|
|
17492
|
+
controller.signal
|
|
17493
|
+
);
|
|
17494
|
+
}
|
|
17495
|
+
async function getTrafficJunction(host = "", username = "", password = "", site = "", gate = "", designation = "", cameraId, signal) {
|
|
17496
|
+
if (signal.aborted)
|
|
17497
|
+
return;
|
|
17795
17498
|
try {
|
|
17796
17499
|
const response = await useDahuaDigest({
|
|
17797
17500
|
host,
|
|
@@ -17804,7 +17507,7 @@ function useDahuaService() {
|
|
|
17804
17507
|
const contentType = response.res.headers["content-type"];
|
|
17805
17508
|
const boundaryMatch = contentType?.match(/boundary=(.*)$/i);
|
|
17806
17509
|
const boundary = boundaryMatch ? `--${boundaryMatch[1]}` : "--myboundary";
|
|
17807
|
-
|
|
17510
|
+
loggerDahua.debug(`[${site}][${gate}] Using boundary: ${boundary}`);
|
|
17808
17511
|
const bufferQueue = useBufferQueue(
|
|
17809
17512
|
boundary,
|
|
17810
17513
|
site,
|
|
@@ -17815,32 +17518,58 @@ function useDahuaService() {
|
|
|
17815
17518
|
password
|
|
17816
17519
|
);
|
|
17817
17520
|
bufferQueue.setStream(response.res);
|
|
17521
|
+
const onAbort = () => {
|
|
17522
|
+
loggerDahua.info(`[${site}]-[${host}] Abort triggered. Cleaning up...`);
|
|
17523
|
+
if (response.res && !response.res.destroyed) {
|
|
17524
|
+
response.res.once("error", (err) => {
|
|
17525
|
+
if (err?.code === "UND_ERR_ABORTED") {
|
|
17526
|
+
loggerDahua.debug(`[${site}]-[${host}] Stream aborted successfully.`);
|
|
17527
|
+
} else {
|
|
17528
|
+
loggerDahua.error(`[${site}]-[${host}] Stream error during abort:`, err);
|
|
17529
|
+
}
|
|
17530
|
+
});
|
|
17531
|
+
response.res.destroy();
|
|
17532
|
+
}
|
|
17533
|
+
};
|
|
17534
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
17818
17535
|
if ([400, 401, 403, 500].includes(response.statusCode)) {
|
|
17819
|
-
|
|
17820
|
-
`[${
|
|
17536
|
+
loggerDahua.error(
|
|
17537
|
+
`[${host}] Connection error:`,
|
|
17821
17538
|
response.statusCode
|
|
17822
17539
|
);
|
|
17823
|
-
throw new
|
|
17540
|
+
throw new import_node_server_utils75.BadRequestError(
|
|
17824
17541
|
`Failed to connect to ANPR: ${response.statusCode}`
|
|
17825
17542
|
);
|
|
17826
17543
|
}
|
|
17827
17544
|
if ([200, 201, 202].includes(response.statusCode)) {
|
|
17828
|
-
|
|
17829
|
-
console.log(`[${
|
|
17545
|
+
loggerDahua.info(`[${host}] Successfully connected to ANPR.`);
|
|
17546
|
+
console.log(`[${host}] Successfully connected to ANPR.`);
|
|
17830
17547
|
}
|
|
17831
17548
|
response.res.on("data", (chunk) => {
|
|
17549
|
+
if (signal.aborted) {
|
|
17550
|
+
response.res.destroy();
|
|
17551
|
+
return;
|
|
17552
|
+
}
|
|
17832
17553
|
bufferQueue.enqueue(chunk);
|
|
17833
17554
|
});
|
|
17834
17555
|
const handleDisconnect = async (reason, err) => {
|
|
17835
|
-
|
|
17836
|
-
|
|
17837
|
-
|
|
17838
|
-
);
|
|
17839
|
-
bufferQueue.destroy();
|
|
17556
|
+
signal.removeEventListener("abort", onAbort);
|
|
17557
|
+
if (bufferQueue.destroy)
|
|
17558
|
+
bufferQueue.destroy();
|
|
17840
17559
|
if (response.res.destroy)
|
|
17841
17560
|
response.res.destroy();
|
|
17561
|
+
if (signal.aborted) {
|
|
17562
|
+
loggerDahua.info(`[${site}]-[${host}] Loop terminated. Not reconnecting.`);
|
|
17563
|
+
return;
|
|
17564
|
+
}
|
|
17565
|
+
loggerDahua.error(
|
|
17566
|
+
`[${site}]-[${host}] ${reason}`,
|
|
17567
|
+
err ? err.code || err : ""
|
|
17568
|
+
);
|
|
17842
17569
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17843
|
-
|
|
17570
|
+
if (signal.aborted)
|
|
17571
|
+
return;
|
|
17572
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17844
17573
|
};
|
|
17845
17574
|
response.res.on(
|
|
17846
17575
|
"end",
|
|
@@ -17855,12 +17584,16 @@ function useDahuaService() {
|
|
|
17855
17584
|
(err) => handleDisconnect("Connection error:", err)
|
|
17856
17585
|
);
|
|
17857
17586
|
} catch (error) {
|
|
17858
|
-
|
|
17587
|
+
if (signal.aborted)
|
|
17588
|
+
return;
|
|
17589
|
+
loggerDahua.error(
|
|
17859
17590
|
`[${site}][${gate}] Initial connect error:`,
|
|
17860
17591
|
error.code || error
|
|
17861
17592
|
);
|
|
17862
17593
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17863
|
-
|
|
17594
|
+
if (signal.aborted)
|
|
17595
|
+
return;
|
|
17596
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17864
17597
|
}
|
|
17865
17598
|
}
|
|
17866
17599
|
async function addPlateNumber(value) {
|
|
@@ -17877,7 +17610,7 @@ function useDahuaService() {
|
|
|
17877
17610
|
});
|
|
17878
17611
|
const { error } = validation.validate(value);
|
|
17879
17612
|
if (error) {
|
|
17880
|
-
throw new
|
|
17613
|
+
throw new import_node_server_utils75.BadRequestError(`Validation error: ${error.message}`);
|
|
17881
17614
|
}
|
|
17882
17615
|
value.owner = String(value.owner ?? "").substring(0, 15) || "unknown";
|
|
17883
17616
|
const _openGate = String(value.isOpenGate);
|
|
@@ -17892,8 +17625,8 @@ function useDahuaService() {
|
|
|
17892
17625
|
});
|
|
17893
17626
|
return response;
|
|
17894
17627
|
} catch (error2) {
|
|
17895
|
-
|
|
17896
|
-
throw new
|
|
17628
|
+
loggerDahua.error(`[${value.host}] Error adding plate number:`, error2);
|
|
17629
|
+
throw new import_node_server_utils75.BadRequestError(`Failed to add plate number: ${error2.message}`);
|
|
17897
17630
|
}
|
|
17898
17631
|
}
|
|
17899
17632
|
async function updatePlateNumber(value) {
|
|
@@ -17911,7 +17644,7 @@ function useDahuaService() {
|
|
|
17911
17644
|
});
|
|
17912
17645
|
const { error } = validation.validate(value);
|
|
17913
17646
|
if (error) {
|
|
17914
|
-
throw new
|
|
17647
|
+
throw new import_node_server_utils75.BadRequestError(`Validation error: ${error.message}`);
|
|
17915
17648
|
}
|
|
17916
17649
|
value.owner = value.owner || "unknown";
|
|
17917
17650
|
let _isOpenGate;
|
|
@@ -17929,8 +17662,8 @@ function useDahuaService() {
|
|
|
17929
17662
|
});
|
|
17930
17663
|
return response;
|
|
17931
17664
|
} catch (error2) {
|
|
17932
|
-
|
|
17933
|
-
throw new
|
|
17665
|
+
loggerDahua.error(`[${value.host}] Error updating plate number:`, error2);
|
|
17666
|
+
throw new import_node_server_utils75.BadRequestError(
|
|
17934
17667
|
`Failed to update plate number: ${error2.message}`
|
|
17935
17668
|
);
|
|
17936
17669
|
}
|
|
@@ -17945,7 +17678,7 @@ function useDahuaService() {
|
|
|
17945
17678
|
});
|
|
17946
17679
|
const { error } = validation.validate(value);
|
|
17947
17680
|
if (error) {
|
|
17948
|
-
throw new
|
|
17681
|
+
throw new import_node_server_utils75.BadRequestError(`Validation error: ${error.message}`);
|
|
17949
17682
|
}
|
|
17950
17683
|
try {
|
|
17951
17684
|
const response = await useDahuaDigest({
|
|
@@ -17956,7 +17689,7 @@ function useDahuaService() {
|
|
|
17956
17689
|
});
|
|
17957
17690
|
return response;
|
|
17958
17691
|
} catch (error2) {
|
|
17959
|
-
|
|
17692
|
+
loggerDahua.error(`[${value.host}] Error removing plate number:`, error2);
|
|
17960
17693
|
}
|
|
17961
17694
|
}
|
|
17962
17695
|
async function getPlateNumber(value) {
|
|
@@ -17969,7 +17702,7 @@ function useDahuaService() {
|
|
|
17969
17702
|
});
|
|
17970
17703
|
const { error } = validation.validate(value);
|
|
17971
17704
|
if (error) {
|
|
17972
|
-
throw new
|
|
17705
|
+
throw new import_node_server_utils75.BadRequestError(`Validation error: ${error.message}`);
|
|
17973
17706
|
}
|
|
17974
17707
|
try {
|
|
17975
17708
|
const response = await useDahuaDigest({
|
|
@@ -17981,7 +17714,7 @@ function useDahuaService() {
|
|
|
17981
17714
|
const text = response?.data?.toString?.("utf-8");
|
|
17982
17715
|
return text;
|
|
17983
17716
|
} catch (error2) {
|
|
17984
|
-
|
|
17717
|
+
loggerDahua.error(`[${value.host}] Error finding plate number:`, error2);
|
|
17985
17718
|
throw error2;
|
|
17986
17719
|
}
|
|
17987
17720
|
}
|
|
@@ -18001,7 +17734,7 @@ function useDahuaService() {
|
|
|
18001
17734
|
});
|
|
18002
17735
|
const { error } = validation.validate(value);
|
|
18003
17736
|
if (error) {
|
|
18004
|
-
throw new
|
|
17737
|
+
throw new import_node_server_utils75.BadRequestError(`Validation error: ${error.message}`);
|
|
18005
17738
|
}
|
|
18006
17739
|
value.owner = String(value.owner ?? "").substring(0, 15) || "unknown";
|
|
18007
17740
|
value.vehicleType = String(value.vehicleType ?? "").substring(0, 31) || "unknown";
|
|
@@ -18018,15 +17751,15 @@ function useDahuaService() {
|
|
|
18018
17751
|
});
|
|
18019
17752
|
return response;
|
|
18020
17753
|
} catch (error2) {
|
|
18021
|
-
|
|
18022
|
-
throw new
|
|
17754
|
+
loggerDahua.error(`[${value.host}] Error bulk add plate number:`, error2);
|
|
17755
|
+
throw new import_node_server_utils75.BadRequestError(
|
|
18023
17756
|
`Failed bulk adding plate number: ${error2.message}`
|
|
18024
17757
|
);
|
|
18025
17758
|
}
|
|
18026
17759
|
}
|
|
18027
17760
|
return {
|
|
18028
17761
|
getSnapshot,
|
|
18029
|
-
|
|
17762
|
+
listenToCamera,
|
|
18030
17763
|
addPlateNumber,
|
|
18031
17764
|
removePlateNumber,
|
|
18032
17765
|
updatePlateNumber,
|
|
@@ -18035,7 +17768,400 @@ function useDahuaService() {
|
|
|
18035
17768
|
};
|
|
18036
17769
|
}
|
|
18037
17770
|
|
|
17771
|
+
// src/repositories/site-camera.repo.ts
|
|
17772
|
+
function useSiteCameraRepo() {
|
|
17773
|
+
const db = import_node_server_utils76.useAtlas.getDb();
|
|
17774
|
+
if (!db) {
|
|
17775
|
+
throw new Error("Unable to connect to server.");
|
|
17776
|
+
}
|
|
17777
|
+
const namespace_collection = "site.cameras";
|
|
17778
|
+
const collection = db.collection(namespace_collection);
|
|
17779
|
+
const { delNamespace, getCache, setCache } = (0, import_node_server_utils76.useCache)(namespace_collection);
|
|
17780
|
+
async function createIndexes() {
|
|
17781
|
+
try {
|
|
17782
|
+
await collection.createIndexes([
|
|
17783
|
+
{
|
|
17784
|
+
key: { site: 1 }
|
|
17785
|
+
},
|
|
17786
|
+
{
|
|
17787
|
+
key: { type: 1 }
|
|
17788
|
+
},
|
|
17789
|
+
{
|
|
17790
|
+
key: { host: 1, type: 1, status: 1, site: 1 },
|
|
17791
|
+
unique: true,
|
|
17792
|
+
partialFilterExpression: { status: "active" }
|
|
17793
|
+
}
|
|
17794
|
+
]);
|
|
17795
|
+
return `Successfully created ${namespace_collection} indexes.`;
|
|
17796
|
+
} catch (error) {
|
|
17797
|
+
import_node_server_utils76.logger.log({
|
|
17798
|
+
level: "error",
|
|
17799
|
+
message: error.message
|
|
17800
|
+
});
|
|
17801
|
+
}
|
|
17802
|
+
}
|
|
17803
|
+
async function add(value, session) {
|
|
17804
|
+
try {
|
|
17805
|
+
value = MSiteCamera(value);
|
|
17806
|
+
const res = await collection.insertOne(value, { session });
|
|
17807
|
+
delCachedData();
|
|
17808
|
+
return res.insertedId;
|
|
17809
|
+
} catch (error) {
|
|
17810
|
+
import_node_server_utils76.logger.log({
|
|
17811
|
+
level: "error",
|
|
17812
|
+
message: error.message
|
|
17813
|
+
});
|
|
17814
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
17815
|
+
if (isDuplicated) {
|
|
17816
|
+
throw new import_node_server_utils76.BadRequestError("ANPR already exist.");
|
|
17817
|
+
}
|
|
17818
|
+
if (error instanceof import_node_server_utils76.AppError) {
|
|
17819
|
+
throw error;
|
|
17820
|
+
} else {
|
|
17821
|
+
throw new Error("Failed to create ANPR.");
|
|
17822
|
+
}
|
|
17823
|
+
}
|
|
17824
|
+
}
|
|
17825
|
+
async function getAll(value) {
|
|
17826
|
+
value.page = value.page ? value.page - 1 : 0;
|
|
17827
|
+
value.limit = value.limit || 10;
|
|
17828
|
+
const cacheKeyOptions = {
|
|
17829
|
+
type: value.type,
|
|
17830
|
+
page: value.page,
|
|
17831
|
+
limit: value.limit,
|
|
17832
|
+
...value.direction && { direction: value.direction }
|
|
17833
|
+
};
|
|
17834
|
+
const query = {
|
|
17835
|
+
type: value.type,
|
|
17836
|
+
...value.direction && {
|
|
17837
|
+
direction: {
|
|
17838
|
+
$in: Array.isArray(value.direction) ? value.direction : [value.direction]
|
|
17839
|
+
}
|
|
17840
|
+
}
|
|
17841
|
+
};
|
|
17842
|
+
if (value.site) {
|
|
17843
|
+
cacheKeyOptions.site = value.site;
|
|
17844
|
+
try {
|
|
17845
|
+
value.site = new import_mongodb47.ObjectId(value.site);
|
|
17846
|
+
query.site = value.site;
|
|
17847
|
+
} catch (error) {
|
|
17848
|
+
throw new import_node_server_utils76.BadRequestError("Invalid site ID format");
|
|
17849
|
+
}
|
|
17850
|
+
}
|
|
17851
|
+
const cacheKey = (0, import_node_server_utils76.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
17852
|
+
const cachedData = await getCache(cacheKey);
|
|
17853
|
+
if (cachedData) {
|
|
17854
|
+
return cachedData;
|
|
17855
|
+
}
|
|
17856
|
+
try {
|
|
17857
|
+
const items = await collection.aggregate([
|
|
17858
|
+
{
|
|
17859
|
+
$match: query
|
|
17860
|
+
},
|
|
17861
|
+
{
|
|
17862
|
+
$skip: value.page * value.limit
|
|
17863
|
+
},
|
|
17864
|
+
{
|
|
17865
|
+
$limit: value.limit
|
|
17866
|
+
},
|
|
17867
|
+
{
|
|
17868
|
+
$project: {
|
|
17869
|
+
password: 0
|
|
17870
|
+
}
|
|
17871
|
+
}
|
|
17872
|
+
]).toArray();
|
|
17873
|
+
const length = await collection.countDocuments(query);
|
|
17874
|
+
const data = (0, import_node_server_utils76.paginate)(items, value.page, value.limit, length);
|
|
17875
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
17876
|
+
import_node_server_utils76.logger.info(`Cache set for key: ${cacheKey}`);
|
|
17877
|
+
}).catch((err) => {
|
|
17878
|
+
import_node_server_utils76.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
17879
|
+
});
|
|
17880
|
+
return data;
|
|
17881
|
+
} catch (error) {
|
|
17882
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
17883
|
+
throw error;
|
|
17884
|
+
}
|
|
17885
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
17886
|
+
}
|
|
17887
|
+
}
|
|
17888
|
+
async function findSiteCameras({ site, type }) {
|
|
17889
|
+
const pipeline = [];
|
|
17890
|
+
const cacheObject = {};
|
|
17891
|
+
if (type) {
|
|
17892
|
+
cacheObject.type = type;
|
|
17893
|
+
pipeline.push({ $match: { "anprs.type": type } });
|
|
17894
|
+
}
|
|
17895
|
+
if (site) {
|
|
17896
|
+
const _site = new import_mongodb47.ObjectId(site);
|
|
17897
|
+
cacheObject.site = site;
|
|
17898
|
+
pipeline.push({ $match: { site: _site } });
|
|
17899
|
+
}
|
|
17900
|
+
pipeline.push({
|
|
17901
|
+
$project: {
|
|
17902
|
+
_id: 1,
|
|
17903
|
+
site: 1,
|
|
17904
|
+
cameras: 1
|
|
17905
|
+
}
|
|
17906
|
+
});
|
|
17907
|
+
try {
|
|
17908
|
+
const items = await collection.aggregate(pipeline).toArray();
|
|
17909
|
+
return items;
|
|
17910
|
+
} catch (error) {
|
|
17911
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
17912
|
+
throw error;
|
|
17913
|
+
}
|
|
17914
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
17915
|
+
}
|
|
17916
|
+
}
|
|
17917
|
+
function delCachedData() {
|
|
17918
|
+
delNamespace().then(() => {
|
|
17919
|
+
import_node_server_utils76.logger.log({
|
|
17920
|
+
level: "info",
|
|
17921
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
17922
|
+
});
|
|
17923
|
+
}).catch((err) => {
|
|
17924
|
+
import_node_server_utils76.logger.log({
|
|
17925
|
+
level: "error",
|
|
17926
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
17927
|
+
});
|
|
17928
|
+
});
|
|
17929
|
+
}
|
|
17930
|
+
async function getBySite(site, options = {}) {
|
|
17931
|
+
const _site = (0, import_node_server_utils76.toObjectId)(site);
|
|
17932
|
+
const cacheKeyOptions = {
|
|
17933
|
+
site,
|
|
17934
|
+
tag: "get-by-site",
|
|
17935
|
+
...options.category && { category: options.category },
|
|
17936
|
+
...options.type && { type: options.type },
|
|
17937
|
+
...options.guardPost && { guardPost: options.guardPost }
|
|
17938
|
+
};
|
|
17939
|
+
const cacheKey = (0, import_node_server_utils76.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
17940
|
+
const cachedData = await getCache(cacheKey);
|
|
17941
|
+
if (cachedData) {
|
|
17942
|
+
return cachedData;
|
|
17943
|
+
}
|
|
17944
|
+
try {
|
|
17945
|
+
delete cacheKeyOptions.tag;
|
|
17946
|
+
cacheKeyOptions.site = _site;
|
|
17947
|
+
const item = await collection.findOne(cacheKeyOptions);
|
|
17948
|
+
setCache(cacheKey, item, 15 * 60).then(() => {
|
|
17949
|
+
import_node_server_utils76.logger.log({
|
|
17950
|
+
level: "info",
|
|
17951
|
+
message: `Cache set for getBySite: ${cacheKey}`
|
|
17952
|
+
});
|
|
17953
|
+
}).catch((err) => {
|
|
17954
|
+
import_node_server_utils76.logger.log({
|
|
17955
|
+
level: "error",
|
|
17956
|
+
message: `Failed to set cache for getBySite: ${err.message}`
|
|
17957
|
+
});
|
|
17958
|
+
});
|
|
17959
|
+
return item;
|
|
17960
|
+
} catch (error) {
|
|
17961
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
17962
|
+
throw error;
|
|
17963
|
+
}
|
|
17964
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
17965
|
+
}
|
|
17966
|
+
}
|
|
17967
|
+
async function getBySiteGuardPost(site, guardPost) {
|
|
17968
|
+
try {
|
|
17969
|
+
site = new import_mongodb47.ObjectId(site);
|
|
17970
|
+
} catch (error) {
|
|
17971
|
+
throw new import_node_server_utils76.BadRequestError("Invalid site ID format");
|
|
17972
|
+
}
|
|
17973
|
+
const cacheKeyOptions = {
|
|
17974
|
+
site,
|
|
17975
|
+
guardPost,
|
|
17976
|
+
tag: "get-by-site"
|
|
17977
|
+
};
|
|
17978
|
+
const cacheKey = (0, import_node_server_utils76.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
17979
|
+
const cachedData = await getCache(cacheKey);
|
|
17980
|
+
if (cachedData) {
|
|
17981
|
+
return cachedData;
|
|
17982
|
+
}
|
|
17983
|
+
try {
|
|
17984
|
+
delete cacheKeyOptions.tag;
|
|
17985
|
+
const item = await collection.findOne({
|
|
17986
|
+
site,
|
|
17987
|
+
guardPost: { $gt: guardPost }
|
|
17988
|
+
});
|
|
17989
|
+
setCache(cacheKey, item, 15 * 60).then(() => {
|
|
17990
|
+
import_node_server_utils76.logger.log({
|
|
17991
|
+
level: "info",
|
|
17992
|
+
message: `Cache set for getBySite: ${cacheKey}`
|
|
17993
|
+
});
|
|
17994
|
+
}).catch((err) => {
|
|
17995
|
+
import_node_server_utils76.logger.log({
|
|
17996
|
+
level: "error",
|
|
17997
|
+
message: `Failed to set cache for getBySite: ${err.message}`
|
|
17998
|
+
});
|
|
17999
|
+
});
|
|
18000
|
+
return item;
|
|
18001
|
+
} catch (error) {
|
|
18002
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
18003
|
+
throw error;
|
|
18004
|
+
}
|
|
18005
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
18006
|
+
}
|
|
18007
|
+
}
|
|
18008
|
+
async function getBySites(site, options = {}) {
|
|
18009
|
+
try {
|
|
18010
|
+
site = new import_mongodb47.ObjectId(site);
|
|
18011
|
+
} catch (error) {
|
|
18012
|
+
throw new import_node_server_utils76.BadRequestError("Invalid site ID format");
|
|
18013
|
+
}
|
|
18014
|
+
const cacheKeyOptions = { site };
|
|
18015
|
+
if (options.category) {
|
|
18016
|
+
cacheKeyOptions.category = options.category;
|
|
18017
|
+
}
|
|
18018
|
+
if (options.type) {
|
|
18019
|
+
cacheKeyOptions.type = options.type;
|
|
18020
|
+
}
|
|
18021
|
+
if (options.direction) {
|
|
18022
|
+
cacheKeyOptions.direction = options.direction;
|
|
18023
|
+
}
|
|
18024
|
+
const cacheKey = (0, import_node_server_utils76.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
18025
|
+
const cachedData = await getCache(cacheKey);
|
|
18026
|
+
if (cachedData) {
|
|
18027
|
+
return cachedData;
|
|
18028
|
+
}
|
|
18029
|
+
try {
|
|
18030
|
+
const items = await collection.find(cacheKeyOptions);
|
|
18031
|
+
setCache(cacheKey, items, 15 * 60).then(() => {
|
|
18032
|
+
import_node_server_utils76.logger.log({
|
|
18033
|
+
level: "info",
|
|
18034
|
+
message: `Cache set for getBySite: ${cacheKey}`
|
|
18035
|
+
});
|
|
18036
|
+
}).catch((err) => {
|
|
18037
|
+
import_node_server_utils76.logger.log({
|
|
18038
|
+
level: "error",
|
|
18039
|
+
message: `Failed to set cache for getBySite: ${err.message}`
|
|
18040
|
+
});
|
|
18041
|
+
});
|
|
18042
|
+
return items;
|
|
18043
|
+
} catch (error) {
|
|
18044
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
18045
|
+
throw error;
|
|
18046
|
+
}
|
|
18047
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
18048
|
+
}
|
|
18049
|
+
}
|
|
18050
|
+
async function updateById(_id, value, session) {
|
|
18051
|
+
const { error } = schemaUpdateSiteCamera.validate(value);
|
|
18052
|
+
if (error) {
|
|
18053
|
+
import_node_server_utils76.logger.info(`Site Camera Management: ${error.message}`);
|
|
18054
|
+
throw new import_node_server_utils76.BadRequestError(error.message);
|
|
18055
|
+
}
|
|
18056
|
+
try {
|
|
18057
|
+
_id = new import_mongodb47.ObjectId(_id);
|
|
18058
|
+
} catch (error2) {
|
|
18059
|
+
throw new import_node_server_utils76.BadRequestError("Invalid camera ID format");
|
|
18060
|
+
}
|
|
18061
|
+
try {
|
|
18062
|
+
value.updatedAt = /* @__PURE__ */ new Date();
|
|
18063
|
+
const result = await collection.findOneAndUpdate({ _id }, { $set: value }, { session, returnDocument: "after" });
|
|
18064
|
+
if (!result?._id) {
|
|
18065
|
+
throw new import_node_server_utils76.BadRequestError("Site camera not found.");
|
|
18066
|
+
}
|
|
18067
|
+
const { listenToCamera } = useDahuaService();
|
|
18068
|
+
await listenToCamera(result);
|
|
18069
|
+
delCachedData();
|
|
18070
|
+
return "Successfully updated site camera.";
|
|
18071
|
+
} catch (error2) {
|
|
18072
|
+
import_node_server_utils76.logger.log({
|
|
18073
|
+
level: "error",
|
|
18074
|
+
message: error2.message
|
|
18075
|
+
});
|
|
18076
|
+
const isDuplicated = error2.message.includes("duplicate");
|
|
18077
|
+
if (isDuplicated) {
|
|
18078
|
+
throw new import_node_server_utils76.BadRequestError("ANPR already exist.");
|
|
18079
|
+
}
|
|
18080
|
+
if (error2 instanceof import_node_server_utils76.AppError) {
|
|
18081
|
+
throw error2;
|
|
18082
|
+
}
|
|
18083
|
+
throw new Error("Failed to update ANPR.");
|
|
18084
|
+
}
|
|
18085
|
+
}
|
|
18086
|
+
async function deleteById(_id, session) {
|
|
18087
|
+
try {
|
|
18088
|
+
_id = new import_mongodb47.ObjectId(_id);
|
|
18089
|
+
} catch (error) {
|
|
18090
|
+
throw new import_node_server_utils76.BadRequestError("Invalid camera ID format");
|
|
18091
|
+
}
|
|
18092
|
+
try {
|
|
18093
|
+
await collection.deleteOne({ _id }, { session });
|
|
18094
|
+
delCachedData();
|
|
18095
|
+
return "Successfully deleted site camera.";
|
|
18096
|
+
} catch (error) {
|
|
18097
|
+
import_node_server_utils76.logger.log({
|
|
18098
|
+
level: "error",
|
|
18099
|
+
message: error.message
|
|
18100
|
+
});
|
|
18101
|
+
if (error instanceof import_node_server_utils76.AppError) {
|
|
18102
|
+
throw error;
|
|
18103
|
+
}
|
|
18104
|
+
throw new Error("Failed to delete site camera.");
|
|
18105
|
+
}
|
|
18106
|
+
}
|
|
18107
|
+
async function getAllCameraWithPassword(value) {
|
|
18108
|
+
value.page = value.page ? value.page - 1 : 0;
|
|
18109
|
+
value.limit = value.limit || 10;
|
|
18110
|
+
const query = {
|
|
18111
|
+
type: value.type,
|
|
18112
|
+
...value.direction && {
|
|
18113
|
+
direction: {
|
|
18114
|
+
$in: Array.isArray(value.direction) ? value.direction : [value.direction]
|
|
18115
|
+
}
|
|
18116
|
+
}
|
|
18117
|
+
};
|
|
18118
|
+
if (value.site) {
|
|
18119
|
+
try {
|
|
18120
|
+
value.site = new import_mongodb47.ObjectId(value.site);
|
|
18121
|
+
query.site = value.site;
|
|
18122
|
+
} catch (error) {
|
|
18123
|
+
throw new import_node_server_utils76.BadRequestError("Invalid site ID format");
|
|
18124
|
+
}
|
|
18125
|
+
}
|
|
18126
|
+
try {
|
|
18127
|
+
const items = await collection.aggregate([
|
|
18128
|
+
{
|
|
18129
|
+
$match: query
|
|
18130
|
+
},
|
|
18131
|
+
{
|
|
18132
|
+
$skip: value.page * value.limit
|
|
18133
|
+
},
|
|
18134
|
+
{
|
|
18135
|
+
$limit: value.limit
|
|
18136
|
+
}
|
|
18137
|
+
]).toArray();
|
|
18138
|
+
const length = await collection.countDocuments(query);
|
|
18139
|
+
const data = (0, import_node_server_utils76.paginate)(items, value.page, value.limit, length);
|
|
18140
|
+
return data;
|
|
18141
|
+
} catch (error) {
|
|
18142
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
18143
|
+
throw error;
|
|
18144
|
+
}
|
|
18145
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
18146
|
+
}
|
|
18147
|
+
}
|
|
18148
|
+
return {
|
|
18149
|
+
createIndexes,
|
|
18150
|
+
add,
|
|
18151
|
+
getAll,
|
|
18152
|
+
findSiteCameras,
|
|
18153
|
+
getBySite,
|
|
18154
|
+
getBySites,
|
|
18155
|
+
delCachedData,
|
|
18156
|
+
getBySiteGuardPost,
|
|
18157
|
+
updateById,
|
|
18158
|
+
deleteById,
|
|
18159
|
+
getAllCameraWithPassword
|
|
18160
|
+
};
|
|
18161
|
+
}
|
|
18162
|
+
|
|
18038
18163
|
// src/services/site.service.ts
|
|
18164
|
+
var import_joi41 = __toESM(require("joi"));
|
|
18039
18165
|
function useSiteService() {
|
|
18040
18166
|
const {
|
|
18041
18167
|
createSite: _createSite,
|
|
@@ -19575,7 +19701,7 @@ function useVehicleController() {
|
|
|
19575
19701
|
next(new import_node_server_utils87.BadRequestError("Spreadsheet file is required."));
|
|
19576
19702
|
return;
|
|
19577
19703
|
}
|
|
19578
|
-
const { originalname, path:
|
|
19704
|
+
const { originalname, path: path5 } = req.file;
|
|
19579
19705
|
const lowerName = originalname.toLowerCase();
|
|
19580
19706
|
const rowSchema = import_joi46.default.object({
|
|
19581
19707
|
fullName: import_joi46.default.string().trim().required(),
|
|
@@ -19614,7 +19740,7 @@ function useVehicleController() {
|
|
|
19614
19740
|
let rows = [];
|
|
19615
19741
|
if (lowerName.endsWith(".xlsx") || lowerName.endsWith(".xls")) {
|
|
19616
19742
|
const workbook = new import_exceljs.default.Workbook();
|
|
19617
|
-
await workbook.xlsx.readFile(
|
|
19743
|
+
await workbook.xlsx.readFile(path5);
|
|
19618
19744
|
const worksheet = workbook.worksheets[0];
|
|
19619
19745
|
if (!worksheet) {
|
|
19620
19746
|
next(
|
|
@@ -19640,7 +19766,7 @@ function useVehicleController() {
|
|
|
19640
19766
|
} else if (lowerName.endsWith(".csv")) {
|
|
19641
19767
|
rows = await new Promise((resolve, reject) => {
|
|
19642
19768
|
const parsed = [];
|
|
19643
|
-
import_fs2.default.createReadStream(
|
|
19769
|
+
import_fs2.default.createReadStream(path5).pipe((0, import_csv_parser.default)()).on("data", (row) => parsed.push(row)).on("end", () => resolve(parsed)).on("error", reject);
|
|
19644
19770
|
});
|
|
19645
19771
|
} else {
|
|
19646
19772
|
next(
|
|
@@ -19679,7 +19805,7 @@ function useVehicleController() {
|
|
|
19679
19805
|
validationErrors: invalidRows,
|
|
19680
19806
|
data
|
|
19681
19807
|
});
|
|
19682
|
-
import_fs2.default.unlink(
|
|
19808
|
+
import_fs2.default.unlink(path5, () => {
|
|
19683
19809
|
});
|
|
19684
19810
|
} catch (error) {
|
|
19685
19811
|
import_node_server_utils87.logger.log({ level: "error", message: error.message });
|
|
@@ -19877,26 +20003,27 @@ function useVehicleController() {
|
|
|
19877
20003
|
}
|
|
19878
20004
|
}
|
|
19879
20005
|
async function approveVehicleById(req, res, next) {
|
|
19880
|
-
const validation = import_joi46.default.object({
|
|
19881
|
-
_id: import_joi46.default.string().hex().length(24).required(),
|
|
19882
|
-
org: import_joi46.default.string().hex().length(24).required(),
|
|
19883
|
-
site: import_joi46.default.string().hex().length(24).required()
|
|
19884
|
-
});
|
|
19885
|
-
const _id = req.params.id;
|
|
19886
|
-
const payload = { ...req.body };
|
|
19887
|
-
const { error, value } = validation.validate({ _id, ...payload });
|
|
19888
|
-
if (error) {
|
|
19889
|
-
import_node_server_utils87.logger.log({ level: "error", message: error.message });
|
|
19890
|
-
next(new import_node_server_utils87.BadRequestError(error.message));
|
|
19891
|
-
return;
|
|
19892
|
-
}
|
|
19893
20006
|
try {
|
|
19894
|
-
|
|
20007
|
+
const schema2 = import_joi46.default.object({
|
|
20008
|
+
_id: import_joi46.default.string().hex().length(24).required(),
|
|
20009
|
+
org: import_joi46.default.string().hex().length(24).required(),
|
|
20010
|
+
site: import_joi46.default.string().hex().length(24).required()
|
|
20011
|
+
});
|
|
20012
|
+
const payload = { _id: req.params.id, ...req.body };
|
|
20013
|
+
const { error, value } = schema2.validate(payload, { abortEarly: false });
|
|
20014
|
+
if (error) {
|
|
20015
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
20016
|
+
import_node_server_utils87.logger.log({ level: "error", message: messages });
|
|
20017
|
+
next(new import_node_server_utils87.BadRequestError(messages));
|
|
20018
|
+
return;
|
|
20019
|
+
}
|
|
20020
|
+
const { _id, org, site } = value;
|
|
20021
|
+
await _approveVehicleById(_id, org, site);
|
|
19895
20022
|
res.json({ message: "Successfully approved and updated vehicle." });
|
|
19896
20023
|
return;
|
|
19897
|
-
} catch (
|
|
19898
|
-
import_node_server_utils87.logger.log({ level: "error", message:
|
|
19899
|
-
next(
|
|
20024
|
+
} catch (error) {
|
|
20025
|
+
import_node_server_utils87.logger.log({ level: "error", message: error.message });
|
|
20026
|
+
next(error);
|
|
19900
20027
|
return;
|
|
19901
20028
|
}
|
|
19902
20029
|
}
|
|
@@ -20074,14 +20201,7 @@ function useSiteCameraService() {
|
|
|
20074
20201
|
for (let index = 0; index < siteCameras.length; index++) {
|
|
20075
20202
|
const siteCamera = siteCameras[index];
|
|
20076
20203
|
if (siteCamera && siteCamera.status === "active" && siteCamera.host && siteCamera.username && siteCamera.password && siteCamera.site && siteCamera.guardPost) {
|
|
20077
|
-
dahuaService.
|
|
20078
|
-
siteCamera.host,
|
|
20079
|
-
siteCamera.username,
|
|
20080
|
-
siteCamera.password,
|
|
20081
|
-
siteCamera.site.toString(),
|
|
20082
|
-
`guard-post-${siteCamera.guardPost}`,
|
|
20083
|
-
siteCamera.direction
|
|
20084
|
-
);
|
|
20204
|
+
dahuaService.listenToCamera(siteCamera);
|
|
20085
20205
|
}
|
|
20086
20206
|
}
|
|
20087
20207
|
}
|
|
@@ -24078,7 +24198,16 @@ var import_node_server_utils108 = require("@7365admin1/node-server-utils");
|
|
|
24078
24198
|
|
|
24079
24199
|
// src/services/person.service.ts
|
|
24080
24200
|
var import_node_server_utils107 = require("@7365admin1/node-server-utils");
|
|
24201
|
+
var import_path = __toESM(require("path"));
|
|
24081
24202
|
function usePersonService() {
|
|
24203
|
+
const MailerConfig = {
|
|
24204
|
+
host: MAILER_TRANSPORT_HOST,
|
|
24205
|
+
port: MAILER_TRANSPORT_PORT,
|
|
24206
|
+
secure: MAILER_TRANSPORT_SECURE,
|
|
24207
|
+
email: MAILER_EMAIL,
|
|
24208
|
+
password: MAILER_PASSWORD
|
|
24209
|
+
};
|
|
24210
|
+
const mailer = new import_node_server_utils107.useMailer(MailerConfig);
|
|
24082
24211
|
const {
|
|
24083
24212
|
add: _add,
|
|
24084
24213
|
getById: _getById,
|
|
@@ -24284,24 +24413,73 @@ function usePersonService() {
|
|
|
24284
24413
|
value.status = "active";
|
|
24285
24414
|
}
|
|
24286
24415
|
await _reviewResidentPerson(id, value, session);
|
|
24416
|
+
const logoPath = import_path.default.join(
|
|
24417
|
+
__dirname,
|
|
24418
|
+
"public",
|
|
24419
|
+
"images",
|
|
24420
|
+
"seven-365.svg"
|
|
24421
|
+
);
|
|
24422
|
+
const statusIconPath = import_path.default.join(__dirname, "public", "icons");
|
|
24423
|
+
let title = "";
|
|
24424
|
+
let message2 = "";
|
|
24425
|
+
let hideLogin = true;
|
|
24426
|
+
let logo = logoPath;
|
|
24427
|
+
let statusLogo = statusIconPath;
|
|
24287
24428
|
if (person.user) {
|
|
24288
|
-
let userStatus;
|
|
24429
|
+
let userStatus = "";
|
|
24289
24430
|
switch (reviewStatus) {
|
|
24290
24431
|
case "approved":
|
|
24291
24432
|
userStatus = "active";
|
|
24292
24433
|
if (person.plateNumber && person.plateNumber.trim() !== "") {
|
|
24293
24434
|
await addVehicle(vehicle, session);
|
|
24294
24435
|
}
|
|
24436
|
+
title = "Your account has been approved";
|
|
24437
|
+
hideLogin = false;
|
|
24438
|
+
statusLogo = `${statusIconPath}/approved-icon.png`;
|
|
24439
|
+
message2 = `Welcome, ${person.name}! Thank you for signing up; we're excited to have you join us!`;
|
|
24295
24440
|
break;
|
|
24296
24441
|
case "resubmit":
|
|
24297
24442
|
userStatus = "resubmit";
|
|
24443
|
+
title = "We request resubmission for your application";
|
|
24444
|
+
hideLogin = false;
|
|
24445
|
+
statusLogo = `${statusIconPath}/resubmission-icon.png`;
|
|
24446
|
+
message2 = `Hi ${person.name}, please resubmit your application with the required updates.`;
|
|
24298
24447
|
break;
|
|
24299
24448
|
case "rejected":
|
|
24300
24449
|
userStatus = "rejected";
|
|
24450
|
+
title = "Your account request for deletion has been rejected.";
|
|
24451
|
+
statusLogo = `${statusIconPath}/deleted-icon.png`;
|
|
24452
|
+
message2 = `Hi ${person.name}, unfortunately your application has been rejected. Please contact support for more information.`;
|
|
24301
24453
|
break;
|
|
24302
24454
|
default:
|
|
24303
24455
|
throw new Error("Invalid review status");
|
|
24304
24456
|
}
|
|
24457
|
+
const dir = __dirname;
|
|
24458
|
+
const filePath = (0, import_node_server_utils107.getDirectory)(
|
|
24459
|
+
dir,
|
|
24460
|
+
"./public/handlebars/resident-remarks-email"
|
|
24461
|
+
);
|
|
24462
|
+
const emailContent = (0, import_node_server_utils107.compileHandlebar)({
|
|
24463
|
+
context: {
|
|
24464
|
+
title,
|
|
24465
|
+
message2,
|
|
24466
|
+
hideLogin,
|
|
24467
|
+
logo,
|
|
24468
|
+
statusLogo
|
|
24469
|
+
},
|
|
24470
|
+
filePath
|
|
24471
|
+
});
|
|
24472
|
+
await mailer.sendMail({
|
|
24473
|
+
to: person.email,
|
|
24474
|
+
subject: title,
|
|
24475
|
+
html: emailContent,
|
|
24476
|
+
sender: "iService365"
|
|
24477
|
+
}).catch((error) => {
|
|
24478
|
+
import_node_server_utils107.logger.log({
|
|
24479
|
+
level: "error",
|
|
24480
|
+
message: `Error sending user ${reviewStatus} email: ${error}`
|
|
24481
|
+
});
|
|
24482
|
+
});
|
|
24305
24483
|
await _updateUserFieldById(
|
|
24306
24484
|
{ _id: person.user.toString(), field: "status", value: userStatus },
|
|
24307
24485
|
session
|
|
@@ -29363,6 +29541,11 @@ var BulletinSort = /* @__PURE__ */ ((BulletinSort2) => {
|
|
|
29363
29541
|
BulletinSort2["ID"] = "_id";
|
|
29364
29542
|
return BulletinSort2;
|
|
29365
29543
|
})(BulletinSort || {});
|
|
29544
|
+
var BulletinOrder = /* @__PURE__ */ ((BulletinOrder2) => {
|
|
29545
|
+
BulletinOrder2["ASC"] = "asc";
|
|
29546
|
+
BulletinOrder2["DESC"] = "desc";
|
|
29547
|
+
return BulletinOrder2;
|
|
29548
|
+
})(BulletinOrder || {});
|
|
29366
29549
|
var schemaBulletinBoard = import_joi75.default.object({
|
|
29367
29550
|
_id: import_joi75.default.string().hex().optional().allow("", null),
|
|
29368
29551
|
site: import_joi75.default.string().hex().optional().allow("", null),
|
|
@@ -29659,12 +29842,13 @@ function useBulletinBoardRepo() {
|
|
|
29659
29842
|
}
|
|
29660
29843
|
async function processExpiredBulletinBoards(session) {
|
|
29661
29844
|
const today = (/* @__PURE__ */ new Date()).toISOString();
|
|
29845
|
+
const query = {
|
|
29846
|
+
noExpiration: false,
|
|
29847
|
+
endDate: { $lt: today }
|
|
29848
|
+
};
|
|
29662
29849
|
try {
|
|
29663
29850
|
const res = await collection.updateMany(
|
|
29664
|
-
|
|
29665
|
-
noExpiration: false,
|
|
29666
|
-
endDate: { $lt: today }
|
|
29667
|
-
},
|
|
29851
|
+
query,
|
|
29668
29852
|
{
|
|
29669
29853
|
$set: {
|
|
29670
29854
|
status: "expired",
|
|
@@ -29822,9 +30006,9 @@ function useBulletinBoardController() {
|
|
|
29822
30006
|
page: import_joi76.default.number().integer().min(1).allow("", null).default(1),
|
|
29823
30007
|
limit: import_joi76.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
29824
30008
|
sort: import_joi76.default.string().valid(...Object.values(BulletinSort)).default("_id" /* ID */),
|
|
29825
|
-
order: import_joi76.default.string().valid(...Object.values(
|
|
30009
|
+
order: import_joi76.default.string().valid(...Object.values(BulletinOrder)).default("desc" /* DESC */),
|
|
29826
30010
|
site: import_joi76.default.string().hex().length(24).required(),
|
|
29827
|
-
status: import_joi76.default.string().valid(...Object.values(
|
|
30011
|
+
status: import_joi76.default.string().valid(...Object.values(BulletinStatus)).optional().default("active" /* ACTIVE */),
|
|
29828
30012
|
recipients: import_joi76.default.alternatives().try(
|
|
29829
30013
|
import_joi76.default.array().items(
|
|
29830
30014
|
import_joi76.default.string().valid(...Object.values(BulletinRecipient))
|
|
@@ -31203,14 +31387,36 @@ function useSiteBillingConfigurationController() {
|
|
|
31203
31387
|
// src/models/event-management.model.ts
|
|
31204
31388
|
var import_mongodb84 = require("mongodb");
|
|
31205
31389
|
var import_joi81 = __toESM(require("joi"));
|
|
31390
|
+
var EventStatus = /* @__PURE__ */ ((EventStatus2) => {
|
|
31391
|
+
EventStatus2["PLANNED"] = "planned";
|
|
31392
|
+
EventStatus2["IN_PROGRESS"] = "in_progress";
|
|
31393
|
+
EventStatus2["COMPLETED"] = "completed";
|
|
31394
|
+
return EventStatus2;
|
|
31395
|
+
})(EventStatus || {});
|
|
31396
|
+
var EventSort = /* @__PURE__ */ ((EventSort2) => {
|
|
31397
|
+
EventSort2["CREATED_AT"] = "createdAt";
|
|
31398
|
+
EventSort2["NAME"] = "name";
|
|
31399
|
+
EventSort2["ID"] = "_id";
|
|
31400
|
+
return EventSort2;
|
|
31401
|
+
})(EventSort || {});
|
|
31402
|
+
var EventOrder = /* @__PURE__ */ ((EventOrder2) => {
|
|
31403
|
+
EventOrder2["ASC"] = "asc";
|
|
31404
|
+
EventOrder2["DESC"] = "desc";
|
|
31405
|
+
return EventOrder2;
|
|
31406
|
+
})(EventOrder || {});
|
|
31407
|
+
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
31408
|
+
EventType2["TASK"] = "TASK";
|
|
31409
|
+
EventType2["EVENT"] = "EVENT";
|
|
31410
|
+
return EventType2;
|
|
31411
|
+
})(EventType || {});
|
|
31206
31412
|
var schemaEventManagement = import_joi81.default.object({
|
|
31207
31413
|
_id: import_joi81.default.string().optional().allow(null, ""),
|
|
31208
31414
|
site: import_joi81.default.string().required(),
|
|
31209
31415
|
title: import_joi81.default.string().required(),
|
|
31210
31416
|
description: import_joi81.default.string().optional().allow(""),
|
|
31211
31417
|
dateTime: import_joi81.default.date().iso().required(),
|
|
31212
|
-
status: import_joi81.default.string().optional().default("planned"),
|
|
31213
|
-
type: import_joi81.default.string().optional().default("TASK")
|
|
31418
|
+
status: import_joi81.default.string().optional().default("planned" /* PLANNED */),
|
|
31419
|
+
type: import_joi81.default.string().optional().default("TASK" /* TASK */)
|
|
31214
31420
|
});
|
|
31215
31421
|
var schemaUpdateEventManagement = import_joi81.default.object({
|
|
31216
31422
|
_id: import_joi81.default.string().hex().required(),
|
|
@@ -31241,8 +31447,8 @@ function MEventManagement(value) {
|
|
|
31241
31447
|
title: value.title,
|
|
31242
31448
|
description: value.description ?? "",
|
|
31243
31449
|
dateTime: new Date(value.dateTime),
|
|
31244
|
-
status: value.status ?? "planned"
|
|
31245
|
-
type: value.type ?? "TASK"
|
|
31450
|
+
status: value.status ?? "planned" /* PLANNED */,
|
|
31451
|
+
type: value.type ?? "TASK" /* TASK */,
|
|
31246
31452
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
31247
31453
|
updatedAt: value.updatedAt,
|
|
31248
31454
|
deletedAt: value.deletedAt
|
|
@@ -31341,10 +31547,11 @@ function useEventManagementRepo() {
|
|
|
31341
31547
|
sort: JSON.stringify(sort),
|
|
31342
31548
|
page,
|
|
31343
31549
|
limit,
|
|
31344
|
-
...type && { type }
|
|
31550
|
+
...type && { type },
|
|
31551
|
+
...date && { dateTime: date }
|
|
31345
31552
|
};
|
|
31346
31553
|
if (search) {
|
|
31347
|
-
query.$
|
|
31554
|
+
query.$or = [{ title: { $regex: search, $options: "i" } }];
|
|
31348
31555
|
cacheOptions.search = search;
|
|
31349
31556
|
}
|
|
31350
31557
|
const cacheKey = (0, import_node_server_utils146.makeCacheKey)(events_namespace_collection, cacheOptions);
|
|
@@ -31544,8 +31751,8 @@ function useEventManagementService() {
|
|
|
31544
31751
|
} = useEventManagementRepo();
|
|
31545
31752
|
async function add(value) {
|
|
31546
31753
|
const session = import_node_server_utils147.useAtlas.getClient()?.startSession();
|
|
31547
|
-
session?.startTransaction();
|
|
31548
31754
|
try {
|
|
31755
|
+
session?.startTransaction();
|
|
31549
31756
|
await _add(value, session);
|
|
31550
31757
|
await session?.commitTransaction();
|
|
31551
31758
|
return "Successfully added event.";
|
|
@@ -31608,67 +31815,51 @@ function useEventManagementController() {
|
|
|
31608
31815
|
deleteEventManagementById: _deleteEventManagementById
|
|
31609
31816
|
} = useEventManagementRepo();
|
|
31610
31817
|
async function add(req, res, next) {
|
|
31611
|
-
const payload = { ...req.body };
|
|
31612
|
-
const { error } = schemaEventManagement.validate(payload, {
|
|
31613
|
-
abortEarly: false
|
|
31614
|
-
});
|
|
31615
|
-
if (error) {
|
|
31616
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
31617
|
-
import_node_server_utils148.logger.log({ level: "error", message: messages });
|
|
31618
|
-
next(new import_node_server_utils148.BadRequestError(messages));
|
|
31619
|
-
return;
|
|
31620
|
-
}
|
|
31621
31818
|
try {
|
|
31622
|
-
const
|
|
31819
|
+
const { error, value } = schemaEventManagement.validate(req.body, {
|
|
31820
|
+
abortEarly: false
|
|
31821
|
+
});
|
|
31822
|
+
if (error) {
|
|
31823
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
31824
|
+
import_node_server_utils148.logger.log({ level: "error", message: messages });
|
|
31825
|
+
next(new import_node_server_utils148.BadRequestError(messages));
|
|
31826
|
+
return;
|
|
31827
|
+
}
|
|
31828
|
+
const data = await _add(value);
|
|
31623
31829
|
res.status(201).json(data);
|
|
31624
31830
|
return;
|
|
31625
|
-
} catch (
|
|
31626
|
-
import_node_server_utils148.logger.log({ level: "error", message:
|
|
31627
|
-
next(
|
|
31831
|
+
} catch (error) {
|
|
31832
|
+
import_node_server_utils148.logger.log({ level: "error", message: error.message });
|
|
31833
|
+
next(error);
|
|
31628
31834
|
return;
|
|
31629
31835
|
}
|
|
31630
31836
|
}
|
|
31631
31837
|
async function getAll(req, res, next) {
|
|
31632
|
-
const allowedFields = ["createdAt", "name"];
|
|
31633
|
-
const allowedOrder = ["asc", "desc"];
|
|
31634
|
-
const validation = import_joi82.default.object({
|
|
31635
|
-
search: import_joi82.default.string().optional().allow("", null),
|
|
31636
|
-
page: import_joi82.default.number().integer().min(1).allow("", null).default(1),
|
|
31637
|
-
limit: import_joi82.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
31638
|
-
sort: import_joi82.default.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
|
|
31639
|
-
order: import_joi82.default.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
|
|
31640
|
-
site: import_joi82.default.string().hex().required(),
|
|
31641
|
-
status: import_joi82.default.string().optional(),
|
|
31642
|
-
type: import_joi82.default.string().optional().valid("TASK", "EVENT").allow(null, ""),
|
|
31643
|
-
date: import_joi82.default.string().optional().allow(null, "")
|
|
31644
|
-
});
|
|
31645
|
-
const query = { ...req.query };
|
|
31646
|
-
const { error } = validation.validate(query, {
|
|
31647
|
-
abortEarly: false
|
|
31648
|
-
});
|
|
31649
|
-
if (error) {
|
|
31650
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
31651
|
-
import_node_server_utils148.logger.log({ level: "error", message: messages });
|
|
31652
|
-
next(new import_node_server_utils148.BadRequestError(messages));
|
|
31653
|
-
return;
|
|
31654
|
-
}
|
|
31655
|
-
const search = req.query.search ?? "";
|
|
31656
|
-
const page = parseInt(req.query.page ?? "1");
|
|
31657
|
-
const limit = parseInt(req.query.limit ?? "10");
|
|
31658
|
-
const site = req.query.site ?? "";
|
|
31659
|
-
const status = req.query.status ?? "";
|
|
31660
|
-
const type = req.query.type ?? "";
|
|
31661
|
-
const date = req.query.date ?? "";
|
|
31662
|
-
const sortObj = {};
|
|
31663
|
-
const sortFields = String(req.query.sort).split(",");
|
|
31664
|
-
const sortOrders = String(req.query.order).split(",");
|
|
31665
|
-
sortFields.forEach((field, index) => {
|
|
31666
|
-
if (allowedFields.includes(field)) {
|
|
31667
|
-
const order = sortOrders[index] === "asc" ? 1 : -1;
|
|
31668
|
-
sortObj[field] = order;
|
|
31669
|
-
}
|
|
31670
|
-
});
|
|
31671
31838
|
try {
|
|
31839
|
+
const validation = import_joi82.default.object({
|
|
31840
|
+
search: import_joi82.default.string().optional().allow("", null),
|
|
31841
|
+
page: import_joi82.default.number().integer().min(1).allow("", null).default(1),
|
|
31842
|
+
limit: import_joi82.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
31843
|
+
sort: import_joi82.default.string().valid(...Object.values(EventSort)).default("_id" /* ID */),
|
|
31844
|
+
order: import_joi82.default.string().valid(...Object.values(EventOrder)).default("desc" /* DESC */),
|
|
31845
|
+
site: import_joi82.default.string().hex().length(24).required(),
|
|
31846
|
+
status: import_joi82.default.string().valid(...Object.values(EventStatus)).allow(null, ""),
|
|
31847
|
+
type: import_joi82.default.string().optional().valid(...Object.values(EventType)).allow(null, ""),
|
|
31848
|
+
date: import_joi82.default.string().optional().allow(null, "")
|
|
31849
|
+
});
|
|
31850
|
+
const { error, value } = validation.validate(req.query, {
|
|
31851
|
+
abortEarly: false
|
|
31852
|
+
});
|
|
31853
|
+
if (error) {
|
|
31854
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
31855
|
+
import_node_server_utils148.logger.log({ level: "error", message: messages });
|
|
31856
|
+
next(new import_node_server_utils148.BadRequestError(messages));
|
|
31857
|
+
return;
|
|
31858
|
+
}
|
|
31859
|
+
const { search, page, limit, site, status, type, date, sort, order } = value;
|
|
31860
|
+
const sortObj = {
|
|
31861
|
+
[sort ?? "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
31862
|
+
};
|
|
31672
31863
|
const data = await _getAll({
|
|
31673
31864
|
search,
|
|
31674
31865
|
page,
|
|
@@ -31681,28 +31872,30 @@ function useEventManagementController() {
|
|
|
31681
31872
|
});
|
|
31682
31873
|
res.status(200).json(data);
|
|
31683
31874
|
return;
|
|
31684
|
-
} catch (
|
|
31685
|
-
import_node_server_utils148.logger.log({ level: "error", message:
|
|
31686
|
-
next(
|
|
31875
|
+
} catch (error) {
|
|
31876
|
+
import_node_server_utils148.logger.log({ level: "error", message: error.message });
|
|
31877
|
+
next(error);
|
|
31687
31878
|
return;
|
|
31688
31879
|
}
|
|
31689
31880
|
}
|
|
31690
31881
|
async function getEventManagementById(req, res, next) {
|
|
31691
|
-
const validation = import_joi82.default.string().hex().required();
|
|
31692
|
-
const _id = req.params.id;
|
|
31693
|
-
const { error } = validation.validate(_id);
|
|
31694
|
-
if (error) {
|
|
31695
|
-
import_node_server_utils148.logger.log({ level: "error", message: error.message });
|
|
31696
|
-
next(new import_node_server_utils148.BadRequestError(error.message));
|
|
31697
|
-
return;
|
|
31698
|
-
}
|
|
31699
31882
|
try {
|
|
31883
|
+
const schema2 = import_joi82.default.object({
|
|
31884
|
+
_id: import_joi82.default.string().hex().length(24).required()
|
|
31885
|
+
});
|
|
31886
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
31887
|
+
if (error) {
|
|
31888
|
+
import_node_server_utils148.logger.log({ level: "error", message: error.message });
|
|
31889
|
+
next(new import_node_server_utils148.BadRequestError(error.message));
|
|
31890
|
+
return;
|
|
31891
|
+
}
|
|
31892
|
+
const { _id } = value;
|
|
31700
31893
|
const data = await _getEventManagementById(_id);
|
|
31701
31894
|
res.status(200).json(data);
|
|
31702
31895
|
return;
|
|
31703
|
-
} catch (
|
|
31704
|
-
import_node_server_utils148.logger.log({ level: "error", message:
|
|
31705
|
-
next(
|
|
31896
|
+
} catch (error) {
|
|
31897
|
+
import_node_server_utils148.logger.log({ level: "error", message: error.message });
|
|
31898
|
+
next(error);
|
|
31706
31899
|
return;
|
|
31707
31900
|
}
|
|
31708
31901
|
}
|
|
@@ -33047,7 +33240,7 @@ var import_mongodb90 = require("mongodb");
|
|
|
33047
33240
|
|
|
33048
33241
|
// src/utils/access-management.ts
|
|
33049
33242
|
var import_fs3 = __toESM(require("fs"));
|
|
33050
|
-
var
|
|
33243
|
+
var import_path2 = __toESM(require("path"));
|
|
33051
33244
|
var import_axios = __toESM(require("axios"));
|
|
33052
33245
|
var import_xml2js = require("xml2js");
|
|
33053
33246
|
var import_crypto = __toESM(require("crypto"));
|
|
@@ -33077,7 +33270,7 @@ var minifyXml = (xml) => {
|
|
|
33077
33270
|
};
|
|
33078
33271
|
var readTemplate = (name, params) => {
|
|
33079
33272
|
const template = import_fs3.default.readFileSync(
|
|
33080
|
-
|
|
33273
|
+
import_path2.default.join(__dirname, `../dist/public/xml-templates/${name}.xml`),
|
|
33081
33274
|
"utf-8"
|
|
33082
33275
|
);
|
|
33083
33276
|
if (!params)
|
|
@@ -33150,6 +33343,15 @@ var formatEntryPassDate = (date) => {
|
|
|
33150
33343
|
const day = String(newDate.getDate()).padStart(2, "0");
|
|
33151
33344
|
return `${year}${month}${day}`;
|
|
33152
33345
|
};
|
|
33346
|
+
var entryPassDate = (TRDATE, TRTIME) => {
|
|
33347
|
+
const year = parseInt(TRDATE.substring(0, 4), 10);
|
|
33348
|
+
const month = parseInt(TRDATE.substring(4, 6), 10) - 1;
|
|
33349
|
+
const day = parseInt(TRDATE.substring(6, 8), 10);
|
|
33350
|
+
const hours = parseInt(TRTIME.substring(0, 2), 10);
|
|
33351
|
+
const minutes = parseInt(TRTIME.substring(2, 4), 10);
|
|
33352
|
+
const seconds = parseInt(TRTIME.substring(4, 6), 10);
|
|
33353
|
+
return new Date(year, month, day, hours, minutes, seconds);
|
|
33354
|
+
};
|
|
33153
33355
|
async function removeAccessGroup({
|
|
33154
33356
|
cardNo,
|
|
33155
33357
|
staffNo,
|
|
@@ -33182,6 +33384,16 @@ async function removeAccessGroup({
|
|
|
33182
33384
|
console.log(error);
|
|
33183
33385
|
}
|
|
33184
33386
|
}
|
|
33387
|
+
async function getTransactions(index, url) {
|
|
33388
|
+
try {
|
|
33389
|
+
const decrypt = decryptAcmUrl(url);
|
|
33390
|
+
const response = await import_axios.default.get(`${decrypt}transactions?from=${index}`);
|
|
33391
|
+
if (response.status === 200 || response.status === 201)
|
|
33392
|
+
return response.data;
|
|
33393
|
+
} catch (error) {
|
|
33394
|
+
return Promise.reject(error);
|
|
33395
|
+
}
|
|
33396
|
+
}
|
|
33185
33397
|
|
|
33186
33398
|
// src/repositories/access-management.repo.ts
|
|
33187
33399
|
var import_xml2js2 = require("xml2js");
|
|
@@ -33189,9 +33401,9 @@ var import_xml2js2 = require("xml2js");
|
|
|
33189
33401
|
// src/utils/rsa-encryption.ts
|
|
33190
33402
|
var crypto2 = __toESM(require("crypto"));
|
|
33191
33403
|
var import_fs4 = __toESM(require("fs"));
|
|
33192
|
-
var
|
|
33193
|
-
var pub =
|
|
33194
|
-
var priv =
|
|
33404
|
+
var import_path3 = __toESM(require("path"));
|
|
33405
|
+
var pub = import_path3.default.resolve(process.cwd(), "./src/public/rsa-keys/new_rsa_512_pub.pem");
|
|
33406
|
+
var priv = import_path3.default.resolve(process.cwd(), "./src/public/rsa-keys/new_rsa_512_priv.pem");
|
|
33195
33407
|
var EncryptionCredentials = class {
|
|
33196
33408
|
};
|
|
33197
33409
|
EncryptionCredentials.RAW_PUBLIC_KEY = import_fs4.default.readFileSync(pub, "utf8");
|
|
@@ -33308,6 +33520,19 @@ function UseAccessManagementRepo() {
|
|
|
33308
33520
|
return Promise.reject("Failed to create Access cards indexes.");
|
|
33309
33521
|
}
|
|
33310
33522
|
}
|
|
33523
|
+
async function indexCombination() {
|
|
33524
|
+
try {
|
|
33525
|
+
await Promise.all([
|
|
33526
|
+
collection().createIndex({ isWinsland: 1 }),
|
|
33527
|
+
collection().createIndex({ doorName: 1 }),
|
|
33528
|
+
collection().createIndex({ liftName: 1 }),
|
|
33529
|
+
collection().createIndex({ liftName: 1, doorName: 1, isWinsland: 1 })
|
|
33530
|
+
]);
|
|
33531
|
+
return Promise.resolve("Access cards indexes created.");
|
|
33532
|
+
} catch (error) {
|
|
33533
|
+
return Promise.reject("Failed to create Access cards indexes.");
|
|
33534
|
+
}
|
|
33535
|
+
}
|
|
33311
33536
|
async function createIndexForEntrypass() {
|
|
33312
33537
|
try {
|
|
33313
33538
|
const entrypass = collectionName("entrypass-settings");
|
|
@@ -35155,6 +35380,116 @@ function UseAccessManagementRepo() {
|
|
|
35155
35380
|
throw new Error(error.message);
|
|
35156
35381
|
}
|
|
35157
35382
|
}
|
|
35383
|
+
async function getTransactionsRepo({ page = 1, limit = 10, site, cardNo, url }) {
|
|
35384
|
+
page = page ? page - 1 : 0;
|
|
35385
|
+
site = new import_mongodb90.ObjectId(site);
|
|
35386
|
+
try {
|
|
35387
|
+
let index = await collectionName("access-card-transactions").findOne({}, { sort: { index: -1 } });
|
|
35388
|
+
index = index ? index.index : 0;
|
|
35389
|
+
const response = await getTransactions(index, url);
|
|
35390
|
+
if (response && Array.isArray(response.items) && response.items.length > 0) {
|
|
35391
|
+
let result2 = response.items.map((item) => ({
|
|
35392
|
+
id: item.id,
|
|
35393
|
+
data: JSON.parse(item.data),
|
|
35394
|
+
timestamp: item.timestamp
|
|
35395
|
+
}));
|
|
35396
|
+
result2 = result2.filter((item) => item.data.Event.ETYPE === "0" && item.data.Event.CARDNO !== "");
|
|
35397
|
+
if (result2.length > 0) {
|
|
35398
|
+
const transactions = result2.map(
|
|
35399
|
+
(item) => new MAccessCardTransaction({
|
|
35400
|
+
index: item.id,
|
|
35401
|
+
cardNo: item.data.Event.CARDNO,
|
|
35402
|
+
staffNo: item.data.Event.STAFFNO,
|
|
35403
|
+
staffName: item.data.Event.STAFFNAME,
|
|
35404
|
+
accessType: item.data.Event.DEVNAME,
|
|
35405
|
+
accessStatus: item.data.Event.TRCODE,
|
|
35406
|
+
description: item.data.Event.TRDESC,
|
|
35407
|
+
accessTime: entryPassDate(item.data.Event.TRDATE, item.data.Event.TRTIME),
|
|
35408
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
35409
|
+
})
|
|
35410
|
+
);
|
|
35411
|
+
await collectionName("access-card-transactions").insertMany(transactions);
|
|
35412
|
+
}
|
|
35413
|
+
}
|
|
35414
|
+
const result = await collectionName("access-card-transactions").aggregate([
|
|
35415
|
+
{
|
|
35416
|
+
$match: { cardNo }
|
|
35417
|
+
},
|
|
35418
|
+
{
|
|
35419
|
+
$lookup: {
|
|
35420
|
+
from: "access-card",
|
|
35421
|
+
let: { cardNo: "$cardNo" },
|
|
35422
|
+
pipeline: [
|
|
35423
|
+
{
|
|
35424
|
+
$match: {
|
|
35425
|
+
$expr: {
|
|
35426
|
+
$eq: ["$cardNo", "$$cardNo"]
|
|
35427
|
+
}
|
|
35428
|
+
}
|
|
35429
|
+
},
|
|
35430
|
+
{
|
|
35431
|
+
$lookup: {
|
|
35432
|
+
from: "users",
|
|
35433
|
+
let: { userId: "$userId" },
|
|
35434
|
+
pipeline: [
|
|
35435
|
+
{
|
|
35436
|
+
$match: {
|
|
35437
|
+
$expr: {
|
|
35438
|
+
$eq: ["$_id", "$$userId"]
|
|
35439
|
+
}
|
|
35440
|
+
}
|
|
35441
|
+
},
|
|
35442
|
+
{
|
|
35443
|
+
$project: {
|
|
35444
|
+
_id: 1,
|
|
35445
|
+
givenName: 1,
|
|
35446
|
+
surname: 1
|
|
35447
|
+
}
|
|
35448
|
+
}
|
|
35449
|
+
],
|
|
35450
|
+
as: "user"
|
|
35451
|
+
}
|
|
35452
|
+
},
|
|
35453
|
+
{
|
|
35454
|
+
$project: {
|
|
35455
|
+
_id: 1,
|
|
35456
|
+
user: { $arrayElemAt: ["$user", 0] },
|
|
35457
|
+
type: 1,
|
|
35458
|
+
cardNo: 1
|
|
35459
|
+
}
|
|
35460
|
+
}
|
|
35461
|
+
],
|
|
35462
|
+
as: "accessCard"
|
|
35463
|
+
}
|
|
35464
|
+
},
|
|
35465
|
+
{
|
|
35466
|
+
$project: {
|
|
35467
|
+
_id: 1,
|
|
35468
|
+
cardNo: 1,
|
|
35469
|
+
staffNo: 1,
|
|
35470
|
+
staffName: 1,
|
|
35471
|
+
accessType: 1,
|
|
35472
|
+
accessStatus: 1,
|
|
35473
|
+
description: 1,
|
|
35474
|
+
accessTime: 1,
|
|
35475
|
+
createdAt: 1,
|
|
35476
|
+
accessCard: { $arrayElemAt: ["$accessCard", 0] }
|
|
35477
|
+
}
|
|
35478
|
+
},
|
|
35479
|
+
{
|
|
35480
|
+
$facet: {
|
|
35481
|
+
totalCount: [{ $count: "count" }],
|
|
35482
|
+
items: [{ $sort: { _id: -1 } }, { $skip: page * limit }, { $limit: limit }]
|
|
35483
|
+
}
|
|
35484
|
+
}
|
|
35485
|
+
]).toArray();
|
|
35486
|
+
const length = result[0].totalCount[0] ? result[0].totalCount[0].count : 0;
|
|
35487
|
+
const items = result[0].items;
|
|
35488
|
+
return (0, import_node_server_utils153.paginate)(items, page, limit, length);
|
|
35489
|
+
} catch (error) {
|
|
35490
|
+
return Promise.reject("Server internal error.");
|
|
35491
|
+
}
|
|
35492
|
+
}
|
|
35158
35493
|
return {
|
|
35159
35494
|
createIndexes,
|
|
35160
35495
|
createIndexForEntrypass,
|
|
@@ -35185,7 +35520,9 @@ function UseAccessManagementRepo() {
|
|
|
35185
35520
|
addVisitorAccessCardRepo,
|
|
35186
35521
|
signQrCodeRepo,
|
|
35187
35522
|
checkoutVisitorRepo,
|
|
35188
|
-
getBlockLevelAndUnitListRepo
|
|
35523
|
+
getBlockLevelAndUnitListRepo,
|
|
35524
|
+
indexCombination,
|
|
35525
|
+
getTransactionsRepo
|
|
35189
35526
|
};
|
|
35190
35527
|
}
|
|
35191
35528
|
|
|
@@ -35225,7 +35562,8 @@ function useAccessManagementSvc() {
|
|
|
35225
35562
|
addVisitorAccessCardRepo,
|
|
35226
35563
|
signQrCodeRepo,
|
|
35227
35564
|
checkoutVisitorRepo,
|
|
35228
|
-
getBlockLevelAndUnitListRepo
|
|
35565
|
+
getBlockLevelAndUnitListRepo,
|
|
35566
|
+
getTransactionsRepo
|
|
35229
35567
|
} = UseAccessManagementRepo();
|
|
35230
35568
|
const addPhysicalCardSvc = async (payload) => {
|
|
35231
35569
|
try {
|
|
@@ -35258,8 +35596,8 @@ function useAccessManagementSvc() {
|
|
|
35258
35596
|
const command = readTemplate("door-levels");
|
|
35259
35597
|
const response = await sendCommand(command, params.acm_url);
|
|
35260
35598
|
const res = await (0, import_xml2js3.parseStringPromise)(response, { explicitArray: false });
|
|
35261
|
-
const
|
|
35262
|
-
return
|
|
35599
|
+
const format2 = await formatDoorAccessLevels(res);
|
|
35600
|
+
return format2;
|
|
35263
35601
|
} catch (err) {
|
|
35264
35602
|
throw new Error(err.message);
|
|
35265
35603
|
}
|
|
@@ -35269,8 +35607,8 @@ function useAccessManagementSvc() {
|
|
|
35269
35607
|
const command = readTemplate("lift-levels");
|
|
35270
35608
|
const response = await sendCommand(command, params.acm_url);
|
|
35271
35609
|
const res = await (0, import_xml2js3.parseStringPromise)(response, { explicitArray: false });
|
|
35272
|
-
const
|
|
35273
|
-
return
|
|
35610
|
+
const format2 = await formatLiftAccessLevels(res);
|
|
35611
|
+
return format2;
|
|
35274
35612
|
} catch (error) {
|
|
35275
35613
|
throw new Error(error.message);
|
|
35276
35614
|
}
|
|
@@ -35280,8 +35618,8 @@ function useAccessManagementSvc() {
|
|
|
35280
35618
|
const command = readTemplate("access-group");
|
|
35281
35619
|
const response = await sendCommand(command, params.acm_url);
|
|
35282
35620
|
const res = await (0, import_xml2js3.parseStringPromise)(response, { explicitArray: false });
|
|
35283
|
-
const
|
|
35284
|
-
return
|
|
35621
|
+
const format2 = await formatAccessGroup(res);
|
|
35622
|
+
return format2;
|
|
35285
35623
|
} catch (err) {
|
|
35286
35624
|
throw new Error(err.message);
|
|
35287
35625
|
}
|
|
@@ -35517,6 +35855,14 @@ function useAccessManagementSvc() {
|
|
|
35517
35855
|
throw new Error(err.message);
|
|
35518
35856
|
}
|
|
35519
35857
|
};
|
|
35858
|
+
const getTransactionsSvc = async ({ page, limit, site, cardNo, url }) => {
|
|
35859
|
+
try {
|
|
35860
|
+
const response = await getTransactionsRepo({ page, limit, site, cardNo, url });
|
|
35861
|
+
return response;
|
|
35862
|
+
} catch (err) {
|
|
35863
|
+
return Promise.reject("Server internal error.");
|
|
35864
|
+
}
|
|
35865
|
+
};
|
|
35520
35866
|
return {
|
|
35521
35867
|
addPhysicalCardSvc,
|
|
35522
35868
|
addNonPhysicalCardSvc,
|
|
@@ -35551,7 +35897,8 @@ function useAccessManagementSvc() {
|
|
|
35551
35897
|
addVisitorAccessCardSvc,
|
|
35552
35898
|
signQrCodeSvc,
|
|
35553
35899
|
checkoutVisitorSvc,
|
|
35554
|
-
getBlockLevelAndUnitListSvc
|
|
35900
|
+
getBlockLevelAndUnitListSvc,
|
|
35901
|
+
getTransactionsSvc
|
|
35555
35902
|
};
|
|
35556
35903
|
}
|
|
35557
35904
|
|
|
@@ -35591,7 +35938,8 @@ function useAccessManagementController() {
|
|
|
35591
35938
|
addVisitorAccessCardSvc,
|
|
35592
35939
|
signQrCodeSvc,
|
|
35593
35940
|
checkoutVisitorSvc,
|
|
35594
|
-
getBlockLevelAndUnitListSvc
|
|
35941
|
+
getBlockLevelAndUnitListSvc,
|
|
35942
|
+
getTransactionsSvc
|
|
35595
35943
|
} = useAccessManagementSvc();
|
|
35596
35944
|
const addPhysicalCard = async (req, res) => {
|
|
35597
35945
|
try {
|
|
@@ -36353,6 +36701,31 @@ function useAccessManagementController() {
|
|
|
36353
36701
|
});
|
|
36354
36702
|
}
|
|
36355
36703
|
};
|
|
36704
|
+
const getTransactions2 = async (req, res) => {
|
|
36705
|
+
const { page = 1, limit = 10, site, cardNo, url } = req.query;
|
|
36706
|
+
const schema2 = import_joi85.default.object({
|
|
36707
|
+
page: import_joi85.default.number().required(),
|
|
36708
|
+
limit: import_joi85.default.number().optional().default(10),
|
|
36709
|
+
site: import_joi85.default.string().hex().required(),
|
|
36710
|
+
cardNo: import_joi85.default.string().required()
|
|
36711
|
+
});
|
|
36712
|
+
const { value, error } = schema2.validate({ page, limit, site, cardNo });
|
|
36713
|
+
if (error) {
|
|
36714
|
+
return res.status(400).json({ message: error.message });
|
|
36715
|
+
}
|
|
36716
|
+
try {
|
|
36717
|
+
const result = await getTransactionsSvc({
|
|
36718
|
+
page: Number(page),
|
|
36719
|
+
limit: Number(value.limit),
|
|
36720
|
+
site,
|
|
36721
|
+
cardNo,
|
|
36722
|
+
url
|
|
36723
|
+
});
|
|
36724
|
+
return res.json(result);
|
|
36725
|
+
} catch (error2) {
|
|
36726
|
+
return Promise.reject("Internal Server Error");
|
|
36727
|
+
}
|
|
36728
|
+
};
|
|
36356
36729
|
return {
|
|
36357
36730
|
addPhysicalCard,
|
|
36358
36731
|
addNonPhysicalCard,
|
|
@@ -36385,7 +36758,8 @@ function useAccessManagementController() {
|
|
|
36385
36758
|
signQrCode,
|
|
36386
36759
|
checkoutVisitor,
|
|
36387
36760
|
removeAccessCard,
|
|
36388
|
-
getBlockLevelAndUnitList
|
|
36761
|
+
getBlockLevelAndUnitList,
|
|
36762
|
+
getTransactions: getTransactions2
|
|
36389
36763
|
};
|
|
36390
36764
|
}
|
|
36391
36765
|
|
|
@@ -37571,6 +37945,18 @@ function useBulletinVideoRepo() {
|
|
|
37571
37945
|
);
|
|
37572
37946
|
}
|
|
37573
37947
|
}
|
|
37948
|
+
async function createTextIndex() {
|
|
37949
|
+
try {
|
|
37950
|
+
await collection.createIndex({
|
|
37951
|
+
title: "text",
|
|
37952
|
+
description: "text"
|
|
37953
|
+
});
|
|
37954
|
+
} catch (error) {
|
|
37955
|
+
throw new import_node_server_utils161.InternalServerError(
|
|
37956
|
+
"Failed to create text index on bulletin videos."
|
|
37957
|
+
);
|
|
37958
|
+
}
|
|
37959
|
+
}
|
|
37574
37960
|
const namespace_collection = "bulletin-videos";
|
|
37575
37961
|
const collection = db.collection(namespace_collection);
|
|
37576
37962
|
const { delNamespace, getCache, setCache } = (0, import_node_server_utils161.useCache)(namespace_collection);
|
|
@@ -37610,7 +37996,8 @@ function useBulletinVideoRepo() {
|
|
|
37610
37996
|
}
|
|
37611
37997
|
const query = {
|
|
37612
37998
|
site,
|
|
37613
|
-
status: { $ne: "deleted" }
|
|
37999
|
+
status: { $ne: "deleted" },
|
|
38000
|
+
...search && { $text: { $search: search } }
|
|
37614
38001
|
};
|
|
37615
38002
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
37616
38003
|
const cacheOptions = {
|
|
@@ -37618,10 +38005,14 @@ function useBulletinVideoRepo() {
|
|
|
37618
38005
|
sort: JSON.stringify(sort),
|
|
37619
38006
|
page,
|
|
37620
38007
|
limit,
|
|
37621
|
-
status: { $ne: "deleted" }
|
|
38008
|
+
status: { $ne: "deleted" },
|
|
38009
|
+
...search && { search }
|
|
37622
38010
|
};
|
|
37623
38011
|
if (search) {
|
|
37624
|
-
query.$
|
|
38012
|
+
query.$or = [
|
|
38013
|
+
{ title: { $regex: search, $options: "i" } },
|
|
38014
|
+
{ description: { $regex: search, $options: "i" } }
|
|
38015
|
+
];
|
|
37625
38016
|
cacheOptions.search = search;
|
|
37626
38017
|
}
|
|
37627
38018
|
const cacheKey = (0, import_node_server_utils161.makeCacheKey)(namespace_collection, cacheOptions);
|
|
@@ -37757,7 +38148,8 @@ function useBulletinVideoRepo() {
|
|
|
37757
38148
|
getBulletinVideoById,
|
|
37758
38149
|
updateBulletinVideoById,
|
|
37759
38150
|
deleteBulletinVideoById,
|
|
37760
|
-
createIndexes
|
|
38151
|
+
createIndexes,
|
|
38152
|
+
createTextIndex
|
|
37761
38153
|
};
|
|
37762
38154
|
}
|
|
37763
38155
|
|
|
@@ -44128,11 +44520,11 @@ async function fetchAttendanceData({
|
|
|
44128
44520
|
};
|
|
44129
44521
|
}
|
|
44130
44522
|
}
|
|
44131
|
-
function filterByShiftTime(attendance, shiftData, timezone,
|
|
44523
|
+
function filterByShiftTime(attendance, shiftData, timezone, format2) {
|
|
44132
44524
|
return attendance.filter((item) => {
|
|
44133
44525
|
if (!item.checkIn)
|
|
44134
44526
|
return false;
|
|
44135
|
-
const checkInLocal = (0, import_moment_timezone.default)(item.checkIn,
|
|
44527
|
+
const checkInLocal = (0, import_moment_timezone.default)(item.checkIn, format2);
|
|
44136
44528
|
if (!checkInLocal.isValid())
|
|
44137
44529
|
return false;
|
|
44138
44530
|
const [startHour, startMinute] = shiftData.checkIn.split(":").map(Number);
|
|
@@ -44207,7 +44599,7 @@ function designationCount(attendance, designationConfig, shiftName) {
|
|
|
44207
44599
|
}
|
|
44208
44600
|
return result;
|
|
44209
44601
|
}
|
|
44210
|
-
function totalCountPerShift(attendance, shiftData, timezone,
|
|
44602
|
+
function totalCountPerShift(attendance, shiftData, timezone, format2) {
|
|
44211
44603
|
let totalCountPerShift3 = [];
|
|
44212
44604
|
const seen = /* @__PURE__ */ new Set();
|
|
44213
44605
|
const uniqueAttendanceData = [];
|
|
@@ -44230,7 +44622,7 @@ function totalCountPerShift(attendance, shiftData, timezone, format) {
|
|
|
44230
44622
|
data = uniqueAttendanceData.filter((item) => {
|
|
44231
44623
|
if (!item.checkIn)
|
|
44232
44624
|
return false;
|
|
44233
|
-
const checkInLocal = (0, import_moment_timezone.default)(item.checkIn,
|
|
44625
|
+
const checkInLocal = (0, import_moment_timezone.default)(item.checkIn, format2);
|
|
44234
44626
|
if (!checkInLocal.isValid())
|
|
44235
44627
|
return false;
|
|
44236
44628
|
const [startHour, startMinute] = shift.checkIn.split(":").map(Number);
|
|
@@ -44267,11 +44659,11 @@ function totalCountPerShift(attendance, shiftData, timezone, format) {
|
|
|
44267
44659
|
}
|
|
44268
44660
|
return totalCountPerShift3;
|
|
44269
44661
|
}
|
|
44270
|
-
function filterByStatus(attendance, shiftData, timezone,
|
|
44662
|
+
function filterByStatus(attendance, shiftData, timezone, format2, status) {
|
|
44271
44663
|
return attendance.filter((item) => {
|
|
44272
44664
|
if (!item.checkIn)
|
|
44273
44665
|
return false;
|
|
44274
|
-
const checkInLocal = (0, import_moment_timezone.default)(item.checkIn,
|
|
44666
|
+
const checkInLocal = (0, import_moment_timezone.default)(item.checkIn, format2);
|
|
44275
44667
|
if (!checkInLocal.isValid())
|
|
44276
44668
|
return false;
|
|
44277
44669
|
const [lateHour, lateMinute] = shiftData.lateCheckInAlert.split(":").map(Number);
|
|
@@ -44321,7 +44713,7 @@ async function fetchSites({ siteUrl, token }) {
|
|
|
44321
44713
|
} while (attempt < maxRetries);
|
|
44322
44714
|
throw lastError;
|
|
44323
44715
|
}
|
|
44324
|
-
async function totalCountPerStatus(attendance, shiftName, shiftData, timezone,
|
|
44716
|
+
async function totalCountPerStatus(attendance, shiftName, shiftData, timezone, format2, totalShifts) {
|
|
44325
44717
|
const totalCountPerStatus3 = {
|
|
44326
44718
|
onTime: 0,
|
|
44327
44719
|
late: 0,
|
|
@@ -44338,7 +44730,7 @@ async function totalCountPerStatus(attendance, shiftName, shiftData, timezone, f
|
|
|
44338
44730
|
const shiftStartTime = parseTime(shift.checkIn);
|
|
44339
44731
|
const shiftEndTime = parseTime(shift.checkOut);
|
|
44340
44732
|
const lateTime = parseTime(shift.lateCheckInAlert);
|
|
44341
|
-
const uniqueAttendanceData = shiftName === "all" ? await filterByShiftTime(attendance, shift, timezone,
|
|
44733
|
+
const uniqueAttendanceData = shiftName === "all" ? await filterByShiftTime(attendance, shift, timezone, format2) : attendance;
|
|
44342
44734
|
for (const item of uniqueAttendanceData) {
|
|
44343
44735
|
const {
|
|
44344
44736
|
checkIn: checkInStr,
|
|
@@ -44347,9 +44739,9 @@ async function totalCountPerStatus(attendance, shiftName, shiftData, timezone, f
|
|
|
44347
44739
|
} = item;
|
|
44348
44740
|
if (!checkInStr || seenGlobal.has(identificationNumber))
|
|
44349
44741
|
continue;
|
|
44350
|
-
const checkIn = (0, import_moment_timezone.default)(checkInStr,
|
|
44351
|
-
const checkOut = checkOutStr ? (0, import_moment_timezone.default)(checkOutStr,
|
|
44352
|
-
const checkOutChecker = checkOut ? (0, import_moment_timezone.default)(checkOutStr,
|
|
44742
|
+
const checkIn = (0, import_moment_timezone.default)(checkInStr, format2);
|
|
44743
|
+
const checkOut = checkOutStr ? (0, import_moment_timezone.default)(checkOutStr, format2) : null;
|
|
44744
|
+
const checkOutChecker = checkOut ? (0, import_moment_timezone.default)(checkOutStr, format2) : checkIn;
|
|
44353
44745
|
if (!checkIn.isValid())
|
|
44354
44746
|
continue;
|
|
44355
44747
|
const shiftStart = (0, import_moment_timezone.default)(checkIn).set({ ...shiftStartTime, second: 59, millisecond: 59 }).subtract(default_early_checkIn, "hour");
|
|
@@ -44385,7 +44777,7 @@ async function totalCountPerStatus(attendance, shiftName, shiftData, timezone, f
|
|
|
44385
44777
|
totalCountPerStatus3.totalCount = shiftMap[shiftName];
|
|
44386
44778
|
return totalCountPerStatus3;
|
|
44387
44779
|
}
|
|
44388
|
-
async function chartCountData(attendance, shiftData, timezone,
|
|
44780
|
+
async function chartCountData(attendance, shiftData, timezone, format2, totalShifts, startDateStr, endDateStr, status = "all") {
|
|
44389
44781
|
const categorizedData = [];
|
|
44390
44782
|
const seenPerDay = /* @__PURE__ */ new Set();
|
|
44391
44783
|
const parseTime = (timeStr) => {
|
|
@@ -44408,7 +44800,7 @@ async function chartCountData(attendance, shiftData, timezone, format, totalShif
|
|
|
44408
44800
|
dailyAttendance,
|
|
44409
44801
|
shiftData,
|
|
44410
44802
|
timezone,
|
|
44411
|
-
|
|
44803
|
+
format2
|
|
44412
44804
|
);
|
|
44413
44805
|
if (status === "all" || status === "under" || status === "over") {
|
|
44414
44806
|
const shifts = [
|
|
@@ -44454,7 +44846,7 @@ async function chartCountData(attendance, shiftData, timezone, format, totalShif
|
|
|
44454
44846
|
dailyAttendance,
|
|
44455
44847
|
shift,
|
|
44456
44848
|
timezone,
|
|
44457
|
-
|
|
44849
|
+
format2
|
|
44458
44850
|
);
|
|
44459
44851
|
for (const item of uniqueAttendanceData) {
|
|
44460
44852
|
const {
|
|
@@ -44464,7 +44856,7 @@ async function chartCountData(attendance, shiftData, timezone, format, totalShif
|
|
|
44464
44856
|
} = item;
|
|
44465
44857
|
if (!checkInStr)
|
|
44466
44858
|
continue;
|
|
44467
|
-
const checkIn = (0, import_moment_timezone.default)(checkInStr,
|
|
44859
|
+
const checkIn = (0, import_moment_timezone.default)(checkInStr, format2);
|
|
44468
44860
|
if (!checkIn.isValid())
|
|
44469
44861
|
continue;
|
|
44470
44862
|
const dayKey = `${identificationNumber}-${checkIn.format(
|
|
@@ -44473,7 +44865,7 @@ async function chartCountData(attendance, shiftData, timezone, format, totalShif
|
|
|
44473
44865
|
if (seenPerDay.has(dayKey))
|
|
44474
44866
|
continue;
|
|
44475
44867
|
seenPerDay.add(dayKey);
|
|
44476
|
-
const checkOut = checkOutStr ? (0, import_moment_timezone.default)(checkOutStr,
|
|
44868
|
+
const checkOut = checkOutStr ? (0, import_moment_timezone.default)(checkOutStr, format2) : checkIn;
|
|
44477
44869
|
const shiftStart = (0, import_moment_timezone.default)(checkIn).set({ ...shiftStartTime, second: 59, millisecond: 59 }).subtract(default_early_checkIn, "hour");
|
|
44478
44870
|
const shiftEnd = (0, import_moment_timezone.default)(checkOut).set({ ...shiftEndTime, second: 0, millisecond: 0 }).subtract(default_early_checkIn, "hour");
|
|
44479
44871
|
const lateCheckIn = (0, import_moment_timezone.default)(checkIn).set({
|
|
@@ -50167,6 +50559,7 @@ function useRoleControllerV2() {
|
|
|
50167
50559
|
AccessTypeProps,
|
|
50168
50560
|
AppServiceType,
|
|
50169
50561
|
BuildingStatus,
|
|
50562
|
+
BulletinOrder,
|
|
50170
50563
|
BulletinRecipient,
|
|
50171
50564
|
BulletinSort,
|
|
50172
50565
|
BulletinStatus,
|
|
@@ -50181,6 +50574,10 @@ function useRoleControllerV2() {
|
|
|
50181
50574
|
EmailSender,
|
|
50182
50575
|
EntryOrder,
|
|
50183
50576
|
EntrySort,
|
|
50577
|
+
EventOrder,
|
|
50578
|
+
EventSort,
|
|
50579
|
+
EventStatus,
|
|
50580
|
+
EventType,
|
|
50184
50581
|
FacilitySort,
|
|
50185
50582
|
FacilityStatus,
|
|
50186
50583
|
GuestSort,
|
|
@@ -50293,6 +50690,7 @@ function useRoleControllerV2() {
|
|
|
50293
50690
|
events_namespace_collection,
|
|
50294
50691
|
facility_bookings_namespace_collection,
|
|
50295
50692
|
feedbackSchema,
|
|
50693
|
+
feedbacks2_namespace_collection,
|
|
50296
50694
|
feedbacks_namespace_collection,
|
|
50297
50695
|
formatDahuaDate,
|
|
50298
50696
|
getPeriodRangeWithPrevious,
|