fix: tolerate same-day pickup profile check
Allow configured stores to ignore a visible same-day profile pickup when booking a future pickup slot, starting with store 33875. Keep the default profile check behavior unchanged for all other stores.
This commit is contained in:
@@ -14,6 +14,7 @@ const { ensureSession, withSessionRetry } = require('./sessionRefresh');
|
||||
const maintenanceMode = require('./maintenanceMode');
|
||||
const { computeReminderSchedule } = require('./journalReminderUtils');
|
||||
const { startStoreMessageWatcher } = require('./storeMessageWatcher');
|
||||
const { getBlockingProfilePickup } = require('./profileCheckTolerance');
|
||||
|
||||
function wait(ms) {
|
||||
if (!ms || ms <= 0) {
|
||||
@@ -959,7 +960,7 @@ async function checkEntry(sessionId, entry, settings) {
|
||||
() => foodsharingClient.fetchPickups(entry.id, session.cookieHeader, session),
|
||||
{ label: 'fetchPickups' }
|
||||
);
|
||||
let hasProfileId = false;
|
||||
const profilePickups = [];
|
||||
let availablePickup = null;
|
||||
|
||||
const desiredWeekday = entry.desiredWeekday ? weekdayMap[entry.desiredWeekday] || entry.desiredWeekday : null;
|
||||
@@ -970,7 +971,7 @@ async function checkEntry(sessionId, entry, settings) {
|
||||
entry.checkProfileId &&
|
||||
pickup.occupiedSlots?.some((slot) => String(slot.profile?.id) === String(session.profile.id))
|
||||
) {
|
||||
hasProfileId = true;
|
||||
profilePickups.push(pickup);
|
||||
}
|
||||
if (!matchesDesiredDate(pickupDate, entry.desiredDate, entry.desiredDateRange)) {
|
||||
return;
|
||||
@@ -983,20 +984,35 @@ async function checkEntry(sessionId, entry, settings) {
|
||||
}
|
||||
});
|
||||
|
||||
if (entry.checkProfileId && hasProfileId) {
|
||||
if (!availablePickup) {
|
||||
console.log(
|
||||
`[INFO] Kein freier Slot für ${entry.label || entry.id} in dieser Runde gefunden. Profil bereits eingetragen: ${
|
||||
profilePickups.length > 0 ? 'ja' : 'nein'
|
||||
}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const blockingProfilePickup = entry.checkProfileId
|
||||
? getBlockingProfilePickup({
|
||||
storeId: entry.id,
|
||||
profilePickups,
|
||||
targetPickup: availablePickup
|
||||
})
|
||||
: null;
|
||||
|
||||
if (entry.checkProfileId && blockingProfilePickup) {
|
||||
console.log(
|
||||
`[INFO] Profil bereits in einem Slot für ${entry.label || entry.id} eingetragen – überspringe Buchung.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!availablePickup) {
|
||||
if (entry.checkProfileId && profilePickups.length > 0 && !blockingProfilePickup) {
|
||||
console.log(
|
||||
`[INFO] Kein freier Slot für ${entry.label || entry.id} in dieser Runde gefunden. Profil bereits eingetragen: ${
|
||||
hasProfileId ? 'ja' : 'nein'
|
||||
}`
|
||||
`[INFO] Heutige Profileintragung für ${entry.label || entry.id} wird toleriert; ` +
|
||||
`Zieltermin: ${new Date(availablePickup.date).toLocaleString('de-DE')}.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldIgnoreSlot(entry, availablePickup, settings)) {
|
||||
@@ -1004,7 +1020,7 @@ async function checkEntry(sessionId, entry, settings) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entry.checkProfileId || !hasProfileId) {
|
||||
if (!entry.checkProfileId || !blockingProfilePickup) {
|
||||
await processBooking(session, entry, availablePickup);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user