button zum prüfen

This commit is contained in:
2025-11-17 21:37:22 +01:00
parent 8e308b0d99
commit cad72232d9
5 changed files with 477 additions and 129 deletions

View File

@@ -7,7 +7,7 @@ const sessionStore = require('./services/sessionStore');
const credentialStore = require('./services/credentialStore');
const { readConfig, writeConfig } = require('./services/configStore');
const foodsharingClient = require('./services/foodsharingClient');
const { scheduleConfig } = require('./services/pickupScheduler');
const { scheduleConfig, runStoreWatchCheck } = require('./services/pickupScheduler');
const adminConfig = require('./services/adminConfig');
const { readNotificationSettings, writeNotificationSettings } = require('./services/userSettingsStore');
const notificationService = require('./services/notificationService');
@@ -295,6 +295,7 @@ async function notifyWatchersForStatusChanges(changes = [], storeInfoMap = new M
});
}
watcher.lastTeamSearchStatus = change.newStatus;
watcher.lastStatusCheckAt = change.fetchedAt || Date.now();
changed = true;
}
}
@@ -789,15 +790,16 @@ app.post('/api/store-watch/subscriptions', requireAuth, (req, res) => {
if (!storeId || !regionId) {
return;
}
const entry = {
storeId: String(storeId),
storeName: store?.storeName || store?.name || `Store ${storeId}`,
regionId: String(regionId),
regionName: store?.regionName || store?.region?.name || '',
lastTeamSearchStatus: previousMap.get(String(storeId))?.lastTeamSearchStatus ?? null
};
normalized.push(entry);
});
const entry = {
storeId: String(storeId),
storeName: store?.storeName || store?.name || `Store ${storeId}`,
regionId: String(regionId),
regionName: store?.regionName || store?.region?.name || '',
lastTeamSearchStatus: previousMap.get(String(storeId))?.lastTeamSearchStatus ?? null,
lastStatusCheckAt: previousMap.get(String(storeId))?.lastStatusCheckAt ?? null
};
normalized.push(entry);
});
const persisted = writeStoreWatch(req.session.profile.id, normalized);
const config = readConfig(req.session.profile.id);
@@ -805,6 +807,20 @@ app.post('/api/store-watch/subscriptions', requireAuth, (req, res) => {
res.json({ success: true, stores: persisted });
});
app.post('/api/store-watch/check', requireAuth, async (req, res) => {
try {
const settings = adminConfig.readSettings();
const summary = await runStoreWatchCheck(req.session.id, settings, {
sendSummary: true,
triggeredBy: 'manual'
});
res.json({ success: true, stores: Array.isArray(summary) ? summary : [] });
} catch (error) {
console.error('[STORE-WATCH] Ad-hoc-Prüfung fehlgeschlagen:', error.message);
res.status(500).json({ error: 'Ad-hoc-Prüfung fehlgeschlagen' });
}
});
app.get('/api/user/preferences', requireAuth, async (req, res) => {
const preferences = readPreferences(req.session.profile.id);
let location = preferences.location;