dok/routes/himmelstor-daily.route.js
2026-04-14 11:40:20 +01:00

33 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ============================================================
routes/himmelstor-daily.route.js
GET /api/himmelstor/daily/progress welche Stationen heute erledigt
============================================================ */
const express = require("express");
const router = express.Router();
const db = require("../database/database");
function requireLogin(req, res, next) {
if (!req.session?.user) return res.status(401).json({ error: "Nicht eingeloggt" });
next();
}
/* ── GET /api/himmelstor/daily/progress ────────────────── */
router.get("/progress", requireLogin, async (req, res) => {
const userId = req.session.user.id;
try {
const [rows] = await db.query(
"SELECT event_id FROM daily_completions WHERE user_id = ? AND event_id BETWEEN 101 AND 107 AND DATE(completed_at) = CURDATE()",
[userId]
);
// event_id 101-107 → Station 1-7
const completed = rows.map(r => r.event_id - 100);
res.json({ completed, total: 7, allDone: completed.length >= 7 });
} catch (err) {
console.error("[Daily] Fortschritt laden:", err);
res.status(500).json({ error: "DB Fehler" });
}
});
module.exports = router;