Initial commit baby!

This commit is contained in:
Rich Teslow
2026-04-13 18:15:41 -07:00
parent 10e6227931
commit 6b0fc9fdf1
99 changed files with 34064 additions and 3 deletions
+51
View File
@@ -0,0 +1,51 @@
import { Router, Request, Response } from 'express';
import { query } from '../config/database';
import { requireAuth } from '../middleware/auth';
const router = Router();
router.use(requireAuth);
// GET /api/search?q=<term>
router.get('/', async (req: Request, res: Response) => {
const q = String(req.query.q || '').trim();
if (q.length < 2) {
return res.json({ devices: [], clients: [], events: [] });
}
const like = `%${q}%`;
const [devices, clients, events] = await Promise.all([
query(
`SELECT id, name, ip_address, model, device_type, status
FROM devices
WHERE name ILIKE $1 OR ip_address ILIKE $1 OR model ILIKE $1 OR serial_number ILIKE $1
ORDER BY (status = 'online') DESC, name ASC
LIMIT 6`,
[like]
),
query(
`SELECT c.mac_address, c.hostname, c.ip_address, c.device_id, c.active,
d.name as device_name
FROM clients c
LEFT JOIN devices d ON d.id = c.device_id
WHERE c.mac_address ILIKE $1 OR c.hostname ILIKE $1 OR c.ip_address ILIKE $1
ORDER BY c.active DESC, c.last_seen DESC
LIMIT 6`,
[like]
),
query(
`SELECT e.id, e.message, e.severity, e.event_time, e.topic, e.device_id,
d.name as device_name
FROM events e
LEFT JOIN devices d ON d.id = e.device_id
WHERE e.message ILIKE $1 OR e.topic ILIKE $1 OR d.name ILIKE $1
ORDER BY e.event_time DESC
LIMIT 6`,
[like]
),
]);
res.json({ devices, clients, events });
});
export default router;