@7365admin1/core 3.100.1 → 3.102.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/index.d.ts +45 -5
- package/dist/index.js +511 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +617 -158
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/customer-site-list.test.mjs +106 -0
- package/test/customer-sites-one-row-per-site.test.mjs +7 -2
- package/test/e2e/customer-site-list.e2e.test.mjs +241 -0
- package/test/e2e/harness.mjs +2 -0
- package/test/e2e/service-provider-invite-approval.e2e.test.mjs +170 -0
- package/test/notification-kind.test.mjs +70 -0
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:
|
|
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
|
-
...
|
|
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
|
|
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) => {
|
|
@@ -10440,6 +10617,26 @@ async function filterByAccess(userIds, context, data) {
|
|
|
10440
10617
|
}
|
|
10441
10618
|
}
|
|
10442
10619
|
|
|
10620
|
+
// src/utils/notification-kind.util.ts
|
|
10621
|
+
var NOT_A_KIND = /* @__PURE__ */ new Set(["", "other", "platform"]);
|
|
10622
|
+
function notificationKind(data, category) {
|
|
10623
|
+
if (data?.kind)
|
|
10624
|
+
return String(data.kind);
|
|
10625
|
+
const module = String(data?.module ?? "");
|
|
10626
|
+
if (!NOT_A_KIND.has(module))
|
|
10627
|
+
return module;
|
|
10628
|
+
const fromCategory = String(category ?? "");
|
|
10629
|
+
return NOT_A_KIND.has(fromCategory) ? "" : fromCategory;
|
|
10630
|
+
}
|
|
10631
|
+
function withNotificationKind(data, category) {
|
|
10632
|
+
if (!data?.params?.id)
|
|
10633
|
+
return data;
|
|
10634
|
+
const kind = notificationKind(data, category);
|
|
10635
|
+
if (!kind)
|
|
10636
|
+
return data;
|
|
10637
|
+
return { ...data, params: { ...data.params, kind } };
|
|
10638
|
+
}
|
|
10639
|
+
|
|
10443
10640
|
// src/services/notification.service.ts
|
|
10444
10641
|
var { addMany: _addNotification } = useNotificationRepo();
|
|
10445
10642
|
var { filterRecipients: _filterRecipients } = useNotificationPreferenceRepo();
|
|
@@ -10450,6 +10647,7 @@ function toStringArray(recipient) {
|
|
|
10450
10647
|
async function send(userIds, title, body, data, isForMAMobileApp = false, appSlug, category) {
|
|
10451
10648
|
try {
|
|
10452
10649
|
const key = category || data?.module || "other";
|
|
10650
|
+
data = withNotificationKind(data, category);
|
|
10453
10651
|
userIds = await filterByAccess(userIds, { category: key, siteId: data?.siteId });
|
|
10454
10652
|
const inAppIds = await _filterRecipients(userIds, key, "inApp");
|
|
10455
10653
|
if (inAppIds.length) {
|
|
@@ -10540,6 +10738,7 @@ var NotificationService = class {
|
|
|
10540
10738
|
`${what} is now on iService365.`,
|
|
10541
10739
|
{
|
|
10542
10740
|
module: "platform",
|
|
10741
|
+
kind: "client",
|
|
10543
10742
|
screen: "",
|
|
10544
10743
|
params: { id: payload.orgId.toString() }
|
|
10545
10744
|
},
|
|
@@ -10581,7 +10780,7 @@ var NotificationService = class {
|
|
|
10581
10780
|
staff,
|
|
10582
10781
|
title,
|
|
10583
10782
|
body,
|
|
10584
|
-
{ module: "platform", screen: "", params: { id: payload.robotId } },
|
|
10783
|
+
{ module: "platform", kind: "robot", screen: "", params: { id: payload.robotId } },
|
|
10585
10784
|
false,
|
|
10586
10785
|
void 0,
|
|
10587
10786
|
"platform"
|
|
@@ -10596,7 +10795,7 @@ var NotificationService = class {
|
|
|
10596
10795
|
staff,
|
|
10597
10796
|
title,
|
|
10598
10797
|
body,
|
|
10599
|
-
{ module: "platform", screen: "", params: { id: payload.robotId } },
|
|
10798
|
+
{ module: "platform", kind: "robot", screen: "", params: { id: payload.robotId } },
|
|
10600
10799
|
false,
|
|
10601
10800
|
void 0,
|
|
10602
10801
|
"platform"
|
|
@@ -10795,7 +10994,13 @@ var NotificationService = class {
|
|
|
10795
10994
|
toStringArray(payload.to),
|
|
10796
10995
|
`${payload.providerName} ${verb} your invitation`,
|
|
10797
10996
|
payload.accepted ? `${payload.providerName} accepted your invitation to provide services at ${payload.siteName}. They can now see the site in their own app.` : `${payload.providerName} declined your invitation to provide services at ${payload.siteName}.`,
|
|
10798
|
-
{
|
|
10997
|
+
{
|
|
10998
|
+
module: "other",
|
|
10999
|
+
kind: "serviceProviderInviteAnswer",
|
|
11000
|
+
screen: "",
|
|
11001
|
+
// `site`, not `siteId`: the row stays unscoped on purpose (see above).
|
|
11002
|
+
...payload.invitationId ? { params: { id: payload.invitationId, ...payload.siteId ? { site: payload.siteId } : {} } } : {}
|
|
11003
|
+
},
|
|
10799
11004
|
false,
|
|
10800
11005
|
void 0,
|
|
10801
11006
|
"serviceProviderInvite"
|
|
@@ -10862,7 +11067,10 @@ var NotificationService = class {
|
|
|
10862
11067
|
body: `${which} has been ${payload.action} on your site's emergency contact list. Check the number is right before it is needed.`,
|
|
10863
11068
|
data: {
|
|
10864
11069
|
contactId: payload.contactId?.toString(),
|
|
10865
|
-
action: payload.action
|
|
11070
|
+
action: payload.action,
|
|
11071
|
+
// The page is the site's contact list, so the site stands in when a
|
|
11072
|
+
// removed contact has no id left to name.
|
|
11073
|
+
params: payload.contactId || payload.siteId ? { id: (payload.contactId ?? payload.siteId).toString() } : void 0
|
|
10866
11074
|
}
|
|
10867
11075
|
});
|
|
10868
11076
|
}
|
|
@@ -12569,6 +12777,7 @@ function useServiceProviderInviteService() {
|
|
|
12569
12777
|
async function listForCaller({
|
|
12570
12778
|
userId,
|
|
12571
12779
|
orgId,
|
|
12780
|
+
siteId,
|
|
12572
12781
|
statuses,
|
|
12573
12782
|
search = "",
|
|
12574
12783
|
page = 1,
|
|
@@ -12589,16 +12798,85 @@ function useServiceProviderInviteService() {
|
|
|
12589
12798
|
// A super admin asking for everything passes no scope; everyone else is
|
|
12590
12799
|
// pinned to their own organisations even if they ask for more.
|
|
12591
12800
|
orgIds: staffMayBypass(actor) && !orgId ? void 0 : scope,
|
|
12801
|
+
siteId: siteId || void 0,
|
|
12592
12802
|
search,
|
|
12593
12803
|
page,
|
|
12594
12804
|
limit
|
|
12595
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 ?? "");
|
|
12596
12857
|
return {
|
|
12597
|
-
...
|
|
12598
|
-
|
|
12599
|
-
|
|
12600
|
-
|
|
12601
|
-
|
|
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
|
|
12602
12880
|
};
|
|
12603
12881
|
}
|
|
12604
12882
|
async function approvalCount({ userId }) {
|
|
@@ -12822,7 +13100,9 @@ function useServiceProviderInviteService() {
|
|
|
12822
13100
|
to,
|
|
12823
13101
|
accepted,
|
|
12824
13102
|
providerName: providerName || providerOrg?.name || String(invite.email ?? ""),
|
|
12825
|
-
siteName: invite.metadata?.siteName ?? "the site"
|
|
13103
|
+
siteName: invite.metadata?.siteName ?? "the site",
|
|
13104
|
+
invitationId: invite._id?.toString(),
|
|
13105
|
+
siteId: invite.metadata?.siteId?.toString?.()
|
|
12826
13106
|
});
|
|
12827
13107
|
} catch (error) {
|
|
12828
13108
|
logger22.log({
|
|
@@ -19426,7 +19706,7 @@ function useVehicleRepo() {
|
|
|
19426
19706
|
let query2 = { ...baseQuery };
|
|
19427
19707
|
if (search)
|
|
19428
19708
|
query2.$text = { $search: search };
|
|
19429
|
-
const
|
|
19709
|
+
const escapeRegex3 = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
19430
19710
|
const buildGroupedPipeline = (matchQuery) => [
|
|
19431
19711
|
{ $match: matchQuery },
|
|
19432
19712
|
{
|
|
@@ -19610,7 +19890,7 @@ function useVehicleRepo() {
|
|
|
19610
19890
|
const countResult = await collection.aggregate(buildGroupedCountPipeline(query2)).toArray();
|
|
19611
19891
|
length = countResult[0]?.total || 0;
|
|
19612
19892
|
if ((!items || items.length === 0) && search) {
|
|
19613
|
-
const escaped =
|
|
19893
|
+
const escaped = escapeRegex3(search);
|
|
19614
19894
|
const regexQuery = {
|
|
19615
19895
|
...baseQuery,
|
|
19616
19896
|
$or: [
|
|
@@ -20399,7 +20679,7 @@ function useVehicleRepo() {
|
|
|
20399
20679
|
...baseQuery,
|
|
20400
20680
|
...search && { $text: { $search: search } }
|
|
20401
20681
|
};
|
|
20402
|
-
const
|
|
20682
|
+
const escapeRegex3 = (input) => input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
20403
20683
|
const buildPipeline = (matchQuery) => [
|
|
20404
20684
|
{ $match: matchQuery },
|
|
20405
20685
|
{
|
|
@@ -20427,7 +20707,7 @@ function useVehicleRepo() {
|
|
|
20427
20707
|
const countResult = await collection.aggregate(buildCountPipeline(query2)).toArray();
|
|
20428
20708
|
length = countResult[0]?.total || 0;
|
|
20429
20709
|
if ((!items || items.length === 0) && search) {
|
|
20430
|
-
const escaped =
|
|
20710
|
+
const escaped = escapeRegex3(search);
|
|
20431
20711
|
const regexQuery = {
|
|
20432
20712
|
...baseQuery,
|
|
20433
20713
|
$or: [
|
|
@@ -28626,9 +28906,9 @@ function parsePromoExpiry(value) {
|
|
|
28626
28906
|
const us = raw.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
|
|
28627
28907
|
if (us)
|
|
28628
28908
|
return endOfDay(us[3], us[1], us[2]);
|
|
28629
|
-
const
|
|
28630
|
-
if (
|
|
28631
|
-
return endOfDay(
|
|
28909
|
+
const iso2 = raw.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
28910
|
+
if (iso2)
|
|
28911
|
+
return endOfDay(iso2[1], iso2[2], iso2[3]);
|
|
28632
28912
|
const parsed = new Date(raw);
|
|
28633
28913
|
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
|
28634
28914
|
}
|
|
@@ -31890,7 +32170,7 @@ function useServiceProviderRepo() {
|
|
|
31890
32170
|
throw new BadRequestError80("Invalid site ID format.");
|
|
31891
32171
|
}
|
|
31892
32172
|
}
|
|
31893
|
-
cacheOptions.membersLookup = "
|
|
32173
|
+
cacheOptions.membersLookup = "2";
|
|
31894
32174
|
const cacheKey = makeCacheKey25(namespace_collection3, cacheOptions);
|
|
31895
32175
|
const cachedData = await getCache(cacheKey);
|
|
31896
32176
|
if (cachedData) {
|
|
@@ -31906,7 +32186,7 @@ function useServiceProviderRepo() {
|
|
|
31906
32186
|
localField: "serviceProviderOrgId",
|
|
31907
32187
|
foreignField: "_id",
|
|
31908
32188
|
as: "organization",
|
|
31909
|
-
pipeline: [{ $project: { nature: 1, email: 1 } }]
|
|
32189
|
+
pipeline: [{ $project: { nature: 1, email: 1, contact: 1 } }]
|
|
31910
32190
|
}
|
|
31911
32191
|
},
|
|
31912
32192
|
{
|
|
@@ -31918,11 +32198,19 @@ function useServiceProviderRepo() {
|
|
|
31918
32198
|
{
|
|
31919
32199
|
$lookup: {
|
|
31920
32200
|
from: "members",
|
|
31921
|
-
|
|
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" },
|
|
31922
32205
|
pipeline: [
|
|
31923
32206
|
{
|
|
31924
32207
|
$match: {
|
|
31925
|
-
$expr: {
|
|
32208
|
+
$expr: {
|
|
32209
|
+
$and: [
|
|
32210
|
+
{ $eq: ["$org", "$$spOrgId"] },
|
|
32211
|
+
{ $eq: ["$siteId", "$$spSiteId"] }
|
|
32212
|
+
]
|
|
32213
|
+
},
|
|
31926
32214
|
status: "active"
|
|
31927
32215
|
}
|
|
31928
32216
|
},
|
|
@@ -31945,6 +32233,7 @@ function useServiceProviderRepo() {
|
|
|
31945
32233
|
}
|
|
31946
32234
|
},
|
|
31947
32235
|
nature: "$organization.nature",
|
|
32236
|
+
contact: { $ifNull: ["$organization.contact", ""] },
|
|
31948
32237
|
orgId: 1,
|
|
31949
32238
|
siteId: 1,
|
|
31950
32239
|
siteName: 1,
|
|
@@ -32194,6 +32483,104 @@ function useServiceProviderRepo() {
|
|
|
32194
32483
|
throw error;
|
|
32195
32484
|
}
|
|
32196
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
|
+
}
|
|
32197
32584
|
return {
|
|
32198
32585
|
createTextIndex,
|
|
32199
32586
|
createUniqueIndex,
|
|
@@ -32204,7 +32591,9 @@ function useServiceProviderRepo() {
|
|
|
32204
32591
|
getServiceProviderById,
|
|
32205
32592
|
getByServiceProviderOrgIdType,
|
|
32206
32593
|
getByEmail,
|
|
32207
|
-
updateStatusById
|
|
32594
|
+
updateStatusById,
|
|
32595
|
+
getEngagedProvidersBySite,
|
|
32596
|
+
getSiteProviderKeys
|
|
32208
32597
|
};
|
|
32209
32598
|
}
|
|
32210
32599
|
|
|
@@ -32922,12 +33311,15 @@ import { BadRequestError as BadRequestError86, logger as logger62 } from "@7365a
|
|
|
32922
33311
|
// src/services/service-provider.service.ts
|
|
32923
33312
|
import {
|
|
32924
33313
|
BadRequestError as BadRequestError85,
|
|
33314
|
+
paginate as paginate25,
|
|
32925
33315
|
useAtlas as useAtlas53
|
|
32926
33316
|
} from "@7365admin1/node-server-utils";
|
|
32927
33317
|
function useServiceProviderService() {
|
|
32928
33318
|
const {
|
|
32929
33319
|
createServiceProvider: _createServiceProvider,
|
|
32930
|
-
getServiceProviders: _getServiceProviders
|
|
33320
|
+
getServiceProviders: _getServiceProviders,
|
|
33321
|
+
getEngagedProvidersBySite: _getEngaged,
|
|
33322
|
+
getSiteProviderKeys: _getSiteProviderKeys
|
|
32931
33323
|
} = useServiceProviderRepo();
|
|
32932
33324
|
const { getById: getOrgById, getByEmail: getOrgByEmail } = useOrgRepo();
|
|
32933
33325
|
const { getSiteById } = useSiteRepo();
|
|
@@ -33007,9 +33399,40 @@ function useServiceProviderService() {
|
|
|
33007
33399
|
status
|
|
33008
33400
|
});
|
|
33009
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
|
+
}
|
|
33010
33432
|
return {
|
|
33011
33433
|
createServiceProvider,
|
|
33012
|
-
getServiceProviders
|
|
33434
|
+
getServiceProviders,
|
|
33435
|
+
getServiceProvidersForSite
|
|
33013
33436
|
};
|
|
33014
33437
|
}
|
|
33015
33438
|
|
|
@@ -33024,7 +33447,18 @@ function useServiceProviderController() {
|
|
|
33024
33447
|
getByEmail: _getByEmail,
|
|
33025
33448
|
updateStatusById: _updateStatusById
|
|
33026
33449
|
} = useServiceProviderRepo();
|
|
33027
|
-
const {
|
|
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
|
+
}
|
|
33028
33462
|
const { createServiceProvider: _add } = useServiceProviderRepo();
|
|
33029
33463
|
async function createServiceProvider(req, res, next) {
|
|
33030
33464
|
const validation = Joi46.string().hex().required();
|
|
@@ -33053,7 +33487,12 @@ function useServiceProviderController() {
|
|
|
33053
33487
|
orgId: Joi46.string().hex().optional().allow("", null),
|
|
33054
33488
|
siteId: Joi46.string().hex().optional().allow("", null),
|
|
33055
33489
|
serviceProviderOrgId: Joi46.string().hex().optional().allow("", null),
|
|
33056
|
-
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)
|
|
33057
33496
|
});
|
|
33058
33497
|
const query2 = { ...req.query };
|
|
33059
33498
|
const { error } = validation.validate(query2);
|
|
@@ -33070,7 +33509,9 @@ function useServiceProviderController() {
|
|
|
33070
33509
|
const serviceProviderOrgId = req.query.serviceProviderOrgId ?? "";
|
|
33071
33510
|
const status = req.query.status ?? "active";
|
|
33072
33511
|
try {
|
|
33073
|
-
|
|
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({
|
|
33074
33515
|
search,
|
|
33075
33516
|
page,
|
|
33076
33517
|
limit,
|
|
@@ -33347,7 +33788,7 @@ import {
|
|
|
33347
33788
|
useAtlas as useAtlas54,
|
|
33348
33789
|
InternalServerError as InternalServerError35,
|
|
33349
33790
|
BadRequestError as BadRequestError88,
|
|
33350
|
-
paginate as
|
|
33791
|
+
paginate as paginate26,
|
|
33351
33792
|
NotFoundError as NotFoundError25,
|
|
33352
33793
|
useCache as useCache30,
|
|
33353
33794
|
logger as logger64,
|
|
@@ -33458,7 +33899,7 @@ function useCustomerRepo() {
|
|
|
33458
33899
|
{ session }
|
|
33459
33900
|
).toArray();
|
|
33460
33901
|
const length = await collection.countDocuments(query2, { session });
|
|
33461
|
-
const data =
|
|
33902
|
+
const data = paginate26(items, page, limit, length);
|
|
33462
33903
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
33463
33904
|
logger64.info(`Cache set for key: ${cacheKey}`);
|
|
33464
33905
|
}).catch((err) => {
|
|
@@ -33818,7 +34259,7 @@ import {
|
|
|
33818
34259
|
InternalServerError as InternalServerError36,
|
|
33819
34260
|
logger as logger67,
|
|
33820
34261
|
makeCacheKey as makeCacheKey27,
|
|
33821
|
-
paginate as
|
|
34262
|
+
paginate as paginate27,
|
|
33822
34263
|
toObjectId as toObjectId12,
|
|
33823
34264
|
useAtlas as useAtlas56,
|
|
33824
34265
|
useCache as useCache31
|
|
@@ -34354,7 +34795,7 @@ function useBuildingUnitRepo() {
|
|
|
34354
34795
|
).toArray();
|
|
34355
34796
|
const total = await collection.aggregate([...pipeline, { $count: "length" }]).toArray();
|
|
34356
34797
|
const length = total[0]?.length ?? 0;
|
|
34357
|
-
const data =
|
|
34798
|
+
const data = paginate27(items, page, limit, length);
|
|
34358
34799
|
setCache(cacheKey, data, 600).then(() => {
|
|
34359
34800
|
logger67.log({
|
|
34360
34801
|
level: "info",
|
|
@@ -34453,7 +34894,7 @@ function useBuildingUnitRepo() {
|
|
|
34453
34894
|
search ? {} : { collation: { locale: "en", numericOrdering: true } }
|
|
34454
34895
|
).toArray();
|
|
34455
34896
|
const length = await collection.countDocuments(query2);
|
|
34456
|
-
const data =
|
|
34897
|
+
const data = paginate27(items, page, limit, length);
|
|
34457
34898
|
setCache(cacheKey, data, 600).then(() => {
|
|
34458
34899
|
logger67.log({
|
|
34459
34900
|
level: "info",
|
|
@@ -37771,7 +38212,7 @@ import {
|
|
|
37771
38212
|
InternalServerError as InternalServerError38,
|
|
37772
38213
|
logger as logger74,
|
|
37773
38214
|
makeCacheKey as makeCacheKey28,
|
|
37774
|
-
paginate as
|
|
38215
|
+
paginate as paginate28,
|
|
37775
38216
|
useAtlas as useAtlas61,
|
|
37776
38217
|
useCache as useCache33
|
|
37777
38218
|
} from "@7365admin1/node-server-utils";
|
|
@@ -38062,7 +38503,7 @@ function useBuildingRepo() {
|
|
|
38062
38503
|
searchText ? {} : { collation: { locale: "en", numericOrdering: true } }
|
|
38063
38504
|
).toArray();
|
|
38064
38505
|
const length = await collection.countDocuments(query2);
|
|
38065
|
-
const data =
|
|
38506
|
+
const data = paginate28(items, page, limit, length);
|
|
38066
38507
|
setCache(cacheKey, data, 600).then(() => {
|
|
38067
38508
|
logger74.log({
|
|
38068
38509
|
level: "info",
|
|
@@ -38134,7 +38575,7 @@ function useBuildingRepo() {
|
|
|
38134
38575
|
]).toArray();
|
|
38135
38576
|
const countResult = await collection.aggregate([...basePipeline, { $count: "total" }]).toArray();
|
|
38136
38577
|
const length = countResult[0]?.total ?? 0;
|
|
38137
|
-
return
|
|
38578
|
+
return paginate28(items, page, limit, length);
|
|
38138
38579
|
} catch (error) {
|
|
38139
38580
|
logger74.log({ level: "error", message: `${error}` });
|
|
38140
38581
|
throw error;
|
|
@@ -38516,7 +38957,7 @@ import {
|
|
|
38516
38957
|
InternalServerError as InternalServerError39,
|
|
38517
38958
|
logger as logger76,
|
|
38518
38959
|
makeCacheKey as makeCacheKey29,
|
|
38519
|
-
paginate as
|
|
38960
|
+
paginate as paginate29,
|
|
38520
38961
|
toObjectId as toObjectId14,
|
|
38521
38962
|
useAtlas as useAtlas62,
|
|
38522
38963
|
useCache as useCache34
|
|
@@ -38752,7 +39193,7 @@ function useBuildingLevelRepo() {
|
|
|
38752
39193
|
search ? {} : { collation: { locale: "en", numericOrdering: true } }
|
|
38753
39194
|
).toArray();
|
|
38754
39195
|
const length = await collection.countDocuments(query2);
|
|
38755
|
-
const data =
|
|
39196
|
+
const data = paginate29(items, page, limit, length);
|
|
38756
39197
|
setCache(cacheKey, data, 600).then(() => {
|
|
38757
39198
|
logger76.log({
|
|
38758
39199
|
level: "info",
|
|
@@ -42689,7 +43130,7 @@ function useCustomerSiteController() {
|
|
|
42689
43130
|
}
|
|
42690
43131
|
}
|
|
42691
43132
|
async function getAll(req, res, next) {
|
|
42692
|
-
const allowedFields = ["createdAt", "name"];
|
|
43133
|
+
const allowedFields = ["createdAt", "name", "siteOrgName"];
|
|
42693
43134
|
const allowedOrder = ["asc", "desc"];
|
|
42694
43135
|
const validation = Joi61.object({
|
|
42695
43136
|
search: Joi61.string().optional().allow("", null),
|
|
@@ -42698,7 +43139,13 @@ function useCustomerSiteController() {
|
|
|
42698
43139
|
sort: Joi61.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
|
|
42699
43140
|
order: Joi61.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
|
|
42700
43141
|
org: Joi61.string().hex().required(),
|
|
42701
|
-
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)
|
|
42702
43149
|
});
|
|
42703
43150
|
const query2 = { ...req.query };
|
|
42704
43151
|
const { error } = validation.validate(query2);
|
|
@@ -42712,6 +43159,9 @@ function useCustomerSiteController() {
|
|
|
42712
43159
|
const limit = parseInt(req.query.limit ?? "10");
|
|
42713
43160
|
const org = req.query.org ?? "";
|
|
42714
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 || "";
|
|
42715
43165
|
const sortObj = {};
|
|
42716
43166
|
const sortFields = String(req.query.sort).split(",");
|
|
42717
43167
|
const sortOrders = String(req.query.order).split(",");
|
|
@@ -42731,7 +43181,10 @@ function useCustomerSiteController() {
|
|
|
42731
43181
|
sort: sortObj,
|
|
42732
43182
|
org,
|
|
42733
43183
|
status,
|
|
42734
|
-
siteScope
|
|
43184
|
+
siteScope,
|
|
43185
|
+
relationship,
|
|
43186
|
+
client,
|
|
43187
|
+
category
|
|
42735
43188
|
});
|
|
42736
43189
|
res.json(data);
|
|
42737
43190
|
return;
|
|
@@ -43189,7 +43642,7 @@ import moment4 from "moment-timezone";
|
|
|
43189
43642
|
import {
|
|
43190
43643
|
useAtlas as useAtlas68,
|
|
43191
43644
|
InternalServerError as InternalServerError41,
|
|
43192
|
-
paginate as
|
|
43645
|
+
paginate as paginate30,
|
|
43193
43646
|
BadRequestError as BadRequestError114,
|
|
43194
43647
|
useCache as useCache36,
|
|
43195
43648
|
logger as logger89,
|
|
@@ -43351,7 +43804,7 @@ function useAttendanceRepository() {
|
|
|
43351
43804
|
} else {
|
|
43352
43805
|
length = await collection.countDocuments(query2);
|
|
43353
43806
|
}
|
|
43354
|
-
const data =
|
|
43807
|
+
const data = paginate30(items, page, limit, length);
|
|
43355
43808
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
43356
43809
|
logger89.info(`Cache set for key: ${cacheKey}`);
|
|
43357
43810
|
}).catch((err) => {
|
|
@@ -43487,7 +43940,7 @@ function useAttendanceRepository() {
|
|
|
43487
43940
|
} else {
|
|
43488
43941
|
length = await collection.countDocuments(query2);
|
|
43489
43942
|
}
|
|
43490
|
-
const data =
|
|
43943
|
+
const data = paginate30(items, page, limit, length);
|
|
43491
43944
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
43492
43945
|
logger89.info(`Cache set for key: ${cacheKey}`);
|
|
43493
43946
|
}).catch((err) => {
|
|
@@ -44763,7 +45216,7 @@ function usePersonService() {
|
|
|
44763
45216
|
let set = {};
|
|
44764
45217
|
const cleanInput = (str) => str.replace(/\s+/g, "");
|
|
44765
45218
|
const cleanPhone = (str) => str.replace(/\D/g, "");
|
|
44766
|
-
const
|
|
45219
|
+
const escapeRegex3 = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
44767
45220
|
const nric = value.nric ? cleanInput(value.nric) : "";
|
|
44768
45221
|
const name = value.name?.trim();
|
|
44769
45222
|
const contact = value.contact?.trim();
|
|
@@ -44771,8 +45224,8 @@ function usePersonService() {
|
|
|
44771
45224
|
const email = value.email?.trim();
|
|
44772
45225
|
const type = value.type?.trim();
|
|
44773
45226
|
const company = value.company?.trim();
|
|
44774
|
-
const nricQuery = nric ? { nric: { $regex: `^${
|
|
44775
|
-
const nameQuery = name ? { name: { $regex: `^${
|
|
45227
|
+
const nricQuery = nric ? { nric: { $regex: `^${escapeRegex3(nric)}$`, $options: "i" } } : null;
|
|
45228
|
+
const nameQuery = name ? { name: { $regex: `^${escapeRegex3(name)}$`, $options: "i" } } : null;
|
|
44776
45229
|
let nricCondition = null;
|
|
44777
45230
|
if (nric) {
|
|
44778
45231
|
if (nric.length < 9) {
|
|
@@ -44785,8 +45238,8 @@ function usePersonService() {
|
|
|
44785
45238
|
}
|
|
44786
45239
|
const orConditions = [
|
|
44787
45240
|
...nricCondition ? [nricCondition] : [],
|
|
44788
|
-
...contact ? [{ contacts: { $regex: `^\\+?${cleanPhone(
|
|
44789
|
-
...plateNumber ? [{ plateNumbers: { $regex: `^${
|
|
45241
|
+
...contact ? [{ contacts: { $regex: `^\\+?${cleanPhone(escapeRegex3(contact))}$`, $options: "i" } }] : [],
|
|
45242
|
+
...plateNumber ? [{ plateNumbers: { $regex: `^${escapeRegex3(plateNumber)}$`, $options: "i" } }] : []
|
|
44790
45243
|
];
|
|
44791
45244
|
const existingPerson2 = await findFirstTen(
|
|
44792
45245
|
{
|
|
@@ -45852,7 +46305,7 @@ import {
|
|
|
45852
46305
|
BadRequestError as BadRequestError122,
|
|
45853
46306
|
InternalServerError as InternalServerError44,
|
|
45854
46307
|
logger as logger94,
|
|
45855
|
-
paginate as
|
|
46308
|
+
paginate as paginate31,
|
|
45856
46309
|
useAtlas as useAtlas72
|
|
45857
46310
|
} from "@7365admin1/node-server-utils";
|
|
45858
46311
|
import { ObjectId as ObjectId95 } from "mongodb";
|
|
@@ -46685,7 +47138,7 @@ function useHidAmicoRepo() {
|
|
|
46685
47138
|
passwordSet: Boolean(password)
|
|
46686
47139
|
};
|
|
46687
47140
|
}
|
|
46688
|
-
function
|
|
47141
|
+
function escapeRegex3(value) {
|
|
46689
47142
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
46690
47143
|
}
|
|
46691
47144
|
function buildIdentityKeyQuery(value) {
|
|
@@ -46761,7 +47214,7 @@ function useHidAmicoRepo() {
|
|
|
46761
47214
|
}
|
|
46762
47215
|
const items = await readers().find(query2).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
|
|
46763
47216
|
const total = await readers().countDocuments(query2);
|
|
46764
|
-
return
|
|
47217
|
+
return paginate31(items.map(hideSecret), page, limit, total);
|
|
46765
47218
|
}
|
|
46766
47219
|
async function getById(id, options = {}) {
|
|
46767
47220
|
const _id = toId4(id, "reader ID");
|
|
@@ -46851,7 +47304,7 @@ function useHidAmicoRepo() {
|
|
|
46851
47304
|
}
|
|
46852
47305
|
const items = await events().find(query2).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
|
|
46853
47306
|
const total = await events().countDocuments(query2);
|
|
46854
|
-
return
|
|
47307
|
+
return paginate31(items, page, limit, total);
|
|
46855
47308
|
}
|
|
46856
47309
|
async function addIdentity(value, session) {
|
|
46857
47310
|
try {
|
|
@@ -46888,7 +47341,7 @@ function useHidAmicoRepo() {
|
|
|
46888
47341
|
query2.type = value.type;
|
|
46889
47342
|
}
|
|
46890
47343
|
if (value.search) {
|
|
46891
|
-
const search =
|
|
47344
|
+
const search = escapeRegex3(value.search);
|
|
46892
47345
|
query2.$or = [
|
|
46893
47346
|
{ hidUserId: { $regex: search, $options: "i" } },
|
|
46894
47347
|
{ registration: { $regex: search, $options: "i" } },
|
|
@@ -46897,7 +47350,7 @@ function useHidAmicoRepo() {
|
|
|
46897
47350
|
}
|
|
46898
47351
|
const items = await identities().find(query2).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
|
|
46899
47352
|
const total = await identities().countDocuments(query2);
|
|
46900
|
-
return
|
|
47353
|
+
return paginate31(items, page, limit, total);
|
|
46901
47354
|
}
|
|
46902
47355
|
async function getIdentityById(id) {
|
|
46903
47356
|
const identity = await identities().findOne({
|
|
@@ -47129,7 +47582,7 @@ function useHidAmicoRepo() {
|
|
|
47129
47582
|
const text2 = search.trim();
|
|
47130
47583
|
if (!text2)
|
|
47131
47584
|
return {};
|
|
47132
|
-
const pattern = { $regex:
|
|
47585
|
+
const pattern = { $regex: escapeRegex3(text2), $options: "i" };
|
|
47133
47586
|
return {
|
|
47134
47587
|
$or: [
|
|
47135
47588
|
{ name: pattern },
|
|
@@ -47486,7 +47939,7 @@ function useHidAmicoRepo() {
|
|
|
47486
47939
|
intercom: Boolean(selected?.intercom)
|
|
47487
47940
|
};
|
|
47488
47941
|
});
|
|
47489
|
-
return
|
|
47942
|
+
return paginate31(items, page - 1, limit, total);
|
|
47490
47943
|
}
|
|
47491
47944
|
async function enqueueGatewayJob(value) {
|
|
47492
47945
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -53511,7 +53964,7 @@ var schemaGuardInviteVisitor = Joi69.object({
|
|
|
53511
53964
|
// src/repositories/access-management.repo.ts
|
|
53512
53965
|
import {
|
|
53513
53966
|
InternalServerError as InternalServerError46,
|
|
53514
|
-
paginate as
|
|
53967
|
+
paginate as paginate32,
|
|
53515
53968
|
useAtlas as useAtlas74
|
|
53516
53969
|
} from "@7365admin1/node-server-utils";
|
|
53517
53970
|
import { ObjectId as ObjectId98 } from "mongodb";
|
|
@@ -54725,7 +55178,7 @@ function UseAccessManagementRepo() {
|
|
|
54725
55178
|
).toArray();
|
|
54726
55179
|
const totalCount = result[0]?.totalCount?.[0]?.count ?? 0;
|
|
54727
55180
|
const items = result[0]?.items ?? [];
|
|
54728
|
-
const paginatedResult =
|
|
55181
|
+
const paginatedResult = paginate32(items, page, limit, totalCount);
|
|
54729
55182
|
return paginatedResult;
|
|
54730
55183
|
} catch (error) {
|
|
54731
55184
|
throw new Error(error.message);
|
|
@@ -54928,7 +55381,7 @@ function UseAccessManagementRepo() {
|
|
|
54928
55381
|
).toArray();
|
|
54929
55382
|
const totalCount = result[0]?.totalCount?.[0]?.count ?? 0;
|
|
54930
55383
|
const items = result[0]?.items ?? [];
|
|
54931
|
-
const paginatedResult =
|
|
55384
|
+
const paginatedResult = paginate32(items, page, limit, totalCount);
|
|
54932
55385
|
return paginatedResult;
|
|
54933
55386
|
} catch (error) {
|
|
54934
55387
|
throw new Error(error.message);
|
|
@@ -55115,7 +55568,7 @@ function UseAccessManagementRepo() {
|
|
|
55115
55568
|
).toArray();
|
|
55116
55569
|
const totalCount = result[0]?.totalCount?.[0]?.count ?? 0;
|
|
55117
55570
|
const items = result[0]?.items ?? [];
|
|
55118
|
-
const paginatedResult =
|
|
55571
|
+
const paginatedResult = paginate32(items, page, limit, totalCount);
|
|
55119
55572
|
return paginatedResult;
|
|
55120
55573
|
} catch (error) {
|
|
55121
55574
|
throw new Error(error.message);
|
|
@@ -55542,7 +55995,7 @@ function UseAccessManagementRepo() {
|
|
|
55542
55995
|
]).toArray();
|
|
55543
55996
|
const length = res[0].totalCount[0] ? res[0].totalCount[0].count : 0;
|
|
55544
55997
|
const items = res[0].items;
|
|
55545
|
-
const paginatedResult =
|
|
55998
|
+
const paginatedResult = paginate32(items, page, limit, length);
|
|
55546
55999
|
return paginatedResult;
|
|
55547
56000
|
} catch (error) {
|
|
55548
56001
|
throw new Error(error.message);
|
|
@@ -55713,7 +56166,7 @@ function UseAccessManagementRepo() {
|
|
|
55713
56166
|
{ allowDiskUse: true }
|
|
55714
56167
|
).toArray();
|
|
55715
56168
|
const count = res[0]?.totalCount[0] ? res[0].totalCount[0].count : 0;
|
|
55716
|
-
const pagination =
|
|
56169
|
+
const pagination = paginate32(res[0].data, page, limit, count);
|
|
55717
56170
|
return pagination;
|
|
55718
56171
|
} catch (error) {
|
|
55719
56172
|
throw new Error(error.message);
|
|
@@ -56142,7 +56595,7 @@ function UseAccessManagementRepo() {
|
|
|
56142
56595
|
}
|
|
56143
56596
|
]).toArray();
|
|
56144
56597
|
const count = res[0]?.totalCounts[0] ? res[0].totalCounts[0].count : 0;
|
|
56145
|
-
const paginated =
|
|
56598
|
+
const paginated = paginate32(res[0].items, page, limit, count);
|
|
56146
56599
|
return [paginated, unit[0], { count }];
|
|
56147
56600
|
} catch (error) {
|
|
56148
56601
|
throw new Error(error.message);
|
|
@@ -56616,7 +57069,7 @@ function UseAccessManagementRepo() {
|
|
|
56616
57069
|
]).toArray();
|
|
56617
57070
|
const length = result[0].totalCount[0] ? result[0].totalCount[0].count : 0;
|
|
56618
57071
|
const items = result[0].items;
|
|
56619
|
-
return
|
|
57072
|
+
return paginate32(items, page, limit, length);
|
|
56620
57073
|
} catch (error) {
|
|
56621
57074
|
throw new Error(error.message);
|
|
56622
57075
|
}
|
|
@@ -58444,7 +58897,7 @@ import {
|
|
|
58444
58897
|
InternalServerError as InternalServerError48,
|
|
58445
58898
|
logger as logger100,
|
|
58446
58899
|
makeCacheKey as makeCacheKey34,
|
|
58447
|
-
paginate as
|
|
58900
|
+
paginate as paginate33,
|
|
58448
58901
|
useAtlas as useAtlas75,
|
|
58449
58902
|
useCache as useCache39
|
|
58450
58903
|
} from "@7365admin1/node-server-utils";
|
|
@@ -58553,7 +59006,7 @@ function useGuestManagementRepo() {
|
|
|
58553
59006
|
collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
|
|
58554
59007
|
]);
|
|
58555
59008
|
const totalCount = countResult[0]?.total || 0;
|
|
58556
|
-
const data =
|
|
59009
|
+
const data = paginate33(items, page, limit, totalCount);
|
|
58557
59010
|
setCache(cacheKey, data, 15 * 60).then(() => logger100.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
58558
59011
|
(err) => logger100.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
58559
59012
|
);
|
|
@@ -59504,7 +59957,7 @@ import { ObjectId as ObjectId104 } from "mongodb";
|
|
|
59504
59957
|
import {
|
|
59505
59958
|
useAtlas as useAtlas77,
|
|
59506
59959
|
InternalServerError as InternalServerError49,
|
|
59507
|
-
paginate as
|
|
59960
|
+
paginate as paginate34,
|
|
59508
59961
|
BadRequestError as BadRequestError131,
|
|
59509
59962
|
NotFoundError as NotFoundError42,
|
|
59510
59963
|
useCache as useCache40,
|
|
@@ -59528,7 +59981,7 @@ var NETWORK_SORTS = {
|
|
|
59528
59981
|
};
|
|
59529
59982
|
var NETWORK_OFFLINE_CODE = "OFFLINE";
|
|
59530
59983
|
var ROBOT_FAULTS_COLLECTION = "robot-faults";
|
|
59531
|
-
function
|
|
59984
|
+
function escapeRegex2(value) {
|
|
59532
59985
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
59533
59986
|
}
|
|
59534
59987
|
function matchDefaulted(field, value, fallback) {
|
|
@@ -59632,7 +60085,7 @@ function networkListPipeline(q) {
|
|
|
59632
60085
|
pipeline.push({ $match: { offline: true } });
|
|
59633
60086
|
const search = (q.search ?? "").trim();
|
|
59634
60087
|
if (search) {
|
|
59635
|
-
const rx = { $regex:
|
|
60088
|
+
const rx = { $regex: escapeRegex2(search), $options: "i" };
|
|
59636
60089
|
pipeline.push({
|
|
59637
60090
|
$match: { $or: [{ name: rx }, { robotSn: rx }, { "client.name": rx }, { "site.name": rx }] }
|
|
59638
60091
|
});
|
|
@@ -59995,7 +60448,7 @@ function useRobotRepo() {
|
|
|
59995
60448
|
}
|
|
59996
60449
|
]).toArray();
|
|
59997
60450
|
const length = await collection.countDocuments(query2);
|
|
59998
|
-
const data =
|
|
60451
|
+
const data = paginate34(items, page, limit, length);
|
|
59999
60452
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
60000
60453
|
logger104.info(`Cache set for key: ${cacheKey}`);
|
|
60001
60454
|
}).catch((err) => {
|
|
@@ -60070,7 +60523,7 @@ function useRobotRepo() {
|
|
|
60070
60523
|
const limit = Math.min(100, Math.max(1, Math.floor(q.limit || 10)));
|
|
60071
60524
|
const [res] = await collection.aggregate(networkListPipeline({ ...q, page, limit })).toArray();
|
|
60072
60525
|
const total = res?.total?.[0]?.n ?? 0;
|
|
60073
|
-
return { ...
|
|
60526
|
+
return { ...paginate34(res?.items ?? [], page - 1, limit, total), total };
|
|
60074
60527
|
}
|
|
60075
60528
|
async function getSiteNames(site) {
|
|
60076
60529
|
if (!ObjectId104.isValid(site))
|
|
@@ -63668,7 +64121,7 @@ import { ObjectId as ObjectId107 } from "mongodb";
|
|
|
63668
64121
|
import {
|
|
63669
64122
|
useAtlas as useAtlas79,
|
|
63670
64123
|
InternalServerError as InternalServerError51,
|
|
63671
|
-
paginate as
|
|
64124
|
+
paginate as paginate35,
|
|
63672
64125
|
BadRequestError as BadRequestError136,
|
|
63673
64126
|
NotFoundError as NotFoundError44,
|
|
63674
64127
|
AppError as AppError21
|
|
@@ -63734,7 +64187,7 @@ function useRobotBuildingMapRepo() {
|
|
|
63734
64187
|
}
|
|
63735
64188
|
]).toArray();
|
|
63736
64189
|
const length = await collection.countDocuments(query2);
|
|
63737
|
-
return
|
|
64190
|
+
return paginate35(items, page > 0 ? page - 1 : 0, limit, length);
|
|
63738
64191
|
}
|
|
63739
64192
|
async function getMapById(id) {
|
|
63740
64193
|
const map = await collection.findOne({ _id: toObjectId16(id, "map"), ...NOT_DELETED2 });
|
|
@@ -64778,7 +65231,7 @@ import {
|
|
|
64778
65231
|
InternalServerError as InternalServerError52,
|
|
64779
65232
|
logger as logger112,
|
|
64780
65233
|
makeCacheKey as makeCacheKey36,
|
|
64781
|
-
paginate as
|
|
65234
|
+
paginate as paginate36,
|
|
64782
65235
|
useAtlas as useAtlas80,
|
|
64783
65236
|
useCache as useCache41
|
|
64784
65237
|
} from "@7365admin1/node-server-utils";
|
|
@@ -64890,7 +65343,7 @@ function usePatrolQuestionRepo() {
|
|
|
64890
65343
|
collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
|
|
64891
65344
|
]);
|
|
64892
65345
|
const totalCount = countResult[0]?.total || 0;
|
|
64893
|
-
const data =
|
|
65346
|
+
const data = paginate36(items, page, limit, totalCount);
|
|
64894
65347
|
setCache(cacheKey, data, 15 * 60).then(() => logger112.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
64895
65348
|
(err) => logger112.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
64896
65349
|
);
|
|
@@ -65243,7 +65696,7 @@ import {
|
|
|
65243
65696
|
InternalServerError as InternalServerError53,
|
|
65244
65697
|
logger as logger115,
|
|
65245
65698
|
makeCacheKey as makeCacheKey37,
|
|
65246
|
-
paginate as
|
|
65699
|
+
paginate as paginate37,
|
|
65247
65700
|
useAtlas as useAtlas81,
|
|
65248
65701
|
useCache as useCache42
|
|
65249
65702
|
} from "@7365admin1/node-server-utils";
|
|
@@ -65406,7 +65859,7 @@ function usePatrolRouteRepo() {
|
|
|
65406
65859
|
collection.aggregate([...countPipeline, { $count: "total" }], { session }).toArray()
|
|
65407
65860
|
]);
|
|
65408
65861
|
const totalCount = countResult[0]?.total || 0;
|
|
65409
|
-
const data =
|
|
65862
|
+
const data = paginate37(items, page, limit, totalCount);
|
|
65410
65863
|
setCache(cacheKey, data, 15 * 60).then(() => logger115.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
65411
65864
|
(err) => logger115.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
65412
65865
|
);
|
|
@@ -65614,7 +66067,7 @@ function usePatrolRouteRepo() {
|
|
|
65614
66067
|
const items = await collection.aggregate(basePipeline, { session }).toArray();
|
|
65615
66068
|
const countResult = await collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray();
|
|
65616
66069
|
const totalCount = countResult[0]?.total || 0;
|
|
65617
|
-
const data =
|
|
66070
|
+
const data = paginate37(items, page, limit, totalCount);
|
|
65618
66071
|
setCache(cacheKey, data, 15 * 60).then(() => logger115.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
65619
66072
|
(err) => logger115.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
65620
66073
|
);
|
|
@@ -66023,7 +66476,7 @@ import {
|
|
|
66023
66476
|
InternalServerError as InternalServerError54,
|
|
66024
66477
|
logger as logger118,
|
|
66025
66478
|
makeCacheKey as makeCacheKey38,
|
|
66026
|
-
paginate as
|
|
66479
|
+
paginate as paginate38,
|
|
66027
66480
|
useAtlas as useAtlas82,
|
|
66028
66481
|
useCache as useCache43
|
|
66029
66482
|
} from "@7365admin1/node-server-utils";
|
|
@@ -66311,7 +66764,7 @@ function usePatrolLogRepo() {
|
|
|
66311
66764
|
collection.aggregate([...countPipeline, { $count: "total" }], { session }).toArray()
|
|
66312
66765
|
]);
|
|
66313
66766
|
const totalCount = countResult[0]?.total || 0;
|
|
66314
|
-
const data =
|
|
66767
|
+
const data = paginate38(items, page, limit, totalCount);
|
|
66315
66768
|
setCache(cacheKey, data, 15 * 60).then(() => logger118.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
66316
66769
|
(err) => logger118.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
66317
66770
|
);
|
|
@@ -66821,7 +67274,7 @@ import {
|
|
|
66821
67274
|
InternalServerError as InternalServerError55,
|
|
66822
67275
|
logger as logger121,
|
|
66823
67276
|
NotFoundError as NotFoundError49,
|
|
66824
|
-
paginate as
|
|
67277
|
+
paginate as paginate39,
|
|
66825
67278
|
useAtlas as useAtlas84
|
|
66826
67279
|
} from "@7365admin1/node-server-utils";
|
|
66827
67280
|
import { ObjectId as ObjectId115 } from "mongodb";
|
|
@@ -66839,7 +67292,7 @@ function usePatrolEmailRepo() {
|
|
|
66839
67292
|
throw new BadRequestError151(`Invalid ${label2} format.`);
|
|
66840
67293
|
}
|
|
66841
67294
|
}
|
|
66842
|
-
function
|
|
67295
|
+
function escapeRegex3(value) {
|
|
66843
67296
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
66844
67297
|
}
|
|
66845
67298
|
async function createIndexes() {
|
|
@@ -66976,8 +67429,8 @@ function usePatrolEmailRepo() {
|
|
|
66976
67429
|
...status ? { status } : { status: { $ne: "deleted" } },
|
|
66977
67430
|
...search && {
|
|
66978
67431
|
$or: [
|
|
66979
|
-
{ subject: { $regex:
|
|
66980
|
-
{ recipients: { $regex:
|
|
67432
|
+
{ subject: { $regex: escapeRegex3(search), $options: "i" } },
|
|
67433
|
+
{ recipients: { $regex: escapeRegex3(search), $options: "i" } }
|
|
66981
67434
|
]
|
|
66982
67435
|
}
|
|
66983
67436
|
};
|
|
@@ -66986,7 +67439,7 @@ function usePatrolEmailRepo() {
|
|
|
66986
67439
|
collection.find(query2, { session }).sort({ createdAt: -1, _id: -1 }).skip(page * limit).limit(limit).toArray(),
|
|
66987
67440
|
collection.countDocuments(query2, { session })
|
|
66988
67441
|
]);
|
|
66989
|
-
return
|
|
67442
|
+
return paginate39(
|
|
66990
67443
|
await withResendState(items, session),
|
|
66991
67444
|
page,
|
|
66992
67445
|
limit,
|
|
@@ -67919,7 +68372,7 @@ import {
|
|
|
67919
68372
|
logger as logger125,
|
|
67920
68373
|
makeCacheKey as makeCacheKey39,
|
|
67921
68374
|
NotFoundError as NotFoundError51,
|
|
67922
|
-
paginate as
|
|
68375
|
+
paginate as paginate40,
|
|
67923
68376
|
useAtlas as useAtlas85,
|
|
67924
68377
|
useCache as useCache44
|
|
67925
68378
|
} from "@7365admin1/node-server-utils";
|
|
@@ -68023,7 +68476,7 @@ function useSiteFacilityRepo() {
|
|
|
68023
68476
|
{ session }
|
|
68024
68477
|
).toArray();
|
|
68025
68478
|
const length = await collection.countDocuments(query2, { session });
|
|
68026
|
-
const data =
|
|
68479
|
+
const data = paginate40(items, page, limit, length);
|
|
68027
68480
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
68028
68481
|
logger125.info(`Cache set for key: ${cacheKey}`);
|
|
68029
68482
|
}).catch((err) => {
|
|
@@ -68601,7 +69054,7 @@ import {
|
|
|
68601
69054
|
logger as logger127,
|
|
68602
69055
|
makeCacheKey as makeCacheKey40,
|
|
68603
69056
|
NotFoundError as NotFoundError53,
|
|
68604
|
-
paginate as
|
|
69057
|
+
paginate as paginate41,
|
|
68605
69058
|
useAtlas as useAtlas87,
|
|
68606
69059
|
useCache as useCache45
|
|
68607
69060
|
} from "@7365admin1/node-server-utils";
|
|
@@ -68689,7 +69142,7 @@ function useServiceProviderBillingRepo() {
|
|
|
68689
69142
|
{ session }
|
|
68690
69143
|
).toArray();
|
|
68691
69144
|
const length = await collection.countDocuments(query2, { session });
|
|
68692
|
-
const data =
|
|
69145
|
+
const data = paginate41(items, page, limit, length);
|
|
68693
69146
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
68694
69147
|
logger127.info(`Cache set for key: ${cacheKey}`);
|
|
68695
69148
|
}).catch((err) => {
|
|
@@ -69271,7 +69724,7 @@ import {
|
|
|
69271
69724
|
logger as logger129,
|
|
69272
69725
|
makeCacheKey as makeCacheKey41,
|
|
69273
69726
|
NotFoundError as NotFoundError54,
|
|
69274
|
-
paginate as
|
|
69727
|
+
paginate as paginate42,
|
|
69275
69728
|
toObjectId as toObjectId18,
|
|
69276
69729
|
useAtlas as useAtlas89,
|
|
69277
69730
|
useCache as useCache46
|
|
@@ -69362,7 +69815,7 @@ function useSiteFacilityBookingRepo() {
|
|
|
69362
69815
|
{ session }
|
|
69363
69816
|
).toArray();
|
|
69364
69817
|
const length = await collection.countDocuments(query2, { session });
|
|
69365
|
-
const data =
|
|
69818
|
+
const data = paginate42(items, page, limit, length);
|
|
69366
69819
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
69367
69820
|
logger129.info(`Cache set for key: ${cacheKey}`);
|
|
69368
69821
|
}).catch((err) => {
|
|
@@ -69840,7 +70293,7 @@ import {
|
|
|
69840
70293
|
logger as logger131,
|
|
69841
70294
|
makeCacheKey as makeCacheKey42,
|
|
69842
70295
|
NotFoundError as NotFoundError56,
|
|
69843
|
-
paginate as
|
|
70296
|
+
paginate as paginate43,
|
|
69844
70297
|
useAtlas as useAtlas91,
|
|
69845
70298
|
useCache as useCache47
|
|
69846
70299
|
} from "@7365admin1/node-server-utils";
|
|
@@ -69969,7 +70422,7 @@ function useDocumentManagementRepo() {
|
|
|
69969
70422
|
{ $limit: limit }
|
|
69970
70423
|
]).toArray();
|
|
69971
70424
|
const length = await collection.countDocuments(query2);
|
|
69972
|
-
const data =
|
|
70425
|
+
const data = paginate43(items, page, limit, length);
|
|
69973
70426
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
69974
70427
|
logger131.info(`Cache set for key: ${cacheKey}`);
|
|
69975
70428
|
}).catch((err) => {
|
|
@@ -70940,7 +71393,7 @@ import {
|
|
|
70940
71393
|
logger as logger134,
|
|
70941
71394
|
makeCacheKey as makeCacheKey43,
|
|
70942
71395
|
NotFoundError as NotFoundError58,
|
|
70943
|
-
paginate as
|
|
71396
|
+
paginate as paginate44,
|
|
70944
71397
|
useAtlas as useAtlas93,
|
|
70945
71398
|
useCache as useCache48
|
|
70946
71399
|
} from "@7365admin1/node-server-utils";
|
|
@@ -71047,7 +71500,7 @@ function useBulletinBoardRepo() {
|
|
|
71047
71500
|
{ session }
|
|
71048
71501
|
).toArray();
|
|
71049
71502
|
const length = await collection.countDocuments(query2, { session });
|
|
71050
|
-
const data =
|
|
71503
|
+
const data = paginate44(items, page, limit, length);
|
|
71051
71504
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
71052
71505
|
logger134.info(`Cache set for key: ${cacheKey}`);
|
|
71053
71506
|
}).catch((err) => {
|
|
@@ -71782,7 +72235,7 @@ import {
|
|
|
71782
72235
|
logger as logger137,
|
|
71783
72236
|
useAtlas as useAtlas95,
|
|
71784
72237
|
useCache as useCache49,
|
|
71785
|
-
paginate as
|
|
72238
|
+
paginate as paginate45,
|
|
71786
72239
|
makeCacheKey as makeCacheKey44
|
|
71787
72240
|
} from "@7365admin1/node-server-utils";
|
|
71788
72241
|
import { ObjectId as ObjectId129 } from "mongodb";
|
|
@@ -71894,7 +72347,7 @@ function useSiteBillingItemRepo() {
|
|
|
71894
72347
|
collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
|
|
71895
72348
|
]);
|
|
71896
72349
|
const totalCount = countResult[0]?.total || 0;
|
|
71897
|
-
const data =
|
|
72350
|
+
const data = paginate45(items, page, limit, totalCount);
|
|
71898
72351
|
setCache(cacheKey, data, 15 * 60).then(() => logger137.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
71899
72352
|
(err) => logger137.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
71900
72353
|
);
|
|
@@ -72043,7 +72496,7 @@ import {
|
|
|
72043
72496
|
logger as logger139,
|
|
72044
72497
|
useAtlas as useAtlas96,
|
|
72045
72498
|
useCache as useCache50,
|
|
72046
|
-
paginate as
|
|
72499
|
+
paginate as paginate46,
|
|
72047
72500
|
makeCacheKey as makeCacheKey45
|
|
72048
72501
|
} from "@7365admin1/node-server-utils";
|
|
72049
72502
|
|
|
@@ -72268,7 +72721,7 @@ function useSiteBillingConfigurationRepo() {
|
|
|
72268
72721
|
collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
|
|
72269
72722
|
]);
|
|
72270
72723
|
const totalCount = countResult[0]?.total || 0;
|
|
72271
|
-
const data =
|
|
72724
|
+
const data = paginate46(items, page, limit, totalCount);
|
|
72272
72725
|
setCache(cacheKey, data, 15 * 60).then(() => logger139.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
72273
72726
|
(err) => logger139.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
72274
72727
|
);
|
|
@@ -73035,7 +73488,7 @@ import {
|
|
|
73035
73488
|
logger as logger144,
|
|
73036
73489
|
makeCacheKey as makeCacheKey46,
|
|
73037
73490
|
NotFoundError as NotFoundError63,
|
|
73038
|
-
paginate as
|
|
73491
|
+
paginate as paginate47,
|
|
73039
73492
|
useAtlas as useAtlas99,
|
|
73040
73493
|
useCache as useCache51
|
|
73041
73494
|
} from "@7365admin1/node-server-utils";
|
|
@@ -73182,7 +73635,7 @@ function useEventManagementRepo() {
|
|
|
73182
73635
|
]).toArray();
|
|
73183
73636
|
length = await collection.countDocuments(regexQuery, { session });
|
|
73184
73637
|
}
|
|
73185
|
-
const data =
|
|
73638
|
+
const data = paginate47(items, page, limit, length);
|
|
73186
73639
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
73187
73640
|
logger144.info(`Cache set for key: ${cacheKey}`);
|
|
73188
73641
|
}).catch((err) => {
|
|
@@ -73759,7 +74212,7 @@ import {
|
|
|
73759
74212
|
logger as logger147,
|
|
73760
74213
|
useAtlas as useAtlas101,
|
|
73761
74214
|
useCache as useCache52,
|
|
73762
|
-
paginate as
|
|
74215
|
+
paginate as paginate48,
|
|
73763
74216
|
makeCacheKey as makeCacheKey47
|
|
73764
74217
|
} from "@7365admin1/node-server-utils";
|
|
73765
74218
|
import { ObjectId as ObjectId135 } from "mongodb";
|
|
@@ -73945,7 +74398,7 @@ function useSiteUnitBillingRepo() {
|
|
|
73945
74398
|
collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
|
|
73946
74399
|
]);
|
|
73947
74400
|
const totalCount = countResult[0]?.total || 0;
|
|
73948
|
-
const data =
|
|
74401
|
+
const data = paginate48(items, page, limit, totalCount);
|
|
73949
74402
|
setCache(cacheKey, data, 15 * 60).then(() => logger147.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
73950
74403
|
(err) => logger147.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
73951
74404
|
);
|
|
@@ -74209,7 +74662,7 @@ function useSiteUnitBillingRepo() {
|
|
|
74209
74662
|
collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
|
|
74210
74663
|
]);
|
|
74211
74664
|
const totalCount = countResult[0]?.total || 0;
|
|
74212
|
-
const data =
|
|
74665
|
+
const data = paginate48(items, page, limit, totalCount);
|
|
74213
74666
|
return data;
|
|
74214
74667
|
} catch (error) {
|
|
74215
74668
|
throw error;
|
|
@@ -74292,7 +74745,7 @@ function useSiteUnitBillingRepo() {
|
|
|
74292
74745
|
collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
|
|
74293
74746
|
]);
|
|
74294
74747
|
const totalCount = countResult[0]?.total || 0;
|
|
74295
|
-
const data =
|
|
74748
|
+
const data = paginate48(items, page, limit, totalCount);
|
|
74296
74749
|
return data;
|
|
74297
74750
|
} catch (error) {
|
|
74298
74751
|
throw error;
|
|
@@ -76354,7 +76807,7 @@ import {
|
|
|
76354
76807
|
logger as logger150,
|
|
76355
76808
|
makeCacheKey as makeCacheKey48,
|
|
76356
76809
|
NotFoundError as NotFoundError66,
|
|
76357
|
-
paginate as
|
|
76810
|
+
paginate as paginate49,
|
|
76358
76811
|
useAtlas as useAtlas104,
|
|
76359
76812
|
useCache as useCache53
|
|
76360
76813
|
} from "@7365admin1/node-server-utils";
|
|
@@ -76441,7 +76894,7 @@ function useNfcPatrolTagRepo() {
|
|
|
76441
76894
|
{ session }
|
|
76442
76895
|
).toArray();
|
|
76443
76896
|
const length = await collection.countDocuments(query2, { session });
|
|
76444
|
-
const data =
|
|
76897
|
+
const data = paginate49(items, page, limit, length);
|
|
76445
76898
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
76446
76899
|
logger150.info(`Cache set for key: ${cacheKey}`);
|
|
76447
76900
|
}).catch((err) => {
|
|
@@ -77154,7 +77607,7 @@ import {
|
|
|
77154
77607
|
logger as logger154,
|
|
77155
77608
|
makeCacheKey as makeCacheKey49,
|
|
77156
77609
|
NotFoundError as NotFoundError67,
|
|
77157
|
-
paginate as
|
|
77610
|
+
paginate as paginate50,
|
|
77158
77611
|
useAtlas as useAtlas106,
|
|
77159
77612
|
useCache as useCache54
|
|
77160
77613
|
} from "@7365admin1/node-server-utils";
|
|
@@ -77265,7 +77718,7 @@ function useBulletinVideoRepo() {
|
|
|
77265
77718
|
{ session }
|
|
77266
77719
|
).toArray();
|
|
77267
77720
|
const length = await collection.countDocuments(query2, { session });
|
|
77268
|
-
const data =
|
|
77721
|
+
const data = paginate50(items, page, limit, length);
|
|
77269
77722
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
77270
77723
|
logger154.info(`Cache set for key: ${cacheKey}`);
|
|
77271
77724
|
}).catch((err) => {
|
|
@@ -77759,7 +78212,7 @@ import {
|
|
|
77759
78212
|
logger as logger157,
|
|
77760
78213
|
useAtlas as useAtlas108,
|
|
77761
78214
|
useCache as useCache55,
|
|
77762
|
-
paginate as
|
|
78215
|
+
paginate as paginate51,
|
|
77763
78216
|
makeCacheKey as makeCacheKey50
|
|
77764
78217
|
} from "@7365admin1/node-server-utils";
|
|
77765
78218
|
import { ObjectId as ObjectId144 } from "mongodb";
|
|
@@ -77899,7 +78352,7 @@ function useStatementOfAccountRepo() {
|
|
|
77899
78352
|
collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
|
|
77900
78353
|
]);
|
|
77901
78354
|
const totalCount = countResult[0]?.total || 0;
|
|
77902
|
-
const data =
|
|
78355
|
+
const data = paginate51(items, page, limit, totalCount);
|
|
77903
78356
|
setCache(cacheKey, data, 15 * 60).then(() => logger157.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
77904
78357
|
(err) => logger157.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
77905
78358
|
);
|
|
@@ -78070,7 +78523,7 @@ function useStatementOfAccountRepo() {
|
|
|
78070
78523
|
collection.aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
|
|
78071
78524
|
]);
|
|
78072
78525
|
const totalCount = countResult[0]?.total || 0;
|
|
78073
|
-
const data =
|
|
78526
|
+
const data = paginate51(items, page, limit, totalCount);
|
|
78074
78527
|
return data;
|
|
78075
78528
|
} catch (error) {
|
|
78076
78529
|
throw error;
|
|
@@ -78773,7 +79226,7 @@ import {
|
|
|
78773
79226
|
logger as logger161,
|
|
78774
79227
|
makeCacheKey as makeCacheKey51,
|
|
78775
79228
|
NotFoundError as NotFoundError71,
|
|
78776
|
-
paginate as
|
|
79229
|
+
paginate as paginate52,
|
|
78777
79230
|
useAtlas as useAtlas110,
|
|
78778
79231
|
useCache as useCache56
|
|
78779
79232
|
} from "@7365admin1/node-server-utils";
|
|
@@ -78874,7 +79327,7 @@ function useEntryPassSettingsRepo() {
|
|
|
78874
79327
|
}
|
|
78875
79328
|
]).toArray();
|
|
78876
79329
|
const length = await collection.countDocuments(query2);
|
|
78877
|
-
const data =
|
|
79330
|
+
const data = paginate52(items, page, limit, length);
|
|
78878
79331
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
78879
79332
|
logger161.info(`Cache set for key: ${cacheKey}`);
|
|
78880
79333
|
}).catch((err) => {
|
|
@@ -79534,7 +79987,7 @@ import {
|
|
|
79534
79987
|
InternalServerError as InternalServerError70,
|
|
79535
79988
|
logger as logger166,
|
|
79536
79989
|
makeCacheKey as makeCacheKey53,
|
|
79537
|
-
paginate as
|
|
79990
|
+
paginate as paginate53,
|
|
79538
79991
|
useAtlas as useAtlas112,
|
|
79539
79992
|
useCache as useCache58
|
|
79540
79993
|
} from "@7365admin1/node-server-utils";
|
|
@@ -79643,7 +80096,7 @@ function useNfcPatrolRouteRepo() {
|
|
|
79643
80096
|
{ session }
|
|
79644
80097
|
).toArray();
|
|
79645
80098
|
const length = await collection.countDocuments(query2, { session });
|
|
79646
|
-
const data =
|
|
80099
|
+
const data = paginate53(items, page, limit, length);
|
|
79647
80100
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
79648
80101
|
logger166.info(`Cache set for key: ${cacheKey}`);
|
|
79649
80102
|
}).catch((err) => {
|
|
@@ -80385,7 +80838,7 @@ import {
|
|
|
80385
80838
|
logger as logger169,
|
|
80386
80839
|
makeCacheKey as makeCacheKey54,
|
|
80387
80840
|
NotFoundError as NotFoundError74,
|
|
80388
|
-
paginate as
|
|
80841
|
+
paginate as paginate54,
|
|
80389
80842
|
useAtlas as useAtlas114,
|
|
80390
80843
|
useCache as useCache59
|
|
80391
80844
|
} from "@7365admin1/node-server-utils";
|
|
@@ -80534,7 +80987,7 @@ function useIncidentReportRepo() {
|
|
|
80534
80987
|
{ session }
|
|
80535
80988
|
).toArray();
|
|
80536
80989
|
const length = await collection.countDocuments(query2, { session });
|
|
80537
|
-
const data =
|
|
80990
|
+
const data = paginate54(items, page, limit, length);
|
|
80538
80991
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
80539
80992
|
logger169.info(`Cache set for key: ${cacheKey}`);
|
|
80540
80993
|
}).catch((err) => {
|
|
@@ -80618,7 +81071,7 @@ function useIncidentReportRepo() {
|
|
|
80618
81071
|
{ session }
|
|
80619
81072
|
).toArray();
|
|
80620
81073
|
const length = await collection.countDocuments(query2, { session });
|
|
80621
|
-
const data =
|
|
81074
|
+
const data = paginate54(items, page, limit, length);
|
|
80622
81075
|
return data;
|
|
80623
81076
|
} catch (error) {
|
|
80624
81077
|
throw error;
|
|
@@ -81666,7 +82119,7 @@ import {
|
|
|
81666
82119
|
logger as logger175,
|
|
81667
82120
|
makeCacheKey as makeCacheKey56,
|
|
81668
82121
|
NotFoundError as NotFoundError77,
|
|
81669
|
-
paginate as
|
|
82122
|
+
paginate as paginate55,
|
|
81670
82123
|
useAtlas as useAtlas118,
|
|
81671
82124
|
useCache as useCache61
|
|
81672
82125
|
} from "@7365admin1/node-server-utils";
|
|
@@ -81867,7 +82320,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
81867
82320
|
]).toArray();
|
|
81868
82321
|
length = await collection.countDocuments(regexQuery, { session });
|
|
81869
82322
|
}
|
|
81870
|
-
const data =
|
|
82323
|
+
const data = paginate55(items, page, limit, length);
|
|
81871
82324
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
81872
82325
|
logger175.info(`Cache set for key: ${cacheKey}`);
|
|
81873
82326
|
}).catch((err) => {
|
|
@@ -82375,7 +82828,7 @@ import {
|
|
|
82375
82828
|
logger as logger177,
|
|
82376
82829
|
makeCacheKey as makeCacheKey57,
|
|
82377
82830
|
NotFoundError as NotFoundError78,
|
|
82378
|
-
paginate as
|
|
82831
|
+
paginate as paginate56,
|
|
82379
82832
|
useAtlas as useAtlas120,
|
|
82380
82833
|
useCache as useCache62
|
|
82381
82834
|
} from "@7365admin1/node-server-utils";
|
|
@@ -82478,7 +82931,7 @@ function useOnlineFormRepo() {
|
|
|
82478
82931
|
}
|
|
82479
82932
|
]).toArray();
|
|
82480
82933
|
const length = await collection.countDocuments(query2);
|
|
82481
|
-
const data =
|
|
82934
|
+
const data = paginate56(items, page, limit, length);
|
|
82482
82935
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
82483
82936
|
logger177.info(`Cache set for key: ${cacheKey}`);
|
|
82484
82937
|
}).catch((err) => {
|
|
@@ -82639,7 +83092,7 @@ function useOnlineFormRepo() {
|
|
|
82639
83092
|
}
|
|
82640
83093
|
]).toArray();
|
|
82641
83094
|
const length = await collection.countDocuments(query2);
|
|
82642
|
-
const data =
|
|
83095
|
+
const data = paginate56(items, page, limit, length);
|
|
82643
83096
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
82644
83097
|
logger177.info(`Cache set for key: ${cacheKey}`);
|
|
82645
83098
|
}).catch((err) => {
|
|
@@ -83070,7 +83523,7 @@ import {
|
|
|
83070
83523
|
InternalServerError as InternalServerError75,
|
|
83071
83524
|
logger as logger180,
|
|
83072
83525
|
makeCacheKey as makeCacheKey58,
|
|
83073
|
-
paginate as
|
|
83526
|
+
paginate as paginate57,
|
|
83074
83527
|
useAtlas as useAtlas122,
|
|
83075
83528
|
useCache as useCache63
|
|
83076
83529
|
} from "@7365admin1/node-server-utils";
|
|
@@ -83178,7 +83631,7 @@ function useNfcPatrolLogRepo() {
|
|
|
83178
83631
|
const length = await collection.countDocuments(query2, {
|
|
83179
83632
|
session
|
|
83180
83633
|
});
|
|
83181
|
-
const data =
|
|
83634
|
+
const data = paginate57(items, pageIndex, limit, length);
|
|
83182
83635
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
83183
83636
|
logger180.info(`Cache set for key: ${cacheKey}`);
|
|
83184
83637
|
}).catch((err) => {
|
|
@@ -83577,7 +84030,7 @@ function useNfcPatrolLogController() {
|
|
|
83577
84030
|
import {
|
|
83578
84031
|
BadRequestError as BadRequestError216,
|
|
83579
84032
|
InternalServerError as InternalServerError76,
|
|
83580
|
-
paginate as
|
|
84033
|
+
paginate as paginate58,
|
|
83581
84034
|
toObjectId as toObjectId19,
|
|
83582
84035
|
useAtlas as useAtlas124
|
|
83583
84036
|
} from "@7365admin1/node-server-utils";
|
|
@@ -84846,7 +85299,7 @@ function useNewDashboardRepo() {
|
|
|
84846
85299
|
]).toArray()
|
|
84847
85300
|
]);
|
|
84848
85301
|
const length = countResult[0]?.count ?? 0;
|
|
84849
|
-
const data =
|
|
85302
|
+
const data = paginate58(items, page, limit, length);
|
|
84850
85303
|
return data;
|
|
84851
85304
|
} catch (error) {
|
|
84852
85305
|
throw error;
|
|
@@ -84976,7 +85429,7 @@ function useNewDashboardRepo() {
|
|
|
84976
85429
|
]
|
|
84977
85430
|
})
|
|
84978
85431
|
]);
|
|
84979
|
-
const data =
|
|
85432
|
+
const data = paginate58(items, page, limit, length);
|
|
84980
85433
|
return data;
|
|
84981
85434
|
} catch (error) {
|
|
84982
85435
|
throw error;
|
|
@@ -85033,7 +85486,7 @@ function useNewDashboardRepo() {
|
|
|
85033
85486
|
]).toArray(),
|
|
85034
85487
|
feedbackCollection.countDocuments(matchQuery)
|
|
85035
85488
|
]);
|
|
85036
|
-
const data =
|
|
85489
|
+
const data = paginate58(items, page, limit, length);
|
|
85037
85490
|
return data;
|
|
85038
85491
|
} catch (error) {
|
|
85039
85492
|
throw error;
|
|
@@ -85352,7 +85805,7 @@ import {
|
|
|
85352
85805
|
BadRequestError as BadRequestError218,
|
|
85353
85806
|
InternalServerError as InternalServerError77,
|
|
85354
85807
|
logger as logger184,
|
|
85355
|
-
paginate as
|
|
85808
|
+
paginate as paginate60,
|
|
85356
85809
|
useAtlas as useAtlas125
|
|
85357
85810
|
} from "@7365admin1/node-server-utils";
|
|
85358
85811
|
|
|
@@ -85447,7 +85900,7 @@ function filterByShiftTime(attendance, shiftData, timezone, format2) {
|
|
|
85447
85900
|
return checkInLocal.isBetween(shiftStart, shiftEnd, null, "[]");
|
|
85448
85901
|
});
|
|
85449
85902
|
}
|
|
85450
|
-
function
|
|
85903
|
+
function paginate59(data, page, limit) {
|
|
85451
85904
|
const length = data.length;
|
|
85452
85905
|
const startIndex = (page - 1) * limit;
|
|
85453
85906
|
const endIndex = startIndex + limit;
|
|
@@ -85795,7 +86248,7 @@ var hrmlabs_attendance_util_default = {
|
|
|
85795
86248
|
hrmLabsAuthentication,
|
|
85796
86249
|
fetchAttendanceData,
|
|
85797
86250
|
filterByShiftTime,
|
|
85798
|
-
paginate:
|
|
86251
|
+
paginate: paginate59,
|
|
85799
86252
|
designationCount,
|
|
85800
86253
|
totalCountPerShift,
|
|
85801
86254
|
filterByStatus,
|
|
@@ -85878,7 +86331,7 @@ function useManpowerMonitoringRepo() {
|
|
|
85878
86331
|
]).toArray();
|
|
85879
86332
|
const total = result[0].totalCount[0]?.count || 0;
|
|
85880
86333
|
const items = result[0].items;
|
|
85881
|
-
return
|
|
86334
|
+
return paginate60(items, page, limit, total);
|
|
85882
86335
|
} catch (error) {
|
|
85883
86336
|
throw new Error(error.message || "Server Internal Error");
|
|
85884
86337
|
}
|
|
@@ -86038,7 +86491,7 @@ import {
|
|
|
86038
86491
|
BadRequestError as BadRequestError219,
|
|
86039
86492
|
InternalServerError as InternalServerError78,
|
|
86040
86493
|
logger as logger185,
|
|
86041
|
-
paginate as
|
|
86494
|
+
paginate as paginate61,
|
|
86042
86495
|
useAtlas as useAtlas126
|
|
86043
86496
|
} from "@7365admin1/node-server-utils";
|
|
86044
86497
|
|
|
@@ -86167,7 +86620,7 @@ function useManpowerRemarksRepo() {
|
|
|
86167
86620
|
]).toArray();
|
|
86168
86621
|
const total = result[0].totalCount[0]?.count || 0;
|
|
86169
86622
|
const items = result[0].items;
|
|
86170
|
-
return
|
|
86623
|
+
return paginate61(items, page, limit, total);
|
|
86171
86624
|
} catch (error) {
|
|
86172
86625
|
throw new Error(error.message || "Server Internal Error");
|
|
86173
86626
|
}
|
|
@@ -87041,7 +87494,7 @@ import {
|
|
|
87041
87494
|
InternalServerError as InternalServerError81,
|
|
87042
87495
|
logger as logger192,
|
|
87043
87496
|
makeCacheKey as makeCacheKey63,
|
|
87044
|
-
paginate as
|
|
87497
|
+
paginate as paginate64,
|
|
87045
87498
|
toObjectId as toObjectId22,
|
|
87046
87499
|
useAtlas as useAtlas130,
|
|
87047
87500
|
useCache as useCache68
|
|
@@ -87139,7 +87592,7 @@ function useOvernightParkingRequestRepo() {
|
|
|
87139
87592
|
{ $limit: limit }
|
|
87140
87593
|
]).toArray();
|
|
87141
87594
|
const length = await collection.countDocuments(query2);
|
|
87142
|
-
const data =
|
|
87595
|
+
const data = paginate64(items, page, limit, length);
|
|
87143
87596
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
87144
87597
|
logger192.info(`Cache set for key: ${cacheKey}`);
|
|
87145
87598
|
}).catch((err) => {
|
|
@@ -87569,7 +88022,7 @@ var {
|
|
|
87569
88022
|
hrmLabsAuthentication: hrmLabsAuthentication3,
|
|
87570
88023
|
fetchAttendanceData: fetchAttendanceData2,
|
|
87571
88024
|
filterByShiftTime: filterByShiftTime2,
|
|
87572
|
-
paginate:
|
|
88025
|
+
paginate: paginate65,
|
|
87573
88026
|
designationCount: designationCount2,
|
|
87574
88027
|
totalCountPerShift: totalCountPerShift2,
|
|
87575
88028
|
filterByStatus: filterByStatus2,
|
|
@@ -87679,7 +88132,7 @@ function useHrmLabsAttendanceSrvc() {
|
|
|
87679
88132
|
status
|
|
87680
88133
|
);
|
|
87681
88134
|
}
|
|
87682
|
-
const paginatedItems =
|
|
88135
|
+
const paginatedItems = paginate65(filteredAttendance, page, limit);
|
|
87683
88136
|
return {
|
|
87684
88137
|
items: paginatedItems.items,
|
|
87685
88138
|
pages: paginatedItems.pages,
|
|
@@ -89418,7 +89871,7 @@ import {
|
|
|
89418
89871
|
BadRequestError as BadRequestError234,
|
|
89419
89872
|
NotFoundError as NotFoundError85,
|
|
89420
89873
|
AppError as AppError37,
|
|
89421
|
-
paginate as
|
|
89874
|
+
paginate as paginate67
|
|
89422
89875
|
} from "@7365admin1/node-server-utils";
|
|
89423
89876
|
var useRedDotPaymentRepo = () => {
|
|
89424
89877
|
const getDB2 = () => {
|
|
@@ -89597,7 +90050,7 @@ var useRedDotPaymentRepo = () => {
|
|
|
89597
90050
|
paymentCollection().aggregate([{ $match: query2 }, { $count: "total" }], { session }).toArray()
|
|
89598
90051
|
]);
|
|
89599
90052
|
const totalCount = countResult[0]?.total || 0;
|
|
89600
|
-
const data =
|
|
90053
|
+
const data = paginate67(items, page, limit, totalCount);
|
|
89601
90054
|
return data;
|
|
89602
90055
|
} catch (error) {
|
|
89603
90056
|
if (error instanceof AppError37) {
|
|
@@ -90164,7 +90617,7 @@ import {
|
|
|
90164
90617
|
InternalServerError as InternalServerError85,
|
|
90165
90618
|
logger as logger206,
|
|
90166
90619
|
BadRequestError as BadRequestError236,
|
|
90167
|
-
paginate as
|
|
90620
|
+
paginate as paginate68,
|
|
90168
90621
|
NotFoundError as NotFoundError86,
|
|
90169
90622
|
AppError as AppError38,
|
|
90170
90623
|
useCache as useCache72,
|
|
@@ -90407,7 +90860,7 @@ function useUserRepoV2() {
|
|
|
90407
90860
|
}
|
|
90408
90861
|
]).toArray();
|
|
90409
90862
|
const length = await collection.countDocuments(query2);
|
|
90410
|
-
const data =
|
|
90863
|
+
const data = paginate68(items, page, limit, length);
|
|
90411
90864
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
90412
90865
|
logger206.info(`Cache set for key: ${cacheKey}`);
|
|
90413
90866
|
}).catch((err) => {
|
|
@@ -90463,7 +90916,7 @@ function useUserRepoV2() {
|
|
|
90463
90916
|
{ $project: { _id: 1, name: 1, email: 1, type: 1, status: 1 } }
|
|
90464
90917
|
]).toArray();
|
|
90465
90918
|
const length = await collection.countDocuments(query2);
|
|
90466
|
-
const data =
|
|
90919
|
+
const data = paginate68(items, page, limit, length);
|
|
90467
90920
|
setCache(cacheKey, data, 15 * 60).then(() => logger206.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
90468
90921
|
(err) => logger206.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
90469
90922
|
);
|
|
@@ -92029,6 +92482,7 @@ function useServiceProviderInviteController() {
|
|
|
92029
92482
|
try {
|
|
92030
92483
|
const schema2 = Joi149.object({
|
|
92031
92484
|
org: Joi149.string().hex().length(24).optional().allow("", null),
|
|
92485
|
+
siteId: Joi149.string().hex().length(24).optional().allow("", null),
|
|
92032
92486
|
status: Joi149.string().optional().allow("", null),
|
|
92033
92487
|
search: Joi149.string().max(200).optional().allow("", null),
|
|
92034
92488
|
page: Joi149.number().min(1).default(1),
|
|
@@ -92038,10 +92492,13 @@ function useServiceProviderInviteController() {
|
|
|
92038
92492
|
if (error)
|
|
92039
92493
|
throw new BadRequestError240(`Invalid input: ${error.message}`);
|
|
92040
92494
|
const statuses = String(value.status ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
92495
|
+
if (value.siteId)
|
|
92496
|
+
await requireSiteReach(req, value.siteId);
|
|
92041
92497
|
res.json(
|
|
92042
92498
|
await listForCaller({
|
|
92043
92499
|
userId: callerId5(req),
|
|
92044
92500
|
orgId: value.org || void 0,
|
|
92501
|
+
siteId: value.siteId || void 0,
|
|
92045
92502
|
statuses,
|
|
92046
92503
|
search: value.search || "",
|
|
92047
92504
|
page: value.page,
|
|
@@ -93218,7 +93675,7 @@ import {
|
|
|
93218
93675
|
BadRequestError as BadRequestError247,
|
|
93219
93676
|
InternalServerError as InternalServerError90,
|
|
93220
93677
|
NotFoundError as NotFoundError90,
|
|
93221
|
-
paginate as
|
|
93678
|
+
paginate as paginate69,
|
|
93222
93679
|
useAtlas as useAtlas143
|
|
93223
93680
|
} from "@7365admin1/node-server-utils";
|
|
93224
93681
|
import { ObjectId as ObjectId178 } from "mongodb";
|
|
@@ -93584,7 +94041,7 @@ function usePostPrelovedRepo() {
|
|
|
93584
94041
|
{ session }
|
|
93585
94042
|
).toArray();
|
|
93586
94043
|
const length = await collection.countDocuments(query2, { session });
|
|
93587
|
-
return
|
|
94044
|
+
return paginate69(items, page, limit, length);
|
|
93588
94045
|
} catch (error) {
|
|
93589
94046
|
throw error;
|
|
93590
94047
|
}
|
|
@@ -93656,7 +94113,7 @@ function usePostPrelovedRepo() {
|
|
|
93656
94113
|
{ session }
|
|
93657
94114
|
).toArray();
|
|
93658
94115
|
const length = await collection.countDocuments(query2, { session });
|
|
93659
|
-
return
|
|
94116
|
+
return paginate69(items, page, limit, length);
|
|
93660
94117
|
} catch (error) {
|
|
93661
94118
|
throw error;
|
|
93662
94119
|
}
|
|
@@ -95027,7 +95484,7 @@ import { BadRequestError as BadRequestError256, InternalServerError as InternalS
|
|
|
95027
95484
|
// src/repositories/channel-preloved.repo.ts
|
|
95028
95485
|
import {
|
|
95029
95486
|
InternalServerError as InternalServerError95,
|
|
95030
|
-
paginate as
|
|
95487
|
+
paginate as paginate71,
|
|
95031
95488
|
useAtlas as useAtlas150
|
|
95032
95489
|
} from "@7365admin1/node-server-utils";
|
|
95033
95490
|
import { ObjectId as ObjectId189 } from "mongodb";
|
|
@@ -95186,7 +95643,7 @@ function useChannelPrelovedRepo() {
|
|
|
95186
95643
|
const totalCount = result[0].totalCount[0]?.count ?? 0;
|
|
95187
95644
|
const items = result[0].items;
|
|
95188
95645
|
items.reverse();
|
|
95189
|
-
return
|
|
95646
|
+
return paginate71(items, normalizedPage, normalizedLimit, totalCount);
|
|
95190
95647
|
} catch (error) {
|
|
95191
95648
|
throw error;
|
|
95192
95649
|
}
|
|
@@ -95309,7 +95766,7 @@ function useChannelPrelovedRepo() {
|
|
|
95309
95766
|
const result = await collection.aggregate(pipeline).toArray();
|
|
95310
95767
|
const totalCount = result[0].totalCount[0]?.count ?? 0;
|
|
95311
95768
|
const items = result[0].items;
|
|
95312
|
-
return
|
|
95769
|
+
return paginate71(items, normalizedPage, normalizedLimit, totalCount);
|
|
95313
95770
|
} catch (error) {
|
|
95314
95771
|
throw error;
|
|
95315
95772
|
}
|
|
@@ -96086,7 +96543,7 @@ import {
|
|
|
96086
96543
|
BadRequestError as BadRequestError260,
|
|
96087
96544
|
InternalServerError as InternalServerError100,
|
|
96088
96545
|
NotFoundError as NotFoundError96,
|
|
96089
|
-
paginate as
|
|
96546
|
+
paginate as paginate72,
|
|
96090
96547
|
useAtlas as useAtlas155,
|
|
96091
96548
|
useCache as useCache76
|
|
96092
96549
|
} from "@7365admin1/node-server-utils";
|
|
@@ -96174,7 +96631,7 @@ function useFormEntryRepo() {
|
|
|
96174
96631
|
{ $project: { user: 0 } }
|
|
96175
96632
|
]).toArray();
|
|
96176
96633
|
const length = await collection.countDocuments(query2);
|
|
96177
|
-
const data =
|
|
96634
|
+
const data = paginate72(items, page, limit, length);
|
|
96178
96635
|
return data;
|
|
96179
96636
|
} catch (error) {
|
|
96180
96637
|
throw error;
|
|
@@ -96306,7 +96763,7 @@ function useFormEntryRepo() {
|
|
|
96306
96763
|
{ $limit: limit }
|
|
96307
96764
|
]).toArray();
|
|
96308
96765
|
const length = await collection.countDocuments(query2);
|
|
96309
|
-
const data =
|
|
96766
|
+
const data = paginate72(items, page, limit, length);
|
|
96310
96767
|
return data;
|
|
96311
96768
|
} catch (error) {
|
|
96312
96769
|
throw error;
|
|
@@ -99042,6 +99499,7 @@ export {
|
|
|
99042
99499
|
notificationCategory,
|
|
99043
99500
|
notificationCategoryLabel,
|
|
99044
99501
|
notificationEvents,
|
|
99502
|
+
notificationKind,
|
|
99045
99503
|
notificationRoom,
|
|
99046
99504
|
notifyAccessMode,
|
|
99047
99505
|
notifyRobotFault,
|
|
@@ -99566,6 +100024,7 @@ export {
|
|
|
99566
100024
|
wallsFromOccupancyGrid,
|
|
99567
100025
|
waypointsFor,
|
|
99568
100026
|
withLiveLink,
|
|
100027
|
+
withNotificationKind,
|
|
99569
100028
|
workOrderSchema,
|
|
99570
100029
|
work_orders2_namespace_collection,
|
|
99571
100030
|
work_orders_namespace_collection
|