@7365admin1/layer-common 4.82.1-staging.476 → 4.83.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/assets/css/primitives.css +0 -57
- package/assets/css/screens.css +4 -8
- package/components/AccessCardDetailsDialog.vue +4 -57
- package/components/AccessCardPreviewDialog.vue +50 -291
- package/components/AppSelect.vue +4 -143
- package/components/AttendanceDetailsDialog.vue +1 -48
- package/components/AttendanceMain.vue +10 -104
- package/components/AttendanceSettingsDialog.vue +1 -53
- package/components/BuildingUnitFormEdit.vue +0 -6
- package/components/BulletinBoardView.vue +1 -1
- package/components/Dialog/UpdateMoreAction.vue +1 -11
- package/components/DocumentForm.vue +112 -407
- package/components/DocumentManagement.vue +12 -213
- package/components/Facility/BookingSetup.vue +0 -63
- package/components/HidAccessLogDashboard.vue +17 -74
- package/components/HidIntercomManagement.vue +14 -183
- package/components/HidQrCodeConfiguration.vue +195 -17
- package/components/HidReaderManagement.vue +0 -398
- package/components/HidReaderUserRoster.vue +3 -44
- package/components/HidUserEnrollment.vue +250 -1573
- package/components/InventoryMain.vue +2 -11
- package/components/InvitationClientForm.vue +1 -19
- package/components/MemberMain.vue +1 -2
- package/components/MyAttendanceMain.vue +2 -60
- package/components/NotificationBell.vue +2 -14
- package/components/RolePermissionMain.vue +2 -4
- package/components/TableMain.vue +7 -22
- package/components/VisitorForm.vue +0 -12
- package/components/VisitorManagement.vue +5 -267
- package/composables/useAttendance.ts +0 -53
- package/composables/useAttendancePermission.ts +0 -25
- package/composables/useCleaningPermission.ts +0 -5
- package/composables/useDocument.ts +0 -7
- package/composables/useFacility.ts +0 -11
- package/composables/useHidAmico.ts +0 -165
- package/composables/useHidNavigation.ts +1 -25
- package/composables/useLandscapingPermission.ts +0 -5
- package/composables/useMember.ts +0 -12
- package/composables/usePeople.ts +0 -19
- package/composables/usePestControlPermission.ts +0 -5
- package/composables/usePoolMaintenancePermission.ts +0 -5
- package/composables/useSecurityPermission.ts +0 -5
- package/composables/useServiceProvider.ts +2 -40
- package/constants/permissions.ts +0 -1
- package/nuxt.config.ts +0 -18
- package/package.json +2 -4
- 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-readers/index.vue +1 -1
- package/plugins/API.ts +0 -16
- package/types/attendance.d.ts +1 -13
- package/types/document.d.ts +0 -14
- package/types/facility.d.ts +0 -4
- package/types/member.d.ts +0 -4
- package/types/people.d.ts +1 -28
- package/types/service-provider.d.ts +0 -5
- package/utils/notification-target.ts +4 -43
- package/utils/role.ts +2 -15
- package/components/AttendanceProxyDialog.vue +0 -391
- package/components/BuildingUnitManagement.vue +0 -298
- package/components/HidAccessPermissions.vue +0 -424
- package/components/HidProfileQrCode.vue +0 -332
- package/composables/useHidReaderSelection.ts +0 -50
- package/composables/useSiteActions.ts +0 -29
- package/composables/useSiteCategory.ts +0 -45
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +0 -23
- package/server/plugins/no-powered-by.ts +0 -7
- package/utils/access-suspended.ts +0 -18
- package/utils/attendance-proxy.ts +0 -110
- package/utils/hid-enrolment-subject.ts +0 -144
- package/utils/hid-permission-assignments.ts +0 -190
- package/utils/hid-reader-selection.ts +0 -52
- package/utils/occupancy-role.ts +0 -109
- package/utils/sanitize-html.ts +0 -16
- package/utils/security-headers.ts +0 -52
- package/utils/service-type.ts +0 -30
- package/utils/site-actions.ts +0 -18
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
MY HID QR CODE.
|
|
3
|
-
|
|
4
|
-
The signed-in member's own pass for one reader. Every other HID screen acts on
|
|
5
|
-
somebody else - a resident being enrolled, a visitor being issued a pass. This
|
|
6
|
-
one has no subject picker at all, because the server takes the caller from the
|
|
7
|
-
session and there is no user id to send.
|
|
8
|
-
|
|
9
|
-
Issuing a code does NOT grant access. A member's door permission comes from the
|
|
10
|
-
HID permissions screen, and minting an access rule here would let anyone who
|
|
11
|
-
can press Generate admit themselves. So the screen reports what the permissions
|
|
12
|
-
screen says (`assigned`) and warns when a code would be refused at the door,
|
|
13
|
-
rather than handing out something that silently fails.
|
|
14
|
-
-->
|
|
15
|
-
<template>
|
|
16
|
-
<div class="hid-profile-qr">
|
|
17
|
-
<div class="hid-profile-qr__header">
|
|
18
|
-
<h2 class="hid-profile-qr__title">HID QR Code</h2>
|
|
19
|
-
<AppSelect
|
|
20
|
-
v-if="readerOptions.length"
|
|
21
|
-
v-model="selectedReaderId"
|
|
22
|
-
class="reader-select"
|
|
23
|
-
:items="readerOptions"
|
|
24
|
-
@update:model-value="loadProfile"
|
|
25
|
-
/>
|
|
26
|
-
</div>
|
|
27
|
-
|
|
28
|
-
<v-card class="screen-modal hid-profile-qr__card">
|
|
29
|
-
<v-card-text class="screen-modal__body">
|
|
30
|
-
<div v-if="loading" class="hid-profile-qr__state">Loading...</div>
|
|
31
|
-
|
|
32
|
-
<div v-else-if="!readerOptions.length" class="hid-profile-qr__state">
|
|
33
|
-
No HID reader is set up for this site yet.
|
|
34
|
-
</div>
|
|
35
|
-
|
|
36
|
-
<template v-else>
|
|
37
|
-
<p class="hid-profile-qr__reader">
|
|
38
|
-
{{ profile?.readerName || "HID reader" }}
|
|
39
|
-
<span>{{ profile?.portalName || "Portal not configured" }}</span>
|
|
40
|
-
</p>
|
|
41
|
-
|
|
42
|
-
<!-- A code this reader cannot read is worse than no code, so the
|
|
43
|
-
capability is checked before anything is offered. -->
|
|
44
|
-
<v-alert
|
|
45
|
-
v-if="profile && !profile.qrEnabled"
|
|
46
|
-
type="warning"
|
|
47
|
-
variant="tonal"
|
|
48
|
-
density="compact"
|
|
49
|
-
class="mb-4"
|
|
50
|
-
>
|
|
51
|
-
This reader is not set up to read QR codes.
|
|
52
|
-
</v-alert>
|
|
53
|
-
|
|
54
|
-
<!-- The honest part: a code opens the door only for a member the
|
|
55
|
-
permissions screen already admits. `assigned` is null when the
|
|
56
|
-
lookup failed, which is not the same as "no". -->
|
|
57
|
-
<v-alert
|
|
58
|
-
v-else-if="profile && profile.assigned === false"
|
|
59
|
-
type="warning"
|
|
60
|
-
variant="tonal"
|
|
61
|
-
density="compact"
|
|
62
|
-
class="mb-4"
|
|
63
|
-
>
|
|
64
|
-
You are not assigned to this reader, so this code will be refused at
|
|
65
|
-
the door. Ask a property manager to add you on the HID permissions
|
|
66
|
-
screen.
|
|
67
|
-
</v-alert>
|
|
68
|
-
|
|
69
|
-
<div v-if="qrImage" class="hid-profile-qr__code">
|
|
70
|
-
<img :src="qrImage" alt="Your HID QR code" width="220" height="220" />
|
|
71
|
-
<p class="hid-profile-qr__issued">
|
|
72
|
-
Issued {{ formatIssuedAt(profile?.issuedAt) }}
|
|
73
|
-
</p>
|
|
74
|
-
</div>
|
|
75
|
-
<p v-else class="hid-profile-qr__state">
|
|
76
|
-
You have no QR code on this reader yet.
|
|
77
|
-
</p>
|
|
78
|
-
|
|
79
|
-
<div class="hid-profile-qr__actions">
|
|
80
|
-
<AppButton
|
|
81
|
-
:disabled="working || !profile?.qrEnabled"
|
|
82
|
-
@click="generate"
|
|
83
|
-
>
|
|
84
|
-
{{ profile?.issued ? "Regenerate" : "Generate QR Code" }}
|
|
85
|
-
</AppButton>
|
|
86
|
-
<AppButton
|
|
87
|
-
v-if="qrImage"
|
|
88
|
-
variant="ghost"
|
|
89
|
-
icon="mdi-download"
|
|
90
|
-
@click="downloadQr"
|
|
91
|
-
>
|
|
92
|
-
Download
|
|
93
|
-
</AppButton>
|
|
94
|
-
<AppButton
|
|
95
|
-
v-if="profile?.issued"
|
|
96
|
-
variant="ghost"
|
|
97
|
-
:disabled="working"
|
|
98
|
-
@click="remove"
|
|
99
|
-
>
|
|
100
|
-
Remove
|
|
101
|
-
</AppButton>
|
|
102
|
-
</div>
|
|
103
|
-
|
|
104
|
-
<p class="field-hint">
|
|
105
|
-
Regenerating replaces the previous code. The old one stops working
|
|
106
|
-
immediately.
|
|
107
|
-
</p>
|
|
108
|
-
</template>
|
|
109
|
-
</v-card-text>
|
|
110
|
-
</v-card>
|
|
111
|
-
|
|
112
|
-
<v-snackbar v-model="snackbar.show" :color="snackbar.color" timeout="4000">
|
|
113
|
-
{{ snackbar.message }}
|
|
114
|
-
</v-snackbar>
|
|
115
|
-
</div>
|
|
116
|
-
</template>
|
|
117
|
-
|
|
118
|
-
<script setup lang="ts">
|
|
119
|
-
import QRCode from "qrcode";
|
|
120
|
-
import type { HidProfileQr } from "../composables/useHidAmico";
|
|
121
|
-
|
|
122
|
-
const props = defineProps<{ site: string }>();
|
|
123
|
-
|
|
124
|
-
const { getReaders, getProfileQr, issueProfileQr, deleteProfileQr } = useHidAmico();
|
|
125
|
-
|
|
126
|
-
type HidReaderOption = { _id: string; name?: string; portalName?: string };
|
|
127
|
-
|
|
128
|
-
const readers = ref<HidReaderOption[]>([]);
|
|
129
|
-
const { selectHidReader, resolveForSite } = useHidReaderSelection();
|
|
130
|
-
const selectedReaderId = ref("");
|
|
131
|
-
const profile = ref<HidProfileQr | null>(null);
|
|
132
|
-
const qrImage = ref("");
|
|
133
|
-
const loading = ref(false);
|
|
134
|
-
const working = ref(false);
|
|
135
|
-
const snackbar = reactive({ show: false, color: "success", message: "" });
|
|
136
|
-
|
|
137
|
-
const readerOptions = computed(() => readers.value.map((reader) => ({
|
|
138
|
-
title: `${reader.name || reader._id} — ${reader.portalName || "Portal not configured"}`,
|
|
139
|
-
value: reader._id,
|
|
140
|
-
})));
|
|
141
|
-
|
|
142
|
-
function showToast(message: string, color: "success" | "error" = "success") {
|
|
143
|
-
snackbar.message = message;
|
|
144
|
-
snackbar.color = color;
|
|
145
|
-
snackbar.show = true;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function toRecord(value: unknown): Record<string, any> {
|
|
149
|
-
return value && typeof value === "object" ? (value as Record<string, any>) : {};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function errorMessage(error: unknown) {
|
|
153
|
-
const record = toRecord(error);
|
|
154
|
-
return String(toRecord(record.data).message || record.message || "Something went wrong.");
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function formatIssuedAt(value?: string) {
|
|
158
|
-
if (!value) return "";
|
|
159
|
-
const date = new Date(value);
|
|
160
|
-
return Number.isNaN(date.getTime()) ? "" : date.toLocaleString();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* The image is drawn here, never fetched. The value is the credential itself,
|
|
165
|
-
* so keeping it on this page and out of any URL is the point.
|
|
166
|
-
*/
|
|
167
|
-
async function renderQr(value: string) {
|
|
168
|
-
if (!value) {
|
|
169
|
-
qrImage.value = "";
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
try {
|
|
173
|
-
qrImage.value = await QRCode.toDataURL(value, { width: 440, margin: 1 });
|
|
174
|
-
} catch (error) {
|
|
175
|
-
console.error("Unable to render the HID QR code:", error);
|
|
176
|
-
qrImage.value = "";
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Saves the rendered code as a PNG.
|
|
182
|
-
*
|
|
183
|
-
* Straight off the data URL already in the page - no request, so the credential
|
|
184
|
-
* never travels again to be downloaded. Same anchor-click approach `VisitorForm`
|
|
185
|
-
* uses for a visitor pass, and the reader name is in the file name because a
|
|
186
|
-
* member can hold one code per reader.
|
|
187
|
-
*/
|
|
188
|
-
function downloadQr() {
|
|
189
|
-
if (!qrImage.value) return;
|
|
190
|
-
const slug = String(profile.value?.readerName || "reader")
|
|
191
|
-
.trim()
|
|
192
|
-
.replace(/[^a-z0-9]+/gi, "-")
|
|
193
|
-
.replace(/^-|-$/g, "")
|
|
194
|
-
.toLowerCase();
|
|
195
|
-
const link = document.createElement("a");
|
|
196
|
-
link.href = qrImage.value;
|
|
197
|
-
link.download = `hid-qr-${slug || "reader"}.png`;
|
|
198
|
-
link.click();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
async function loadReaders() {
|
|
202
|
-
if (!props.site) return;
|
|
203
|
-
const response = toRecord(await getReaders({ site: props.site, page: 1, limit: 100 }));
|
|
204
|
-
const data = toRecord(response.data);
|
|
205
|
-
const items = response.items ?? data.items ?? data.readers ?? [];
|
|
206
|
-
readers.value = (Array.isArray(items) ? items : []).filter((reader) => reader?._id);
|
|
207
|
-
/* Shared with every other HID screen — see `useHidReaderSelection`. The
|
|
208
|
-
resolver refuses a remembered reader that is not this site's, so a site
|
|
209
|
-
switch or a deleted reader falls back to the first rather than querying
|
|
210
|
-
an id the site does not own. */
|
|
211
|
-
selectedReaderId.value = resolveForSite(props.site, readers.value);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
async function loadProfile() {
|
|
215
|
-
if (!selectedReaderId.value) return;
|
|
216
|
-
loading.value = true;
|
|
217
|
-
try {
|
|
218
|
-
const response = await getProfileQr(selectedReaderId.value);
|
|
219
|
-
profile.value = response?.data ?? null;
|
|
220
|
-
await renderQr(profile.value?.qrValue || "");
|
|
221
|
-
} catch (error: unknown) {
|
|
222
|
-
profile.value = null;
|
|
223
|
-
qrImage.value = "";
|
|
224
|
-
showToast(errorMessage(error), "error");
|
|
225
|
-
} finally {
|
|
226
|
-
loading.value = false;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
async function generate() {
|
|
231
|
-
if (!selectedReaderId.value) return;
|
|
232
|
-
working.value = true;
|
|
233
|
-
try {
|
|
234
|
-
const response = await issueProfileQr(selectedReaderId.value);
|
|
235
|
-
profile.value = response?.data ?? null;
|
|
236
|
-
await renderQr(profile.value?.qrValue || "");
|
|
237
|
-
showToast("QR code generated.");
|
|
238
|
-
} catch (error: unknown) {
|
|
239
|
-
showToast(errorMessage(error), "error");
|
|
240
|
-
} finally {
|
|
241
|
-
working.value = false;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
async function remove() {
|
|
246
|
-
if (!selectedReaderId.value) return;
|
|
247
|
-
if (!window.confirm("Remove your QR code from this reader?")) return;
|
|
248
|
-
working.value = true;
|
|
249
|
-
try {
|
|
250
|
-
const response = await deleteProfileQr(selectedReaderId.value);
|
|
251
|
-
profile.value = response?.data ?? null;
|
|
252
|
-
await renderQr("");
|
|
253
|
-
showToast("QR code removed.");
|
|
254
|
-
} catch (error: unknown) {
|
|
255
|
-
showToast(errorMessage(error), "error");
|
|
256
|
-
} finally {
|
|
257
|
-
working.value = false;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
watch(
|
|
262
|
-
() => props.site,
|
|
263
|
-
async () => {
|
|
264
|
-
await loadReaders();
|
|
265
|
-
await loadProfile();
|
|
266
|
-
},
|
|
267
|
-
{ immediate: true },
|
|
268
|
-
);
|
|
269
|
-
|
|
270
|
-
/* Publish every change, including the seed above: a screen that had to fall
|
|
271
|
-
back to the first reader should leave the others agreeing with it. */
|
|
272
|
-
watch(selectedReaderId, (value) => {
|
|
273
|
-
if (value) selectHidReader(props.site, value);
|
|
274
|
-
});
|
|
275
|
-
</script>
|
|
276
|
-
|
|
277
|
-
<style scoped>
|
|
278
|
-
.hid-profile-qr__header {
|
|
279
|
-
display: flex;
|
|
280
|
-
align-items: center;
|
|
281
|
-
gap: 12px;
|
|
282
|
-
flex-wrap: wrap;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
.hid-profile-qr__title {
|
|
286
|
-
margin: 0;
|
|
287
|
-
font-size: 18px;
|
|
288
|
-
font-weight: 600;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
.hid-profile-qr__card {
|
|
292
|
-
margin-top: 16px;
|
|
293
|
-
max-width: 460px;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
.hid-profile-qr__reader {
|
|
297
|
-
margin: 0 0 14px;
|
|
298
|
-
font-size: 14px;
|
|
299
|
-
font-weight: 600;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
.hid-profile-qr__reader span {
|
|
303
|
-
display: block;
|
|
304
|
-
color: var(--muted);
|
|
305
|
-
font-size: 12px;
|
|
306
|
-
font-weight: 500;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
.hid-profile-qr__code {
|
|
310
|
-
display: grid;
|
|
311
|
-
place-items: center;
|
|
312
|
-
margin-bottom: 14px;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
.hid-profile-qr__issued {
|
|
316
|
-
margin: 8px 0 0;
|
|
317
|
-
color: var(--muted);
|
|
318
|
-
font-size: 12px;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
.hid-profile-qr__state {
|
|
322
|
-
color: var(--muted);
|
|
323
|
-
font-size: 13.5px;
|
|
324
|
-
padding: 8px 0 14px;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
.hid-profile-qr__actions {
|
|
328
|
-
display: flex;
|
|
329
|
-
gap: 8px;
|
|
330
|
-
flex-wrap: wrap;
|
|
331
|
-
}
|
|
332
|
-
</style>
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EMPTY_HID_READER_CHOICE,
|
|
3
|
-
resolveHidReaderId,
|
|
4
|
-
type HidReaderChoice,
|
|
5
|
-
} from "../utils/hid-reader-selection";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* ONE HID READER CHOICE, SHARED BY EVERY HID SCREEN.
|
|
9
|
-
*
|
|
10
|
-
* Declared at MODULE scope on purpose. Each screen held its own `ref("")`, and
|
|
11
|
-
* because the HID screens are separate pages the ref was rebuilt on every
|
|
12
|
-
* navigation — HID Reader Users, HID Cards, Access Logs and HID QR Code each
|
|
13
|
-
* reset to the first reader no matter what had just been picked next door.
|
|
14
|
-
*
|
|
15
|
-
* A module-scoped ref is enough because moving between those pages is a ROUTE
|
|
16
|
-
* change, not a page load: the menu's items carry a `route` and
|
|
17
|
-
* `NavigationItem.vue` renders them through `:to`, so vue-router handles them
|
|
18
|
-
* and this module is never re-evaluated.
|
|
19
|
-
*
|
|
20
|
-
* Deliberately NOT persisted. `localStorage` would carry the choice through a
|
|
21
|
-
* hard refresh as well, which is a real but much smaller benefit than the
|
|
22
|
-
* navigation case, and it is worth adding only once somebody has felt the
|
|
23
|
-
* absence. See `utils/hid-reader-selection.ts` for the staleness rule that
|
|
24
|
-
* would have to hold either way.
|
|
25
|
-
*
|
|
26
|
-
* Intercom keeps its own reader and is not wired to this. Its question is which
|
|
27
|
-
* panel you are calling, not which door you are administering, and joining them
|
|
28
|
-
* would mean switching reader on Access Logs changed who you would dial.
|
|
29
|
-
*/
|
|
30
|
-
const choice = ref<HidReaderChoice>({ ...EMPTY_HID_READER_CHOICE });
|
|
31
|
-
|
|
32
|
-
export default function useHidReaderSelection() {
|
|
33
|
-
/** Remember a choice. The site travels with it; an id alone means nothing. */
|
|
34
|
-
function selectHidReader(siteId: string, readerId: string) {
|
|
35
|
-
choice.value = { siteId: String(siteId ?? ""), readerId: String(readerId ?? "") };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The reader this screen should show, given the readers it just loaded.
|
|
40
|
-
*
|
|
41
|
-
* Call it after the reader list arrives, and write the answer back with
|
|
42
|
-
* `selectHidReader` so the screens agree on what "current" means even when
|
|
43
|
-
* one of them had to fall back to the first reader.
|
|
44
|
-
*/
|
|
45
|
-
function resolveForSite(siteId: string, readers: readonly { _id?: unknown }[]) {
|
|
46
|
-
return resolveHidReaderId(siteId, readers, choice.value);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return { choice, selectHidReader, resolveForSite };
|
|
50
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { NO_SITE_ACTIONS, siteActionsOf, type TSiteActions } from "../utils/site-actions";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* May the signed-in person add / delete sites (and add organisations) in this
|
|
5
|
-
* organisation? Re-asked whenever the organisation changes; hidden until core
|
|
6
|
-
* answers. See `utils/site-actions.ts`.
|
|
7
|
-
*/
|
|
8
|
-
export default function useSiteActions(org: MaybeRefOrGetter<string>) {
|
|
9
|
-
const actions = ref<TSiteActions>({ ...NO_SITE_ACTIONS });
|
|
10
|
-
|
|
11
|
-
watch(
|
|
12
|
-
() => toValue(org),
|
|
13
|
-
async (id) => {
|
|
14
|
-
actions.value = { ...NO_SITE_ACTIONS };
|
|
15
|
-
if (!id) return;
|
|
16
|
-
try {
|
|
17
|
-
const res = await useNuxtApp().$api<Record<string, any>>("/api/customer-sites", {
|
|
18
|
-
query: { org: id, status: "active", limit: 1, withActions: true },
|
|
19
|
-
});
|
|
20
|
-
if (toValue(org) === id) actions.value = siteActionsOf(res);
|
|
21
|
-
} catch {
|
|
22
|
-
// stays hidden - the server refuses the action anyway
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
{ immediate: true },
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
return actions;
|
|
29
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* THE CATEGORY OF THE SITE THE USER IS CURRENTLY IN.
|
|
3
|
-
*
|
|
4
|
-
* One shared answer, published once by the application's layout from the site
|
|
5
|
-
* it already loaded for the switcher, and read by anything that has to behave
|
|
6
|
-
* differently on a commercial or industrial site - the business Add Tenant
|
|
7
|
-
* form, the tenant list. Publishing it rather than re-fetching it per
|
|
8
|
-
* component means no two screens can disagree about which site this is.
|
|
9
|
-
*
|
|
10
|
-
* READ FROM THE CUSTOMER-SITE RECORD, NOT THE SITE RECORD. Both carry a
|
|
11
|
-
* `category` and `customer-site.service` keeps them equal (it writes the site
|
|
12
|
-
* on create and on update), but `siteSchema` DEFAULTS the site's own copy to
|
|
13
|
-
* `commercial` - so a site created without an explicit category reads back as
|
|
14
|
-
* commercial there even when it is a residential estate. The customer-site
|
|
15
|
-
* copy has no default: it is either the category somebody chose or nothing.
|
|
16
|
-
*
|
|
17
|
-
* An empty category means "not published yet" or "never set", and every
|
|
18
|
-
* caller must behave as it did before this existed - never assume commercial
|
|
19
|
-
* from silence.
|
|
20
|
-
*/
|
|
21
|
-
const BUSINESS_SITE_CATEGORIES: string[] = ["commercial", "industrial"];
|
|
22
|
-
|
|
23
|
-
export default function useSiteCategory() {
|
|
24
|
-
const siteCategory = useState<string>("current-site-category", () => "");
|
|
25
|
-
|
|
26
|
-
function setSiteCategory(value?: string | null) {
|
|
27
|
-
siteCategory.value = typeof value === "string" ? value : "";
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The categories whose units are LET TO A BUSINESS rather than lived in.
|
|
32
|
-
*
|
|
33
|
-
* These are the sites where a unit has an owner, an occupier and often a
|
|
34
|
-
* person in charge who is neither, so they are the sites that ask for a
|
|
35
|
-
* tenant's standing and print it back (see `OCCUPANCY_ROLE_OPTIONS`).
|
|
36
|
-
*
|
|
37
|
-
* The category never changes what the APPLICATION is called: the rail says
|
|
38
|
-
* Property Management on every site it serves.
|
|
39
|
-
*/
|
|
40
|
-
const isBusinessSite = computed(() =>
|
|
41
|
-
BUSINESS_SITE_CATEGORIES.includes(siteCategory.value),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
return { siteCategory, isBusinessSite, setSiteCategory };
|
|
45
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
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>
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// Nuxt's renderer stamps `x-powered-by: Nuxt` on the HTML shell. It tells a
|
|
2
|
-
// scanner the framework for free and helps nobody, so drop it.
|
|
3
|
-
export default defineNitroPlugin((nitroApp) => {
|
|
4
|
-
nitroApp.hooks.hook("render:response", (response) => {
|
|
5
|
-
if (response?.headers) delete response.headers["x-powered-by"];
|
|
6
|
-
});
|
|
7
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Suspended = no access (owner 2026-10-01). When every membership of the
|
|
3
|
-
* signed-in person is suspended the API answers any request with 401 +
|
|
4
|
-
* `code: "ACCESS_SUSPENDED"` and the message "Your access has been suspended
|
|
5
|
-
* by <org>. Contact your administrator." (core `suspendedSessionGuard`). The
|
|
6
|
-
* session is already dead server-side; the app signs out and the sign-in page
|
|
7
|
-
* (web-app-main) shows the message once, from this cookie.
|
|
8
|
-
*/
|
|
9
|
-
export const ACCESS_SUSPENDED_CODE = "ACCESS_SUSPENDED";
|
|
10
|
-
export const SIGNIN_NOTICE_COOKIE = "signin-notice";
|
|
11
|
-
|
|
12
|
-
export function accessSuspendedMessage(data: unknown): string | null {
|
|
13
|
-
const body = data as { code?: unknown; message?: unknown } | null | undefined;
|
|
14
|
-
if (body?.code !== ACCESS_SUSPENDED_CODE) return null;
|
|
15
|
-
return typeof body.message === "string" && body.message
|
|
16
|
-
? body.message
|
|
17
|
-
: "Your access has been suspended. Contact your administrator.";
|
|
18
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Site device mode (owner request 2026-10-01): one shared phone at a site checks
|
|
3
|
-
* a person in or out with a photo, their name and their NRIC/FIN.
|
|
4
|
-
*
|
|
5
|
-
* Privacy (Singapore PDPA): the full NRIC is masked HERE, in the browser,
|
|
6
|
-
* before anything is sent. Only the last 4 characters leave the device, plus
|
|
7
|
-
* the prefix letter when the full number was typed, so the record can be shown
|
|
8
|
-
* as "G****932P" (owner's display rule); last 4 only is shown as "****932P".
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export const FULL_NRIC_RE = /^[STFGM]\d{7}[A-Z]$/;
|
|
12
|
-
export const NRIC_LAST4_RE = /^\d{3}[A-Z]$/;
|
|
13
|
-
const FULL_NRIC_ANYWHERE_RE = /[STFGM]\d{7}[A-Z]/i;
|
|
14
|
-
|
|
15
|
-
export type TParsedNric =
|
|
16
|
-
| { ok: true; nricLast4: string; nricPrefix: string; masked: string; typedFull: boolean }
|
|
17
|
-
| { ok: false; error: string };
|
|
18
|
-
|
|
19
|
-
/** Full NRIC/FIN or just its last 4, any case, spaces ignored. */
|
|
20
|
-
export function parseNric(input: unknown): TParsedNric {
|
|
21
|
-
const value = String(input ?? "").replace(/\s+/g, "").toUpperCase();
|
|
22
|
-
if (!value) return { ok: false, error: "Type the NRIC/FIN, or just its last 4 characters (e.g. 932P)." };
|
|
23
|
-
if (FULL_NRIC_RE.test(value)) {
|
|
24
|
-
const nricLast4 = value.slice(-4);
|
|
25
|
-
const nricPrefix = value[0];
|
|
26
|
-
return { ok: true, nricLast4, nricPrefix, masked: `${nricPrefix}****${nricLast4}`, typedFull: true };
|
|
27
|
-
}
|
|
28
|
-
if (NRIC_LAST4_RE.test(value)) {
|
|
29
|
-
return { ok: true, nricLast4: value, nricPrefix: "", masked: `****${value}`, typedFull: false };
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
ok: false,
|
|
33
|
-
error: "That doesn't look like an NRIC/FIN. Type the full number (e.g. S1234567D) or just the last 4 (e.g. 567D).",
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Empty string when fine, otherwise the sentence to show. */
|
|
38
|
-
export function nameError(input: unknown): string {
|
|
39
|
-
const value = String(input ?? "").trim();
|
|
40
|
-
if (!value) return "Type the person's name.";
|
|
41
|
-
if (FULL_NRIC_ANYWHERE_RE.test(value)) return "Please type the NRIC in the NRIC box, not in the name.";
|
|
42
|
-
if (value.length < 2) return "Type the person's full name.";
|
|
43
|
-
if (value.length > 80) return "The name is too long (80 characters at most).";
|
|
44
|
-
return "";
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function postError(input: unknown): string {
|
|
48
|
-
const value = String(input ?? "").trim();
|
|
49
|
-
if (FULL_NRIC_ANYWHERE_RE.test(value)) return "Please don't type an NRIC in Shift / post.";
|
|
50
|
-
if (value.length > 80) return "Shift / post is too long (80 characters at most).";
|
|
51
|
-
return "";
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** What is sent to the server. Never contains the full NRIC. */
|
|
55
|
-
export function proxyPayload(input: { name: string; nric: string; post?: string }) {
|
|
56
|
-
const parsed = parseNric(input.nric);
|
|
57
|
-
if (!parsed.ok) throw new Error(parsed.error);
|
|
58
|
-
const name = String(input.name).trim().replace(/\s+/g, " ");
|
|
59
|
-
const post = String(input.post ?? "").trim();
|
|
60
|
-
return {
|
|
61
|
-
name,
|
|
62
|
-
nricLast4: parsed.nricLast4,
|
|
63
|
-
...(parsed.nricPrefix ? { nricPrefix: parsed.nricPrefix } : {}),
|
|
64
|
-
...(post ? { post } : {}),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** CSV cell: quoted, and a leading = + - @ neutralised so a spreadsheet never runs it. */
|
|
69
|
-
function csvCell(value: unknown): string {
|
|
70
|
-
let text = value === null || value === undefined ? "" : String(value);
|
|
71
|
-
if (/^[=+\-@\t\r]/.test(text)) text = `'${text}`;
|
|
72
|
-
return `"${text.replace(/"/g, '""')}"`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function toCsv(headers: string[], rows: unknown[][]): string {
|
|
76
|
-
return [headers, ...rows].map((row) => row.map(csvCell).join(",")).join("\r\n");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** One export row for an attendance list item (web Attendance page). */
|
|
80
|
-
export function attendanceCsvRow(
|
|
81
|
-
item: Record<string, any>,
|
|
82
|
-
photoLink: (id: string, which: "checkIn" | "checkOut") => string,
|
|
83
|
-
formatDate: (d: unknown) => string,
|
|
84
|
-
): unknown[] {
|
|
85
|
-
return [
|
|
86
|
-
item.isProxy ? item.proxyName : item.userName,
|
|
87
|
-
item.isProxy ? item.nricMasked : "",
|
|
88
|
-
item.isProxy ? item.post ?? "" : "",
|
|
89
|
-
item.isProxy ? `Site device (${item.userName ?? ""})` : "Own account",
|
|
90
|
-
item.checkInTimestamp ? formatDate(item.checkInTimestamp) : "",
|
|
91
|
-
item.checkOutTimestamp ? formatDate(item.checkOutTimestamp) : "",
|
|
92
|
-
item.totalHours ?? "",
|
|
93
|
-
item.hasCheckInPhoto ? photoLink(String(item._id), "checkIn") : "",
|
|
94
|
-
item.hasCheckOutPhoto ? photoLink(String(item._id), "checkOut") : "",
|
|
95
|
-
item.suspicious ? item.suspiciousReason : "",
|
|
96
|
-
];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export const ATTENDANCE_CSV_HEADERS = [
|
|
100
|
-
"Person",
|
|
101
|
-
"NRIC (last 4)",
|
|
102
|
-
"Shift / post",
|
|
103
|
-
"Taken on",
|
|
104
|
-
"Check in",
|
|
105
|
-
"Check out",
|
|
106
|
-
"Total hours",
|
|
107
|
-
"Check-in photo",
|
|
108
|
-
"Check-out photo",
|
|
109
|
-
"Check this",
|
|
110
|
-
];
|