aktueller stand
This commit is contained in:
File diff suppressed because one or more lines are too long
59
server.js
59
server.js
@@ -150,6 +150,31 @@ async function fetchProfileWithCache(session, { force = false } = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function buildRegularPickupMapForConfig(session, config) {
|
||||||
|
try {
|
||||||
|
const entries = Array.isArray(config) ? config : [];
|
||||||
|
const storeIds = Array.from(
|
||||||
|
new Set(entries.filter((entry) => entry?.id && !entry.hidden).map((entry) => String(entry.id)))
|
||||||
|
);
|
||||||
|
if (storeIds.length === 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const results = await Promise.all(
|
||||||
|
storeIds.map(async (storeId) => {
|
||||||
|
const result = await getRegularPickupSchedule(session, storeId);
|
||||||
|
return [storeId, Array.isArray(result.rules) ? result.rules : []];
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return results.reduce((acc, [storeId, rules]) => {
|
||||||
|
acc[storeId] = rules;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('[PICKUP] Regular-Pickup-Map konnte nicht geladen werden:', error.message);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function scheduleWithCurrentSettings(sessionId, config) {
|
function scheduleWithCurrentSettings(sessionId, config) {
|
||||||
const settings = adminConfig.readSettings();
|
const settings = adminConfig.readSettings();
|
||||||
scheduleConfig(sessionId, config, settings);
|
scheduleConfig(sessionId, config, settings);
|
||||||
@@ -848,9 +873,13 @@ app.post('/api/auth/logout', requireAuth, (req, res) => {
|
|||||||
app.get('/api/auth/session', requireAuth, async (req, res) => {
|
app.get('/api/auth/session', requireAuth, async (req, res) => {
|
||||||
const settings = adminConfig.readSettings();
|
const settings = adminConfig.readSettings();
|
||||||
const { stores } = await loadStoresForSession(req.session, settings, { reason: 'session-check' });
|
const { stores } = await loadStoresForSession(req.session, settings, { reason: 'session-check' });
|
||||||
|
const config = readConfig(req.session.profile.id);
|
||||||
|
const regularPickupMap = await buildRegularPickupMapForConfig(req.session, config);
|
||||||
res.json({
|
res.json({
|
||||||
profile: req.session.profile,
|
profile: req.session.profile,
|
||||||
stores,
|
stores,
|
||||||
|
config,
|
||||||
|
regularPickupMap,
|
||||||
isAdmin: !!req.session.isAdmin,
|
isAdmin: !!req.session.isAdmin,
|
||||||
adminSettings: req.session.isAdmin ? settings : undefined,
|
adminSettings: req.session.isAdmin ? settings : undefined,
|
||||||
storeRefreshJob: summarizeJob(getStoreRefreshJob(req.session.id)),
|
storeRefreshJob: summarizeJob(getStoreRefreshJob(req.session.id)),
|
||||||
@@ -1336,34 +1365,8 @@ app.get('/api/stores/:storeId/regular-pickup', requireAuth, async (req, res) =>
|
|||||||
|
|
||||||
app.get('/api/stores', requireAuth, async (req, res) => {
|
app.get('/api/stores', requireAuth, async (req, res) => {
|
||||||
const stores = req.session.storesCache?.data || [];
|
const stores = req.session.storesCache?.data || [];
|
||||||
let regularPickupMap = {};
|
const config = readConfig(req.session.profile.id);
|
||||||
try {
|
const regularPickupMap = await buildRegularPickupMapForConfig(req.session, config);
|
||||||
const profileId = req.session.profile?.id;
|
|
||||||
if (profileId) {
|
|
||||||
const config = readConfig(profileId);
|
|
||||||
const storeIds = Array.from(
|
|
||||||
new Set(
|
|
||||||
(Array.isArray(config) ? config : [])
|
|
||||||
.filter((entry) => entry?.id && !entry.hidden)
|
|
||||||
.map((entry) => String(entry.id))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (storeIds.length > 0) {
|
|
||||||
const results = await Promise.all(
|
|
||||||
storeIds.map(async (storeId) => {
|
|
||||||
const result = await getRegularPickupSchedule(req.session, storeId);
|
|
||||||
return [storeId, Array.isArray(result.rules) ? result.rules : []];
|
|
||||||
})
|
|
||||||
);
|
|
||||||
regularPickupMap = results.reduce((acc, [storeId, rules]) => {
|
|
||||||
acc[storeId] = rules;
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('[PICKUP] Regular-Pickup-Map konnte nicht geladen werden:', error.message);
|
|
||||||
}
|
|
||||||
res.json({ stores, regularPickupMap });
|
res.json({ stores, regularPickupMap });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
10
src/App.js
10
src/App.js
@@ -40,6 +40,7 @@ function App() {
|
|||||||
const [focusedStoreId, setFocusedStoreId] = useState(null);
|
const [focusedStoreId, setFocusedStoreId] = useState(null);
|
||||||
const [nearestStoreLabel, setNearestStoreLabel] = useState(null);
|
const [nearestStoreLabel, setNearestStoreLabel] = useState(null);
|
||||||
const [regularPickupMap, setRegularPickupMap] = useState({});
|
const [regularPickupMap, setRegularPickupMap] = useState({});
|
||||||
|
const bootstrapOnceRef = useRef(false);
|
||||||
const minSelectableDate = useMemo(() => startOfDay(new Date()), []);
|
const minSelectableDate = useMemo(() => startOfDay(new Date()), []);
|
||||||
|
|
||||||
const weekdays = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'];
|
const weekdays = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'];
|
||||||
@@ -232,9 +233,12 @@ function App() {
|
|||||||
setStores(Array.isArray(result.stores) ? result.stores : []);
|
setStores(Array.isArray(result.stores) ? result.stores : []);
|
||||||
setAdminSettingsSnapshot(result.adminSettings ?? null);
|
setAdminSettingsSnapshot(result.adminSettings ?? null);
|
||||||
setConfig(Array.isArray(result.config) ? result.config : []);
|
setConfig(Array.isArray(result.config) ? result.config : []);
|
||||||
|
if (result.regularPickupMap && typeof result.regularPickupMap === 'object') {
|
||||||
|
setRegularPickupMap(result.regularPickupMap);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
[setStores, setAdminSettingsSnapshot, setConfig]
|
[setStores, setAdminSettingsSnapshot, setConfig, setRegularPickupMap]
|
||||||
);
|
);
|
||||||
|
|
||||||
const resetSessionState = useCallback(() => {
|
const resetSessionState = useCallback(() => {
|
||||||
@@ -361,6 +365,10 @@ function App() {
|
|||||||
let ticker;
|
let ticker;
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
(async () => {
|
(async () => {
|
||||||
|
if (bootstrapOnceRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bootstrapOnceRef.current = true;
|
||||||
const storedToken = getStoredToken();
|
const storedToken = getStoredToken();
|
||||||
if (!storedToken) {
|
if (!storedToken) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -91,26 +91,32 @@ const useSessionManager = ({ normalizeConfigEntries, onUnauthorized, setError, s
|
|||||||
progress?.update?.('Betriebe werden geprüft...', 45);
|
progress?.update?.('Betriebe werden geprüft...', 45);
|
||||||
const stores = Array.isArray(data.stores) ? data.stores : [];
|
const stores = Array.isArray(data.stores) ? data.stores : [];
|
||||||
const adminSettings = data.isAdmin ? normalizeAdminSettings(data.adminSettings) : null;
|
const adminSettings = data.isAdmin ? normalizeAdminSettings(data.adminSettings) : null;
|
||||||
|
const configSource = Array.isArray(data.config) ? data.config : data.config || null;
|
||||||
const configResponse = await fetch('/api/config', {
|
let config = normalizeConfigEntries(Array.isArray(configSource) ? configSource : []);
|
||||||
headers: { Authorization: `Bearer ${token}` }
|
if (!configSource) {
|
||||||
});
|
const configResponse = await fetch('/api/config', {
|
||||||
if (configResponse.status === 401) {
|
headers: { Authorization: `Bearer ${token}` }
|
||||||
handleUnauthorized();
|
});
|
||||||
return {};
|
if (configResponse.status === 401) {
|
||||||
|
handleUnauthorized();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
if (!configResponse.ok) {
|
||||||
|
throw new Error(`HTTP ${configResponse.status}`);
|
||||||
|
}
|
||||||
|
const configData = await configResponse.json();
|
||||||
|
progress?.update?.('Konfiguration wird geladen...', 75);
|
||||||
|
config = normalizeConfigEntries(Array.isArray(configData) ? configData : []);
|
||||||
|
} else {
|
||||||
|
progress?.update?.('Konfiguration wird geladen...', 75);
|
||||||
}
|
}
|
||||||
if (!configResponse.ok) {
|
|
||||||
throw new Error(`HTTP ${configResponse.status}`);
|
|
||||||
}
|
|
||||||
const configData = await configResponse.json();
|
|
||||||
progress?.update?.('Konfiguration wird geladen...', 75);
|
|
||||||
const config = normalizeConfigEntries(Array.isArray(configData) ? configData : []);
|
|
||||||
progress?.update?.('Synchronisierung abgeschlossen', 95);
|
progress?.update?.('Synchronisierung abgeschlossen', 95);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
session: sessionData,
|
session: sessionData,
|
||||||
stores,
|
stores,
|
||||||
adminSettings,
|
adminSettings,
|
||||||
|
regularPickupMap: data.regularPickupMap ?? null,
|
||||||
config,
|
config,
|
||||||
storeRefreshJob: data.storeRefreshJob,
|
storeRefreshJob: data.storeRefreshJob,
|
||||||
storesFresh: data.storesFresh
|
storesFresh: data.storesFresh
|
||||||
|
|||||||
Reference in New Issue
Block a user