@7365admin1/layer-common 4.90.1 → 4.90.2-staging.484
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 +4 -4
- package/assets/css/primitives.css +57 -0
- package/assets/css/robot-hero.css +3 -0
- package/assets/css/screens.css +8 -4
- package/components/AccessCardDetailsDialog.vue +57 -4
- package/components/AccessCardPreviewDialog.vue +291 -50
- package/components/AppSelect.vue +143 -4
- package/components/BuildingUnitFormEdit.vue +6 -0
- package/components/BuildingUnitManagement.vue +298 -0
- package/components/ClientMain.vue +56 -14
- package/components/Dialog/UpdateMoreAction.vue +11 -1
- package/components/DocumentForm.vue +407 -112
- package/components/DocumentManagement.vue +213 -12
- package/components/Facility/BookingSetup.vue +63 -0
- package/components/HidAccessLogDashboard.vue +74 -17
- package/components/HidAccessPermissions.vue +424 -0
- package/components/HidIntercomManagement.vue +183 -14
- package/components/HidProfileQrCode.vue +332 -0
- package/components/HidQrCodeConfiguration.vue +17 -195
- package/components/HidReaderManagement.vue +398 -0
- package/components/HidReaderUserRoster.vue +44 -3
- package/components/HidUserEnrollment.vue +2239 -276
- package/components/InvitationClientForm.vue +19 -1
- package/components/MemberInformation.vue +4 -4
- package/components/PassInformation.vue +2 -2
- package/components/TableMain.vue +22 -7
- package/components/VisitorForm.vue +65 -19
- package/components/VisitorManagement.vue +267 -5
- package/composables/useDocument.ts +7 -0
- package/composables/useFacility.ts +11 -0
- package/composables/useHidAmico.ts +165 -0
- package/composables/useHidNavigation.ts +25 -1
- package/composables/useHidReaderSelection.ts +50 -0
- package/composables/useMember.ts +12 -0
- package/composables/useNFCPatrolReportFilters.ts +21 -3
- package/composables/useNFCPatrolRoute.ts +8 -1
- package/composables/usePeople.ts +19 -0
- package/composables/useServiceProvider.ts +45 -2
- package/composables/useSiteCategory.ts +45 -0
- package/package.json +1 -1
- package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
- package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
- package/types/document.d.ts +14 -0
- package/types/facility.d.ts +4 -0
- package/types/member.d.ts +4 -0
- package/types/people.d.ts +28 -1
- package/types/service-provider.d.ts +5 -0
- package/types/site.d.ts +7 -1
- package/utils/hid-enrolment-subject.ts +344 -0
- package/utils/hid-permission-assignments.ts +198 -0
- package/utils/hid-reader-selection.ts +52 -0
- package/utils/occupancy-role.ts +109 -0
- package/utils/service-type.ts +30 -0
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
:org="orgId"
|
|
6
6
|
message="Enable HID as a service for this site before managing physical HID cards."
|
|
7
7
|
>
|
|
8
|
-
<HidUserEnrollment :site="siteId" card-management />
|
|
8
|
+
<HidUserEnrollment :site="siteId" :org="orgId" card-management />
|
|
9
9
|
</HidEnabledGate>
|
|
10
10
|
</v-container>
|
|
11
11
|
</template>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-container fluid>
|
|
3
|
+
<HidEnabledGate
|
|
4
|
+
:site="siteId"
|
|
5
|
+
:org="orgId"
|
|
6
|
+
message="Enable HID as a service for this site before generating a QR code."
|
|
7
|
+
>
|
|
8
|
+
<HidProfileQrCode :site="siteId" />
|
|
9
|
+
</HidEnabledGate>
|
|
10
|
+
</v-container>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
definePageMeta({
|
|
15
|
+
layout: "default",
|
|
16
|
+
middleware: ["01-auth", "02-org"],
|
|
17
|
+
memberOnly: true,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const route = useRoute();
|
|
21
|
+
const siteId = computed(() => String(route.params.site ?? ""));
|
|
22
|
+
const orgId = computed(() => String(route.params.org ?? ""));
|
|
23
|
+
</script>
|
package/types/document.d.ts
CHANGED
|
@@ -3,4 +3,18 @@ declare type TDocument = {
|
|
|
3
3
|
name: string;
|
|
4
4
|
attachment: string;
|
|
5
5
|
type: string;
|
|
6
|
+
/**
|
|
7
|
+
* Set at upload or renewal, absent when the document never expires.
|
|
8
|
+
*
|
|
9
|
+
* An ISO instant on the way out of the API and a `YYYY-MM-DD` string on the
|
|
10
|
+
* way back in, which is what `InputDatePicker` binds to - hence the loose
|
|
11
|
+
* type rather than `string`.
|
|
12
|
+
*/
|
|
13
|
+
expiryDate?: string | Date | null;
|
|
14
|
+
remarks?: string;
|
|
15
|
+
size?: number;
|
|
16
|
+
parentId?: string | null;
|
|
17
|
+
createdAt?: string | Date;
|
|
18
|
+
updatedAt?: string | Date;
|
|
19
|
+
status?: string;
|
|
6
20
|
};
|
package/types/facility.d.ts
CHANGED
|
@@ -73,6 +73,10 @@ declare type TFacility = {
|
|
|
73
73
|
hourInterval?: number;
|
|
74
74
|
isBookingFeeEnabled: boolean;
|
|
75
75
|
isGuestEnabled: boolean;
|
|
76
|
+
/** Residents may complete this facility's checklist themselves. */
|
|
77
|
+
isResidentChecklistEnabled?: boolean;
|
|
78
|
+
/** Security may complete it. Mutually exclusive with the above. */
|
|
79
|
+
isSecurityChecklistEnabled?: boolean;
|
|
76
80
|
bookingAmount: number | null;
|
|
77
81
|
peakBookingFeeAmount?: number | null;
|
|
78
82
|
bookingFeeGuestAmount?: number | null;
|
package/types/member.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ declare type TMember = {
|
|
|
10
10
|
customerOrgId?: string;
|
|
11
11
|
customerSiteId?: string;
|
|
12
12
|
status?: string;
|
|
13
|
+
email?: string;
|
|
14
|
+
/** The building unit this member manages (a unit's Management tab). */
|
|
15
|
+
unit?: string | null;
|
|
16
|
+
unitName?: string;
|
|
13
17
|
createdAt?: string;
|
|
14
18
|
updatedAt?: string;
|
|
15
19
|
deletedAt?: string;
|
package/types/people.d.ts
CHANGED
|
@@ -22,11 +22,38 @@ declare type TPeople = {
|
|
|
22
22
|
email?: string;
|
|
23
23
|
files?: { name: string, id: string }[];
|
|
24
24
|
isOwner?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Owner / occupant / person-in-charge, as the BUSINESS people form asks it.
|
|
27
|
+
* Absent on everyone else - `isOwner` is still the flag that decides unit
|
|
28
|
+
* ownership, and the server derives it from this when it is sent. See
|
|
29
|
+
* `OccupancyRoles` in core's `person.model.ts`.
|
|
30
|
+
*/
|
|
31
|
+
occupancyRole?: TOccupancyRole;
|
|
32
|
+
// Link to this person's `users` row. Empty for the person types that carry
|
|
33
|
+
// no login, and empty for a resident whose account was never written.
|
|
34
|
+
user?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
declare type TOccupancyRole = "owner" | "occupant" | "person-in-charge";
|
|
38
|
+
|
|
39
|
+
/** One standing and everything the product says about it. See `utils/occupancy-role.ts`. */
|
|
40
|
+
declare type TOccupancyRoleOption = {
|
|
41
|
+
value: TOccupancyRole;
|
|
42
|
+
/** The label a stored role is printed with. */
|
|
43
|
+
title: string;
|
|
44
|
+
/** The row menu's wording. */
|
|
45
|
+
action: string;
|
|
46
|
+
/** The confirmation's heading and its sentence. */
|
|
47
|
+
prompt: string;
|
|
48
|
+
description: string;
|
|
25
49
|
};
|
|
26
50
|
|
|
27
51
|
declare type TPlateNumber = { plateNumber: string, recNo?: string, _id?: string, status: TVehicleStatus, type: TVehicleType, anprCameras?: TVehicleAnprCamera[] };
|
|
28
52
|
|
|
29
53
|
|
|
30
|
-
|
|
54
|
+
// `""` is the FORM's "nothing picked yet" - it is stripped from the payload
|
|
55
|
+
// before it is sent, because absence is what the server reads as "never
|
|
56
|
+
// asked". See `PeopleFormMgmt.vue`.
|
|
57
|
+
declare type TPeoplePayload = Pick<TGuest, "name" | "block" | "level" | "unit" | "unitName" | "contact" | "plateNumber" | "nric" | "contact" | "remarks" | "org" | "site" | "start" | "end" | "type" | "isOwner"> & { status?: string; user?: string; occupancyRole?: TOccupancyRole | "" }
|
|
31
58
|
|
|
32
59
|
declare type TPeopleType = "guest" | "resident" | "tenant"
|
|
@@ -7,6 +7,11 @@ declare type TServiceProvider = {
|
|
|
7
7
|
serviceProviderOrgId: string;
|
|
8
8
|
type: string;
|
|
9
9
|
nature: string;
|
|
10
|
+
status?: string;
|
|
11
|
+
email?: string;
|
|
12
|
+
/** The building unit this provider serves (a unit's Management tab). */
|
|
13
|
+
unit?: string | null;
|
|
14
|
+
unitName?: string;
|
|
10
15
|
};
|
|
11
16
|
|
|
12
17
|
declare type TServiceProviderName = {
|
package/types/site.d.ts
CHANGED
|
@@ -5,7 +5,10 @@ declare type THidQrCodeFormat = "0" | "1" | "2";
|
|
|
5
5
|
declare type THidPermissionCategory =
|
|
6
6
|
| "resident"
|
|
7
7
|
| "property_management"
|
|
8
|
-
|
|
8
|
+
/** A provider COMPANY - granting one admits every active member of that org. */
|
|
9
|
+
| "service_provider"
|
|
10
|
+
/** ONE PERSON from a provider company, by their membership at this site. */
|
|
11
|
+
| "service_provider_member";
|
|
9
12
|
|
|
10
13
|
declare type THidPermissionAssignment = {
|
|
11
14
|
subjectId: string;
|
|
@@ -27,7 +30,10 @@ declare type THidSitePermissions = {
|
|
|
27
30
|
counts: {
|
|
28
31
|
resident: number;
|
|
29
32
|
propertyManagement: number;
|
|
33
|
+
/** Provider COMPANIES granted. */
|
|
30
34
|
serviceProvider: number;
|
|
35
|
+
/** Named provider people granted. Counted apart from the companies. */
|
|
36
|
+
serviceProviderMember: number;
|
|
31
37
|
intercom: number;
|
|
32
38
|
};
|
|
33
39
|
};
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHO A HID ENROLMENT IS FOR — the pure decisions behind the subject picker.
|
|
3
|
+
*
|
|
4
|
+
* `HidUserEnrollment.vue` can enrol a resident or a staff member. The write path
|
|
5
|
+
* always carried both (`subjectLink` maps them onto `person` or `member`); what
|
|
6
|
+
* was missing was a way to choose. These are the parts of that choice worth
|
|
7
|
+
* testing on their own, kept here because a `.vue` component has no test harness
|
|
8
|
+
* in this repo.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* What the ENROLLING dropdown offers. Three of these four are the server's own
|
|
13
|
+
* permission categories; `service_provider_staff` is this screen's own value
|
|
14
|
+
* and deliberately not one of them - see `subjectLinkOf`.
|
|
15
|
+
*/
|
|
16
|
+
export type HidEnrolmentSubject =
|
|
17
|
+
| "resident"
|
|
18
|
+
| "property_management"
|
|
19
|
+
| "service_provider_staff";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The dropdown's options, in the order they are drawn.
|
|
23
|
+
*
|
|
24
|
+
* `title`/`value` because `AppSelect` takes that shape.
|
|
25
|
+
*/
|
|
26
|
+
export const HID_ENROLMENT_SUBJECTS: ReadonlyArray<{
|
|
27
|
+
title: string;
|
|
28
|
+
value: HidEnrolmentSubject;
|
|
29
|
+
}> = [
|
|
30
|
+
{ title: "Resident", value: "resident" },
|
|
31
|
+
{ title: "Member", value: "property_management" },
|
|
32
|
+
{ title: "Service provider", value: "service_provider_staff" },
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* What an EDIT calls the subject it is already attached to.
|
|
37
|
+
*
|
|
38
|
+
* Wider than the dropdown on purpose. An identity's category cannot change after
|
|
39
|
+
* it is created, so an edit states it rather than offering it — and the records
|
|
40
|
+
* in the wild include `service_provider`, which the dropdown does not offer yet
|
|
41
|
+
* but `openEdit` does resolve. Falling back to the first option would label a
|
|
42
|
+
* contractor "Resident", which is worse than saying nothing useful.
|
|
43
|
+
*/
|
|
44
|
+
export function subjectCategoryLabel(category: unknown): string {
|
|
45
|
+
const labels: Record<string, string> = {
|
|
46
|
+
resident: "Resident",
|
|
47
|
+
property_management: "Member",
|
|
48
|
+
// The dropdown's own value: ONE PERSON from a provider company.
|
|
49
|
+
service_provider_staff: "Service provider",
|
|
50
|
+
// The server's category, which names a COMPANY. Records in the wild carry
|
|
51
|
+
// it, and an edit must not call such a row a resident.
|
|
52
|
+
service_provider: "Service provider",
|
|
53
|
+
visitor: "Visitor",
|
|
54
|
+
};
|
|
55
|
+
return labels[String(category ?? "")] ?? "Unknown";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* One page of `GET /api/members`, read defensively.
|
|
60
|
+
*
|
|
61
|
+
* `paginate` puts `{ items, pages }` at the root, but `items` sits under `data`
|
|
62
|
+
* on some of this product's endpoints, so both are read — the same allowance
|
|
63
|
+
* `readCandidatePage` makes. A response that carries neither is an empty page
|
|
64
|
+
* rather than a thrown error: an empty staff picker with a placeholder beats a
|
|
65
|
+
* broken dialog.
|
|
66
|
+
*/
|
|
67
|
+
export function readMemberPage(response: unknown): {
|
|
68
|
+
items: Record<string, unknown>[];
|
|
69
|
+
pages: number;
|
|
70
|
+
total: number;
|
|
71
|
+
} {
|
|
72
|
+
const source = (response && typeof response === "object" ? response : {}) as Record<string, unknown>;
|
|
73
|
+
const nested = (source.data && typeof source.data === "object" ? source.data : {}) as Record<string, unknown>;
|
|
74
|
+
const raw = Array.isArray(source.items)
|
|
75
|
+
? source.items
|
|
76
|
+
: Array.isArray(nested.items)
|
|
77
|
+
? nested.items
|
|
78
|
+
: [];
|
|
79
|
+
const pages = Number(source.pages ?? nested.pages ?? 1);
|
|
80
|
+
const items = raw.filter((row): row is Record<string, unknown> => Boolean(row) && typeof row === "object");
|
|
81
|
+
/*
|
|
82
|
+
* `total` drives "showing 10 of 23" and the Load more button. It falls back to
|
|
83
|
+
* the page's own length, not to zero, so a response without it simply reads as
|
|
84
|
+
* "this is everything" — a missing count must never make the button offer a
|
|
85
|
+
* page that is not there.
|
|
86
|
+
*/
|
|
87
|
+
const total = Number(source.total ?? nested.total ?? items.length);
|
|
88
|
+
return {
|
|
89
|
+
items,
|
|
90
|
+
pages: Number.isFinite(pages) && pages > 0 ? Math.floor(pages) : 1,
|
|
91
|
+
total: Number.isFinite(total) && total >= 0 ? Math.floor(total) : items.length,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Can this member actually be enrolled?
|
|
97
|
+
*
|
|
98
|
+
* Reader access is bound by USER id — `resolvePermissionUserBindings` in
|
|
99
|
+
* `iservice365-core` drops every subject without one — so a member with no app
|
|
100
|
+
* account cannot be given access and is not a candidate. The id arrives as a
|
|
101
|
+
* string from JSON but may be an object if a caller passes a raw document, so
|
|
102
|
+
* both are read rather than trusting the shape.
|
|
103
|
+
*/
|
|
104
|
+
export function memberHasAccount(row: Record<string, unknown> | null | undefined): boolean {
|
|
105
|
+
const user = row?.user;
|
|
106
|
+
if (!user) return false;
|
|
107
|
+
if (typeof user === "object") {
|
|
108
|
+
const id = (user as { _id?: unknown; toString?: () => string })._id ?? user;
|
|
109
|
+
return Boolean(String(id ?? "").trim());
|
|
110
|
+
}
|
|
111
|
+
return Boolean(String(user).trim());
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* How a member reads in the picker: their name, and their role beneath it.
|
|
116
|
+
*
|
|
117
|
+
* THE ACCOUNT'S NAME FIRST, then the membership's. The two diverge — a
|
|
118
|
+
* membership is created with whatever name was typed at invite time, and the
|
|
119
|
+
* person may have set their own on the account since — and the account name is
|
|
120
|
+
* the one they are known by. `userName` comes from the members endpoint's own
|
|
121
|
+
* lookup into `users`; a member with no account has none, but such a row is not
|
|
122
|
+
* a candidate anyway (`memberHasAccount`).
|
|
123
|
+
*
|
|
124
|
+
* Every step falls back, because a row with no name at all still has to be
|
|
125
|
+
* selectable rather than blank, or it cannot be told apart from the next one.
|
|
126
|
+
*/
|
|
127
|
+
export function memberCandidateOf(row: Record<string, unknown>): {
|
|
128
|
+
subjectId: string;
|
|
129
|
+
name: string;
|
|
130
|
+
subtitle: string;
|
|
131
|
+
} {
|
|
132
|
+
const text = (value: unknown) => String(value ?? "").trim();
|
|
133
|
+
return {
|
|
134
|
+
subjectId: text(row._id),
|
|
135
|
+
name: text(row.userName) || text(row.name) || text(row.email) || "Member",
|
|
136
|
+
subtitle: text(row.roleName) || text(row.email) || "",
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Why somebody the operator can see elsewhere is not in this list.
|
|
142
|
+
*
|
|
143
|
+
* Left unexplained, an absence reads as a broken screen — the same reason the
|
|
144
|
+
* resident cascade carries `unitResidentNote`. Returns "" when there is nothing
|
|
145
|
+
* to say, so the caller can render it unconditionally.
|
|
146
|
+
*/
|
|
147
|
+
export function hiddenSubjectNote(count: number, noun: "resident" | "member"): string {
|
|
148
|
+
if (!Number.isFinite(count) || count <= 0) return "";
|
|
149
|
+
const whole = Math.floor(count);
|
|
150
|
+
const subject = whole === 1 ? `1 ${noun}` : `${whole} ${noun}s`;
|
|
151
|
+
const verb = whole === 1 ? "is" : "are";
|
|
152
|
+
const holder = whole === 1 ? "that person has" : "they have";
|
|
153
|
+
return `${subject} at this site ${verb} not listed:`
|
|
154
|
+
+ ` HID enrollment needs an app account, and ${holder} none yet.`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* ── THE LINK THAT REACHES THE DEVICE ──────────────────────────────────── */
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* WHICH SUBJECT FIELD AN ENROLMENT WRITES, and what the identity is called.
|
|
161
|
+
*
|
|
162
|
+
* This is the one decision in the dialog that changes who a door lets in, so it
|
|
163
|
+
* lives here with tests rather than inline in the template's script.
|
|
164
|
+
*
|
|
165
|
+
* `service_provider_staff` links through `member`, NOT `serviceProvider`, and
|
|
166
|
+
* that is the whole design:
|
|
167
|
+
*
|
|
168
|
+
* - `serviceProvider` names a `site.service-providers` row, which is a COMPANY.
|
|
169
|
+
* `resolvePermissionUserBindings` expands one into every active member of
|
|
170
|
+
* that organisation with NO site filter, so granting it puts a 200-person
|
|
171
|
+
* firm on a door that eight of them attend.
|
|
172
|
+
* - A provider employee's membership lives in `members` with `siteId` set to
|
|
173
|
+
* this site - `members` carries a unique index on `{org, siteId, user, type}`,
|
|
174
|
+
* so it cannot exist there without one. That makes the person site-scoped by
|
|
175
|
+
* construction, which is the whole point.
|
|
176
|
+
*
|
|
177
|
+
* The identity `type` is `"contractor"` rather than `"staff"`, and it is load
|
|
178
|
+
* bearing on the server as well as here: core's `permissionSubjectOfIdentity`
|
|
179
|
+
* reads it to tell a contractor's `member` link from a property-management one,
|
|
180
|
+
* and files the grant under `service_provider_member` or `property_management`
|
|
181
|
+
* accordingly. It is also what the Access Permissions tabs filter on.
|
|
182
|
+
*
|
|
183
|
+
* An earlier version filed provider staff under `property_management`, since that
|
|
184
|
+
* category's subject list already accepts these rows. It worked for access and
|
|
185
|
+
* failed for identity: `permissionIdentityType` derives the identity's type from
|
|
186
|
+
* the category, so every contractor came back as `staff` - and because the
|
|
187
|
+
* reconcile rewrites the identity it finds, the `"contractor"` written here was
|
|
188
|
+
* overwritten seconds later.
|
|
189
|
+
*
|
|
190
|
+
* An empty `subjectId` returns `{}` ON PURPOSE. Sending `person: ""` is not
|
|
191
|
+
* "leave this alone", it is "clear it": the server reads an empty string as the
|
|
192
|
+
* link being removed and then refuses the write for having no subject at all.
|
|
193
|
+
*/
|
|
194
|
+
export function subjectLinkOf(
|
|
195
|
+
category: unknown,
|
|
196
|
+
subjectId: unknown,
|
|
197
|
+
): {
|
|
198
|
+
person?: string;
|
|
199
|
+
member?: string;
|
|
200
|
+
serviceProvider?: string;
|
|
201
|
+
type?: "resident" | "staff" | "contractor";
|
|
202
|
+
} {
|
|
203
|
+
const id = String(subjectId ?? "").trim();
|
|
204
|
+
if (!id) return {};
|
|
205
|
+
const of = (
|
|
206
|
+
field: "person" | "member" | "serviceProvider",
|
|
207
|
+
type: "resident" | "staff" | "contractor",
|
|
208
|
+
) => ({
|
|
209
|
+
person: field === "person" ? id : "",
|
|
210
|
+
member: field === "member" ? id : "",
|
|
211
|
+
serviceProvider: field === "serviceProvider" ? id : "",
|
|
212
|
+
type,
|
|
213
|
+
});
|
|
214
|
+
switch (String(category ?? "")) {
|
|
215
|
+
case "resident":
|
|
216
|
+
return of("person", "resident");
|
|
217
|
+
case "service_provider_staff":
|
|
218
|
+
return of("member", "contractor");
|
|
219
|
+
case "service_provider":
|
|
220
|
+
return of("serviceProvider", "contractor");
|
|
221
|
+
default:
|
|
222
|
+
return of("member", "staff");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Which PERMISSION CATEGORY an enrolment's access grant is stored under.
|
|
228
|
+
*
|
|
229
|
+
* Mirrors `permissionSubjectOfIdentity` in core, which reads the stored links
|
|
230
|
+
* rather than this dropdown: a `member` link resolves to `property_management`
|
|
231
|
+
* whatever the identity's `type` says. Provider staff therefore share the staff
|
|
232
|
+
* category, which is correct - they are validated against the same subject list
|
|
233
|
+
* - and the identity `type` is what tells them apart on screen.
|
|
234
|
+
*/
|
|
235
|
+
export function permissionCategoryOf(category: unknown): string {
|
|
236
|
+
const value = String(category ?? "");
|
|
237
|
+
if (value === "resident") return "resident";
|
|
238
|
+
if (value === "service_provider") return "service_provider";
|
|
239
|
+
if (value === "service_provider_staff") return "service_provider_member";
|
|
240
|
+
return "property_management";
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* ── PROVIDER STAFF AS PICKER ROWS ─────────────────────────────────────── */
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Can this provider employee be enrolled?
|
|
247
|
+
*
|
|
248
|
+
* Two conditions, and both have to be checked here rather than trusted from the
|
|
249
|
+
* list. An app account, because reader access is bound by user id
|
|
250
|
+
* (`memberHasAccount`). And an ACTIVE membership: `getProviderMembersBySite`
|
|
251
|
+
* returns everyone who is not deleted, so a suspended person is in the list the
|
|
252
|
+
* Members screen draws - marked, deliberately, so the property manager can see
|
|
253
|
+
* them. Offering a suspended person a door is a different matter.
|
|
254
|
+
*/
|
|
255
|
+
export function providerCanEnrol(
|
|
256
|
+
row: Record<string, unknown> | null | undefined,
|
|
257
|
+
): boolean {
|
|
258
|
+
if (!memberHasAccount(row)) return false;
|
|
259
|
+
return String(row?.status ?? "").trim() === "active";
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* How a provider employee reads in the picker: their name, their company and
|
|
264
|
+
* the service beneath it.
|
|
265
|
+
*
|
|
266
|
+
* The company comes FIRST in the subtitle. Two contractors with the same first
|
|
267
|
+
* name are common, and which firm somebody belongs to is what the property
|
|
268
|
+
* manager actually recognises them by - the service type alone ("Security")
|
|
269
|
+
* describes half the list.
|
|
270
|
+
*/
|
|
271
|
+
export function providerCandidateOf(row: Record<string, unknown>): {
|
|
272
|
+
subjectId: string;
|
|
273
|
+
name: string;
|
|
274
|
+
subtitle: string;
|
|
275
|
+
} {
|
|
276
|
+
const text = (value: unknown) => String(value ?? "").trim();
|
|
277
|
+
const parts = [text(row.company), text(row.typeLabel)].filter(Boolean);
|
|
278
|
+
return {
|
|
279
|
+
subjectId: text(row._id),
|
|
280
|
+
name: text(row.name) || text(row.email) || "Service provider",
|
|
281
|
+
subtitle: parts.join(" · ") || text(row.role) || text(row.email) || "",
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Does this list tell us who has an app account?
|
|
287
|
+
*
|
|
288
|
+
* `GET /api/service-providers/site-members` only began returning `user` in core
|
|
289
|
+
* 3.130; before that the service layer dropped it even though the repository
|
|
290
|
+
* projected it. Frontend and backend deploy separately, so this screen can run
|
|
291
|
+
* against either. Asked of the ROWS rather than of a version number: the key is
|
|
292
|
+
* present on every row or on none.
|
|
293
|
+
*
|
|
294
|
+
* It matters because the answer flips a filter from "cannot be bound to a door"
|
|
295
|
+
* to "unknown", and a screen that silently reports NOBODY can be enrolled is
|
|
296
|
+
* worse than one that offers somebody the server then refuses by name.
|
|
297
|
+
*/
|
|
298
|
+
export function providerAccountsKnown(
|
|
299
|
+
rows: ReadonlyArray<Record<string, unknown>>,
|
|
300
|
+
): boolean {
|
|
301
|
+
return rows.some((row) => Boolean(row) && typeof row === "object" && "user" in row);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Who may be offered a door, from whatever the endpoint returned.
|
|
306
|
+
*
|
|
307
|
+
* With accounts known, both conditions apply (`providerCanEnrol`). Without them,
|
|
308
|
+
* active membership is all that can be checked here — the server still refuses
|
|
309
|
+
* anyone it cannot bind, with a message naming them, which is a better failure
|
|
310
|
+
* than an empty picker.
|
|
311
|
+
*/
|
|
312
|
+
export function providerEnrollableRows<T extends Record<string, unknown>>(
|
|
313
|
+
rows: ReadonlyArray<T>,
|
|
314
|
+
): T[] {
|
|
315
|
+
const known = providerAccountsKnown(rows);
|
|
316
|
+
return rows.filter((row) =>
|
|
317
|
+
known ? providerCanEnrol(row) : String(row?.status ?? "").trim() === "active",
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/* ── THE SERVICE FILTER'S "ALL" ────────────────────────────────────────── */
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* WHY "ALL SERVICES" CANNOT BE THE EMPTY STRING HERE.
|
|
325
|
+
*
|
|
326
|
+
* `filterProviderMembers` reads an empty `type` as "do not filter", and the
|
|
327
|
+
* Members screen's own filter uses `value: ""` for All services - but that screen
|
|
328
|
+
* draws a Vuetify `v-select`, which renders an empty value perfectly well.
|
|
329
|
+
*
|
|
330
|
+
* `AppSelect` does not. Its `hasSingleValue` is false for `""`, so the field
|
|
331
|
+
* falls back to the placeholder, draws in the placeholder's grey, and the option
|
|
332
|
+
* is never marked as the chosen one in the menu. The filter worked; it just
|
|
333
|
+
* looked like nothing was selected and like only the real services existed.
|
|
334
|
+
*
|
|
335
|
+
* So the option carries a real value here and is translated on the way to the
|
|
336
|
+
* filter. Changing `AppSelect` instead would touch every one of its callers.
|
|
337
|
+
*/
|
|
338
|
+
export const HID_ALL_SERVICES = "all";
|
|
339
|
+
|
|
340
|
+
/** The `type` to filter by: "" for All services, the service code otherwise. */
|
|
341
|
+
export function serviceFilterOf(selected: unknown): string {
|
|
342
|
+
const value = String(selected ?? "").trim();
|
|
343
|
+
return value === HID_ALL_SERVICES ? "" : value;
|
|
344
|
+
}
|