feat(devices): manually add a device by MAC (offline pre-register) → 2.1.3
'+ Add by MAC' in the band header → POST /api/devices → lan_devices.addManual (status=known, present=false; enriched on next scan). Repo + API + frontend tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,21 @@ export async function get(mac) {
|
||||
return r || null;
|
||||
}
|
||||
|
||||
// Manually add a device by MAC (e.g. an offline device whose MAC you know). Lands
|
||||
// as status='known', present=false. Idempotent — re-adding updates name/grp/vendor.
|
||||
export async function addManual({ mac, name = null, grp = 'Flagged', vendor = null, randomized = false }) {
|
||||
const { rows: [r] } = await pool.query(
|
||||
`INSERT INTO lan_devices (mac, name, grp, vendor, randomized, status, present, first_seen, last_seen)
|
||||
VALUES ($1,$2,$3,$4,$5,'known',false,now(),now())
|
||||
ON CONFLICT (mac) DO UPDATE SET
|
||||
name = EXCLUDED.name, grp = EXCLUDED.grp,
|
||||
vendor = COALESCE(NULLIF(EXCLUDED.vendor,''), lan_devices.vendor),
|
||||
status = 'known'
|
||||
RETURNING ${COLS}`,
|
||||
[mac, name, grp, vendor, !!randomized]);
|
||||
return r;
|
||||
}
|
||||
|
||||
// Insert unseen MACs as status='new'; for existing, refresh ip/vendor/last_seen/present
|
||||
// WITHOUT touching owner-curated name/grp/status/flagged.
|
||||
export async function upsertScan(rows) {
|
||||
|
||||
Reference in New Issue
Block a user