Neue Seite um Betriebe zu überwachen

This commit is contained in:
2025-11-10 17:22:26 +01:00
parent 49dec43c1e
commit 69a588e6f1
7 changed files with 458 additions and 24 deletions

View File

@@ -12,6 +12,7 @@ const adminConfig = require('./services/adminConfig');
const { readNotificationSettings, writeNotificationSettings } = require('./services/userSettingsStore');
const notificationService = require('./services/notificationService');
const { readStoreWatch, writeStoreWatch } = require('./services/storeWatchStore');
const { readPreferences, writePreferences } = require('./services/userPreferencesStore');
const ONE_YEAR_MS = 365 * 24 * 60 * 60 * 1000;
const adminEmail = (process.env.ADMIN_EMAIL || '').toLowerCase();
@@ -463,6 +464,35 @@ app.post('/api/store-watch/subscriptions', requireAuth, (req, res) => {
res.json({ success: true, stores: persisted });
});
app.get('/api/user/preferences', requireAuth, (req, res) => {
const preferences = readPreferences(req.session.profile.id);
res.json(preferences);
});
app.post('/api/user/preferences/location', requireAuth, (req, res) => {
const { lat, lon } = req.body || {};
if (lat === null || lon === null || lat === undefined || lon === undefined) {
const updated = writePreferences(req.session.profile.id, { location: null });
return res.json({ location: updated.location });
}
const parsedLat = Number(lat);
const parsedLon = Number(lon);
if (
!Number.isFinite(parsedLat) ||
!Number.isFinite(parsedLon) ||
parsedLat < -90 ||
parsedLat > 90 ||
parsedLon < -180 ||
parsedLon > 180
) {
return res.status(400).json({ error: 'Ungültige Koordinaten' });
}
const updated = writePreferences(req.session.profile.id, {
location: { lat: parsedLat, lon: parsedLon }
});
res.json({ location: updated.location });
});
app.get('/api/config', requireAuth, (req, res) => {
const config = readConfig(req.session.profile.id);
res.json(config);