aktueller stand
This commit is contained in:
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) {
|
||||
const settings = adminConfig.readSettings();
|
||||
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) => {
|
||||
const settings = adminConfig.readSettings();
|
||||
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({
|
||||
profile: req.session.profile,
|
||||
stores,
|
||||
config,
|
||||
regularPickupMap,
|
||||
isAdmin: !!req.session.isAdmin,
|
||||
adminSettings: req.session.isAdmin ? settings : undefined,
|
||||
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) => {
|
||||
const stores = req.session.storesCache?.data || [];
|
||||
let regularPickupMap = {};
|
||||
try {
|
||||
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);
|
||||
}
|
||||
const config = readConfig(req.session.profile.id);
|
||||
const regularPickupMap = await buildRegularPickupMapForConfig(req.session, config);
|
||||
res.json({ stores, regularPickupMap });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user