User Management

This commit is contained in:
Oliver
2026-05-25 12:43:21 -03:00
parent 45cde10a21
commit 18ea3f19d6
3 changed files with 27 additions and 16 deletions
+7 -7
View File
@@ -43,16 +43,16 @@ GET <base_url>
Authorization: Basic <base64> Authorization: Basic <base64>
``` ```
Response — n8n may return a JSON array, a single object, or NDJSON. **Actual response shape** (confirmed via console):
All three formats are handled by `parseJson()` (see below).
```json ```json
[ { "Name": ["Oliver", "Luka", "Benni"] }
{ "Name": "Oliver", "id": 1, "createdAt": "...", "updatedAt": "..." },
{ "Name": "Luka", "id": 2, ... },
{ "Name": "Benni", "id": 3, ... }
]
``` ```
`buildDropdown()` handles all three shapes n8n may return:
1. `{ Name: ["Oliver", "Luka", "Benni"] }` — single object, Name is an array (current)
2. `[ { Name: "Oliver" }, ... ]` — array of objects
3. `{ Name: "Oliver" }` — single object, Name is a string
### POST — submit scan ### POST — submit scan
Called when the user presses Enter in the scan input. Called when the user presses Enter in the scan input.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

+20 -9
View File
@@ -1280,6 +1280,7 @@
} }
const data = await parseJson(res); const data = await parseJson(res);
console.log("[HR] Users response:", data);
buildDropdown(data); buildDropdown(data);
hideBanner(); hideBanner();
} catch (err) { } catch (err) {
@@ -1296,15 +1297,25 @@
function buildDropdown(users) { function buildDropdown(users) {
userSelect.innerHTML = userSelect.innerHTML =
'<option value="">— Select User —</option>'; '<option value="">— Select User —</option>';
// Normalise: webhook may return a single object or an array
const list = Array.isArray(users) // Normalise all shapes n8n may return:
? users // { Name: ["Oliver", "Luka", "Benni"] } ← actual format
: users // [ { Name: "Oliver" }, ... ] ← standard array
? [users] // { Name: "Oliver" } ← single object
: []; let names = [];
list.forEach((u) => { if (Array.isArray(users)) {
const opt = new Option(u.Name, u.Name); // Array of objects: pull .Name from each
userSelect.appendChild(opt); names = users.map((u) => u.Name).filter(Boolean);
} else if (users && Array.isArray(users.Name)) {
// Single object with a Name array
names = users.Name.filter(Boolean);
} else if (users && users.Name) {
// Single object with a single Name string
names = [users.Name];
}
names.forEach((name) => {
userSelect.appendChild(new Option(name, name));
}); });
} }