This reverts commit 3ef328421f
.
Co-authored-by: CarinaWolli <wollencarina@gmail.com>
pull/8373/head^2
v2.8.4.1
parent
1a7911e9e2
commit
20c010fef1
|
@ -784,24 +784,6 @@ describe("getSchedule", () => {
|
||||||
dateString: plus2DateString,
|
dateString: plus2DateString,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const scheduleForEventOnADayWithDateOverrideDifferentTimezone = await getSchedule(
|
|
||||||
{
|
|
||||||
eventTypeId: 1,
|
|
||||||
eventTypeSlug: "",
|
|
||||||
startTime: `${plus1DateString}T18:30:00.000Z`,
|
|
||||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
|
||||||
timeZone: Timezones["+6:00"],
|
|
||||||
},
|
|
||||||
ctx
|
|
||||||
);
|
|
||||||
// it should return the same as this is the utc time
|
|
||||||
expect(scheduleForEventOnADayWithDateOverrideDifferentTimezone).toHaveTimeSlots(
|
|
||||||
["08:30:00.000Z", "09:30:00.000Z", "10:30:00.000Z", "11:30:00.000Z"],
|
|
||||||
{
|
|
||||||
dateString: plus2DateString,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("that a user is considered busy when there's a booking they host", async () => {
|
test("that a user is considered busy when there's a booking they host", async () => {
|
||||||
|
|
|
@ -208,22 +208,11 @@ const getSlots = ({
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!!activeOverrides.length) {
|
if (!!activeOverrides.length) {
|
||||||
const overrides = activeOverrides.flatMap((override) => {
|
const overrides = activeOverrides.flatMap((override) => ({
|
||||||
const organizerUtcOffset = dayjs(override.start.toString()).tz(override.timeZone).utcOffset();
|
userIds: override.userId ? [override.userId] : [],
|
||||||
const inviteeUtcOffset = dayjs(override.start.toString()).tz(timeZone).utcOffset();
|
startTime: override.start.getUTCHours() * 60 + override.start.getUTCMinutes(),
|
||||||
const offset = inviteeUtcOffset - organizerUtcOffset;
|
endTime: override.end.getUTCHours() * 60 + override.end.getUTCMinutes(),
|
||||||
|
}));
|
||||||
return {
|
|
||||||
userIds: override.userId ? [override.userId] : [],
|
|
||||||
startTime:
|
|
||||||
dayjs(override.start).utc().add(offset, "minute").hour() * 60 +
|
|
||||||
dayjs(override.start).utc().add(offset, "minute").minute(),
|
|
||||||
endTime:
|
|
||||||
dayjs(override.end).utc().add(offset, "minute").hour() * 60 +
|
|
||||||
dayjs(override.end).utc().add(offset, "minute").minute(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// unset all working hours that relate to this user availability override
|
// unset all working hours that relate to this user availability override
|
||||||
overrides.forEach((override) => {
|
overrides.forEach((override) => {
|
||||||
let i = -1;
|
let i = -1;
|
||||||
|
|
|
@ -19,7 +19,6 @@ import type prisma from "@calcom/prisma";
|
||||||
import { availabilityUserSelect } from "@calcom/prisma";
|
import { availabilityUserSelect } from "@calcom/prisma";
|
||||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||||
import type { EventBusyDate } from "@calcom/types/Calendar";
|
import type { EventBusyDate } from "@calcom/types/Calendar";
|
||||||
import type { WorkingHours } from "@calcom/types/schedule";
|
|
||||||
|
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
|
|
||||||
|
@ -76,21 +75,12 @@ const checkIfIsAvailable = ({
|
||||||
time,
|
time,
|
||||||
busy,
|
busy,
|
||||||
eventLength,
|
eventLength,
|
||||||
dateOverrides = [],
|
|
||||||
workingHours = [],
|
|
||||||
currentSeats,
|
currentSeats,
|
||||||
organizerTimeZone,
|
|
||||||
}: {
|
}: {
|
||||||
time: Dayjs;
|
time: Dayjs;
|
||||||
busy: EventBusyDate[];
|
busy: EventBusyDate[];
|
||||||
eventLength: number;
|
eventLength: number;
|
||||||
dateOverrides?: {
|
|
||||||
start: Date;
|
|
||||||
end: Date;
|
|
||||||
}[];
|
|
||||||
workingHours?: WorkingHours[];
|
|
||||||
currentSeats?: CurrentSeats;
|
currentSeats?: CurrentSeats;
|
||||||
organizerTimeZone?: string;
|
|
||||||
}): boolean => {
|
}): boolean => {
|
||||||
if (currentSeats?.some((booking) => booking.startTime.toISOString() === time.toISOString())) {
|
if (currentSeats?.some((booking) => booking.startTime.toISOString() === time.toISOString())) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -99,57 +89,6 @@ const checkIfIsAvailable = ({
|
||||||
const slotEndTime = time.add(eventLength, "minutes").utc();
|
const slotEndTime = time.add(eventLength, "minutes").utc();
|
||||||
const slotStartTime = time.utc();
|
const slotStartTime = time.utc();
|
||||||
|
|
||||||
//check if date override for slot exists
|
|
||||||
let dateOverrideExist = false;
|
|
||||||
|
|
||||||
if (
|
|
||||||
dateOverrides.find((date) => {
|
|
||||||
const utcOffset = organizerTimeZone ? dayjs.tz(date.start, organizerTimeZone).utcOffset() * -1 : 0;
|
|
||||||
|
|
||||||
if (
|
|
||||||
dayjs(date.start).add(utcOffset, "minutes").format("YYYY MM DD") ===
|
|
||||||
slotStartTime.format("YYYY MM DD")
|
|
||||||
) {
|
|
||||||
dateOverrideExist = true;
|
|
||||||
if (dayjs(date.start).add(utcOffset, "minutes") === dayjs(date.end).add(utcOffset, "minutes")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
slotEndTime.isBefore(dayjs(date.start).add(utcOffset, "minutes")) ||
|
|
||||||
slotEndTime.isSame(dayjs(date.start).add(utcOffset, "minutes"))
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (slotStartTime.isAfter(dayjs(date.end).add(utcOffset, "minutes"))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
// slot is not within the date override
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dateOverrideExist) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//if no date override for slot exists check if it is within normal work hours
|
|
||||||
if (
|
|
||||||
workingHours.find((workingHour) => {
|
|
||||||
if (workingHour.days.includes(slotStartTime.day())) {
|
|
||||||
const start = slotStartTime.hour() * 60 + slotStartTime.minute();
|
|
||||||
const end = slotStartTime.hour() * 60 + slotStartTime.minute();
|
|
||||||
if (start < workingHour.startTime || end > workingHour.endTime) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
// slot is outside of working hours
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return busy.every((busyTime) => {
|
return busy.every((busyTime) => {
|
||||||
const startTime = dayjs.utc(busyTime.start).utc();
|
const startTime = dayjs.utc(busyTime.start).utc();
|
||||||
const endTime = dayjs.utc(busyTime.end);
|
const endTime = dayjs.utc(busyTime.end);
|
||||||
|
@ -176,6 +115,7 @@ const checkIfIsAvailable = ({
|
||||||
else if (startTime.isBetween(time, slotEndTime)) {
|
else if (startTime.isBetween(time, slotEndTime)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -408,11 +348,7 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||||
);
|
);
|
||||||
// flattens availability of multiple users
|
// flattens availability of multiple users
|
||||||
const dateOverrides = userAvailability.flatMap((availability) =>
|
const dateOverrides = userAvailability.flatMap((availability) =>
|
||||||
availability.dateOverrides.map((override) => ({
|
availability.dateOverrides.map((override) => ({ userId: availability.user.id, ...override }))
|
||||||
userId: availability.user.id,
|
|
||||||
timeZone: availability.timeZone,
|
|
||||||
...override,
|
|
||||||
}))
|
|
||||||
);
|
);
|
||||||
const workingHours = getAggregateWorkingHours(userAvailability, eventType.schedulingType);
|
const workingHours = getAggregateWorkingHours(userAvailability, eventType.schedulingType);
|
||||||
const availabilityCheckProps = {
|
const availabilityCheckProps = {
|
||||||
|
@ -436,9 +372,6 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||||
|
|
||||||
const timeSlots: ReturnType<typeof getTimeSlots> = [];
|
const timeSlots: ReturnType<typeof getTimeSlots> = [];
|
||||||
|
|
||||||
const organizerTimeZone =
|
|
||||||
eventType.timeZone || eventType?.schedule?.timeZone || userAvailability?.[0]?.timeZone;
|
|
||||||
|
|
||||||
for (
|
for (
|
||||||
let currentCheckedTime = startTime;
|
let currentCheckedTime = startTime;
|
||||||
currentCheckedTime.isBefore(endTime);
|
currentCheckedTime.isBefore(endTime);
|
||||||
|
@ -453,7 +386,8 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||||
dateOverrides,
|
dateOverrides,
|
||||||
minimumBookingNotice: eventType.minimumBookingNotice,
|
minimumBookingNotice: eventType.minimumBookingNotice,
|
||||||
frequency: eventType.slotInterval || input.duration || eventType.length,
|
frequency: eventType.slotInterval || input.duration || eventType.length,
|
||||||
organizerTimeZone,
|
organizerTimeZone:
|
||||||
|
eventType.timeZone || eventType?.schedule?.timeZone || userAvailability?.[0]?.timeZone,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -489,7 +423,6 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||||
time: slot.time,
|
time: slot.time,
|
||||||
...schedule,
|
...schedule,
|
||||||
...availabilityCheckProps,
|
...availabilityCheckProps,
|
||||||
organizerTimeZone: schedule.timeZone,
|
|
||||||
});
|
});
|
||||||
const endCheckForAvailability = performance.now();
|
const endCheckForAvailability = performance.now();
|
||||||
checkForAvailabilityCount++;
|
checkForAvailabilityCount++;
|
||||||
|
@ -497,7 +430,6 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||||
return isAvailable;
|
return isAvailable;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// what else are you going to call it?
|
// what else are you going to call it?
|
||||||
const looseHostAvailability = userAvailability.filter(({ user: { isFixed } }) => !isFixed);
|
const looseHostAvailability = userAvailability.filter(({ user: { isFixed } }) => !isFixed);
|
||||||
if (looseHostAvailability.length > 0) {
|
if (looseHostAvailability.length > 0) {
|
||||||
|
@ -514,7 +446,6 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||||
time: slot.time,
|
time: slot.time,
|
||||||
...userSchedule,
|
...userSchedule,
|
||||||
...availabilityCheckProps,
|
...availabilityCheckProps,
|
||||||
organizerTimeZone: userSchedule.timeZone,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return slot;
|
return slot;
|
||||||
|
@ -576,19 +507,17 @@ export async function getSchedule(input: z.infer<typeof getScheduleSchema>, ctx:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userSchedule = userAvailability.find(({ user: { id: userId } }) => userId === slotUserId);
|
|
||||||
|
|
||||||
return checkIfIsAvailable({
|
return checkIfIsAvailable({
|
||||||
time: slot.time,
|
time: slot.time,
|
||||||
busy,
|
busy,
|
||||||
...availabilityCheckProps,
|
...availabilityCheckProps,
|
||||||
organizerTimeZone: userSchedule?.timeZone,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return slot;
|
return slot;
|
||||||
})
|
})
|
||||||
.filter((slot) => !!slot.userIds?.length);
|
.filter((slot) => !!slot.userIds?.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
availableTimeSlots = availableTimeSlots.filter((slot) => isTimeWithinBounds(slot.time));
|
availableTimeSlots = availableTimeSlots.filter((slot) => isTimeWithinBounds(slot.time));
|
||||||
|
|
||||||
const computedAvailableSlots = availableTimeSlots.reduce(
|
const computedAvailableSlots = availableTimeSlots.reduce(
|
||||||
|
|
|
@ -2,7 +2,6 @@ export type TimeRange = {
|
||||||
userId?: number | null;
|
userId?: number | null;
|
||||||
start: Date;
|
start: Date;
|
||||||
end: Date;
|
end: Date;
|
||||||
timeZone?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Schedule = TimeRange[][];
|
export type Schedule = TimeRange[][];
|
||||||
|
|
Loading…
Reference in New Issue