@7365admin1/core 3.99.1-staging.373 → 3.99.1-staging.375
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/.changeset/dashboard-deleted-work-orders.md +5 -0
- package/.changeset/sp-inviter-view.md +5 -0
- package/dist/index.d.ts +25 -3
- package/dist/index.js +272 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +380 -135
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/dashboard-deleted-work-orders.e2e.test.mjs +54 -0
- package/test/e2e/harness.mjs +2 -0
- package/test/e2e/service-provider-invite-approval.e2e.test.mjs +170 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": patch
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Dashboard: a deleted work order (`status: "deleted"` in `work-orders2`) no longer counts as open on the Open Work Order tile, its trend, the activity chart, or as pending in the Work Order Status bar. The filters listed only "Deleted"; both spellings are now excluded.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": minor
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Service providers, inviter's view: `GET /service-providers?siteId=&include=engagements` also lists providers on the site through an accepted invitation (read from `customer.sites`, nothing written), and now requires the caller to reach the site. Staff counts are the provider's people assigned to that site. `GET /service-provider-invitations` takes `siteId` and returns each row with the accepting company, who invited and when, when it was answered, contact details once accepted, and whether the provider is still on the site.
|
package/dist/index.d.ts
CHANGED
|
@@ -2821,6 +2821,11 @@ declare function useServiceProviderRepo(): {
|
|
|
2821
2821
|
serviceProviderOrgId?: string | ObjectId | undefined;
|
|
2822
2822
|
}) => Promise<{}>;
|
|
2823
2823
|
updateStatusById: (_id: string | ObjectId, status: string) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
2824
|
+
getEngagedProvidersBySite: (site: string | ObjectId) => Promise<bson.Document[]>;
|
|
2825
|
+
getSiteProviderKeys: (site: string | ObjectId) => Promise<{
|
|
2826
|
+
orgIds: Set<any>;
|
|
2827
|
+
emails: Set<string>;
|
|
2828
|
+
}>;
|
|
2824
2829
|
};
|
|
2825
2830
|
|
|
2826
2831
|
declare function useServiceProviderController(): {
|
|
@@ -14988,10 +14993,12 @@ declare function useVerificationRepoV2(): {
|
|
|
14988
14993
|
where?: Record<string, any> | undefined;
|
|
14989
14994
|
session?: ClientSession | undefined;
|
|
14990
14995
|
}) => Promise<any>;
|
|
14991
|
-
getServiceProviderInvites: ({ statuses, orgIds, email, search, includeDeleted, page, limit, }: {
|
|
14996
|
+
getServiceProviderInvites: ({ statuses, orgIds, email, siteId, search, includeDeleted, page, limit, }: {
|
|
14992
14997
|
statuses?: string[] | undefined;
|
|
14993
14998
|
orgIds?: string[] | undefined;
|
|
14994
14999
|
email?: string | undefined;
|
|
15000
|
+
/** One site's invitations; the id is matched in both stored forms. */
|
|
15001
|
+
siteId?: string | undefined;
|
|
14995
15002
|
search?: string | undefined;
|
|
14996
15003
|
includeDeleted?: boolean | undefined;
|
|
14997
15004
|
page?: number | undefined;
|
|
@@ -15275,20 +15282,35 @@ declare function useServiceProviderInviteController(): {
|
|
|
15275
15282
|
};
|
|
15276
15283
|
|
|
15277
15284
|
declare function useServiceProviderInviteService(): {
|
|
15278
|
-
listForCaller: ({ userId, orgId, statuses, search, page, limit, }: {
|
|
15285
|
+
listForCaller: ({ userId, orgId, siteId, statuses, search, page, limit, }: {
|
|
15279
15286
|
userId?: string | undefined;
|
|
15280
15287
|
orgId?: string | undefined;
|
|
15288
|
+
/** The site on screen: only its invitations. */
|
|
15289
|
+
siteId?: string | undefined;
|
|
15281
15290
|
statuses?: string[] | undefined;
|
|
15282
15291
|
search?: string | undefined;
|
|
15283
15292
|
page?: number | undefined;
|
|
15284
15293
|
limit?: number | undefined;
|
|
15285
15294
|
}) => Promise<{
|
|
15286
15295
|
items: {
|
|
15296
|
+
metadata: {
|
|
15297
|
+
name: string;
|
|
15298
|
+
};
|
|
15299
|
+
viewStatus: string;
|
|
15287
15300
|
statusLabel: string;
|
|
15301
|
+
companyName: string;
|
|
15302
|
+
providerOrgId: any;
|
|
15303
|
+
service: string;
|
|
15304
|
+
siteName: string;
|
|
15305
|
+
invitedByName: string;
|
|
15306
|
+
invitedAt: string;
|
|
15307
|
+
answeredAt: any;
|
|
15308
|
+
contactEmail: string;
|
|
15309
|
+
contactPhone: string;
|
|
15310
|
+
onSite: boolean;
|
|
15288
15311
|
_id?: ObjectId | undefined;
|
|
15289
15312
|
type: string;
|
|
15290
15313
|
email: string;
|
|
15291
|
-
metadata?: TVerificationMetadataV2 | undefined;
|
|
15292
15314
|
status?: string | undefined;
|
|
15293
15315
|
createdAt: string;
|
|
15294
15316
|
updatedAt?: string | null | undefined;
|
package/dist/index.js
CHANGED
|
@@ -8397,6 +8397,7 @@ function useVerificationRepoV2() {
|
|
|
8397
8397
|
statuses = [],
|
|
8398
8398
|
orgIds,
|
|
8399
8399
|
email = "",
|
|
8400
|
+
siteId = "",
|
|
8400
8401
|
search = "",
|
|
8401
8402
|
includeDeleted = false,
|
|
8402
8403
|
page = 1,
|
|
@@ -8415,6 +8416,12 @@ function useVerificationRepoV2() {
|
|
|
8415
8416
|
query2.status = { $in: statuses };
|
|
8416
8417
|
if (email)
|
|
8417
8418
|
query2.email = email.trim().toLowerCase();
|
|
8419
|
+
if (siteId) {
|
|
8420
|
+
const ids2 = [siteId];
|
|
8421
|
+
if (import_mongodb22.ObjectId.isValid(siteId))
|
|
8422
|
+
ids2.push(new import_mongodb22.ObjectId(siteId));
|
|
8423
|
+
query2["metadata.siteId"] = { $in: ids2 };
|
|
8424
|
+
}
|
|
8418
8425
|
if (!includeDeleted)
|
|
8419
8426
|
query2.deletedAt = null;
|
|
8420
8427
|
if (search.trim()) {
|
|
@@ -13733,6 +13740,7 @@ function useServiceProviderInviteService() {
|
|
|
13733
13740
|
async function listForCaller({
|
|
13734
13741
|
userId,
|
|
13735
13742
|
orgId,
|
|
13743
|
+
siteId,
|
|
13736
13744
|
statuses,
|
|
13737
13745
|
search = "",
|
|
13738
13746
|
page = 1,
|
|
@@ -13753,16 +13761,85 @@ function useServiceProviderInviteService() {
|
|
|
13753
13761
|
// A super admin asking for everything passes no scope; everyone else is
|
|
13754
13762
|
// pinned to their own organisations even if they ask for more.
|
|
13755
13763
|
orgIds: staffMayBypass(actor) && !orgId ? void 0 : scope,
|
|
13764
|
+
siteId: siteId || void 0,
|
|
13756
13765
|
search,
|
|
13757
13766
|
page,
|
|
13758
13767
|
limit
|
|
13759
13768
|
});
|
|
13769
|
+
const names = /* @__PURE__ */ new Map();
|
|
13770
|
+
const items = await Promise.all(
|
|
13771
|
+
(data.items ?? []).map(
|
|
13772
|
+
(invite) => sentRow(invite, names)
|
|
13773
|
+
)
|
|
13774
|
+
);
|
|
13775
|
+
return { ...data, items };
|
|
13776
|
+
}
|
|
13777
|
+
async function sentRow(invite, names) {
|
|
13778
|
+
const metadata = invite.metadata ?? {};
|
|
13779
|
+
const status = serviceProviderInviteViewStatus(invite);
|
|
13780
|
+
const accepted = status === "complete" /* COMPLETE */ && !invite.deletedAt;
|
|
13781
|
+
const siteId = metadata.siteId?.toString?.() ?? "";
|
|
13782
|
+
const history = invite.history ?? [];
|
|
13783
|
+
const answer = [...history].reverse().find(
|
|
13784
|
+
(h) => ["accepted", "site-linked", "declined", "cancelled", "rejected"].includes(h?.action)
|
|
13785
|
+
);
|
|
13786
|
+
let providerOrgId = metadata.providerOrg?.toString?.() ?? "";
|
|
13787
|
+
let providerOrgName = String(metadata.providerOrgName ?? "");
|
|
13788
|
+
if (accepted && !providerOrgId) {
|
|
13789
|
+
const byEmail = await getOrgByEmail(
|
|
13790
|
+
String(invite.email ?? "").trim().toLowerCase()
|
|
13791
|
+
).catch(() => null);
|
|
13792
|
+
providerOrgId = byEmail?._id?.toString?.() ?? "";
|
|
13793
|
+
providerOrgName = byEmail?.name ?? "";
|
|
13794
|
+
}
|
|
13795
|
+
let contactEmail = "";
|
|
13796
|
+
let contactPhone = "";
|
|
13797
|
+
let onSite = false;
|
|
13798
|
+
if (accepted && providerOrgId) {
|
|
13799
|
+
const [org, links] = await Promise.all([
|
|
13800
|
+
getOrgById(providerOrgId).catch(() => null),
|
|
13801
|
+
siteId ? useCustomerSiteRepo().countActiveByOrgAndSite(providerOrgId, siteId).catch(() => 0) : Promise.resolve(0)
|
|
13802
|
+
]);
|
|
13803
|
+
providerOrgName = providerOrgName || org?.name || "";
|
|
13804
|
+
contactEmail = String(org?.email ?? "");
|
|
13805
|
+
contactPhone = String(org?.contact ?? "");
|
|
13806
|
+
onSite = links > 0;
|
|
13807
|
+
}
|
|
13808
|
+
const invitedBy = metadata.invitedBy?.toString?.() ?? "";
|
|
13809
|
+
let invitedByName = String(metadata.invitedByName ?? "");
|
|
13810
|
+
if (!invitedByName && invitedBy) {
|
|
13811
|
+
if (!names.has(invitedBy)) {
|
|
13812
|
+
names.set(
|
|
13813
|
+
invitedBy,
|
|
13814
|
+
getUserById(invitedBy).then((u) => String(u?.name ?? "")).catch(() => "")
|
|
13815
|
+
);
|
|
13816
|
+
}
|
|
13817
|
+
invitedByName = await names.get(invitedBy);
|
|
13818
|
+
}
|
|
13819
|
+
const companyName = providerOrgName || String(metadata.name ?? "");
|
|
13760
13820
|
return {
|
|
13761
|
-
...
|
|
13762
|
-
|
|
13763
|
-
|
|
13764
|
-
|
|
13765
|
-
|
|
13821
|
+
...invite,
|
|
13822
|
+
// Apps still on an older layer-common read the company from
|
|
13823
|
+
// `metadata.name` (set only on sign-up invitations). Filled in the reply
|
|
13824
|
+
// only - nothing is written. ponytail: drop once every app's pin reads
|
|
13825
|
+
// `companyName`.
|
|
13826
|
+
metadata: { ...metadata, name: companyName },
|
|
13827
|
+
// `status` stays the stored value (it decides which actions a row
|
|
13828
|
+
// offers); `viewStatus` reads a lapsed "pending" as "expired".
|
|
13829
|
+
viewStatus: status,
|
|
13830
|
+
statusLabel: serviceProviderInviteLabel(status),
|
|
13831
|
+
// The company the invitation is for: the one that accepted it, else the
|
|
13832
|
+
// new company's name the sender typed (a sign-up invitation).
|
|
13833
|
+
companyName,
|
|
13834
|
+
providerOrgId,
|
|
13835
|
+
service: String(metadata.app ?? ""),
|
|
13836
|
+
siteName: String(metadata.siteName ?? ""),
|
|
13837
|
+
invitedByName,
|
|
13838
|
+
invitedAt: invite.createdAt ?? null,
|
|
13839
|
+
answeredAt: status === "expired" ? invite.expireAt ?? null : status === "pending" || status === "awaiting-approval" /* AWAITING_APPROVAL */ ? null : answer?.at ?? invite.updatedAt ?? null,
|
|
13840
|
+
contactEmail,
|
|
13841
|
+
contactPhone,
|
|
13842
|
+
onSite
|
|
13766
13843
|
};
|
|
13767
13844
|
}
|
|
13768
13845
|
async function approvalCount({ userId }) {
|
|
@@ -33112,7 +33189,7 @@ function useServiceProviderRepo() {
|
|
|
33112
33189
|
throw new import_node_server_utils97.BadRequestError("Invalid site ID format.");
|
|
33113
33190
|
}
|
|
33114
33191
|
}
|
|
33115
|
-
cacheOptions.membersLookup = "
|
|
33192
|
+
cacheOptions.membersLookup = "2";
|
|
33116
33193
|
const cacheKey = (0, import_node_server_utils97.makeCacheKey)(namespace_collection3, cacheOptions);
|
|
33117
33194
|
const cachedData = await getCache(cacheKey);
|
|
33118
33195
|
if (cachedData) {
|
|
@@ -33128,7 +33205,7 @@ function useServiceProviderRepo() {
|
|
|
33128
33205
|
localField: "serviceProviderOrgId",
|
|
33129
33206
|
foreignField: "_id",
|
|
33130
33207
|
as: "organization",
|
|
33131
|
-
pipeline: [{ $project: { nature: 1, email: 1 } }]
|
|
33208
|
+
pipeline: [{ $project: { nature: 1, email: 1, contact: 1 } }]
|
|
33132
33209
|
}
|
|
33133
33210
|
},
|
|
33134
33211
|
{
|
|
@@ -33140,11 +33217,19 @@ function useServiceProviderRepo() {
|
|
|
33140
33217
|
{
|
|
33141
33218
|
$lookup: {
|
|
33142
33219
|
from: "members",
|
|
33143
|
-
|
|
33220
|
+
// The provider's staff assigned to THIS site, not the provider's
|
|
33221
|
+
// whole headcount - the client has no business knowing how big
|
|
33222
|
+
// its contractor is, only who works on its estate.
|
|
33223
|
+
let: { spOrgId: "$serviceProviderOrgId", spSiteId: "$siteId" },
|
|
33144
33224
|
pipeline: [
|
|
33145
33225
|
{
|
|
33146
33226
|
$match: {
|
|
33147
|
-
$expr: {
|
|
33227
|
+
$expr: {
|
|
33228
|
+
$and: [
|
|
33229
|
+
{ $eq: ["$org", "$$spOrgId"] },
|
|
33230
|
+
{ $eq: ["$siteId", "$$spSiteId"] }
|
|
33231
|
+
]
|
|
33232
|
+
},
|
|
33148
33233
|
status: "active"
|
|
33149
33234
|
}
|
|
33150
33235
|
},
|
|
@@ -33167,6 +33252,7 @@ function useServiceProviderRepo() {
|
|
|
33167
33252
|
}
|
|
33168
33253
|
},
|
|
33169
33254
|
nature: "$organization.nature",
|
|
33255
|
+
contact: { $ifNull: ["$organization.contact", ""] },
|
|
33170
33256
|
orgId: 1,
|
|
33171
33257
|
siteId: 1,
|
|
33172
33258
|
siteName: 1,
|
|
@@ -33416,6 +33502,104 @@ function useServiceProviderRepo() {
|
|
|
33416
33502
|
throw error;
|
|
33417
33503
|
}
|
|
33418
33504
|
}
|
|
33505
|
+
async function getEngagedProvidersBySite(site) {
|
|
33506
|
+
try {
|
|
33507
|
+
site = new import_mongodb72.ObjectId(site);
|
|
33508
|
+
} catch {
|
|
33509
|
+
throw new import_node_server_utils97.BadRequestError("Invalid site ID format.");
|
|
33510
|
+
}
|
|
33511
|
+
return await db2.collection("customer.sites").aggregate([
|
|
33512
|
+
{
|
|
33513
|
+
$match: {
|
|
33514
|
+
site,
|
|
33515
|
+
status: "active",
|
|
33516
|
+
// The client's own row for its own site is not a provider, and a
|
|
33517
|
+
// row that does not say whose site it is proves nothing.
|
|
33518
|
+
siteOrg: { $nin: [null, ""] },
|
|
33519
|
+
$expr: { $ne: ["$org", "$siteOrg"] }
|
|
33520
|
+
}
|
|
33521
|
+
},
|
|
33522
|
+
{ $sort: { _id: 1 } },
|
|
33523
|
+
{
|
|
33524
|
+
$group: {
|
|
33525
|
+
_id: "$org",
|
|
33526
|
+
engagementId: { $first: "$_id" },
|
|
33527
|
+
siteName: { $first: "$name" },
|
|
33528
|
+
since: { $first: "$createdAt" }
|
|
33529
|
+
}
|
|
33530
|
+
},
|
|
33531
|
+
{
|
|
33532
|
+
$lookup: {
|
|
33533
|
+
from: "organizations",
|
|
33534
|
+
localField: "_id",
|
|
33535
|
+
foreignField: "_id",
|
|
33536
|
+
as: "organization",
|
|
33537
|
+
pipeline: [
|
|
33538
|
+
{ $project: { name: 1, nature: 1, email: 1, contact: 1 } }
|
|
33539
|
+
]
|
|
33540
|
+
}
|
|
33541
|
+
},
|
|
33542
|
+
{ $unwind: { path: "$organization", preserveNullAndEmptyArrays: true } },
|
|
33543
|
+
{
|
|
33544
|
+
$lookup: {
|
|
33545
|
+
from: "members",
|
|
33546
|
+
let: { spOrgId: "$_id" },
|
|
33547
|
+
pipeline: [
|
|
33548
|
+
{
|
|
33549
|
+
$match: {
|
|
33550
|
+
$expr: { $eq: ["$org", "$$spOrgId"] },
|
|
33551
|
+
siteId: site,
|
|
33552
|
+
status: "active"
|
|
33553
|
+
}
|
|
33554
|
+
},
|
|
33555
|
+
{ $count: "c" }
|
|
33556
|
+
],
|
|
33557
|
+
as: "_memberCount"
|
|
33558
|
+
}
|
|
33559
|
+
},
|
|
33560
|
+
{
|
|
33561
|
+
$project: {
|
|
33562
|
+
_id: "$engagementId",
|
|
33563
|
+
name: { $ifNull: ["$organization.name", ""] },
|
|
33564
|
+
type: { $ifNull: ["$organization.nature", ""] },
|
|
33565
|
+
nature: "$organization.nature",
|
|
33566
|
+
email: { $ifNull: ["$organization.email", ""] },
|
|
33567
|
+
contact: { $ifNull: ["$organization.contact", ""] },
|
|
33568
|
+
siteId: site,
|
|
33569
|
+
siteName: 1,
|
|
33570
|
+
serviceProviderOrgId: "$_id",
|
|
33571
|
+
status: "active",
|
|
33572
|
+
category: "external",
|
|
33573
|
+
since: 1,
|
|
33574
|
+
source: "engagement",
|
|
33575
|
+
members: {
|
|
33576
|
+
$ifNull: [{ $arrayElemAt: ["$_memberCount.c", 0] }, 0]
|
|
33577
|
+
}
|
|
33578
|
+
}
|
|
33579
|
+
},
|
|
33580
|
+
{ $sort: { name: 1 } },
|
|
33581
|
+
{ $limit: 200 }
|
|
33582
|
+
]).toArray();
|
|
33583
|
+
}
|
|
33584
|
+
async function getSiteProviderKeys(site) {
|
|
33585
|
+
try {
|
|
33586
|
+
site = new import_mongodb72.ObjectId(site);
|
|
33587
|
+
} catch {
|
|
33588
|
+
throw new import_node_server_utils97.BadRequestError("Invalid site ID format.");
|
|
33589
|
+
}
|
|
33590
|
+
const rows = await collection.find(
|
|
33591
|
+
{ siteId: site },
|
|
33592
|
+
{ projection: { serviceProviderOrgId: 1, email: 1 } }
|
|
33593
|
+
).toArray();
|
|
33594
|
+
return {
|
|
33595
|
+
orgIds: new Set(
|
|
33596
|
+
rows.map((r) => r.serviceProviderOrgId?.toString?.() ?? "").filter(Boolean)
|
|
33597
|
+
),
|
|
33598
|
+
emails: new Set(
|
|
33599
|
+
rows.map((r) => String(r.email ?? "").trim().toLowerCase()).filter(Boolean)
|
|
33600
|
+
)
|
|
33601
|
+
};
|
|
33602
|
+
}
|
|
33419
33603
|
return {
|
|
33420
33604
|
createTextIndex,
|
|
33421
33605
|
createUniqueIndex,
|
|
@@ -33426,7 +33610,9 @@ function useServiceProviderRepo() {
|
|
|
33426
33610
|
getServiceProviderById,
|
|
33427
33611
|
getByServiceProviderOrgIdType,
|
|
33428
33612
|
getByEmail,
|
|
33429
|
-
updateStatusById
|
|
33613
|
+
updateStatusById,
|
|
33614
|
+
getEngagedProvidersBySite,
|
|
33615
|
+
getSiteProviderKeys
|
|
33430
33616
|
};
|
|
33431
33617
|
}
|
|
33432
33618
|
|
|
@@ -34146,7 +34332,9 @@ var import_node_server_utils102 = require("@7365admin1/node-server-utils");
|
|
|
34146
34332
|
function useServiceProviderService() {
|
|
34147
34333
|
const {
|
|
34148
34334
|
createServiceProvider: _createServiceProvider,
|
|
34149
|
-
getServiceProviders: _getServiceProviders
|
|
34335
|
+
getServiceProviders: _getServiceProviders,
|
|
34336
|
+
getEngagedProvidersBySite: _getEngaged,
|
|
34337
|
+
getSiteProviderKeys: _getSiteProviderKeys
|
|
34150
34338
|
} = useServiceProviderRepo();
|
|
34151
34339
|
const { getById: getOrgById, getByEmail: getOrgByEmail } = useOrgRepo();
|
|
34152
34340
|
const { getSiteById } = useSiteRepo();
|
|
@@ -34226,9 +34414,40 @@ function useServiceProviderService() {
|
|
|
34226
34414
|
status
|
|
34227
34415
|
});
|
|
34228
34416
|
}
|
|
34417
|
+
async function getServiceProvidersForSite({
|
|
34418
|
+
search = "",
|
|
34419
|
+
page = 1,
|
|
34420
|
+
limit = 10,
|
|
34421
|
+
siteId
|
|
34422
|
+
}) {
|
|
34423
|
+
const [engaged, keys] = await Promise.all([
|
|
34424
|
+
_getEngaged(siteId),
|
|
34425
|
+
_getSiteProviderKeys(siteId)
|
|
34426
|
+
]);
|
|
34427
|
+
const needle = search.trim().toLowerCase();
|
|
34428
|
+
const derived = engaged.filter(
|
|
34429
|
+
(row) => !keys.orgIds.has(row.serviceProviderOrgId?.toString?.() ?? "") && !(row.email && keys.emails.has(String(row.email).trim().toLowerCase())) && (!needle || String(row.name ?? "").toLowerCase().includes(needle))
|
|
34430
|
+
);
|
|
34431
|
+
const stored = (p, l) => _getServiceProviders({ search, page: p, limit: l, siteId, status: "active" });
|
|
34432
|
+
if (!derived.length)
|
|
34433
|
+
return await stored(page, limit);
|
|
34434
|
+
const start = (Math.max(page, 1) - 1) * limit;
|
|
34435
|
+
const fromDerived = derived.slice(start, start + limit);
|
|
34436
|
+
const need = limit - fromDerived.length;
|
|
34437
|
+
const storedStart = Math.max(0, start - derived.length);
|
|
34438
|
+
const first = await stored(1, Math.max(storedStart + need, 1));
|
|
34439
|
+
const total = derived.length + totalOf(first);
|
|
34440
|
+
const fromStored = need > 0 ? (first?.items ?? []).slice(storedStart, storedStart + need) : [];
|
|
34441
|
+
return (0, import_node_server_utils102.paginate)([...fromDerived, ...fromStored], Math.max(page, 1) - 1, limit, total);
|
|
34442
|
+
}
|
|
34443
|
+
function totalOf(data) {
|
|
34444
|
+
const match = /of\s+(\d+)/.exec(String(data?.pageRange ?? ""));
|
|
34445
|
+
return match ? Number(match[1]) : (data?.items ?? []).length;
|
|
34446
|
+
}
|
|
34229
34447
|
return {
|
|
34230
34448
|
createServiceProvider,
|
|
34231
|
-
getServiceProviders
|
|
34449
|
+
getServiceProviders,
|
|
34450
|
+
getServiceProvidersForSite
|
|
34232
34451
|
};
|
|
34233
34452
|
}
|
|
34234
34453
|
|
|
@@ -34243,7 +34462,18 @@ function useServiceProviderController() {
|
|
|
34243
34462
|
getByEmail: _getByEmail,
|
|
34244
34463
|
updateStatusById: _updateStatusById
|
|
34245
34464
|
} = useServiceProviderRepo();
|
|
34246
|
-
const {
|
|
34465
|
+
const {
|
|
34466
|
+
createServiceProvider: _createServiceProvider,
|
|
34467
|
+
getServiceProvidersForSite: _getServiceProvidersForSite
|
|
34468
|
+
} = useServiceProviderService();
|
|
34469
|
+
async function isSiteClient(req, siteId) {
|
|
34470
|
+
const actor = await resolveInviteActor(callerId(req));
|
|
34471
|
+
if (staffMayBypass(actor))
|
|
34472
|
+
return true;
|
|
34473
|
+
const site = await useSiteRepo().getSiteById(siteId).catch(() => null);
|
|
34474
|
+
const owner = (site?.orgId ?? site?.org)?.toString?.() ?? "";
|
|
34475
|
+
return Boolean(owner) && actor.orgIds.includes(owner);
|
|
34476
|
+
}
|
|
34247
34477
|
const { createServiceProvider: _add } = useServiceProviderRepo();
|
|
34248
34478
|
async function createServiceProvider(req, res, next) {
|
|
34249
34479
|
const validation = import_joi46.default.string().hex().required();
|
|
@@ -34272,7 +34502,12 @@ function useServiceProviderController() {
|
|
|
34272
34502
|
orgId: import_joi46.default.string().hex().optional().allow("", null),
|
|
34273
34503
|
siteId: import_joi46.default.string().hex().optional().allow("", null),
|
|
34274
34504
|
serviceProviderOrgId: import_joi46.default.string().hex().optional().allow("", null),
|
|
34275
|
-
status: import_joi46.default.string().optional().allow("", null)
|
|
34505
|
+
status: import_joi46.default.string().optional().allow("", null),
|
|
34506
|
+
// "engagements": also list providers engaged through an accepted
|
|
34507
|
+
// invitation. Opt-in, because those rows carry the engagement's id, not
|
|
34508
|
+
// a service-providers id - a caller that stores the id (the MA app's
|
|
34509
|
+
// feedback provider picker) must keep getting stored rows only.
|
|
34510
|
+
include: import_joi46.default.string().valid("engagements").optional().allow("", null)
|
|
34276
34511
|
});
|
|
34277
34512
|
const query2 = { ...req.query };
|
|
34278
34513
|
const { error } = validation.validate(query2);
|
|
@@ -34289,7 +34524,9 @@ function useServiceProviderController() {
|
|
|
34289
34524
|
const serviceProviderOrgId = req.query.serviceProviderOrgId ?? "";
|
|
34290
34525
|
const status = req.query.status ?? "active";
|
|
34291
34526
|
try {
|
|
34292
|
-
|
|
34527
|
+
if (siteId)
|
|
34528
|
+
await requireSiteReach(req, siteId);
|
|
34529
|
+
const data = req.query.include === "engagements" && siteId && status === "active" && !orgId && !serviceProviderOrgId && await isSiteClient(req, siteId) ? await _getServiceProvidersForSite({ search, page, limit, siteId }) : await _getServiceProviders({
|
|
34293
34530
|
search,
|
|
34294
34531
|
page,
|
|
34295
34532
|
limit,
|
|
@@ -86044,6 +86281,8 @@ var Period = /* @__PURE__ */ ((Period2) => {
|
|
|
86044
86281
|
Period2["THIS_MONTH"] = "thisMonth";
|
|
86045
86282
|
return Period2;
|
|
86046
86283
|
})(Period || {});
|
|
86284
|
+
var WORK_ORDER_DELETED = ["Deleted", "deleted"];
|
|
86285
|
+
var WORK_ORDER_NOT_OPEN = ["Completed", ...WORK_ORDER_DELETED];
|
|
86047
86286
|
function useNewDashboardRepo() {
|
|
86048
86287
|
const db2 = import_node_server_utils252.useAtlas.getDb();
|
|
86049
86288
|
if (!db2) {
|
|
@@ -86145,7 +86384,7 @@ function useNewDashboardRepo() {
|
|
|
86145
86384
|
$match: {
|
|
86146
86385
|
site: { $in: [siteIdObj, siteId] },
|
|
86147
86386
|
service: "Security",
|
|
86148
|
-
status: { $nin:
|
|
86387
|
+
status: { $nin: WORK_ORDER_NOT_OPEN }
|
|
86149
86388
|
}
|
|
86150
86389
|
},
|
|
86151
86390
|
{
|
|
@@ -86177,7 +86416,7 @@ function useNewDashboardRepo() {
|
|
|
86177
86416
|
site: { $in: [siteIdObj, siteId] },
|
|
86178
86417
|
service: "Security",
|
|
86179
86418
|
createdAt: priorPeriodRange,
|
|
86180
|
-
status: { $nin:
|
|
86419
|
+
status: { $nin: WORK_ORDER_NOT_OPEN }
|
|
86181
86420
|
}
|
|
86182
86421
|
},
|
|
86183
86422
|
{ $count: "count" }
|
|
@@ -86188,7 +86427,7 @@ function useNewDashboardRepo() {
|
|
|
86188
86427
|
site: { $in: [siteIdObj, siteId] },
|
|
86189
86428
|
service: "Security",
|
|
86190
86429
|
createdAt: periodRange,
|
|
86191
|
-
status: { $nin:
|
|
86430
|
+
status: { $nin: WORK_ORDER_NOT_OPEN }
|
|
86192
86431
|
}
|
|
86193
86432
|
},
|
|
86194
86433
|
{ $count: "count" }
|
|
@@ -86548,7 +86787,7 @@ function useNewDashboardRepo() {
|
|
|
86548
86787
|
{
|
|
86549
86788
|
$match: {
|
|
86550
86789
|
site: { $in: [siteIdObj, siteId] },
|
|
86551
|
-
status: { $nin:
|
|
86790
|
+
status: { $nin: WORK_ORDER_NOT_OPEN }
|
|
86552
86791
|
}
|
|
86553
86792
|
},
|
|
86554
86793
|
{
|
|
@@ -86579,7 +86818,7 @@ function useNewDashboardRepo() {
|
|
|
86579
86818
|
$match: {
|
|
86580
86819
|
site: { $in: [siteIdObj, siteId] },
|
|
86581
86820
|
createdAt: priorPeriodRange,
|
|
86582
|
-
status: { $nin:
|
|
86821
|
+
status: { $nin: WORK_ORDER_NOT_OPEN }
|
|
86583
86822
|
}
|
|
86584
86823
|
},
|
|
86585
86824
|
{ $count: "count" }
|
|
@@ -86589,7 +86828,7 @@ function useNewDashboardRepo() {
|
|
|
86589
86828
|
$match: {
|
|
86590
86829
|
site: { $in: [siteIdObj, siteId] },
|
|
86591
86830
|
createdAt: periodRange,
|
|
86592
|
-
status: { $nin:
|
|
86831
|
+
status: { $nin: WORK_ORDER_NOT_OPEN }
|
|
86593
86832
|
}
|
|
86594
86833
|
},
|
|
86595
86834
|
{ $count: "count" }
|
|
@@ -86773,7 +87012,8 @@ function useNewDashboardRepo() {
|
|
|
86773
87012
|
{
|
|
86774
87013
|
$match: {
|
|
86775
87014
|
site: { $in: [siteIdObj, siteId] },
|
|
86776
|
-
createdAt: periodRange
|
|
87015
|
+
createdAt: periodRange,
|
|
87016
|
+
status: { $nin: WORK_ORDER_DELETED }
|
|
86777
87017
|
}
|
|
86778
87018
|
},
|
|
86779
87019
|
{
|
|
@@ -86935,7 +87175,7 @@ function useNewDashboardRepo() {
|
|
|
86935
87175
|
const workOrderService = workOrderServiceMap[serviceType] ?? serviceType;
|
|
86936
87176
|
const workOrderMatchQuery = {
|
|
86937
87177
|
site,
|
|
86938
|
-
status: { $nin:
|
|
87178
|
+
status: { $nin: WORK_ORDER_NOT_OPEN }
|
|
86939
87179
|
};
|
|
86940
87180
|
if (serviceType !== "property_management_agency") {
|
|
86941
87181
|
workOrderMatchQuery.service = workOrderService;
|
|
@@ -87111,7 +87351,7 @@ function useNewDashboardRepo() {
|
|
|
87111
87351
|
try {
|
|
87112
87352
|
const workOrderQuery = {
|
|
87113
87353
|
site,
|
|
87114
|
-
status: { $nin:
|
|
87354
|
+
status: { $nin: WORK_ORDER_DELETED },
|
|
87115
87355
|
$or: [
|
|
87116
87356
|
{ createdAt: { $gte: rangeStart, $lte: rangeEnd } },
|
|
87117
87357
|
{
|
|
@@ -87830,7 +88070,7 @@ function filterByShiftTime(attendance, shiftData, timezone, format2) {
|
|
|
87830
88070
|
return checkInLocal.isBetween(shiftStart, shiftEnd, null, "[]");
|
|
87831
88071
|
});
|
|
87832
88072
|
}
|
|
87833
|
-
function
|
|
88073
|
+
function paginate59(data, page, limit) {
|
|
87834
88074
|
const length = data.length;
|
|
87835
88075
|
const startIndex = (page - 1) * limit;
|
|
87836
88076
|
const endIndex = startIndex + limit;
|
|
@@ -88178,7 +88418,7 @@ var hrmlabs_attendance_util_default = {
|
|
|
88178
88418
|
hrmLabsAuthentication,
|
|
88179
88419
|
fetchAttendanceData,
|
|
88180
88420
|
filterByShiftTime,
|
|
88181
|
-
paginate:
|
|
88421
|
+
paginate: paginate59,
|
|
88182
88422
|
designationCount,
|
|
88183
88423
|
totalCountPerShift,
|
|
88184
88424
|
filterByStatus,
|
|
@@ -89915,7 +90155,7 @@ var {
|
|
|
89915
90155
|
hrmLabsAuthentication: hrmLabsAuthentication3,
|
|
89916
90156
|
fetchAttendanceData: fetchAttendanceData2,
|
|
89917
90157
|
filterByShiftTime: filterByShiftTime2,
|
|
89918
|
-
paginate:
|
|
90158
|
+
paginate: paginate65,
|
|
89919
90159
|
designationCount: designationCount2,
|
|
89920
90160
|
totalCountPerShift: totalCountPerShift2,
|
|
89921
90161
|
filterByStatus: filterByStatus2,
|
|
@@ -90025,7 +90265,7 @@ function useHrmLabsAttendanceSrvc() {
|
|
|
90025
90265
|
status
|
|
90026
90266
|
);
|
|
90027
90267
|
}
|
|
90028
|
-
const paginatedItems =
|
|
90268
|
+
const paginatedItems = paginate65(filteredAttendance, page, limit);
|
|
90029
90269
|
return {
|
|
90030
90270
|
items: paginatedItems.items,
|
|
90031
90271
|
pages: paginatedItems.pages,
|
|
@@ -94325,6 +94565,7 @@ function useServiceProviderInviteController() {
|
|
|
94325
94565
|
try {
|
|
94326
94566
|
const schema2 = import_joi149.default.object({
|
|
94327
94567
|
org: import_joi149.default.string().hex().length(24).optional().allow("", null),
|
|
94568
|
+
siteId: import_joi149.default.string().hex().length(24).optional().allow("", null),
|
|
94328
94569
|
status: import_joi149.default.string().optional().allow("", null),
|
|
94329
94570
|
search: import_joi149.default.string().max(200).optional().allow("", null),
|
|
94330
94571
|
page: import_joi149.default.number().min(1).default(1),
|
|
@@ -94334,10 +94575,13 @@ function useServiceProviderInviteController() {
|
|
|
94334
94575
|
if (error)
|
|
94335
94576
|
throw new import_node_server_utils282.BadRequestError(`Invalid input: ${error.message}`);
|
|
94336
94577
|
const statuses = String(value.status ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
94578
|
+
if (value.siteId)
|
|
94579
|
+
await requireSiteReach(req, value.siteId);
|
|
94337
94580
|
res.json(
|
|
94338
94581
|
await listForCaller({
|
|
94339
94582
|
userId: callerId5(req),
|
|
94340
94583
|
orgId: value.org || void 0,
|
|
94584
|
+
siteId: value.siteId || void 0,
|
|
94341
94585
|
statuses,
|
|
94342
94586
|
search: value.search || "",
|
|
94343
94587
|
page: value.page,
|