feat: checkbox to count managed events for team-wide limits (#16923)
Co-authored-by: CarinaWolli <[email protected]>
This commit is contained in:
1 parent
0d757039f7
commit
b5fa43f086
17 files changed
+266
-61
No files matched your search
@@ -27,6 +27,7 @@ const _getBusyTimesFromLimits = async (
|
||||
duration: number | undefined,
|
||||
eventType: NonNullable<EventType>,
|
||||
bookings: EventBusyDetails[],
|
||||
timeZone: string,
|
||||
rescheduleUid?: string
|
||||
) => {
|
||||
performance.mark("limitsStart");
|
||||
@@ -45,6 +46,7 @@ const _getBusyTimesFromLimits = async (
|
||||
eventTypeId: eventType.id,
|
||||
limitManager,
|
||||
rescheduleUid,
|
||||
timeZone,
|
||||
});
|
||||
performance.mark("bookingLimitsEnd");
|
||||
performance.measure(`checking booking limits took $1'`, "bookingLimitsStart", "bookingLimitsEnd");
|
||||
@@ -89,6 +91,8 @@ const _getBusyTimesFromBookingLimits = async (params: {
|
||||
eventTypeId?: number;
|
||||
teamId?: number;
|
||||
user?: { id: number; email: string };
|
||||
includeManagedEvents?: boolean;
|
||||
timeZone?: string | null;
|
||||
}) => {
|
||||
const {
|
||||
bookings,
|
||||
@@ -100,6 +104,8 @@ const _getBusyTimesFromBookingLimits = async (params: {
|
||||
teamId,
|
||||
user,
|
||||
rescheduleUid,
|
||||
includeManagedEvents = false,
|
||||
timeZone,
|
||||
} = params;
|
||||
|
||||
for (const key of descendingLimitKeys) {
|
||||
@@ -123,6 +129,8 @@ const _getBusyTimesFromBookingLimits = async (params: {
|
||||
teamId,
|
||||
user,
|
||||
rescheduleUid,
|
||||
includeManagedEvents,
|
||||
timeZone,
|
||||
});
|
||||
} catch (_) {
|
||||
limitManager.addBusyTime(periodStart, unit);
|
||||
@@ -231,6 +239,8 @@ const _getBusyTimesFromTeamLimits = async (
|
||||
dateFrom: Dayjs,
|
||||
dateTo: Dayjs,
|
||||
teamId: number,
|
||||
includeManagedEvents: boolean,
|
||||
timeZone: string,
|
||||
rescheduleUid?: string
|
||||
) => {
|
||||
const { limitDateFrom, limitDateTo } = getStartEndDateforLimitCheck(
|
||||
@@ -245,6 +255,7 @@ const _getBusyTimesFromTeamLimits = async (
|
||||
startDate: limitDateFrom.toDate(),
|
||||
endDate: limitDateTo.toDate(),
|
||||
excludedUid: rescheduleUid,
|
||||
includeManagedEvents,
|
||||
});
|
||||
|
||||
const busyTimes = bookings.map(({ id, startTime, endTime, eventTypeId, title, userId }) => ({
|
||||
@@ -266,6 +277,8 @@ const _getBusyTimesFromTeamLimits = async (
|
||||
rescheduleUid,
|
||||
teamId,
|
||||
user,
|
||||
includeManagedEvents,
|
||||
timeZone,
|
||||
});
|
||||
|
||||
return limitManager.getBusyTimes();
|
||||
|
||||
@@ -53,10 +53,22 @@ const _getEventType = async (id: number) => {
|
||||
id: true,
|
||||
seatsPerTimeSlot: true,
|
||||
bookingLimits: true,
|
||||
parent: {
|
||||
select: {
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
bookingLimits: true,
|
||||
includeManagedEventsInLimits: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
bookingLimits: true,
|
||||
includeManagedEventsInLimits: true,
|
||||
},
|
||||
},
|
||||
hosts: {
|
||||
@@ -286,20 +298,27 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
|
||||
duration,
|
||||
eventType,
|
||||
initialData?.busyTimesFromLimitsBookings ?? [],
|
||||
timeZone,
|
||||
initialData?.rescheduleUid ?? undefined
|
||||
)
|
||||
: [];
|
||||
|
||||
const teamBookingLimits = parseBookingLimit(eventType?.team?.bookingLimits);
|
||||
const teamForBookingLimits =
|
||||
eventType?.team ??
|
||||
(eventType?.parent?.team?.includeManagedEventsInLimits ? eventType?.parent?.team : null);
|
||||
|
||||
const teamBookingLimits = parseBookingLimit(teamForBookingLimits?.bookingLimits);
|
||||
|
||||
const busyTimesFromTeamLimits =
|
||||
eventType?.team && teamBookingLimits
|
||||
teamForBookingLimits && teamBookingLimits
|
||||
? await getBusyTimesFromTeamLimits(
|
||||
user,
|
||||
teamBookingLimits,
|
||||
dateFrom.tz(timeZone),
|
||||
dateTo.tz(timeZone),
|
||||
eventType?.team.id,
|
||||
teamForBookingLimits.id,
|
||||
teamForBookingLimits.includeManagedEventsInLimits,
|
||||
timeZone,
|
||||
initialData?.rescheduleUid ?? undefined
|
||||
)
|
||||
: [];
|
||||
@@ -458,6 +477,7 @@ const _getPeriodStartDatesBetween = (dateFrom: Dayjs, dateTo: Dayjs, period: Int
|
||||
const dates = [];
|
||||
let startDate = dayjs(dateFrom).startOf(period);
|
||||
const endDate = dayjs(dateTo).endOf(period);
|
||||
|
||||
while (startDate.isBefore(endDate)) {
|
||||
dates.push(startDate);
|
||||
startDate = startDate.add(1, period);
|
||||
|
||||
Reference in new issue
Block a user