Dateien nach "backend/src/tools/bestellungen" hochladen

This commit is contained in:
2026-05-26 12:39:58 +02:00
parent fafd9e3121
commit bd358c581f

View File

@@ -24,7 +24,7 @@ const loadOrder = (id, userId) => {
return order; return order;
}; };
// GET / Liste mit Zählern // GET / Liste mit Zählern + Items
router.get('/', authenticate, (req, res) => { router.get('/', authenticate, (req, res) => {
const orders = db.prepare(` const orders = db.prepare(`
SELECT o.*, SELECT o.*,
@@ -38,6 +38,14 @@ router.get('/', authenticate, (req, res) => {
GROUP BY o.id GROUP BY o.id
ORDER BY o.created_at DESC ORDER BY o.created_at DESC
`).all(uid(req)); `).all(uid(req));
// Attach items to each order
const items = db.prepare('SELECT * FROM order_items WHERE order_id IN (SELECT id FROM orders WHERE user_id=?) ORDER BY order_id, id').all(uid(req));
const itemsByOrder = {};
for (const item of items) {
if (!itemsByOrder[item.order_id]) itemsByOrder[item.order_id] = [];
itemsByOrder[item.order_id].push(item);
}
for (const order of orders) order.items = itemsByOrder[order.id] || [];
res.json(orders); res.json(orders);
}); });