feat: auto-disable store after notification and improve ntfy payloads
This commit is contained in:
@@ -3,6 +3,7 @@ const foodsharingClient = require('./foodsharingClient');
|
||||
const sessionStore = require('./sessionStore');
|
||||
const { DEFAULT_SETTINGS } = require('./adminConfig');
|
||||
const notificationService = require('./notificationService');
|
||||
const { readConfig, writeConfig } = require('./configStore');
|
||||
|
||||
const weekdayMap = {
|
||||
Montag: 'Monday',
|
||||
@@ -55,6 +56,34 @@ function resolveSettings(settings) {
|
||||
};
|
||||
}
|
||||
|
||||
function deactivateEntryInMemory(entry) {
|
||||
if (entry) {
|
||||
entry.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
function persistEntryDeactivation(profileId, entryId) {
|
||||
if (!profileId || !entryId) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const config = readConfig(profileId);
|
||||
let changed = false;
|
||||
const updated = config.map((item) => {
|
||||
if (String(item?.id) === String(entryId) && item?.active !== false) {
|
||||
changed = true;
|
||||
return { ...item, active: false };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
if (changed) {
|
||||
writeConfig(profileId, updated);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`[CONFIG] Konnte Eintrag ${entryId} für Profil ${profileId} nicht deaktivieren:`, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureSession(session) {
|
||||
const profileId = session.profile?.id;
|
||||
if (!profileId) {
|
||||
@@ -166,8 +195,11 @@ async function processBooking(session, entry, pickup) {
|
||||
storeName,
|
||||
pickupDate: pickup.date,
|
||||
onlyNotify: true,
|
||||
booked: false
|
||||
booked: false,
|
||||
storeId: entry.id
|
||||
});
|
||||
deactivateEntryInMemory(entry);
|
||||
persistEntryDeactivation(session.profile.id, entry.id);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -185,14 +217,20 @@ async function processBooking(session, entry, pickup) {
|
||||
storeName,
|
||||
pickupDate: pickup.date,
|
||||
onlyNotify: false,
|
||||
booked: true
|
||||
booked: true,
|
||||
storeId: entry.id
|
||||
});
|
||||
deactivateEntryInMemory(entry);
|
||||
persistEntryDeactivation(session.profile.id, entry.id);
|
||||
} catch (error) {
|
||||
console.error(`[ERROR] Buchung für ${storeName} am ${readableDate} fehlgeschlagen:`, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function checkEntry(sessionId, entry, settings) {
|
||||
if (entry?.active === false) {
|
||||
return;
|
||||
}
|
||||
const session = sessionStore.get(sessionId);
|
||||
if (!session) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user