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

@@ -98,6 +98,16 @@ async function sendSlotNotification({ profileId, storeName, pickupDate, onlyNoti
});
}
function formatStoreWatchStatus(status) {
if (status === 1) {
return 'Suchend';
}
if (status === 0) {
return 'Nicht suchend';
}
return 'Status unbekannt';
}
async function sendStoreWatchNotification({ profileId, storeName, storeId, regionName }) {
const storeLink = storeId ? `https://foodsharing.de/store/${storeId}` : null;
const title = `Team sucht Verstärkung: ${storeName}`;
@@ -112,6 +122,33 @@ async function sendStoreWatchNotification({ profileId, storeName, storeId, regio
});
}
async function sendStoreWatchSummaryNotification({ profileId, entries = [], triggeredBy = 'manual' }) {
if (!profileId || !Array.isArray(entries) || entries.length === 0) {
return;
}
const lines = entries
.map((entry) => {
const regionSuffix = entry.regionName ? ` (${entry.regionName})` : '';
const statusLabel = formatStoreWatchStatus(entry.status);
const timestamp = entry.checkedAt ? ` Stand ${formatDateLabel(entry.checkedAt)}` : '';
const errorLabel = entry.error ? ` Fehler: ${entry.error}` : '';
return `${entry.storeName || `Store ${entry.storeId}`}${regionSuffix}: ${statusLabel}${timestamp}${errorLabel}`;
})
.join('\n');
const prefix =
triggeredBy === 'manual'
? 'Manuell angestoßene Store-Watch-Prüfung abgeschlossen:'
: 'Store-Watch-Prüfung abgeschlossen:';
const title =
triggeredBy === 'manual' ? 'Ad-hoc Store-Watch-Prüfung' : 'Store-Watch-Prüfung';
const message = `${prefix}\n${lines}`;
await notifyChannels(profileId, {
title,
message,
priority: 'default'
});
}
async function sendDesiredWindowMissedNotification({ profileId, storeName, desiredWindowLabel }) {
if (!profileId) {
return;
@@ -165,6 +202,7 @@ async function sendTestNotification(profileId, channel) {
module.exports = {
sendSlotNotification,
sendStoreWatchNotification,
sendStoreWatchSummaryNotification,
sendTestNotification,
sendDesiredWindowMissedNotification
};