@7365admin1/core 3.12.0 → 3.14.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 +45 -3
- package/dist/index.js +210 -223
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +209 -223
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -8716,6 +8716,7 @@ var APP_POOL_MAINTENANCE = process.env.APP_POOL_MAINTENANCE ?? "http://localhost
|
|
|
8716
8716
|
var ENCRYPTION_KEY = process.env.ENCRYPTION_KEY ?? "";
|
|
8717
8717
|
var DOMAIN = process.env.DOMAIN ?? "localhost";
|
|
8718
8718
|
var OPEN_AI_API_KEY = process.env.OPEN_AI_API_KEY;
|
|
8719
|
+
var ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
|
|
8719
8720
|
var STORAGE_API = process.env.STORAGE_API;
|
|
8720
8721
|
|
|
8721
8722
|
// src/services/auth.service.ts
|
|
@@ -9216,59 +9217,41 @@ function useMemberRepo() {
|
|
|
9216
9217
|
try {
|
|
9217
9218
|
const items = await collection.aggregate([
|
|
9218
9219
|
{ $match: query },
|
|
9219
|
-
{ $sort: { _id: -1 } },
|
|
9220
|
-
{ $skip: page * limit },
|
|
9221
|
-
{ $limit: limit },
|
|
9222
|
-
{
|
|
9223
|
-
$lookup: {
|
|
9224
|
-
from: "organizations",
|
|
9225
|
-
localField: "org",
|
|
9226
|
-
foreignField: "_id",
|
|
9227
|
-
as: "orgData"
|
|
9228
|
-
}
|
|
9229
|
-
},
|
|
9230
|
-
{
|
|
9231
|
-
$unwind: {
|
|
9232
|
-
path: "$orgData",
|
|
9233
|
-
preserveNullAndEmptyArrays: true
|
|
9234
|
-
}
|
|
9235
|
-
},
|
|
9236
9220
|
{
|
|
9237
9221
|
$lookup: {
|
|
9238
9222
|
from: "organizations",
|
|
9239
9223
|
localField: "org",
|
|
9240
9224
|
foreignField: "_id",
|
|
9241
|
-
as: "
|
|
9225
|
+
as: "org"
|
|
9242
9226
|
}
|
|
9243
9227
|
},
|
|
9244
9228
|
{
|
|
9245
9229
|
$unwind: {
|
|
9246
|
-
path: "$
|
|
9230
|
+
path: "$org",
|
|
9247
9231
|
preserveNullAndEmptyArrays: true
|
|
9248
9232
|
}
|
|
9249
9233
|
},
|
|
9250
9234
|
{
|
|
9251
9235
|
$group: {
|
|
9252
|
-
_id: "$org",
|
|
9253
|
-
text: { $first: "$
|
|
9254
|
-
value: { $first: "$org" },
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
},
|
|
9259
|
-
|
|
9260
|
-
$first: "$orgData.onboardingCompleted"
|
|
9261
|
-
},
|
|
9262
|
-
onboardingCompletedAt: {
|
|
9263
|
-
$first: "$orgData.onboardingCompletedAt"
|
|
9264
|
-
}
|
|
9236
|
+
_id: "$org._id",
|
|
9237
|
+
text: { $first: "$org.name" },
|
|
9238
|
+
value: { $first: "$org._id" },
|
|
9239
|
+
type: { $first: "$org.type" },
|
|
9240
|
+
defaultSite: { $first: "$org.defaultSite" },
|
|
9241
|
+
onboardingRequired: { $first: "$org.onboardingRequired" },
|
|
9242
|
+
onboardingCompleted: { $first: "$org.onboardingCompleted" },
|
|
9243
|
+
onboardingCompletedAt: { $first: "$org.onboardingCompletedAt" }
|
|
9265
9244
|
}
|
|
9266
9245
|
},
|
|
9246
|
+
{ $sort: { _id: -1 } },
|
|
9247
|
+
{ $skip: page * limit },
|
|
9248
|
+
{ $limit: limit },
|
|
9267
9249
|
{
|
|
9268
9250
|
$project: {
|
|
9269
9251
|
_id: 0,
|
|
9270
9252
|
text: 1,
|
|
9271
9253
|
value: 1,
|
|
9254
|
+
type: 1,
|
|
9272
9255
|
defaultSite: 1,
|
|
9273
9256
|
onboardingRequired: 1,
|
|
9274
9257
|
onboardingCompleted: 1,
|
|
@@ -10150,6 +10133,56 @@ function useVerificationRepo() {
|
|
|
10150
10133
|
async function findOne(query) {
|
|
10151
10134
|
return await collection.findOne(query);
|
|
10152
10135
|
}
|
|
10136
|
+
async function completePendingInvites({
|
|
10137
|
+
email,
|
|
10138
|
+
orgId,
|
|
10139
|
+
siteId,
|
|
10140
|
+
app,
|
|
10141
|
+
session
|
|
10142
|
+
}) {
|
|
10143
|
+
const orgCandidates = [orgId];
|
|
10144
|
+
try {
|
|
10145
|
+
orgCandidates.push(new ObjectId13(orgId));
|
|
10146
|
+
} catch {
|
|
10147
|
+
}
|
|
10148
|
+
const query = {
|
|
10149
|
+
email: { $regex: `^${email}$`, $options: "i" },
|
|
10150
|
+
status: "pending",
|
|
10151
|
+
type: {
|
|
10152
|
+
$in: ["user-invite" /* USER_INVITE */, "member-invite" /* MEMBER_INVITE */]
|
|
10153
|
+
},
|
|
10154
|
+
"metadata.org": { $in: orgCandidates }
|
|
10155
|
+
};
|
|
10156
|
+
if (siteId) {
|
|
10157
|
+
const siteCandidates = [siteId];
|
|
10158
|
+
try {
|
|
10159
|
+
siteCandidates.push(new ObjectId13(siteId));
|
|
10160
|
+
} catch {
|
|
10161
|
+
}
|
|
10162
|
+
query["metadata.siteId"] = { $in: siteCandidates };
|
|
10163
|
+
}
|
|
10164
|
+
if (app) {
|
|
10165
|
+
query["metadata.app"] = app;
|
|
10166
|
+
}
|
|
10167
|
+
try {
|
|
10168
|
+
const result = await collection.updateMany(
|
|
10169
|
+
query,
|
|
10170
|
+
{ $set: { status: "complete", updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
10171
|
+
{ session }
|
|
10172
|
+
);
|
|
10173
|
+
delNamespace().then(() => {
|
|
10174
|
+
logger9.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
10175
|
+
}).catch((err) => {
|
|
10176
|
+
logger9.error(
|
|
10177
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
10178
|
+
err
|
|
10179
|
+
);
|
|
10180
|
+
});
|
|
10181
|
+
return result;
|
|
10182
|
+
} catch (error) {
|
|
10183
|
+
throw new InternalServerError8("Failed to complete pending invites.");
|
|
10184
|
+
}
|
|
10185
|
+
}
|
|
10153
10186
|
return {
|
|
10154
10187
|
createIndex,
|
|
10155
10188
|
createTextIndex,
|
|
@@ -10159,7 +10192,8 @@ function useVerificationRepo() {
|
|
|
10159
10192
|
getByIdByType,
|
|
10160
10193
|
updateStatusById,
|
|
10161
10194
|
getByStatus,
|
|
10162
|
-
findOne
|
|
10195
|
+
findOne,
|
|
10196
|
+
completePendingInvites
|
|
10163
10197
|
};
|
|
10164
10198
|
}
|
|
10165
10199
|
|
|
@@ -11108,21 +11142,10 @@ function useSiteRepo() {
|
|
|
11108
11142
|
throw new BadRequestError18("Invalid site ID format.");
|
|
11109
11143
|
}
|
|
11110
11144
|
try {
|
|
11111
|
-
const cacheKey = makeCacheKey9(namespace_collection, { _id });
|
|
11112
|
-
const cachedData = await getCache(cacheKey);
|
|
11113
|
-
if (cachedData) {
|
|
11114
|
-
logger12.info(`Cache hit for key: ${cacheKey}`);
|
|
11115
|
-
return cachedData;
|
|
11116
|
-
}
|
|
11117
11145
|
const data = await collection.aggregate([{ $match: { _id, status: { $ne: "deleted" } } }]).toArray();
|
|
11118
11146
|
if (!data || !data.length) {
|
|
11119
11147
|
throw new NotFoundError8("Site not found.");
|
|
11120
11148
|
}
|
|
11121
|
-
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
11122
|
-
logger12.info(`Cache set for key: ${cacheKey}`);
|
|
11123
|
-
}).catch((err) => {
|
|
11124
|
-
logger12.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
11125
|
-
});
|
|
11126
11149
|
return data[0];
|
|
11127
11150
|
} catch (error) {
|
|
11128
11151
|
throw error;
|
|
@@ -11769,6 +11792,61 @@ function useVerificationRepoV2() {
|
|
|
11769
11792
|
throw new InternalServerError11("Failed to update verification code.");
|
|
11770
11793
|
}
|
|
11771
11794
|
}
|
|
11795
|
+
async function completePendingInvites({
|
|
11796
|
+
email,
|
|
11797
|
+
orgId,
|
|
11798
|
+
siteId,
|
|
11799
|
+
app,
|
|
11800
|
+
session
|
|
11801
|
+
}) {
|
|
11802
|
+
const orgCandidates = [orgId];
|
|
11803
|
+
try {
|
|
11804
|
+
orgCandidates.push(new ObjectId18(orgId));
|
|
11805
|
+
} catch {
|
|
11806
|
+
}
|
|
11807
|
+
const query = {
|
|
11808
|
+
email: { $regex: `^${email}$`, $options: "i" },
|
|
11809
|
+
status: "pending" /* PENDING */,
|
|
11810
|
+
type: {
|
|
11811
|
+
$in: ["user-invite" /* USER_INVITE */, "member-invite" /* MEMBER_INVITE */]
|
|
11812
|
+
},
|
|
11813
|
+
"metadata.org": { $in: orgCandidates }
|
|
11814
|
+
};
|
|
11815
|
+
if (siteId) {
|
|
11816
|
+
const siteCandidates = [siteId];
|
|
11817
|
+
try {
|
|
11818
|
+
siteCandidates.push(new ObjectId18(siteId));
|
|
11819
|
+
} catch {
|
|
11820
|
+
}
|
|
11821
|
+
query["metadata.siteId"] = { $in: siteCandidates };
|
|
11822
|
+
}
|
|
11823
|
+
if (app) {
|
|
11824
|
+
query["metadata.app"] = app;
|
|
11825
|
+
}
|
|
11826
|
+
try {
|
|
11827
|
+
const result = await collection.updateMany(
|
|
11828
|
+
query,
|
|
11829
|
+
{
|
|
11830
|
+
$set: {
|
|
11831
|
+
status: "complete" /* COMPLETE */,
|
|
11832
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11833
|
+
}
|
|
11834
|
+
},
|
|
11835
|
+
{ session }
|
|
11836
|
+
);
|
|
11837
|
+
delNamespace().then(() => {
|
|
11838
|
+
logger13.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
11839
|
+
}).catch((err) => {
|
|
11840
|
+
logger13.error(
|
|
11841
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
11842
|
+
err
|
|
11843
|
+
);
|
|
11844
|
+
});
|
|
11845
|
+
return result;
|
|
11846
|
+
} catch (error) {
|
|
11847
|
+
throw new InternalServerError11("Failed to complete pending invites.");
|
|
11848
|
+
}
|
|
11849
|
+
}
|
|
11772
11850
|
return {
|
|
11773
11851
|
createIndex,
|
|
11774
11852
|
createTextIndex,
|
|
@@ -11780,7 +11858,8 @@ function useVerificationRepoV2() {
|
|
|
11780
11858
|
updateStatusById,
|
|
11781
11859
|
countPendingOrgInvites,
|
|
11782
11860
|
getPendingVerificationByEmail,
|
|
11783
|
-
updateVerificationCodeById
|
|
11861
|
+
updateVerificationCodeById,
|
|
11862
|
+
completePendingInvites
|
|
11784
11863
|
};
|
|
11785
11864
|
}
|
|
11786
11865
|
|
|
@@ -13893,7 +13972,7 @@ function useMemberService() {
|
|
|
13893
13972
|
getAllByUserId: _getAllByUserId,
|
|
13894
13973
|
completeOnboardingById: _completeOnboardingById
|
|
13895
13974
|
} = useMemberRepo();
|
|
13896
|
-
const { getById: _getVerificationById, updateStatusById } = useVerificationRepo();
|
|
13975
|
+
const { getById: _getVerificationById, updateStatusById, completePendingInvites } = useVerificationRepo();
|
|
13897
13976
|
const { getUserByEmail, updateDefaultOrgByEmail, getUserById } = useUserRepo();
|
|
13898
13977
|
const { getById: getOrgById } = useOrgRepo();
|
|
13899
13978
|
const { getSiteById } = useSiteRepo();
|
|
@@ -13997,6 +14076,13 @@ function useMemberService() {
|
|
|
13997
14076
|
session
|
|
13998
14077
|
);
|
|
13999
14078
|
}
|
|
14079
|
+
await completePendingInvites({
|
|
14080
|
+
email: user.email,
|
|
14081
|
+
orgId,
|
|
14082
|
+
siteId,
|
|
14083
|
+
app,
|
|
14084
|
+
session
|
|
14085
|
+
});
|
|
14000
14086
|
await session?.commitTransaction();
|
|
14001
14087
|
return { member };
|
|
14002
14088
|
} catch (error) {
|
|
@@ -21059,6 +21145,7 @@ async function convertObjectIdUtil2(id, fieldName) {
|
|
|
21059
21145
|
throw new Error(`Invalid ID conversion to ObjectId of ${fieldName}.`);
|
|
21060
21146
|
return new ObjectId40(id);
|
|
21061
21147
|
} catch (_) {
|
|
21148
|
+
console.log(`Invalid ID conversion to ObjectId of ${fieldName}. : `, id);
|
|
21062
21149
|
throw new Error(`Invalid ID conversion to ObjectId of ${fieldName}.`);
|
|
21063
21150
|
}
|
|
21064
21151
|
}
|
|
@@ -33473,12 +33560,28 @@ var KeyRepo = class {
|
|
|
33473
33560
|
return Promise.reject("Server internal error.");
|
|
33474
33561
|
}
|
|
33475
33562
|
}
|
|
33476
|
-
static async updateKeyById(keyId, key, site, session, isChild, visitorId) {
|
|
33563
|
+
static async updateKeyById(keyId, key, site, session, isChild, visitorId, isDifferentStatus, isPassKeyVisitorAdd) {
|
|
33477
33564
|
keyId = await convertObjectIdUtil2(keyId, "keyId");
|
|
33478
33565
|
if (site)
|
|
33479
33566
|
site = await convertObjectIdUtil2(site, "Site");
|
|
33480
|
-
if (visitorId)
|
|
33481
|
-
visitorId = await convertObjectIdUtil2(visitorId, "
|
|
33567
|
+
if (visitorId) {
|
|
33568
|
+
visitorId = await convertObjectIdUtil2(visitorId, "Visitor Id");
|
|
33569
|
+
if (!isPassKeyVisitorAdd) {
|
|
33570
|
+
const findOptions = { sort: { _id: -1 } };
|
|
33571
|
+
const latestHistory = await this.collectionDynamic("keys-histories").findOne(
|
|
33572
|
+
{ passOrKeyId: keyId },
|
|
33573
|
+
findOptions
|
|
33574
|
+
);
|
|
33575
|
+
console.log("visitorId", visitorId.toString());
|
|
33576
|
+
console.log("latestHistory.visitorId", latestHistory?.visitorId.toString());
|
|
33577
|
+
if (latestHistory?.visitorId && latestHistory.visitorId?.toString() !== visitorId.toString()) {
|
|
33578
|
+
console.log("Not updating keyId", keyId);
|
|
33579
|
+
return;
|
|
33580
|
+
} else {
|
|
33581
|
+
console.log("updating keyId", keyId);
|
|
33582
|
+
}
|
|
33583
|
+
}
|
|
33584
|
+
}
|
|
33482
33585
|
if (key.updatedBy)
|
|
33483
33586
|
key.updatedBy = await convertObjectIdUtil2(key.updatedBy, "Updated By");
|
|
33484
33587
|
if (!key.status)
|
|
@@ -33486,9 +33589,14 @@ var KeyRepo = class {
|
|
|
33486
33589
|
try {
|
|
33487
33590
|
key.updatedAt = /* @__PURE__ */ new Date();
|
|
33488
33591
|
const query = { _id: keyId, ...site && { site } };
|
|
33489
|
-
let find = query;
|
|
33490
|
-
if (isChild)
|
|
33592
|
+
let find = { ...query };
|
|
33593
|
+
if (isChild) {
|
|
33491
33594
|
find = { parentId: keyId, site };
|
|
33595
|
+
} else {
|
|
33596
|
+
if (isDifferentStatus && typeof key?.status == "string") {
|
|
33597
|
+
find.status = { $ne: key.status };
|
|
33598
|
+
}
|
|
33599
|
+
}
|
|
33492
33600
|
const result = await this.collection().updateMany(
|
|
33493
33601
|
find,
|
|
33494
33602
|
{ $set: key },
|
|
@@ -33514,7 +33622,11 @@ var KeyRepo = class {
|
|
|
33514
33622
|
session
|
|
33515
33623
|
});
|
|
33516
33624
|
} else {
|
|
33517
|
-
|
|
33625
|
+
if (visitorId) {
|
|
33626
|
+
console.log(`visitorId: ${visitorId} keyId: ${keyId} Not Updated`);
|
|
33627
|
+
} else {
|
|
33628
|
+
throw new Error("Failed Updating Keys");
|
|
33629
|
+
}
|
|
33518
33630
|
}
|
|
33519
33631
|
return result;
|
|
33520
33632
|
} catch (error) {
|
|
@@ -33879,40 +33991,6 @@ function useVisitorTransactionService() {
|
|
|
33879
33991
|
}
|
|
33880
33992
|
return normalized;
|
|
33881
33993
|
}
|
|
33882
|
-
async function syncTransactionKeys({
|
|
33883
|
-
current,
|
|
33884
|
-
incoming,
|
|
33885
|
-
site,
|
|
33886
|
-
session
|
|
33887
|
-
}) {
|
|
33888
|
-
const currentIds = current.map((item) => item.keyId.toString());
|
|
33889
|
-
const incomingIds = incoming.map((item) => item.keyId.toString());
|
|
33890
|
-
const currentSet = new Set(currentIds);
|
|
33891
|
-
const incomingSet = new Set(incomingIds);
|
|
33892
|
-
const removedIds = currentIds.filter((id) => !incomingSet.has(id));
|
|
33893
|
-
const addedIds = incomingIds.filter((id) => !currentSet.has(id));
|
|
33894
|
-
for (const keyId of removedIds) {
|
|
33895
|
-
const existingKey = await KeyRepo.getById(keyId);
|
|
33896
|
-
if (!existingKey)
|
|
33897
|
-
continue;
|
|
33898
|
-
if (existingKey.status === "In Use" /* IN_USE */) {
|
|
33899
|
-
await KeyRepo.updateKeyById(
|
|
33900
|
-
keyId,
|
|
33901
|
-
{ status: "Available" /* AVAILABLE */ },
|
|
33902
|
-
site,
|
|
33903
|
-
session
|
|
33904
|
-
);
|
|
33905
|
-
}
|
|
33906
|
-
}
|
|
33907
|
-
for (const keyId of addedIds) {
|
|
33908
|
-
await KeyRepo.updateKeyById(
|
|
33909
|
-
keyId,
|
|
33910
|
-
{ status: "In Use" /* IN_USE */ },
|
|
33911
|
-
site,
|
|
33912
|
-
session
|
|
33913
|
-
);
|
|
33914
|
-
}
|
|
33915
|
-
}
|
|
33916
33994
|
async function add(value) {
|
|
33917
33995
|
const session = useAtlas50.getClient()?.startSession();
|
|
33918
33996
|
const allowedPersonTypes = [
|
|
@@ -34048,7 +34126,9 @@ function useVisitorTransactionService() {
|
|
|
34048
34126
|
value.site,
|
|
34049
34127
|
session,
|
|
34050
34128
|
void 0,
|
|
34051
|
-
visitorId
|
|
34129
|
+
visitorId,
|
|
34130
|
+
void 0,
|
|
34131
|
+
true
|
|
34052
34132
|
);
|
|
34053
34133
|
}
|
|
34054
34134
|
for (const item of preparedPassKeys) {
|
|
@@ -34060,7 +34140,11 @@ function useVisitorTransactionService() {
|
|
|
34060
34140
|
visitorId
|
|
34061
34141
|
},
|
|
34062
34142
|
value.site,
|
|
34063
|
-
session
|
|
34143
|
+
session,
|
|
34144
|
+
void 0,
|
|
34145
|
+
visitorId,
|
|
34146
|
+
void 0,
|
|
34147
|
+
true
|
|
34064
34148
|
);
|
|
34065
34149
|
}
|
|
34066
34150
|
})
|
|
@@ -34116,7 +34200,9 @@ function useVisitorTransactionService() {
|
|
|
34116
34200
|
value.site,
|
|
34117
34201
|
session,
|
|
34118
34202
|
void 0,
|
|
34119
|
-
result
|
|
34203
|
+
result,
|
|
34204
|
+
void 0,
|
|
34205
|
+
true
|
|
34120
34206
|
);
|
|
34121
34207
|
}
|
|
34122
34208
|
}
|
|
@@ -34128,7 +34214,9 @@ function useVisitorTransactionService() {
|
|
|
34128
34214
|
value.site,
|
|
34129
34215
|
session,
|
|
34130
34216
|
void 0,
|
|
34131
|
-
result
|
|
34217
|
+
result,
|
|
34218
|
+
void 0,
|
|
34219
|
+
true
|
|
34132
34220
|
);
|
|
34133
34221
|
}
|
|
34134
34222
|
}
|
|
@@ -34264,7 +34352,8 @@ function useVisitorTransactionService() {
|
|
|
34264
34352
|
value.site,
|
|
34265
34353
|
session,
|
|
34266
34354
|
void 0,
|
|
34267
|
-
id
|
|
34355
|
+
id,
|
|
34356
|
+
true
|
|
34268
34357
|
);
|
|
34269
34358
|
delete item.receivedDate;
|
|
34270
34359
|
item.lastUpdate = /* @__PURE__ */ new Date();
|
|
@@ -34311,7 +34400,8 @@ function useVisitorTransactionService() {
|
|
|
34311
34400
|
value.site,
|
|
34312
34401
|
session,
|
|
34313
34402
|
void 0,
|
|
34314
|
-
id
|
|
34403
|
+
id,
|
|
34404
|
+
true
|
|
34315
34405
|
);
|
|
34316
34406
|
delete item.receivedDate;
|
|
34317
34407
|
item.lastUpdate = /* @__PURE__ */ new Date();
|
|
@@ -34482,63 +34572,12 @@ function useVisitorTransactionService() {
|
|
|
34482
34572
|
session?.endSession();
|
|
34483
34573
|
}
|
|
34484
34574
|
}
|
|
34485
|
-
async function changeVisitorTransactionKeysById(id, visitorPass, passKeys) {
|
|
34486
|
-
const session = useAtlas50.getClient()?.startSession();
|
|
34487
|
-
if (!session) {
|
|
34488
|
-
throw new Error(
|
|
34489
|
-
"Unable to start session for visitor transaction service."
|
|
34490
|
-
);
|
|
34491
|
-
}
|
|
34492
|
-
try {
|
|
34493
|
-
session.startTransaction();
|
|
34494
|
-
const visitorTransaction = await _getVisitorTransactionById(id);
|
|
34495
|
-
if (!visitorTransaction) {
|
|
34496
|
-
throw new Error("Visitor transaction not found.");
|
|
34497
|
-
}
|
|
34498
|
-
const updatePayload = {};
|
|
34499
|
-
if (visitorPass !== void 0) {
|
|
34500
|
-
const currentVisitorPass = normalizeKeyRefs(
|
|
34501
|
-
visitorTransaction.visitorPass
|
|
34502
|
-
);
|
|
34503
|
-
const incomingVisitorPass = normalizeKeyRefs(visitorPass);
|
|
34504
|
-
await syncTransactionKeys({
|
|
34505
|
-
current: currentVisitorPass,
|
|
34506
|
-
incoming: incomingVisitorPass,
|
|
34507
|
-
site: visitorTransaction.site,
|
|
34508
|
-
session
|
|
34509
|
-
});
|
|
34510
|
-
updatePayload.visitorPass = incomingVisitorPass;
|
|
34511
|
-
}
|
|
34512
|
-
if (passKeys !== void 0) {
|
|
34513
|
-
const currentPassKeys = normalizeKeyRefs(visitorTransaction.passKeys);
|
|
34514
|
-
const incomingPassKeys = normalizeKeyRefs(passKeys);
|
|
34515
|
-
await syncTransactionKeys({
|
|
34516
|
-
current: currentPassKeys,
|
|
34517
|
-
incoming: incomingPassKeys,
|
|
34518
|
-
site: visitorTransaction.site,
|
|
34519
|
-
session
|
|
34520
|
-
});
|
|
34521
|
-
updatePayload.passKeys = incomingPassKeys;
|
|
34522
|
-
}
|
|
34523
|
-
if (Object.keys(updatePayload).length > 0) {
|
|
34524
|
-
await _updateVisitorTansactionById(id, updatePayload, session);
|
|
34525
|
-
}
|
|
34526
|
-
await session.commitTransaction();
|
|
34527
|
-
return "Successfully changed visitor transaction keys.";
|
|
34528
|
-
} catch (error) {
|
|
34529
|
-
await session.abortTransaction();
|
|
34530
|
-
logger80.error("Error in visitor transaction change keys by id:", error);
|
|
34531
|
-
throw error;
|
|
34532
|
-
} finally {
|
|
34533
|
-
session.endSession();
|
|
34534
|
-
}
|
|
34535
|
-
}
|
|
34536
34575
|
return {
|
|
34537
34576
|
add,
|
|
34538
34577
|
updateVisitorTransactionById,
|
|
34539
34578
|
processTransactionDahuaStatus,
|
|
34540
|
-
inviteVisitor
|
|
34541
|
-
changeVisitorTransactionKeysById
|
|
34579
|
+
inviteVisitor
|
|
34580
|
+
// changeVisitorTransactionKeysById,
|
|
34542
34581
|
};
|
|
34543
34582
|
}
|
|
34544
34583
|
|
|
@@ -34549,8 +34588,8 @@ function useVisitorTransactionController() {
|
|
|
34549
34588
|
const {
|
|
34550
34589
|
add: _add,
|
|
34551
34590
|
updateVisitorTransactionById: _updateVisitorTransactionById,
|
|
34552
|
-
inviteVisitor: _inviteVisitor
|
|
34553
|
-
changeVisitorTransactionKeysById: _changeVisitorTransactionKeysById
|
|
34591
|
+
inviteVisitor: _inviteVisitor
|
|
34592
|
+
// changeVisitorTransactionKeysById: _changeVisitorTransactionKeysById,
|
|
34554
34593
|
} = useVisitorTransactionService();
|
|
34555
34594
|
const {
|
|
34556
34595
|
getAll: _getAll,
|
|
@@ -34707,7 +34746,12 @@ function useVisitorTransactionController() {
|
|
|
34707
34746
|
return;
|
|
34708
34747
|
} catch (error2) {
|
|
34709
34748
|
logger81.log({ level: "error", message: error2.message });
|
|
34710
|
-
|
|
34749
|
+
console.log("error", error2);
|
|
34750
|
+
if (error2?.message) {
|
|
34751
|
+
next(new BadRequestError101(error2?.message));
|
|
34752
|
+
} else {
|
|
34753
|
+
next(error2);
|
|
34754
|
+
}
|
|
34711
34755
|
return;
|
|
34712
34756
|
}
|
|
34713
34757
|
}
|
|
@@ -34800,61 +34844,14 @@ function useVisitorTransactionController() {
|
|
|
34800
34844
|
}
|
|
34801
34845
|
}
|
|
34802
34846
|
}
|
|
34803
|
-
async function changeVisitorTransactionKeysById(req, res, next) {
|
|
34804
|
-
const idValidation = Joi57.string().hex().length(24).required();
|
|
34805
|
-
const bodyValidation = Joi57.object({
|
|
34806
|
-
visitorPass: Joi57.array().items(
|
|
34807
|
-
Joi57.object({
|
|
34808
|
-
keyId: Joi57.string().hex().length(24).required()
|
|
34809
|
-
})
|
|
34810
|
-
).optional(),
|
|
34811
|
-
passKeys: Joi57.array().items(
|
|
34812
|
-
Joi57.object({
|
|
34813
|
-
keyId: Joi57.string().hex().length(24).required()
|
|
34814
|
-
})
|
|
34815
|
-
).optional()
|
|
34816
|
-
}).or("visitorPass", "passKeys");
|
|
34817
|
-
const _id = req.params.id;
|
|
34818
|
-
const { error: idError } = idValidation.validate(_id);
|
|
34819
|
-
if (idError) {
|
|
34820
|
-
logger81.log({ level: "error", message: idError.message });
|
|
34821
|
-
next(new BadRequestError101(idError.message));
|
|
34822
|
-
return;
|
|
34823
|
-
}
|
|
34824
|
-
const { error, value } = bodyValidation.validate(req.body, {
|
|
34825
|
-
abortEarly: false
|
|
34826
|
-
});
|
|
34827
|
-
if (error) {
|
|
34828
|
-
const message = error.details.map((d) => d.message).join(", ");
|
|
34829
|
-
logger81.log({ level: "error", message });
|
|
34830
|
-
next(new BadRequestError101(message));
|
|
34831
|
-
return;
|
|
34832
|
-
}
|
|
34833
|
-
try {
|
|
34834
|
-
const { visitorPass, passKeys } = value;
|
|
34835
|
-
const result = await _changeVisitorTransactionKeysById(
|
|
34836
|
-
_id,
|
|
34837
|
-
visitorPass,
|
|
34838
|
-
passKeys
|
|
34839
|
-
);
|
|
34840
|
-
res.status(200).json({
|
|
34841
|
-
message: result || "Successfully changed visitor transaction keys."
|
|
34842
|
-
});
|
|
34843
|
-
return;
|
|
34844
|
-
} catch (error2) {
|
|
34845
|
-
logger81.log({ level: "error", message: error2.message });
|
|
34846
|
-
next(error2);
|
|
34847
|
-
return;
|
|
34848
|
-
}
|
|
34849
|
-
}
|
|
34850
34847
|
return {
|
|
34851
34848
|
add,
|
|
34852
34849
|
getAll,
|
|
34853
34850
|
updateVisitorTansactionById,
|
|
34854
34851
|
deleteVisitorTransaction,
|
|
34855
34852
|
inviteVisitor,
|
|
34856
|
-
getVisitorTransactionById
|
|
34857
|
-
changeVisitorTransactionKeysById
|
|
34853
|
+
getVisitorTransactionById
|
|
34854
|
+
// changeVisitorTransactionKeysById,
|
|
34858
34855
|
};
|
|
34859
34856
|
}
|
|
34860
34857
|
|
|
@@ -54646,7 +54643,7 @@ function useIncidentReportRepo() {
|
|
|
54646
54643
|
}
|
|
54647
54644
|
|
|
54648
54645
|
// src/services/incident-report.service.ts
|
|
54649
|
-
import
|
|
54646
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
54650
54647
|
function useIncidentReportService() {
|
|
54651
54648
|
const {
|
|
54652
54649
|
add: _add,
|
|
@@ -54739,20 +54736,12 @@ function useIncidentReportService() {
|
|
|
54739
54736
|
}
|
|
54740
54737
|
}
|
|
54741
54738
|
async function createIncidentSummary(value) {
|
|
54742
|
-
const session = useAtlas91.getClient()?.startSession();
|
|
54743
|
-
session?.startTransaction();
|
|
54744
54739
|
const sample = `On August 4, 2024, an incident report labeled IR10 was submitted following an earthquake that occurred between 10:00 AM and 10:30 AM at a designated test site. The report indicated that the incident was reported by a complainant named Maryam, who provided her contact information as +65-123456789. The recipient of the complaint was Rash, whose contact number is +65-987654321. The description of the complaint detailed a historical context regarding the origins of Lorem Ipsum text, an academic piece that has been referenced throughout centuries.
|
|
54745
|
-
|
|
54746
|
-
|
|
54747
|
-
|
|
54748
|
-
'
|
|
54749
|
-
|
|
54750
|
-
'
|
|
54751
|
-
' +
|
|
54752
|
-
"No authorities were called, and the incident's resolution was marked at 11:00 AM, with actions taken by Ola, the shift in charge during the incident. The management was informed of the incident at 10:08 AM, and security implications were considered but not detailed. The report remains pending and does not mention a reason for rejection or approval status. The incident is documented with attached photographs. The overall status of the report remains pending as of the latest update.`;
|
|
54753
|
-
const openai = new OpenAI({
|
|
54754
|
-
apiKey: OPEN_AI_API_KEY
|
|
54755
|
-
});
|
|
54740
|
+
|
|
54741
|
+
The report highlighted that no individuals were directly affected or injured in the incident. However, there was damage to property associated with the incident, particularly mentioning an individual named Ruzzy, with contact +65-34567777889, who experienced property damage. The report states that this damage was also elaborated upon with historical context, reiterating similar pieces of information on the classical literature that influenced the Lorem Ipsum narrative.
|
|
54742
|
+
|
|
54743
|
+
No authorities were called, and the incident's resolution was marked at 11:00 AM, with actions taken by Ola, the shift in charge during the incident. The management was informed of the incident at 10:08 AM, and security implications were considered but not detailed. The report remains pending and does not mention a reason for rejection or approval status. The incident is documented with attached photographs. The overall status of the report remains pending as of the latest update.`;
|
|
54744
|
+
const anthropic = new Anthropic({ apiKey: ANTHROPIC_API_KEY });
|
|
54756
54745
|
try {
|
|
54757
54746
|
if (value?.incidentInformation?.siteInfo?.site) {
|
|
54758
54747
|
const site = await _getSiteById(
|
|
@@ -54769,19 +54758,15 @@ function useIncidentReportService() {
|
|
|
54769
54758
|
value.organization = org.name;
|
|
54770
54759
|
}
|
|
54771
54760
|
}
|
|
54772
|
-
const
|
|
54773
|
-
model: "
|
|
54774
|
-
|
|
54775
|
-
|
|
54776
|
-
|
|
54777
|
-
content: `You write a comprehensive summary for incident reports, exclude the attachment, and make it in essay format, and don't add any explaination to how the summary is about, and don't use the mongodb id number for the summary and Must include the following answers to What happened ?, Where did it happened ?, Who was involved ?, How did it happened?, Why did it happened?, Is there any security implications due to incident ?, just keep it plain since we will save it directly into the database. here's a sample: ${sample}`
|
|
54778
|
-
},
|
|
54779
|
-
{ role: "user", content: JSON.stringify(value) }
|
|
54780
|
-
]
|
|
54761
|
+
const response = await anthropic.messages.create({
|
|
54762
|
+
model: "claude-sonnet-4-6",
|
|
54763
|
+
max_tokens: 1024,
|
|
54764
|
+
system: `You write a comprehensive summary for incident reports, exclude the attachment, and make it in essay format, and don't add any explaination to how the summary is about, and don't use the mongodb id number for the summary and Must include the following answers to What happened ?, Where did it happened ?, Who was involved ?, How did it happened?, Why did it happened?, Is there any security implications due to incident ?, just keep it plain since we will save it directly into the database. here's a sample: ${sample}`,
|
|
54765
|
+
messages: [{ role: "user", content: JSON.stringify(value) }]
|
|
54781
54766
|
});
|
|
54782
|
-
const
|
|
54783
|
-
if (
|
|
54784
|
-
return
|
|
54767
|
+
const briefSummary = response.content[0].type === "text" ? response.content[0].text : null;
|
|
54768
|
+
if (briefSummary) {
|
|
54769
|
+
return briefSummary;
|
|
54785
54770
|
} else {
|
|
54786
54771
|
return "Failed to generate a summary.";
|
|
54787
54772
|
}
|
|
@@ -70055,6 +70040,7 @@ export {
|
|
|
70055
70040
|
useManpowerSitesSrvc,
|
|
70056
70041
|
useMemberController,
|
|
70057
70042
|
useMemberRepo,
|
|
70043
|
+
useMemberService,
|
|
70058
70044
|
useNewDashboardController,
|
|
70059
70045
|
useNewDashboardRepo,
|
|
70060
70046
|
useNfcPatrolLogController,
|