@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/dist/index.js CHANGED
@@ -6267,6 +6267,7 @@ __export(src_exports, {
6267
6267
  useManpowerSitesSrvc: () => useManpowerSitesSrvc,
6268
6268
  useMemberController: () => useMemberController,
6269
6269
  useMemberRepo: () => useMemberRepo,
6270
+ useMemberService: () => useMemberService,
6270
6271
  useNewDashboardController: () => useNewDashboardController,
6271
6272
  useNewDashboardRepo: () => useNewDashboardRepo,
6272
6273
  useNfcPatrolLogController: () => useNfcPatrolLogController,
@@ -9170,6 +9171,7 @@ var APP_POOL_MAINTENANCE = process.env.APP_POOL_MAINTENANCE ?? "http://localhost
9170
9171
  var ENCRYPTION_KEY = process.env.ENCRYPTION_KEY ?? "";
9171
9172
  var DOMAIN = process.env.DOMAIN ?? "localhost";
9172
9173
  var OPEN_AI_API_KEY = process.env.OPEN_AI_API_KEY;
9174
+ var ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
9173
9175
  var STORAGE_API = process.env.STORAGE_API;
9174
9176
 
9175
9177
  // src/services/auth.service.ts
@@ -9660,59 +9662,41 @@ function useMemberRepo() {
9660
9662
  try {
9661
9663
  const items = await collection.aggregate([
9662
9664
  { $match: query },
9663
- { $sort: { _id: -1 } },
9664
- { $skip: page * limit },
9665
- { $limit: limit },
9666
- {
9667
- $lookup: {
9668
- from: "organizations",
9669
- localField: "org",
9670
- foreignField: "_id",
9671
- as: "orgData"
9672
- }
9673
- },
9674
- {
9675
- $unwind: {
9676
- path: "$orgData",
9677
- preserveNullAndEmptyArrays: true
9678
- }
9679
- },
9680
9665
  {
9681
9666
  $lookup: {
9682
9667
  from: "organizations",
9683
9668
  localField: "org",
9684
9669
  foreignField: "_id",
9685
- as: "defaultSite"
9670
+ as: "org"
9686
9671
  }
9687
9672
  },
9688
9673
  {
9689
9674
  $unwind: {
9690
- path: "$defaultSite",
9675
+ path: "$org",
9691
9676
  preserveNullAndEmptyArrays: true
9692
9677
  }
9693
9678
  },
9694
9679
  {
9695
9680
  $group: {
9696
- _id: "$org",
9697
- text: { $first: "$orgName" },
9698
- value: { $first: "$org" },
9699
- defaultSite: { $first: "$defaultSite.defaultSite" },
9700
- onboardingRequired: {
9701
- $first: "$orgData.onboardingRequired"
9702
- },
9703
- onboardingCompleted: {
9704
- $first: "$orgData.onboardingCompleted"
9705
- },
9706
- onboardingCompletedAt: {
9707
- $first: "$orgData.onboardingCompletedAt"
9708
- }
9681
+ _id: "$org._id",
9682
+ text: { $first: "$org.name" },
9683
+ value: { $first: "$org._id" },
9684
+ type: { $first: "$org.type" },
9685
+ defaultSite: { $first: "$org.defaultSite" },
9686
+ onboardingRequired: { $first: "$org.onboardingRequired" },
9687
+ onboardingCompleted: { $first: "$org.onboardingCompleted" },
9688
+ onboardingCompletedAt: { $first: "$org.onboardingCompletedAt" }
9709
9689
  }
9710
9690
  },
9691
+ { $sort: { _id: -1 } },
9692
+ { $skip: page * limit },
9693
+ { $limit: limit },
9711
9694
  {
9712
9695
  $project: {
9713
9696
  _id: 0,
9714
9697
  text: 1,
9715
9698
  value: 1,
9699
+ type: 1,
9716
9700
  defaultSite: 1,
9717
9701
  onboardingRequired: 1,
9718
9702
  onboardingCompleted: 1,
@@ -10577,6 +10561,56 @@ function useVerificationRepo() {
10577
10561
  async function findOne(query) {
10578
10562
  return await collection.findOne(query);
10579
10563
  }
10564
+ async function completePendingInvites({
10565
+ email,
10566
+ orgId,
10567
+ siteId,
10568
+ app,
10569
+ session
10570
+ }) {
10571
+ const orgCandidates = [orgId];
10572
+ try {
10573
+ orgCandidates.push(new import_mongodb13.ObjectId(orgId));
10574
+ } catch {
10575
+ }
10576
+ const query = {
10577
+ email: { $regex: `^${email}$`, $options: "i" },
10578
+ status: "pending",
10579
+ type: {
10580
+ $in: ["user-invite" /* USER_INVITE */, "member-invite" /* MEMBER_INVITE */]
10581
+ },
10582
+ "metadata.org": { $in: orgCandidates }
10583
+ };
10584
+ if (siteId) {
10585
+ const siteCandidates = [siteId];
10586
+ try {
10587
+ siteCandidates.push(new import_mongodb13.ObjectId(siteId));
10588
+ } catch {
10589
+ }
10590
+ query["metadata.siteId"] = { $in: siteCandidates };
10591
+ }
10592
+ if (app) {
10593
+ query["metadata.app"] = app;
10594
+ }
10595
+ try {
10596
+ const result = await collection.updateMany(
10597
+ query,
10598
+ { $set: { status: "complete", updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
10599
+ { session }
10600
+ );
10601
+ delNamespace().then(() => {
10602
+ import_node_server_utils15.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
10603
+ }).catch((err) => {
10604
+ import_node_server_utils15.logger.error(
10605
+ `Failed to clear cache for namespace: ${namespace_collection}`,
10606
+ err
10607
+ );
10608
+ });
10609
+ return result;
10610
+ } catch (error) {
10611
+ throw new import_node_server_utils15.InternalServerError("Failed to complete pending invites.");
10612
+ }
10613
+ }
10580
10614
  return {
10581
10615
  createIndex,
10582
10616
  createTextIndex,
@@ -10586,7 +10620,8 @@ function useVerificationRepo() {
10586
10620
  getByIdByType,
10587
10621
  updateStatusById,
10588
10622
  getByStatus,
10589
- findOne
10623
+ findOne,
10624
+ completePendingInvites
10590
10625
  };
10591
10626
  }
10592
10627
 
@@ -11511,21 +11546,10 @@ function useSiteRepo() {
11511
11546
  throw new import_node_server_utils19.BadRequestError("Invalid site ID format.");
11512
11547
  }
11513
11548
  try {
11514
- const cacheKey = (0, import_node_server_utils19.makeCacheKey)(namespace_collection, { _id });
11515
- const cachedData = await getCache(cacheKey);
11516
- if (cachedData) {
11517
- import_node_server_utils19.logger.info(`Cache hit for key: ${cacheKey}`);
11518
- return cachedData;
11519
- }
11520
11549
  const data = await collection.aggregate([{ $match: { _id, status: { $ne: "deleted" } } }]).toArray();
11521
11550
  if (!data || !data.length) {
11522
11551
  throw new import_node_server_utils19.NotFoundError("Site not found.");
11523
11552
  }
11524
- setCache(cacheKey, data[0], 15 * 60).then(() => {
11525
- import_node_server_utils19.logger.info(`Cache set for key: ${cacheKey}`);
11526
- }).catch((err) => {
11527
- import_node_server_utils19.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
11528
- });
11529
11553
  return data[0];
11530
11554
  } catch (error) {
11531
11555
  throw error;
@@ -12163,6 +12187,61 @@ function useVerificationRepoV2() {
12163
12187
  throw new import_node_server_utils20.InternalServerError("Failed to update verification code.");
12164
12188
  }
12165
12189
  }
12190
+ async function completePendingInvites({
12191
+ email,
12192
+ orgId,
12193
+ siteId,
12194
+ app,
12195
+ session
12196
+ }) {
12197
+ const orgCandidates = [orgId];
12198
+ try {
12199
+ orgCandidates.push(new import_mongodb18.ObjectId(orgId));
12200
+ } catch {
12201
+ }
12202
+ const query = {
12203
+ email: { $regex: `^${email}$`, $options: "i" },
12204
+ status: "pending" /* PENDING */,
12205
+ type: {
12206
+ $in: ["user-invite" /* USER_INVITE */, "member-invite" /* MEMBER_INVITE */]
12207
+ },
12208
+ "metadata.org": { $in: orgCandidates }
12209
+ };
12210
+ if (siteId) {
12211
+ const siteCandidates = [siteId];
12212
+ try {
12213
+ siteCandidates.push(new import_mongodb18.ObjectId(siteId));
12214
+ } catch {
12215
+ }
12216
+ query["metadata.siteId"] = { $in: siteCandidates };
12217
+ }
12218
+ if (app) {
12219
+ query["metadata.app"] = app;
12220
+ }
12221
+ try {
12222
+ const result = await collection.updateMany(
12223
+ query,
12224
+ {
12225
+ $set: {
12226
+ status: "complete" /* COMPLETE */,
12227
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
12228
+ }
12229
+ },
12230
+ { session }
12231
+ );
12232
+ delNamespace().then(() => {
12233
+ import_node_server_utils20.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
12234
+ }).catch((err) => {
12235
+ import_node_server_utils20.logger.error(
12236
+ `Failed to clear cache for namespace: ${namespace_collection}`,
12237
+ err
12238
+ );
12239
+ });
12240
+ return result;
12241
+ } catch (error) {
12242
+ throw new import_node_server_utils20.InternalServerError("Failed to complete pending invites.");
12243
+ }
12244
+ }
12166
12245
  return {
12167
12246
  createIndex,
12168
12247
  createTextIndex,
@@ -12174,7 +12253,8 @@ function useVerificationRepoV2() {
12174
12253
  updateStatusById,
12175
12254
  countPendingOrgInvites,
12176
12255
  getPendingVerificationByEmail,
12177
- updateVerificationCodeById
12256
+ updateVerificationCodeById,
12257
+ completePendingInvites
12178
12258
  };
12179
12259
  }
12180
12260
 
@@ -14262,7 +14342,7 @@ function useMemberService() {
14262
14342
  getAllByUserId: _getAllByUserId,
14263
14343
  completeOnboardingById: _completeOnboardingById
14264
14344
  } = useMemberRepo();
14265
- const { getById: _getVerificationById, updateStatusById } = useVerificationRepo();
14345
+ const { getById: _getVerificationById, updateStatusById, completePendingInvites } = useVerificationRepo();
14266
14346
  const { getUserByEmail, updateDefaultOrgByEmail, getUserById } = useUserRepo();
14267
14347
  const { getById: getOrgById } = useOrgRepo();
14268
14348
  const { getSiteById } = useSiteRepo();
@@ -14366,6 +14446,13 @@ function useMemberService() {
14366
14446
  session
14367
14447
  );
14368
14448
  }
14449
+ await completePendingInvites({
14450
+ email: user.email,
14451
+ orgId,
14452
+ siteId,
14453
+ app,
14454
+ session
14455
+ });
14369
14456
  await session?.commitTransaction();
14370
14457
  return { member };
14371
14458
  } catch (error) {
@@ -21318,6 +21405,7 @@ async function convertObjectIdUtil2(id, fieldName) {
21318
21405
  throw new Error(`Invalid ID conversion to ObjectId of ${fieldName}.`);
21319
21406
  return new import_mongodb40.ObjectId(id);
21320
21407
  } catch (_) {
21408
+ console.log(`Invalid ID conversion to ObjectId of ${fieldName}. : `, id);
21321
21409
  throw new Error(`Invalid ID conversion to ObjectId of ${fieldName}.`);
21322
21410
  }
21323
21411
  }
@@ -33624,12 +33712,28 @@ var KeyRepo = class {
33624
33712
  return Promise.reject("Server internal error.");
33625
33713
  }
33626
33714
  }
33627
- static async updateKeyById(keyId, key, site, session, isChild, visitorId) {
33715
+ static async updateKeyById(keyId, key, site, session, isChild, visitorId, isDifferentStatus, isPassKeyVisitorAdd) {
33628
33716
  keyId = await convertObjectIdUtil2(keyId, "keyId");
33629
33717
  if (site)
33630
33718
  site = await convertObjectIdUtil2(site, "Site");
33631
- if (visitorId)
33632
- visitorId = await convertObjectIdUtil2(visitorId, "visitor Id");
33719
+ if (visitorId) {
33720
+ visitorId = await convertObjectIdUtil2(visitorId, "Visitor Id");
33721
+ if (!isPassKeyVisitorAdd) {
33722
+ const findOptions = { sort: { _id: -1 } };
33723
+ const latestHistory = await this.collectionDynamic("keys-histories").findOne(
33724
+ { passOrKeyId: keyId },
33725
+ findOptions
33726
+ );
33727
+ console.log("visitorId", visitorId.toString());
33728
+ console.log("latestHistory.visitorId", latestHistory?.visitorId.toString());
33729
+ if (latestHistory?.visitorId && latestHistory.visitorId?.toString() !== visitorId.toString()) {
33730
+ console.log("Not updating keyId", keyId);
33731
+ return;
33732
+ } else {
33733
+ console.log("updating keyId", keyId);
33734
+ }
33735
+ }
33736
+ }
33633
33737
  if (key.updatedBy)
33634
33738
  key.updatedBy = await convertObjectIdUtil2(key.updatedBy, "Updated By");
33635
33739
  if (!key.status)
@@ -33637,9 +33741,14 @@ var KeyRepo = class {
33637
33741
  try {
33638
33742
  key.updatedAt = /* @__PURE__ */ new Date();
33639
33743
  const query = { _id: keyId, ...site && { site } };
33640
- let find = query;
33641
- if (isChild)
33744
+ let find = { ...query };
33745
+ if (isChild) {
33642
33746
  find = { parentId: keyId, site };
33747
+ } else {
33748
+ if (isDifferentStatus && typeof key?.status == "string") {
33749
+ find.status = { $ne: key.status };
33750
+ }
33751
+ }
33643
33752
  const result = await this.collection().updateMany(
33644
33753
  find,
33645
33754
  { $set: key },
@@ -33665,7 +33774,11 @@ var KeyRepo = class {
33665
33774
  session
33666
33775
  });
33667
33776
  } else {
33668
- throw new Error("Failed Updating Keys");
33777
+ if (visitorId) {
33778
+ console.log(`visitorId: ${visitorId} keyId: ${keyId} Not Updated`);
33779
+ } else {
33780
+ throw new Error("Failed Updating Keys");
33781
+ }
33669
33782
  }
33670
33783
  return result;
33671
33784
  } catch (error) {
@@ -34030,40 +34143,6 @@ function useVisitorTransactionService() {
34030
34143
  }
34031
34144
  return normalized;
34032
34145
  }
34033
- async function syncTransactionKeys({
34034
- current,
34035
- incoming,
34036
- site,
34037
- session
34038
- }) {
34039
- const currentIds = current.map((item) => item.keyId.toString());
34040
- const incomingIds = incoming.map((item) => item.keyId.toString());
34041
- const currentSet = new Set(currentIds);
34042
- const incomingSet = new Set(incomingIds);
34043
- const removedIds = currentIds.filter((id) => !incomingSet.has(id));
34044
- const addedIds = incomingIds.filter((id) => !currentSet.has(id));
34045
- for (const keyId of removedIds) {
34046
- const existingKey = await KeyRepo.getById(keyId);
34047
- if (!existingKey)
34048
- continue;
34049
- if (existingKey.status === "In Use" /* IN_USE */) {
34050
- await KeyRepo.updateKeyById(
34051
- keyId,
34052
- { status: "Available" /* AVAILABLE */ },
34053
- site,
34054
- session
34055
- );
34056
- }
34057
- }
34058
- for (const keyId of addedIds) {
34059
- await KeyRepo.updateKeyById(
34060
- keyId,
34061
- { status: "In Use" /* IN_USE */ },
34062
- site,
34063
- session
34064
- );
34065
- }
34066
- }
34067
34146
  async function add(value) {
34068
34147
  const session = import_node_server_utils106.useAtlas.getClient()?.startSession();
34069
34148
  const allowedPersonTypes = [
@@ -34199,7 +34278,9 @@ function useVisitorTransactionService() {
34199
34278
  value.site,
34200
34279
  session,
34201
34280
  void 0,
34202
- visitorId
34281
+ visitorId,
34282
+ void 0,
34283
+ true
34203
34284
  );
34204
34285
  }
34205
34286
  for (const item of preparedPassKeys) {
@@ -34211,7 +34292,11 @@ function useVisitorTransactionService() {
34211
34292
  visitorId
34212
34293
  },
34213
34294
  value.site,
34214
- session
34295
+ session,
34296
+ void 0,
34297
+ visitorId,
34298
+ void 0,
34299
+ true
34215
34300
  );
34216
34301
  }
34217
34302
  })
@@ -34267,7 +34352,9 @@ function useVisitorTransactionService() {
34267
34352
  value.site,
34268
34353
  session,
34269
34354
  void 0,
34270
- result
34355
+ result,
34356
+ void 0,
34357
+ true
34271
34358
  );
34272
34359
  }
34273
34360
  }
@@ -34279,7 +34366,9 @@ function useVisitorTransactionService() {
34279
34366
  value.site,
34280
34367
  session,
34281
34368
  void 0,
34282
- result
34369
+ result,
34370
+ void 0,
34371
+ true
34283
34372
  );
34284
34373
  }
34285
34374
  }
@@ -34415,7 +34504,8 @@ function useVisitorTransactionService() {
34415
34504
  value.site,
34416
34505
  session,
34417
34506
  void 0,
34418
- id
34507
+ id,
34508
+ true
34419
34509
  );
34420
34510
  delete item.receivedDate;
34421
34511
  item.lastUpdate = /* @__PURE__ */ new Date();
@@ -34462,7 +34552,8 @@ function useVisitorTransactionService() {
34462
34552
  value.site,
34463
34553
  session,
34464
34554
  void 0,
34465
- id
34555
+ id,
34556
+ true
34466
34557
  );
34467
34558
  delete item.receivedDate;
34468
34559
  item.lastUpdate = /* @__PURE__ */ new Date();
@@ -34633,63 +34724,12 @@ function useVisitorTransactionService() {
34633
34724
  session?.endSession();
34634
34725
  }
34635
34726
  }
34636
- async function changeVisitorTransactionKeysById(id, visitorPass, passKeys) {
34637
- const session = import_node_server_utils106.useAtlas.getClient()?.startSession();
34638
- if (!session) {
34639
- throw new Error(
34640
- "Unable to start session for visitor transaction service."
34641
- );
34642
- }
34643
- try {
34644
- session.startTransaction();
34645
- const visitorTransaction = await _getVisitorTransactionById(id);
34646
- if (!visitorTransaction) {
34647
- throw new Error("Visitor transaction not found.");
34648
- }
34649
- const updatePayload = {};
34650
- if (visitorPass !== void 0) {
34651
- const currentVisitorPass = normalizeKeyRefs(
34652
- visitorTransaction.visitorPass
34653
- );
34654
- const incomingVisitorPass = normalizeKeyRefs(visitorPass);
34655
- await syncTransactionKeys({
34656
- current: currentVisitorPass,
34657
- incoming: incomingVisitorPass,
34658
- site: visitorTransaction.site,
34659
- session
34660
- });
34661
- updatePayload.visitorPass = incomingVisitorPass;
34662
- }
34663
- if (passKeys !== void 0) {
34664
- const currentPassKeys = normalizeKeyRefs(visitorTransaction.passKeys);
34665
- const incomingPassKeys = normalizeKeyRefs(passKeys);
34666
- await syncTransactionKeys({
34667
- current: currentPassKeys,
34668
- incoming: incomingPassKeys,
34669
- site: visitorTransaction.site,
34670
- session
34671
- });
34672
- updatePayload.passKeys = incomingPassKeys;
34673
- }
34674
- if (Object.keys(updatePayload).length > 0) {
34675
- await _updateVisitorTansactionById(id, updatePayload, session);
34676
- }
34677
- await session.commitTransaction();
34678
- return "Successfully changed visitor transaction keys.";
34679
- } catch (error) {
34680
- await session.abortTransaction();
34681
- import_node_server_utils106.logger.error("Error in visitor transaction change keys by id:", error);
34682
- throw error;
34683
- } finally {
34684
- session.endSession();
34685
- }
34686
- }
34687
34727
  return {
34688
34728
  add,
34689
34729
  updateVisitorTransactionById,
34690
34730
  processTransactionDahuaStatus,
34691
- inviteVisitor,
34692
- changeVisitorTransactionKeysById
34731
+ inviteVisitor
34732
+ // changeVisitorTransactionKeysById,
34693
34733
  };
34694
34734
  }
34695
34735
 
@@ -34700,8 +34740,8 @@ function useVisitorTransactionController() {
34700
34740
  const {
34701
34741
  add: _add,
34702
34742
  updateVisitorTransactionById: _updateVisitorTransactionById,
34703
- inviteVisitor: _inviteVisitor,
34704
- changeVisitorTransactionKeysById: _changeVisitorTransactionKeysById
34743
+ inviteVisitor: _inviteVisitor
34744
+ // changeVisitorTransactionKeysById: _changeVisitorTransactionKeysById,
34705
34745
  } = useVisitorTransactionService();
34706
34746
  const {
34707
34747
  getAll: _getAll,
@@ -34858,7 +34898,12 @@ function useVisitorTransactionController() {
34858
34898
  return;
34859
34899
  } catch (error2) {
34860
34900
  import_node_server_utils107.logger.log({ level: "error", message: error2.message });
34861
- next(error2);
34901
+ console.log("error", error2);
34902
+ if (error2?.message) {
34903
+ next(new import_node_server_utils107.BadRequestError(error2?.message));
34904
+ } else {
34905
+ next(error2);
34906
+ }
34862
34907
  return;
34863
34908
  }
34864
34909
  }
@@ -34951,61 +34996,14 @@ function useVisitorTransactionController() {
34951
34996
  }
34952
34997
  }
34953
34998
  }
34954
- async function changeVisitorTransactionKeysById(req, res, next) {
34955
- const idValidation = import_joi57.default.string().hex().length(24).required();
34956
- const bodyValidation = import_joi57.default.object({
34957
- visitorPass: import_joi57.default.array().items(
34958
- import_joi57.default.object({
34959
- keyId: import_joi57.default.string().hex().length(24).required()
34960
- })
34961
- ).optional(),
34962
- passKeys: import_joi57.default.array().items(
34963
- import_joi57.default.object({
34964
- keyId: import_joi57.default.string().hex().length(24).required()
34965
- })
34966
- ).optional()
34967
- }).or("visitorPass", "passKeys");
34968
- const _id = req.params.id;
34969
- const { error: idError } = idValidation.validate(_id);
34970
- if (idError) {
34971
- import_node_server_utils107.logger.log({ level: "error", message: idError.message });
34972
- next(new import_node_server_utils107.BadRequestError(idError.message));
34973
- return;
34974
- }
34975
- const { error, value } = bodyValidation.validate(req.body, {
34976
- abortEarly: false
34977
- });
34978
- if (error) {
34979
- const message = error.details.map((d) => d.message).join(", ");
34980
- import_node_server_utils107.logger.log({ level: "error", message });
34981
- next(new import_node_server_utils107.BadRequestError(message));
34982
- return;
34983
- }
34984
- try {
34985
- const { visitorPass, passKeys } = value;
34986
- const result = await _changeVisitorTransactionKeysById(
34987
- _id,
34988
- visitorPass,
34989
- passKeys
34990
- );
34991
- res.status(200).json({
34992
- message: result || "Successfully changed visitor transaction keys."
34993
- });
34994
- return;
34995
- } catch (error2) {
34996
- import_node_server_utils107.logger.log({ level: "error", message: error2.message });
34997
- next(error2);
34998
- return;
34999
- }
35000
- }
35001
34999
  return {
35002
35000
  add,
35003
35001
  getAll,
35004
35002
  updateVisitorTansactionById,
35005
35003
  deleteVisitorTransaction,
35006
35004
  inviteVisitor,
35007
- getVisitorTransactionById,
35008
- changeVisitorTransactionKeysById
35005
+ getVisitorTransactionById
35006
+ // changeVisitorTransactionKeysById,
35009
35007
  };
35010
35008
  }
