@7365admin1/layer-common 4.149.2 → 4.150.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 +10 -4
- package/components/EntryPassInformation.vue +13 -0
- package/components/HidAccessPermissions.vue +202 -40
- package/components/HidEnabledGate.vue +29 -10
- package/components/HidIntercomManagement.vue +26 -13
- package/components/HidProfileQrCode.vue +6 -2
- package/components/HidQrCodeConfiguration.vue +2 -2
- package/components/HidReaderForm.vue +239 -1
- package/components/HidReaderManagement.vue +26 -8
- package/components/HidReaderUserRoster.vue +3 -1
- package/components/HidServiceSettingsPanel.vue +2 -2
- package/components/HidUserEnrollment.vue +1662 -162
- package/components/OvernightParkingAvailability.vue +123 -11
- package/components/SiteSettings.vue +5 -2
- package/components/VisitorForm.vue +39 -11
- package/composables/useCleaningPermission.ts +11 -0
- package/composables/useHidAccessPermission.ts +176 -81
- package/composables/useHidAmico.ts +37 -0
- package/composables/useHidNavigation.ts +44 -23
- package/composables/useLandscapingPermission.ts +11 -0
- package/composables/useMechanicalElectricalPermission.ts +5 -0
- package/composables/usePestControlPermission.ts +11 -0
- package/composables/usePoolMaintenancePermission.ts +11 -0
- package/composables/usePropertyPermission.ts +31 -7
- package/composables/useSecurityPermission.ts +33 -13
- package/composables/useServiceProvider.ts +9 -4
- package/constants/permissions.ts +73 -21
- package/package.json +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +3 -0
- package/types/overnight-parking.d.ts +14 -0
- package/types/site.d.ts +7 -1
- package/utils/hid-enrolment-subject.ts +226 -4
- package/utils/hid-permission-assignments.ts +75 -6
- package/utils/hid-qr-validity.ts +25 -0
- package/utils/hid-reader-audiences.ts +557 -0
- package/utils/hid-registration.ts +24 -0
- package/utils/module-routes.ts +15 -2
- package/utils/nav-sections.ts +1 -1
|
@@ -8,14 +8,20 @@
|
|
|
8
8
|
* in this repo.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
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";
|
|
12
20
|
|
|
13
21
|
/**
|
|
14
22
|
* The dropdown's options, in the order they are drawn.
|
|
15
23
|
*
|
|
16
|
-
* `title`/`value` because `AppSelect` takes that shape.
|
|
17
|
-
* option is expected next; adding it here is most of the work, since the write
|
|
18
|
-
* path already maps `service_provider` onto `serviceProvider`.
|
|
24
|
+
* `title`/`value` because `AppSelect` takes that shape.
|
|
19
25
|
*/
|
|
20
26
|
export const HID_ENROLMENT_SUBJECTS: ReadonlyArray<{
|
|
21
27
|
title: string;
|
|
@@ -23,6 +29,7 @@ export const HID_ENROLMENT_SUBJECTS: ReadonlyArray<{
|
|
|
23
29
|
}> = [
|
|
24
30
|
{ title: "Resident", value: "resident" },
|
|
25
31
|
{ title: "Member", value: "property_management" },
|
|
32
|
+
{ title: "Service provider", value: "service_provider_staff" },
|
|
26
33
|
];
|
|
27
34
|
|
|
28
35
|
/**
|
|
@@ -38,6 +45,10 @@ export function subjectCategoryLabel(category: unknown): string {
|
|
|
38
45
|
const labels: Record<string, string> = {
|
|
39
46
|
resident: "Resident",
|
|
40
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.
|
|
41
52
|
service_provider: "Service provider",
|
|
42
53
|
visitor: "Visitor",
|
|
43
54
|
};
|
|
@@ -142,3 +153,214 @@ export function hiddenSubjectNote(count: number, noun: "resident" | "member"): s
|
|
|
142
153
|
return `${subject} at this site ${verb} not listed:`
|
|
143
154
|
+ ` HID enrollment needs an app account, and ${holder} none yet.`;
|
|
144
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
|
+
/**
|
|
244
|
+
* The dropdown value for a grant's category — the inverse of
|
|
245
|
+
* `permissionCategoryOf`.
|
|
246
|
+
*
|
|
247
|
+
* An edit STATES the subject type rather than offering it, because an identity's
|
|
248
|
+
* category cannot change after it is created. This is how a stored record is
|
|
249
|
+
* turned back into the value the form holds, and it is wider than the dropdown on
|
|
250
|
+
* purpose: records in the wild carry `service_provider`, which names a COMPANY
|
|
251
|
+
* and which the dropdown does not offer.
|
|
252
|
+
*
|
|
253
|
+
* Paired with `subjectOfIdentity` so the mapping lives in one place. `openEdit`
|
|
254
|
+
* used to repeat the whole links-and-type ternary inline, which is how the copy
|
|
255
|
+
* in `HidAccessPermissions.vue` was able to go stale without anything noticing.
|
|
256
|
+
*/
|
|
257
|
+
export function enrolmentSubjectOfCategory(category: unknown): string {
|
|
258
|
+
const value = String(category ?? "");
|
|
259
|
+
if (value === "resident") return "resident";
|
|
260
|
+
if (value === "service_provider_member") return "service_provider_staff";
|
|
261
|
+
if (value === "service_provider") return "service_provider";
|
|
262
|
+
return "property_management";
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/* ── PROVIDER STAFF AS PICKER ROWS ─────────────────────────────────────── */
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Can this provider employee be enrolled?
|
|
269
|
+
*
|
|
270
|
+
* Two conditions, and both have to be checked here rather than trusted from the
|
|
271
|
+
* list. An app account, because reader access is bound by user id
|
|
272
|
+
* (`memberHasAccount`). And an ACTIVE membership: `getProviderMembersBySite`
|
|
273
|
+
* returns everyone who is not deleted, so a suspended person is in the list the
|
|
274
|
+
* Members screen draws - marked, deliberately, so the property manager can see
|
|
275
|
+
* them. Offering a suspended person a door is a different matter.
|
|
276
|
+
*/
|
|
277
|
+
export function providerCanEnrol(
|
|
278
|
+
row: Record<string, unknown> | null | undefined,
|
|
279
|
+
): boolean {
|
|
280
|
+
if (!memberHasAccount(row)) return false;
|
|
281
|
+
return String(row?.status ?? "").trim() === "active";
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* How a provider employee reads in the picker: their name, their company and
|
|
286
|
+
* the service beneath it.
|
|
287
|
+
*
|
|
288
|
+
* The company comes FIRST in the subtitle. Two contractors with the same first
|
|
289
|
+
* name are common, and which firm somebody belongs to is what the property
|
|
290
|
+
* manager actually recognises them by - the service type alone ("Security")
|
|
291
|
+
* describes half the list.
|
|
292
|
+
*/
|
|
293
|
+
export function providerCandidateOf(row: Record<string, unknown>): {
|
|
294
|
+
subjectId: string;
|
|
295
|
+
name: string;
|
|
296
|
+
subtitle: string;
|
|
297
|
+
} {
|
|
298
|
+
const text = (value: unknown) => String(value ?? "").trim();
|
|
299
|
+
const parts = [text(row.company), text(row.typeLabel)].filter(Boolean);
|
|
300
|
+
return {
|
|
301
|
+
subjectId: text(row._id),
|
|
302
|
+
name: text(row.name) || text(row.email) || "Service provider",
|
|
303
|
+
subtitle: parts.join(" · ") || text(row.role) || text(row.email) || "",
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Does this list tell us who has an app account?
|
|
309
|
+
*
|
|
310
|
+
* `GET /api/service-providers/site-members` only began returning `user` in core
|
|
311
|
+
* 3.130; before that the service layer dropped it even though the repository
|
|
312
|
+
* projected it. Frontend and backend deploy separately, so this screen can run
|
|
313
|
+
* against either. Asked of the ROWS rather than of a version number: the key is
|
|
314
|
+
* present on every row or on none.
|
|
315
|
+
*
|
|
316
|
+
* It matters because the answer flips a filter from "cannot be bound to a door"
|
|
317
|
+
* to "unknown", and a screen that silently reports NOBODY can be enrolled is
|
|
318
|
+
* worse than one that offers somebody the server then refuses by name.
|
|
319
|
+
*/
|
|
320
|
+
export function providerAccountsKnown(
|
|
321
|
+
rows: ReadonlyArray<Record<string, unknown>>,
|
|
322
|
+
): boolean {
|
|
323
|
+
return rows.some((row) => Boolean(row) && typeof row === "object" && "user" in row);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Who may be offered a door, from whatever the endpoint returned.
|
|
328
|
+
*
|
|
329
|
+
* With accounts known, both conditions apply (`providerCanEnrol`). Without them,
|
|
330
|
+
* active membership is all that can be checked here — the server still refuses
|
|
331
|
+
* anyone it cannot bind, with a message naming them, which is a better failure
|
|
332
|
+
* than an empty picker.
|
|
333
|
+
*/
|
|
334
|
+
export function providerEnrollableRows<T extends Record<string, unknown>>(
|
|
335
|
+
rows: ReadonlyArray<T>,
|
|
336
|
+
): T[] {
|
|
337
|
+
const known = providerAccountsKnown(rows);
|
|
338
|
+
return rows.filter((row) =>
|
|
339
|
+
known ? providerCanEnrol(row) : String(row?.status ?? "").trim() === "active",
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* ── THE SERVICE FILTER'S "ALL" ────────────────────────────────────────── */
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* WHY "ALL SERVICES" CANNOT BE THE EMPTY STRING HERE.
|
|
347
|
+
*
|
|
348
|
+
* `filterProviderMembers` reads an empty `type` as "do not filter", and the
|
|
349
|
+
* Members screen's own filter uses `value: ""` for All services - but that screen
|
|
350
|
+
* draws a Vuetify `v-select`, which renders an empty value perfectly well.
|
|
351
|
+
*
|
|
352
|
+
* `AppSelect` does not. Its `hasSingleValue` is false for `""`, so the field
|
|
353
|
+
* falls back to the placeholder, draws in the placeholder's grey, and the option
|
|
354
|
+
* is never marked as the chosen one in the menu. The filter worked; it just
|
|
355
|
+
* looked like nothing was selected and like only the real services existed.
|
|
356
|
+
*
|
|
357
|
+
* So the option carries a real value here and is translated on the way to the
|
|
358
|
+
* filter. Changing `AppSelect` instead would touch every one of its callers.
|
|
359
|
+
*/
|
|
360
|
+
export const HID_ALL_SERVICES = "all";
|
|
361
|
+
|
|
362
|
+
/** The `type` to filter by: "" for All services, the service code otherwise. */
|
|
363
|
+
export function serviceFilterOf(selected: unknown): string {
|
|
364
|
+
const value = String(selected ?? "").trim();
|
|
365
|
+
return value === HID_ALL_SERVICES ? "" : value;
|
|
366
|
+
}
|
|
@@ -27,11 +27,19 @@
|
|
|
27
27
|
* through is a 400.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* The real categories. `intercom` is a candidate FILTER, never a category.
|
|
32
|
+
*
|
|
33
|
+
* Mirrors `HID_PERMISSION_CATEGORIES` in core, and has to: `seedAssignments`
|
|
34
|
+
* DROPS a row whose category is not in this list, so a category missing here
|
|
35
|
+
* silently loses that grant from the edit state - and the save that follows,
|
|
36
|
+
* being a whole-reader replace, would revoke it.
|
|
37
|
+
*/
|
|
31
38
|
export const HID_PERMISSION_CATEGORIES: THidPermissionCategory[] = [
|
|
32
39
|
"resident",
|
|
33
40
|
"property_management",
|
|
34
41
|
"service_provider",
|
|
42
|
+
"service_provider_member",
|
|
35
43
|
];
|
|
36
44
|
|
|
37
45
|
export type HidAssignmentState = Map<string, { category: THidPermissionCategory; intercom: boolean }>;
|
|
@@ -134,11 +142,20 @@ export function applySelection(
|
|
|
134
142
|
|
|
135
143
|
/** Per-category totals for the dialog header, counted over the whole reader. */
|
|
136
144
|
export function countByCategory(state: HidAssignmentState): Record<THidPermissionCategory, number> {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
/*
|
|
146
|
+
* Every category seeded at zero, and the increment guarded.
|
|
147
|
+
* `counts[category] += 1` on a key this object does not hold yields NaN, so a
|
|
148
|
+
* category added to the union but missed here would print "NaN" beside a tab
|
|
149
|
+
* rather than a number. That is exactly what happened when
|
|
150
|
+
* `service_provider_member` was added.
|
|
151
|
+
*/
|
|
152
|
+
const counts = HID_PERMISSION_CATEGORIES.reduce(
|
|
153
|
+
(seeded, category) => ({ ...seeded, [category]: 0 }),
|
|
154
|
+
{} as Record<THidPermissionCategory, number>,
|
|
155
|
+
);
|
|
156
|
+
for (const value of state.values()) {
|
|
157
|
+
counts[value.category] = (counts[value.category] ?? 0) + 1;
|
|
158
|
+
}
|
|
142
159
|
return counts;
|
|
143
160
|
}
|
|
144
161
|
|
|
@@ -188,3 +205,55 @@ export function readCandidatePage(response: unknown): {
|
|
|
188
205
|
pageRange,
|
|
189
206
|
};
|
|
190
207
|
}
|
|
208
|
+
|
|
209
|
+
/* ── THE SUBJECT AN IDENTITY NAMES ─────────────────────────────────────── */
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* WHICH GRANT AN ENROLLED PERSON'S ACCESS IS FILED UNDER.
|
|
213
|
+
*
|
|
214
|
+
* Mirrors `permissionSubjectOfIdentity` in core, which is the authority. This
|
|
215
|
+
* repository cannot import it - layer-common does not depend on the core
|
|
216
|
+
* package - so there is a copy, and the point of putting it HERE is that there
|
|
217
|
+
* is only one.
|
|
218
|
+
*
|
|
219
|
+
* There used to be two: a local `subjectOf` in `HidAccessPermissions.vue` and
|
|
220
|
+
* the same ternary inline in `HidUserEnrollment.vue`. The first was stale. It
|
|
221
|
+
* read every `member` link as `property_management`, so granting a contractor
|
|
222
|
+
* from the permissions screen wrote a staff assignment - and the reconcile then
|
|
223
|
+
* derived `staff` from that category and rewrote the identity's `type`, moving
|
|
224
|
+
* the person out of the service-provider tab and into the member one. The
|
|
225
|
+
* screen for managing contractors reclassified them by being used.
|
|
226
|
+
*
|
|
227
|
+
* A `member` link is how BOTH a property-management member and a service
|
|
228
|
+
* provider's own employee are stored - the person's membership at this site -
|
|
229
|
+
* so the identity's `type` is the discriminator. `"contractor"` is written by
|
|
230
|
+
* the enrolment form and re-confirmed by `permissionIdentityType` on every
|
|
231
|
+
* reconcile, so the two agree instead of one overwriting the other.
|
|
232
|
+
*
|
|
233
|
+
* Returns null for a visitor and for an identity linked to nobody. Visitor
|
|
234
|
+
* access comes from `user_access_rules` rather than a group, so there is nothing
|
|
235
|
+
* to switch; an identity holding only an account link names no subject to
|
|
236
|
+
* assign. Both are still DRAWN by the permissions screen, disabled, with a
|
|
237
|
+
* reason - dropping them silently is what once made the pager say "1-9 of 9"
|
|
238
|
+
* over seven rows.
|
|
239
|
+
*/
|
|
240
|
+
export function subjectOfIdentity(
|
|
241
|
+
identity: Record<string, unknown> | null | undefined,
|
|
242
|
+
): { subjectId: string; category: THidPermissionCategory } | null {
|
|
243
|
+
if (!identity) return null;
|
|
244
|
+
if (identity.person) {
|
|
245
|
+
return { subjectId: String(identity.person), category: "resident" };
|
|
246
|
+
}
|
|
247
|
+
if (identity.member) {
|
|
248
|
+
return {
|
|
249
|
+
subjectId: String(identity.member),
|
|
250
|
+
category: String(identity.type ?? "") === "contractor"
|
|
251
|
+
? "service_provider_member"
|
|
252
|
+
: "property_management",
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
if (identity.serviceProvider) {
|
|
256
|
+
return { subjectId: String(identity.serviceProvider), category: "service_provider" };
|
|
257
|
+
}
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minutes from `now` to the next local midnight, so a visitor HID QR runs to
|
|
3
|
+
* the end of the visit day. The resident app's invite form does the same
|
|
4
|
+
* (`minutesUntilEndOfDay` in its VisitorForm.tsx). Never less than 1: the API
|
|
5
|
+
* refuses a zero validity.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* How long the site's HID visitor pass lasts: the `usage` on the HID entry of
|
|
9
|
+
* `visitorQrCodes` (Site Settings > Resident Visitors). Anything but
|
|
10
|
+
* "singleUse" is the whole visit day - the same reading as core's
|
|
11
|
+
* `getHidVisitorQrUsage` and the resident app's invite form.
|
|
12
|
+
*/
|
|
13
|
+
export function hidQrUsageFromSettings(settings: unknown): "wholeDay" | "singleUse" {
|
|
14
|
+
const codes = (settings as { visitorQrCodes?: unknown } | null)?.visitorQrCodes;
|
|
15
|
+
const hid = Array.isArray(codes)
|
|
16
|
+
? codes.find((code) => (code as { type?: unknown } | null)?.type === "hid")
|
|
17
|
+
: undefined;
|
|
18
|
+
return (hid as { usage?: unknown } | undefined)?.usage === "singleUse" ? "singleUse" : "wholeDay";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function minutesUntilEndOfDay(now: Date = new Date()) {
|
|
22
|
+
const midnight = new Date(now);
|
|
23
|
+
midnight.setHours(24, 0, 0, 0);
|
|
24
|
+
return Math.max(1, Math.floor((midnight.getTime() - now.getTime()) / 60_000));
|
|
25
|
+
}
|