@7365admin1/core 3.101.0 → 3.102.1

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.mjs CHANGED
@@ -7428,6 +7428,7 @@ function useVerificationRepoV2() {
7428
7428
  statuses = [],
7429
7429
  orgIds,
7430
7430
  email = "",
7431
+ siteId = "",
7431
7432
  search = "",
7432
7433
  includeDeleted = false,
7433
7434
  page = 1,
@@ -7446,6 +7447,12 @@ function useVerificationRepoV2() {
7446
7447
  query2.status = { $in: statuses };
7447
7448
  if (email)
7448
7449
  query2.email = email.trim().toLowerCase();
7450
+ if (siteId) {
7451
+ const ids2 = [siteId];
7452
+ if (ObjectId22.isValid(siteId))
7453
+ ids2.push(new ObjectId22(siteId));
7454
+ query2["metadata.siteId"] = { $in: ids2 };
7455
+ }
7449
7456
  if (!includeDeleted)
7450
7457
  query2.deletedAt = null;
7451
7458
  if (search.trim()) {
@@ -7624,6 +7631,91 @@ function MCustomerSite(value) {
7624
7631
  // src/repositories/customer-site.repo.ts
7625
7632
  import { ObjectId as ObjectId24 } from "mongodb";
7626
7633
  import Joi13 from "joi";
7634
+
7635
+ // src/utils/customer-site-list.util.ts
7636
+ var SITE_RELATIONSHIPS = ["own", "served"];
7637
+ var SP_INVITE_TYPES = [
7638
+ "service-provider-invite",
7639
+ "service-provider-create-org"
7640
+ ];
7641
+ function escapeRegex(value) {
7642
+ return String(value ?? "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7643
+ }
7644
+ function relationshipMatch(org, relationship, client) {
7645
+ const self = [org, String(org)];
7646
+ const match = {};
7647
+ const and = [];
7648
+ if (relationship === "own") {
7649
+ and.push({ siteOrg: { $in: [...self, null, ""] } });
7650
+ } else if (relationship === "served") {
7651
+ and.push({ siteOrg: { $nin: [...self, null, ""] } });
7652
+ }
7653
+ if (client) {
7654
+ and.push(
7655
+ { siteOrg: { $in: [client, String(client)] } },
7656
+ { siteOrg: { $nin: self } }
7657
+ );
7658
+ }
7659
+ if (and.length)
7660
+ match.$and = and;
7661
+ return match;
7662
+ }
7663
+ function relationshipField(orgId) {
7664
+ return {
7665
+ relationship: {
7666
+ $cond: [
7667
+ {
7668
+ $or: [
7669
+ { $in: [{ $ifNull: ["$siteOrg", ""] }, ["", null]] },
7670
+ { $eq: [{ $toString: "$siteOrg" }, orgId] }
7671
+ ]
7672
+ },
7673
+ "own",
7674
+ "served"
7675
+ ]
7676
+ }
7677
+ };
7678
+ }
7679
+ function searchMatch(search) {
7680
+ const term = String(search ?? "").trim();
7681
+ if (!term)
7682
+ return null;
7683
+ const re = { $regex: escapeRegex(term), $options: "i" };
7684
+ return {
7685
+ $or: [
7686
+ { name: re },
7687
+ { siteOrgName: re },
7688
+ { "siteAddress.line1": re },
7689
+ { "siteAddress.line2": re },
7690
+ { "siteAddress.city": re },
7691
+ { "siteAddress.postalCode": re },
7692
+ { "siteAddress.country": re }
7693
+ ]
7694
+ };
7695
+ }
7696
+ var iso = (value) => {
7697
+ if (!value)
7698
+ return null;
7699
+ const d = new Date(value);
7700
+ return Number.isNaN(d.getTime()) ? null : d.toISOString();
7701
+ };
7702
+ function invitationFor(siteId, invites) {
7703
+ const mine = invites.filter((v2) => String(v2?.metadata?.siteId ?? "") === siteId).sort(
7704
+ (a, b) => new Date(b.createdAt ?? 0).getTime() - new Date(a.createdAt ?? 0).getTime()
7705
+ );
7706
+ const v = mine[0];
7707
+ if (!v)
7708
+ return null;
7709
+ const accepted = [...v.history ?? []].reverse().find((h) => h?.action === "accepted" || h?.action === "site-linked");
7710
+ return {
7711
+ id: String(v._id ?? ""),
7712
+ invitedByName: String(v.metadata?.invitedByName ?? ""),
7713
+ invitedAt: iso(v.createdAt),
7714
+ acceptedAt: iso(accepted?.at)
7715
+ };
7716
+ }
7717
+
7718
+ // src/repositories/customer-site.repo.ts
7627
7719
  function useCustomerSiteRepo() {
7628
7720
  const db2 = useAtlas15.getDb();
7629
7721
  if (!db2) {
@@ -7631,6 +7723,7 @@ function useCustomerSiteRepo() {
7631
7723
  }
7632
7724
  const namespace_collection3 = "customer.sites";
7633
7725
  const collection = db2.collection(namespace_collection3);
7726
+ const verifications = db2.collection("verifications");
7634
7727
  const { delNamespace, getCache, setCache } = useCache12(namespace_collection3);
7635
7728
  async function createIndexes() {
7636
7729
  try {
@@ -7720,7 +7813,10 @@ function useCustomerSiteRepo() {
7720
7813
  sort = {},
7721
7814
  org = "",
7722
7815
  status = "active",
7723
- siteScope = null
7816
+ siteScope = null,
7817
+ relationship = "",
7818
+ client = "",
7819
+ category = ""
7724
7820
  }, session) {
7725
7821
  page = page > 0 ? page - 1 : 0;
7726
7822
  try {
@@ -7732,6 +7828,14 @@ function useCustomerSiteRepo() {
7732
7828
  org,
7733
7829
  status
7734
7830
  };
7831
+ let clientId = null;
7832
+ if (client) {
7833
+ try {
7834
+ clientId = new ObjectId24(client);
7835
+ } catch (error) {
7836
+ throw new BadRequestError23("Invalid client ID format.");
7837
+ }
7838
+ }
7735
7839
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
7736
7840
  const cacheOptions = {
7737
7841
  org: org.toString(),
@@ -7748,6 +7852,12 @@ function useCustomerSiteRepo() {
7748
7852
  if (search) {
7749
7853
  cacheOptions.search = search;
7750
7854
  }
7855
+ if (relationship)
7856
+ cacheOptions.relationship = relationship;
7857
+ if (client)
7858
+ cacheOptions.client = client;
7859
+ if (category)
7860
+ cacheOptions.category = category;
7751
7861
  const cacheKey = makeCacheKey10(namespace_collection3, cacheOptions);
7752
7862
  const cachedData = await getCache(cacheKey);
7753
7863
  if (cachedData) {
@@ -7755,8 +7865,14 @@ function useCustomerSiteRepo() {
7755
7865
  return cachedData;
7756
7866
  }
7757
7867
  try {
7868
+ const orgId = org.toString();
7869
+ const search_ = searchMatch(search);
7870
+ const listMatch = {
7871
+ ...query2,
7872
+ ...relationshipMatch(org, relationship, clientId)
7873
+ };
7758
7874
  const distinctPipeline = [
7759
- { $match: query2 },
7875
+ { $match: listMatch },
7760
7876
  { $sort: sort },
7761
7877
  { $group: { _id: "$site", doc: { $first: "$$ROOT" } } },
7762
7878
  { $replaceRoot: { newRoot: "$doc" } },
@@ -7773,8 +7889,22 @@ function useCustomerSiteRepo() {
7773
7889
  // The site's own timezone, so the Edit Site form opens on the zone the
7774
7890
  // site really has. Lives only on the site, never on this row.
7775
7891
  { $set: { timezone: "$_liveSite.timezone" } },
7892
+ /*
7893
+ * The Sites list's columns. Address and category come from the SITE,
7894
+ * like the name: a served site's engagement row was written by the
7895
+ * invitation with neither. The row's own `address` / `category` are
7896
+ * left exactly as they were for every other caller.
7897
+ */
7898
+ {
7899
+ $set: {
7900
+ siteAddress: { $ifNull: ["$_liveSite.address", "$address"] },
7901
+ siteCategory: { $ifNull: ["$_liveSite.category", "$category"] },
7902
+ ...relationshipField(orgId)
7903
+ }
7904
+ },
7776
7905
  { $unset: "_liveSite" },
7777
- ...search ? [{ $match: { name: { $regex: search, $options: "i" } } }] : [],
7906
+ ...search_ ? [{ $match: search_ }] : [],
7907
+ ...category ? [{ $match: { siteCategory: category } }] : [],
7778
7908
  { $sort: sort }
7779
7909
  ];
7780
7910
  const items = await collection.aggregate(
@@ -7787,7 +7917,54 @@ function useCustomerSiteRepo() {
7787
7917
  ).toArray();
7788
7918
  const countResult = await collection.aggregate([...distinctPipeline, { $count: "total" }], { session }).toArray();
7789
7919
  const length = countResult[0]?.total ?? 0;
7790
- const data = paginate10(items, page, limit, length);
7920
+ const servedSites = items.filter((row) => row.relationship === "served" && row.site).map((row) => row.site);
7921
+ if (servedSites.length) {
7922
+ const invites = await verifications.find(
7923
+ {
7924
+ type: { $in: SP_INVITE_TYPES },
7925
+ status: "complete",
7926
+ "metadata.providerOrg": { $in: [orgId, org] },
7927
+ "metadata.siteId": {
7928
+ $in: [...servedSites, ...servedSites.map(String)]
7929
+ }
7930
+ },
7931
+ {
7932
+ projection: {
7933
+ createdAt: 1,
7934
+ history: 1,
7935
+ "metadata.siteId": 1,
7936
+ "metadata.invitedByName": 1
7937
+ },
7938
+ session
7939
+ }
7940
+ ).toArray().catch((error) => {
7941
+ logger13.error(
7942
+ `Sites list: invitation lookup failed: ${error?.message}`
7943
+ );
7944
+ return [];
7945
+ });
7946
+ for (const row of items) {
7947
+ if (row.relationship === "served") {
7948
+ row.invitation = invitationFor(String(row.site), invites);
7949
+ }
7950
+ }
7951
+ }
7952
+ const clients = await collection.aggregate(
7953
+ [
7954
+ { $match: { ...query2, ...relationshipMatch(org, "served") } },
7955
+ { $sort: { _id: -1 } },
7956
+ { $group: { _id: "$siteOrg", name: { $first: "$siteOrgName" } } },
7957
+ { $sort: { name: 1 } }
7958
+ ],
7959
+ { session }
7960
+ ).toArray();
7961
+ const data = {
7962
+ ...paginate10(items, page, limit, length),
7963
+ clients: clients.map((c) => ({
7964
+ _id: String(c._id),
7965
+ name: c.name ?? ""
7966
+ }))
7967
+ };
7791
7968
  setCache(cacheKey, data, 15 * 60).then(() => {
7792
7969
  logger13.info(`Cache set for key: ${cacheKey}`);
7793
7970
  }).catch((err) => {
@@ -12600,6 +12777,7 @@ function useServiceProviderInviteService() {
12600
12777
  async function listForCaller({
12601
12778
  userId,
12602
12779
  orgId,
12780
+ siteId,
12603
12781
  statuses,
12604
12782
  search = "",
12605
12783
  page = 1,
@@ -12620,16 +12798,85 @@ function useServiceProviderInviteService() {
12620
12798
  // A super admin asking for everything passes no scope; everyone else is
12621
12799
  // pinned to their own organisations even if they ask for more.
12622
12800
  orgIds: staffMayBypass(actor) && !orgId ? void 0 : scope,
12801
+ siteId: siteId || void 0,
12623
12802
  search,
12624
12803
  page,
12625
12804
  limit
12626
12805
  });
12806
+ const names = /* @__PURE__ */ new Map();
12807
+ const items = await Promise.all(
12808
+ (data.items ?? []).map(
12809
+ (invite) => sentRow(invite, names)
12810
+ )
12811
+ );
12812
+ return { ...data, items };
12813
+ }
12814
+ async function sentRow(invite, names) {
12815
+ const metadata = invite.metadata ?? {};
12816
+ const status = serviceProviderInviteViewStatus(invite);
12817
+ const accepted = status === "complete" /* COMPLETE */ && !invite.deletedAt;
12818
+ const siteId = metadata.siteId?.toString?.() ?? "";
12819
+ const history = invite.history ?? [];
12820
+ const answer = [...history].reverse().find(
12821
+ (h) => ["accepted", "site-linked", "declined", "cancelled", "rejected"].includes(h?.action)
12822
+ );
12823
+ let providerOrgId = metadata.providerOrg?.toString?.() ?? "";
12824
+ let providerOrgName = String(metadata.providerOrgName ?? "");
12825
+ if (accepted && !providerOrgId) {
12826
+ const byEmail = await getOrgByEmail(
12827
+ String(invite.email ?? "").trim().toLowerCase()
12828
+ ).catch(() => null);
12829
+ providerOrgId = byEmail?._id?.toString?.() ?? "";
12830
+ providerOrgName = byEmail?.name ?? "";
12831
+ }
12832
+ let contactEmail = "";
12833
+ let contactPhone = "";
12834
+ let onSite = false;
12835
+ if (accepted && providerOrgId) {
12836
+ const [org, links] = await Promise.all([
12837
+ getOrgById(providerOrgId).catch(() => null),
12838
+ siteId ? useCustomerSiteRepo().countActiveByOrgAndSite(providerOrgId, siteId).catch(() => 0) : Promise.resolve(0)
12839
+ ]);
12840
+ providerOrgName = providerOrgName || org?.name || "";
12841
+ contactEmail = String(org?.email ?? "");
12842
+ contactPhone = String(org?.contact ?? "");
12843
+ onSite = links > 0;
12844
+ }
12845
+ const invitedBy = metadata.invitedBy?.toString?.() ?? "";
12846
+ let invitedByName = String(metadata.invitedByName ?? "");
12847
+ if (!invitedByName && invitedBy) {
12848
+ if (!names.has(invitedBy)) {
12849
+ names.set(
12850
+ invitedBy,
12851
+ getUserById(invitedBy).then((u) => String(u?.name ?? "")).catch(() => "")
12852
+ );
12853
+ }
12854
+ invitedByName = await names.get(invitedBy);
12855
+ }
12856
+ const companyName = providerOrgName || String(metadata.name ?? "");
12627
12857
  return {
12628
- ...data,
12629
- items: (data.items ?? []).map((invite) => ({
12630
- ...invite,
12631
- statusLabel: serviceProviderInviteLabel(invite.status)
12632
- }))
12858
+ ...invite,
12859
+ // Apps still on an older layer-common read the company from
12860
+ // `metadata.name` (set only on sign-up invitations). Filled in the reply
12861
+ // only - nothing is written. ponytail: drop once every app's pin reads
12862
+ // `companyName`.
12863
+ metadata: { ...metadata, name: companyName },
12864
+ // `status` stays the stored value (it decides which actions a row
12865
+ // offers); `viewStatus` reads a lapsed "pending" as "expired".
12866
+ viewStatus: status,
12867
+ statusLabel: serviceProviderInviteLabel(status),
12868
+ // The company the invitation is for: the one that accepted it, else the
12869
+ // new company's name the sender typed (a sign-up invitation).
12870
+ companyName,
12871
+ providerOrgId,
12872
+ service: String(metadata.app ?? ""),
12873
+ siteName: String(metadata.siteName ?? ""),
12874
+ invitedByName,
12875
+ invitedAt: invite.createdAt ?? null,
12876
+ answeredAt: status === "expired" ? invite.expireAt ?? null : status === "pending" || status === "awaiting-approval" /* AWAITING_APPROVAL */ ? null : answer?.at ?? invite.updatedAt ?? null,
12877
+ contactEmail,
12878
+ contactPhone,
12879
+ onSite
12633
12880
  };
12634
12881
  }
12635
12882
  async function approvalCount({ userId }) {
@@ -19459,7 +19706,7 @@ function useVehicleRepo() {
19459
19706
  let query2 = { ...baseQuery };
19460
19707
  if (search)
19461
19708
  query2.$text = { $search: search };
19462
- const escapeRegex2 = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
19709
+ const escapeRegex3 = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
19463
19710
  const buildGroupedPipeline = (matchQuery) => [
19464
19711
  { $match: matchQuery },
19465
19712
  {
@@ -19643,7 +19890,7 @@ function useVehicleRepo() {
19643
19890
  const countResult = await collection.aggregate(buildGroupedCountPipeline(query2)).toArray();
19644
19891
  length = countResult[0]?.total || 0;
19645
19892
  if ((!items || items.length === 0) && search) {
19646
- const escaped = escapeRegex2(search);
19893
+ const escaped = escapeRegex3(search);
19647
19894
  const regexQuery = {
19648
19895
  ...baseQuery,
19649
19896
  $or: [
@@ -20432,7 +20679,7 @@ function useVehicleRepo() {
20432
20679
  ...baseQuery,
20433
20680
  ...search && { $text: { $search: search } }
20434
20681
  };
20435
- const escapeRegex2 = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
20682
+ const escapeRegex3 = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
20436
20683
  const buildPipeline = (matchQuery) => [
20437
20684
  { $match: matchQuery },
20438
20685
  {
@@ -20460,7 +20707,7 @@ function useVehicleRepo() {
20460
20707
  const countResult = await collection.aggregate(buildCountPipeline(query2)).toArray();
20461
20708
  length = countResult[0]?.total || 0;
20462
20709
  if ((!items || items.length === 0) && search) {
20463
- const escaped = escapeRegex2(search);
20710
+ const escaped = escapeRegex3(search);
20464
20711
  const regexQuery = {
20465
20712
  ...baseQuery,
20466
20713
  $or: [
@@ -28659,9 +28906,9 @@ function parsePromoExpiry(value) {
28659
28906
  const us = raw.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
28660
28907
  if (us)
28661
28908
  return endOfDay(us[3], us[1], us[2]);
28662
- const iso = raw.match(/^(\d{4})-(\d{2})-(\d{2})$/);
28663
- if (iso)
28664
- return endOfDay(iso[1], iso[2], iso[3]);
28909
+ const iso2 = raw.match(/^(\d{4})-(\d{2})-(\d{2})$/);
28910
+ if (iso2)
28911
+ return endOfDay(iso2[1], iso2[2], iso2[3]);
28665
28912
  const parsed = new Date(raw);
28666
28913
  return Number.isNaN(parsed.getTime()) ? null : parsed;
28667
28914
  }
@@ -31923,7 +32170,7 @@ function useServiceProviderRepo() {
31923
32170
  throw new BadRequestError80("Invalid site ID format.");
31924
32171
  }
31925
32172
  }
31926
- cacheOptions.membersLookup = "1";
32173
+ cacheOptions.membersLookup = "2";
31927
32174
  const cacheKey = makeCacheKey25(namespace_collection3, cacheOptions);
31928
32175
  const cachedData = await getCache(cacheKey);
31929
32176
  if (cachedData) {
@@ -31939,7 +32186,7 @@ function useServiceProviderRepo() {
31939
32186
  localField: "serviceProviderOrgId",
31940
32187
  foreignField: "_id",
31941
32188
  as: "organization",
31942
- pipeline: [{ $project: { nature: 1, email: 1 } }]
32189
+ pipeline: [{ $project: { nature: 1, email: 1, contact: 1 } }]
31943
32190
  }
31944
32191
  },
31945
32192
  {
@@ -31951,11 +32198,19 @@ function useServiceProviderRepo() {
31951
32198
  {
31952
32199
  $lookup: {
31953
32200
  from: "members",
31954
- let: { spOrgId: "$serviceProviderOrgId" },
32201
+ // The provider's staff assigned to THIS site, not the provider's
32202
+ // whole headcount - the client has no business knowing how big
32203
+ // its contractor is, only who works on its estate.
32204
+ let: { spOrgId: "$serviceProviderOrgId", spSiteId: "$siteId" },
31955
32205
  pipeline: [
31956
32206
  {
31957
32207
  $match: {
31958
- $expr: { $eq: ["$org", "$$spOrgId"] },
32208
+ $expr: {
32209
+ $and: [
32210
+ { $eq: ["$org", "$$spOrgId"] },
32211
+ { $eq: ["$siteId", "$$spSiteId"] }
32212
+ ]
32213
+ },
31959
32214
  status: "active"
31960
32215
  }
31961
32216
  },
@@ -31978,6 +32233,7 @@ function useServiceProviderRepo() {
31978
32233
  }
31979
32234
  },
31980
32235
  nature: "$organization.nature",
32236
+ contact: { $ifNull: ["$organization.contact", ""] },
31981
32237
  orgId: 1,
31982
32238
  siteId: 1,
31983
32239
  siteName: 1,
@@ -32227,6 +32483,104 @@ function useServiceProviderRepo() {
32227
32483
  throw error;
32228
32484
  }
32229
32485
  }
32486
+ async function getEngagedProvidersBySite(site) {
32487
+ try {
32488
+ site = new ObjectId72(site);
32489
+ } catch {
32490
+ throw new BadRequestError80("Invalid site ID format.");
32491
+ }
32492
+ return await db2.collection("customer.sites").aggregate([
32493
+ {
32494
+ $match: {
32495
+ site,
32496
+ status: "active",
32497
+ // The client's own row for its own site is not a provider, and a
32498
+ // row that does not say whose site it is proves nothing.
32499
+ siteOrg: { $nin: [null, ""] },
32500
+ $expr: { $ne: ["$org", "$siteOrg"] }
32501
+ }
32502
+ },
32503
+ { $sort: { _id: 1 } },
32504
+ {
32505
+ $group: {
32506
+ _id: "$org",
32507
+ engagementId: { $first: "$_id" },
32508
+ siteName: { $first: "$name" },
32509
+ since: { $first: "$createdAt" }
32510
+ }
32511
+ },
32512
+ {
32513
+ $lookup: {
32514
+ from: "organizations",
32515
+ localField: "_id",
32516
+ foreignField: "_id",
32517
+ as: "organization",
32518
+ pipeline: [
32519
+ { $project: { name: 1, nature: 1, email: 1, contact: 1 } }
32520
+ ]
32521
+ }
32522
+ },
32523
+ { $unwind: { path: "$organization", preserveNullAndEmptyArrays: true } },
32524
+ {
32525
+ $lookup: {
32526
+ from: "members",
32527
+ let: { spOrgId: "$_id" },
32528
+ pipeline: [
32529
+ {
32530
+ $match: {
32531
+ $expr: { $eq: ["$org", "$$spOrgId"] },
32532
+ siteId: site,
32533
+ status: "active"
32534
+ }
32535
+ },
32536
+ { $count: "c" }
32537
+ ],
32538
+ as: "_memberCount"
32539
+ }
32540
+ },
32541
+ {
32542
+ $project: {
32543
+ _id: "$engagementId",
32544
+ name: { $ifNull: ["$organization.name", ""] },
32545
+ type: { $ifNull: ["$organization.nature", ""] },
32546
+ nature: "$organization.nature",
32547
+ email: { $ifNull: ["$organization.email", ""] },
32548
+ contact: { $ifNull: ["$organization.contact", ""] },
32549
+ siteId: site,
32550
+ siteName: 1,
32551
+ serviceProviderOrgId: "$_id",
32552
+ status: "active",
32553
+ category: "external",
32554
+ since: 1,
32555
+ source: "engagement",
32556
+ members: {
32557
+ $ifNull: [{ $arrayElemAt: ["$_memberCount.c", 0] }, 0]
32558
+ }
32559
+ }
32560
+ },
32561
+ { $sort: { name: 1 } },
32562
+ { $limit: 200 }
32563
+ ]).toArray();
32564
+ }
32565
+ async function getSiteProviderKeys(site) {
32566
+ try {
32567
+ site = new ObjectId72(site);
32568
+ } catch {
32569
+ throw new BadRequestError80("Invalid site ID format.");
32570
+ }
32571
+ const rows = await collection.find(
32572
+ { siteId: site },
32573
+ { projection: { serviceProviderOrgId: 1, email: 1 } }
32574
+ ).toArray();
32575
+ return {
32576
+ orgIds: new Set(
32577
+ rows.map((r) => r.serviceProviderOrgId?.toString?.() ?? "").filter(Boolean)
32578
+ ),
32579
+ emails: new Set(
32580
+ rows.map((r) => String(r.email ?? "").trim().toLowerCase()).filter(Boolean)
32581
+ )
32582
+ };
32583
+ }
32230
32584
  return {
32231
32585
  createTextIndex,
32232
32586
  createUniqueIndex,
@@ -32237,7 +32591,9 @@ function useServiceProviderRepo() {
32237
32591
  getServiceProviderById,
32238
32592
  getByServiceProviderOrgIdType,
32239
32593
  getByEmail,
32240
- updateStatusById
32594
+ updateStatusById,
32595
+ getEngagedProvidersBySite,
32596
+ getSiteProviderKeys
32241
32597
  };
32242
32598
  }
32243
32599
 
@@ -32955,12 +33311,15 @@ import { BadRequestError as BadRequestError86, logger as logger62 } from "@7365a
32955
33311
  // src/services/service-provider.service.ts
32956
33312
  import {
32957
33313
  BadRequestError as BadRequestError85,
33314
+ paginate as paginate25,
32958
33315
  useAtlas as useAtlas53
32959
33316
  } from "@7365admin1/node-server-utils";
32960
33317
  function useServiceProviderService() {
32961
33318
  const {
32962
33319
  createServiceProvider: _createServiceProvider,
32963
- getServiceProviders: _getServiceProviders
33320
+ getServiceProviders: _getServiceProviders,
33321
+ getEngagedProvidersBySite: _getEngaged,
33322
+ getSiteProviderKeys: _getSiteProviderKeys
32964
33323
  } = useServiceProviderRepo();
32965
33324
  const { getById: getOrgById, getByEmail: getOrgByEmail } = useOrgRepo();
32966
33325
  const { getSiteById } = useSiteRepo();
@@ -33040,9 +33399,40 @@ function useServiceProviderService() {
33040
33399
  status
33041
33400
  });
33042
33401
  }
33402
+ async function getServiceProvidersForSite({
33403
+ search = "",
33404
+ page = 1,
33405
+ limit = 10,
33406
+ siteId
33407
+ }) {
33408
+ const [engaged, keys] = await Promise.all([
33409
+ _getEngaged(siteId),
33410
+ _getSiteProviderKeys(siteId)
33411
+ ]);
33412
+ const needle = search.trim().toLowerCase();
33413
+ const derived = engaged.filter(
33414
+ (row) => !keys.orgIds.has(row.serviceProviderOrgId?.toString?.() ?? "") && !(row.email && keys.emails.has(String(row.email).trim().toLowerCase())) && (!needle || String(row.name ?? "").toLowerCase().includes(needle))
33415
+ );
33416
+ const stored = (p, l) => _getServiceProviders({ search, page: p, limit: l, siteId, status: "active" });
33417
+ if (!derived.length)
33418
+ return await stored(page, limit);
33419
+ const start = (Math.max(page, 1) - 1) * limit;
33420
+ const fromDerived = derived.slice(start, start + limit);
33421
+ const need = limit - fromDerived.length;
33422
+ const storedStart = Math.max(0, start - derived.length);
33423
+ const first = await stored(1, Math.max(storedStart + need, 1));
33424
+ const total = derived.length + totalOf(first);
33425
+ const fromStored = need > 0 ? (first?.items ?? []).slice(storedStart, storedStart + need) : [];
33426
+ return paginate25([...fromDerived, ...fromStored], Math.max(page, 1) - 1, limit, total);
33427
+ }
33428
+ function totalOf(data) {
33429
+ const match = /of\s+(\d+)/.exec(String(data?.pageRange ?? ""));
33430
+ return match ? Number(match[1]) : (data?.items ?? []).length;
33431
+ }
33043
33432
  return {
33044
33433
  createServiceProvider,
33045
- getServiceProviders
33434
+ getServiceProviders,
33435
+ getServiceProvidersForSite
33046
33436
  };
33047
33437
  }
33048
33438
 
@@ -33057,7 +33447,18 @@ function useServiceProviderController() {
33057
33447
  getByEmail: _getByEmail,
33058
33448
  updateStatusById: _updateStatusById
33059
33449
  } = useServiceProviderRepo();
33060
- const { createServiceProvider: _createServiceProvider } = useServiceProviderService();
33450
+ const {
33451
+ createServiceProvider: _createServiceProvider,
33452
+ getServiceProvidersForSite: _getServiceProvidersForSite
33453
+ } = useServiceProviderService();
33454
+ async function isSiteClient(req, siteId) {
33455
+ const actor = await resolveInviteActor(callerId(req));
33456
+ if (staffMayBypass(actor))
33457
+ return true;
33458
+ const site = await useSiteRepo().getSiteById(siteId).catch(() => null);
33459
+ const owner = (site?.orgId ?? site?.org)?.toString?.() ?? "";
33460
+ return Boolean(owner) && actor.orgIds.includes(owner);
33461
+ }
33061
33462
  const { createServiceProvider: _add } = useServiceProviderRepo();
33062
33463
  async function createServiceProvider(req, res, next) {
33063
33464
  const validation = Joi46.string().hex().required();
@@ -33086,7 +33487,12 @@ function useServiceProviderController() {
33086
33487
  orgId: Joi46.string().hex().optional().allow("", null),
33087
33488
  siteId: Joi46.string().hex().optional().allow("", null),
33088
33489
  serviceProviderOrgId: Joi46.string().hex().optional().allow("", null),
33089
- status: Joi46.string().optional().allow("", null)
33490
+ status: Joi46.string().optional().allow("", null),
33491
+ // "engagements": also list providers engaged through an accepted
33492
+ // invitation. Opt-in, because those rows carry the engagement's id, not
33493
+ // a service-providers id - a caller that stores the id (the MA app's
33494
+ // feedback provider picker) must keep getting stored rows only.
33495
+ include: Joi46.string().valid("engagements").optional().allow("", null)
33090
33496
  });
33091
33497
  const query2 = { ...req.query };
33092
33498
  const { error } = validation.validate(query2);
@@ -33103,7 +33509,9 @@ function useServiceProviderController() {
33103
33509
  const serviceProviderOrgId = req.query.serviceProviderOrgId ?? "";
33104
33510
  const status = req.query.status ?? "active";
33105
33511
  try {
33106
- const data = await _getServiceProviders({
33512
+ if (siteId)
33513
+ await requireSiteReach(req, siteId);
33514
+ const data = req.query.include === "engagements" && siteId && status === "active" && !orgId && !serviceProviderOrgId && await isSiteClient(req, siteId) ? await _getServiceProvidersForSite({ search, page, limit, siteId }) : await _getServiceProviders({
33107
33515
  search,
33108
33516
  page,
33109
33517
  limit,
@@ -33380,7 +33788,7 @@ import {
33380
33788
  useAtlas as useAtlas54,
33381
33789
  InternalServerError as InternalServerError35,
33382
33790
  BadRequestError as BadRequestError88,
33383
- paginate as paginate25,
33791
+ paginate as paginate26,
33384
33792
  NotFoundError as NotFoundError25,
33385
33793
  useCache as useCache30,
33386
33794
  logger as logger64,
@@ -33491,7 +33899,7 @@ function useCustomerRepo() {
33491
33899
  { session }
33492
33900
  ).toArray();
33493
33901
  const length = await collection.countDocuments(query2, { session });
33494
- const data = paginate25(items, page, limit, length);
33902
+ const data = paginate26(items, page, limit, length);
33495
33903
  setCache(cacheKey, data, 15 * 60).then(() => {
33496
33904
  logger64.info(`Cache set for key: ${cacheKey}`);
33497
33905
  }).catch((err) => {
@@ -33851,7 +34259,7 @@ import {
33851
34259
  InternalServerError as InternalServerError36,
33852
34260
  logger as logger67,
33853
34261
  makeCacheKey as makeCacheKey27,
33854
- paginate as paginate26,
34262
+ paginate as paginate27,
33855
34263
  toObjectId as toObjectId12,
33856
34264
  useAtlas as useAtlas56,
33857
34265
  useCache as useCache31
@@ -34387,7 +34795,7 @@ function useBuildingUnitRepo() {
34387
34795
  ).toArray();
34388
34796
  const total = await collection.aggregate([...pipeline, { $count: "length" }]).toArray();
34389
34797
  const length = total[0]?.length ?? 0;
34390
- const data = paginate26(items, page, limit, length);
34798
+ const data = paginate27(items, page, limit, length);
34391
34799
  setCache(cacheKey, data, 600).then(() => {
34392
34800
  logger67.log({
34393
34801
  level: "info",
@@ -34486,7 +34894,7 @@ function useBuildingUnitRepo() {
34486
34894
  search ? {} : { collation: { locale: "en", numericOrdering: true } }
34487
34895
  ).toArray();
34488
34896
  const length = await collection.countDocuments(query2);
34489
- const data = paginate26(items, page, limit, length);
34897
+ const data = paginate27(items, page, limit, length);
34490
34898
  setCache(cacheKey, data, 600).then(() => {
34491
34899
  logger67.log({
34492
34900
  level: "info",
@@ -37804,7 +38212,7 @@ import {
37804
38212
  InternalServerError as InternalServerError38,
37805
38213
  logger as logger74,
37806
38214
  makeCacheKey as makeCacheKey28,
37807
- paginate as paginate27,
38215
+ paginate as paginate28,
37808
38216
  useAtlas as useAtlas61,
37809
38217
  useCache as useCache33
37810
38218
  } from "@7365admin1/node-server-utils";
@@ -38095,7 +38503,7 @@ function useBuildingRepo() {
38095
38503
  searchText ? {} : { collation: { locale: "en", numericOrdering: true } }
38096
38504
  ).toArray();
38097
38505
  const length = await collection.countDocuments(query2);
38098
- const data = paginate27(items, page, limit, length);
38506
+ const data = paginate28(items, page, limit, length);
38099
38507
  setCache(cacheKey, data, 600).then(() => {
38100
38508
  logger74.log({
38101
38509
  level: "info",
@@ -38167,7 +38575,7 @@ function useBuildingRepo() {
38167
38575
  ]).toArray();
38168
38576
  const countResult = await collection.aggregate([...basePipeline, { $count: "total" }]).toArray();
38169
38577
  const length = countResult[0]?.total ?? 0;
38170
- return paginate27(items, page, limit, length);
38578
+ return paginate28(items, page, limit, length);
38171
38579
  } catch (error) {
38172
38580
  logger74.log({ level: "error", message: `${error}` });
38173
38581
  throw error;
@@ -38549,7 +38957,7 @@ import {
38549
38957
  InternalServerError as InternalServerError39,
38550
38958
  logger as logger76,
38551
38959
  makeCacheKey as makeCacheKey29,
38552
- paginate as paginate28,
38960
+ paginate as paginate29,
38553
38961
  toObjectId as toObjectId14,
38554
38962
  useAtlas as useAtlas62,
38555
38963
  useCache as useCache34
@@ -38785,7 +39193,7 @@ function useBuildingLevelRepo() {
38785
39193
  search ? {} : { collation: { locale: "en", numericOrdering: true } }
38786
39194
  ).toArray();
38787
39195
  const length = await collection.countDocuments(query2);
38788
- const data = paginate28(items, page, limit, length);
39196
+ const data = paginate29(items, page, limit, length);
38789
39197
  setCache(cacheKey, data, 600).then(() => {
38790
39198
  logger76.log({
38791
39199
  level: "info",
@@ -42722,7 +43130,7 @@ function useCustomerSiteController() {
42722
43130
  }
42723
43131
  }
42724
43132
  async function getAll(req, res, next) {
42725
- const allowedFields = ["createdAt", "name"];
43133
+ const allowedFields = ["createdAt", "name", "siteOrgName"];
42726
43134
  const allowedOrder = ["asc", "desc"];
42727
43135
  const validation = Joi61.object({
42728
43136
  search: Joi61.string().optional().allow("", null),
@@ -42731,7 +43139,13 @@ function useCustomerSiteController() {
42731
43139
  sort: Joi61.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
42732
43140
  order: Joi61.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
42733
43141
  org: Joi61.string().hex().required(),
42734
- status: Joi61.string().required()
43142
+ status: Joi61.string().required(),
43143
+ // The Organization app's Sites list filters. All optional: every other
43144
+ // caller (site switchers, mobile pickers) sends none of them and gets
43145
+ // exactly the list it got before.
43146
+ relationship: Joi61.string().valid(...SITE_RELATIONSHIPS).optional().allow("", null),
43147
+ client: Joi61.string().hex().length(24).optional().allow("", null),
43148
+ category: Joi61.string().valid(...Object.values(SiteCategories)).optional().allow("", null)
42735
43149
  });
42736
43150
  const query2 = { ...req.query };
42737
43151
  const { error } = validation.validate(query2);
@@ -42745,6 +43159,9 @@ function useCustomerSiteController() {
42745
43159
  const limit = parseInt(req.query.limit ?? "10");
42746
43160
  const org = req.query.org ?? "";
42747
43161
  const status = req.query.status ?? "active";
43162
+ const relationship = req.query.relationship || "";
43163
+ const client = req.query.client || "";
43164
+ const category = req.query.category || "";
42748
43165
  const sortObj = {};
42749
43166
  const sortFields = String(req.query.sort).split(",");
42750
43167
  const sortOrders = String(req.query.order).split(",");
@@ -42764,7 +43181,10 @@ function useCustomerSiteController() {
42764
43181
  sort: sortObj,
42765
43182
  org,
42766
43183
  status,
42767
- siteScope
43184
+ siteScope,
43185
+ relationship,
43186
+ client,
43187
+ category
42768
43188
  });
42769
43189
  res.json(data);
42770
43190
  return;
@@ -43222,7 +43642,7 @@ import moment4 from "moment-timezone";
43222
43642
  import {
43223
43643
  useAtlas as useAtlas68,
43224
43644
  InternalServerError as InternalServerError41,
43225
- paginate as paginate29,
43645
+ paginate as paginate30,
43226
43646
  BadRequestError as BadRequestError114,
43227
43647
  useCache as useCache36,
43228
43648
  logger as logger89,
@@ -43384,7 +43804,7 @@ function useAttendanceRepository() {
43384
43804
  } else {
43385
43805
  length = await collection.countDocuments(query2);
43386
43806
  }
43387
- const data = paginate29(items, page, limit, length);
43807
+ const data = paginate30(items, page, limit, length);
43388
43808
  setCache(cacheKey, data, 15 * 60).then(() => {
43389
43809
  logger89.info(`Cache set for key: ${cacheKey}`);
43390
43810
  }).catch((err) => {
@@ -43520,7 +43940,7 @@ function useAttendanceRepository() {
43520
43940
  } else {
43521
43941
  length = await collection.countDocuments(query2);
43522
43942
  }
43523
- const data = paginate29(items, page, limit, length);
43943
+ const data = paginate30(items, page, limit, length);
43524
43944
  setCache(cacheKey, data, 15 * 60).then(() => {
43525
43945
  logger89.info(`Cache set for key: ${cacheKey}`);
43526
43946
  }).catch((err) => {
@@ -44796,7 +45216,7 @@ function usePersonService() {
44796
45216
  let set = {};
44797
45217
  const cleanInput = (str) => str.replace(/\s+/g, "");
44798
45218
  const cleanPhone = (str) => str.replace(/\D/g, "");
44799
- const escapeRegex2 = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
45219
+ const escapeRegex3 = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
44800
45220
  const nric = value.nric ? cleanInput(value.nric) : "";
44801
45221
  const name = value.name?.trim();
44802
45222
  const contact = value.contact?.trim();
@@ -44804,8 +45224,8 @@ function usePersonService() {
44804
45224
  const email = value.email?.trim();
44805
45225
  const type = value.type?.trim();
44806
45226
  const company = value.company?.trim();
44807
- const nricQuery = nric ? { nric: { $regex: `^${escapeRegex2(nric)}$`, $options: "i" } } : null;
44808
- const nameQuery = name ? { name: { $regex: `^${escapeRegex2(name)}$`, $options: "i" } } : null;
45227
+ const nricQuery = nric ? { nric: { $regex: `^${escapeRegex3(nric)}$`, $options: "i" } } : null;
45228
+ const nameQuery = name ? { name: { $regex: `^${escapeRegex3(name)}$`, $options: "i" } } : null;
44809
45229
  let nricCondition = null;
44810
45230
  if (nric) {
44811
45231
  if (nric.length < 9) {
@@ -44818,8 +45238,8 @@ function usePersonService() {
44818
45238
  }
44819
45239
  const orConditions = [
44820
45240
  ...nricCondition ? [nricCondition] : [],
44821
- ...contact ? [{ contacts: { $regex: `^\\+?${cleanPhone(escapeRegex2(contact))}$`, $options: "i" } }] : [],
44822
- ...plateNumber ? [{ plateNumbers: { $regex: `^${escapeRegex2(plateNumber)}$`, $options: "i" } }] : []
45241
+ ...contact ? [{ contacts: { $regex: `^\\+?${cleanPhone(escapeRegex3(contact))}$`, $options: "i" } }] : [],
45242
+ ...plateNumber ? [{ plateNumbers: { $regex: `^${escapeRegex3(plateNumber)}$`, $options: "i" } }] : []
44823
45243
  ];
44824
45244
  const existingPerson2 = await findFirstTen(
44825
45245
  {
@@ -45885,7 +46305,7 @@ import {
45885
46305
  BadRequestError as BadRequestError122,
45886
46306
  InternalServerError as InternalServerError44,
45887
46307
  logger as logger94,
45888
- paginate as paginate30,
46308
+ paginate as paginate31,
45889
46309
  useAtlas as useAtlas72
45890
46310
  } from "@7365admin1/node-server-utils";
45891
46311
  import { ObjectId as ObjectId95 } from "mongodb";
@@ -46718,7 +47138,7 @@ function useHidAmicoRepo() {
46718
47138
  passwordSet: Boolean(password)
46719
47139
  };
46720
47140
  }
46721
- function escapeRegex2(value) {
47141
+ function escapeRegex3(value) {
46722
47142
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
46723
47143
  }
46724
47144
  function buildIdentityKeyQuery(value) {
@@ -46794,7 +47214,7 @@ function useHidAmicoRepo() {
46794
47214
  }
46795
47215
  const items = await readers().find(query2).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
46796
47216
  const total = await readers().countDocuments(query2);
46797
- return paginate30(items.map(hideSecret), page, limit, total);
47217
+ return paginate31(items.map(hideSecret), page, limit, total);
46798
47218
  }
46799
47219
  async function getById(id, options = {}) {
46800
47220
  const _id = toId4(id, "reader ID");
@@ -46884,7 +47304,7 @@ function useHidAmicoRepo() {
46884
47304
  }
46885
47305
  const items = await events().find(query2).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
46886
47306
  const total = await events().countDocuments(query2);
46887
- return paginate30(items, page, limit, total);
47307
+ return paginate31(items, page, limit, total);
46888
47308
  }
46889
47309
  async function addIdentity(value, session) {
46890
47310
  try {
@@ -46921,7 +47341,7 @@ function useHidAmicoRepo() {
46921
47341
  query2.type = value.type;
46922
47342
  }
46923
47343
  if (value.search) {
46924
- const search = escapeRegex2(value.search);
47344
+ const search = escapeRegex3(value.search);
46925
47345
  query2.$or = [
46926
47346
  { hidUserId: { $regex: search, $options: "i" } },
46927
47347
  { registration: { $regex: search, $options: "i" } },
@@ -46930,7 +47350,7 @@ function useHidAmicoRepo() {
46930
47350
  }
46931
47351
  const items = await identities().find(query2).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
46932
47352
  const total = await identities().countDocuments(query2);
46933
- return paginate30(items, page, limit, total);
47353
+ return paginate31(items, page, limit, total);
46934
47354
  }
46935
47355
  async function getIdentityById(id) {
46936
47356
  const identity = await identities().findOne({
@@ -47162,7 +47582,7 @@ function useHidAmicoRepo() {
47162
47582
  const text2 = search.trim();
47163
47583
  if (!text2)
47164
47584
  return {};
47165
- const pattern = { $regex: escapeRegex2(text2), $options: "i" };
47585
+ const pattern = { $regex: escapeRegex3(text2), $options: "i" };
47166
47586
  return {
47167
47587
  $or: [
47168
47588
  { name: pattern },
@@ -47519,7 +47939,7 @@ function useHidAmicoRepo() {
47519
47939
  intercom: Boolean(selected?.intercom)
47520
47940
  };
47521
47941
  });
47522
- return paginate30(items, page - 1, limit, total);
47942
+ return paginate31(items, page - 1, limit, total);
47523
47943
  }
47524
47944
  async function enqueueGatewayJob(value) {
47525
47945
  const now = /* @__PURE__ */ new Date();
@@ -53544,7 +53964,7 @@ var schemaGuardInviteVisitor = Joi69.object({
53544
53964
  // src/repositories/access-management.repo.ts
53545
53965
  import {
53546
53966
  InternalServerError as InternalServerError46,
53547
- paginate as paginate31,
53967
+ paginate as paginate32,
53548
53968
  useAtlas as useAtlas74
53549
53969
  } from "@7365admin1/node-server-utils";
53550
53970
  import { ObjectId as ObjectId98 } from "mongodb";
@@ -54758,7 +55178,7 @@ function UseAccessManagementRepo() {
54758
55178
  ).toArray();
54759
55179
  const totalCount = result[0]?.totalCount?.[0]?.count ?? 0;
54760
55180
  const items = result[0]?.items ?? [];
54761
- const paginatedResult = paginate31(items, page, limit, totalCount);
55181
+ const paginatedResult = paginate32(items, page, limit, totalCount);
54762
55182
  return paginatedResult;
54763
55183
  } catch (error) {
54764
55184
  throw new Error(error.message);
@@ -54961,7 +55381,7 @@ function UseAccessManagementRepo() {
54961
55381
  ).toArray();
54962
55382
  const totalCount = result[0]?.totalCount?.[0]?.count ?? 0;
54963
55383
  const items = result[0]?.items ?? [];
54964
- const paginatedResult = paginate31(items, page, limit, totalCount);
55384
+ const paginatedResult = paginate32(items, page, limit, totalCount);
54965
55385
  return paginatedResult;
54966
55386
  } catch (error) {
54967
55387
  throw new Error(error.message);
@@ -55148,7 +55568,7 @@ function UseAccessManagementRepo() {
55148
55568
  ).toArray();
55149
55569
  const totalCount = result[0]?.totalCount?.[0]?.count ?? 0;
55150
55570
  const items = result[0]?.items ?? [];
55151
- const paginatedResult = paginate31(items, page, limit, totalCount);
55571
+ const paginatedResult = paginate32(items, page, limit, totalCount);
55152
55572
  return paginatedResult;
55153
55573
  } catch (error) {
55154
55574
  throw new Error(error.message);
@@ -55575,7 +55995,7 @@ function UseAccessManagementRepo() {
55575
55995
  ]).toArray();
55576
55996
  const length = res[0].totalCount[0] ? res[0].totalCount[0].count : 0;
55577
55997
  const items = res[0].items;
55578
- const paginatedResult = paginate31(items, page, limit, length);
55998
+ const paginatedResult = paginate32(items, page, limit, length);
55579
55999
  return paginatedResult;
55580
56000
  } catch (error) {
55581
56001
  throw new Error(error.message);
@@ -55746,7 +56166,7 @@ function UseAccessManagementRepo() {
55746
56166
  { allowDiskUse: true }
55747
56167
  ).toArray();
55748
56168
  const count = res[0]?.totalCount[0] ? res[0].totalCount[0].count : 0;
55749
- const pagination = paginate31(res[0].data, page, limit, count);
56169
+ const pagination = paginate32(res[0].data, page, limit, count);
55750
56170
  return pagination;
55751
56171
  } catch (error) {
55752
56172
  throw new Error(error.message);
@@ -56175,7 +56595,7 @@ function UseAccessManagementRepo() {
56175
56595
  }
56176
56596
  ]).toArray();
56177
56597
  const count = res[0]?.totalCounts[0] ? res[0].totalCounts[0].count : 0;
56178
- const paginated = paginate31(res[0].items, page, limit, count);
56598
+ const paginated = paginate32(res[0].items, page, limit, count);
56179
56599
  return [paginated, unit[0], { count }];
56180
56600
  } catch (error) {
56181
56601
  throw new Error(error.message);
@@ -56649,7 +57069,7 @@ function UseAccessManagementRepo() {
56649
57069
  ]).toArray();
56650
57070
  const length = result[0].totalCount[0] ? result[0].totalCount[0].count : 0;
56651
57071
  const items = result[0].items;
56652
- return paginate31(items, page, limit, length);
57072
+ return paginate32(items, page, limit, length);
56653
57073
  } catch (error) {
56654
57074
  throw new Error(error.message);
56655
57075
  }
@@ -58477,7 +58897,7 @@ import {
58477
58897
  InternalServerError as InternalServerError48,
58478
58898
  logger as logger100,
58479
58899
  makeCacheKey as makeCacheKey34,
58480
- paginate as paginate32,
58900
+ paginate as paginate33,
58481
58901
  useAtlas as useAtlas75,
58482
58902
  useCache as useCache39
58483
58903
  } from "@7365admin1/node-server-utils";
@@ -58586,7 +59006,7 @@ function useGuestManagementRepo() {
58586
59006
  collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
58587
59007
  ]);
58588
59008
  const totalCount = countResult[0]?.total || 0;
58589
- const data = paginate32(items, page, limit, totalCount);
59009
+ const data = paginate33(items, page, limit, totalCount);
58590
59010
  setCache(cacheKey, data, 15 * 60).then(() => logger100.info(`Cache set for key: ${cacheKey}`)).catch(
58591
59011
  (err) => logger100.error(`Failed to set cache for key: ${cacheKey}`, err)
58592
59012
  );
@@ -59537,7 +59957,7 @@ import { ObjectId as ObjectId104 } from "mongodb";
59537
59957
  import {
59538
59958
  useAtlas as useAtlas77,
59539
59959
  InternalServerError as InternalServerError49,
59540
- paginate as paginate33,
59960
+ paginate as paginate34,
59541
59961
  BadRequestError as BadRequestError131,
59542
59962
  NotFoundError as NotFoundError42,
59543
59963
  useCache as useCache40,
@@ -59561,7 +59981,7 @@ var NETWORK_SORTS = {
59561
59981
  };
59562
59982
  var NETWORK_OFFLINE_CODE = "OFFLINE";
59563
59983
  var ROBOT_FAULTS_COLLECTION = "robot-faults";
59564
- function escapeRegex(value) {
59984
+ function escapeRegex2(value) {
59565
59985
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
59566
59986
  }
59567
59987
  function matchDefaulted(field, value, fallback) {
@@ -59665,7 +60085,7 @@ function networkListPipeline(q) {
59665
60085
  pipeline.push({ $match: { offline: true } });
59666
60086
  const search = (q.search ?? "").trim();
59667
60087
  if (search) {
59668
- const rx = { $regex: escapeRegex(search), $options: "i" };
60088
+ const rx = { $regex: escapeRegex2(search), $options: "i" };
59669
60089
  pipeline.push({
59670
60090
  $match: { $or: [{ name: rx }, { robotSn: rx }, { "client.name": rx }, { "site.name": rx }] }
59671
60091
  });
@@ -60028,7 +60448,7 @@ function useRobotRepo() {
60028
60448
  }
60029
60449
  ]).toArray();
60030
60450
  const length = await collection.countDocuments(query2);
60031
- const data = paginate33(items, page, limit, length);
60451
+ const data = paginate34(items, page, limit, length);
60032
60452
  setCache(cacheKey, data, 15 * 60).then(() => {
60033
60453
  logger104.info(`Cache set for key: ${cacheKey}`);
60034
60454
  }).catch((err) => {
@@ -60103,7 +60523,7 @@ function useRobotRepo() {
60103
60523
  const limit = Math.min(100, Math.max(1, Math.floor(q.limit || 10)));
60104
60524
  const [res] = await collection.aggregate(networkListPipeline({ ...q, page, limit })).toArray();
60105
60525
  const total = res?.total?.[0]?.n ?? 0;
60106
- return { ...paginate33(res?.items ?? [], page - 1, limit, total), total };
60526
+ return { ...paginate34(res?.items ?? [], page - 1, limit, total), total };
60107
60527
  }
60108
60528
  async function getSiteNames(site) {
60109
60529
  if (!ObjectId104.isValid(site))
@@ -63701,7 +64121,7 @@ import { ObjectId as ObjectId107 } from "mongodb";
63701
64121
  import {
63702
64122
  useAtlas as useAtlas79,
63703
64123
  InternalServerError as InternalServerError51,
63704
- paginate as paginate34,
64124
+ paginate as paginate35,
63705
64125
  BadRequestError as BadRequestError136,
63706
64126
  NotFoundError as NotFoundError44,
63707
64127
  AppError as AppError21
@@ -63767,7 +64187,7 @@ function useRobotBuildingMapRepo() {
63767
64187
  }
63768
64188
  ]).toArray();
63769
64189
  const length = await collection.countDocuments(query2);
63770
- return paginate34(items, page > 0 ? page - 1 : 0, limit, length);
64190
+ return paginate35(items, page > 0 ? page - 1 : 0, limit, length);
63771
64191
  }
63772
64192
  async function getMapById(id) {
63773
64193
  const map = await collection.findOne({ _id: toObjectId16(id, "map"), ...NOT_DELETED2 });
@@ -64811,7 +65231,7 @@ import {
64811
65231
  InternalServerError as InternalServerError52,
64812
65232
  logger as logger112,
64813
65233
  makeCacheKey as makeCacheKey36,
64814
- paginate as paginate35,
65234
+ paginate as paginate36,
64815
65235
  useAtlas as useAtlas80,
64816
65236
  useCache as useCache41
64817
65237
  } from "@7365admin1/node-server-utils";
@@ -64923,7 +65343,7 @@ function usePatrolQuestionRepo() {
64923
65343
  collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
64924
65344
  ]);
64925
65345
  const totalCount = countResult[0]?.total || 0;
64926
- const data = paginate35(items, page, limit, totalCount);
65346
+ const data = paginate36(items, page, limit, totalCount);
64927
65347
  setCache(cacheKey, data, 15 * 60).then(() => logger112.info(`Cache set for key: ${cacheKey}`)).catch(
64928
65348
  (err) => logger112.error(`Failed to set cache for key: ${cacheKey}`, err)
64929
65349
  );
@@ -65276,7 +65696,7 @@ import {
65276
65696
  InternalServerError as InternalServerError53,
65277
65697
  logger as logger115,
65278
65698
  makeCacheKey as makeCacheKey37,
65279
- paginate as paginate36,
65699
+ paginate as paginate37,
65280
65700
  useAtlas as useAtlas81,
65281
65701
  useCache as useCache42
65282
65702
  } from "@7365admin1/node-server-utils";
@@ -65439,7 +65859,7 @@ function usePatrolRouteRepo() {
65439
65859
  collection.aggregate([...countPipeline, { $count: "total" }], { session }).toArray()
65440
65860
  ]);
65441
65861
  const totalCount = countResult[0]?.total || 0;
65442
- const data = paginate36(items, page, limit, totalCount);
65862
+ const data = paginate37(items, page, limit, totalCount);
65443
65863
  setCache(cacheKey, data, 15 * 60).then(() => logger115.info(`Cache set for key: ${cacheKey}`)).catch(
65444
65864
  (err) => logger115.error(`Failed to set cache for key: ${cacheKey}`, err)
65445
65865
  );
@@ -65647,7 +66067,7 @@ function usePatrolRouteRepo() {
65647
66067
  const items = await collection.aggregate(basePipeline, { session }).toArray();
65648
66068
  const countResult = await collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray();
65649
66069
  const totalCount = countResult[0]?.total || 0;
65650
- const data = paginate36(items, page, limit, totalCount);
66070
+ const data = paginate37(items, page, limit, totalCount);
65651
66071
  setCache(cacheKey, data, 15 * 60).then(() => logger115.info(`Cache set for key: ${cacheKey}`)).catch(
65652
66072
  (err) => logger115.error(`Failed to set cache for key: ${cacheKey}`, err)
65653
66073
  );
@@ -66056,7 +66476,7 @@ import {
66056
66476
  InternalServerError as InternalServerError54,
66057
66477
  logger as logger118,
66058
66478
  makeCacheKey as makeCacheKey38,
66059
- paginate as paginate37,
66479
+ paginate as paginate38,
66060
66480
  useAtlas as useAtlas82,
66061
66481
  useCache as useCache43
66062
66482
  } from "@7365admin1/node-server-utils";
@@ -66344,7 +66764,7 @@ function usePatrolLogRepo() {
66344
66764
  collection.aggregate([...countPipeline, { $count: "total" }], { session }).toArray()
66345
66765
  ]);
66346
66766
  const totalCount = countResult[0]?.total || 0;
66347
- const data = paginate37(items, page, limit, totalCount);
66767
+ const data = paginate38(items, page, limit, totalCount);
66348
66768
  setCache(cacheKey, data, 15 * 60).then(() => logger118.info(`Cache set for key: ${cacheKey}`)).catch(
66349
66769
  (err) => logger118.error(`Failed to set cache for key: ${cacheKey}`, err)
66350
66770
  );
@@ -66854,7 +67274,7 @@ import {
66854
67274
  InternalServerError as InternalServerError55,
66855
67275
  logger as logger121,
66856
67276
  NotFoundError as NotFoundError49,
66857
- paginate as paginate38,
67277
+ paginate as paginate39,
66858
67278
  useAtlas as useAtlas84
66859
67279
  } from "@7365admin1/node-server-utils";
66860
67280
  import { ObjectId as ObjectId115 } from "mongodb";
@@ -66872,7 +67292,7 @@ function usePatrolEmailRepo() {
66872
67292
  throw new BadRequestError151(`Invalid ${label2} format.`);
66873
67293
  }
66874
67294
  }
66875
- function escapeRegex2(value) {
67295
+ function escapeRegex3(value) {
66876
67296
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
66877
67297
  }
66878
67298
  async function createIndexes() {
@@ -67009,8 +67429,8 @@ function usePatrolEmailRepo() {
67009
67429
  ...status ? { status } : { status: { $ne: "deleted" } },
67010
67430
  ...search && {
67011
67431
  $or: [
67012
- { subject: { $regex: escapeRegex2(search), $options: "i" } },
67013
- { recipients: { $regex: escapeRegex2(search), $options: "i" } }
67432
+ { subject: { $regex: escapeRegex3(search), $options: "i" } },
67433
+ { recipients: { $regex: escapeRegex3(search), $options: "i" } }
67014
67434
  ]
67015
67435
  }
67016
67436
  };
@@ -67019,7 +67439,7 @@ function usePatrolEmailRepo() {
67019
67439
  collection.find(query2, { session }).sort({ createdAt: -1, _id: -1 }).skip(page * limit).limit(limit).toArray(),
67020
67440
  collection.countDocuments(query2, { session })
67021
67441
  ]);
67022
- return paginate38(
67442
+ return paginate39(
67023
67443
  await withResendState(items, session),
67024
67444
  page,
67025
67445
  limit,
@@ -67952,7 +68372,7 @@ import {
67952
68372
  logger as logger125,
67953
68373
  makeCacheKey as makeCacheKey39,
67954
68374
  NotFoundError as NotFoundError51,
67955
- paginate as paginate39,
68375
+ paginate as paginate40,
67956
68376
  useAtlas as useAtlas85,
67957
68377
  useCache as useCache44
67958
68378
  } from "@7365admin1/node-server-utils";
@@ -68056,7 +68476,7 @@ function useSiteFacilityRepo() {
68056
68476
  { session }
68057
68477
  ).toArray();
68058
68478
  const length = await collection.countDocuments(query2, { session });
68059
- const data = paginate39(items, page, limit, length);
68479
+ const data = paginate40(items, page, limit, length);
68060
68480
  setCache(cacheKey, data, 15 * 60).then(() => {
68061
68481
  logger125.info(`Cache set for key: ${cacheKey}`);
68062
68482
  }).catch((err) => {
@@ -68634,7 +69054,7 @@ import {
68634
69054
  logger as logger127,
68635
69055
  makeCacheKey as makeCacheKey40,
68636
69056
  NotFoundError as NotFoundError53,
68637
- paginate as paginate40,
69057
+ paginate as paginate41,
68638
69058
  useAtlas as useAtlas87,
68639
69059
  useCache as useCache45
68640
69060
  } from "@7365admin1/node-server-utils";
@@ -68722,7 +69142,7 @@ function useServiceProviderBillingRepo() {
68722
69142
  { session }
68723
69143
  ).toArray();
68724
69144
  const length = await collection.countDocuments(query2, { session });
68725
- const data = paginate40(items, page, limit, length);
69145
+ const data = paginate41(items, page, limit, length);
68726
69146
  setCache(cacheKey, data, 15 * 60).then(() => {
68727
69147
  logger127.info(`Cache set for key: ${cacheKey}`);
68728
69148
  }).catch((err) => {
@@ -69304,7 +69724,7 @@ import {
69304
69724
  logger as logger129,
69305
69725
  makeCacheKey as makeCacheKey41,
69306
69726
  NotFoundError as NotFoundError54,
69307
- paginate as paginate41,
69727
+ paginate as paginate42,
69308
69728
  toObjectId as toObjectId18,
69309
69729
  useAtlas as useAtlas89,
69310
69730
  useCache as useCache46
@@ -69395,7 +69815,7 @@ function useSiteFacilityBookingRepo() {
69395
69815
  { session }
69396
69816
  ).toArray();
69397
69817
  const length = await collection.countDocuments(query2, { session });
69398
- const data = paginate41(items, page, limit, length);
69818
+ const data = paginate42(items, page, limit, length);
69399
69819
  setCache(cacheKey, data, 15 * 60).then(() => {
69400
69820
  logger129.info(`Cache set for key: ${cacheKey}`);
69401
69821
  }).catch((err) => {
@@ -69873,7 +70293,7 @@ import {
69873
70293
  logger as logger131,
69874
70294
  makeCacheKey as makeCacheKey42,
69875
70295
  NotFoundError as NotFoundError56,
69876
- paginate as paginate42,
70296
+ paginate as paginate43,
69877
70297
  useAtlas as useAtlas91,
69878
70298
  useCache as useCache47
69879
70299
  } from "@7365admin1/node-server-utils";
@@ -70002,7 +70422,7 @@ function useDocumentManagementRepo() {
70002
70422
  { $limit: limit }
70003
70423
  ]).toArray();
70004
70424
  const length = await collection.countDocuments(query2);
70005
- const data = paginate42(items, page, limit, length);
70425
+ const data = paginate43(items, page, limit, length);
70006
70426
  setCache(cacheKey, data, 15 * 60).then(() => {
70007
70427
  logger131.info(`Cache set for key: ${cacheKey}`);
70008
70428
  }).catch((err) => {
@@ -70973,7 +71393,7 @@ import {
70973
71393
  logger as logger134,
70974
71394
  makeCacheKey as makeCacheKey43,
70975
71395
  NotFoundError as NotFoundError58,
70976
- paginate as paginate43,
71396
+ paginate as paginate44,
70977
71397
  useAtlas as useAtlas93,
70978
71398
  useCache as useCache48
70979
71399
  } from "@7365admin1/node-server-utils";
@@ -71080,7 +71500,7 @@ function useBulletinBoardRepo() {
71080
71500
  { session }
71081
71501
  ).toArray();
71082
71502
  const length = await collection.countDocuments(query2, { session });
71083
- const data = paginate43(items, page, limit, length);
71503
+ const data = paginate44(items, page, limit, length);
71084
71504
  setCache(cacheKey, data, 15 * 60).then(() => {
71085
71505
  logger134.info(`Cache set for key: ${cacheKey}`);
71086
71506
  }).catch((err) => {
@@ -71815,7 +72235,7 @@ import {
71815
72235
  logger as logger137,
71816
72236
  useAtlas as useAtlas95,
71817
72237
  useCache as useCache49,
71818
- paginate as paginate44,
72238
+ paginate as paginate45,
71819
72239
  makeCacheKey as makeCacheKey44
71820
72240
  } from "@7365admin1/node-server-utils";
71821
72241
  import { ObjectId as ObjectId129 } from "mongodb";
@@ -71927,7 +72347,7 @@ function useSiteBillingItemRepo() {
71927
72347
  collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
71928
72348
  ]);
71929
72349
  const totalCount = countResult[0]?.total || 0;
71930
- const data = paginate44(items, page, limit, totalCount);
72350
+ const data = paginate45(items, page, limit, totalCount);
71931
72351
  setCache(cacheKey, data, 15 * 60).then(() => logger137.info(`Cache set for key: ${cacheKey}`)).catch(
71932
72352
  (err) => logger137.error(`Failed to set cache for key: ${cacheKey}`, err)
71933
72353
  );
@@ -72076,7 +72496,7 @@ import {
72076
72496
  logger as logger139,
72077
72497
  useAtlas as useAtlas96,
72078
72498
  useCache as useCache50,
72079
- paginate as paginate45,
72499
+ paginate as paginate46,
72080
72500
  makeCacheKey as makeCacheKey45
72081
72501
  } from "@7365admin1/node-server-utils";
72082
72502
 
@@ -72301,7 +72721,7 @@ function useSiteBillingConfigurationRepo() {
72301
72721
  collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
72302
72722
  ]);
72303
72723
  const totalCount = countResult[0]?.total || 0;
72304
- const data = paginate45(items, page, limit, totalCount);
72724
+ const data = paginate46(items, page, limit, totalCount);
72305
72725
  setCache(cacheKey, data, 15 * 60).then(() => logger139.info(`Cache set for key: ${cacheKey}`)).catch(
72306
72726
  (err) => logger139.error(`Failed to set cache for key: ${cacheKey}`, err)
72307
72727
  );
@@ -73068,7 +73488,7 @@ import {
73068
73488
  logger as logger144,
73069
73489
  makeCacheKey as makeCacheKey46,
73070
73490
  NotFoundError as NotFoundError63,
73071
- paginate as paginate46,
73491
+ paginate as paginate47,
73072
73492
  useAtlas as useAtlas99,
73073
73493
  useCache as useCache51
73074
73494
  } from "@7365admin1/node-server-utils";
@@ -73215,7 +73635,7 @@ function useEventManagementRepo() {
73215
73635
  ]).toArray();
73216
73636
  length = await collection.countDocuments(regexQuery, { session });
73217
73637
  }
73218
- const data = paginate46(items, page, limit, length);
73638
+ const data = paginate47(items, page, limit, length);
73219
73639
  setCache(cacheKey, data, 15 * 60).then(() => {
73220
73640
  logger144.info(`Cache set for key: ${cacheKey}`);
73221
73641
  }).catch((err) => {
@@ -73792,7 +74212,7 @@ import {
73792
74212
  logger as logger147,
73793
74213
  useAtlas as useAtlas101,
73794
74214
  useCache as useCache52,
73795
- paginate as paginate47,
74215
+ paginate as paginate48,
73796
74216
  makeCacheKey as makeCacheKey47
73797
74217
  } from "@7365admin1/node-server-utils";
73798
74218
  import { ObjectId as ObjectId135 } from "mongodb";
@@ -73978,7 +74398,7 @@ function useSiteUnitBillingRepo() {
73978
74398
  collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
73979
74399
  ]);
73980
74400
  const totalCount = countResult[0]?.total || 0;
73981
- const data = paginate47(items, page, limit, totalCount);
74401
+ const data = paginate48(items, page, limit, totalCount);
73982
74402
  setCache(cacheKey, data, 15 * 60).then(() => logger147.info(`Cache set for key: ${cacheKey}`)).catch(
73983
74403
  (err) => logger147.error(`Failed to set cache for key: ${cacheKey}`, err)
73984
74404
  );
@@ -74242,7 +74662,7 @@ function useSiteUnitBillingRepo() {
74242
74662
  collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
74243
74663
  ]);
74244
74664
  const totalCount = countResult[0]?.total || 0;
74245
- const data = paginate47(items, page, limit, totalCount);
74665
+ const data = paginate48(items, page, limit, totalCount);
74246
74666
  return data;
74247
74667
  } catch (error) {
74248
74668
  throw error;
@@ -74325,7 +74745,7 @@ function useSiteUnitBillingRepo() {
74325
74745
  collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
74326
74746
  ]);
74327
74747
  const totalCount = countResult[0]?.total || 0;
74328
- const data = paginate47(items, page, limit, totalCount);
74748
+ const data = paginate48(items, page, limit, totalCount);
74329
74749
  return data;
74330
74750
  } catch (error) {
74331
74751
  throw error;
@@ -76387,7 +76807,7 @@ import {
76387
76807
  logger as logger150,
76388
76808
  makeCacheKey as makeCacheKey48,
76389
76809
  NotFoundError as NotFoundError66,
76390
- paginate as paginate48,
76810
+ paginate as paginate49,
76391
76811
  useAtlas as useAtlas104,
76392
76812
  useCache as useCache53
76393
76813
  } from "@7365admin1/node-server-utils";
@@ -76474,7 +76894,7 @@ function useNfcPatrolTagRepo() {
76474
76894
  { session }
76475
76895
  ).toArray();
76476
76896
  const length = await collection.countDocuments(query2, { session });
76477
- const data = paginate48(items, page, limit, length);
76897
+ const data = paginate49(items, page, limit, length);
76478
76898
  setCache(cacheKey, data, 15 * 60).then(() => {
76479
76899
  logger150.info(`Cache set for key: ${cacheKey}`);
76480
76900
  }).catch((err) => {
@@ -77187,7 +77607,7 @@ import {
77187
77607
  logger as logger154,
77188
77608
  makeCacheKey as makeCacheKey49,
77189
77609
  NotFoundError as NotFoundError67,
77190
- paginate as paginate49,
77610
+ paginate as paginate50,
77191
77611
  useAtlas as useAtlas106,
77192
77612
  useCache as useCache54
77193
77613
  } from "@7365admin1/node-server-utils";
@@ -77298,7 +77718,7 @@ function useBulletinVideoRepo() {
77298
77718
  { session }
77299
77719
  ).toArray();
77300
77720
  const length = await collection.countDocuments(query2, { session });
77301
- const data = paginate49(items, page, limit, length);
77721
+ const data = paginate50(items, page, limit, length);
77302
77722
  setCache(cacheKey, data, 15 * 60).then(() => {
77303
77723
  logger154.info(`Cache set for key: ${cacheKey}`);
77304
77724
  }).catch((err) => {
@@ -77792,7 +78212,7 @@ import {
77792
78212
  logger as logger157,
77793
78213
  useAtlas as useAtlas108,
77794
78214
  useCache as useCache55,
77795
- paginate as paginate50,
78215
+ paginate as paginate51,
77796
78216
  makeCacheKey as makeCacheKey50
77797
78217
  } from "@7365admin1/node-server-utils";
77798
78218
  import { ObjectId as ObjectId144 } from "mongodb";
@@ -77932,7 +78352,7 @@ function useStatementOfAccountRepo() {
77932
78352
  collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
77933
78353
  ]);
77934
78354
  const totalCount = countResult[0]?.total || 0;
77935
- const data = paginate50(items, page, limit, totalCount);
78355
+ const data = paginate51(items, page, limit, totalCount);
77936
78356
  setCache(cacheKey, data, 15 * 60).then(() => logger157.info(`Cache set for key: ${cacheKey}`)).catch(
77937
78357
  (err) => logger157.error(`Failed to set cache for key: ${cacheKey}`, err)
77938
78358
  );
@@ -78103,7 +78523,7 @@ function useStatementOfAccountRepo() {
78103
78523
  collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
78104
78524
  ]);
78105
78525
  const totalCount = countResult[0]?.total || 0;
78106
- const data = paginate50(items, page, limit, totalCount);
78526
+ const data = paginate51(items, page, limit, totalCount);
78107
78527
  return data;
78108
78528
  } catch (error) {
78109
78529
  throw error;
@@ -78806,7 +79226,7 @@ import {
78806
79226
  logger as logger161,
78807
79227
  makeCacheKey as makeCacheKey51,
78808
79228
  NotFoundError as NotFoundError71,
78809
- paginate as paginate51,
79229
+ paginate as paginate52,
78810
79230
  useAtlas as useAtlas110,
78811
79231
  useCache as useCache56
78812
79232
  } from "@7365admin1/node-server-utils";
@@ -78907,7 +79327,7 @@ function useEntryPassSettingsRepo() {
78907
79327
  }
78908
79328
  ]).toArray();
78909
79329
  const length = await collection.countDocuments(query2);
78910
- const data = paginate51(items, page, limit, length);
79330
+ const data = paginate52(items, page, limit, length);
78911
79331
  setCache(cacheKey, data, 15 * 60).then(() => {
78912
79332
  logger161.info(`Cache set for key: ${cacheKey}`);
78913
79333
  }).catch((err) => {
@@ -79567,7 +79987,7 @@ import {
79567
79987
  InternalServerError as InternalServerError70,
79568
79988
  logger as logger166,
79569
79989
  makeCacheKey as makeCacheKey53,
79570
- paginate as paginate52,
79990
+ paginate as paginate53,
79571
79991
  useAtlas as useAtlas112,
79572
79992
  useCache as useCache58
79573
79993
  } from "@7365admin1/node-server-utils";
@@ -79676,7 +80096,7 @@ function useNfcPatrolRouteRepo() {
79676
80096
  { session }
79677
80097
  ).toArray();
79678
80098
  const length = await collection.countDocuments(query2, { session });
79679
- const data = paginate52(items, page, limit, length);
80099
+ const data = paginate53(items, page, limit, length);
79680
80100
  setCache(cacheKey, data, 15 * 60).then(() => {
79681
80101
  logger166.info(`Cache set for key: ${cacheKey}`);
79682
80102
  }).catch((err) => {
@@ -80418,7 +80838,7 @@ import {
80418
80838
  logger as logger169,
80419
80839
  makeCacheKey as makeCacheKey54,
80420
80840
  NotFoundError as NotFoundError74,
80421
- paginate as paginate53,
80841
+ paginate as paginate54,
80422
80842
  useAtlas as useAtlas114,
80423
80843
  useCache as useCache59
80424
80844
  } from "@7365admin1/node-server-utils";
@@ -80567,7 +80987,7 @@ function useIncidentReportRepo() {
80567
80987
  { session }
80568
80988
  ).toArray();
80569
80989
  const length = await collection.countDocuments(query2, { session });
80570
- const data = paginate53(items, page, limit, length);
80990
+ const data = paginate54(items, page, limit, length);
80571
80991
  setCache(cacheKey, data, 15 * 60).then(() => {
80572
80992
  logger169.info(`Cache set for key: ${cacheKey}`);
80573
80993
  }).catch((err) => {
@@ -80651,7 +81071,7 @@ function useIncidentReportRepo() {
80651
81071
  { session }
80652
81072
  ).toArray();
80653
81073
  const length = await collection.countDocuments(query2, { session });
80654
- const data = paginate53(items, page, limit, length);
81074
+ const data = paginate54(items, page, limit, length);
80655
81075
  return data;
80656
81076
  } catch (error) {
80657
81077
  throw error;
@@ -81699,7 +82119,7 @@ import {
81699
82119
  logger as logger175,
81700
82120
  makeCacheKey as makeCacheKey56,
81701
82121
  NotFoundError as NotFoundError77,
81702
- paginate as paginate54,
82122
+ paginate as paginate55,
81703
82123
  useAtlas as useAtlas118,
81704
82124
  useCache as useCache61
81705
82125
  } from "@7365admin1/node-server-utils";
@@ -81900,7 +82320,7 @@ function useOccurrenceSubjectRepo() {
81900
82320
  ]).toArray();
81901
82321
  length = await collection.countDocuments(regexQuery, { session });
81902
82322
  }
81903
- const data = paginate54(items, page, limit, length);
82323
+ const data = paginate55(items, page, limit, length);
81904
82324
  setCache(cacheKey, data, 15 * 60).then(() => {
81905
82325
  logger175.info(`Cache set for key: ${cacheKey}`);
81906
82326
  }).catch((err) => {
@@ -82408,7 +82828,7 @@ import {
82408
82828
  logger as logger177,
82409
82829
  makeCacheKey as makeCacheKey57,
82410
82830
  NotFoundError as NotFoundError78,
82411
- paginate as paginate55,
82831
+ paginate as paginate56,
82412
82832
  useAtlas as useAtlas120,
82413
82833
  useCache as useCache62
82414
82834
  } from "@7365admin1/node-server-utils";
@@ -82511,7 +82931,7 @@ function useOnlineFormRepo() {
82511
82931
  }
82512
82932
  ]).toArray();
82513
82933
  const length = await collection.countDocuments(query2);
82514
- const data = paginate55(items, page, limit, length);
82934
+ const data = paginate56(items, page, limit, length);
82515
82935
  setCache(cacheKey, data, 15 * 60).then(() => {
82516
82936
  logger177.info(`Cache set for key: ${cacheKey}`);
82517
82937
  }).catch((err) => {
@@ -82672,7 +83092,7 @@ function useOnlineFormRepo() {
82672
83092
  }
82673
83093
  ]).toArray();
82674
83094
  const length = await collection.countDocuments(query2);
82675
- const data = paginate55(items, page, limit, length);
83095
+ const data = paginate56(items, page, limit, length);
82676
83096
  setCache(cacheKey, data, 15 * 60).then(() => {
82677
83097
  logger177.info(`Cache set for key: ${cacheKey}`);
82678
83098
  }).catch((err) => {
@@ -83103,7 +83523,7 @@ import {
83103
83523
  InternalServerError as InternalServerError75,
83104
83524
  logger as logger180,
83105
83525
  makeCacheKey as makeCacheKey58,
83106
- paginate as paginate56,
83526
+ paginate as paginate57,
83107
83527
  useAtlas as useAtlas122,
83108
83528
  useCache as useCache63
83109
83529
  } from "@7365admin1/node-server-utils";
@@ -83211,7 +83631,7 @@ function useNfcPatrolLogRepo() {
83211
83631
  const length = await collection.countDocuments(query2, {
83212
83632
  session
83213
83633
  });
83214
- const data = paginate56(items, pageIndex, limit, length);
83634
+ const data = paginate57(items, pageIndex, limit, length);
83215
83635
  setCache(cacheKey, data, 15 * 60).then(() => {
83216
83636
  logger180.info(`Cache set for key: ${cacheKey}`);
83217
83637
  }).catch((err) => {
@@ -83610,7 +84030,7 @@ function useNfcPatrolLogController() {
83610
84030
  import {
83611
84031
  BadRequestError as BadRequestError216,
83612
84032
  InternalServerError as InternalServerError76,
83613
- paginate as paginate57,
84033
+ paginate as paginate58,
83614
84034
  toObjectId as toObjectId19,
83615
84035
  useAtlas as useAtlas124
83616
84036
  } from "@7365admin1/node-server-utils";
@@ -83688,6 +84108,8 @@ var Period = /* @__PURE__ */ ((Period2) => {
83688
84108
  Period2["THIS_MONTH"] = "thisMonth";
83689
84109
  return Period2;
83690
84110
  })(Period || {});
84111
+ var WORK_ORDER_DELETED = ["Deleted", "deleted"];
84112
+ var WORK_ORDER_NOT_OPEN = ["Completed", ...WORK_ORDER_DELETED];
83691
84113
  function useNewDashboardRepo() {
83692
84114
  const db2 = useAtlas124.getDb();
83693
84115
  if (!db2) {
@@ -83789,7 +84211,7 @@ function useNewDashboardRepo() {
83789
84211
  $match: {
83790
84212
  site: { $in: [siteIdObj, siteId] },
83791
84213
  service: "Security",
83792
- status: { $nin: ["Completed", "Deleted"] }
84214
+ status: { $nin: WORK_ORDER_NOT_OPEN }
83793
84215
  }
83794
84216
  },
83795
84217
  {
@@ -83821,7 +84243,7 @@ function useNewDashboardRepo() {
83821
84243
  site: { $in: [siteIdObj, siteId] },
83822
84244
  service: "Security",
83823
84245
  createdAt: priorPeriodRange,
83824
- status: { $nin: ["Completed", "Deleted"] }
84246
+ status: { $nin: WORK_ORDER_NOT_OPEN }
83825
84247
  }
83826
84248
  },
83827
84249
  { $count: "count" }
@@ -83832,7 +84254,7 @@ function useNewDashboardRepo() {
83832
84254
  site: { $in: [siteIdObj, siteId] },
83833
84255
  service: "Security",
83834
84256
  createdAt: periodRange,
83835
- status: { $nin: ["Completed", "Deleted"] }
84257
+ status: { $nin: WORK_ORDER_NOT_OPEN }
83836
84258
  }
83837
84259
  },
83838
84260
  { $count: "count" }
@@ -84192,7 +84614,7 @@ function useNewDashboardRepo() {
84192
84614
  {
84193
84615
  $match: {
84194
84616
  site: { $in: [siteIdObj, siteId] },
84195
- status: { $nin: ["Completed", "Deleted"] }
84617
+ status: { $nin: WORK_ORDER_NOT_OPEN }
84196
84618
  }
84197
84619
  },
84198
84620
  {
@@ -84223,7 +84645,7 @@ function useNewDashboardRepo() {
84223
84645
  $match: {
84224
84646
  site: { $in: [siteIdObj, siteId] },
84225
84647
  createdAt: priorPeriodRange,
84226
- status: { $nin: ["Completed", "Deleted"] }
84648
+ status: { $nin: WORK_ORDER_NOT_OPEN }
84227
84649
  }
84228
84650
  },
84229
84651
  { $count: "count" }
@@ -84233,7 +84655,7 @@ function useNewDashboardRepo() {
84233
84655
  $match: {
84234
84656
  site: { $in: [siteIdObj, siteId] },
84235
84657
  createdAt: periodRange,
84236
- status: { $nin: ["Completed", "Deleted"] }
84658
+ status: { $nin: WORK_ORDER_NOT_OPEN }
84237
84659
  }
84238
84660
  },
84239
84661
  { $count: "count" }
@@ -84417,7 +84839,8 @@ function useNewDashboardRepo() {
84417
84839
  {
84418
84840
  $match: {
84419
84841
  site: { $in: [siteIdObj, siteId] },
84420
- createdAt: periodRange
84842
+ createdAt: periodRange,
84843
+ status: { $nin: WORK_ORDER_DELETED }
84421
84844
  }
84422
84845
  },
84423
84846
  {
@@ -84579,7 +85002,7 @@ function useNewDashboardRepo() {
84579
85002
  const workOrderService = workOrderServiceMap[serviceType] ?? serviceType;
84580
85003
  const workOrderMatchQuery = {
84581
85004
  site,
84582
- status: { $nin: ["Completed", "Deleted"] }
85005
+ status: { $nin: WORK_ORDER_NOT_OPEN }
84583
85006
  };
84584
85007
  if (serviceType !== "property_management_agency") {
84585
85008
  workOrderMatchQuery.service = workOrderService;
@@ -84755,7 +85178,7 @@ function useNewDashboardRepo() {
84755
85178
  try {
84756
85179
  const workOrderQuery = {
84757
85180
  site,
84758
- status: { $nin: ["Deleted"] },
85181
+ status: { $nin: WORK_ORDER_DELETED },
84759
85182
  $or: [
84760
85183
  { createdAt: { $gte: rangeStart, $lte: rangeEnd } },
84761
85184
  {
@@ -84879,7 +85302,7 @@ function useNewDashboardRepo() {
84879
85302
  ]).toArray()
84880
85303
  ]);
84881
85304
  const length = countResult[0]?.count ?? 0;
84882
- const data = paginate57(items, page, limit, length);
85305
+ const data = paginate58(items, page, limit, length);
84883
85306
  return data;
84884
85307
  } catch (error) {
84885
85308
  throw error;
@@ -85009,7 +85432,7 @@ function useNewDashboardRepo() {
85009
85432
  ]
85010
85433
  })
85011
85434
  ]);
85012
- const data = paginate57(items, page, limit, length);
85435
+ const data = paginate58(items, page, limit, length);
85013
85436
  return data;
85014
85437
  } catch (error) {
85015
85438
  throw error;
@@ -85066,7 +85489,7 @@ function useNewDashboardRepo() {
85066
85489
  ]).toArray(),
85067
85490
  feedbackCollection.countDocuments(matchQuery)
85068
85491
  ]);
85069
- const data = paginate57(items, page, limit, length);
85492
+ const data = paginate58(items, page, limit, length);
85070
85493
  return data;
85071
85494
  } catch (error) {
85072
85495
  throw error;
@@ -85385,7 +85808,7 @@ import {
85385
85808
  BadRequestError as BadRequestError218,
85386
85809
  InternalServerError as InternalServerError77,
85387
85810
  logger as logger184,
85388
- paginate as paginate59,
85811
+ paginate as paginate60,
85389
85812
  useAtlas as useAtlas125
85390
85813
  } from "@7365admin1/node-server-utils";
85391
85814
 
@@ -85480,7 +85903,7 @@ function filterByShiftTime(attendance, shiftData, timezone, format2) {
85480
85903
  return checkInLocal.isBetween(shiftStart, shiftEnd, null, "[]");
85481
85904
  });
85482
85905
  }
85483
- function paginate58(data, page, limit) {
85906
+ function paginate59(data, page, limit) {
85484
85907
  const length = data.length;
85485
85908
  const startIndex = (page - 1) * limit;
85486
85909
  const endIndex = startIndex + limit;
@@ -85828,7 +86251,7 @@ var hrmlabs_attendance_util_default = {
85828
86251
  hrmLabsAuthentication,
85829
86252
  fetchAttendanceData,
85830
86253
  filterByShiftTime,
85831
- paginate: paginate58,
86254
+ paginate: paginate59,
85832
86255
  designationCount,
85833
86256
  totalCountPerShift,
85834
86257
  filterByStatus,
@@ -85911,7 +86334,7 @@ function useManpowerMonitoringRepo() {
85911
86334
  ]).toArray();
85912
86335
  const total = result[0].totalCount[0]?.count || 0;
85913
86336
  const items = result[0].items;
85914
- return paginate59(items, page, limit, total);
86337
+ return paginate60(items, page, limit, total);
85915
86338
  } catch (error) {
85916
86339
  throw new Error(error.message || "Server Internal Error");
85917
86340
  }
@@ -86071,7 +86494,7 @@ import {
86071
86494
  BadRequestError as BadRequestError219,
86072
86495
  InternalServerError as InternalServerError78,
86073
86496
  logger as logger185,
86074
- paginate as paginate60,
86497
+ paginate as paginate61,
86075
86498
  useAtlas as useAtlas126
86076
86499
  } from "@7365admin1/node-server-utils";
86077
86500
 
@@ -86200,7 +86623,7 @@ function useManpowerRemarksRepo() {
86200
86623
  ]).toArray();
86201
86624
  const total = result[0].totalCount[0]?.count || 0;
86202
86625
  const items = result[0].items;
86203
- return paginate60(items, page, limit, total);
86626
+ return paginate61(items, page, limit, total);
86204
86627
  } catch (error) {
86205
86628
  throw new Error(error.message || "Server Internal Error");
86206
86629
  }
@@ -87074,7 +87497,7 @@ import {
87074
87497
  InternalServerError as InternalServerError81,
87075
87498
  logger as logger192,
87076
87499
  makeCacheKey as makeCacheKey63,
87077
- paginate as paginate63,
87500
+ paginate as paginate64,
87078
87501
  toObjectId as toObjectId22,
87079
87502
  useAtlas as useAtlas130,
87080
87503
  useCache as useCache68
@@ -87172,7 +87595,7 @@ function useOvernightParkingRequestRepo() {
87172
87595
  { $limit: limit }
87173
87596
  ]).toArray();
87174
87597
  const length = await collection.countDocuments(query2);
87175
- const data = paginate63(items, page, limit, length);
87598
+ const data = paginate64(items, page, limit, length);
87176
87599
  setCache(cacheKey, data, 15 * 60).then(() => {
87177
87600
  logger192.info(`Cache set for key: ${cacheKey}`);
87178
87601
  }).catch((err) => {
@@ -87602,7 +88025,7 @@ var {
87602
88025
  hrmLabsAuthentication: hrmLabsAuthentication3,
87603
88026
  fetchAttendanceData: fetchAttendanceData2,
87604
88027
  filterByShiftTime: filterByShiftTime2,
87605
- paginate: paginate64,
88028
+ paginate: paginate65,
87606
88029
  designationCount: designationCount2,
87607
88030
  totalCountPerShift: totalCountPerShift2,
87608
88031
  filterByStatus: filterByStatus2,
@@ -87712,7 +88135,7 @@ function useHrmLabsAttendanceSrvc() {
87712
88135
  status
87713
88136
  );
87714
88137
  }
87715
- const paginatedItems = paginate64(filteredAttendance, page, limit);
88138
+ const paginatedItems = paginate65(filteredAttendance, page, limit);
87716
88139
  return {
87717
88140
  items: paginatedItems.items,
87718
88141
  pages: paginatedItems.pages,
@@ -89451,7 +89874,7 @@ import {
89451
89874
  BadRequestError as BadRequestError234,
89452
89875
  NotFoundError as NotFoundError85,
89453
89876
  AppError as AppError37,
89454
- paginate as paginate66
89877
+ paginate as paginate67
89455
89878
  } from "@7365admin1/node-server-utils";
89456
89879
  var useRedDotPaymentRepo = () => {
89457
89880
  const getDB2 = () => {
@@ -89630,7 +90053,7 @@ var useRedDotPaymentRepo = () => {
89630
90053
  paymentCollection().aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
89631
90054
  ]);
89632
90055
  const totalCount = countResult[0]?.total || 0;
89633
- const data = paginate66(items, page, limit, totalCount);
90056
+ const data = paginate67(items, page, limit, totalCount);
89634
90057
  return data;
89635
90058
  } catch (error) {
89636
90059
  if (error instanceof AppError37) {
@@ -90197,7 +90620,7 @@ import {
90197
90620
  InternalServerError as InternalServerError85,
90198
90621
  logger as logger206,
90199
90622
  BadRequestError as BadRequestError236,
90200
- paginate as paginate67,
90623
+ paginate as paginate68,
90201
90624
  NotFoundError as NotFoundError86,
90202
90625
  AppError as AppError38,
90203
90626
  useCache as useCache72,
@@ -90440,7 +90863,7 @@ function useUserRepoV2() {
90440
90863
  }
90441
90864
  ]).toArray();
90442
90865
  const length = await collection.countDocuments(query2);
90443
- const data = paginate67(items, page, limit, length);
90866
+ const data = paginate68(items, page, limit, length);
90444
90867
  setCache(cacheKey, data, 15 * 60).then(() => {
90445
90868
  logger206.info(`Cache set for key: ${cacheKey}`);
90446
90869
  }).catch((err) => {
@@ -90496,7 +90919,7 @@ function useUserRepoV2() {
90496
90919
  { $project: { _id: 1, name: 1, email: 1, type: 1, status: 1 } }
90497
90920
  ]).toArray();
90498
90921
  const length = await collection.countDocuments(query2);
90499
- const data = paginate67(items, page, limit, length);
90922
+ const data = paginate68(items, page, limit, length);
90500
90923
  setCache(cacheKey, data, 15 * 60).then(() => logger206.info(`Cache set for key: ${cacheKey}`)).catch(
90501
90924
  (err) => logger206.error(`Failed to set cache for key: ${cacheKey}`, err)
90502
90925
  );
@@ -92062,6 +92485,7 @@ function useServiceProviderInviteController() {
92062
92485
  try {
92063
92486
  const schema2 = Joi149.object({
92064
92487
  org: Joi149.string().hex().length(24).optional().allow("", null),
92488
+ siteId: Joi149.string().hex().length(24).optional().allow("", null),
92065
92489
  status: Joi149.string().optional().allow("", null),
92066
92490
  search: Joi149.string().max(200).optional().allow("", null),
92067
92491
  page: Joi149.number().min(1).default(1),
@@ -92071,10 +92495,13 @@ function useServiceProviderInviteController() {
92071
92495
  if (error)
92072
92496
  throw new BadRequestError240(`Invalid input: ${error.message}`);
92073
92497
  const statuses = String(value.status ?? "").split(",").map((s) => s.trim()).filter(Boolean);
92498
+ if (value.siteId)
92499
+ await requireSiteReach(req, value.siteId);
92074
92500
  res.json(
92075
92501
  await listForCaller({
92076
92502
  userId: callerId5(req),
92077
92503
  orgId: value.org || void 0,
92504
+ siteId: value.siteId || void 0,
92078
92505
  statuses,
92079
92506
  search: value.search || "",
92080
92507
  page: value.page,
@@ -93251,7 +93678,7 @@ import {
93251
93678
  BadRequestError as BadRequestError247,
93252
93679
  InternalServerError as InternalServerError90,
93253
93680
  NotFoundError as NotFoundError90,
93254
- paginate as paginate68,
93681
+ paginate as paginate69,
93255
93682
  useAtlas as useAtlas143
93256
93683
  } from "@7365admin1/node-server-utils";
93257
93684
  import { ObjectId as ObjectId178 } from "mongodb";
@@ -93617,7 +94044,7 @@ function usePostPrelovedRepo() {
93617
94044
  { session }
93618
94045
  ).toArray();
93619
94046
  const length = await collection.countDocuments(query2, { session });
93620
- return paginate68(items, page, limit, length);
94047
+ return paginate69(items, page, limit, length);
93621
94048
  } catch (error) {
93622
94049
  throw error;
93623
94050
  }
@@ -93689,7 +94116,7 @@ function usePostPrelovedRepo() {
93689
94116
  { session }
93690
94117
  ).toArray();
93691
94118
  const length = await collection.countDocuments(query2, { session });
93692
- return paginate68(items, page, limit, length);
94119
+ return paginate69(items, page, limit, length);
93693
94120
  } catch (error) {
93694
94121
  throw error;
93695
94122
  }
@@ -95060,7 +95487,7 @@ import { BadRequestError as BadRequestError256, InternalServerError as InternalS
95060
95487
  // src/repositories/channel-preloved.repo.ts
95061
95488
  import {
95062
95489
  InternalServerError as InternalServerError95,
95063
- paginate as paginate70,
95490
+ paginate as paginate71,
95064
95491
  useAtlas as useAtlas150
95065
95492
  } from "@7365admin1/node-server-utils";
95066
95493
  import { ObjectId as ObjectId189 } from "mongodb";
@@ -95219,7 +95646,7 @@ function useChannelPrelovedRepo() {
95219
95646
  const totalCount = result[0].totalCount[0]?.count ?? 0;
95220
95647
  const items = result[0].items;
95221
95648
  items.reverse();
95222
- return paginate70(items, normalizedPage, normalizedLimit, totalCount);
95649
+ return paginate71(items, normalizedPage, normalizedLimit, totalCount);
95223
95650
  } catch (error) {
95224
95651
  throw error;
95225
95652
  }
@@ -95342,7 +95769,7 @@ function useChannelPrelovedRepo() {
95342
95769
  const result = await collection.aggregate(pipeline).toArray();
95343
95770
  const totalCount = result[0].totalCount[0]?.count ?? 0;
95344
95771
  const items = result[0].items;
95345
- return paginate70(items, normalizedPage, normalizedLimit, totalCount);
95772
+ return paginate71(items, normalizedPage, normalizedLimit, totalCount);
95346
95773
  } catch (error) {
95347
95774
  throw error;
95348
95775
  }
@@ -96119,7 +96546,7 @@ import {
96119
96546
  BadRequestError as BadRequestError260,
96120
96547
  InternalServerError as InternalServerError100,
96121
96548
  NotFoundError as NotFoundError96,
96122
- paginate as paginate71,
96549
+ paginate as paginate72,
96123
96550
  useAtlas as useAtlas155,
96124
96551
  useCache as useCache76
96125
96552
  } from "@7365admin1/node-server-utils";
@@ -96207,7 +96634,7 @@ function useFormEntryRepo() {
96207
96634
  { $project: { user: 0 } }
96208
96635
  ]).toArray();
96209
96636
  const length = await collection.countDocuments(query2);
96210
- const data = paginate71(items, page, limit, length);
96637
+ const data = paginate72(items, page, limit, length);
96211
96638
  return data;
96212
96639
  } catch (error) {
96213
96640
  throw error;
@@ -96339,7 +96766,7 @@ function useFormEntryRepo() {
96339
96766
  { $limit: limit }
96340
96767
  ]).toArray();
96341
96768
  const length = await collection.countDocuments(query2);
96342
- const data = paginate71(items, page, limit, length);
96769
+ const data = paginate72(items, page, limit, length);
96343
96770
  return data;
96344
96771
  } catch (error) {
96345
96772
  throw error;