@7365admin1/core 2.46.0 → 2.48.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 +121 -59
- package/dist/index.js +1318 -865
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1313 -865
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -49,6 +49,10 @@ __export(src_exports, {
|
|
|
49
49
|
EmailSender: () => EmailSender,
|
|
50
50
|
EntryOrder: () => EntryOrder,
|
|
51
51
|
EntrySort: () => EntrySort,
|
|
52
|
+
EventOrder: () => EventOrder,
|
|
53
|
+
EventSort: () => EventSort,
|
|
54
|
+
EventStatus: () => EventStatus,
|
|
55
|
+
EventType: () => EventType,
|
|
52
56
|
FacilitySort: () => FacilitySort,
|
|
53
57
|
FacilityStatus: () => FacilityStatus,
|
|
54
58
|
GuestSort: () => GuestSort,
|
|
@@ -161,6 +165,7 @@ __export(src_exports, {
|
|
|
161
165
|
events_namespace_collection: () => events_namespace_collection,
|
|
162
166
|
facility_bookings_namespace_collection: () => facility_bookings_namespace_collection,
|
|
163
167
|
feedbackSchema: () => feedbackSchema,
|
|
168
|
+
feedbacks2_namespace_collection: () => feedbacks2_namespace_collection,
|
|
164
169
|
feedbacks_namespace_collection: () => feedbacks_namespace_collection,
|
|
165
170
|
formatDahuaDate: () => formatDahuaDate,
|
|
166
171
|
getPeriodRangeWithPrevious: () => getPeriodRangeWithPrevious,
|
|
@@ -716,15 +721,22 @@ function MFeedback(value) {
|
|
|
716
721
|
// src/repositories/feedback.repo.ts
|
|
717
722
|
var import_node_server_utils5 = require("@7365admin1/node-server-utils");
|
|
718
723
|
var feedbacks_namespace_collection = "feedbacks";
|
|
724
|
+
var feedbacks2_namespace_collection = "feedbacks2";
|
|
719
725
|
function useFeedbackRepo() {
|
|
720
726
|
const db = import_node_server_utils5.useAtlas.getDb();
|
|
721
727
|
if (!db) {
|
|
722
728
|
throw new import_node_server_utils5.InternalServerError("Unable to connect to server.");
|
|
723
729
|
}
|
|
724
730
|
const collection = db.collection(feedbacks_namespace_collection);
|
|
731
|
+
const feedbacks2Collection = db.collection(feedbacks2_namespace_collection);
|
|
725
732
|
const { delNamespace, getCache, setCache } = (0, import_node_server_utils5.useCache)(
|
|
726
733
|
feedbacks_namespace_collection
|
|
727
734
|
);
|
|
735
|
+
const {
|
|
736
|
+
delNamespace: delNamespaceFeedbacks2,
|
|
737
|
+
getCache: getCacheFeedbacks2,
|
|
738
|
+
setCache: setCacheFeedbacks2
|
|
739
|
+
} = (0, import_node_server_utils5.useCache)(feedbacks2_namespace_collection);
|
|
728
740
|
const { delNamespace: _delDashboardNameSpace } = (0, import_node_server_utils5.useCache)("dashboard");
|
|
729
741
|
async function createIndex() {
|
|
730
742
|
try {
|
|
@@ -1185,7 +1197,7 @@ function useFeedbackRepo() {
|
|
|
1185
1197
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
1186
1198
|
deletedAt: /* @__PURE__ */ new Date()
|
|
1187
1199
|
};
|
|
1188
|
-
const res = await
|
|
1200
|
+
const res = await feedbacks2Collection.updateOne(
|
|
1189
1201
|
{ _id },
|
|
1190
1202
|
{ $set: updateValue },
|
|
1191
1203
|
{ session }
|
|
@@ -1193,13 +1205,13 @@ function useFeedbackRepo() {
|
|
|
1193
1205
|
if (res.modifiedCount === 0) {
|
|
1194
1206
|
throw new import_node_server_utils5.InternalServerError("Unable to delete feedback.");
|
|
1195
1207
|
}
|
|
1196
|
-
|
|
1208
|
+
delNamespaceFeedbacks2().then(() => {
|
|
1197
1209
|
import_node_server_utils5.logger.info(
|
|
1198
|
-
`Cache cleared for namespace: ${
|
|
1210
|
+
`Cache cleared for namespace: ${feedbacks2_namespace_collection}`
|
|
1199
1211
|
);
|
|
1200
1212
|
}).catch((err) => {
|
|
1201
1213
|
import_node_server_utils5.logger.error(
|
|
1202
|
-
`Failed to clear cache for namespace: ${
|
|
1214
|
+
`Failed to clear cache for namespace: ${feedbacks2_namespace_collection}`,
|
|
1203
1215
|
err
|
|
1204
1216
|
);
|
|
1205
1217
|
});
|
|
@@ -3143,6 +3155,7 @@ var APP_POOL_MAINTENANCE = process.env.APP_POOL_MAINTENANCE ?? "http://localhost
|
|
|
3143
3155
|
var ENCRYPTION_KEY = process.env.ENCRYPTION_KEY ?? "";
|
|
3144
3156
|
var DOMAIN = process.env.DOMAIN ?? "localhost";
|
|
3145
3157
|
var OPEN_AI_API_KEY = process.env.OPEN_AI_API_KEY;
|
|
3158
|
+
var STORAGE_API = process.env.STORAGE_API;
|
|
3146
3159
|
|
|
3147
3160
|
// src/services/auth.service.ts
|
|
3148
3161
|
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
@@ -5490,6 +5503,39 @@ function useVerificationRepoV2() {
|
|
|
5490
5503
|
throw new import_node_server_utils20.InternalServerError("Error updating verification status.");
|
|
5491
5504
|
}
|
|
5492
5505
|
}
|
|
5506
|
+
async function countPendingOrgInvites(orgId) {
|
|
5507
|
+
try {
|
|
5508
|
+
orgId = new import_mongodb18.ObjectId(orgId);
|
|
5509
|
+
} catch (error) {
|
|
5510
|
+
throw new import_node_server_utils20.BadRequestError("Invalid organization ID format.");
|
|
5511
|
+
}
|
|
5512
|
+
const query = {
|
|
5513
|
+
status: "pending" /* PENDING */,
|
|
5514
|
+
type: { $in: ["user-invite", "member-invite"] },
|
|
5515
|
+
"metadata.org": orgId
|
|
5516
|
+
};
|
|
5517
|
+
const cacheKey = (0, import_node_server_utils20.makeCacheKey)(namespace_collection, {
|
|
5518
|
+
status: "pending" /* PENDING */,
|
|
5519
|
+
type: JSON.stringify(["user-invite", "member-invite"]),
|
|
5520
|
+
org: orgId.toString()
|
|
5521
|
+
});
|
|
5522
|
+
const cachedData = await getCache(cacheKey);
|
|
5523
|
+
if (typeof cachedData === "number") {
|
|
5524
|
+
import_node_server_utils20.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5525
|
+
return cachedData;
|
|
5526
|
+
}
|
|
5527
|
+
try {
|
|
5528
|
+
const count = await collection.countDocuments(query);
|
|
5529
|
+
setCache(cacheKey, count, 15 * 60).then(() => {
|
|
5530
|
+
import_node_server_utils20.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5531
|
+
}).catch((err) => {
|
|
5532
|
+
import_node_server_utils20.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5533
|
+
});
|
|
5534
|
+
return count;
|
|
5535
|
+
} catch (error) {
|
|
5536
|
+
throw new import_node_server_utils20.InternalServerError("Failed to count pending invitations.");
|
|
5537
|
+
}
|
|
5538
|
+
}
|
|
5493
5539
|
return {
|
|
5494
5540
|
createIndex,
|
|
5495
5541
|
createTextIndex,
|
|
@@ -5498,7 +5544,8 @@ function useVerificationRepoV2() {
|
|
|
5498
5544
|
getByVerificationCode,
|
|
5499
5545
|
getVerificationById,
|
|
5500
5546
|
getVerifications,
|
|
5501
|
-
updateStatusById
|
|
5547
|
+
updateStatusById,
|
|
5548
|
+
countPendingOrgInvites
|
|
5502
5549
|
};
|
|
5503
5550
|
}
|
|
5504
5551
|
|
|
@@ -5576,6 +5623,46 @@ function useVerificationService() {
|
|
|
5576
5623
|
throw error;
|
|
5577
5624
|
}
|
|
5578
5625
|
}
|
|
5626
|
+
async function createSimpleUserInvite({
|
|
5627
|
+
email,
|
|
5628
|
+
metadata
|
|
5629
|
+
}) {
|
|
5630
|
+
const type = "user-invite";
|
|
5631
|
+
const value = {
|
|
5632
|
+
type,
|
|
5633
|
+
email,
|
|
5634
|
+
metadata,
|
|
5635
|
+
expireAt: new Date(
|
|
5636
|
+
(/* @__PURE__ */ new Date()).getTime() + 72 * 60 * 60 * 1e3
|
|
5637
|
+
).toISOString(),
|
|
5638
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5639
|
+
};
|
|
5640
|
+
if (value.metadata?.org) {
|
|
5641
|
+
await getOrgById(value.metadata?.org);
|
|
5642
|
+
}
|
|
5643
|
+
if (value.metadata?.siteId) {
|
|
5644
|
+
await getSiteById(value.metadata?.siteId);
|
|
5645
|
+
}
|
|
5646
|
+
const res = await add(value);
|
|
5647
|
+
const dir = __dirname;
|
|
5648
|
+
const filePath = (0, import_node_server_utils21.getDirectory)(dir, "./public/handlebars/user-invite");
|
|
5649
|
+
const link = `${APP_MAIN}/verify/invitation/${res}`;
|
|
5650
|
+
const emailContent = (0, import_node_server_utils21.compileHandlebar)({
|
|
5651
|
+
context: {
|
|
5652
|
+
email,
|
|
5653
|
+
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
5654
|
+
link
|
|
5655
|
+
},
|
|
5656
|
+
filePath
|
|
5657
|
+
});
|
|
5658
|
+
mailer.sendMail({
|
|
5659
|
+
to: email,
|
|
5660
|
+
subject: "User Invite",
|
|
5661
|
+
html: emailContent,
|
|
5662
|
+
sender: "iService365"
|
|
5663
|
+
});
|
|
5664
|
+
return res;
|
|
5665
|
+
}
|
|
5579
5666
|
const {
|
|
5580
5667
|
add: _add,
|
|
5581
5668
|
updateVerificationStatusById: _updateVerificationStatusById,
|
|
@@ -5869,7 +5956,8 @@ function useVerificationService() {
|
|
|
5869
5956
|
cancelUserInvitation,
|
|
5870
5957
|
updateStatusById,
|
|
5871
5958
|
signUp,
|
|
5872
|
-
checkExpiredInvitation
|
|
5959
|
+
checkExpiredInvitation,
|
|
5960
|
+
createSimpleUserInvite
|
|
5873
5961
|
};
|
|
5874
5962
|
}
|
|
5875
5963
|
|
|
@@ -7090,7 +7178,16 @@ function useUserController() {
|
|
|
7090
7178
|
async function updateUserFieldById(req, res, next) {
|
|
7091
7179
|
const validation = import_joi13.default.object({
|
|
7092
7180
|
_id: import_joi13.default.string().hex().required(),
|
|
7093
|
-
field: import_joi13.default.string().valid(
|
|
7181
|
+
field: import_joi13.default.string().valid(
|
|
7182
|
+
"name",
|
|
7183
|
+
"email",
|
|
7184
|
+
"contact",
|
|
7185
|
+
"nric",
|
|
7186
|
+
"dateOfBirth",
|
|
7187
|
+
"profile",
|
|
7188
|
+
"gender",
|
|
7189
|
+
"defaultOrg"
|
|
7190
|
+
).required(),
|
|
7094
7191
|
value: import_joi13.default.when("field", {
|
|
7095
7192
|
switch: [
|
|
7096
7193
|
{ is: "email", then: import_joi13.default.string().email().required() },
|
|
@@ -7694,6 +7791,7 @@ var import_joi16 = __toESM(require("joi"));
|
|
|
7694
7791
|
function useVerificationController() {
|
|
7695
7792
|
const {
|
|
7696
7793
|
createUserInvite: _createUserInvite,
|
|
7794
|
+
createSimpleUserInvite: _createSimpleUserInvite,
|
|
7697
7795
|
createServiceProviderInvite: _createServiceProviderInvite,
|
|
7698
7796
|
createForgetPassword: _createForgetPassword,
|
|
7699
7797
|
verify: _verify,
|
|
@@ -7744,6 +7842,58 @@ function useVerificationController() {
|
|
|
7744
7842
|
return;
|
|
7745
7843
|
}
|
|
7746
7844
|
}
|
|
7845
|
+
async function createSimpleUserInvite(req, res, next) {
|
|
7846
|
+
const payload = { ...req.body };
|
|
7847
|
+
const validation = import_joi16.default.object({
|
|
7848
|
+
email: import_joi16.default.string().email().required(),
|
|
7849
|
+
app: import_joi16.default.string().optional().allow("", null),
|
|
7850
|
+
role: import_joi16.default.string().hex().optional().allow("", null),
|
|
7851
|
+
name: import_joi16.default.string().optional().allow("", null),
|
|
7852
|
+
org: import_joi16.default.string().hex().optional().allow("", null),
|
|
7853
|
+
siteId: import_joi16.default.string().hex().optional().allow("", null),
|
|
7854
|
+
siteName: import_joi16.default.string().optional().allow("", null)
|
|
7855
|
+
});
|
|
7856
|
+
const { error } = validation.validate(payload);
|
|
7857
|
+
if (error) {
|
|
7858
|
+
import_node_server_utils32.logger.log({
|
|
7859
|
+
level: "error",
|
|
7860
|
+
message: `${error.message}`
|
|
7861
|
+
});
|
|
7862
|
+
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
7863
|
+
return;
|
|
7864
|
+
}
|
|
7865
|
+
const email = req.body.email ?? "";
|
|
7866
|
+
const app = req.body.app ?? "";
|
|
7867
|
+
const role = req.body.role ?? "";
|
|
7868
|
+
const name = req.body.name ?? "";
|
|
7869
|
+
const org = req.body.org ?? "";
|
|
7870
|
+
const siteId = req.body.siteId ?? "";
|
|
7871
|
+
const siteName = req.body.siteName ?? "";
|
|
7872
|
+
try {
|
|
7873
|
+
await _createSimpleUserInvite({
|
|
7874
|
+
email,
|
|
7875
|
+
metadata: {
|
|
7876
|
+
app,
|
|
7877
|
+
role,
|
|
7878
|
+
name,
|
|
7879
|
+
org,
|
|
7880
|
+
siteId,
|
|
7881
|
+
siteName
|
|
7882
|
+
}
|
|
7883
|
+
});
|
|
7884
|
+
res.status(201).json({
|
|
7885
|
+
message: "Successfully invited user."
|
|
7886
|
+
});
|
|
7887
|
+
return;
|
|
7888
|
+
} catch (error2) {
|
|
7889
|
+
import_node_server_utils32.logger.log({
|
|
7890
|
+
level: "error",
|
|
7891
|
+
message: `${error2.message}`
|
|
7892
|
+
});
|
|
7893
|
+
next(error2);
|
|
7894
|
+
return;
|
|
7895
|
+
}
|
|
7896
|
+
}
|
|
7747
7897
|
async function createServiceProviderInvite(req, res, next) {
|
|
7748
7898
|
const payload = req.body;
|
|
7749
7899
|
const validation = import_joi16.default.object({
|
|
@@ -7885,7 +8035,8 @@ function useVerificationController() {
|
|
|
7885
8035
|
createServiceProviderInvite,
|
|
7886
8036
|
createForgetPassword,
|
|
7887
8037
|
verify,
|
|
7888
|
-
cancelUserInvitation
|
|
8038
|
+
cancelUserInvitation,
|
|
8039
|
+
createSimpleUserInvite
|
|
7889
8040
|
};
|
|
7890
8041
|
}
|
|
7891
8042
|
|
|
@@ -13050,7 +13201,7 @@ function useCustomerController() {
|
|
|
13050
13201
|
var import_node_server_utils77 = require("@7365admin1/node-server-utils");
|
|
13051
13202
|
|
|
13052
13203
|
// src/repositories/site-camera.repo.ts
|
|
13053
|
-
var
|
|
13204
|
+
var import_node_server_utils76 = require("@7365admin1/node-server-utils");
|
|
13054
13205
|
|
|
13055
13206
|
// src/models/site-camera.model.ts
|
|
13056
13207
|
var import_node_server_utils66 = require("@7365admin1/node-server-utils");
|
|
@@ -13115,406 +13266,26 @@ function MSiteCamera(value) {
|
|
|
13115
13266
|
}
|
|
13116
13267
|
|
|
13117
13268
|
// src/repositories/site-camera.repo.ts
|
|
13118
|
-
var
|
|
13119
|
-
function useSiteCameraRepo() {
|
|
13120
|
-
const db = import_node_server_utils67.useAtlas.getDb();
|
|
13121
|
-
if (!db) {
|
|
13122
|
-
throw new Error("Unable to connect to server.");
|
|
13123
|
-
}
|
|
13124
|
-
const namespace_collection = "site.cameras";
|
|
13125
|
-
const collection = db.collection(namespace_collection);
|
|
13126
|
-
const { delNamespace, getCache, setCache } = (0, import_node_server_utils67.useCache)(namespace_collection);
|
|
13127
|
-
async function createIndexes() {
|
|
13128
|
-
try {
|
|
13129
|
-
await collection.createIndexes([
|
|
13130
|
-
{
|
|
13131
|
-
key: { site: 1 }
|
|
13132
|
-
},
|
|
13133
|
-
{
|
|
13134
|
-
key: { type: 1 }
|
|
13135
|
-
},
|
|
13136
|
-
{
|
|
13137
|
-
key: { host: 1, type: 1, status: 1, site: 1 },
|
|
13138
|
-
unique: true,
|
|
13139
|
-
partialFilterExpression: { status: "active" }
|
|
13140
|
-
}
|
|
13141
|
-
]);
|
|
13142
|
-
return `Successfully created ${namespace_collection} indexes.`;
|
|
13143
|
-
} catch (error) {
|
|
13144
|
-
import_node_server_utils67.logger.log({
|
|
13145
|
-
level: "error",
|
|
13146
|
-
message: error.message
|
|
13147
|
-
});
|
|
13148
|
-
}
|
|
13149
|
-
}
|
|
13150
|
-
async function add(value, session) {
|
|
13151
|
-
try {
|
|
13152
|
-
value = MSiteCamera(value);
|
|
13153
|
-
const res = await collection.insertOne(value, { session });
|
|
13154
|
-
delCachedData();
|
|
13155
|
-
return res.insertedId;
|
|
13156
|
-
} catch (error) {
|
|
13157
|
-
import_node_server_utils67.logger.log({
|
|
13158
|
-
level: "error",
|
|
13159
|
-
message: error.message
|
|
13160
|
-
});
|
|
13161
|
-
const isDuplicated = error.message.includes("duplicate");
|
|
13162
|
-
if (isDuplicated) {
|
|
13163
|
-
throw new import_node_server_utils67.BadRequestError("ANPR already exist.");
|
|
13164
|
-
}
|
|
13165
|
-
if (error instanceof import_node_server_utils67.AppError) {
|
|
13166
|
-
throw error;
|
|
13167
|
-
} else {
|
|
13168
|
-
throw new Error("Failed to create ANPR.");
|
|
13169
|
-
}
|
|
13170
|
-
}
|
|
13171
|
-
}
|
|
13172
|
-
async function getAll(value) {
|
|
13173
|
-
value.page = value.page ? value.page - 1 : 0;
|
|
13174
|
-
value.limit = value.limit || 10;
|
|
13175
|
-
const cacheKeyOptions = {
|
|
13176
|
-
type: value.type,
|
|
13177
|
-
page: value.page,
|
|
13178
|
-
limit: value.limit,
|
|
13179
|
-
...value.direction && { direction: value.direction }
|
|
13180
|
-
};
|
|
13181
|
-
const query = {
|
|
13182
|
-
type: value.type,
|
|
13183
|
-
...value.direction && {
|
|
13184
|
-
direction: {
|
|
13185
|
-
$in: Array.isArray(value.direction) ? value.direction : [value.direction]
|
|
13186
|
-
}
|
|
13187
|
-
}
|
|
13188
|
-
};
|
|
13189
|
-
if (value.site) {
|
|
13190
|
-
cacheKeyOptions.site = value.site;
|
|
13191
|
-
try {
|
|
13192
|
-
value.site = new import_mongodb38.ObjectId(value.site);
|
|
13193
|
-
query.site = value.site;
|
|
13194
|
-
} catch (error) {
|
|
13195
|
-
throw new import_node_server_utils67.BadRequestError("Invalid site ID format");
|
|
13196
|
-
}
|
|
13197
|
-
}
|
|
13198
|
-
const cacheKey = (0, import_node_server_utils67.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
13199
|
-
const cachedData = await getCache(cacheKey);
|
|
13200
|
-
if (cachedData) {
|
|
13201
|
-
return cachedData;
|
|
13202
|
-
}
|
|
13203
|
-
try {
|
|
13204
|
-
const items = await collection.aggregate([
|
|
13205
|
-
{
|
|
13206
|
-
$match: query
|
|
13207
|
-
},
|
|
13208
|
-
{
|
|
13209
|
-
$skip: value.page * value.limit
|
|
13210
|
-
},
|
|
13211
|
-
{
|
|
13212
|
-
$limit: value.limit
|
|
13213
|
-
},
|
|
13214
|
-
{
|
|
13215
|
-
$project: {
|
|
13216
|
-
password: 0
|
|
13217
|
-
}
|
|
13218
|
-
}
|
|
13219
|
-
]).toArray();
|
|
13220
|
-
const length = await collection.countDocuments(query);
|
|
13221
|
-
const data = (0, import_node_server_utils67.paginate)(items, value.page, value.limit, length);
|
|
13222
|
-
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
13223
|
-
import_node_server_utils67.logger.info(`Cache set for key: ${cacheKey}`);
|
|
13224
|
-
}).catch((err) => {
|
|
13225
|
-
import_node_server_utils67.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
13226
|
-
});
|
|
13227
|
-
return data;
|
|
13228
|
-
} catch (error) {
|
|
13229
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13230
|
-
throw error;
|
|
13231
|
-
}
|
|
13232
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13233
|
-
}
|
|
13234
|
-
}
|
|
13235
|
-
async function findSiteCameras({ site, type }) {
|
|
13236
|
-
const pipeline = [];
|
|
13237
|
-
const cacheObject = {};
|
|
13238
|
-
if (type) {
|
|
13239
|
-
cacheObject.type = type;
|
|
13240
|
-
pipeline.push({ $match: { "anprs.type": type } });
|
|
13241
|
-
}
|
|
13242
|
-
if (site) {
|
|
13243
|
-
const _site = new import_mongodb38.ObjectId(site);
|
|
13244
|
-
cacheObject.site = site;
|
|
13245
|
-
pipeline.push({ $match: { site: _site } });
|
|
13246
|
-
}
|
|
13247
|
-
pipeline.push({
|
|
13248
|
-
$project: {
|
|
13249
|
-
_id: 1,
|
|
13250
|
-
site: 1,
|
|
13251
|
-
cameras: 1
|
|
13252
|
-
}
|
|
13253
|
-
});
|
|
13254
|
-
try {
|
|
13255
|
-
const items = await collection.aggregate(pipeline).toArray();
|
|
13256
|
-
return items;
|
|
13257
|
-
} catch (error) {
|
|
13258
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13259
|
-
throw error;
|
|
13260
|
-
}
|
|
13261
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13262
|
-
}
|
|
13263
|
-
}
|
|
13264
|
-
function delCachedData() {
|
|
13265
|
-
delNamespace().then(() => {
|
|
13266
|
-
import_node_server_utils67.logger.log({
|
|
13267
|
-
level: "info",
|
|
13268
|
-
message: `Cache namespace cleared for ${namespace_collection}`
|
|
13269
|
-
});
|
|
13270
|
-
}).catch((err) => {
|
|
13271
|
-
import_node_server_utils67.logger.log({
|
|
13272
|
-
level: "error",
|
|
13273
|
-
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
13274
|
-
});
|
|
13275
|
-
});
|
|
13276
|
-
}
|
|
13277
|
-
async function getBySite(site, options = {}) {
|
|
13278
|
-
const _site = (0, import_node_server_utils67.toObjectId)(site);
|
|
13279
|
-
const cacheKeyOptions = {
|
|
13280
|
-
site,
|
|
13281
|
-
tag: "get-by-site",
|
|
13282
|
-
...options.category && { category: options.category },
|
|
13283
|
-
...options.type && { type: options.type },
|
|
13284
|
-
...options.guardPost && { guardPost: options.guardPost }
|
|
13285
|
-
};
|
|
13286
|
-
const cacheKey = (0, import_node_server_utils67.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
13287
|
-
const cachedData = await getCache(cacheKey);
|
|
13288
|
-
if (cachedData) {
|
|
13289
|
-
return cachedData;
|
|
13290
|
-
}
|
|
13291
|
-
try {
|
|
13292
|
-
delete cacheKeyOptions.tag;
|
|
13293
|
-
cacheKeyOptions.site = _site;
|
|
13294
|
-
const item = await collection.findOne(cacheKeyOptions);
|
|
13295
|
-
setCache(cacheKey, item, 15 * 60).then(() => {
|
|
13296
|
-
import_node_server_utils67.logger.log({
|
|
13297
|
-
level: "info",
|
|
13298
|
-
message: `Cache set for getBySite: ${cacheKey}`
|
|
13299
|
-
});
|
|
13300
|
-
}).catch((err) => {
|
|
13301
|
-
import_node_server_utils67.logger.log({
|
|
13302
|
-
level: "error",
|
|
13303
|
-
message: `Failed to set cache for getBySite: ${err.message}`
|
|
13304
|
-
});
|
|
13305
|
-
});
|
|
13306
|
-
return item;
|
|
13307
|
-
} catch (error) {
|
|
13308
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13309
|
-
throw error;
|
|
13310
|
-
}
|
|
13311
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13312
|
-
}
|
|
13313
|
-
}
|
|
13314
|
-
async function getBySiteGuardPost(site, guardPost) {
|
|
13315
|
-
try {
|
|
13316
|
-
site = new import_mongodb38.ObjectId(site);
|
|
13317
|
-
} catch (error) {
|
|
13318
|
-
throw new import_node_server_utils67.BadRequestError("Invalid site ID format");
|
|
13319
|
-
}
|
|
13320
|
-
const cacheKeyOptions = {
|
|
13321
|
-
site,
|
|
13322
|
-
guardPost,
|
|
13323
|
-
tag: "get-by-site"
|
|
13324
|
-
};
|
|
13325
|
-
const cacheKey = (0, import_node_server_utils67.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
13326
|
-
const cachedData = await getCache(cacheKey);
|
|
13327
|
-
if (cachedData) {
|
|
13328
|
-
return cachedData;
|
|
13329
|
-
}
|
|
13330
|
-
try {
|
|
13331
|
-
delete cacheKeyOptions.tag;
|
|
13332
|
-
const item = await collection.findOne({
|
|
13333
|
-
site,
|
|
13334
|
-
guardPost: { $gt: guardPost }
|
|
13335
|
-
});
|
|
13336
|
-
setCache(cacheKey, item, 15 * 60).then(() => {
|
|
13337
|
-
import_node_server_utils67.logger.log({
|
|
13338
|
-
level: "info",
|
|
13339
|
-
message: `Cache set for getBySite: ${cacheKey}`
|
|
13340
|
-
});
|
|
13341
|
-
}).catch((err) => {
|
|
13342
|
-
import_node_server_utils67.logger.log({
|
|
13343
|
-
level: "error",
|
|
13344
|
-
message: `Failed to set cache for getBySite: ${err.message}`
|
|
13345
|
-
});
|
|
13346
|
-
});
|
|
13347
|
-
return item;
|
|
13348
|
-
} catch (error) {
|
|
13349
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13350
|
-
throw error;
|
|
13351
|
-
}
|
|
13352
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13353
|
-
}
|
|
13354
|
-
}
|
|
13355
|
-
async function getBySites(site, options = {}) {
|
|
13356
|
-
try {
|
|
13357
|
-
site = new import_mongodb38.ObjectId(site);
|
|
13358
|
-
} catch (error) {
|
|
13359
|
-
throw new import_node_server_utils67.BadRequestError("Invalid site ID format");
|
|
13360
|
-
}
|
|
13361
|
-
const cacheKeyOptions = { site };
|
|
13362
|
-
if (options.category) {
|
|
13363
|
-
cacheKeyOptions.category = options.category;
|
|
13364
|
-
}
|
|
13365
|
-
if (options.type) {
|
|
13366
|
-
cacheKeyOptions.type = options.type;
|
|
13367
|
-
}
|
|
13368
|
-
if (options.direction) {
|
|
13369
|
-
cacheKeyOptions.direction = options.direction;
|
|
13370
|
-
}
|
|
13371
|
-
const cacheKey = (0, import_node_server_utils67.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
13372
|
-
const cachedData = await getCache(cacheKey);
|
|
13373
|
-
if (cachedData) {
|
|
13374
|
-
return cachedData;
|
|
13375
|
-
}
|
|
13376
|
-
try {
|
|
13377
|
-
const items = await collection.find(cacheKeyOptions);
|
|
13378
|
-
setCache(cacheKey, items, 15 * 60).then(() => {
|
|
13379
|
-
import_node_server_utils67.logger.log({
|
|
13380
|
-
level: "info",
|
|
13381
|
-
message: `Cache set for getBySite: ${cacheKey}`
|
|
13382
|
-
});
|
|
13383
|
-
}).catch((err) => {
|
|
13384
|
-
import_node_server_utils67.logger.log({
|
|
13385
|
-
level: "error",
|
|
13386
|
-
message: `Failed to set cache for getBySite: ${err.message}`
|
|
13387
|
-
});
|
|
13388
|
-
});
|
|
13389
|
-
return items;
|
|
13390
|
-
} catch (error) {
|
|
13391
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13392
|
-
throw error;
|
|
13393
|
-
}
|
|
13394
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13395
|
-
}
|
|
13396
|
-
}
|
|
13397
|
-
async function updateById(_id, value, session) {
|
|
13398
|
-
const { error } = schemaUpdateSiteCamera.validate(value);
|
|
13399
|
-
if (error) {
|
|
13400
|
-
import_node_server_utils67.logger.info(`Site Camera Management: ${error.message}`);
|
|
13401
|
-
throw new import_node_server_utils67.BadRequestError(error.message);
|
|
13402
|
-
}
|
|
13403
|
-
try {
|
|
13404
|
-
_id = new import_mongodb38.ObjectId(_id);
|
|
13405
|
-
} catch (error2) {
|
|
13406
|
-
throw new import_node_server_utils67.BadRequestError("Invalid camera ID format");
|
|
13407
|
-
}
|
|
13408
|
-
try {
|
|
13409
|
-
await collection.updateOne({ _id }, { $set: value }, { session });
|
|
13410
|
-
delCachedData();
|
|
13411
|
-
return "Successfully updated site camera.";
|
|
13412
|
-
} catch (error2) {
|
|
13413
|
-
import_node_server_utils67.logger.log({
|
|
13414
|
-
level: "error",
|
|
13415
|
-
message: error2.message
|
|
13416
|
-
});
|
|
13417
|
-
const isDuplicated = error2.message.includes("duplicate");
|
|
13418
|
-
if (isDuplicated) {
|
|
13419
|
-
throw new import_node_server_utils67.BadRequestError("ANPR already exist.");
|
|
13420
|
-
}
|
|
13421
|
-
if (error2 instanceof import_node_server_utils67.AppError) {
|
|
13422
|
-
throw error2;
|
|
13423
|
-
}
|
|
13424
|
-
throw new Error("Failed to update ANPR.");
|
|
13425
|
-
}
|
|
13426
|
-
}
|
|
13427
|
-
async function deleteById(_id, session) {
|
|
13428
|
-
try {
|
|
13429
|
-
_id = new import_mongodb38.ObjectId(_id);
|
|
13430
|
-
} catch (error) {
|
|
13431
|
-
throw new import_node_server_utils67.BadRequestError("Invalid camera ID format");
|
|
13432
|
-
}
|
|
13433
|
-
try {
|
|
13434
|
-
await collection.deleteOne({ _id }, { session });
|
|
13435
|
-
delCachedData();
|
|
13436
|
-
return "Successfully deleted site camera.";
|
|
13437
|
-
} catch (error) {
|
|
13438
|
-
import_node_server_utils67.logger.log({
|
|
13439
|
-
level: "error",
|
|
13440
|
-
message: error.message
|
|
13441
|
-
});
|
|
13442
|
-
if (error instanceof import_node_server_utils67.AppError) {
|
|
13443
|
-
throw error;
|
|
13444
|
-
}
|
|
13445
|
-
throw new Error("Failed to delete site camera.");
|
|
13446
|
-
}
|
|
13447
|
-
}
|
|
13448
|
-
async function getAllCameraWithPassword(value) {
|
|
13449
|
-
value.page = value.page ? value.page - 1 : 0;
|
|
13450
|
-
value.limit = value.limit || 10;
|
|
13451
|
-
const query = {
|
|
13452
|
-
type: value.type,
|
|
13453
|
-
...value.direction && {
|
|
13454
|
-
direction: {
|
|
13455
|
-
$in: Array.isArray(value.direction) ? value.direction : [value.direction]
|
|
13456
|
-
}
|
|
13457
|
-
}
|
|
13458
|
-
};
|
|
13459
|
-
if (value.site) {
|
|
13460
|
-
try {
|
|
13461
|
-
value.site = new import_mongodb38.ObjectId(value.site);
|
|
13462
|
-
query.site = value.site;
|
|
13463
|
-
} catch (error) {
|
|
13464
|
-
throw new import_node_server_utils67.BadRequestError("Invalid site ID format");
|
|
13465
|
-
}
|
|
13466
|
-
}
|
|
13467
|
-
try {
|
|
13468
|
-
const items = await collection.aggregate([
|
|
13469
|
-
{
|
|
13470
|
-
$match: query
|
|
13471
|
-
},
|
|
13472
|
-
{
|
|
13473
|
-
$skip: value.page * value.limit
|
|
13474
|
-
},
|
|
13475
|
-
{
|
|
13476
|
-
$limit: value.limit
|
|
13477
|
-
}
|
|
13478
|
-
]).toArray();
|
|
13479
|
-
const length = await collection.countDocuments(query);
|
|
13480
|
-
const data = (0, import_node_server_utils67.paginate)(items, value.page, value.limit, length);
|
|
13481
|
-
return data;
|
|
13482
|
-
} catch (error) {
|
|
13483
|
-
if (error instanceof import_node_server_utils67.BadRequestError) {
|
|
13484
|
-
throw error;
|
|
13485
|
-
}
|
|
13486
|
-
throw new import_node_server_utils67.BadRequestError("Failed to retrieve site cameras.");
|
|
13487
|
-
}
|
|
13488
|
-
}
|
|
13489
|
-
return {
|
|
13490
|
-
createIndexes,
|
|
13491
|
-
add,
|
|
13492
|
-
getAll,
|
|
13493
|
-
findSiteCameras,
|
|
13494
|
-
getBySite,
|
|
13495
|
-
getBySites,
|
|
13496
|
-
delCachedData,
|
|
13497
|
-
getBySiteGuardPost,
|
|
13498
|
-
updateById,
|
|
13499
|
-
deleteById,
|
|
13500
|
-
getAllCameraWithPassword
|
|
13501
|
-
};
|
|
13502
|
-
}
|
|
13269
|
+
var import_mongodb47 = require("mongodb");
|
|
13503
13270
|
|
|
13504
|
-
// src/services/
|
|
13505
|
-
var
|
|
13271
|
+
// src/services/dahua.service.ts
|
|
13272
|
+
var import_node_server_utils75 = require("@7365admin1/node-server-utils");
|
|
13273
|
+
var import_fs = require("fs");
|
|
13274
|
+
var import_joi40 = __toESM(require("joi"));
|
|
13275
|
+
var path = __toESM(require("path"));
|
|
13276
|
+
var import_urllib = require("urllib");
|
|
13506
13277
|
|
|
13507
13278
|
// src/repositories/visitor-transaction.repo.ts
|
|
13508
|
-
var
|
|
13279
|
+
var import_node_server_utils68 = require("@7365admin1/node-server-utils");
|
|
13509
13280
|
|
|
13510
13281
|
// src/models/visitor-transactions.model.ts
|
|
13511
13282
|
var import_joi36 = __toESM(require("joi"));
|
|
13512
|
-
var
|
|
13283
|
+
var import_mongodb39 = require("mongodb");
|
|
13513
13284
|
|
|
13514
13285
|
// src/models/person.model.ts
|
|
13515
|
-
var
|
|
13286
|
+
var import_node_server_utils67 = require("@7365admin1/node-server-utils");
|
|
13516
13287
|
var import_joi35 = __toESM(require("joi"));
|
|
13517
|
-
var
|
|
13288
|
+
var import_mongodb38 = require("mongodb");
|
|
13518
13289
|
var PersonTypes = /* @__PURE__ */ ((PersonTypes3) => {
|
|
13519
13290
|
PersonTypes3["WALK_IN"] = "walk-in";
|
|
13520
13291
|
PersonTypes3["DROP_OFF"] = "drop-off";
|
|
@@ -13607,25 +13378,25 @@ var schemaUpdatePerson = import_joi35.default.object({
|
|
|
13607
13378
|
function MPerson(value) {
|
|
13608
13379
|
const { error } = schemaPerson.validate(value);
|
|
13609
13380
|
if (error) {
|
|
13610
|
-
throw new
|
|
13381
|
+
throw new import_node_server_utils67.BadRequestError(error.details[0].message);
|
|
13611
13382
|
}
|
|
13612
13383
|
if (value._id && typeof value._id === "string") {
|
|
13613
13384
|
try {
|
|
13614
|
-
value._id = new
|
|
13385
|
+
value._id = new import_mongodb38.ObjectId(value._id);
|
|
13615
13386
|
} catch (error2) {
|
|
13616
13387
|
throw new Error("Invalid ID.");
|
|
13617
13388
|
}
|
|
13618
13389
|
}
|
|
13619
13390
|
if (value.org && typeof value.org === "string") {
|
|
13620
13391
|
try {
|
|
13621
|
-
value.org = new
|
|
13392
|
+
value.org = new import_mongodb38.ObjectId(value.org);
|
|
13622
13393
|
} catch (error2) {
|
|
13623
13394
|
throw new Error("Invalid org ID.");
|
|
13624
13395
|
}
|
|
13625
13396
|
}
|
|
13626
13397
|
if (value.site && typeof value.site === "string") {
|
|
13627
13398
|
try {
|
|
13628
|
-
value.site = new
|
|
13399
|
+
value.site = new import_mongodb38.ObjectId(value.site);
|
|
13629
13400
|
} catch (error2) {
|
|
13630
13401
|
throw new Error("Invalid site ID.");
|
|
13631
13402
|
}
|
|
@@ -13634,9 +13405,9 @@ function MPerson(value) {
|
|
|
13634
13405
|
value.files = value.files.map((file) => {
|
|
13635
13406
|
if (file.id && typeof file.id === "string") {
|
|
13636
13407
|
try {
|
|
13637
|
-
file.id = new
|
|
13408
|
+
file.id = new import_mongodb38.ObjectId(file.id);
|
|
13638
13409
|
} catch {
|
|
13639
|
-
throw new
|
|
13410
|
+
throw new import_node_server_utils67.BadRequestError("Invalid file id format");
|
|
13640
13411
|
}
|
|
13641
13412
|
}
|
|
13642
13413
|
return file;
|
|
@@ -13644,7 +13415,7 @@ function MPerson(value) {
|
|
|
13644
13415
|
}
|
|
13645
13416
|
if (value.user && typeof value.user === "string") {
|
|
13646
13417
|
try {
|
|
13647
|
-
value.user = new
|
|
13418
|
+
value.user = new import_mongodb38.ObjectId(value.user);
|
|
13648
13419
|
} catch (error2) {
|
|
13649
13420
|
throw new Error("Invalid user ID.");
|
|
13650
13421
|
}
|
|
@@ -13814,28 +13585,28 @@ function MVisitorTransaction(value) {
|
|
|
13814
13585
|
}
|
|
13815
13586
|
if (value._id && typeof value._id === "string") {
|
|
13816
13587
|
try {
|
|
13817
|
-
value._id = new
|
|
13588
|
+
value._id = new import_mongodb39.ObjectId(value._id);
|
|
13818
13589
|
} catch (error2) {
|
|
13819
13590
|
throw new Error("Invalid ID.");
|
|
13820
13591
|
}
|
|
13821
13592
|
}
|
|
13822
13593
|
if (value.org && typeof value.org === "string") {
|
|
13823
13594
|
try {
|
|
13824
|
-
value.org = new
|
|
13595
|
+
value.org = new import_mongodb39.ObjectId(value.org);
|
|
13825
13596
|
} catch (error2) {
|
|
13826
13597
|
throw new Error("Invalid org ID.");
|
|
13827
13598
|
}
|
|
13828
13599
|
}
|
|
13829
13600
|
if (value.site && typeof value.site === "string") {
|
|
13830
13601
|
try {
|
|
13831
|
-
value.site = new
|
|
13602
|
+
value.site = new import_mongodb39.ObjectId(value.site);
|
|
13832
13603
|
} catch (error2) {
|
|
13833
13604
|
throw new Error("Invalid site ID.");
|
|
13834
13605
|
}
|
|
13835
13606
|
}
|
|
13836
13607
|
if (value.unit && typeof value.unit === "string") {
|
|
13837
13608
|
try {
|
|
13838
|
-
value.unit = new
|
|
13609
|
+
value.unit = new import_mongodb39.ObjectId(value.unit);
|
|
13839
13610
|
} catch (error2) {
|
|
13840
13611
|
throw new Error("Invalid unit ID.");
|
|
13841
13612
|
}
|
|
@@ -13850,9 +13621,9 @@ function MVisitorTransaction(value) {
|
|
|
13850
13621
|
if (value.visitorPass && Array.isArray(value.visitorPass) && value.visitorPass.length > 0) {
|
|
13851
13622
|
value.visitorPass = value.visitorPass.map((v) => {
|
|
13852
13623
|
if (typeof v === "string")
|
|
13853
|
-
return { keyId: new
|
|
13624
|
+
return { keyId: new import_mongodb39.ObjectId(v) };
|
|
13854
13625
|
if (v?.keyId && typeof v.keyId === "string") {
|
|
13855
|
-
return { keyId: new
|
|
13626
|
+
return { keyId: new import_mongodb39.ObjectId(v.keyId) };
|
|
13856
13627
|
}
|
|
13857
13628
|
return v;
|
|
13858
13629
|
});
|
|
@@ -13860,16 +13631,16 @@ function MVisitorTransaction(value) {
|
|
|
13860
13631
|
if (value.passKeys && Array.isArray(value.passKeys) && value.passKeys.length > 0) {
|
|
13861
13632
|
value.passKeys = value.passKeys.map((p) => {
|
|
13862
13633
|
if (typeof p === "string")
|
|
13863
|
-
return { keyId: new
|
|
13634
|
+
return { keyId: new import_mongodb39.ObjectId(p) };
|
|
13864
13635
|
if (p?.keyId && typeof p.keyId === "string") {
|
|
13865
|
-
return { keyId: new
|
|
13636
|
+
return { keyId: new import_mongodb39.ObjectId(p.keyId) };
|
|
13866
13637
|
}
|
|
13867
13638
|
return p;
|
|
13868
13639
|
});
|
|
13869
13640
|
}
|
|
13870
13641
|
if (value.inviterId && typeof value.inviterId === "string") {
|
|
13871
13642
|
try {
|
|
13872
|
-
value.inviterId = new
|
|
13643
|
+
value.inviterId = new import_mongodb39.ObjectId(value.inviterId);
|
|
13873
13644
|
} catch (error2) {
|
|
13874
13645
|
throw new Error("Invalid inviter ID.");
|
|
13875
13646
|
}
|
|
@@ -13926,12 +13697,12 @@ function MVisitorTransaction(value) {
|
|
|
13926
13697
|
}
|
|
13927
13698
|
|
|
13928
13699
|
// src/repositories/visitor-transaction.repo.ts
|
|
13929
|
-
var
|
|
13700
|
+
var import_mongodb40 = require("mongodb");
|
|
13930
13701
|
var visitors_namespace_collection = "visitor.transactions";
|
|
13931
13702
|
function useVisitorTransactionRepo() {
|
|
13932
|
-
const db =
|
|
13703
|
+
const db = import_node_server_utils68.useAtlas.getDb();
|
|
13933
13704
|
if (!db) {
|
|
13934
|
-
throw new
|
|
13705
|
+
throw new import_node_server_utils68.InternalServerError("Unable to connect to server.");
|
|
13935
13706
|
}
|
|
13936
13707
|
const collection = db.collection(visitors_namespace_collection);
|
|
13937
13708
|
async function createTextIndex() {
|
|
@@ -13945,7 +13716,7 @@ function useVisitorTransactionRepo() {
|
|
|
13945
13716
|
contact: "text"
|
|
13946
13717
|
});
|
|
13947
13718
|
} catch (error) {
|
|
13948
|
-
throw new
|
|
13719
|
+
throw new import_node_server_utils68.InternalServerError(
|
|
13949
13720
|
"Failed to create text index on visitor transaction."
|
|
13950
13721
|
);
|
|
13951
13722
|
}
|
|
@@ -13959,7 +13730,7 @@ function useVisitorTransactionRepo() {
|
|
|
13959
13730
|
console.log("Error in add visitor transaction:", error);
|
|
13960
13731
|
const isDuplicated = error.message.includes("duplicate");
|
|
13961
13732
|
if (isDuplicated) {
|
|
13962
|
-
throw new
|
|
13733
|
+
throw new import_node_server_utils68.BadRequestError("Visitor already exists.");
|
|
13963
13734
|
}
|
|
13964
13735
|
throw error;
|
|
13965
13736
|
}
|
|
@@ -13995,8 +13766,8 @@ function useVisitorTransactionRepo() {
|
|
|
13995
13766
|
expectedCheckInFilter.$lte = new Date(dateTo);
|
|
13996
13767
|
}
|
|
13997
13768
|
const query = {
|
|
13998
|
-
...
|
|
13999
|
-
...
|
|
13769
|
+
...import_mongodb40.ObjectId.isValid(org) && { org: new import_mongodb40.ObjectId(org) },
|
|
13770
|
+
...import_mongodb40.ObjectId.isValid(site) && { site: new import_mongodb40.ObjectId(site) },
|
|
14000
13771
|
...Object.keys(checkInFilter).length > 0 && { checkIn: checkInFilter },
|
|
14001
13772
|
...Object.keys(expectedCheckInFilter).length > 0 && {
|
|
14002
13773
|
expectedCheckIn: expectedCheckInFilter
|
|
@@ -14181,14 +13952,14 @@ function useVisitorTransactionRepo() {
|
|
|
14181
13952
|
collection.aggregate([...basePipeline, { $count: "total" }]).toArray()
|
|
14182
13953
|
]);
|
|
14183
13954
|
const totalCount = countResult[0]?.total || 0;
|
|
14184
|
-
const data = (0,
|
|
13955
|
+
const data = (0, import_node_server_utils68.paginate)(items, page, limit, totalCount);
|
|
14185
13956
|
return data;
|
|
14186
13957
|
} catch (error) {
|
|
14187
13958
|
throw error;
|
|
14188
13959
|
}
|
|
14189
13960
|
}
|
|
14190
13961
|
async function getVisitorTransactionById(id) {
|
|
14191
|
-
const _id = (0,
|
|
13962
|
+
const _id = (0, import_node_server_utils68.toObjectId)(id);
|
|
14192
13963
|
try {
|
|
14193
13964
|
const basePipeline = [{ $match: { _id } }];
|
|
14194
13965
|
const [result] = await collection.aggregate([
|
|
@@ -14230,7 +14001,7 @@ function useVisitorTransactionRepo() {
|
|
|
14230
14001
|
}
|
|
14231
14002
|
}
|
|
14232
14003
|
async function getOpenByPlateNumber(plateNumber, site) {
|
|
14233
|
-
const _site = typeof site === "string" ? (0,
|
|
14004
|
+
const _site = typeof site === "string" ? (0, import_node_server_utils68.toObjectId)(site) : site;
|
|
14234
14005
|
const query = {
|
|
14235
14006
|
plateNumber,
|
|
14236
14007
|
site: _site,
|
|
@@ -14240,16 +14011,16 @@ function useVisitorTransactionRepo() {
|
|
|
14240
14011
|
const data = await collection.findOne(query);
|
|
14241
14012
|
return data;
|
|
14242
14013
|
} catch (error) {
|
|
14243
|
-
throw new
|
|
14014
|
+
throw new import_node_server_utils68.InternalServerError(
|
|
14244
14015
|
"Failed to fetch visitor transaction by plate number."
|
|
14245
14016
|
);
|
|
14246
14017
|
}
|
|
14247
14018
|
}
|
|
14248
14019
|
async function updateById(_id, value, session) {
|
|
14249
14020
|
try {
|
|
14250
|
-
_id = new
|
|
14021
|
+
_id = new import_mongodb40.ObjectId(_id);
|
|
14251
14022
|
} catch (error) {
|
|
14252
|
-
throw new
|
|
14023
|
+
throw new import_node_server_utils68.BadRequestError("Invalid visitor transaction ID format.");
|
|
14253
14024
|
}
|
|
14254
14025
|
value.updatedAt = /* @__PURE__ */ new Date();
|
|
14255
14026
|
if (value.checkOut) {
|
|
@@ -14268,9 +14039,9 @@ function useVisitorTransactionRepo() {
|
|
|
14268
14039
|
}
|
|
14269
14040
|
async function deleteVisitorTransaction(_id) {
|
|
14270
14041
|
try {
|
|
14271
|
-
_id = new
|
|
14042
|
+
_id = new import_mongodb40.ObjectId(_id);
|
|
14272
14043
|
} catch (error) {
|
|
14273
|
-
throw new
|
|
14044
|
+
throw new import_node_server_utils68.BadRequestError("Invalid customer ID format.");
|
|
14274
14045
|
}
|
|
14275
14046
|
try {
|
|
14276
14047
|
const updateValue = {
|
|
@@ -14280,7 +14051,7 @@ function useVisitorTransactionRepo() {
|
|
|
14280
14051
|
};
|
|
14281
14052
|
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
14282
14053
|
if (res.modifiedCount === 0) {
|
|
14283
|
-
throw new
|
|
14054
|
+
throw new import_node_server_utils68.InternalServerError("Unable to delete visitor transaction.");
|
|
14284
14055
|
}
|
|
14285
14056
|
return res.modifiedCount;
|
|
14286
14057
|
} catch (error) {
|
|
@@ -14314,7 +14085,7 @@ function useVisitorTransactionRepo() {
|
|
|
14314
14085
|
}
|
|
14315
14086
|
}
|
|
14316
14087
|
async function getExpiredCheckedOutTransactionsBySite(siteId) {
|
|
14317
|
-
const site = (0,
|
|
14088
|
+
const site = (0, import_node_server_utils68.toObjectId)(siteId);
|
|
14318
14089
|
try {
|
|
14319
14090
|
const now = /* @__PURE__ */ new Date();
|
|
14320
14091
|
const expiredTransactions = await collection.find({
|
|
@@ -14335,7 +14106,7 @@ function useVisitorTransactionRepo() {
|
|
|
14335
14106
|
async function updateManyDahuaSyncStatus(ids, dahuaSyncStatus, session) {
|
|
14336
14107
|
try {
|
|
14337
14108
|
const objectIds = ids.map(
|
|
14338
|
-
(id) => typeof id === "string" ? new
|
|
14109
|
+
(id) => typeof id === "string" ? new import_mongodb40.ObjectId(id) : id
|
|
14339
14110
|
);
|
|
14340
14111
|
const res = await collection.updateMany(
|
|
14341
14112
|
{ _id: { $in: objectIds } },
|
|
@@ -14366,10 +14137,13 @@ function useVisitorTransactionRepo() {
|
|
|
14366
14137
|
};
|
|
14367
14138
|
}
|
|
14368
14139
|
|
|
14369
|
-
// src/
|
|
14140
|
+
// src/repositories/vehicle.repo.ts
|
|
14370
14141
|
var import_node_server_utils70 = require("@7365admin1/node-server-utils");
|
|
14142
|
+
|
|
14143
|
+
// src/models/vehicle.model.ts
|
|
14144
|
+
var import_node_server_utils69 = require("@7365admin1/node-server-utils");
|
|
14371
14145
|
var import_joi37 = __toESM(require("joi"));
|
|
14372
|
-
var
|
|
14146
|
+
var import_mongodb41 = require("mongodb");
|
|
14373
14147
|
var VehicleType = /* @__PURE__ */ ((VehicleType2) => {
|
|
14374
14148
|
VehicleType2["WHITELIST"] = "whitelist";
|
|
14375
14149
|
VehicleType2["BLOCKLIST"] = "blocklist";
|
|
@@ -14446,35 +14220,35 @@ var vehicleSchema = import_joi37.default.object({
|
|
|
14446
14220
|
function MVehicle(value) {
|
|
14447
14221
|
const { error } = vehicleSchema.validate(value);
|
|
14448
14222
|
if (error) {
|
|
14449
|
-
|
|
14450
|
-
throw new
|
|
14223
|
+
import_node_server_utils69.logger.log({ level: "error", message: error.message });
|
|
14224
|
+
throw new import_node_server_utils69.BadRequestError(error.message);
|
|
14451
14225
|
}
|
|
14452
14226
|
if (value.org) {
|
|
14453
14227
|
try {
|
|
14454
|
-
value.org = new
|
|
14228
|
+
value.org = new import_mongodb41.ObjectId(value.org);
|
|
14455
14229
|
} catch (error2) {
|
|
14456
|
-
throw new
|
|
14230
|
+
throw new import_node_server_utils69.BadRequestError("Invalid org ID format.");
|
|
14457
14231
|
}
|
|
14458
14232
|
}
|
|
14459
14233
|
if (value.site) {
|
|
14460
14234
|
try {
|
|
14461
|
-
value.site = new
|
|
14235
|
+
value.site = new import_mongodb41.ObjectId(value.site);
|
|
14462
14236
|
} catch (error2) {
|
|
14463
|
-
throw new
|
|
14237
|
+
throw new import_node_server_utils69.BadRequestError("Invalid site ID format.");
|
|
14464
14238
|
}
|
|
14465
14239
|
}
|
|
14466
14240
|
if (value.unit) {
|
|
14467
14241
|
try {
|
|
14468
|
-
value.unit = new
|
|
14242
|
+
value.unit = new import_mongodb41.ObjectId(value.unit);
|
|
14469
14243
|
} catch (error2) {
|
|
14470
|
-
throw new
|
|
14244
|
+
throw new import_node_server_utils69.BadRequestError("Invalid building unit ID format.");
|
|
14471
14245
|
}
|
|
14472
14246
|
}
|
|
14473
14247
|
if (value.peopleId) {
|
|
14474
14248
|
try {
|
|
14475
|
-
value.peopleId = new
|
|
14249
|
+
value.peopleId = new import_mongodb41.ObjectId(value.peopleId);
|
|
14476
14250
|
} catch (error2) {
|
|
14477
|
-
throw new
|
|
14251
|
+
throw new import_node_server_utils69.BadRequestError("Invalid building unit ID format.");
|
|
14478
14252
|
}
|
|
14479
14253
|
}
|
|
14480
14254
|
const createdAtDate = value.createdAt ? new Date(value.createdAt) : /* @__PURE__ */ new Date();
|
|
@@ -14522,20 +14296,20 @@ var schemaVehicleTransaction = import_joi37.default.object({
|
|
|
14522
14296
|
function MVehicleTransaction(value) {
|
|
14523
14297
|
const { error } = schemaVehicleTransaction.validate(value);
|
|
14524
14298
|
if (error) {
|
|
14525
|
-
|
|
14526
|
-
throw new
|
|
14299
|
+
import_node_server_utils69.logger.log({ level: "error", message: error.message });
|
|
14300
|
+
throw new import_node_server_utils69.BadRequestError(error.message);
|
|
14527
14301
|
}
|
|
14528
14302
|
if (value._id) {
|
|
14529
14303
|
try {
|
|
14530
|
-
value._id = new
|
|
14304
|
+
value._id = new import_mongodb41.ObjectId(value._id);
|
|
14531
14305
|
} catch (error2) {
|
|
14532
|
-
throw new
|
|
14306
|
+
throw new import_node_server_utils69.BadRequestError("Invalid ID.");
|
|
14533
14307
|
}
|
|
14534
14308
|
}
|
|
14535
14309
|
try {
|
|
14536
|
-
value.site = new
|
|
14310
|
+
value.site = new import_mongodb41.ObjectId(value.site);
|
|
14537
14311
|
} catch (error2) {
|
|
14538
|
-
throw new
|
|
14312
|
+
throw new import_node_server_utils69.BadRequestError("Invalid site ID.");
|
|
14539
14313
|
}
|
|
14540
14314
|
return {
|
|
14541
14315
|
_id: value._id,
|
|
@@ -14551,23 +14325,15 @@ function MVehicleTransaction(value) {
|
|
|
14551
14325
|
};
|
|
14552
14326
|
}
|
|
14553
14327
|
|
|
14554
|
-
// src/services/dahua.service.ts
|
|
14555
|
-
var import_node_server_utils76 = require("@7365admin1/node-server-utils");
|
|
14556
|
-
var import_fs = require("fs");
|
|
14557
|
-
var import_joi40 = __toESM(require("joi"));
|
|
14558
|
-
var path = __toESM(require("path"));
|
|
14559
|
-
var import_urllib = require("urllib");
|
|
14560
|
-
|
|
14561
14328
|
// src/repositories/vehicle.repo.ts
|
|
14562
|
-
var
|
|
14563
|
-
var import_mongodb43 = require("mongodb");
|
|
14329
|
+
var import_mongodb42 = require("mongodb");
|
|
14564
14330
|
var import_joi38 = __toESM(require("joi"));
|
|
14565
14331
|
var vehicles_namespace_collection = "vehicles";
|
|
14566
14332
|
function useVehicleRepo() {
|
|
14567
14333
|
vehicles_namespace_collection;
|
|
14568
|
-
const db =
|
|
14334
|
+
const db = import_node_server_utils70.useAtlas.getDb();
|
|
14569
14335
|
if (!db) {
|
|
14570
|
-
throw new
|
|
14336
|
+
throw new import_node_server_utils70.InternalServerError("Unable to connect to server.");
|
|
14571
14337
|
}
|
|
14572
14338
|
const collection = db.collection(vehicles_namespace_collection);
|
|
14573
14339
|
async function createIndex() {
|
|
@@ -14578,7 +14344,7 @@ function useVehicleRepo() {
|
|
|
14578
14344
|
{ key: { category: 1 } }
|
|
14579
14345
|
]);
|
|
14580
14346
|
} catch (error) {
|
|
14581
|
-
throw new
|
|
14347
|
+
throw new import_node_server_utils70.InternalServerError("Failed to create index on vehicle.");
|
|
14582
14348
|
}
|
|
14583
14349
|
}
|
|
14584
14350
|
async function createTextIndex() {
|
|
@@ -14592,7 +14358,7 @@ function useVehicleRepo() {
|
|
|
14592
14358
|
nric: "text"
|
|
14593
14359
|
});
|
|
14594
14360
|
} catch (error) {
|
|
14595
|
-
throw new
|
|
14361
|
+
throw new import_node_server_utils70.InternalServerError(
|
|
14596
14362
|
"Failed to create text index on visitor transaction."
|
|
14597
14363
|
);
|
|
14598
14364
|
}
|
|
@@ -14603,11 +14369,11 @@ function useVehicleRepo() {
|
|
|
14603
14369
|
const res = await collection.insertOne(value, { session });
|
|
14604
14370
|
return res.insertedId;
|
|
14605
14371
|
} catch (error) {
|
|
14606
|
-
|
|
14372
|
+
import_node_server_utils70.logger.log({
|
|
14607
14373
|
level: "error",
|
|
14608
14374
|
message: error.message
|
|
14609
14375
|
});
|
|
14610
|
-
if (error instanceof
|
|
14376
|
+
if (error instanceof import_node_server_utils70.AppError) {
|
|
14611
14377
|
throw error;
|
|
14612
14378
|
} else {
|
|
14613
14379
|
throw new Error("Failed to create vehicle.");
|
|
@@ -14788,7 +14554,7 @@ function useVehicleRepo() {
|
|
|
14788
14554
|
const regexCountResult = await collection.aggregate(buildGroupedCountPipeline(regexQuery)).toArray();
|
|
14789
14555
|
length = regexCountResult[0]?.total || 0;
|
|
14790
14556
|
}
|
|
14791
|
-
const data = (0,
|
|
14557
|
+
const data = (0, import_node_server_utils70.paginate)(items, page, limit, length);
|
|
14792
14558
|
return data;
|
|
14793
14559
|
} catch (error) {
|
|
14794
14560
|
throw error;
|
|
@@ -14796,9 +14562,9 @@ function useVehicleRepo() {
|
|
|
14796
14562
|
}
|
|
14797
14563
|
async function getSeasonPassTypes(site) {
|
|
14798
14564
|
try {
|
|
14799
|
-
site = new
|
|
14565
|
+
site = new import_mongodb42.ObjectId(site);
|
|
14800
14566
|
} catch (error) {
|
|
14801
|
-
throw new
|
|
14567
|
+
throw new import_node_server_utils70.BadRequestError("Invalid site ID format.");
|
|
14802
14568
|
}
|
|
14803
14569
|
try {
|
|
14804
14570
|
const categories = await collection.aggregate([
|
|
@@ -14821,17 +14587,17 @@ function useVehicleRepo() {
|
|
|
14821
14587
|
]).toArray();
|
|
14822
14588
|
return categories;
|
|
14823
14589
|
} catch (error) {
|
|
14824
|
-
if (error instanceof
|
|
14590
|
+
if (error instanceof import_node_server_utils70.BadRequestError) {
|
|
14825
14591
|
throw error;
|
|
14826
14592
|
}
|
|
14827
|
-
throw new
|
|
14593
|
+
throw new import_node_server_utils70.BadRequestError("Failed to retrieve season pass types.");
|
|
14828
14594
|
}
|
|
14829
14595
|
}
|
|
14830
14596
|
async function getVehicleById(_id) {
|
|
14831
14597
|
try {
|
|
14832
|
-
_id = new
|
|
14598
|
+
_id = new import_mongodb42.ObjectId(_id);
|
|
14833
14599
|
} catch (error) {
|
|
14834
|
-
throw new
|
|
14600
|
+
throw new import_node_server_utils70.BadRequestError("Invalid vehicle ID format.");
|
|
14835
14601
|
}
|
|
14836
14602
|
try {
|
|
14837
14603
|
const data = await collection.aggregate([
|
|
@@ -15000,7 +14766,7 @@ function useVehicleRepo() {
|
|
|
15000
14766
|
}
|
|
15001
14767
|
]).toArray();
|
|
15002
14768
|
if (!data || !data.length) {
|
|
15003
|
-
throw new
|
|
14769
|
+
throw new import_node_server_utils70.NotFoundError("Vehicle not found.");
|
|
15004
14770
|
}
|
|
15005
14771
|
const result = data[0];
|
|
15006
14772
|
return result;
|
|
@@ -15011,7 +14777,7 @@ function useVehicleRepo() {
|
|
|
15011
14777
|
async function getByPlaceNumber(value) {
|
|
15012
14778
|
const { error } = import_joi38.default.string().required().validate(value);
|
|
15013
14779
|
if (error) {
|
|
15014
|
-
throw new
|
|
14780
|
+
throw new import_node_server_utils70.BadRequestError(error.details[0].message);
|
|
15015
14781
|
}
|
|
15016
14782
|
try {
|
|
15017
14783
|
const data = await collection.findOne({
|
|
@@ -15019,7 +14785,7 @@ function useVehicleRepo() {
|
|
|
15019
14785
|
status: "active"
|
|
15020
14786
|
});
|
|
15021
14787
|
if (!data) {
|
|
15022
|
-
throw new
|
|
14788
|
+
throw new import_node_server_utils70.NotFoundError("Vehicle not found.");
|
|
15023
14789
|
}
|
|
15024
14790
|
return data;
|
|
15025
14791
|
} catch (error2) {
|
|
@@ -15028,9 +14794,9 @@ function useVehicleRepo() {
|
|
|
15028
14794
|
}
|
|
15029
14795
|
async function updateVehicleById(_id, value, session) {
|
|
15030
14796
|
try {
|
|
15031
|
-
_id = new
|
|
14797
|
+
_id = new import_mongodb42.ObjectId(_id);
|
|
15032
14798
|
} catch (error) {
|
|
15033
|
-
throw new
|
|
14799
|
+
throw new import_node_server_utils70.BadRequestError("Invalid vehicle ID format.");
|
|
15034
14800
|
}
|
|
15035
14801
|
try {
|
|
15036
14802
|
const updateValue = {
|
|
@@ -15043,7 +14809,7 @@ function useVehicleRepo() {
|
|
|
15043
14809
|
{ session }
|
|
15044
14810
|
);
|
|
15045
14811
|
if (res.modifiedCount === 0) {
|
|
15046
|
-
throw new
|
|
14812
|
+
throw new import_node_server_utils70.InternalServerError("Unable to update vehicle.");
|
|
15047
14813
|
}
|
|
15048
14814
|
return res.modifiedCount;
|
|
15049
14815
|
} catch (error) {
|
|
@@ -15052,9 +14818,9 @@ function useVehicleRepo() {
|
|
|
15052
14818
|
}
|
|
15053
14819
|
async function deleteVehicle(_id, session) {
|
|
15054
14820
|
try {
|
|
15055
|
-
_id = new
|
|
14821
|
+
_id = new import_mongodb42.ObjectId(_id);
|
|
15056
14822
|
} catch (error) {
|
|
15057
|
-
throw new
|
|
14823
|
+
throw new import_node_server_utils70.BadRequestError("Invalid vehicle ID format.");
|
|
15058
14824
|
}
|
|
15059
14825
|
try {
|
|
15060
14826
|
const updateValue = {
|
|
@@ -15067,7 +14833,7 @@ function useVehicleRepo() {
|
|
|
15067
14833
|
{ session }
|
|
15068
14834
|
);
|
|
15069
14835
|
if (res.modifiedCount === 0)
|
|
15070
|
-
throw new
|
|
14836
|
+
throw new import_node_server_utils70.InternalServerError("Unable to delete vehicle.");
|
|
15071
14837
|
return res.modifiedCount;
|
|
15072
14838
|
} catch (error) {
|
|
15073
14839
|
throw error;
|
|
@@ -15076,7 +14842,7 @@ function useVehicleRepo() {
|
|
|
15076
14842
|
async function getVehicleByPlateNumber(plateNumber) {
|
|
15077
14843
|
const { error } = import_joi38.default.string().required().validate(plateNumber);
|
|
15078
14844
|
if (error) {
|
|
15079
|
-
throw new
|
|
14845
|
+
throw new import_node_server_utils70.BadRequestError(error.details[0].message);
|
|
15080
14846
|
}
|
|
15081
14847
|
try {
|
|
15082
14848
|
const data = await collection.findOne(
|
|
@@ -15085,7 +14851,7 @@ function useVehicleRepo() {
|
|
|
15085
14851
|
);
|
|
15086
14852
|
return data;
|
|
15087
14853
|
} catch (error2) {
|
|
15088
|
-
throw new
|
|
14854
|
+
throw new import_node_server_utils70.InternalServerError(
|
|
15089
14855
|
"Failed to fetch individual by plate number."
|
|
15090
14856
|
);
|
|
15091
14857
|
}
|
|
@@ -15098,7 +14864,7 @@ function useVehicleRepo() {
|
|
|
15098
14864
|
}) {
|
|
15099
14865
|
page = page > 0 ? page - 1 : 0;
|
|
15100
14866
|
if (!nric) {
|
|
15101
|
-
throw new
|
|
14867
|
+
throw new import_node_server_utils70.BadRequestError("NRIC is required.");
|
|
15102
14868
|
}
|
|
15103
14869
|
const _nric = nric.trim();
|
|
15104
14870
|
const query = {
|
|
@@ -15125,7 +14891,7 @@ function useVehicleRepo() {
|
|
|
15125
14891
|
}
|
|
15126
14892
|
]).toArray();
|
|
15127
14893
|
const length = await collection.countDocuments(query);
|
|
15128
|
-
const data = (0,
|
|
14894
|
+
const data = (0, import_node_server_utils70.paginate)(items, page, limit, length);
|
|
15129
14895
|
return data;
|
|
15130
14896
|
} catch (error) {
|
|
15131
14897
|
throw error;
|
|
@@ -15157,7 +14923,7 @@ function useVehicleRepo() {
|
|
|
15157
14923
|
page = page > 0 ? page - 1 : 0;
|
|
15158
14924
|
const skip = page * limit;
|
|
15159
14925
|
try {
|
|
15160
|
-
const unit = (0,
|
|
14926
|
+
const unit = (0, import_node_server_utils70.toObjectId)(unitId);
|
|
15161
14927
|
const query = {
|
|
15162
14928
|
unit
|
|
15163
14929
|
};
|
|
@@ -15172,7 +14938,7 @@ function useVehicleRepo() {
|
|
|
15172
14938
|
limit
|
|
15173
14939
|
}).toArray();
|
|
15174
14940
|
const length = await collection.countDocuments(query);
|
|
15175
|
-
const data = (0,
|
|
14941
|
+
const data = (0, import_node_server_utils70.paginate)(items, page, limit, length);
|
|
15176
14942
|
return data;
|
|
15177
14943
|
} catch (error) {
|
|
15178
14944
|
throw error;
|
|
@@ -15208,7 +14974,7 @@ function useVehicleRepo() {
|
|
|
15208
14974
|
return {
|
|
15209
14975
|
updateOne: {
|
|
15210
14976
|
filter: {
|
|
15211
|
-
site: new
|
|
14977
|
+
site: new import_mongodb42.ObjectId(vehicle.site),
|
|
15212
14978
|
plateNumber,
|
|
15213
14979
|
$or: [
|
|
15214
14980
|
{ deletedAt: "" },
|
|
@@ -15219,9 +14985,9 @@ function useVehicleRepo() {
|
|
|
15219
14985
|
update: {
|
|
15220
14986
|
$set: {
|
|
15221
14987
|
...rest,
|
|
15222
|
-
site: new
|
|
15223
|
-
unit: vehicle.unit ? new
|
|
15224
|
-
org: vehicle.org ? new
|
|
14988
|
+
site: new import_mongodb42.ObjectId(vehicle.site),
|
|
14989
|
+
unit: vehicle.unit ? new import_mongodb42.ObjectId(vehicle.unit) : null,
|
|
14990
|
+
org: vehicle.org ? new import_mongodb42.ObjectId(vehicle.org) : null,
|
|
15225
14991
|
plateNumber,
|
|
15226
14992
|
updatedAt: now
|
|
15227
14993
|
},
|
|
@@ -15241,11 +15007,11 @@ function useVehicleRepo() {
|
|
|
15241
15007
|
upsertedIds: res.upsertedIds
|
|
15242
15008
|
};
|
|
15243
15009
|
} catch (error) {
|
|
15244
|
-
|
|
15010
|
+
import_node_server_utils70.logger.log({
|
|
15245
15011
|
level: "error",
|
|
15246
15012
|
message: error.message
|
|
15247
15013
|
});
|
|
15248
|
-
if (error instanceof
|
|
15014
|
+
if (error instanceof import_node_server_utils70.AppError) {
|
|
15249
15015
|
throw error;
|
|
15250
15016
|
}
|
|
15251
15017
|
throw new Error("Failed to bulk upsert vehicles.");
|
|
@@ -15271,19 +15037,19 @@ function useVehicleRepo() {
|
|
|
15271
15037
|
}
|
|
15272
15038
|
|
|
15273
15039
|
// src/services/vehicle.service.ts
|
|
15274
|
-
var
|
|
15040
|
+
var import_node_server_utils74 = require("@7365admin1/node-server-utils");
|
|
15275
15041
|
|
|
15276
15042
|
// src/repositories/person.repo.ts
|
|
15277
|
-
var
|
|
15278
|
-
var
|
|
15043
|
+
var import_node_server_utils71 = require("@7365admin1/node-server-utils");
|
|
15044
|
+
var import_mongodb43 = require("mongodb");
|
|
15279
15045
|
var site_people_namespace_collection = "site.people";
|
|
15280
15046
|
function usePersonRepo() {
|
|
15281
|
-
const db =
|
|
15047
|
+
const db = import_node_server_utils71.useAtlas.getDb();
|
|
15282
15048
|
if (!db) {
|
|
15283
|
-
throw new
|
|
15049
|
+
throw new import_node_server_utils71.InternalServerError("Unable to connect to server.");
|
|
15284
15050
|
}
|
|
15285
15051
|
const collection = db.collection(site_people_namespace_collection);
|
|
15286
|
-
const { delNamespace, getCache, setCache } = (0,
|
|
15052
|
+
const { delNamespace, getCache, setCache } = (0, import_node_server_utils71.useCache)(
|
|
15287
15053
|
site_people_namespace_collection
|
|
15288
15054
|
);
|
|
15289
15055
|
async function createIndexes() {
|
|
@@ -15293,7 +15059,7 @@ function usePersonRepo() {
|
|
|
15293
15059
|
{ key: { nric: 1 } }
|
|
15294
15060
|
]);
|
|
15295
15061
|
} catch (error) {
|
|
15296
|
-
throw new
|
|
15062
|
+
throw new import_node_server_utils71.InternalServerError("Failed to create index on site people.");
|
|
15297
15063
|
}
|
|
15298
15064
|
}
|
|
15299
15065
|
async function createTextIndex() {
|
|
@@ -15307,7 +15073,7 @@ function usePersonRepo() {
|
|
|
15307
15073
|
contact: "text"
|
|
15308
15074
|
});
|
|
15309
15075
|
} catch (error) {
|
|
15310
|
-
throw new
|
|
15076
|
+
throw new import_node_server_utils71.InternalServerError(
|
|
15311
15077
|
"Failed to create text index on site people."
|
|
15312
15078
|
);
|
|
15313
15079
|
}
|
|
@@ -15317,11 +15083,11 @@ function usePersonRepo() {
|
|
|
15317
15083
|
value = MPerson(value);
|
|
15318
15084
|
const res = await collection.insertOne(value, { session });
|
|
15319
15085
|
delNamespace().then(() => {
|
|
15320
|
-
|
|
15086
|
+
import_node_server_utils71.logger.info(
|
|
15321
15087
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
15322
15088
|
);
|
|
15323
15089
|
}).catch((err) => {
|
|
15324
|
-
|
|
15090
|
+
import_node_server_utils71.logger.error(
|
|
15325
15091
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
15326
15092
|
err
|
|
15327
15093
|
);
|
|
@@ -15330,7 +15096,7 @@ function usePersonRepo() {
|
|
|
15330
15096
|
} catch (error) {
|
|
15331
15097
|
const isDuplicated = error.message.includes("duplicate");
|
|
15332
15098
|
if (isDuplicated) {
|
|
15333
|
-
throw new
|
|
15099
|
+
throw new import_node_server_utils71.BadRequestError("Person already exists.");
|
|
15334
15100
|
}
|
|
15335
15101
|
throw error;
|
|
15336
15102
|
}
|
|
@@ -15367,8 +15133,8 @@ function usePersonRepo() {
|
|
|
15367
15133
|
{ "plates.plateNumber": { $regex: search, $options: "i" } }
|
|
15368
15134
|
]
|
|
15369
15135
|
},
|
|
15370
|
-
...
|
|
15371
|
-
...
|
|
15136
|
+
...import_mongodb43.ObjectId.isValid(org) && { org: new import_mongodb43.ObjectId(org) },
|
|
15137
|
+
...import_mongodb43.ObjectId.isValid(site) && { site: new import_mongodb43.ObjectId(site) },
|
|
15372
15138
|
...PERSON_TYPES.includes(type) && { type }
|
|
15373
15139
|
};
|
|
15374
15140
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
@@ -15384,13 +15150,13 @@ function usePersonRepo() {
|
|
|
15384
15150
|
...query.site && { site: query.site.toString() },
|
|
15385
15151
|
...PERSON_TYPES.includes(type) && { type }
|
|
15386
15152
|
};
|
|
15387
|
-
const cacheKey = (0,
|
|
15153
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(
|
|
15388
15154
|
site_people_namespace_collection,
|
|
15389
15155
|
cacheOptions
|
|
15390
15156
|
);
|
|
15391
15157
|
const cachedData = await getCache(cacheKey);
|
|
15392
15158
|
if (cachedData) {
|
|
15393
|
-
|
|
15159
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15394
15160
|
return cachedData;
|
|
15395
15161
|
}
|
|
15396
15162
|
try {
|
|
@@ -15422,9 +15188,9 @@ function usePersonRepo() {
|
|
|
15422
15188
|
collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
|
|
15423
15189
|
]);
|
|
15424
15190
|
const totalCount = countResult[0]?.total || 0;
|
|
15425
|
-
const data = (0,
|
|
15426
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
15427
|
-
(err) =>
|
|
15191
|
+
const data = (0, import_node_server_utils71.paginate)(items, page, limit, totalCount);
|
|
15192
|
+
setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
15193
|
+
(err) => import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
15428
15194
|
);
|
|
15429
15195
|
return data;
|
|
15430
15196
|
} catch (error) {
|
|
@@ -15433,9 +15199,9 @@ function usePersonRepo() {
|
|
|
15433
15199
|
}
|
|
15434
15200
|
async function updateById(_id, value, session) {
|
|
15435
15201
|
try {
|
|
15436
|
-
_id = new
|
|
15202
|
+
_id = new import_mongodb43.ObjectId(_id);
|
|
15437
15203
|
} catch (error) {
|
|
15438
|
-
throw new
|
|
15204
|
+
throw new import_node_server_utils71.BadRequestError("Invalid person transaction ID format.");
|
|
15439
15205
|
}
|
|
15440
15206
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
15441
15207
|
try {
|
|
@@ -15445,11 +15211,11 @@ function usePersonRepo() {
|
|
|
15445
15211
|
{ session }
|
|
15446
15212
|
);
|
|
15447
15213
|
delNamespace().then(() => {
|
|
15448
|
-
|
|
15214
|
+
import_node_server_utils71.logger.info(
|
|
15449
15215
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
15450
15216
|
);
|
|
15451
15217
|
}).catch((err) => {
|
|
15452
|
-
|
|
15218
|
+
import_node_server_utils71.logger.error(
|
|
15453
15219
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
15454
15220
|
err
|
|
15455
15221
|
);
|
|
@@ -15461,9 +15227,9 @@ function usePersonRepo() {
|
|
|
15461
15227
|
}
|
|
15462
15228
|
async function deleteById(_id) {
|
|
15463
15229
|
try {
|
|
15464
|
-
_id = new
|
|
15230
|
+
_id = new import_mongodb43.ObjectId(_id);
|
|
15465
15231
|
} catch (error) {
|
|
15466
|
-
throw new
|
|
15232
|
+
throw new import_node_server_utils71.BadRequestError("Invalid customer ID format.");
|
|
15467
15233
|
}
|
|
15468
15234
|
try {
|
|
15469
15235
|
const updateValue = {
|
|
@@ -15473,14 +15239,14 @@ function usePersonRepo() {
|
|
|
15473
15239
|
};
|
|
15474
15240
|
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
15475
15241
|
if (res.modifiedCount === 0) {
|
|
15476
|
-
throw new
|
|
15242
|
+
throw new import_node_server_utils71.InternalServerError("Unable to delete visitor transaction.");
|
|
15477
15243
|
}
|
|
15478
15244
|
delNamespace().then(() => {
|
|
15479
|
-
|
|
15245
|
+
import_node_server_utils71.logger.info(
|
|
15480
15246
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
15481
15247
|
);
|
|
15482
15248
|
}).catch((err) => {
|
|
15483
|
-
|
|
15249
|
+
import_node_server_utils71.logger.error(
|
|
15484
15250
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
15485
15251
|
err
|
|
15486
15252
|
);
|
|
@@ -15492,17 +15258,17 @@ function usePersonRepo() {
|
|
|
15492
15258
|
}
|
|
15493
15259
|
async function getById(_id) {
|
|
15494
15260
|
try {
|
|
15495
|
-
_id = new
|
|
15261
|
+
_id = new import_mongodb43.ObjectId(_id);
|
|
15496
15262
|
} catch (error) {
|
|
15497
|
-
throw new
|
|
15263
|
+
throw new import_node_server_utils71.BadRequestError("Invalid person ID.");
|
|
15498
15264
|
}
|
|
15499
|
-
const cacheKey = (0,
|
|
15265
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15500
15266
|
_id: String(_id)
|
|
15501
15267
|
});
|
|
15502
15268
|
try {
|
|
15503
15269
|
const cached = await getCache(cacheKey);
|
|
15504
15270
|
if (cached) {
|
|
15505
|
-
|
|
15271
|
+
import_node_server_utils71.logger.log({
|
|
15506
15272
|
level: "info",
|
|
15507
15273
|
message: `Cache hit for getById person: ${cacheKey}`
|
|
15508
15274
|
});
|
|
@@ -15512,34 +15278,34 @@ function usePersonRepo() {
|
|
|
15512
15278
|
_id
|
|
15513
15279
|
});
|
|
15514
15280
|
setCache(cacheKey, result, 300).then(() => {
|
|
15515
|
-
|
|
15281
|
+
import_node_server_utils71.logger.log({
|
|
15516
15282
|
level: "info",
|
|
15517
15283
|
message: `Cache set for person by id: ${cacheKey}`
|
|
15518
15284
|
});
|
|
15519
15285
|
}).catch((err) => {
|
|
15520
|
-
|
|
15286
|
+
import_node_server_utils71.logger.log({
|
|
15521
15287
|
level: "error",
|
|
15522
15288
|
message: `Failed to set cache for person by id: ${err.message}`
|
|
15523
15289
|
});
|
|
15524
15290
|
});
|
|
15525
15291
|
return result;
|
|
15526
15292
|
} catch (error) {
|
|
15527
|
-
if (error instanceof
|
|
15293
|
+
if (error instanceof import_node_server_utils71.AppError) {
|
|
15528
15294
|
throw error;
|
|
15529
15295
|
} else {
|
|
15530
|
-
throw new
|
|
15296
|
+
throw new import_node_server_utils71.InternalServerError("Failed to get person by id.");
|
|
15531
15297
|
}
|
|
15532
15298
|
}
|
|
15533
15299
|
}
|
|
15534
15300
|
async function getPersonByPlateNumber(plateNumber) {
|
|
15535
|
-
const cacheKey = (0,
|
|
15301
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15536
15302
|
plateNumber,
|
|
15537
15303
|
key: "get-person-plate-number"
|
|
15538
15304
|
});
|
|
15539
15305
|
try {
|
|
15540
15306
|
const cacheData = await getCache(cacheKey);
|
|
15541
15307
|
if (cacheData) {
|
|
15542
|
-
|
|
15308
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15543
15309
|
return cacheData;
|
|
15544
15310
|
}
|
|
15545
15311
|
const data = await collection.findOne(
|
|
@@ -15547,57 +15313,57 @@ function usePersonRepo() {
|
|
|
15547
15313
|
{ sort: { _id: -1 } }
|
|
15548
15314
|
);
|
|
15549
15315
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15550
|
-
|
|
15316
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15551
15317
|
}).catch((err) => {
|
|
15552
|
-
|
|
15318
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15553
15319
|
});
|
|
15554
15320
|
return data;
|
|
15555
15321
|
} catch (error) {
|
|
15556
|
-
throw new
|
|
15322
|
+
throw new import_node_server_utils71.InternalServerError(
|
|
15557
15323
|
"Failed to fetch individual by plate number."
|
|
15558
15324
|
);
|
|
15559
15325
|
}
|
|
15560
15326
|
}
|
|
15561
15327
|
async function getByNRIC(value) {
|
|
15562
15328
|
try {
|
|
15563
|
-
const cacheKey = (0,
|
|
15329
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15564
15330
|
nric: value
|
|
15565
15331
|
});
|
|
15566
15332
|
const cachedData = await getCache(cacheKey);
|
|
15567
15333
|
if (cachedData) {
|
|
15568
|
-
|
|
15334
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15569
15335
|
return cachedData;
|
|
15570
15336
|
}
|
|
15571
15337
|
const data = await collection.findOne({ nric: value });
|
|
15572
15338
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15573
|
-
|
|
15339
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15574
15340
|
}).catch((err) => {
|
|
15575
|
-
|
|
15341
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15576
15342
|
});
|
|
15577
15343
|
return data;
|
|
15578
15344
|
} catch (error) {
|
|
15579
|
-
throw new
|
|
15345
|
+
throw new import_node_server_utils71.InternalServerError("Failed to retrieve person by NRIC.");
|
|
15580
15346
|
}
|
|
15581
15347
|
}
|
|
15582
15348
|
async function getPersonByPhoneNumber(value) {
|
|
15583
15349
|
try {
|
|
15584
|
-
const cacheKey = (0,
|
|
15350
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15585
15351
|
contact: value
|
|
15586
15352
|
});
|
|
15587
15353
|
const cachedData = await getCache(cacheKey);
|
|
15588
15354
|
if (cachedData) {
|
|
15589
|
-
|
|
15355
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15590
15356
|
return cachedData;
|
|
15591
15357
|
}
|
|
15592
15358
|
const data = await collection.findOne({ contact: value });
|
|
15593
15359
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15594
|
-
|
|
15360
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15595
15361
|
}).catch((err) => {
|
|
15596
|
-
|
|
15362
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15597
15363
|
});
|
|
15598
15364
|
return data;
|
|
15599
15365
|
} catch (error) {
|
|
15600
|
-
throw new
|
|
15366
|
+
throw new import_node_server_utils71.InternalServerError(
|
|
15601
15367
|
"Failed to retrieve person by Phone Number."
|
|
15602
15368
|
);
|
|
15603
15369
|
}
|
|
@@ -15607,7 +15373,7 @@ function usePersonRepo() {
|
|
|
15607
15373
|
type = [],
|
|
15608
15374
|
unit
|
|
15609
15375
|
}, session) {
|
|
15610
|
-
const cacheKey = (0,
|
|
15376
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15611
15377
|
unit: JSON.stringify(unit),
|
|
15612
15378
|
status,
|
|
15613
15379
|
type,
|
|
@@ -15615,7 +15381,7 @@ function usePersonRepo() {
|
|
|
15615
15381
|
});
|
|
15616
15382
|
const cacheData = await getCache(cacheKey);
|
|
15617
15383
|
if (cacheData) {
|
|
15618
|
-
|
|
15384
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15619
15385
|
return cacheData;
|
|
15620
15386
|
}
|
|
15621
15387
|
try {
|
|
@@ -15628,25 +15394,25 @@ function usePersonRepo() {
|
|
|
15628
15394
|
};
|
|
15629
15395
|
const data = await collection.find(query).sort({ _id: -1 }).toArray();
|
|
15630
15396
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15631
|
-
|
|
15397
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15632
15398
|
}).catch((err) => {
|
|
15633
|
-
|
|
15399
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15634
15400
|
});
|
|
15635
15401
|
return data;
|
|
15636
15402
|
} catch (error) {
|
|
15637
|
-
throw new
|
|
15403
|
+
throw new import_node_server_utils71.InternalServerError(
|
|
15638
15404
|
"Failed to fetch people type residents by unit."
|
|
15639
15405
|
);
|
|
15640
15406
|
}
|
|
15641
15407
|
}
|
|
15642
15408
|
async function getCompany(search) {
|
|
15643
15409
|
try {
|
|
15644
|
-
const cacheKey = (0,
|
|
15410
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15645
15411
|
company: search
|
|
15646
15412
|
});
|
|
15647
15413
|
const cachedData = await getCache(cacheKey);
|
|
15648
15414
|
if (cachedData) {
|
|
15649
|
-
|
|
15415
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15650
15416
|
return cachedData;
|
|
15651
15417
|
}
|
|
15652
15418
|
const baseQuery = {
|
|
@@ -15690,24 +15456,24 @@ function usePersonRepo() {
|
|
|
15690
15456
|
]).toArray();
|
|
15691
15457
|
}
|
|
15692
15458
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15693
|
-
|
|
15459
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15694
15460
|
}).catch((err) => {
|
|
15695
|
-
|
|
15461
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15696
15462
|
});
|
|
15697
15463
|
return data;
|
|
15698
15464
|
} catch (error) {
|
|
15699
|
-
throw new
|
|
15465
|
+
throw new import_node_server_utils71.InternalServerError("Failed to fetch visitor by company.");
|
|
15700
15466
|
}
|
|
15701
15467
|
}
|
|
15702
15468
|
async function getPeopleByPlateNumber(plateNumber) {
|
|
15703
|
-
const cacheKey = (0,
|
|
15469
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15704
15470
|
plateNumber,
|
|
15705
15471
|
key: "get-people-plate-number"
|
|
15706
15472
|
});
|
|
15707
15473
|
try {
|
|
15708
15474
|
const cacheData = await getCache(cacheKey);
|
|
15709
15475
|
if (cacheData) {
|
|
15710
|
-
|
|
15476
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15711
15477
|
return cacheData;
|
|
15712
15478
|
}
|
|
15713
15479
|
const data = await collection.find(
|
|
@@ -15715,13 +15481,13 @@ function usePersonRepo() {
|
|
|
15715
15481
|
{ sort: { _id: -1 } }
|
|
15716
15482
|
).toArray();
|
|
15717
15483
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15718
|
-
|
|
15484
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15719
15485
|
}).catch((err) => {
|
|
15720
|
-
|
|
15486
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15721
15487
|
});
|
|
15722
15488
|
return data;
|
|
15723
15489
|
} catch (error) {
|
|
15724
|
-
throw new
|
|
15490
|
+
throw new import_node_server_utils71.InternalServerError("Failed to fetch people by plate number.");
|
|
15725
15491
|
}
|
|
15726
15492
|
}
|
|
15727
15493
|
async function getPeopleByNRIC({
|
|
@@ -15736,7 +15502,7 @@ function usePersonRepo() {
|
|
|
15736
15502
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
15737
15503
|
const query = {
|
|
15738
15504
|
...nric && { nric: normalizedNric },
|
|
15739
|
-
site: typeof site === "string" ? new
|
|
15505
|
+
site: typeof site === "string" ? new import_mongodb43.ObjectId(site) : site
|
|
15740
15506
|
};
|
|
15741
15507
|
const cacheOptions = {
|
|
15742
15508
|
site,
|
|
@@ -15746,32 +15512,32 @@ function usePersonRepo() {
|
|
|
15746
15512
|
sort: JSON.stringify(sort)
|
|
15747
15513
|
};
|
|
15748
15514
|
try {
|
|
15749
|
-
const cacheKey = (0,
|
|
15515
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(
|
|
15750
15516
|
site_people_namespace_collection,
|
|
15751
15517
|
cacheOptions
|
|
15752
15518
|
);
|
|
15753
15519
|
const cachedData = await getCache(cacheKey);
|
|
15754
15520
|
if (cachedData) {
|
|
15755
|
-
|
|
15521
|
+
import_node_server_utils71.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
15756
15522
|
return cachedData;
|
|
15757
15523
|
}
|
|
15758
15524
|
const items = await collection.find(query).sort(sort).skip(page * limit).limit(limit).toArray();
|
|
15759
15525
|
const length = await collection.countDocuments(query);
|
|
15760
|
-
const data = (0,
|
|
15526
|
+
const data = (0, import_node_server_utils71.paginate)(items, page, limit, length);
|
|
15761
15527
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
15762
|
-
|
|
15528
|
+
import_node_server_utils71.logger.info(`Cache set for key: ${cacheKey}`);
|
|
15763
15529
|
}).catch((err) => {
|
|
15764
|
-
|
|
15530
|
+
import_node_server_utils71.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
15765
15531
|
});
|
|
15766
15532
|
return data;
|
|
15767
15533
|
} catch (error) {
|
|
15768
|
-
throw new
|
|
15534
|
+
throw new import_node_server_utils71.InternalServerError("Failed to retrieve person by NRIC.");
|
|
15769
15535
|
}
|
|
15770
15536
|
}
|
|
15771
15537
|
async function pushVehicleById(id, plate, session) {
|
|
15772
15538
|
const { plateNumber, recNo } = plate;
|
|
15773
15539
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
15774
|
-
const _id = (0,
|
|
15540
|
+
const _id = (0, import_node_server_utils71.toObjectId)(id);
|
|
15775
15541
|
try {
|
|
15776
15542
|
const updateExisting = await collection.updateOne(
|
|
15777
15543
|
{
|
|
@@ -15804,7 +15570,7 @@ function usePersonRepo() {
|
|
|
15804
15570
|
);
|
|
15805
15571
|
}
|
|
15806
15572
|
} catch (error) {
|
|
15807
|
-
throw new
|
|
15573
|
+
throw new import_node_server_utils71.InternalServerError("Failed to push vehicle plates by nric.");
|
|
15808
15574
|
}
|
|
15809
15575
|
}
|
|
15810
15576
|
async function pullVehicleByRecNo(recNo, session) {
|
|
@@ -15825,18 +15591,18 @@ function usePersonRepo() {
|
|
|
15825
15591
|
{ session }
|
|
15826
15592
|
);
|
|
15827
15593
|
} catch (error) {
|
|
15828
|
-
throw new
|
|
15594
|
+
throw new import_node_server_utils71.InternalServerError("Failed to pull vehicle plates by nric.");
|
|
15829
15595
|
}
|
|
15830
15596
|
}
|
|
15831
15597
|
async function getByUserId(userId) {
|
|
15832
|
-
const user = (0,
|
|
15833
|
-
const cacheKey = (0,
|
|
15598
|
+
const user = (0, import_node_server_utils71.toObjectId)(userId);
|
|
15599
|
+
const cacheKey = (0, import_node_server_utils71.makeCacheKey)(site_people_namespace_collection, {
|
|
15834
15600
|
user: userId
|
|
15835
15601
|
});
|
|
15836
15602
|
try {
|
|
15837
15603
|
const cached = await getCache(cacheKey);
|
|
15838
15604
|
if (cached) {
|
|
15839
|
-
|
|
15605
|
+
import_node_server_utils71.logger.log({
|
|
15840
15606
|
level: "info",
|
|
15841
15607
|
message: `Cache hit for getByUserId person: ${cacheKey}`
|
|
15842
15608
|
});
|
|
@@ -15846,31 +15612,31 @@ function usePersonRepo() {
|
|
|
15846
15612
|
user
|
|
15847
15613
|
});
|
|
15848
15614
|
setCache(cacheKey, result, 15 * 60).then(() => {
|
|
15849
|
-
|
|
15615
|
+
import_node_server_utils71.logger.log({
|
|
15850
15616
|
level: "info",
|
|
15851
15617
|
message: `Cache set for person by user: ${cacheKey}`
|
|
15852
15618
|
});
|
|
15853
15619
|
}).catch((err) => {
|
|
15854
|
-
|
|
15620
|
+
import_node_server_utils71.logger.log({
|
|
15855
15621
|
level: "error",
|
|
15856
15622
|
message: `Failed to set cache for person by user: ${err.message}`
|
|
15857
15623
|
});
|
|
15858
15624
|
});
|
|
15859
15625
|
return result;
|
|
15860
15626
|
} catch (error) {
|
|
15861
|
-
if (error instanceof
|
|
15627
|
+
if (error instanceof import_node_server_utils71.AppError) {
|
|
15862
15628
|
throw error;
|
|
15863
15629
|
} else {
|
|
15864
|
-
throw new
|
|
15630
|
+
throw new import_node_server_utils71.InternalServerError("Failed to get person by user.");
|
|
15865
15631
|
}
|
|
15866
15632
|
}
|
|
15867
15633
|
}
|
|
15868
15634
|
async function reviewResidentPerson(_id, value, session) {
|
|
15869
15635
|
value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
15870
15636
|
try {
|
|
15871
|
-
_id = new
|
|
15637
|
+
_id = new import_mongodb43.ObjectId(_id);
|
|
15872
15638
|
} catch (error) {
|
|
15873
|
-
throw new
|
|
15639
|
+
throw new import_node_server_utils71.BadRequestError("Invalid ID format.");
|
|
15874
15640
|
}
|
|
15875
15641
|
try {
|
|
15876
15642
|
const res = await collection.updateOne(
|
|
@@ -15879,14 +15645,14 @@ function usePersonRepo() {
|
|
|
15879
15645
|
{ session }
|
|
15880
15646
|
);
|
|
15881
15647
|
if (res.modifiedCount === 0) {
|
|
15882
|
-
throw new
|
|
15648
|
+
throw new import_node_server_utils71.InternalServerError(`Unable to ${value.status} person.`);
|
|
15883
15649
|
}
|
|
15884
15650
|
delNamespace().then(() => {
|
|
15885
|
-
|
|
15651
|
+
import_node_server_utils71.logger.info(
|
|
15886
15652
|
`Cache cleared for namespace: ${site_people_namespace_collection}`
|
|
15887
15653
|
);
|
|
15888
15654
|
}).catch((err) => {
|
|
15889
|
-
|
|
15655
|
+
import_node_server_utils71.logger.error(
|
|
15890
15656
|
`Failed to clear cache for namespace: ${site_people_namespace_collection}`,
|
|
15891
15657
|
err
|
|
15892
15658
|
);
|
|
@@ -15919,15 +15685,15 @@ function usePersonRepo() {
|
|
|
15919
15685
|
}
|
|
15920
15686
|
|
|
15921
15687
|
// src/services/vehicle.service.ts
|
|
15922
|
-
var
|
|
15688
|
+
var import_mongodb46 = require("mongodb");
|
|
15923
15689
|
|
|
15924
15690
|
// src/repositories/building-unit.repository.ts
|
|
15925
|
-
var
|
|
15691
|
+
var import_node_server_utils73 = require("@7365admin1/node-server-utils");
|
|
15926
15692
|
|
|
15927
15693
|
// src/models/building.model.ts
|
|
15928
|
-
var
|
|
15694
|
+
var import_node_server_utils72 = require("@7365admin1/node-server-utils");
|
|
15929
15695
|
var import_joi39 = __toESM(require("joi"));
|
|
15930
|
-
var
|
|
15696
|
+
var import_mongodb44 = require("mongodb");
|
|
15931
15697
|
var SortFields = /* @__PURE__ */ ((SortFields2) => {
|
|
15932
15698
|
SortFields2["ID"] = "_id";
|
|
15933
15699
|
SortFields2["CREATED_AT"] = "createdAt";
|
|
@@ -16016,20 +15782,20 @@ var schemaUpdateOptions = import_joi39.default.object({
|
|
|
16016
15782
|
function MBuilding(value) {
|
|
16017
15783
|
const { error } = schemaBuilding.validate(value);
|
|
16018
15784
|
if (error) {
|
|
16019
|
-
|
|
16020
|
-
throw new
|
|
15785
|
+
import_node_server_utils72.logger.info(`Building Model: ${error.message}`);
|
|
15786
|
+
throw new import_node_server_utils72.BadRequestError(error.message);
|
|
16021
15787
|
}
|
|
16022
15788
|
if (value._id && typeof value._id === "string") {
|
|
16023
15789
|
try {
|
|
16024
|
-
value._id = new
|
|
15790
|
+
value._id = new import_mongodb44.ObjectId(value._id);
|
|
16025
15791
|
} catch (error2) {
|
|
16026
|
-
throw new
|
|
15792
|
+
throw new import_node_server_utils72.BadRequestError("Invalid _id format");
|
|
16027
15793
|
}
|
|
16028
15794
|
}
|
|
16029
15795
|
try {
|
|
16030
|
-
value.site = new
|
|
15796
|
+
value.site = new import_mongodb44.ObjectId(value.site);
|
|
16031
15797
|
} catch (error2) {
|
|
16032
|
-
throw new
|
|
15798
|
+
throw new import_node_server_utils72.BadRequestError("Invalid site format");
|
|
16033
15799
|
}
|
|
16034
15800
|
return {
|
|
16035
15801
|
_id: value._id ?? void 0,
|
|
@@ -16048,40 +15814,40 @@ function MBuilding(value) {
|
|
|
16048
15814
|
function MBuildingUnit(value) {
|
|
16049
15815
|
const { error } = schemaBuildingUnit.validate(value);
|
|
16050
15816
|
if (error) {
|
|
16051
|
-
|
|
16052
|
-
throw new
|
|
15817
|
+
import_node_server_utils72.logger.info(`Building Unit Model: ${error.message}`);
|
|
15818
|
+
throw new import_node_server_utils72.BadRequestError(error.message);
|
|
16053
15819
|
}
|
|
16054
15820
|
if (value._id && typeof value._id === "string") {
|
|
16055
15821
|
try {
|
|
16056
|
-
value._id = new
|
|
15822
|
+
value._id = new import_mongodb44.ObjectId(value._id);
|
|
16057
15823
|
} catch (error2) {
|
|
16058
|
-
throw new
|
|
15824
|
+
throw new import_node_server_utils72.BadRequestError("Invalid ID");
|
|
16059
15825
|
}
|
|
16060
15826
|
}
|
|
16061
15827
|
try {
|
|
16062
|
-
value.site = new
|
|
15828
|
+
value.site = new import_mongodb44.ObjectId(value.site);
|
|
16063
15829
|
} catch (error2) {
|
|
16064
|
-
throw new
|
|
15830
|
+
throw new import_node_server_utils72.BadRequestError("Invalid site ID");
|
|
16065
15831
|
}
|
|
16066
15832
|
try {
|
|
16067
|
-
value.building = new
|
|
15833
|
+
value.building = new import_mongodb44.ObjectId(value.building);
|
|
16068
15834
|
} catch (error2) {
|
|
16069
|
-
throw new
|
|
15835
|
+
throw new import_node_server_utils72.BadRequestError("Invalid building ID");
|
|
16070
15836
|
}
|
|
16071
15837
|
if (value.owner && typeof value.owner === "string") {
|
|
16072
15838
|
try {
|
|
16073
|
-
value.owner = new
|
|
15839
|
+
value.owner = new import_mongodb44.ObjectId(value.owner);
|
|
16074
15840
|
} catch (error2) {
|
|
16075
|
-
throw new
|
|
15841
|
+
throw new import_node_server_utils72.BadRequestError("Invalid Owner ID");
|
|
16076
15842
|
}
|
|
16077
15843
|
}
|
|
16078
15844
|
if (value.billing && Array.isArray(value.billing)) {
|
|
16079
15845
|
value.billing = value.billing.map((billing) => {
|
|
16080
15846
|
if (billing._id && typeof billing._id === "string") {
|
|
16081
15847
|
try {
|
|
16082
|
-
billing._id = new
|
|
15848
|
+
billing._id = new import_mongodb44.ObjectId(billing._id);
|
|
16083
15849
|
} catch {
|
|
16084
|
-
throw new
|
|
15850
|
+
throw new import_node_server_utils72.BadRequestError("Invalid billing id format");
|
|
16085
15851
|
}
|
|
16086
15852
|
}
|
|
16087
15853
|
return billing;
|
|
@@ -16113,15 +15879,15 @@ function MBuildingUnit(value) {
|
|
|
16113
15879
|
}
|
|
16114
15880
|
|
|
16115
15881
|
// src/repositories/building-unit.repository.ts
|
|
16116
|
-
var
|
|
15882
|
+
var import_mongodb45 = require("mongodb");
|
|
16117
15883
|
function useBuildingUnitRepo() {
|
|
16118
|
-
const db =
|
|
15884
|
+
const db = import_node_server_utils73.useAtlas.getDb();
|
|
16119
15885
|
if (!db) {
|
|
16120
15886
|
throw new Error("Unable to connect to server.");
|
|
16121
15887
|
}
|
|
16122
15888
|
const namespace_collection = "building-units";
|
|
16123
15889
|
const collection = db.collection(namespace_collection);
|
|
16124
|
-
const { getCache, setCache, delNamespace, delCache } = (0,
|
|
15890
|
+
const { getCache, setCache, delNamespace, delCache } = (0, import_node_server_utils73.useCache)(namespace_collection);
|
|
16125
15891
|
async function createIndexes() {
|
|
16126
15892
|
try {
|
|
16127
15893
|
await collection.createIndexes([
|
|
@@ -16145,12 +15911,12 @@ function useBuildingUnitRepo() {
|
|
|
16145
15911
|
}
|
|
16146
15912
|
function delCachedData() {
|
|
16147
15913
|
delNamespace().then(() => {
|
|
16148
|
-
|
|
15914
|
+
import_node_server_utils73.logger.log({
|
|
16149
15915
|
level: "info",
|
|
16150
15916
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
16151
15917
|
});
|
|
16152
15918
|
}).catch((err) => {
|
|
16153
|
-
|
|
15919
|
+
import_node_server_utils73.logger.log({
|
|
16154
15920
|
level: "error",
|
|
16155
15921
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
16156
15922
|
});
|
|
@@ -16175,15 +15941,15 @@ function useBuildingUnitRepo() {
|
|
|
16175
15941
|
delCachedData();
|
|
16176
15942
|
return res.insertedId;
|
|
16177
15943
|
} catch (error) {
|
|
16178
|
-
|
|
15944
|
+
import_node_server_utils73.logger.log({
|
|
16179
15945
|
level: "error",
|
|
16180
15946
|
message: error.message
|
|
16181
15947
|
});
|
|
16182
15948
|
const isDuplicated = error.message.includes("duplicate");
|
|
16183
15949
|
if (isDuplicated) {
|
|
16184
|
-
throw new
|
|
15950
|
+
throw new import_node_server_utils73.BadRequestError("Building unit already exists.");
|
|
16185
15951
|
}
|
|
16186
|
-
if (error instanceof
|
|
15952
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16187
15953
|
throw error;
|
|
16188
15954
|
} else {
|
|
16189
15955
|
throw new Error("Failed to create building unit.");
|
|
@@ -16193,27 +15959,27 @@ function useBuildingUnitRepo() {
|
|
|
16193
15959
|
async function updateById(_id, value, session) {
|
|
16194
15960
|
const { error } = schemaUpdateOptions.validate(value);
|
|
16195
15961
|
if (error) {
|
|
16196
|
-
throw new
|
|
15962
|
+
throw new import_node_server_utils73.BadRequestError(error.message);
|
|
16197
15963
|
}
|
|
16198
15964
|
try {
|
|
16199
|
-
_id = new
|
|
15965
|
+
_id = new import_mongodb45.ObjectId(_id);
|
|
16200
15966
|
} catch (error2) {
|
|
16201
|
-
throw new
|
|
15967
|
+
throw new import_node_server_utils73.BadRequestError("Invalid ID.");
|
|
16202
15968
|
}
|
|
16203
15969
|
if (value.billing && Array.isArray(value.billing)) {
|
|
16204
15970
|
value.billing = value.billing.map((billing) => {
|
|
16205
15971
|
if (billing._id && typeof billing._id === "string") {
|
|
16206
15972
|
try {
|
|
16207
|
-
billing._id = new
|
|
15973
|
+
billing._id = new import_mongodb45.ObjectId(billing._id);
|
|
16208
15974
|
} catch {
|
|
16209
|
-
throw new
|
|
15975
|
+
throw new import_node_server_utils73.BadRequestError("Invalid billing id format");
|
|
16210
15976
|
}
|
|
16211
15977
|
}
|
|
16212
15978
|
return billing;
|
|
16213
15979
|
});
|
|
16214
15980
|
}
|
|
16215
15981
|
if (value.owner) {
|
|
16216
|
-
value.owner = new
|
|
15982
|
+
value.owner = new import_mongodb45.ObjectId(value.owner);
|
|
16217
15983
|
}
|
|
16218
15984
|
try {
|
|
16219
15985
|
const res = await collection.updateOne(
|
|
@@ -16224,15 +15990,15 @@ function useBuildingUnitRepo() {
|
|
|
16224
15990
|
delCachedData();
|
|
16225
15991
|
return res;
|
|
16226
15992
|
} catch (error2) {
|
|
16227
|
-
|
|
15993
|
+
import_node_server_utils73.logger.log({
|
|
16228
15994
|
level: "error",
|
|
16229
15995
|
message: error2.message
|
|
16230
15996
|
});
|
|
16231
15997
|
const isDuplicated = error2.message.includes("duplicate");
|
|
16232
15998
|
if (isDuplicated) {
|
|
16233
|
-
throw new
|
|
15999
|
+
throw new import_node_server_utils73.BadRequestError("Building unit already exists.");
|
|
16234
16000
|
}
|
|
16235
|
-
if (error2 instanceof
|
|
16001
|
+
if (error2 instanceof import_node_server_utils73.AppError) {
|
|
16236
16002
|
throw error2;
|
|
16237
16003
|
} else {
|
|
16238
16004
|
throw new Error("Failed to create building unit.");
|
|
@@ -16242,12 +16008,12 @@ function useBuildingUnitRepo() {
|
|
|
16242
16008
|
async function updateByBuildingId(building, value, session) {
|
|
16243
16009
|
const { error } = schemaUpdateOptions.validate(value);
|
|
16244
16010
|
if (error) {
|
|
16245
|
-
throw new
|
|
16011
|
+
throw new import_node_server_utils73.BadRequestError(error.message);
|
|
16246
16012
|
}
|
|
16247
16013
|
try {
|
|
16248
|
-
building = new
|
|
16014
|
+
building = new import_mongodb45.ObjectId(building);
|
|
16249
16015
|
} catch (error2) {
|
|
16250
|
-
throw new
|
|
16016
|
+
throw new import_node_server_utils73.BadRequestError("Invalid building ID.");
|
|
16251
16017
|
}
|
|
16252
16018
|
try {
|
|
16253
16019
|
const res = await collection.updateMany(
|
|
@@ -16258,15 +16024,15 @@ function useBuildingUnitRepo() {
|
|
|
16258
16024
|
delCachedData();
|
|
16259
16025
|
return res;
|
|
16260
16026
|
} catch (error2) {
|
|
16261
|
-
|
|
16027
|
+
import_node_server_utils73.logger.log({
|
|
16262
16028
|
level: "error",
|
|
16263
16029
|
message: error2.message
|
|
16264
16030
|
});
|
|
16265
16031
|
const isDuplicated = error2.message.includes("duplicate");
|
|
16266
16032
|
if (isDuplicated) {
|
|
16267
|
-
throw new
|
|
16033
|
+
throw new import_node_server_utils73.BadRequestError("Building unit already exists.");
|
|
16268
16034
|
}
|
|
16269
|
-
if (error2 instanceof
|
|
16035
|
+
if (error2 instanceof import_node_server_utils73.AppError) {
|
|
16270
16036
|
throw error2;
|
|
16271
16037
|
} else {
|
|
16272
16038
|
throw new Error("Failed to create building unit.");
|
|
@@ -16286,8 +16052,8 @@ function useBuildingUnitRepo() {
|
|
|
16286
16052
|
const query = {
|
|
16287
16053
|
status,
|
|
16288
16054
|
...search && { $text: { $search: search } },
|
|
16289
|
-
...site && { site: (0,
|
|
16290
|
-
...building && { building: (0,
|
|
16055
|
+
...site && { site: (0, import_node_server_utils73.toObjectId)(site) },
|
|
16056
|
+
...building && { building: (0, import_node_server_utils73.toObjectId)(building) }
|
|
16291
16057
|
};
|
|
16292
16058
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
16293
16059
|
const cacheParams = {
|
|
@@ -16299,15 +16065,15 @@ function useBuildingUnitRepo() {
|
|
|
16299
16065
|
...building && { building },
|
|
16300
16066
|
...status && { status }
|
|
16301
16067
|
};
|
|
16302
|
-
const cacheKey = (0,
|
|
16303
|
-
|
|
16068
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, cacheParams);
|
|
16069
|
+
import_node_server_utils73.logger.log({
|
|
16304
16070
|
level: "info",
|
|
16305
16071
|
message: `Cache key for getAll building units: ${cacheKey}`
|
|
16306
16072
|
});
|
|
16307
16073
|
try {
|
|
16308
16074
|
const cached = await getCache(cacheKey);
|
|
16309
16075
|
if (cached) {
|
|
16310
|
-
|
|
16076
|
+
import_node_server_utils73.logger.log({
|
|
16311
16077
|
level: "info",
|
|
16312
16078
|
message: `Cache hit for getAll building units: ${cacheKey}`
|
|
16313
16079
|
});
|
|
@@ -16346,35 +16112,35 @@ function useBuildingUnitRepo() {
|
|
|
16346
16112
|
{ $limit: limit }
|
|
16347
16113
|
]).toArray();
|
|
16348
16114
|
const length = await collection.countDocuments(query);
|
|
16349
|
-
const data = (0,
|
|
16115
|
+
const data = (0, import_node_server_utils73.paginate)(items, page, limit, length);
|
|
16350
16116
|
setCache(cacheKey, data, 600).then(() => {
|
|
16351
|
-
|
|
16117
|
+
import_node_server_utils73.logger.log({
|
|
16352
16118
|
level: "info",
|
|
16353
16119
|
message: `Cache set for getAll building units: ${cacheKey}`
|
|
16354
16120
|
});
|
|
16355
16121
|
}).catch((err) => {
|
|
16356
|
-
|
|
16122
|
+
import_node_server_utils73.logger.log({
|
|
16357
16123
|
level: "error",
|
|
16358
16124
|
message: `Failed to set cache for getAll building units: ${err.message}`
|
|
16359
16125
|
});
|
|
16360
16126
|
});
|
|
16361
16127
|
return data;
|
|
16362
16128
|
} catch (error) {
|
|
16363
|
-
|
|
16129
|
+
import_node_server_utils73.logger.log({ level: "error", message: `${error}` });
|
|
16364
16130
|
throw error;
|
|
16365
16131
|
}
|
|
16366
16132
|
}
|
|
16367
16133
|
async function getById(_id, session) {
|
|
16368
16134
|
try {
|
|
16369
|
-
_id = new
|
|
16135
|
+
_id = new import_mongodb45.ObjectId(_id);
|
|
16370
16136
|
} catch (error) {
|
|
16371
|
-
throw new
|
|
16137
|
+
throw new import_node_server_utils73.BadRequestError("Invalid ID.");
|
|
16372
16138
|
}
|
|
16373
|
-
const cacheKey = (0,
|
|
16139
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
16374
16140
|
try {
|
|
16375
16141
|
const cached = await getCache(cacheKey);
|
|
16376
16142
|
if (cached) {
|
|
16377
|
-
|
|
16143
|
+
import_node_server_utils73.logger.log({
|
|
16378
16144
|
level: "info",
|
|
16379
16145
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
16380
16146
|
});
|
|
@@ -16385,42 +16151,42 @@ function useBuildingUnitRepo() {
|
|
|
16385
16151
|
deletedAt: { $in: ["", null] }
|
|
16386
16152
|
});
|
|
16387
16153
|
if (!result) {
|
|
16388
|
-
throw new
|
|
16154
|
+
throw new import_node_server_utils73.BadRequestError("Building unit not found.");
|
|
16389
16155
|
}
|
|
16390
16156
|
setCache(cacheKey, result, 300).then(() => {
|
|
16391
|
-
|
|
16157
|
+
import_node_server_utils73.logger.log({
|
|
16392
16158
|
level: "info",
|
|
16393
16159
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
16394
16160
|
});
|
|
16395
16161
|
}).catch((err) => {
|
|
16396
|
-
|
|
16162
|
+
import_node_server_utils73.logger.log({
|
|
16397
16163
|
level: "error",
|
|
16398
16164
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
16399
16165
|
});
|
|
16400
16166
|
});
|
|
16401
16167
|
return result;
|
|
16402
16168
|
} catch (error) {
|
|
16403
|
-
if (error instanceof
|
|
16169
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16404
16170
|
throw error;
|
|
16405
16171
|
} else {
|
|
16406
|
-
throw new
|
|
16172
|
+
throw new import_node_server_utils73.InternalServerError("Failed to get building unit.");
|
|
16407
16173
|
}
|
|
16408
16174
|
}
|
|
16409
16175
|
}
|
|
16410
16176
|
async function getByBuildingLevel(building, level) {
|
|
16411
16177
|
try {
|
|
16412
|
-
building = new
|
|
16178
|
+
building = new import_mongodb45.ObjectId(building);
|
|
16413
16179
|
} catch (error) {
|
|
16414
|
-
throw new
|
|
16180
|
+
throw new import_node_server_utils73.BadRequestError("Invalid building ID.");
|
|
16415
16181
|
}
|
|
16416
|
-
const cacheKey = (0,
|
|
16182
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, {
|
|
16417
16183
|
building: String(building),
|
|
16418
16184
|
level
|
|
16419
16185
|
});
|
|
16420
16186
|
try {
|
|
16421
16187
|
const cached = await getCache(cacheKey);
|
|
16422
16188
|
if (cached) {
|
|
16423
|
-
|
|
16189
|
+
import_node_server_utils73.logger.log({
|
|
16424
16190
|
level: "info",
|
|
16425
16191
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
16426
16192
|
});
|
|
@@ -16432,30 +16198,30 @@ function useBuildingUnitRepo() {
|
|
|
16432
16198
|
status: "active"
|
|
16433
16199
|
});
|
|
16434
16200
|
setCache(cacheKey, result, 300).then(() => {
|
|
16435
|
-
|
|
16201
|
+
import_node_server_utils73.logger.log({
|
|
16436
16202
|
level: "info",
|
|
16437
16203
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
16438
16204
|
});
|
|
16439
16205
|
}).catch((err) => {
|
|
16440
|
-
|
|
16206
|
+
import_node_server_utils73.logger.log({
|
|
16441
16207
|
level: "error",
|
|
16442
16208
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
16443
16209
|
});
|
|
16444
16210
|
});
|
|
16445
16211
|
return result;
|
|
16446
16212
|
} catch (error) {
|
|
16447
|
-
if (error instanceof
|
|
16213
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16448
16214
|
throw error;
|
|
16449
16215
|
} else {
|
|
16450
|
-
throw new
|
|
16216
|
+
throw new import_node_server_utils73.InternalServerError("Failed to get building unit.");
|
|
16451
16217
|
}
|
|
16452
16218
|
}
|
|
16453
16219
|
}
|
|
16454
16220
|
async function updateLevelByBuildingLevel(building, level, newLevel, session) {
|
|
16455
16221
|
try {
|
|
16456
|
-
building = new
|
|
16222
|
+
building = new import_mongodb45.ObjectId(building);
|
|
16457
16223
|
} catch (error) {
|
|
16458
|
-
throw new
|
|
16224
|
+
throw new import_node_server_utils73.BadRequestError("Invalid building ID.");
|
|
16459
16225
|
}
|
|
16460
16226
|
try {
|
|
16461
16227
|
const result = await collection.updateMany(
|
|
@@ -16474,26 +16240,26 @@ function useBuildingUnitRepo() {
|
|
|
16474
16240
|
delCachedData();
|
|
16475
16241
|
return result;
|
|
16476
16242
|
} catch (error) {
|
|
16477
|
-
if (error instanceof
|
|
16243
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16478
16244
|
throw error;
|
|
16479
16245
|
} else {
|
|
16480
|
-
throw new
|
|
16246
|
+
throw new import_node_server_utils73.InternalServerError("Failed to update building unit level.");
|
|
16481
16247
|
}
|
|
16482
16248
|
}
|
|
16483
16249
|
}
|
|
16484
16250
|
async function getByBuilding(building) {
|
|
16485
16251
|
try {
|
|
16486
|
-
building = new
|
|
16252
|
+
building = new import_mongodb45.ObjectId(building);
|
|
16487
16253
|
} catch (error) {
|
|
16488
|
-
throw new
|
|
16254
|
+
throw new import_node_server_utils73.BadRequestError("Invalid building ID.");
|
|
16489
16255
|
}
|
|
16490
|
-
const cacheKey = (0,
|
|
16256
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, {
|
|
16491
16257
|
building: String(building)
|
|
16492
16258
|
});
|
|
16493
16259
|
try {
|
|
16494
16260
|
const cached = await getCache(cacheKey);
|
|
16495
16261
|
if (cached) {
|
|
16496
|
-
|
|
16262
|
+
import_node_server_utils73.logger.log({
|
|
16497
16263
|
level: "info",
|
|
16498
16264
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
16499
16265
|
});
|
|
@@ -16504,30 +16270,30 @@ function useBuildingUnitRepo() {
|
|
|
16504
16270
|
status: "active"
|
|
16505
16271
|
});
|
|
16506
16272
|
setCache(cacheKey, result, 300).then(() => {
|
|
16507
|
-
|
|
16273
|
+
import_node_server_utils73.logger.log({
|
|
16508
16274
|
level: "info",
|
|
16509
16275
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
16510
16276
|
});
|
|
16511
16277
|
}).catch((err) => {
|
|
16512
|
-
|
|
16278
|
+
import_node_server_utils73.logger.log({
|
|
16513
16279
|
level: "error",
|
|
16514
16280
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
16515
16281
|
});
|
|
16516
16282
|
});
|
|
16517
16283
|
return result;
|
|
16518
16284
|
} catch (error) {
|
|
16519
|
-
if (error instanceof
|
|
16285
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16520
16286
|
throw error;
|
|
16521
16287
|
} else {
|
|
16522
|
-
throw new
|
|
16288
|
+
throw new import_node_server_utils73.InternalServerError("Failed to get building unit.");
|
|
16523
16289
|
}
|
|
16524
16290
|
}
|
|
16525
16291
|
}
|
|
16526
16292
|
async function deleteById(_id, session) {
|
|
16527
16293
|
try {
|
|
16528
|
-
_id = new
|
|
16294
|
+
_id = new import_mongodb45.ObjectId(_id);
|
|
16529
16295
|
} catch (error) {
|
|
16530
|
-
throw new
|
|
16296
|
+
throw new import_node_server_utils73.BadRequestError("Invalid ID.");
|
|
16531
16297
|
}
|
|
16532
16298
|
try {
|
|
16533
16299
|
const res = await collection.updateOne(
|
|
@@ -16538,11 +16304,11 @@ function useBuildingUnitRepo() {
|
|
|
16538
16304
|
delCachedData();
|
|
16539
16305
|
return "Room/Facility deleted successfully.";
|
|
16540
16306
|
} catch (error) {
|
|
16541
|
-
|
|
16307
|
+
import_node_server_utils73.logger.log({
|
|
16542
16308
|
level: "error",
|
|
16543
16309
|
message: error.message
|
|
16544
16310
|
});
|
|
16545
|
-
if (error instanceof
|
|
16311
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16546
16312
|
throw error;
|
|
16547
16313
|
} else {
|
|
16548
16314
|
throw new Error("Failed to deleted room/facility.");
|
|
@@ -16551,9 +16317,9 @@ function useBuildingUnitRepo() {
|
|
|
16551
16317
|
}
|
|
16552
16318
|
async function getBuildingUnits(site, block, level) {
|
|
16553
16319
|
try {
|
|
16554
|
-
site = new
|
|
16320
|
+
site = new import_mongodb45.ObjectId(site);
|
|
16555
16321
|
} catch (error) {
|
|
16556
|
-
throw new
|
|
16322
|
+
throw new import_node_server_utils73.BadRequestError("Invalid site ID format.");
|
|
16557
16323
|
}
|
|
16558
16324
|
const query = { site, block, level };
|
|
16559
16325
|
const cacheOptions = {
|
|
@@ -16561,33 +16327,33 @@ function useBuildingUnitRepo() {
|
|
|
16561
16327
|
block,
|
|
16562
16328
|
level
|
|
16563
16329
|
};
|
|
16564
|
-
const cacheKey = (0,
|
|
16330
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, cacheOptions);
|
|
16565
16331
|
const cachedData = await getCache(cacheKey);
|
|
16566
16332
|
if (cachedData) {
|
|
16567
|
-
|
|
16333
|
+
import_node_server_utils73.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
16568
16334
|
return cachedData;
|
|
16569
16335
|
}
|
|
16570
16336
|
try {
|
|
16571
16337
|
const data = await collection.aggregate([{ $match: query }, { $project: { name: 1 } }]).toArray();
|
|
16572
16338
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
16573
|
-
|
|
16339
|
+
import_node_server_utils73.logger.info(`Cache set for key: ${cacheKey}`);
|
|
16574
16340
|
}).catch((err) => {
|
|
16575
|
-
|
|
16341
|
+
import_node_server_utils73.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
16576
16342
|
});
|
|
16577
16343
|
return data;
|
|
16578
16344
|
} catch (error) {
|
|
16579
|
-
if (error instanceof
|
|
16345
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16580
16346
|
throw error;
|
|
16581
16347
|
} else {
|
|
16582
|
-
throw new
|
|
16348
|
+
throw new import_node_server_utils73.InternalServerError("Failed to get building units.");
|
|
16583
16349
|
}
|
|
16584
16350
|
}
|
|
16585
16351
|
}
|
|
16586
16352
|
async function getBuildingUnitsWithOwner(site, unitIds) {
|
|
16587
16353
|
try {
|
|
16588
|
-
site = new
|
|
16354
|
+
site = new import_mongodb45.ObjectId(site);
|
|
16589
16355
|
} catch (error) {
|
|
16590
|
-
throw new
|
|
16356
|
+
throw new import_node_server_utils73.BadRequestError("Invalid site ID format.");
|
|
16591
16357
|
}
|
|
16592
16358
|
const query = {
|
|
16593
16359
|
site,
|
|
@@ -16599,25 +16365,25 @@ function useBuildingUnitRepo() {
|
|
|
16599
16365
|
const cacheOptions = {
|
|
16600
16366
|
site: site.toString()
|
|
16601
16367
|
};
|
|
16602
|
-
const cacheKey = (0,
|
|
16368
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, cacheOptions);
|
|
16603
16369
|
const cachedData = await getCache(cacheKey);
|
|
16604
16370
|
if (cachedData) {
|
|
16605
|
-
|
|
16371
|
+
import_node_server_utils73.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
16606
16372
|
return cachedData;
|
|
16607
16373
|
}
|
|
16608
16374
|
try {
|
|
16609
16375
|
const data = await collection.aggregate([{ $match: query }]).toArray();
|
|
16610
16376
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
16611
|
-
|
|
16377
|
+
import_node_server_utils73.logger.info(`Cache set for key: ${cacheKey}`);
|
|
16612
16378
|
}).catch((err) => {
|
|
16613
|
-
|
|
16379
|
+
import_node_server_utils73.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
16614
16380
|
});
|
|
16615
16381
|
return data;
|
|
16616
16382
|
} catch (error) {
|
|
16617
|
-
if (error instanceof
|
|
16383
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16618
16384
|
throw error;
|
|
16619
16385
|
} else {
|
|
16620
|
-
throw new
|
|
16386
|
+
throw new import_node_server_utils73.InternalServerError(
|
|
16621
16387
|
"Failed to get building units with owner."
|
|
16622
16388
|
);
|
|
16623
16389
|
}
|
|
@@ -16626,9 +16392,9 @@ function useBuildingUnitRepo() {
|
|
|
16626
16392
|
async function getUnitByBlockLevelUnitNumber(block, level, unitNumber, site, session) {
|
|
16627
16393
|
let _site;
|
|
16628
16394
|
try {
|
|
16629
|
-
_site = new
|
|
16395
|
+
_site = new import_mongodb45.ObjectId(site);
|
|
16630
16396
|
} catch (error) {
|
|
16631
|
-
throw new
|
|
16397
|
+
throw new import_node_server_utils73.BadRequestError("Invalid ID.");
|
|
16632
16398
|
}
|
|
16633
16399
|
const cacheOptions = {
|
|
16634
16400
|
block,
|
|
@@ -16647,11 +16413,11 @@ function useBuildingUnitRepo() {
|
|
|
16647
16413
|
{ deletedAt: "" }
|
|
16648
16414
|
]
|
|
16649
16415
|
};
|
|
16650
|
-
const cacheKey = (0,
|
|
16416
|
+
const cacheKey = (0, import_node_server_utils73.makeCacheKey)(namespace_collection, cacheOptions);
|
|
16651
16417
|
try {
|
|
16652
16418
|
const cached = await getCache(cacheKey);
|
|
16653
16419
|
if (cached) {
|
|
16654
|
-
|
|
16420
|
+
import_node_server_utils73.logger.log({
|
|
16655
16421
|
level: "info",
|
|
16656
16422
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
16657
16423
|
});
|
|
@@ -16661,25 +16427,25 @@ function useBuildingUnitRepo() {
|
|
|
16661
16427
|
session
|
|
16662
16428
|
});
|
|
16663
16429
|
if (!result) {
|
|
16664
|
-
throw new
|
|
16430
|
+
throw new import_node_server_utils73.BadRequestError("Building unit not found.");
|
|
16665
16431
|
}
|
|
16666
16432
|
setCache(cacheKey, result, 300).then(() => {
|
|
16667
|
-
|
|
16433
|
+
import_node_server_utils73.logger.log({
|
|
16668
16434
|
level: "info",
|
|
16669
16435
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
16670
16436
|
});
|
|
16671
16437
|
}).catch((err) => {
|
|
16672
|
-
|
|
16438
|
+
import_node_server_utils73.logger.log({
|
|
16673
16439
|
level: "error",
|
|
16674
16440
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
16675
16441
|
});
|
|
16676
16442
|
});
|
|
16677
16443
|
return result;
|
|
16678
16444
|
} catch (error) {
|
|
16679
|
-
if (error instanceof
|
|
16445
|
+
if (error instanceof import_node_server_utils73.AppError) {
|
|
16680
16446
|
throw error;
|
|
16681
16447
|
} else {
|
|
16682
|
-
throw new
|
|
16448
|
+
throw new import_node_server_utils73.InternalServerError("Failed to get building unit.");
|
|
16683
16449
|
}
|
|
16684
16450
|
}
|
|
16685
16451
|
}
|
|
@@ -16748,7 +16514,7 @@ function useVehicleService() {
|
|
|
16748
16514
|
async function add(value, session) {
|
|
16749
16515
|
const isExternalSession = !!session;
|
|
16750
16516
|
if (!session) {
|
|
16751
|
-
session = await
|
|
16517
|
+
session = await import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
16752
16518
|
if (!session) {
|
|
16753
16519
|
throw new Error("Unable to start session for vehicle service.");
|
|
16754
16520
|
}
|
|
@@ -16759,11 +16525,11 @@ function useVehicleService() {
|
|
|
16759
16525
|
_getById(value.org)
|
|
16760
16526
|
]);
|
|
16761
16527
|
if (!org)
|
|
16762
|
-
throw new
|
|
16528
|
+
throw new import_node_server_utils74.BadRequestError("Org not found");
|
|
16763
16529
|
if (existingPlateNumber)
|
|
16764
|
-
throw new
|
|
16530
|
+
throw new import_node_server_utils74.BadRequestError("Vehicle plate number already exists");
|
|
16765
16531
|
if (!Object.values(OrgNature).includes(org.nature)) {
|
|
16766
|
-
throw new
|
|
16532
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
16767
16533
|
"This organization is not allowed to add vehicles."
|
|
16768
16534
|
);
|
|
16769
16535
|
}
|
|
@@ -16830,7 +16596,7 @@ function useVehicleService() {
|
|
|
16830
16596
|
page++;
|
|
16831
16597
|
} while (page <= pages);
|
|
16832
16598
|
if (!siteCameras.length) {
|
|
16833
|
-
throw new
|
|
16599
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
16834
16600
|
}
|
|
16835
16601
|
}
|
|
16836
16602
|
for (const plateNumber of plateNumbers) {
|
|
@@ -16866,7 +16632,7 @@ function useVehicleService() {
|
|
|
16866
16632
|
};
|
|
16867
16633
|
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
16868
16634
|
if (dahuaResponse?.statusCode !== 200) {
|
|
16869
|
-
throw new
|
|
16635
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
16870
16636
|
`Failed to add plate number to ANPR ${_type}`
|
|
16871
16637
|
);
|
|
16872
16638
|
}
|
|
@@ -16887,7 +16653,7 @@ function useVehicleService() {
|
|
|
16887
16653
|
};
|
|
16888
16654
|
const dahuaResponse = await _updatePlateNumber(dahuaPayload);
|
|
16889
16655
|
if (dahuaResponse?.statusCode !== 200) {
|
|
16890
|
-
throw new
|
|
16656
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
16891
16657
|
`Failed to update plate number to ANPR ${_type}`
|
|
16892
16658
|
);
|
|
16893
16659
|
}
|
|
@@ -16913,7 +16679,7 @@ function useVehicleService() {
|
|
|
16913
16679
|
}
|
|
16914
16680
|
return message;
|
|
16915
16681
|
} catch (error) {
|
|
16916
|
-
|
|
16682
|
+
import_node_server_utils74.logger.error("Error in vehicle service add:", error);
|
|
16917
16683
|
if (!isExternalSession) {
|
|
16918
16684
|
await session.abortTransaction();
|
|
16919
16685
|
}
|
|
@@ -16925,7 +16691,7 @@ function useVehicleService() {
|
|
|
16925
16691
|
}
|
|
16926
16692
|
}
|
|
16927
16693
|
async function deleteVehicle(_id, recno, site, type, bypass = false) {
|
|
16928
|
-
const session =
|
|
16694
|
+
const session = import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
16929
16695
|
if (!session) {
|
|
16930
16696
|
throw new Error("Unable to start session for vehicle service.");
|
|
16931
16697
|
}
|
|
@@ -16948,7 +16714,7 @@ function useVehicleService() {
|
|
|
16948
16714
|
page++;
|
|
16949
16715
|
} while (page < pages);
|
|
16950
16716
|
if (!siteCameras.length) {
|
|
16951
|
-
throw new
|
|
16717
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
16952
16718
|
}
|
|
16953
16719
|
for (const camera of siteCameras) {
|
|
16954
16720
|
const host = camera.host;
|
|
@@ -16963,7 +16729,7 @@ function useVehicleService() {
|
|
|
16963
16729
|
};
|
|
16964
16730
|
const dahuaResponse = await _removePlateNumber(dahuaPayload);
|
|
16965
16731
|
if (!bypass && dahuaResponse?.statusCode !== 200) {
|
|
16966
|
-
throw new
|
|
16732
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
16967
16733
|
`Failed to remove plate number to ANPR from ${type}`
|
|
16968
16734
|
);
|
|
16969
16735
|
}
|
|
@@ -16975,7 +16741,7 @@ function useVehicleService() {
|
|
|
16975
16741
|
await session.commitTransaction();
|
|
16976
16742
|
return `Vehicle plate number deleted from ${type} record successfully.`;
|
|
16977
16743
|
} catch (error) {
|
|
16978
|
-
|
|
16744
|
+
import_node_server_utils74.logger.error("Error in vehicle service delete:", error);
|
|
16979
16745
|
await session.abortTransaction();
|
|
16980
16746
|
throw error;
|
|
16981
16747
|
} finally {
|
|
@@ -16983,16 +16749,16 @@ function useVehicleService() {
|
|
|
16983
16749
|
}
|
|
16984
16750
|
}
|
|
16985
16751
|
async function approveVehicleById(id, orgId, siteId) {
|
|
16986
|
-
const session =
|
|
16752
|
+
const session = import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
16987
16753
|
if (!session) {
|
|
16988
16754
|
throw new Error("Unable to start session for vehicle service.");
|
|
16989
16755
|
}
|
|
16990
16756
|
const org = await _getById(orgId);
|
|
16991
16757
|
if (!org)
|
|
16992
|
-
throw new
|
|
16758
|
+
throw new import_node_server_utils74.BadRequestError("Org not found");
|
|
16993
16759
|
const allowedNatures2 = "property_management_agency" /* PROPERTY_MANAGEMENT_AGENCY */;
|
|
16994
16760
|
if (!allowedNatures2.includes(org.nature)) {
|
|
16995
|
-
throw new
|
|
16761
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
16996
16762
|
"Only property management can approve vehicles."
|
|
16997
16763
|
);
|
|
16998
16764
|
}
|
|
@@ -17000,7 +16766,7 @@ function useVehicleService() {
|
|
|
17000
16766
|
const plate = vehicle.plates.find((p) => p._id.toString() === id);
|
|
17001
16767
|
const _plateNumber = plate?.plateNumber;
|
|
17002
16768
|
if (!vehicle) {
|
|
17003
|
-
throw new
|
|
16769
|
+
throw new import_node_server_utils74.BadRequestError("Vehicle not found");
|
|
17004
16770
|
}
|
|
17005
16771
|
const owner = vehicle.name;
|
|
17006
16772
|
const hasStart = typeof vehicle.start === "string" ? vehicle.start.trim() !== "" : !!vehicle.start;
|
|
@@ -17042,7 +16808,7 @@ function useVehicleService() {
|
|
|
17042
16808
|
page++;
|
|
17043
16809
|
} while (page < pages);
|
|
17044
16810
|
if (!siteCameras.length) {
|
|
17045
|
-
throw new
|
|
16811
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
17046
16812
|
}
|
|
17047
16813
|
for (const camera of siteCameras) {
|
|
17048
16814
|
const { host, username, password } = camera;
|
|
@@ -17058,7 +16824,7 @@ function useVehicleService() {
|
|
|
17058
16824
|
};
|
|
17059
16825
|
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
17060
16826
|
if (dahuaResponse?.statusCode !== 200) {
|
|
17061
|
-
throw new
|
|
16827
|
+
throw new import_node_server_utils74.BadRequestError("Failed to add plate number to ANPR");
|
|
17062
16828
|
}
|
|
17063
16829
|
const responseData = dahuaResponse?.data.toString("utf-8");
|
|
17064
16830
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
@@ -17083,7 +16849,7 @@ function useVehicleService() {
|
|
|
17083
16849
|
await session.commitTransaction();
|
|
17084
16850
|
return "Vehicle plate number approved and added successfully.";
|
|
17085
16851
|
} catch (error) {
|
|
17086
|
-
|
|
16852
|
+
import_node_server_utils74.logger.error("Error in vehicle service approving and adding:", error);
|
|
17087
16853
|
await session.abortTransaction();
|
|
17088
16854
|
throw error;
|
|
17089
16855
|
} finally {
|
|
@@ -17091,7 +16857,7 @@ function useVehicleService() {
|
|
|
17091
16857
|
}
|
|
17092
16858
|
}
|
|
17093
16859
|
async function processDeletingExpiredVehicles() {
|
|
17094
|
-
const session =
|
|
16860
|
+
const session = import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
17095
16861
|
if (!session) {
|
|
17096
16862
|
throw new Error("Unable to start session for vehicle service.");
|
|
17097
16863
|
}
|
|
@@ -17118,7 +16884,7 @@ function useVehicleService() {
|
|
|
17118
16884
|
page++;
|
|
17119
16885
|
} while (page < pages);
|
|
17120
16886
|
if (!siteCameras.length) {
|
|
17121
|
-
throw new
|
|
16887
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
17122
16888
|
}
|
|
17123
16889
|
for (const camera of siteCameras) {
|
|
17124
16890
|
const host = camera.host;
|
|
@@ -17138,7 +16904,7 @@ function useVehicleService() {
|
|
|
17138
16904
|
await session.commitTransaction();
|
|
17139
16905
|
return `Expired Vehicle plate numbers deleted successfully.`;
|
|
17140
16906
|
} catch (error) {
|
|
17141
|
-
|
|
16907
|
+
import_node_server_utils74.logger.error(
|
|
17142
16908
|
"Error in vehicle service process deleting expired vehicles:",
|
|
17143
16909
|
error
|
|
17144
16910
|
);
|
|
@@ -17149,16 +16915,16 @@ function useVehicleService() {
|
|
|
17149
16915
|
}
|
|
17150
16916
|
}
|
|
17151
16917
|
async function reactivateVehicleById(id, orgId, siteId) {
|
|
17152
|
-
const session =
|
|
16918
|
+
const session = import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
17153
16919
|
if (!session) {
|
|
17154
16920
|
throw new Error("Unable to start session for vehicle service.");
|
|
17155
16921
|
}
|
|
17156
16922
|
const org = await _getById(orgId);
|
|
17157
16923
|
if (!org)
|
|
17158
|
-
throw new
|
|
16924
|
+
throw new import_node_server_utils74.BadRequestError("Org not found");
|
|
17159
16925
|
const allowedNatures2 = "property_management_agency" /* PROPERTY_MANAGEMENT_AGENCY */;
|
|
17160
16926
|
if (!allowedNatures2.includes(org.nature)) {
|
|
17161
|
-
throw new
|
|
16927
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
17162
16928
|
"Only property management can reactivate vehicles."
|
|
17163
16929
|
);
|
|
17164
16930
|
}
|
|
@@ -17166,7 +16932,7 @@ function useVehicleService() {
|
|
|
17166
16932
|
const plate = vehicle.plates.find((p) => p._id.toString() === id);
|
|
17167
16933
|
const _plateNumber = plate?.plateNumber;
|
|
17168
16934
|
if (!vehicle) {
|
|
17169
|
-
throw new
|
|
16935
|
+
throw new import_node_server_utils74.BadRequestError("Vehicle not found");
|
|
17170
16936
|
}
|
|
17171
16937
|
const owner = vehicle.name;
|
|
17172
16938
|
let startDate = /* @__PURE__ */ new Date();
|
|
@@ -17196,7 +16962,7 @@ function useVehicleService() {
|
|
|
17196
16962
|
page++;
|
|
17197
16963
|
} while (page < pages);
|
|
17198
16964
|
if (!siteCameras.length) {
|
|
17199
|
-
throw new
|
|
16965
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
17200
16966
|
}
|
|
17201
16967
|
for (const camera of siteCameras) {
|
|
17202
16968
|
const { host, username, password } = camera;
|
|
@@ -17212,7 +16978,7 @@ function useVehicleService() {
|
|
|
17212
16978
|
};
|
|
17213
16979
|
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
17214
16980
|
if (dahuaResponse?.statusCode !== 200) {
|
|
17215
|
-
throw new
|
|
16981
|
+
throw new import_node_server_utils74.BadRequestError("Failed to add plate number to ANPR");
|
|
17216
16982
|
}
|
|
17217
16983
|
const responseData = dahuaResponse?.data.toString("utf-8");
|
|
17218
16984
|
value.recNo = responseData.split("=")[1]?.trim();
|
|
@@ -17238,7 +17004,7 @@ function useVehicleService() {
|
|
|
17238
17004
|
await session.commitTransaction();
|
|
17239
17005
|
return "Vehicle reactivated successfully.";
|
|
17240
17006
|
} catch (error) {
|
|
17241
|
-
|
|
17007
|
+
import_node_server_utils74.logger.error("Error in vehicle service reactivation:", error);
|
|
17242
17008
|
await session.abortTransaction();
|
|
17243
17009
|
throw error;
|
|
17244
17010
|
} finally {
|
|
@@ -17246,7 +17012,7 @@ function useVehicleService() {
|
|
|
17246
17012
|
}
|
|
17247
17013
|
}
|
|
17248
17014
|
async function updateVehicleById(_id, value) {
|
|
17249
|
-
const session =
|
|
17015
|
+
const session = import_node_server_utils74.useAtlas.getClient()?.startSession();
|
|
17250
17016
|
if (!session) {
|
|
17251
17017
|
throw new Error("Unable to start session for vehicle service.");
|
|
17252
17018
|
}
|
|
@@ -17281,7 +17047,7 @@ function useVehicleService() {
|
|
|
17281
17047
|
page++;
|
|
17282
17048
|
} while (page < pages);
|
|
17283
17049
|
if (!siteCameras.length) {
|
|
17284
|
-
throw new
|
|
17050
|
+
throw new import_node_server_utils74.BadRequestError("No site cameras found.");
|
|
17285
17051
|
}
|
|
17286
17052
|
for (const camera of siteCameras) {
|
|
17287
17053
|
const { host, username, password } = camera;
|
|
@@ -17298,7 +17064,7 @@ function useVehicleService() {
|
|
|
17298
17064
|
removePlateNumber
|
|
17299
17065
|
);
|
|
17300
17066
|
if (responseForDeletion?.statusCode !== 200) {
|
|
17301
|
-
throw new
|
|
17067
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
17302
17068
|
"Failed to delete plate number to ANPR"
|
|
17303
17069
|
);
|
|
17304
17070
|
}
|
|
@@ -17315,7 +17081,7 @@ function useVehicleService() {
|
|
|
17315
17081
|
};
|
|
17316
17082
|
const dahuaResponse = await _addPlateNumber(dahuaPayload);
|
|
17317
17083
|
if (dahuaResponse?.statusCode !== 200) {
|
|
17318
|
-
throw new
|
|
17084
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
17319
17085
|
"Failed to update plate number to ANPR"
|
|
17320
17086
|
);
|
|
17321
17087
|
}
|
|
@@ -17335,7 +17101,7 @@ function useVehicleService() {
|
|
|
17335
17101
|
};
|
|
17336
17102
|
const dahuaResponse = await _updatePlateNumber(dahuaPayload);
|
|
17337
17103
|
if (dahuaResponse?.statusCode !== 200) {
|
|
17338
|
-
throw new
|
|
17104
|
+
throw new import_node_server_utils74.BadRequestError(
|
|
17339
17105
|
"Failed to update plate number to ANPR"
|
|
17340
17106
|
);
|
|
17341
17107
|
}
|
|
@@ -17349,7 +17115,7 @@ function useVehicleService() {
|
|
|
17349
17115
|
...start && { start },
|
|
17350
17116
|
...end && { end },
|
|
17351
17117
|
...unit && {
|
|
17352
|
-
unit: typeof unit === "string" ? new
|
|
17118
|
+
unit: typeof unit === "string" ? new import_mongodb46.ObjectId(unit) : unit
|
|
17353
17119
|
},
|
|
17354
17120
|
...value.recNo && { recNo: value.recNo },
|
|
17355
17121
|
...type && { type: value.type }
|
|
@@ -17357,7 +17123,7 @@ function useVehicleService() {
|
|
|
17357
17123
|
await _updateVehicleById(_id, formattedValue, session);
|
|
17358
17124
|
await session.commitTransaction();
|
|
17359
17125
|
} catch (error) {
|
|
17360
|
-
|
|
17126
|
+
import_node_server_utils74.logger.error("Error in vehicle service update:", error);
|
|
17361
17127
|
await session.abortTransaction();
|
|
17362
17128
|
throw error;
|
|
17363
17129
|
} finally {
|
|
@@ -17379,7 +17145,7 @@ function useVehicleService() {
|
|
|
17379
17145
|
item.unit,
|
|
17380
17146
|
site
|
|
17381
17147
|
);
|
|
17382
|
-
const unitId = unit && unit._id &&
|
|
17148
|
+
const unitId = unit && unit._id && import_mongodb46.ObjectId.isValid(unit._id) ? unit._id.toString() : unit?._id;
|
|
17383
17149
|
return {
|
|
17384
17150
|
...item,
|
|
17385
17151
|
org,
|
|
@@ -17492,6 +17258,7 @@ var loggerDahua = winston.createLogger({
|
|
|
17492
17258
|
});
|
|
17493
17259
|
|
|
17494
17260
|
// src/services/dahua.service.ts
|
|
17261
|
+
var cameraRegistry = /* @__PURE__ */ new Map();
|
|
17495
17262
|
function useDahuaDigest({
|
|
17496
17263
|
host = "",
|
|
17497
17264
|
username = "",
|
|
@@ -17840,7 +17607,33 @@ function useDahuaService() {
|
|
|
17840
17607
|
throw error;
|
|
17841
17608
|
}
|
|
17842
17609
|
}
|
|
17843
|
-
async function
|
|
17610
|
+
async function listenToCamera(camera) {
|
|
17611
|
+
if (!camera?._id) {
|
|
17612
|
+
loggerDahua.error(`Camera _id is required to listen to camera.`);
|
|
17613
|
+
throw new import_node_server_utils75.BadRequestError("Camera _id is required to listen to camera.");
|
|
17614
|
+
}
|
|
17615
|
+
const cameraId = camera._id.toString();
|
|
17616
|
+
if (cameraRegistry.has(cameraId)) {
|
|
17617
|
+
loggerDahua.info(`[${camera.host}] Stopping existing connection for update.`);
|
|
17618
|
+
cameraRegistry.get(cameraId)?.abort();
|
|
17619
|
+
cameraRegistry.delete(cameraId);
|
|
17620
|
+
}
|
|
17621
|
+
const controller = new AbortController();
|
|
17622
|
+
cameraRegistry.set(cameraId, controller);
|
|
17623
|
+
getTrafficJunction(
|
|
17624
|
+
camera.host,
|
|
17625
|
+
camera.username,
|
|
17626
|
+
camera.password,
|
|
17627
|
+
camera.site.toString(),
|
|
17628
|
+
`guard-post-${camera.guardPost}`,
|
|
17629
|
+
camera.direction,
|
|
17630
|
+
cameraId,
|
|
17631
|
+
controller.signal
|
|
17632
|
+
);
|
|
17633
|
+
}
|
|
17634
|
+
async function getTrafficJunction(host = "", username = "", password = "", site = "", gate = "", designation = "", cameraId, signal) {
|
|
17635
|
+
if (signal.aborted)
|
|
17636
|
+
return;
|
|
17844
17637
|
try {
|
|
17845
17638
|
const response = await useDahuaDigest({
|
|
17846
17639
|
host,
|
|
@@ -17864,32 +17657,58 @@ function useDahuaService() {
|
|
|
17864
17657
|
password
|
|
17865
17658
|
);
|
|
17866
17659
|
bufferQueue.setStream(response.res);
|
|
17660
|
+
const onAbort = () => {
|
|
17661
|
+
loggerDahua.info(`[${site}]-[${host}] Abort triggered. Cleaning up...`);
|
|
17662
|
+
if (response.res && !response.res.destroyed) {
|
|
17663
|
+
response.res.once("error", (err) => {
|
|
17664
|
+
if (err?.code === "UND_ERR_ABORTED") {
|
|
17665
|
+
loggerDahua.debug(`[${site}]-[${host}] Stream aborted successfully.`);
|
|
17666
|
+
} else {
|
|
17667
|
+
loggerDahua.error(`[${site}]-[${host}] Stream error during abort:`, err);
|
|
17668
|
+
}
|
|
17669
|
+
});
|
|
17670
|
+
response.res.destroy();
|
|
17671
|
+
}
|
|
17672
|
+
};
|
|
17673
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
17867
17674
|
if ([400, 401, 403, 500].includes(response.statusCode)) {
|
|
17868
17675
|
loggerDahua.error(
|
|
17869
|
-
`[${
|
|
17676
|
+
`[${host}] Connection error:`,
|
|
17870
17677
|
response.statusCode
|
|
17871
17678
|
);
|
|
17872
|
-
throw new
|
|
17679
|
+
throw new import_node_server_utils75.BadRequestError(
|
|
17873
17680
|
`Failed to connect to ANPR: ${response.statusCode}`
|
|
17874
17681
|
);
|
|
17875
17682
|
}
|
|
17876
17683
|
if ([200, 201, 202].includes(response.statusCode)) {
|
|
17877
|
-
loggerDahua.info(`[${
|
|
17878
|
-
console.log(`[${
|
|
17684
|
+
loggerDahua.info(`[${host}] Successfully connected to ANPR.`);
|
|
17685
|
+
console.log(`[${host}] Successfully connected to ANPR.`);
|
|
17879
17686
|
}
|
|
17880
17687
|
response.res.on("data", (chunk) => {
|
|
17688
|
+
if (signal.aborted) {
|
|
17689
|
+
response.res.destroy();
|
|
17690
|
+
return;
|
|
17691
|
+
}
|
|
17881
17692
|
bufferQueue.enqueue(chunk);
|
|
17882
17693
|
});
|
|
17883
17694
|
const handleDisconnect = async (reason, err) => {
|
|
17695
|
+
signal.removeEventListener("abort", onAbort);
|
|
17696
|
+
if (bufferQueue.destroy)
|
|
17697
|
+
bufferQueue.destroy();
|
|
17698
|
+
if (response.res.destroy)
|
|
17699
|
+
response.res.destroy();
|
|
17700
|
+
if (signal.aborted) {
|
|
17701
|
+
loggerDahua.info(`[${site}]-[${host}] Loop terminated. Not reconnecting.`);
|
|
17702
|
+
return;
|
|
17703
|
+
}
|
|
17884
17704
|
loggerDahua.error(
|
|
17885
|
-
`[${site}][${
|
|
17705
|
+
`[${site}]-[${host}] ${reason}`,
|
|
17886
17706
|
err ? err.code || err : ""
|
|
17887
17707
|
);
|
|
17888
|
-
bufferQueue.destroy();
|
|
17889
|
-
if (response.res.destroy)
|
|
17890
|
-
response.res.destroy();
|
|
17891
17708
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17892
|
-
|
|
17709
|
+
if (signal.aborted)
|
|
17710
|
+
return;
|
|
17711
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17893
17712
|
};
|
|
17894
17713
|
response.res.on(
|
|
17895
17714
|
"end",
|
|
@@ -17904,12 +17723,16 @@ function useDahuaService() {
|
|
|
17904
17723
|
(err) => handleDisconnect("Connection error:", err)
|
|
17905
17724
|
);
|
|
17906
17725
|
} catch (error) {
|
|
17726
|
+
if (signal.aborted)
|
|
17727
|
+
return;
|
|
17907
17728
|
loggerDahua.error(
|
|
17908
17729
|
`[${site}][${gate}] Initial connect error:`,
|
|
17909
17730
|
error.code || error
|
|
17910
17731
|
);
|
|
17911
17732
|
await new Promise((res) => setTimeout(res, 5e3));
|
|
17912
|
-
|
|
17733
|
+
if (signal.aborted)
|
|
17734
|
+
return;
|
|
17735
|
+
getTrafficJunction(host, username, password, site, gate, designation, cameraId, signal);
|
|
17913
17736
|
}
|
|
17914
17737
|
}
|
|
17915
17738
|
async function addPlateNumber(value) {
|
|
@@ -17926,7 +17749,7 @@ function useDahuaService() {
|
|
|
17926
17749
|
});
|
|
17927
17750
|
const { error } = validation.validate(value);
|
|
17928
17751
|
if (error) {
|
|
17929
|
-
throw new
|
|
17752
|
+
throw new import_node_server_utils75.BadRequestError(`Validation error: ${error.message}`);
|
|
17930
17753
|
}
|
|
17931
17754
|
value.owner = String(value.owner ?? "").substring(0, 15) || "unknown";
|
|
17932
17755
|
const _openGate = String(value.isOpenGate);
|
|
@@ -17942,7 +17765,7 @@ function useDahuaService() {
|
|
|
17942
17765
|
return response;
|
|
17943
17766
|
} catch (error2) {
|
|
17944
17767
|
loggerDahua.error(`[${value.host}] Error adding plate number:`, error2);
|
|
17945
|
-
throw new
|
|
17768
|
+
throw new import_node_server_utils75.BadRequestError(`Failed to add plate number: ${error2.message}`);
|
|
17946
17769
|
}
|
|
17947
17770
|
}
|
|
17948
17771
|
async function updatePlateNumber(value) {
|
|
@@ -17960,7 +17783,7 @@ function useDahuaService() {
|
|
|
17960
17783
|
});
|
|
17961
17784
|
const { error } = validation.validate(value);
|
|
17962
17785
|
if (error) {
|
|
17963
|
-
throw new
|
|
17786
|
+
throw new import_node_server_utils75.BadRequestError(`Validation error: ${error.message}`);
|
|
17964
17787
|
}
|
|
17965
17788
|
value.owner = value.owner || "unknown";
|
|
17966
17789
|
let _isOpenGate;
|
|
@@ -17979,7 +17802,7 @@ function useDahuaService() {
|
|
|
17979
17802
|
return response;
|
|
17980
17803
|
} catch (error2) {
|
|
17981
17804
|
loggerDahua.error(`[${value.host}] Error updating plate number:`, error2);
|
|
17982
|
-
throw new
|
|
17805
|
+
throw new import_node_server_utils75.BadRequestError(
|
|
17983
17806
|
`Failed to update plate number: ${error2.message}`
|
|
17984
17807
|
);
|
|
17985
17808
|
}
|
|
@@ -17994,7 +17817,7 @@ function useDahuaService() {
|
|
|
17994
17817
|
});
|
|
17995
17818
|
const { error } = validation.validate(value);
|
|
17996
17819
|
if (error) {
|
|
17997
|
-
throw new
|
|
17820
|
+
throw new import_node_server_utils75.BadRequestError(`Validation error: ${error.message}`);
|
|
17998
17821
|
}
|
|
17999
17822
|
try {
|
|
18000
17823
|
const response = await useDahuaDigest({
|
|
@@ -18018,7 +17841,7 @@ function useDahuaService() {
|
|
|
18018
17841
|
});
|
|
18019
17842
|
const { error } = validation.validate(value);
|
|
18020
17843
|
if (error) {
|
|
18021
|
-
throw new
|
|
17844
|
+
throw new import_node_server_utils75.BadRequestError(`Validation error: ${error.message}`);
|
|
18022
17845
|
}
|
|
18023
17846
|
try {
|
|
18024
17847
|
const response = await useDahuaDigest({
|
|
@@ -18050,7 +17873,7 @@ function useDahuaService() {
|
|
|
18050
17873
|
});
|
|
18051
17874
|
const { error } = validation.validate(value);
|
|
18052
17875
|
if (error) {
|
|
18053
|
-
throw new
|
|
17876
|
+
throw new import_node_server_utils75.BadRequestError(`Validation error: ${error.message}`);
|
|
18054
17877
|
}
|
|
18055
17878
|
value.owner = String(value.owner ?? "").substring(0, 15) || "unknown";
|
|
18056
17879
|
value.vehicleType = String(value.vehicleType ?? "").substring(0, 31) || "unknown";
|
|
@@ -18068,14 +17891,14 @@ function useDahuaService() {
|
|
|
18068
17891
|
return response;
|
|
18069
17892
|
} catch (error2) {
|
|
18070
17893
|
loggerDahua.error(`[${value.host}] Error bulk add plate number:`, error2);
|
|
18071
|
-
throw new
|
|
17894
|
+
throw new import_node_server_utils75.BadRequestError(
|
|
18072
17895
|
`Failed bulk adding plate number: ${error2.message}`
|
|
18073
17896
|
);
|
|
18074
17897
|
}
|
|
18075
17898
|
}
|
|
18076
17899
|
return {
|
|
18077
17900
|
getSnapshot,
|
|
18078
|
-
|
|
17901
|
+
listenToCamera,
|
|
18079
17902
|
addPlateNumber,
|
|
18080
17903
|
removePlateNumber,
|
|
18081
17904
|
updatePlateNumber,
|
|
@@ -18084,7 +17907,400 @@ function useDahuaService() {
|
|
|
18084
17907
|
};
|
|
18085
17908
|
}
|
|
18086
17909
|
|
|
17910
|
+
// src/repositories/site-camera.repo.ts
|
|
17911
|
+
function useSiteCameraRepo() {
|
|
17912
|
+
const db = import_node_server_utils76.useAtlas.getDb();
|
|
17913
|
+
if (!db) {
|
|
17914
|
+
throw new Error("Unable to connect to server.");
|
|
17915
|
+
}
|
|
17916
|
+
const namespace_collection = "site.cameras";
|
|
17917
|
+
const collection = db.collection(namespace_collection);
|
|
17918
|
+
const { delNamespace, getCache, setCache } = (0, import_node_server_utils76.useCache)(namespace_collection);
|
|
17919
|
+
async function createIndexes() {
|
|
17920
|
+
try {
|
|
17921
|
+
await collection.createIndexes([
|
|
17922
|
+
{
|
|
17923
|
+
key: { site: 1 }
|
|
17924
|
+
},
|
|
17925
|
+
{
|
|
17926
|
+
key: { type: 1 }
|
|
17927
|
+
},
|
|
17928
|
+
{
|
|
17929
|
+
key: { host: 1, type: 1, status: 1, site: 1 },
|
|
17930
|
+
unique: true,
|
|
17931
|
+
partialFilterExpression: { status: "active" }
|
|
17932
|
+
}
|
|
17933
|
+
]);
|
|
17934
|
+
return `Successfully created ${namespace_collection} indexes.`;
|
|
17935
|
+
} catch (error) {
|
|
17936
|
+
import_node_server_utils76.logger.log({
|
|
17937
|
+
level: "error",
|
|
17938
|
+
message: error.message
|
|
17939
|
+
});
|
|
17940
|
+
}
|
|
17941
|
+
}
|
|
17942
|
+
async function add(value, session) {
|
|
17943
|
+
try {
|
|
17944
|
+
value = MSiteCamera(value);
|
|
17945
|
+
const res = await collection.insertOne(value, { session });
|
|
17946
|
+
delCachedData();
|
|
17947
|
+
return res.insertedId;
|
|
17948
|
+
} catch (error) {
|
|
17949
|
+
import_node_server_utils76.logger.log({
|
|
17950
|
+
level: "error",
|
|
17951
|
+
message: error.message
|
|
17952
|
+
});
|
|
17953
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
17954
|
+
if (isDuplicated) {
|
|
17955
|
+
throw new import_node_server_utils76.BadRequestError("ANPR already exist.");
|
|
17956
|
+
}
|
|
17957
|
+
if (error instanceof import_node_server_utils76.AppError) {
|
|
17958
|
+
throw error;
|
|
17959
|
+
} else {
|
|
17960
|
+
throw new Error("Failed to create ANPR.");
|
|
17961
|
+
}
|
|
17962
|
+
}
|
|
17963
|
+
}
|
|
17964
|
+
async function getAll(value) {
|
|
17965
|
+
value.page = value.page ? value.page - 1 : 0;
|
|
17966
|
+
value.limit = value.limit || 10;
|
|
17967
|
+
const cacheKeyOptions = {
|
|
17968
|
+
type: value.type,
|
|
17969
|
+
page: value.page,
|
|
17970
|
+
limit: value.limit,
|
|
17971
|
+
...value.direction && { direction: value.direction }
|
|
17972
|
+
};
|
|
17973
|
+
const query = {
|
|
17974
|
+
type: value.type,
|
|
17975
|
+
...value.direction && {
|
|
17976
|
+
direction: {
|
|
17977
|
+
$in: Array.isArray(value.direction) ? value.direction : [value.direction]
|
|
17978
|
+
}
|
|
17979
|
+
}
|
|
17980
|
+
};
|
|
17981
|
+
if (value.site) {
|
|
17982
|
+
cacheKeyOptions.site = value.site;
|
|
17983
|
+
try {
|
|
17984
|
+
value.site = new import_mongodb47.ObjectId(value.site);
|
|
17985
|
+
query.site = value.site;
|
|
17986
|
+
} catch (error) {
|
|
17987
|
+
throw new import_node_server_utils76.BadRequestError("Invalid site ID format");
|
|
17988
|
+
}
|
|
17989
|
+
}
|
|
17990
|
+
const cacheKey = (0, import_node_server_utils76.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
17991
|
+
const cachedData = await getCache(cacheKey);
|
|
17992
|
+
if (cachedData) {
|
|
17993
|
+
return cachedData;
|
|
17994
|
+
}
|
|
17995
|
+
try {
|
|
17996
|
+
const items = await collection.aggregate([
|
|
17997
|
+
{
|
|
17998
|
+
$match: query
|
|
17999
|
+
},
|
|
18000
|
+
{
|
|
18001
|
+
$skip: value.page * value.limit
|
|
18002
|
+
},
|
|
18003
|
+
{
|
|
18004
|
+
$limit: value.limit
|
|
18005
|
+
},
|
|
18006
|
+
{
|
|
18007
|
+
$project: {
|
|
18008
|
+
password: 0
|
|
18009
|
+
}
|
|
18010
|
+
}
|
|
18011
|
+
]).toArray();
|
|
18012
|
+
const length = await collection.countDocuments(query);
|
|
18013
|
+
const data = (0, import_node_server_utils76.paginate)(items, value.page, value.limit, length);
|
|
18014
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
18015
|
+
import_node_server_utils76.logger.info(`Cache set for key: ${cacheKey}`);
|
|
18016
|
+
}).catch((err) => {
|
|
18017
|
+
import_node_server_utils76.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
18018
|
+
});
|
|
18019
|
+
return data;
|
|
18020
|
+
} catch (error) {
|
|
18021
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
18022
|
+
throw error;
|
|
18023
|
+
}
|
|
18024
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
18025
|
+
}
|
|
18026
|
+
}
|
|
18027
|
+
async function findSiteCameras({ site, type }) {
|
|
18028
|
+
const pipeline = [];
|
|
18029
|
+
const cacheObject = {};
|
|
18030
|
+
if (type) {
|
|
18031
|
+
cacheObject.type = type;
|
|
18032
|
+
pipeline.push({ $match: { "anprs.type": type } });
|
|
18033
|
+
}
|
|
18034
|
+
if (site) {
|
|
18035
|
+
const _site = new import_mongodb47.ObjectId(site);
|
|
18036
|
+
cacheObject.site = site;
|
|
18037
|
+
pipeline.push({ $match: { site: _site } });
|
|
18038
|
+
}
|
|
18039
|
+
pipeline.push({
|
|
18040
|
+
$project: {
|
|
18041
|
+
_id: 1,
|
|
18042
|
+
site: 1,
|
|
18043
|
+
cameras: 1
|
|
18044
|
+
}
|
|
18045
|
+
});
|
|
18046
|
+
try {
|
|
18047
|
+
const items = await collection.aggregate(pipeline).toArray();
|
|
18048
|
+
return items;
|
|
18049
|
+
} catch (error) {
|
|
18050
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
18051
|
+
throw error;
|
|
18052
|
+
}
|
|
18053
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
18054
|
+
}
|
|
18055
|
+
}
|
|
18056
|
+
function delCachedData() {
|
|
18057
|
+
delNamespace().then(() => {
|
|
18058
|
+
import_node_server_utils76.logger.log({
|
|
18059
|
+
level: "info",
|
|
18060
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
18061
|
+
});
|
|
18062
|
+
}).catch((err) => {
|
|
18063
|
+
import_node_server_utils76.logger.log({
|
|
18064
|
+
level: "error",
|
|
18065
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
18066
|
+
});
|
|
18067
|
+
});
|
|
18068
|
+
}
|
|
18069
|
+
async function getBySite(site, options = {}) {
|
|
18070
|
+
const _site = (0, import_node_server_utils76.toObjectId)(site);
|
|
18071
|
+
const cacheKeyOptions = {
|
|
18072
|
+
site,
|
|
18073
|
+
tag: "get-by-site",
|
|
18074
|
+
...options.category && { category: options.category },
|
|
18075
|
+
...options.type && { type: options.type },
|
|
18076
|
+
...options.guardPost && { guardPost: options.guardPost }
|
|
18077
|
+
};
|
|
18078
|
+
const cacheKey = (0, import_node_server_utils76.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
18079
|
+
const cachedData = await getCache(cacheKey);
|
|
18080
|
+
if (cachedData) {
|
|
18081
|
+
return cachedData;
|
|
18082
|
+
}
|
|
18083
|
+
try {
|
|
18084
|
+
delete cacheKeyOptions.tag;
|
|
18085
|
+
cacheKeyOptions.site = _site;
|
|
18086
|
+
const item = await collection.findOne(cacheKeyOptions);
|
|
18087
|
+
setCache(cacheKey, item, 15 * 60).then(() => {
|
|
18088
|
+
import_node_server_utils76.logger.log({
|
|
18089
|
+
level: "info",
|
|
18090
|
+
message: `Cache set for getBySite: ${cacheKey}`
|
|
18091
|
+
});
|
|
18092
|
+
}).catch((err) => {
|
|
18093
|
+
import_node_server_utils76.logger.log({
|
|
18094
|
+
level: "error",
|
|
18095
|
+
message: `Failed to set cache for getBySite: ${err.message}`
|
|
18096
|
+
});
|
|
18097
|
+
});
|
|
18098
|
+
return item;
|
|
18099
|
+
} catch (error) {
|
|
18100
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
18101
|
+
throw error;
|
|
18102
|
+
}
|
|
18103
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
18104
|
+
}
|
|
18105
|
+
}
|
|
18106
|
+
async function getBySiteGuardPost(site, guardPost) {
|
|
18107
|
+
try {
|
|
18108
|
+
site = new import_mongodb47.ObjectId(site);
|
|
18109
|
+
} catch (error) {
|
|
18110
|
+
throw new import_node_server_utils76.BadRequestError("Invalid site ID format");
|
|
18111
|
+
}
|
|
18112
|
+
const cacheKeyOptions = {
|
|
18113
|
+
site,
|
|
18114
|
+
guardPost,
|
|
18115
|
+
tag: "get-by-site"
|
|
18116
|
+
};
|
|
18117
|
+
const cacheKey = (0, import_node_server_utils76.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
18118
|
+
const cachedData = await getCache(cacheKey);
|
|
18119
|
+
if (cachedData) {
|
|
18120
|
+
return cachedData;
|
|
18121
|
+
}
|
|
18122
|
+
try {
|
|
18123
|
+
delete cacheKeyOptions.tag;
|
|
18124
|
+
const item = await collection.findOne({
|
|
18125
|
+
site,
|
|
18126
|
+
guardPost: { $gt: guardPost }
|
|
18127
|
+
});
|
|
18128
|
+
setCache(cacheKey, item, 15 * 60).then(() => {
|
|
18129
|
+
import_node_server_utils76.logger.log({
|
|
18130
|
+
level: "info",
|
|
18131
|
+
message: `Cache set for getBySite: ${cacheKey}`
|
|
18132
|
+
});
|
|
18133
|
+
}).catch((err) => {
|
|
18134
|
+
import_node_server_utils76.logger.log({
|
|
18135
|
+
level: "error",
|
|
18136
|
+
message: `Failed to set cache for getBySite: ${err.message}`
|
|
18137
|
+
});
|
|
18138
|
+
});
|
|
18139
|
+
return item;
|
|
18140
|
+
} catch (error) {
|
|
18141
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
18142
|
+
throw error;
|
|
18143
|
+
}
|
|
18144
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
18145
|
+
}
|
|
18146
|
+
}
|
|
18147
|
+
async function getBySites(site, options = {}) {
|
|
18148
|
+
try {
|
|
18149
|
+
site = new import_mongodb47.ObjectId(site);
|
|
18150
|
+
} catch (error) {
|
|
18151
|
+
throw new import_node_server_utils76.BadRequestError("Invalid site ID format");
|
|
18152
|
+
}
|
|
18153
|
+
const cacheKeyOptions = { site };
|
|
18154
|
+
if (options.category) {
|
|
18155
|
+
cacheKeyOptions.category = options.category;
|
|
18156
|
+
}
|
|
18157
|
+
if (options.type) {
|
|
18158
|
+
cacheKeyOptions.type = options.type;
|
|
18159
|
+
}
|
|
18160
|
+
if (options.direction) {
|
|
18161
|
+
cacheKeyOptions.direction = options.direction;
|
|
18162
|
+
}
|
|
18163
|
+
const cacheKey = (0, import_node_server_utils76.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
18164
|
+
const cachedData = await getCache(cacheKey);
|
|
18165
|
+
if (cachedData) {
|
|
18166
|
+
return cachedData;
|
|
18167
|
+
}
|
|
18168
|
+
try {
|
|
18169
|
+
const items = await collection.find(cacheKeyOptions);
|
|
18170
|
+
setCache(cacheKey, items, 15 * 60).then(() => {
|
|
18171
|
+
import_node_server_utils76.logger.log({
|
|
18172
|
+
level: "info",
|
|
18173
|
+
message: `Cache set for getBySite: ${cacheKey}`
|
|
18174
|
+
});
|
|
18175
|
+
}).catch((err) => {
|
|
18176
|
+
import_node_server_utils76.logger.log({
|
|
18177
|
+
level: "error",
|
|
18178
|
+
message: `Failed to set cache for getBySite: ${err.message}`
|
|
18179
|
+
});
|
|
18180
|
+
});
|
|
18181
|
+
return items;
|
|
18182
|
+
} catch (error) {
|
|
18183
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
18184
|
+
throw error;
|
|
18185
|
+
}
|
|
18186
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
18187
|
+
}
|
|
18188
|
+
}
|
|
18189
|
+
async function updateById(_id, value, session) {
|
|
18190
|
+
const { error } = schemaUpdateSiteCamera.validate(value);
|
|
18191
|
+
if (error) {
|
|
18192
|
+
import_node_server_utils76.logger.info(`Site Camera Management: ${error.message}`);
|
|
18193
|
+
throw new import_node_server_utils76.BadRequestError(error.message);
|
|
18194
|
+
}
|
|
18195
|
+
try {
|
|
18196
|
+
_id = new import_mongodb47.ObjectId(_id);
|
|
18197
|
+
} catch (error2) {
|
|
18198
|
+
throw new import_node_server_utils76.BadRequestError("Invalid camera ID format");
|
|
18199
|
+
}
|
|
18200
|
+
try {
|
|
18201
|
+
value.updatedAt = /* @__PURE__ */ new Date();
|
|
18202
|
+
const result = await collection.findOneAndUpdate({ _id }, { $set: value }, { session, returnDocument: "after" });
|
|
18203
|
+
if (!result?._id) {
|
|
18204
|
+
throw new import_node_server_utils76.BadRequestError("Site camera not found.");
|
|
18205
|
+
}
|
|
18206
|
+
const { listenToCamera } = useDahuaService();
|
|
18207
|
+
await listenToCamera(result);
|
|
18208
|
+
delCachedData();
|
|
18209
|
+
return "Successfully updated site camera.";
|
|
18210
|
+
} catch (error2) {
|
|
18211
|
+
import_node_server_utils76.logger.log({
|
|
18212
|
+
level: "error",
|
|
18213
|
+
message: error2.message
|
|
18214
|
+
});
|
|
18215
|
+
const isDuplicated = error2.message.includes("duplicate");
|
|
18216
|
+
if (isDuplicated) {
|
|
18217
|
+
throw new import_node_server_utils76.BadRequestError("ANPR already exist.");
|
|
18218
|
+
}
|
|
18219
|
+
if (error2 instanceof import_node_server_utils76.AppError) {
|
|
18220
|
+
throw error2;
|
|
18221
|
+
}
|
|
18222
|
+
throw new Error("Failed to update ANPR.");
|
|
18223
|
+
}
|
|
18224
|
+
}
|
|
18225
|
+
async function deleteById(_id, session) {
|
|
18226
|
+
try {
|
|
18227
|
+
_id = new import_mongodb47.ObjectId(_id);
|
|
18228
|
+
} catch (error) {
|
|
18229
|
+
throw new import_node_server_utils76.BadRequestError("Invalid camera ID format");
|
|
18230
|
+
}
|
|
18231
|
+
try {
|
|
18232
|
+
await collection.deleteOne({ _id }, { session });
|
|
18233
|
+
delCachedData();
|
|
18234
|
+
return "Successfully deleted site camera.";
|
|
18235
|
+
} catch (error) {
|
|
18236
|
+
import_node_server_utils76.logger.log({
|
|
18237
|
+
level: "error",
|
|
18238
|
+
message: error.message
|
|
18239
|
+
});
|
|
18240
|
+
if (error instanceof import_node_server_utils76.AppError) {
|
|
18241
|
+
throw error;
|
|
18242
|
+
}
|
|
18243
|
+
throw new Error("Failed to delete site camera.");
|
|
18244
|
+
}
|
|
18245
|
+
}
|
|
18246
|
+
async function getAllCameraWithPassword(value) {
|
|
18247
|
+
value.page = value.page ? value.page - 1 : 0;
|
|
18248
|
+
value.limit = value.limit || 10;
|
|
18249
|
+
const query = {
|
|
18250
|
+
type: value.type,
|
|
18251
|
+
...value.direction && {
|
|
18252
|
+
direction: {
|
|
18253
|
+
$in: Array.isArray(value.direction) ? value.direction : [value.direction]
|
|
18254
|
+
}
|
|
18255
|
+
}
|
|
18256
|
+
};
|
|
18257
|
+
if (value.site) {
|
|
18258
|
+
try {
|
|
18259
|
+
value.site = new import_mongodb47.ObjectId(value.site);
|
|
18260
|
+
query.site = value.site;
|
|
18261
|
+
} catch (error) {
|
|
18262
|
+
throw new import_node_server_utils76.BadRequestError("Invalid site ID format");
|
|
18263
|
+
}
|
|
18264
|
+
}
|
|
18265
|
+
try {
|
|
18266
|
+
const items = await collection.aggregate([
|
|
18267
|
+
{
|
|
18268
|
+
$match: query
|
|
18269
|
+
},
|
|
18270
|
+
{
|
|
18271
|
+
$skip: value.page * value.limit
|
|
18272
|
+
},
|
|
18273
|
+
{
|
|
18274
|
+
$limit: value.limit
|
|
18275
|
+
}
|
|
18276
|
+
]).toArray();
|
|
18277
|
+
const length = await collection.countDocuments(query);
|
|
18278
|
+
const data = (0, import_node_server_utils76.paginate)(items, value.page, value.limit, length);
|
|
18279
|
+
return data;
|
|
18280
|
+
} catch (error) {
|
|
18281
|
+
if (error instanceof import_node_server_utils76.BadRequestError) {
|
|
18282
|
+
throw error;
|
|
18283
|
+
}
|
|
18284
|
+
throw new import_node_server_utils76.BadRequestError("Failed to retrieve site cameras.");
|
|
18285
|
+
}
|
|
18286
|
+
}
|
|
18287
|
+
return {
|
|
18288
|
+
createIndexes,
|
|
18289
|
+
add,
|
|
18290
|
+
getAll,
|
|
18291
|
+
findSiteCameras,
|
|
18292
|
+
getBySite,
|
|
18293
|
+
getBySites,
|
|
18294
|
+
delCachedData,
|
|
18295
|
+
getBySiteGuardPost,
|
|
18296
|
+
updateById,
|
|
18297
|
+
deleteById,
|
|
18298
|
+
getAllCameraWithPassword
|
|
18299
|
+
};
|
|
18300
|
+
}
|
|
18301
|
+
|
|
18087
18302
|
// src/services/site.service.ts
|
|
18303
|
+
var import_joi41 = __toESM(require("joi"));
|
|
18088
18304
|
function useSiteService() {
|
|
18089
18305
|
const {
|
|
18090
18306
|
createSite: _createSite,
|
|
@@ -19624,7 +19840,7 @@ function useVehicleController() {
|
|
|
19624
19840
|
next(new import_node_server_utils87.BadRequestError("Spreadsheet file is required."));
|
|
19625
19841
|
return;
|
|
19626
19842
|
}
|
|
19627
|
-
const { originalname, path:
|
|
19843
|
+
const { originalname, path: path4 } = req.file;
|
|
19628
19844
|
const lowerName = originalname.toLowerCase();
|
|
19629
19845
|
const rowSchema = import_joi46.default.object({
|
|
19630
19846
|
fullName: import_joi46.default.string().trim().required(),
|
|
@@ -19663,7 +19879,7 @@ function useVehicleController() {
|
|
|
19663
19879
|
let rows = [];
|
|
19664
19880
|
if (lowerName.endsWith(".xlsx") || lowerName.endsWith(".xls")) {
|
|
19665
19881
|
const workbook = new import_exceljs.default.Workbook();
|
|
19666
|
-
await workbook.xlsx.readFile(
|
|
19882
|
+
await workbook.xlsx.readFile(path4);
|
|
19667
19883
|
const worksheet = workbook.worksheets[0];
|
|
19668
19884
|
if (!worksheet) {
|
|
19669
19885
|
next(
|
|
@@ -19689,7 +19905,7 @@ function useVehicleController() {
|
|
|
19689
19905
|
} else if (lowerName.endsWith(".csv")) {
|
|
19690
19906
|
rows = await new Promise((resolve, reject) => {
|
|
19691
19907
|
const parsed = [];
|
|
19692
|
-
import_fs2.default.createReadStream(
|
|
19908
|
+
import_fs2.default.createReadStream(path4).pipe((0, import_csv_parser.default)()).on("data", (row) => parsed.push(row)).on("end", () => resolve(parsed)).on("error", reject);
|
|
19693
19909
|
});
|
|
19694
19910
|
} else {
|
|
19695
19911
|
next(
|
|
@@ -19728,7 +19944,7 @@ function useVehicleController() {
|
|
|
19728
19944
|
validationErrors: invalidRows,
|
|
19729
19945
|
data
|
|
19730
19946
|
});
|
|
19731
|
-
import_fs2.default.unlink(
|
|
19947
|
+
import_fs2.default.unlink(path4, () => {
|
|
19732
19948
|
});
|
|
19733
19949
|
} catch (error) {
|
|
19734
19950
|
import_node_server_utils87.logger.log({ level: "error", message: error.message });
|
|
@@ -20124,14 +20340,7 @@ function useSiteCameraService() {
|
|
|
20124
20340
|
for (let index = 0; index < siteCameras.length; index++) {
|
|
20125
20341
|
const siteCamera = siteCameras[index];
|
|
20126
20342
|
if (siteCamera && siteCamera.status === "active" && siteCamera.host && siteCamera.username && siteCamera.password && siteCamera.site && siteCamera.guardPost) {
|
|
20127
|
-
dahuaService.
|
|
20128
|
-
siteCamera.host,
|
|
20129
|
-
siteCamera.username,
|
|
20130
|
-
siteCamera.password,
|
|
20131
|
-
siteCamera.site.toString(),
|
|
20132
|
-
`guard-post-${siteCamera.guardPost}`,
|
|
20133
|
-
siteCamera.direction
|
|
20134
|
-
);
|
|
20343
|
+
dahuaService.listenToCamera(siteCamera);
|
|
20135
20344
|
}
|
|
20136
20345
|
}
|
|
20137
20346
|
}
|
|
@@ -24128,7 +24337,6 @@ var import_node_server_utils108 = require("@7365admin1/node-server-utils");
|
|
|
24128
24337
|
|
|
24129
24338
|
// src/services/person.service.ts
|
|
24130
24339
|
var import_node_server_utils107 = require("@7365admin1/node-server-utils");
|
|
24131
|
-
var import_path = __toESM(require("path"));
|
|
24132
24340
|
function usePersonService() {
|
|
24133
24341
|
const MailerConfig = {
|
|
24134
24342
|
host: MAILER_TRANSPORT_HOST,
|
|
@@ -24343,13 +24551,8 @@ function usePersonService() {
|
|
|
24343
24551
|
value.status = "active";
|
|
24344
24552
|
}
|
|
24345
24553
|
await _reviewResidentPerson(id, value, session);
|
|
24346
|
-
const logoPath =
|
|
24347
|
-
|
|
24348
|
-
"public",
|
|
24349
|
-
"images",
|
|
24350
|
-
"seven-365.svg"
|
|
24351
|
-
);
|
|
24352
|
-
const statusIconPath = import_path.default.join(__dirname, "public", "icons");
|
|
24554
|
+
const logoPath = `${STORAGE_API}/seven-365.svg`;
|
|
24555
|
+
const statusIconPath = STORAGE_API;
|
|
24353
24556
|
let title = "";
|
|
24354
24557
|
let message2 = "";
|
|
24355
24558
|
let hideLogin = true;
|
|
@@ -31317,14 +31520,36 @@ function useSiteBillingConfigurationController() {
|
|
|
31317
31520
|
// src/models/event-management.model.ts
|
|
31318
31521
|
var import_mongodb84 = require("mongodb");
|
|
31319
31522
|
var import_joi81 = __toESM(require("joi"));
|
|
31523
|
+
var EventStatus = /* @__PURE__ */ ((EventStatus2) => {
|
|
31524
|
+
EventStatus2["PLANNED"] = "planned";
|
|
31525
|
+
EventStatus2["IN_PROGRESS"] = "in_progress";
|
|
31526
|
+
EventStatus2["COMPLETED"] = "completed";
|
|
31527
|
+
return EventStatus2;
|
|
31528
|
+
})(EventStatus || {});
|
|
31529
|
+
var EventSort = /* @__PURE__ */ ((EventSort2) => {
|
|
31530
|
+
EventSort2["CREATED_AT"] = "createdAt";
|
|
31531
|
+
EventSort2["NAME"] = "name";
|
|
31532
|
+
EventSort2["ID"] = "_id";
|
|
31533
|
+
return EventSort2;
|
|
31534
|
+
})(EventSort || {});
|
|
31535
|
+
var EventOrder = /* @__PURE__ */ ((EventOrder2) => {
|
|
31536
|
+
EventOrder2["ASC"] = "asc";
|
|
31537
|
+
EventOrder2["DESC"] = "desc";
|
|
31538
|
+
return EventOrder2;
|
|
31539
|
+
})(EventOrder || {});
|
|
31540
|
+
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
31541
|
+
EventType2["TASK"] = "TASK";
|
|
31542
|
+
EventType2["EVENT"] = "EVENT";
|
|
31543
|
+
return EventType2;
|
|
31544
|
+
})(EventType || {});
|
|
31320
31545
|
var schemaEventManagement = import_joi81.default.object({
|
|
31321
31546
|
_id: import_joi81.default.string().optional().allow(null, ""),
|
|
31322
31547
|
site: import_joi81.default.string().required(),
|
|
31323
31548
|
title: import_joi81.default.string().required(),
|
|
31324
31549
|
description: import_joi81.default.string().optional().allow(""),
|
|
31325
31550
|
dateTime: import_joi81.default.date().iso().required(),
|
|
31326
|
-
status: import_joi81.default.string().optional().default("planned"),
|
|
31327
|
-
type: import_joi81.default.string().optional().default("TASK")
|
|
31551
|
+
status: import_joi81.default.string().optional().default("planned" /* PLANNED */),
|
|
31552
|
+
type: import_joi81.default.string().optional().default("TASK" /* TASK */)
|
|
31328
31553
|
});
|
|
31329
31554
|
var schemaUpdateEventManagement = import_joi81.default.object({
|
|
31330
31555
|
_id: import_joi81.default.string().hex().required(),
|
|
@@ -31355,8 +31580,8 @@ function MEventManagement(value) {
|
|
|
31355
31580
|
title: value.title,
|
|
31356
31581
|
description: value.description ?? "",
|
|
31357
31582
|
dateTime: new Date(value.dateTime),
|
|
31358
|
-
status: value.status ?? "planned"
|
|
31359
|
-
type: value.type ?? "TASK"
|
|
31583
|
+
status: value.status ?? "planned" /* PLANNED */,
|
|
31584
|
+
type: value.type ?? "TASK" /* TASK */,
|
|
31360
31585
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
31361
31586
|
updatedAt: value.updatedAt,
|
|
31362
31587
|
deletedAt: value.deletedAt
|
|
@@ -31455,7 +31680,8 @@ function useEventManagementRepo() {
|
|
|
31455
31680
|
sort: JSON.stringify(sort),
|
|
31456
31681
|
page,
|
|
31457
31682
|
limit,
|
|
31458
|
-
...type && { type }
|
|
31683
|
+
...type && { type },
|
|
31684
|
+
...date && { dateTime: date }
|
|
31459
31685
|
};
|
|
31460
31686
|
if (search) {
|
|
31461
31687
|
query.$or = [{ title: { $regex: search, $options: "i" } }];
|
|
@@ -31658,8 +31884,8 @@ function useEventManagementService() {
|
|
|
31658
31884
|
} = useEventManagementRepo();
|
|
31659
31885
|
async function add(value) {
|
|
31660
31886
|
const session = import_node_server_utils147.useAtlas.getClient()?.startSession();
|
|
31661
|
-
session?.startTransaction();
|
|
31662
31887
|
try {
|
|
31888
|
+
session?.startTransaction();
|
|
31663
31889
|
await _add(value, session);
|
|
31664
31890
|
await session?.commitTransaction();
|
|
31665
31891
|
return "Successfully added event.";
|
|
@@ -31722,67 +31948,51 @@ function useEventManagementController() {
|
|
|
31722
31948
|
deleteEventManagementById: _deleteEventManagementById
|
|
31723
31949
|
} = useEventManagementRepo();
|
|
31724
31950
|
async function add(req, res, next) {
|
|
31725
|
-
const payload = { ...req.body };
|
|
31726
|
-
const { error } = schemaEventManagement.validate(payload, {
|
|
31727
|
-
abortEarly: false
|
|
31728
|
-
});
|
|
31729
|
-
if (error) {
|
|
31730
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
31731
|
-
import_node_server_utils148.logger.log({ level: "error", message: messages });
|
|
31732
|
-
next(new import_node_server_utils148.BadRequestError(messages));
|
|
31733
|
-
return;
|
|
31734
|
-
}
|
|
31735
31951
|
try {
|
|
31736
|
-
const
|
|
31952
|
+
const { error, value } = schemaEventManagement.validate(req.body, {
|
|
31953
|
+
abortEarly: false
|
|
31954
|
+
});
|
|
31955
|
+
if (error) {
|
|
31956
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
31957
|
+
import_node_server_utils148.logger.log({ level: "error", message: messages });
|
|
31958
|
+
next(new import_node_server_utils148.BadRequestError(messages));
|
|
31959
|
+
return;
|
|
31960
|
+
}
|
|
31961
|
+
const data = await _add(value);
|
|
31737
31962
|
res.status(201).json(data);
|
|
31738
31963
|
return;
|
|
31739
|
-
} catch (
|
|
31740
|
-
import_node_server_utils148.logger.log({ level: "error", message:
|
|
31741
|
-
next(
|
|
31964
|
+
} catch (error) {
|
|
31965
|
+
import_node_server_utils148.logger.log({ level: "error", message: error.message });
|
|
31966
|
+
next(error);
|
|
31742
31967
|
return;
|
|
31743
31968
|
}
|
|
31744
31969
|
}
|
|
31745
31970
|
async function getAll(req, res, next) {
|
|
31746
|
-
const allowedFields = ["createdAt", "name"];
|
|
31747
|
-
const allowedOrder = ["asc", "desc"];
|
|
31748
|
-
const validation = import_joi82.default.object({
|
|
31749
|
-
search: import_joi82.default.string().optional().allow("", null),
|
|
31750
|
-
page: import_joi82.default.number().integer().min(1).allow("", null).default(1),
|
|
31751
|
-
limit: import_joi82.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
31752
|
-
sort: import_joi82.default.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
|
|
31753
|
-
order: import_joi82.default.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
|
|
31754
|
-
site: import_joi82.default.string().hex().required(),
|
|
31755
|
-
status: import_joi82.default.string().optional(),
|
|
31756
|
-
type: import_joi82.default.string().optional().valid("TASK", "EVENT").allow(null, ""),
|
|
31757
|
-
date: import_joi82.default.string().optional().allow(null, "")
|
|
31758
|
-
});
|
|
31759
|
-
const query = { ...req.query };
|
|
31760
|
-
const { error } = validation.validate(query, {
|
|
31761
|
-
abortEarly: false
|
|
31762
|
-
});
|
|
31763
|
-
if (error) {
|
|
31764
|
-
const messages = error.details.map((d) => d.message).join(", ");
|
|
31765
|
-
import_node_server_utils148.logger.log({ level: "error", message: messages });
|
|
31766
|
-
next(new import_node_server_utils148.BadRequestError(messages));
|
|
31767
|
-
return;
|
|
31768
|
-
}
|
|
31769
|
-
const search = req.query.search ?? "";
|
|
31770
|
-
const page = parseInt(req.query.page ?? "1");
|
|
31771
|
-
const limit = parseInt(req.query.limit ?? "10");
|
|
31772
|
-
const site = req.query.site ?? "";
|
|
31773
|
-
const status = req.query.status ?? "";
|
|
31774
|
-
const type = req.query.type ?? "";
|
|
31775
|
-
const date = req.query.date ?? "";
|
|
31776
|
-
const sortObj = {};
|
|
31777
|
-
const sortFields = String(req.query.sort).split(",");
|
|
31778
|
-
const sortOrders = String(req.query.order).split(",");
|
|
31779
|
-
sortFields.forEach((field, index) => {
|
|
31780
|
-
if (allowedFields.includes(field)) {
|
|
31781
|
-
const order = sortOrders[index] === "asc" ? 1 : -1;
|
|
31782
|
-
sortObj[field] = order;
|
|
31783
|
-
}
|
|
31784
|
-
});
|
|
31785
31971
|
try {
|
|
31972
|
+
const validation = import_joi82.default.object({
|
|
31973
|
+
search: import_joi82.default.string().optional().allow("", null),
|
|
31974
|
+
page: import_joi82.default.number().integer().min(1).allow("", null).default(1),
|
|
31975
|
+
limit: import_joi82.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
31976
|
+
sort: import_joi82.default.string().valid(...Object.values(EventSort)).default("_id" /* ID */),
|
|
31977
|
+
order: import_joi82.default.string().valid(...Object.values(EventOrder)).default("desc" /* DESC */),
|
|
31978
|
+
site: import_joi82.default.string().hex().length(24).required(),
|
|
31979
|
+
status: import_joi82.default.string().valid(...Object.values(EventStatus)).allow(null, ""),
|
|
31980
|
+
type: import_joi82.default.string().optional().valid(...Object.values(EventType)).allow(null, ""),
|
|
31981
|
+
date: import_joi82.default.string().optional().allow(null, "")
|
|
31982
|
+
});
|
|
31983
|
+
const { error, value } = validation.validate(req.query, {
|
|
31984
|
+
abortEarly: false
|
|
31985
|
+
});
|
|
31986
|
+
if (error) {
|
|
31987
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
31988
|
+
import_node_server_utils148.logger.log({ level: "error", message: messages });
|
|
31989
|
+
next(new import_node_server_utils148.BadRequestError(messages));
|
|
31990
|
+
return;
|
|
31991
|
+
}
|
|
31992
|
+
const { search, page, limit, site, status, type, date, sort, order } = value;
|
|
31993
|
+
const sortObj = {
|
|
31994
|
+
[sort ?? "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
31995
|
+
};
|
|
31786
31996
|
const data = await _getAll({
|
|
31787
31997
|
search,
|
|
31788
31998
|
page,
|
|
@@ -31795,35 +32005,36 @@ function useEventManagementController() {
|
|
|
31795
32005
|
});
|
|
31796
32006
|
res.status(200).json(data);
|
|
31797
32007
|
return;
|
|
31798
|
-
} catch (
|
|
31799
|
-
import_node_server_utils148.logger.log({ level: "error", message:
|
|
31800
|
-
next(
|
|
32008
|
+
} catch (error) {
|
|
32009
|
+
import_node_server_utils148.logger.log({ level: "error", message: error.message });
|
|
32010
|
+
next(error);
|
|
31801
32011
|
return;
|
|
31802
32012
|
}
|
|
31803
32013
|
}
|
|
31804
32014
|
async function getEventManagementById(req, res, next) {
|
|
31805
|
-
const validation = import_joi82.default.string().hex().required();
|
|
31806
|
-
const _id = req.params.id;
|
|
31807
|
-
const { error } = validation.validate(_id);
|
|
31808
|
-
if (error) {
|
|
31809
|
-
import_node_server_utils148.logger.log({ level: "error", message: error.message });
|
|
31810
|
-
next(new import_node_server_utils148.BadRequestError(error.message));
|
|
31811
|
-
return;
|
|
31812
|
-
}
|
|
31813
32015
|
try {
|
|
32016
|
+
const schema2 = import_joi82.default.object({
|
|
32017
|
+
_id: import_joi82.default.string().hex().length(24).required()
|
|
32018
|
+
});
|
|
32019
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
32020
|
+
if (error) {
|
|
32021
|
+
import_node_server_utils148.logger.log({ level: "error", message: error.message });
|
|
32022
|
+
next(new import_node_server_utils148.BadRequestError(error.message));
|
|
32023
|
+
return;
|
|
32024
|
+
}
|
|
32025
|
+
const { _id } = value;
|
|
31814
32026
|
const data = await _getEventManagementById(_id);
|
|
31815
32027
|
res.status(200).json(data);
|
|
31816
32028
|
return;
|
|
31817
|
-
} catch (
|
|
31818
|
-
import_node_server_utils148.logger.log({ level: "error", message:
|
|
31819
|
-
next(
|
|
32029
|
+
} catch (error) {
|
|
32030
|
+
import_node_server_utils148.logger.log({ level: "error", message: error.message });
|
|
32031
|
+
next(error);
|
|
31820
32032
|
return;
|
|
31821
32033
|
}
|
|
31822
32034
|
}
|
|
31823
32035
|
async function updateEventManagementById(req, res, next) {
|
|
31824
|
-
const
|
|
31825
|
-
const
|
|
31826
|
-
const { error } = schemaUpdateEventManagement.validate(payload, {
|
|
32036
|
+
const payload = { _id: req.params.id, ...req.body };
|
|
32037
|
+
const { error, value } = schemaUpdateEventManagement.validate(payload, {
|
|
31827
32038
|
abortEarly: false
|
|
31828
32039
|
});
|
|
31829
32040
|
if (error) {
|
|
@@ -31832,8 +32043,9 @@ function useEventManagementController() {
|
|
|
31832
32043
|
next(new import_node_server_utils148.BadRequestError(messages));
|
|
31833
32044
|
return;
|
|
31834
32045
|
}
|
|
32046
|
+
const { _id, ...rest } = value;
|
|
31835
32047
|
try {
|
|
31836
|
-
const result = await _updateEventManagementById(_id,
|
|
32048
|
+
const result = await _updateEventManagementById(_id, rest);
|
|
31837
32049
|
res.status(200).json({ message: result });
|
|
31838
32050
|
return;
|
|
31839
32051
|
} catch (error2) {
|
|
@@ -33161,7 +33373,7 @@ var import_mongodb90 = require("mongodb");
|
|
|
33161
33373
|
|
|
33162
33374
|
// src/utils/access-management.ts
|
|
33163
33375
|
var import_fs3 = __toESM(require("fs"));
|
|
33164
|
-
var
|
|
33376
|
+
var import_path = __toESM(require("path"));
|
|
33165
33377
|
var import_axios = __toESM(require("axios"));
|
|
33166
33378
|
var import_xml2js = require("xml2js");
|
|
33167
33379
|
var import_crypto = __toESM(require("crypto"));
|
|
@@ -33191,7 +33403,7 @@ var minifyXml = (xml) => {
|
|
|
33191
33403
|
};
|
|
33192
33404
|
var readTemplate = (name, params) => {
|
|
33193
33405
|
const template = import_fs3.default.readFileSync(
|
|
33194
|
-
|
|
33406
|
+
import_path.default.join(__dirname, `../dist/public/xml-templates/${name}.xml`),
|
|
33195
33407
|
"utf-8"
|
|
33196
33408
|
);
|
|
33197
33409
|
if (!params)
|
|
@@ -33264,6 +33476,15 @@ var formatEntryPassDate = (date) => {
|
|
|
33264
33476
|
const day = String(newDate.getDate()).padStart(2, "0");
|
|
33265
33477
|
return `${year}${month}${day}`;
|
|
33266
33478
|
};
|
|
33479
|
+
var entryPassDate = (TRDATE, TRTIME) => {
|
|
33480
|
+
const year = parseInt(TRDATE.substring(0, 4), 10);
|
|
33481
|
+
const month = parseInt(TRDATE.substring(4, 6), 10) - 1;
|
|
33482
|
+
const day = parseInt(TRDATE.substring(6, 8), 10);
|
|
33483
|
+
const hours = parseInt(TRTIME.substring(0, 2), 10);
|
|
33484
|
+
const minutes = parseInt(TRTIME.substring(2, 4), 10);
|
|
33485
|
+
const seconds = parseInt(TRTIME.substring(4, 6), 10);
|
|
33486
|
+
return new Date(year, month, day, hours, minutes, seconds);
|
|
33487
|
+
};
|
|
33267
33488
|
async function removeAccessGroup({
|
|
33268
33489
|
cardNo,
|
|
33269
33490
|
staffNo,
|
|
@@ -33296,6 +33517,16 @@ async function removeAccessGroup({
|
|
|
33296
33517
|
console.log(error);
|
|
33297
33518
|
}
|
|
33298
33519
|
}
|
|
33520
|
+
async function getTransactions(index, url) {
|
|
33521
|
+
try {
|
|
33522
|
+
const decrypt = decryptAcmUrl(url);
|
|
33523
|
+
const response = await import_axios.default.get(`${decrypt}transactions?from=${index}`);
|
|
33524
|
+
if (response.status === 200 || response.status === 201)
|
|
33525
|
+
return response.data;
|
|
33526
|
+
} catch (error) {
|
|
33527
|
+
return Promise.reject(error);
|
|
33528
|
+
}
|
|
33529
|
+
}
|
|
33299
33530
|
|
|
33300
33531
|
// src/repositories/access-management.repo.ts
|
|
33301
33532
|
var import_xml2js2 = require("xml2js");
|
|
@@ -33303,9 +33534,9 @@ var import_xml2js2 = require("xml2js");
|
|
|
33303
33534
|
// src/utils/rsa-encryption.ts
|
|
33304
33535
|
var crypto2 = __toESM(require("crypto"));
|
|
33305
33536
|
var import_fs4 = __toESM(require("fs"));
|
|
33306
|
-
var
|
|
33307
|
-
var pub =
|
|
33308
|
-
var priv =
|
|
33537
|
+
var import_path2 = __toESM(require("path"));
|
|
33538
|
+
var pub = import_path2.default.resolve(process.cwd(), "./src/public/rsa-keys/new_rsa_512_pub.pem");
|
|
33539
|
+
var priv = import_path2.default.resolve(process.cwd(), "./src/public/rsa-keys/new_rsa_512_priv.pem");
|
|
33309
33540
|
var EncryptionCredentials = class {
|
|
33310
33541
|
};
|
|
33311
33542
|
EncryptionCredentials.RAW_PUBLIC_KEY = import_fs4.default.readFileSync(pub, "utf8");
|
|
@@ -35282,6 +35513,116 @@ function UseAccessManagementRepo() {
|
|
|
35282
35513
|
throw new Error(error.message);
|
|
35283
35514
|
}
|
|
35284
35515
|
}
|
|
35516
|
+
async function getTransactionsRepo({ page = 1, limit = 10, site, cardNo, url }) {
|
|
35517
|
+
page = page ? page - 1 : 0;
|
|
35518
|
+
site = new import_mongodb90.ObjectId(site);
|
|
35519
|
+
try {
|
|
35520
|
+
let index = await collectionName("access-card-transactions").findOne({}, { sort: { index: -1 } });
|
|
35521
|
+
index = index ? index.index : 0;
|
|
35522
|
+
const response = await getTransactions(index, url);
|
|
35523
|
+
if (response && Array.isArray(response.items) && response.items.length > 0) {
|
|
35524
|
+
let result2 = response.items.map((item) => ({
|
|
35525
|
+
id: item.id,
|
|
35526
|
+
data: JSON.parse(item.data),
|
|
35527
|
+
timestamp: item.timestamp
|
|
35528
|
+
}));
|
|
35529
|
+
result2 = result2.filter((item) => item.data.Event.ETYPE === "0" && item.data.Event.CARDNO !== "");
|
|
35530
|
+
if (result2.length > 0) {
|
|
35531
|
+
const transactions = result2.map(
|
|
35532
|
+
(item) => new MAccessCardTransaction({
|
|
35533
|
+
index: item.id,
|
|
35534
|
+
cardNo: item.data.Event.CARDNO,
|
|
35535
|
+
staffNo: item.data.Event.STAFFNO,
|
|
35536
|
+
staffName: item.data.Event.STAFFNAME,
|
|
35537
|
+
accessType: item.data.Event.DEVNAME,
|
|
35538
|
+
accessStatus: item.data.Event.TRCODE,
|
|
35539
|
+
description: item.data.Event.TRDESC,
|
|
35540
|
+
accessTime: entryPassDate(item.data.Event.TRDATE, item.data.Event.TRTIME),
|
|
35541
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
35542
|
+
})
|
|
35543
|
+
);
|
|
35544
|
+
await collectionName("access-card-transactions").insertMany(transactions);
|
|
35545
|
+
}
|
|
35546
|
+
}
|
|
35547
|
+
const result = await collectionName("access-card-transactions").aggregate([
|
|
35548
|
+
{
|
|
35549
|
+
$match: { cardNo }
|
|
35550
|
+
},
|
|
35551
|
+
{
|
|
35552
|
+
$lookup: {
|
|
35553
|
+
from: "access-card",
|
|
35554
|
+
let: { cardNo: "$cardNo" },
|
|
35555
|
+
pipeline: [
|
|
35556
|
+
{
|
|
35557
|
+
$match: {
|
|
35558
|
+
$expr: {
|
|
35559
|
+
$eq: ["$cardNo", "$$cardNo"]
|
|
35560
|
+
}
|
|
35561
|
+
}
|
|
35562
|
+
},
|
|
35563
|
+
{
|
|
35564
|
+
$lookup: {
|
|
35565
|
+
from: "users",
|
|
35566
|
+
let: { userId: "$userId" },
|
|
35567
|
+
pipeline: [
|
|
35568
|
+
{
|
|
35569
|
+
$match: {
|
|
35570
|
+
$expr: {
|
|
35571
|
+
$eq: ["$_id", "$$userId"]
|
|
35572
|
+
}
|
|
35573
|
+
}
|
|
35574
|
+
},
|
|
35575
|
+
{
|
|
35576
|
+
$project: {
|
|
35577
|
+
_id: 1,
|
|
35578
|
+
givenName: 1,
|
|
35579
|
+
surname: 1
|
|
35580
|
+
}
|
|
35581
|
+
}
|
|
35582
|
+
],
|
|
35583
|
+
as: "user"
|
|
35584
|
+
}
|
|
35585
|
+
},
|
|
35586
|
+
{
|
|
35587
|
+
$project: {
|
|
35588
|
+
_id: 1,
|
|
35589
|
+
user: { $arrayElemAt: ["$user", 0] },
|
|
35590
|
+
type: 1,
|
|
35591
|
+
cardNo: 1
|
|
35592
|
+
}
|
|
35593
|
+
}
|
|
35594
|
+
],
|
|
35595
|
+
as: "accessCard"
|
|
35596
|
+
}
|
|
35597
|
+
},
|
|
35598
|
+
{
|
|
35599
|
+
$project: {
|
|
35600
|
+
_id: 1,
|
|
35601
|
+
cardNo: 1,
|
|
35602
|
+
staffNo: 1,
|
|
35603
|
+
staffName: 1,
|
|
35604
|
+
accessType: 1,
|
|
35605
|
+
accessStatus: 1,
|
|
35606
|
+
description: 1,
|
|
35607
|
+
accessTime: 1,
|
|
35608
|
+
createdAt: 1,
|
|
35609
|
+
accessCard: { $arrayElemAt: ["$accessCard", 0] }
|
|
35610
|
+
}
|
|
35611
|
+
},
|
|
35612
|
+
{
|
|
35613
|
+
$facet: {
|
|
35614
|
+
totalCount: [{ $count: "count" }],
|
|
35615
|
+
items: [{ $sort: { _id: -1 } }, { $skip: page * limit }, { $limit: limit }]
|
|
35616
|
+
}
|
|
35617
|
+
}
|
|
35618
|
+
]).toArray();
|
|
35619
|
+
const length = result[0].totalCount[0] ? result[0].totalCount[0].count : 0;
|
|
35620
|
+
const items = result[0].items;
|
|
35621
|
+
return (0, import_node_server_utils153.paginate)(items, page, limit, length);
|
|
35622
|
+
} catch (error) {
|
|
35623
|
+
return Promise.reject("Server internal error.");
|
|
35624
|
+
}
|
|
35625
|
+
}
|
|
35285
35626
|
return {
|
|
35286
35627
|
createIndexes,
|
|
35287
35628
|
createIndexForEntrypass,
|
|
@@ -35313,7 +35654,8 @@ function UseAccessManagementRepo() {
|
|
|
35313
35654
|
signQrCodeRepo,
|
|
35314
35655
|
checkoutVisitorRepo,
|
|
35315
35656
|
getBlockLevelAndUnitListRepo,
|
|
35316
|
-
indexCombination
|
|
35657
|
+
indexCombination,
|
|
35658
|
+
getTransactionsRepo
|
|
35317
35659
|
};
|
|
35318
35660
|
}
|
|
35319
35661
|
|
|
@@ -35353,7 +35695,8 @@ function useAccessManagementSvc() {
|
|
|
35353
35695
|
addVisitorAccessCardRepo,
|
|
35354
35696
|
signQrCodeRepo,
|
|
35355
35697
|
checkoutVisitorRepo,
|
|
35356
|
-
getBlockLevelAndUnitListRepo
|
|
35698
|
+
getBlockLevelAndUnitListRepo,
|
|
35699
|
+
getTransactionsRepo
|
|
35357
35700
|
} = UseAccessManagementRepo();
|
|
35358
35701
|
const addPhysicalCardSvc = async (payload) => {
|
|
35359
35702
|
try {
|
|
@@ -35645,6 +35988,14 @@ function useAccessManagementSvc() {
|
|
|
35645
35988
|
throw new Error(err.message);
|
|
35646
35989
|
}
|
|
35647
35990
|
};
|
|
35991
|
+
const getTransactionsSvc = async ({ page, limit, site, cardNo, url }) => {
|
|
35992
|
+
try {
|
|
35993
|
+
const response = await getTransactionsRepo({ page, limit, site, cardNo, url });
|
|
35994
|
+
return response;
|
|
35995
|
+
} catch (err) {
|
|
35996
|
+
return Promise.reject("Server internal error.");
|
|
35997
|
+
}
|
|
35998
|
+
};
|
|
35648
35999
|
return {
|
|
35649
36000
|
addPhysicalCardSvc,
|
|
35650
36001
|
addNonPhysicalCardSvc,
|
|
@@ -35679,7 +36030,8 @@ function useAccessManagementSvc() {
|
|
|
35679
36030
|
addVisitorAccessCardSvc,
|
|
35680
36031
|
signQrCodeSvc,
|
|
35681
36032
|
checkoutVisitorSvc,
|
|
35682
|
-
getBlockLevelAndUnitListSvc
|
|
36033
|
+
getBlockLevelAndUnitListSvc,
|
|
36034
|
+
getTransactionsSvc
|
|
35683
36035
|
};
|
|
35684
36036
|
}
|
|
35685
36037
|
|
|
@@ -35719,7 +36071,8 @@ function useAccessManagementController() {
|
|
|
35719
36071
|
addVisitorAccessCardSvc,
|
|
35720
36072
|
signQrCodeSvc,
|
|
35721
36073
|
checkoutVisitorSvc,
|
|
35722
|
-
getBlockLevelAndUnitListSvc
|
|
36074
|
+
getBlockLevelAndUnitListSvc,
|
|
36075
|
+
getTransactionsSvc
|
|
35723
36076
|
} = useAccessManagementSvc();
|
|
35724
36077
|
const addPhysicalCard = async (req, res) => {
|
|
35725
36078
|
try {
|
|
@@ -36481,6 +36834,31 @@ function useAccessManagementController() {
|
|
|
36481
36834
|
});
|
|
36482
36835
|
}
|
|
36483
36836
|
};
|
|
36837
|
+
const getTransactions2 = async (req, res) => {
|
|
36838
|
+
const { page = 1, limit = 10, site, cardNo, url } = req.query;
|
|
36839
|
+
const schema2 = import_joi85.default.object({
|
|
36840
|
+
page: import_joi85.default.number().required(),
|
|
36841
|
+
limit: import_joi85.default.number().optional().default(10),
|
|
36842
|
+
site: import_joi85.default.string().hex().required(),
|
|
36843
|
+
cardNo: import_joi85.default.string().required()
|
|
36844
|
+
});
|
|
36845
|
+
const { value, error } = schema2.validate({ page, limit, site, cardNo });
|
|
36846
|
+
if (error) {
|
|
36847
|
+
return res.status(400).json({ message: error.message });
|
|
36848
|
+
}
|
|
36849
|
+
try {
|
|
36850
|
+
const result = await getTransactionsSvc({
|
|
36851
|
+
page: Number(page),
|
|
36852
|
+
limit: Number(value.limit),
|
|
36853
|
+
site,
|
|
36854
|
+
cardNo,
|
|
36855
|
+
url
|
|
36856
|
+
});
|
|
36857
|
+
return res.json(result);
|
|
36858
|
+
} catch (error2) {
|
|
36859
|
+
return Promise.reject("Internal Server Error");
|
|
36860
|
+
}
|
|
36861
|
+
};
|
|
36484
36862
|
return {
|
|
36485
36863
|
addPhysicalCard,
|
|
36486
36864
|
addNonPhysicalCard,
|
|
@@ -36513,7 +36891,8 @@ function useAccessManagementController() {
|
|
|
36513
36891
|
signQrCode,
|
|
36514
36892
|
checkoutVisitor,
|
|
36515
36893
|
removeAccessCard,
|
|
36516
|
-
getBlockLevelAndUnitList
|
|
36894
|
+
getBlockLevelAndUnitList,
|
|
36895
|
+
getTransactions: getTransactions2
|
|
36517
36896
|
};
|
|
36518
36897
|
}
|
|
36519
36898
|
|
|
@@ -44225,14 +44604,15 @@ async function hrmLabsAuthentication({
|
|
|
44225
44604
|
showPassword: false
|
|
44226
44605
|
},
|
|
44227
44606
|
{
|
|
44228
|
-
headers: { "Content-Type": "application/json" }
|
|
44607
|
+
headers: { "Content-Type": "application/json" },
|
|
44608
|
+
validateStatus: () => true
|
|
44229
44609
|
}
|
|
44230
44610
|
);
|
|
44231
44611
|
if (res.data?.success && res.data.data?.token) {
|
|
44232
44612
|
return res.data.data.token;
|
|
44233
44613
|
}
|
|
44234
44614
|
throw new Error(
|
|
44235
|
-
"HRMLabs Authentication failed. Please check your credentials."
|
|
44615
|
+
res.status === 401 || res.status === 403 ? "HRMLabs Authentication failed. Please check your credentials." : `HRMLabs Authentication failed with status ${res.status}.`
|
|
44236
44616
|
);
|
|
44237
44617
|
}
|
|
44238
44618
|
async function fetchAttendanceData({
|
|
@@ -46423,7 +46803,7 @@ function useHrmLabsAttendanceSrvc() {
|
|
|
46423
46803
|
} catch (error) {
|
|
46424
46804
|
import_node_server_utils209.logger.error(error.message || error);
|
|
46425
46805
|
console.log("Error fetching attendance data:", error);
|
|
46426
|
-
|
|
46806
|
+
return { success: false, message: error?.message || "Internal Server Error!", items: [], pages: 0, pageRange: "0-0 of 0", count: {} };
|
|
46427
46807
|
}
|
|
46428
46808
|
}
|
|
46429
46809
|
async function getAttendanceDataCount(payload) {
|
|
@@ -46537,7 +46917,7 @@ function useHrmLabsAttendanceSrvc() {
|
|
|
46537
46917
|
} catch (error) {
|
|
46538
46918
|
import_node_server_utils209.logger.error(error.message || error);
|
|
46539
46919
|
console.log("Error fetching attendance data count:", error);
|
|
46540
|
-
|
|
46920
|
+
return { success: false, message: error?.message || "Internal Server Error!", totalCount: null };
|
|
46541
46921
|
}
|
|
46542
46922
|
}
|
|
46543
46923
|
async function getAllAttendance(payload) {
|
|
@@ -46709,7 +47089,7 @@ function useHrmLabsAttendanceSrvc() {
|
|
|
46709
47089
|
} catch (error) {
|
|
46710
47090
|
import_node_server_utils209.logger.error(error.message || error);
|
|
46711
47091
|
console.log("Error fetching attendance data:", error);
|
|
46712
|
-
|
|
47092
|
+
return { success: false, message: error?.message || "Internal Server Error!", items: [], count: {}, countPerJobTitle: {}, totalCount: null, countPerStatus: {} };
|
|
46713
47093
|
}
|
|
46714
47094
|
}
|
|
46715
47095
|
async function getChartAttendanceData(payload) {
|
|
@@ -46816,7 +47196,7 @@ function useHrmLabsAttendanceSrvc() {
|
|
|
46816
47196
|
} catch (error) {
|
|
46817
47197
|
import_node_server_utils209.logger.error(error.message || error);
|
|
46818
47198
|
console.log("Error fetching attendance data:", error);
|
|
46819
|
-
|
|
47199
|
+
return { success: false, message: error?.message || "Internal Server Error!", chartCount: null };
|
|
46820
47200
|
}
|
|
46821
47201
|
}
|
|
46822
47202
|
return {
|
|
@@ -48446,7 +48826,8 @@ function useVerificationServiceV2() {
|
|
|
48446
48826
|
add: _add,
|
|
48447
48827
|
updateVerificationStatusById: _updateVerificationStatusById,
|
|
48448
48828
|
getByVerificationCode: _getByVerificationCode,
|
|
48449
|
-
updateStatusById: _updateStatusById
|
|
48829
|
+
updateStatusById: _updateStatusById,
|
|
48830
|
+
countPendingOrgInvites: _countPendingOrgInvites
|
|
48450
48831
|
} = useVerificationRepoV2();
|
|
48451
48832
|
const {
|
|
48452
48833
|
getUserByEmailStatus: _getUserByEmailStatus,
|
|
@@ -48454,6 +48835,8 @@ function useVerificationServiceV2() {
|
|
|
48454
48835
|
} = useUserRepo();
|
|
48455
48836
|
const { getById: getOrgById, getByEmail: _getByEmail } = useOrgRepo();
|
|
48456
48837
|
const { getSiteById } = useSiteRepo();
|
|
48838
|
+
const { getByOrgId: _getSubscriptionByOrgId } = useSubscriptionRepo();
|
|
48839
|
+
const { countByOrg: _countMemberByOrg } = useMemberRepo();
|
|
48457
48840
|
function errorByType(type, status) {
|
|
48458
48841
|
if ((type === "user-invite" /* USER_INVITE */ || type === "member-invite" /* MEMBER_INVITE */ || type === "service-provider-invite" /* SERVICE_PROVIDER_INVITE */ || type === "service-provider-create-org" /* SERVICE_PROVIDER_CREATE_ORG */) && status === "expired" /* EXPIRED */) {
|
|
48459
48842
|
throw new import_node_server_utils221.BadRequestError(
|
|
@@ -48717,6 +49100,30 @@ function useVerificationServiceV2() {
|
|
|
48717
49100
|
throw error2;
|
|
48718
49101
|
}
|
|
48719
49102
|
}
|
|
49103
|
+
async function createOrganizationInvite({
|
|
49104
|
+
email,
|
|
49105
|
+
metadata
|
|
49106
|
+
}) {
|
|
49107
|
+
const orgId = metadata.org?.toString() ?? "";
|
|
49108
|
+
if (!orgId) {
|
|
49109
|
+
throw new import_node_server_utils221.BadRequestError("Organization is required.");
|
|
49110
|
+
}
|
|
49111
|
+
await getOrgById(orgId);
|
|
49112
|
+
const [subscription, memberCount, pendingInviteCount] = await Promise.all([
|
|
49113
|
+
_getSubscriptionByOrgId(orgId),
|
|
49114
|
+
_countMemberByOrg(orgId),
|
|
49115
|
+
_countPendingOrgInvites(orgId)
|
|
49116
|
+
]);
|
|
49117
|
+
const maxSeats = subscription?.maxSeats ?? 0;
|
|
49118
|
+
if (!maxSeats) {
|
|
49119
|
+
throw new import_node_server_utils221.BadRequestError("No seats configured for organization.");
|
|
49120
|
+
}
|
|
49121
|
+
const usedSeats = memberCount + pendingInviteCount;
|
|
49122
|
+
if (usedSeats >= maxSeats) {
|
|
49123
|
+
throw new import_node_server_utils221.BadRequestError("No available seats for new invitation.");
|
|
49124
|
+
}
|
|
49125
|
+
return createUserInvite({ email, metadata });
|
|
49126
|
+
}
|
|
48720
49127
|
async function createForgetPassword(email) {
|
|
48721
49128
|
const value = {
|
|
48722
49129
|
type: "forget-password" /* FORGET_PASSWORD */,
|
|
@@ -48767,6 +49174,7 @@ function useVerificationServiceV2() {
|
|
|
48767
49174
|
signUp,
|
|
48768
49175
|
verify,
|
|
48769
49176
|
createUserInvite,
|
|
49177
|
+
createOrganizationInvite,
|
|
48770
49178
|
createServiceProviderInvite,
|
|
48771
49179
|
createForgetPassword,
|
|
48772
49180
|
cancelUserInvitation
|
|
@@ -48780,6 +49188,7 @@ function useVerificationControllerV2() {
|
|
|
48780
49188
|
const {
|
|
48781
49189
|
verify: _verify,
|
|
48782
49190
|
createUserInvite: _createUserInvite,
|
|
49191
|
+
createOrganizationInvite: _createOrganizationInvite,
|
|
48783
49192
|
createServiceProviderInvite: _createServiceProviderInvite,
|
|
48784
49193
|
createForgetPassword: _createForgetPassword,
|
|
48785
49194
|
cancelUserInvitation: _cancelUserInvitation
|
|
@@ -48876,6 +49285,44 @@ function useVerificationControllerV2() {
|
|
|
48876
49285
|
return;
|
|
48877
49286
|
}
|
|
48878
49287
|
}
|
|
49288
|
+
async function createOrganizationInvite(req, res, next) {
|
|
49289
|
+
const schema2 = import_joi127.default.object({
|
|
49290
|
+
email: import_joi127.default.string().email().lowercase().required(),
|
|
49291
|
+
role: import_joi127.default.string().hex().length(24).required(),
|
|
49292
|
+
org: import_joi127.default.string().hex().length(24).required(),
|
|
49293
|
+
app: import_joi127.default.string().optional().allow("", null).default("organization"),
|
|
49294
|
+
name: import_joi127.default.string().optional().allow("", null),
|
|
49295
|
+
siteId: import_joi127.default.string().hex().length(24).optional().allow("", null),
|
|
49296
|
+
siteName: import_joi127.default.string().optional().allow("", null)
|
|
49297
|
+
});
|
|
49298
|
+
const { error, value } = schema2.validate(req.body, { abortEarly: false });
|
|
49299
|
+
if (error) {
|
|
49300
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
49301
|
+
import_node_server_utils222.logger.log({ level: "error", message: messages });
|
|
49302
|
+
next(new import_node_server_utils222.BadRequestError(messages));
|
|
49303
|
+
return;
|
|
49304
|
+
}
|
|
49305
|
+
try {
|
|
49306
|
+
const { email, app, role, name, org, siteId, siteName } = value;
|
|
49307
|
+
await _createOrganizationInvite({
|
|
49308
|
+
email,
|
|
49309
|
+
metadata: {
|
|
49310
|
+
app,
|
|
49311
|
+
role,
|
|
49312
|
+
name,
|
|
49313
|
+
org,
|
|
49314
|
+
siteId,
|
|
49315
|
+
siteName
|
|
49316
|
+
}
|
|
49317
|
+
});
|
|
49318
|
+
res.status(201).json({ message: "Successfully invited user." });
|
|
49319
|
+
return;
|
|
49320
|
+
} catch (error2) {
|
|
49321
|
+
import_node_server_utils222.logger.log({ level: "error", message: `${error2.message}` });
|
|
49322
|
+
next(error2);
|
|
49323
|
+
return;
|
|
49324
|
+
}
|
|
49325
|
+
}
|
|
48879
49326
|
async function createForgetPassword(req, res, next) {
|
|
48880
49327
|
const schema2 = import_joi127.default.object({
|
|
48881
49328
|
email: import_joi127.default.string().email().lowercase().required()
|
|
@@ -48961,6 +49408,7 @@ function useVerificationControllerV2() {
|
|
|
48961
49408
|
return {
|
|
48962
49409
|
verify,
|
|
48963
49410
|
createUserInvite,
|
|
49411
|
+
createOrganizationInvite,
|
|
48964
49412
|
createServiceProviderInvite,
|
|
48965
49413
|
createForgetPassword,
|
|
48966
49414
|
getVerifications,
|
|
@@ -50328,6 +50776,10 @@ function useRoleControllerV2() {
|
|
|
50328
50776
|
EmailSender,
|
|
50329
50777
|
EntryOrder,
|
|
50330
50778
|
EntrySort,
|
|
50779
|
+
EventOrder,
|
|
50780
|
+
EventSort,
|
|
50781
|
+
EventStatus,
|
|
50782
|
+
EventType,
|
|
50331
50783
|
FacilitySort,
|
|
50332
50784
|
FacilityStatus,
|
|
50333
50785
|
GuestSort,
|
|
@@ -50440,6 +50892,7 @@ function useRoleControllerV2() {
|
|
|
50440
50892
|
events_namespace_collection,
|
|
50441
50893
|
facility_bookings_namespace_collection,
|
|
50442
50894
|
feedbackSchema,
|
|
50895
|
+
feedbacks2_namespace_collection,
|
|
50443
50896
|
feedbacks_namespace_collection,
|
|
50444
50897
|
formatDahuaDate,
|
|
50445
50898
|
getPeriodRangeWithPrevious,
|