fix: eventtype null cant be booked error (#18975)

* fix err msg and add more description

* improvements

* fix cause

* add warn logs for when failing to specific limit checks

* typefix

* safestringify log

* improve error

* test fix and log min booking notice

* adds out of bounds error code

* test fix

* fix
This commit is contained in:
Syed Ali Shahbaz authored and GitHub committed 2025-01-29 13:00:51 +00:00
1 parent 8615ccb1aa
commit 92678dc042
5 files changed
+64 -31

No files matched your search

+1
View File
@@ -16,4 +16,5 @@ export enum ErrorCode {
UnableToSubscribeToThePlatform = "unable_to_subscribe_to_the_platform",
UpdatingOauthClientError = "updating_oauth_client_error",
CreatingOauthClientError = "creating_oauth_client_error",
BookingTimeOutOfBounds = "booking_time_out_of_bounds_error",
}
+53 -18
View File
@@ -250,6 +250,15 @@ export function isTimeViolatingFutureLimit({
isAfterRollingEndDay,
endOfRollingPeriodEndDayInBookerTz: periodLimits.endOfRollingPeriodEndDayInBookerTz.format(),
});
if (isAfterRollingEndDay)
log.warn(
"Booking is out of bounds due to rolling period end day.",
safeStringify({
formattedDate: dateInSystemTz.format(),
isAfterRollingEndDay,
endOfRollingPeriodEndDayInBookerTz: periodLimits.endOfRollingPeriodEndDayInBookerTz.format(),
})
);
return isAfterRollingEndDay;
}
@@ -263,6 +272,17 @@ export function isTimeViolatingFutureLimit({
startOfRangeStartDayInEventTz: periodLimits.startOfRangeStartDayInEventTz.format(),
endOfRangeEndDayInEventTz: periodLimits.endOfRangeEndDayInEventTz.format(),
});
if (isBeforeRangeStart || isAfterRangeEnd)
log.warn(
"Booking is out of bounds due to range start and end.",
safeStringify({
formattedDate: dateInSystemTz.format(),
isBeforeRangeStart,
isAfterRangeEnd,
startOfRangeStartDayInEventTz: periodLimits.startOfRangeStartDayInEventTz.format(),
endOfRangeEndDayInEventTz: periodLimits.endOfRangeEndDayInEventTz.format(),
})
);
return isBeforeRangeStart || isAfterRangeEnd;
}
return false;
@@ -287,22 +307,37 @@ export default function isOutOfBounds(
},
minimumBookingNotice?: number
) {
return (
isTimeOutOfBounds({ time, minimumBookingNotice }) ||
isTimeViolatingFutureLimit({
time,
periodLimits: calculatePeriodLimits({
periodType,
periodDays,
periodCountCalendarDays,
periodStartDate,
periodEndDate,
// Temporary till we find a way to provide allDatesWithBookabilityStatus in handleNewBooking without re-computing availability for the booked timeslot
allDatesWithBookabilityStatusInBookerTz: null,
_skipRollingWindowCheck: true,
eventUtcOffset,
bookerUtcOffset,
}),
})
);
const log = logger.getSubLogger({ prefix: ["isOutOfBounds"] });
const isOutOfBoundsByTime = isTimeOutOfBounds({ time, minimumBookingNotice });
const periodLimits = calculatePeriodLimits({
periodType,
periodDays,
periodCountCalendarDays,
periodStartDate,
periodEndDate,
allDatesWithBookabilityStatusInBookerTz: null, // Temporary workaround
_skipRollingWindowCheck: true,
eventUtcOffset,
bookerUtcOffset,
});
const isOutOfBoundsByPeriod = isTimeViolatingFutureLimit({
time,
periodLimits,
});
if (isOutOfBoundsByTime) {
log.warn(
"Booking is out of bounds due to minimum booking notice.",
safeStringify({ minimumBookingNotice })
);
return true;
}
if (isOutOfBoundsByPeriod) {
log.warn("Booking is out of bounds due to period restrictions", safeStringify({ periodLimits }));
return true;
}
return false;
}