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:
39
services/profileCheckTolerance.js
Normal file
39
services/profileCheckTolerance.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const TIME_ZONE = 'Europe/Berlin';
|
||||
const TODAY_PROFILE_CHECK_TOLERANCE_STORE_IDS = new Set(['33875']);
|
||||
|
||||
function getDateKeyInTimeZone(date, timeZone = TIME_ZONE) {
|
||||
const parsed = date instanceof Date ? date : new Date(date);
|
||||
if (Number.isNaN(parsed.getTime())) {
|
||||
return null;
|
||||
}
|
||||
const formatter = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone,
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
});
|
||||
return formatter.format(parsed);
|
||||
}
|
||||
|
||||
function getBlockingProfilePickup({ storeId, profilePickups = [], targetPickup, now = new Date() }) {
|
||||
const pickUpsWithDate = profilePickups.filter((pickup) => pickup?.date);
|
||||
if (pickUpsWithDate.length === 0) {
|
||||
return null;
|
||||
}
|
||||
if (!TODAY_PROFILE_CHECK_TOLERANCE_STORE_IDS.has(String(storeId))) {
|
||||
return pickUpsWithDate[0];
|
||||
}
|
||||
|
||||
const todayKey = getDateKeyInTimeZone(now);
|
||||
const targetKey = getDateKeyInTimeZone(targetPickup?.date);
|
||||
if (!todayKey || !targetKey || targetKey === todayKey) {
|
||||
return pickUpsWithDate[0];
|
||||
}
|
||||
|
||||
return pickUpsWithDate.find((pickup) => getDateKeyInTimeZone(pickup.date) !== todayKey) || null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
TODAY_PROFILE_CHECK_TOLERANCE_STORE_IDS,
|
||||
getBlockingProfilePickup
|
||||
};
|
||||
Reference in New Issue
Block a user