35011
35009
 
@@ -54554,7 +54552,7 @@ function useIncidentReportRepo() {
54554
54552
  }
54555
54553
 
54556
54554
  // src/services/incident-report.service.ts
54557
- var import_openai = __toESM(require("openai"));
54555
+ var import_sdk = __toESM(require("@anthropic-ai/sdk"));
54558
54556
  function useIncidentReportService() {
54559
54557
  const {
54560
54558
  add: _add,
@@ -54647,20 +54645,12 @@ function useIncidentReportService() {
54647
54645
  }
54648
54646
  }
54649
54647
  async function createIncidentSummary(value) {
54650
- const session = import_node_server_utils182.useAtlas.getClient()?.startSession();
54651
- session?.startTransaction();
54652
54648
  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.
54653
- ' +
54654
- '
54655
- ' +
54656
- '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.
54657
- ' +
54658
- '
54659
- ' +
54660
- "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.`;
54661
- const openai = new import_openai.default({
54662
- apiKey: OPEN_AI_API_KEY
54663
- });
54649
+
54650
+ 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.
54651
+
54652
+ 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.`;
54653
+ const anthropic = new import_sdk.default({ apiKey: ANTHROPIC_API_KEY });
54664
54654
  try {
54665
54655
  if (value?.incidentInformation?.siteInfo?.site) {
54666
54656
  const site = await _getSiteById(
@@ -54677,19 +54667,15 @@ function useIncidentReportService() {
54677
54667
  value.organization = org.name;
54678
54668
  }
54679
54669
  }
54680
- const completion = await openai.chat.completions.create({
54681
- model: "gpt-4o-mini",
54682
- messages: [
54683
- {
54684
- role: "system",
54685
- 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}`
54686
- },
54687
- { role: "user", content: JSON.stringify(value) }
54688
- ]
54670
+ const response = await anthropic.messages.create({
54671
+ model: "claude-sonnet-4-6",
54672
+ max_tokens: 1024,
54673
+ 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}`,
54674
+ messages: [{ role: "user", content: JSON.stringify(value) }]
54689
54675
  });
54690
- const briefsummary = completion?.choices[0]?.message?.content;
54691
- if (briefsummary) {
54692
- return briefsummary;
54676
+ const briefSummary = response.content[0].type === "text" ? response.content[0].text : null;
54677
+ if (briefSummary) {
54678
+ return briefSummary;
54693
54679
  } else {
54694
54680
  return "Failed to generate a summary.";
54695
54681
  }
@@ -69768,6 +69754,7 @@ function useHidAmicoController() {
69768
69754
  useManpowerSitesSrvc,
69769
69755
  useMemberController,
69770
69756
  useMemberRepo,
69757
+ useMemberService,
69771
69758
  useNewDashboardController,
69772
69759
  useNewDashboardRepo,
69773
69760
  useNfcPatrolLogController,