This reverts commit a0f6e50d5b.
Co-authored-by: Hariom Balhara <hariombalhara@gmgmail.com>
This commit is contained in:
co-authored by
Hariom Balhara
parent
240f27ef4c
commit
98d9cd105b
@@ -22,7 +22,8 @@ import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { EventTypeRepository } from "@calcom/lib/server/repository/eventType";
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingStatus, SchedulingType } from "@calcom/prisma/enums";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import { EventTypeMetaDataSchema, stringToDayjsZod } from "@calcom/prisma/zod-utils";
|
||||
import type { EventBusyDetails, IntervalLimitUnit } from "@calcom/types/Calendar";
|
||||
import type { TimeRange } from "@calcom/types/schedule";
|
||||
@@ -541,7 +542,7 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
|
||||
},
|
||||
}));
|
||||
|
||||
const datesOutOfOffice: IOutOfOfficeData = await calculateOutOfOfficeRanges(outOfOfficeDays, availability);
|
||||
const datesOutOfOffice: IOutOfOfficeData = calculateOutOfOfficeRanges(outOfOfficeDays, availability);
|
||||
|
||||
const { dateRanges, oooExcludedDateRanges } = buildDateRanges({
|
||||
dateFrom,
|
||||
@@ -628,17 +629,15 @@ export interface IOutOfOfficeData {
|
||||
};
|
||||
}
|
||||
|
||||
const calculateOutOfOfficeRanges = async (
|
||||
const calculateOutOfOfficeRanges = (
|
||||
outOfOfficeDays: GetUserAvailabilityInitialData["outOfOfficeDays"],
|
||||
availability: GetUserAvailabilityParamsDTO["availability"]
|
||||
): Promise<IOutOfOfficeData> => {
|
||||
): IOutOfOfficeData => {
|
||||
if (!outOfOfficeDays || outOfOfficeDays.length === 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const acc: IOutOfOfficeData = {};
|
||||
|
||||
for (const { start, end, toUser, user, reason } of outOfOfficeDays) {
|
||||
return outOfOfficeDays.reduce((acc: IOutOfOfficeData, { start, end, toUser, user, reason }) => {
|
||||
// here we should use startDate or today if start is before today
|
||||
// consider timezone in start and end date range
|
||||
const startDateRange = dayjs(start).utc().isBefore(dayjs().startOf("day").utc())
|
||||
@@ -659,27 +658,19 @@ const calculateOutOfOfficeRanges = async (
|
||||
continue; // Skip to the next iteration if day not found in flattenDays
|
||||
}
|
||||
|
||||
const enrichedToUser = toUser ? await UserRepository.enrichUserWithItsProfile({ user: toUser }) : null;
|
||||
|
||||
acc[date.format("YYYY-MM-DD")] = {
|
||||
// @TODO: would be good having start and end availability time here, but for now should be good
|
||||
// you can obtain that from user availability defined outside of here
|
||||
fromUser: { id: user.id, displayName: user.name },
|
||||
// optional chaining destructuring toUser
|
||||
...(!!enrichedToUser && {
|
||||
toUser: {
|
||||
id: enrichedToUser.id,
|
||||
username: enrichedToUser.username,
|
||||
displayName: enrichedToUser.name,
|
||||
},
|
||||
}),
|
||||
toUser: !!toUser ? { id: toUser.id, displayName: toUser.name, username: toUser.username } : null,
|
||||
reason: !!reason ? reason.reason : null,
|
||||
emoji: !!reason ? reason.emoji : null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return acc;
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
||||
type GetUsersAvailabilityProps = {
|
||||
|
||||
+1
-21
@@ -184,7 +184,6 @@ function buildSlotsWithDateRanges({
|
||||
}
|
||||
}
|
||||
|
||||
const processedOOODates = new Set<string>();
|
||||
dateRanges.forEach((range) => {
|
||||
const dateYYYYMMDD = range.start.format("YYYY-MM-DD");
|
||||
const startTimeWithMinNotice = dayjs.utc().add(minimumBookingNotice, "minute");
|
||||
@@ -207,25 +206,6 @@ function buildSlotsWithDateRanges({
|
||||
|
||||
slotStartTime = slotStartTime.add(offsetStart ?? 0, "minutes").tz(timeZone);
|
||||
|
||||
// Add OOO slot if exists and is before current range
|
||||
if (datesOutOfOffice) {
|
||||
Object.entries(datesOutOfOffice).forEach(([dateStr, oooData]) => {
|
||||
const oooDate = dayjs(dateStr);
|
||||
if (oooDate.isBefore(dateYYYYMMDD, "day") && !processedOOODates.has(dateStr)) {
|
||||
slots.push({
|
||||
time: oooDate.startOf("day"),
|
||||
away: true,
|
||||
...(oooData.fromUser && { fromUser: oooData.fromUser }),
|
||||
...(oooData.toUser && { toUser: oooData.toUser }),
|
||||
...(oooData.reason && { reason: oooData.reason }),
|
||||
...(oooData.emoji && { emoji: oooData.emoji }),
|
||||
});
|
||||
// when the date range increases in the next iteration, we don't want to process this date again
|
||||
processedOOODates.add(dateStr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
while (!slotStartTime.add(eventLength, "minutes").subtract(1, "second").utc().isAfter(rangeEnd)) {
|
||||
const dateOutOfOfficeExists = datesOutOfOffice?.[dateYYYYMMDD];
|
||||
let slotData: {
|
||||
@@ -251,8 +231,8 @@ function buildSlotsWithDateRanges({
|
||||
...(reason && { reason }),
|
||||
...(emoji && { emoji }),
|
||||
};
|
||||
processedOOODates.add(dateYYYYMMDD);
|
||||
}
|
||||
|
||||
slots.push(slotData);
|
||||
slotStartTime = slotStartTime.add(frequency + (offsetStart ?? 0), "minutes");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user