fix: buffer times in handleNewBooking (#14871)
* get buffer busy time from bookings outside of start and end time * add test for buffers * fix typo --------- Co-authored-by: CarinaWolli <[email protected]>
This commit is contained in:
1 parent
b8890c841c
commit
304ef29618
4 files changed
+152
-3
No files matched your search
@@ -14,6 +14,8 @@ import { stringToDayjs } from "@calcom/prisma/zod-utils";
|
||||
import type { EventBusyDetails, IntervalLimit } from "@calcom/types/Calendar";
|
||||
import type { CredentialPayload } from "@calcom/types/Credential";
|
||||
|
||||
import { getDefinedBufferTimes } from "../features/eventtypes/lib/getDefinedBufferTimes";
|
||||
|
||||
export async function getBusyTimes(params: {
|
||||
credentials: CredentialPayload[];
|
||||
userId: number;
|
||||
@@ -85,10 +87,16 @@ export async function getBusyTimes(params: {
|
||||
const endTimeDate =
|
||||
rescheduleUid && duration ? dayjs(endTime).add(duration, "minute").toDate() : new Date(endTime);
|
||||
|
||||
// to also get bookings that are outside of start and end time, but the buffer falls within the start and end time
|
||||
const definedBufferTimes = getDefinedBufferTimes();
|
||||
const maxBuffer = definedBufferTimes[definedBufferTimes.length - 1];
|
||||
const startTimeAdjustedWithMaxBuffer = dayjs(startTimeDate).subtract(maxBuffer, "minute").toDate();
|
||||
const endTimeAdjustedWithMaxBuffer = dayjs(endTimeDate).add(maxBuffer, "minute").toDate();
|
||||
|
||||
// startTime is less than endTimeDate and endTime grater than startTimeDate
|
||||
const sharedQuery = {
|
||||
startTime: { lte: endTimeDate },
|
||||
endTime: { gte: startTimeDate },
|
||||
startTime: { lte: endTimeAdjustedWithMaxBuffer },
|
||||
endTime: { gte: startTimeAdjustedWithMaxBuffer },
|
||||
status: {
|
||||
in: [BookingStatus.ACCEPTED],
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user