Dashboard: Globale Suche mit Live-Ergebnissen fuer Tools, Links, Code, Archiv, Bestellungen

This commit is contained in:
2026-06-05 08:50:00 +02:00
parent e9e639b654
commit 90fed8fb5f
4 changed files with 280 additions and 4 deletions

View File

@@ -0,0 +1,48 @@
const express = require('express');
const db = require('../db');
const { authenticate } = require('../middleware/auth');
const router = express.Router();
router.get('/', authenticate, (req, res) => {
const q = (req.query.q || '').trim();
if (q.length < 2) return res.json({ links:[], snippets:[], calculations:[], orders:[] });
const uid = req.user.id;
const like = `%${q.toLowerCase()}%`;
const links = db.prepare(`
SELECT id, title, url, icon, description, folder_id FROM link_list
WHERE user_id=? AND (LOWER(title) LIKE ? OR LOWER(url) LIKE ? OR LOWER(description) LIKE ?)
ORDER BY title LIMIT 8
`).all(uid, like, like, like);
let snippets = [];
try {
snippets = db.prepare(`
SELECT id, title, description, language FROM snippets
WHERE user_id=? AND (LOWER(title) LIKE ? OR LOWER(description) LIKE ?)
ORDER BY title LIMIT 5
`).all(uid, like, like);
} catch {}
let calculations = [];
try {
calculations = db.prepare(`
SELECT id, name FROM calculations
WHERE user_id=? AND LOWER(name) LIKE ?
ORDER BY name LIMIT 5
`).all(uid, like);
} catch {}
let orders = [];
try {
orders = db.prepare(`
SELECT id, name, status FROM orders
WHERE user_id=? AND LOWER(name) LIKE ?
ORDER BY name LIMIT 5
`).all(uid, like);
} catch {}
res.json({ links, snippets, calculations, orders });
});
module.exports = router;