@7365admin1/core 3.96.1-staging.366 → 3.96.1-staging.367
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/hid-sip-account-unit-label.md +40 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +98 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": minor
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Return the owner's block, level and unit with each HID SIP account.
|
|
6
|
+
|
|
7
|
+
`listSipAccounts` answered a name, email and extension per account, which is
|
|
8
|
+
enough to say who holds an extension but not which home it reaches. Two
|
|
9
|
+
residents called Harris were indistinguishable in the intercom contact picker,
|
|
10
|
+
and the contact saved onto the reader carried no address at all — so the door
|
|
11
|
+
panel's contact list named a person without saying whose unit was being rung.
|
|
12
|
+
|
|
13
|
+
Each row now carries `unitLabel`, the readable `Blk 1/Level 1/Unit 1`. The three
|
|
14
|
+
stored values are ObjectIds into `buildings`, `building-levels` and
|
|
15
|
+
`building-units`, so every one is resolved to its name; joining the raw values
|
|
16
|
+
would stamp `665f.../665f.../665f...` onto the reader. A block carries both a
|
|
17
|
+
number and an optional descriptive name and the short number wins, because the
|
|
18
|
+
label is read off a door panel.
|
|
19
|
+
|
|
20
|
+
The address comes from `site.people` first — where it is edited, and the source
|
|
21
|
+
`loadPermissionSubjects` already trusts for a resident's subtitle — and falls
|
|
22
|
+
back to the copy `person.service` keeps on `users`, for an account whose owner
|
|
23
|
+
has no active person row on the site.
|
|
24
|
+
|
|
25
|
+
An owner with neither does not live here, so `unitLabel` carries their
|
|
26
|
+
membership type instead — "Security Agency" rather than nothing — read from a
|
|
27
|
+
live `members` row on the SAME site. A user can hold several memberships (the
|
|
28
|
+
unique index is `org_1_siteId_1_user_1_type_1`), so a non-organization row is
|
|
29
|
+
preferred: "organization" names the company that employs them, not what they are
|
|
30
|
+
at this door. It is still used when it is the only membership there is. A `type`
|
|
31
|
+
of 24 hex characters is dropped rather than printed — `MMember` accepts an
|
|
32
|
+
organisation id in that field, and stamping one onto the reader's contact list
|
|
33
|
+
would be the same defect as joining the raw block and level ids.
|
|
34
|
+
|
|
35
|
+
`""` only when the site knows neither, which the picker reads as "no suffix" and
|
|
36
|
+
leaves the bare name.
|
|
37
|
+
|
|
38
|
+
Four id-keyed lookups for the whole list, not one per row, and the `members`
|
|
39
|
+
read is skipped entirely when every owner already has an address. The response
|
|
40
|
+
still never contains a SIP password.
|
package/dist/index.d.ts
CHANGED
|
@@ -16765,6 +16765,7 @@ declare function useHidAmicoRepo(): {
|
|
|
16765
16765
|
userId: string;
|
|
16766
16766
|
name: string;
|
|
16767
16767
|
email: string;
|
|
16768
|
+
unitLabel: string;
|
|
16768
16769
|
extension: string;
|
|
16769
16770
|
username: string;
|
|
16770
16771
|
status: string;
|
|
@@ -17494,6 +17495,7 @@ declare function useHidAmicoService(): {
|
|
|
17494
17495
|
userId: string;
|
|
17495
17496
|
name: string;
|
|
17496
17497
|
email: string;
|
|
17498
|
+
unitLabel: string;
|
|
17497
17499
|
extension: string;
|
|
17498
17500
|
username: string;
|
|
17499
17501
|
status: string;
|
package/dist/index.js
CHANGED
|
@@ -47891,10 +47891,104 @@ function useHidAmicoRepo() {
|
|
|
47891
47891
|
status: { $ne: "disabled" }
|
|
47892
47892
|
});
|
|
47893
47893
|
}
|
|
47894
|
+
function memberTypeLabel(value) {
|
|
47895
|
+
const type = String(value ?? "").trim();
|
|
47896
|
+
if (!type || /^[a-fA-F0-9]{24}$/.test(type))
|
|
47897
|
+
return "";
|
|
47898
|
+
return type.split(/[_\s]+/).filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
47899
|
+
}
|
|
47900
|
+
function isOrganizationMemberType(value) {
|
|
47901
|
+
return String(value ?? "").trim().toLowerCase() === "organization";
|
|
47902
|
+
}
|
|
47903
|
+
async function loadUnitLabels(siteId, userIds, userMap) {
|
|
47904
|
+
const labels = /* @__PURE__ */ new Map();
|
|
47905
|
+
if (!userIds.length)
|
|
47906
|
+
return labels;
|
|
47907
|
+
const people = await db2().collection("site.people").find({
|
|
47908
|
+
site: siteId,
|
|
47909
|
+
user: { $in: userIds },
|
|
47910
|
+
status: "active"
|
|
47911
|
+
}, {
|
|
47912
|
+
projection: { user: 1, block: 1, level: 1, unit: 1, unitName: 1 }
|
|
47913
|
+
}).toArray();
|
|
47914
|
+
const peopleMap = new Map(people.map((row) => [String(row.user), row]));
|
|
47915
|
+
const addressOf = (key) => {
|
|
47916
|
+
const person = peopleMap.get(key);
|
|
47917
|
+
if (person) {
|
|
47918
|
+
return {
|
|
47919
|
+
block: optionalObjectId2(person.block),
|
|
47920
|
+
level: optionalObjectId2(person.level),
|
|
47921
|
+
unit: optionalObjectId2(person.unit),
|
|
47922
|
+
unitName: String(person.unitName || "")
|
|
47923
|
+
};
|
|
47924
|
+
}
|
|
47925
|
+
const user = userMap.get(key);
|
|
47926
|
+
return {
|
|
47927
|
+
block: optionalObjectId2(user?.block),
|
|
47928
|
+
level: optionalObjectId2(user?.level),
|
|
47929
|
+
unit: optionalObjectId2(user?.unitId),
|
|
47930
|
+
unitName: String(user?.unitName || "")
|
|
47931
|
+
};
|
|
47932
|
+
};
|
|
47933
|
+
const addresses = new Map(userIds.map((userId) => {
|
|
47934
|
+
const key = String(userId);
|
|
47935
|
+
return [key, addressOf(key)];
|
|
47936
|
+
}));
|
|
47937
|
+
const collect = (pick) => {
|
|
47938
|
+
const seen2 = /* @__PURE__ */ new Map();
|
|
47939
|
+
for (const address of addresses.values()) {
|
|
47940
|
+
const id = pick(address);
|
|
47941
|
+
if (id)
|
|
47942
|
+
seen2.set(String(id), id);
|
|
47943
|
+
}
|
|
47944
|
+
return [...seen2.values()];
|
|
47945
|
+
};
|
|
47946
|
+
const lookup = async (collection, ids2, projection) => {
|
|
47947
|
+
if (!ids2.length)
|
|
47948
|
+
return /* @__PURE__ */ new Map();
|
|
47949
|
+
const rows = await db2().collection(collection).find(
|
|
47950
|
+
{ _id: { $in: ids2 } },
|
|
47951
|
+
{ projection }
|
|
47952
|
+
).toArray();
|
|
47953
|
+
return new Map(rows.map((row) => [String(row._id), row]));
|
|
47954
|
+
};
|
|
47955
|
+
const [blocks, levels, units] = await Promise.all([
|
|
47956
|
+
lookup("buildings", collect((address) => address.block), { block: 1, name: 1 }),
|
|
47957
|
+
lookup("building-levels", collect((address) => address.level), { name: 1 }),
|
|
47958
|
+
lookup("building-units", collect((address) => address.unit), { name: 1 })
|
|
47959
|
+
]);
|
|
47960
|
+
for (const [key, address] of addresses) {
|
|
47961
|
+
const blockRow = address.block ? blocks.get(String(address.block)) : void 0;
|
|
47962
|
+
const blockLabel = blockRow ? blockRow.block ? `Blk ${String(blockRow.block)}` : String(blockRow.name || "") : "";
|
|
47963
|
+
const levelLabel = address.level ? String(levels.get(String(address.level))?.name || "") : "";
|
|
47964
|
+
const unitLabel = (address.unit ? String(units.get(String(address.unit))?.name || "") : "") || address.unitName;
|
|
47965
|
+
labels.set(key, [blockLabel, levelLabel, unitLabel].filter(Boolean).join("/"));
|
|
47966
|
+
}
|
|
47967
|
+
const withoutAddress = userIds.filter((userId) => !labels.get(String(userId)));
|
|
47968
|
+
if (!withoutAddress.length)
|
|
47969
|
+
return labels;
|
|
47970
|
+
const members = await db2().collection("members").find({
|
|
47971
|
+
siteId,
|
|
47972
|
+
user: { $in: withoutAddress },
|
|
47973
|
+
status: "active"
|
|
47974
|
+
}, {
|
|
47975
|
+
projection: { user: 1, type: 1 }
|
|
47976
|
+
}).toArray();
|
|
47977
|
+
const ordered = [...members].sort((left, right) => Number(isOrganizationMemberType(left.type)) - Number(isOrganizationMemberType(right.type)));
|
|
47978
|
+
for (const member of ordered) {
|
|
47979
|
+
const key = String(member.user);
|
|
47980
|
+
const label2 = memberTypeLabel(member.type);
|
|
47981
|
+
if (!label2 || labels.get(key))
|
|
47982
|
+
continue;
|
|
47983
|
+
labels.set(key, label2);
|
|
47984
|
+
}
|
|
47985
|
+
return labels;
|
|
47986
|
+
}
|
|
47894
47987
|
async function listSipAccounts(orgIdValue, siteValue) {
|
|
47988
|
+
const siteId = toId4(siteValue, "site ID");
|
|
47895
47989
|
const accounts = await sipAccounts().find({
|
|
47896
47990
|
orgId: toId4(orgIdValue, "organization ID"),
|
|
47897
|
-
site:
|
|
47991
|
+
site: siteId,
|
|
47898
47992
|
status: { $ne: "disabled" }
|
|
47899
47993
|
}, {
|
|
47900
47994
|
projection: { user: 1, extension: 1, username: 1, status: 1, provisionedAt: 1 }
|
|
@@ -47902,9 +47996,10 @@ function useHidAmicoRepo() {
|
|
|
47902
47996
|
const userIds = accounts.map((account) => optionalObjectId2(account.user)).filter((value) => Boolean(value));
|
|
47903
47997
|
const users = userIds.length ? await db2().collection("users").find(
|
|
47904
47998
|
{ _id: { $in: userIds } },
|
|
47905
|
-
{ projection: { name: 1, email: 1 } }
|
|
47999
|
+
{ projection: { name: 1, email: 1, block: 1, level: 1, unitId: 1, unitName: 1 } }
|
|
47906
48000
|
).toArray() : [];
|
|
47907
48001
|
const userMap = new Map(users.map((user) => [String(user._id), user]));
|
|
48002
|
+
const unitLabels = await loadUnitLabels(siteId, userIds, userMap);
|
|
47908
48003
|
return accounts.map((account) => {
|
|
47909
48004
|
const user = userMap.get(String(account.user));
|
|
47910
48005
|
return {
|
|
@@ -47912,6 +48007,7 @@ function useHidAmicoRepo() {
|
|
|
47912
48007
|
userId: String(account.user),
|
|
47913
48008
|
name: String(user?.name || user?.email || ""),
|
|
47914
48009
|
email: String(user?.email || ""),
|
|
48010
|
+
unitLabel: unitLabels.get(String(account.user)) || "",
|
|
47915
48011
|
extension: String(account.extension || ""),
|
|
47916
48012
|
username: String(account.username || ""),
|
|
47917
48013
|
status: String(account.status || ""),
|