refactor: convert findQualifiedHostsWithDelegationCredentials to service class with DI (#22974)
* refactor: convert findQualifiedHostsWithDelegationCredentials to service class with DI - Create QualifiedHostsService class following UserAvailabilityService pattern - Add IQualifiedHostsService interface with prisma and bookingRepo dependencies - Create DI module and container for qualified hosts service - Update filterHostsBySameRoundRobinHost to accept prisma as parameter - Update all usage sites to use the new service: - loadAndValidateUsers.ts - slots/util.ts - test mocks in _post.test.ts - Maintain backward compatibility with original function export - Fix type issues in team properties (rrResetInterval, rrTimestampBasis) Co-Authored-By: [email protected] <[email protected]> * fix: update filterHostsBySameRoundRobinHost test to include prisma parameter - Add missing prisma parameter to all test function calls - Resolves unit test failure caused by function signature change Co-Authored-By: [email protected] <[email protected]> * fix: resolve type issues in FilterHostsService - Import PrismaClient type instead of using unknown - Fix type compatibility for BookingRepository constructor - Update test mocks to use proper BookingRepository type - Ensure all DI dependencies are properly typed Co-Authored-By: [email protected] <[email protected]> * refactor: rename DI files to CamelCase and update imports - Rename all files in packages/lib/di from kebab-case to CamelCase - Update 22 external files with import statements to use new file names - Update internal DI module files with corrected imports - Maintain consistency with TypeScript naming conventions Co-Authored-By: [email protected] <[email protected]> * chore: bump platform libs * chore: bump platform libs * fix: remove obsolete vitest mock after service class refactoring - Remove obsolete mock for old function module - Keep correct mock for new DI container - Resolves CI unit test failures Co-Authored-By: [email protected] <[email protected]> * fix: correct import path for calAIPhone zod-utils module Co-Authored-By: [email protected] <[email protected]> * fix: Booker active booking limit can't be switched off (#23005) * refactor: Get rid of `getServerSideProps` for /getting-started pages (#23003) * refactor * fix type check * fix: Remove Reporting page within Routing Forms (#22990) * fix error in handleNewBooking (#23011) Co-authored-by: CarinaWolli <[email protected]> * Documentation edits made through Mintlify web editor (#23007) Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> * fix: Contact support button position changed from absolute to fixed (#23002) * feat: Add private links to API (#22943) * --init * address change requests * adding further changes * address feedback * further changes * further clean-up * clean up * fix module import and others * add guards * remove unnecessary comments * remove unnecessary comments * cleanup * sort coderabbig suggestions * improve check * chore: bump platform libraries --------- Co-authored-by: Lauris Skraucis <[email protected]> Co-authored-by: supalarry <[email protected]> * chore: release v5.5.15 * chore: bump platform libs * chore: bump platform libs --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]> Co-authored-by: Benny Joo <[email protected]> Co-authored-by: Sahitya Chandra <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> Co-authored-by: Ayush Kumar <[email protected]> Co-authored-by: Syed Ali Shahbaz <[email protected]> Co-authored-by: Lauris Skraucis <[email protected]> Co-authored-by: supalarry <[email protected]> Co-authored-by: emrysal <[email protected]>
This commit is contained in:
58 files changed
+433
-285
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
import type { NextApiRequest } from "next";
|
import type { NextApiRequest } from "next";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { getUserAvailabilityService } from "@calcom/lib/di/containers/get-user-availability";
|
import { getUserAvailabilityService } from "@calcom/lib/di/containers/GetUserAvailability";
|
||||||
import { HttpError } from "@calcom/lib/http-error";
|
import { HttpError } from "@calcom/lib/http-error";
|
||||||
import { defaultResponder } from "@calcom/lib/server/defaultResponder";
|
import { defaultResponder } from "@calcom/lib/server/defaultResponder";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
|||||||
|
|
||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
import { isSupportedTimeZone } from "@calcom/lib/dayjs";
|
import { isSupportedTimeZone } from "@calcom/lib/dayjs";
|
||||||
import { getAvailableSlotsService } from "@calcom/lib/di/containers/available-slots";
|
import { getAvailableSlotsService } from "@calcom/lib/di/containers/AvailableSlots";
|
||||||
import { HttpError } from "@calcom/lib/http-error";
|
import { HttpError } from "@calcom/lib/http-error";
|
||||||
import { defaultResponder } from "@calcom/lib/server/defaultResponder";
|
import { defaultResponder } from "@calcom/lib/server/defaultResponder";
|
||||||
import { createContext } from "@calcom/trpc/server/createContext";
|
import { createContext } from "@calcom/trpc/server/createContext";
|
||||||
|
|||||||
@@ -76,11 +76,13 @@ vi.mock("@calcom/features/watchlist/operations/check-if-users-are-blocked.contro
|
|||||||
checkIfUsersAreBlocked: vi.fn().mockResolvedValue(false),
|
checkIfUsersAreBlocked: vi.fn().mockResolvedValue(false),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/lib/bookings/findQualifiedHostsWithDelegationCredentials", () => ({
|
vi.mock("@calcom/lib/di/containers/QualifiedHosts", () => ({
|
||||||
findQualifiedHostsWithDelegationCredentials: vi.fn().mockResolvedValue({
|
getQualifiedHostsService: vi.fn().mockReturnValue({
|
||||||
qualifiedRRHosts: [],
|
findQualifiedHostsWithDelegationCredentials: vi.fn().mockResolvedValue({
|
||||||
allFallbackRRHosts: [],
|
qualifiedRRHosts: [],
|
||||||
fixedHosts: [],
|
allFallbackRRHosts: [],
|
||||||
|
fixedHosts: [],
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
"@axiomhq/winston": "^1.2.0",
|
"@axiomhq/winston": "^1.2.0",
|
||||||
"@calcom/platform-constants": "*",
|
"@calcom/platform-constants": "*",
|
||||||
"@calcom/platform-enums": "*",
|
"@calcom/platform-enums": "*",
|
||||||
"@calcom/platform-libraries": "npm:@calcom/[email protected]4",
|
"@calcom/platform-libraries": "npm:@calcom/[email protected]8",
|
||||||
"@calcom/platform-types": "*",
|
"@calcom/platform-types": "*",
|
||||||
"@calcom/platform-utils": "*",
|
"@calcom/platform-utils": "*",
|
||||||
"@calcom/prisma": "*",
|
"@calcom/prisma": "*",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { z } from "zod";
|
|||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
import { ZGetRetellLLMSchema } from "@calcom/features/calAIPhone/zod-utils";
|
import { ZGetRetellLLMSchema } from "@calcom/features/calAIPhone/zod-utils";
|
||||||
import type { TGetRetellLLMSchema } from "@calcom/features/calAIPhone/zod-utils";
|
import type { TGetRetellLLMSchema } from "@calcom/features/calAIPhone/zod-utils";
|
||||||
import { getAvailableSlotsService } from "@calcom/lib/di/containers/available-slots";
|
import { getAvailableSlotsService } from "@calcom/lib/di/containers/AvailableSlots";
|
||||||
import { fetcher } from "@calcom/lib/retellAIFetcher";
|
import { fetcher } from "@calcom/lib/retellAIFetcher";
|
||||||
import { defaultHandler } from "@calcom/lib/server/defaultHandler";
|
import { defaultHandler } from "@calcom/lib/server/defaultHandler";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import prismaMock from "../../../../tests/libs/__mocks__/prismaMock";
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
import { getCheckBookingLimitsService } from "@calcom/lib/di/containers/booking-limits";
|
import { getCheckBookingLimitsService } from "@calcom/lib/di/containers/BookingLimits";
|
||||||
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
|
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
|
||||||
import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateIntervalLimitOrder";
|
import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateIntervalLimitOrder";
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
import { describe, vi, test } from "vitest";
|
import { describe, vi, test } from "vitest";
|
||||||
|
|
||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
import { getAvailableSlotsService } from "@calcom/lib/di/containers/available-slots";
|
import { getAvailableSlotsService } from "@calcom/lib/di/containers/AvailableSlots";
|
||||||
import { SchedulingType, type BookingStatus } from "@calcom/prisma/enums";
|
import { SchedulingType, type BookingStatus } from "@calcom/prisma/enums";
|
||||||
|
|
||||||
import { expect, expectedSlotsForSchedule } from "./getSchedule/expects";
|
import { expect, expectedSlotsForSchedule } from "./getSchedule/expects";
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
|
|
||||||
import { describe, test } from "vitest";
|
import { describe, test } from "vitest";
|
||||||
|
|
||||||
import { getAvailableSlotsService } from "@calcom/lib/di/containers/available-slots";
|
import { getAvailableSlotsService } from "@calcom/lib/di/containers/AvailableSlots";
|
||||||
|
|
||||||
import { expect, expectedSlotsForSchedule } from "./expects";
|
import { expect, expectedSlotsForSchedule } from "./expects";
|
||||||
import { setupAndTeardown } from "./setupAndTeardown";
|
import { setupAndTeardown } from "./setupAndTeardown";
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { expectNoAttemptToGetAvailability } from "../../utils/bookingScenario/ex
|
|||||||
|
|
||||||
import { describe, test } from "vitest";
|
import { describe, test } from "vitest";
|
||||||
|
|
||||||
import { getAvailableSlotsService } from "@calcom/lib/di/containers/available-slots";
|
import { getAvailableSlotsService } from "@calcom/lib/di/containers/AvailableSlots";
|
||||||
import { MembershipRole } from "@calcom/prisma/enums";
|
import { MembershipRole } from "@calcom/prisma/enums";
|
||||||
|
|
||||||
import { expect, expectedSlotsForSchedule } from "./expects";
|
import { expect, expectedSlotsForSchedule } from "./expects";
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import type { ScenarioData } from "../../utils/bookingScenario/bookingScenario";
|
|||||||
|
|
||||||
import { describe, expect, vi, test } from "vitest";
|
import { describe, expect, vi, test } from "vitest";
|
||||||
|
|
||||||
import { getAvailableSlotsService } from "@calcom/lib/di/containers/available-slots";
|
import { getAvailableSlotsService } from "@calcom/lib/di/containers/AvailableSlots";
|
||||||
import { PeriodType } from "@calcom/prisma/enums";
|
import { PeriodType } from "@calcom/prisma/enums";
|
||||||
|
|
||||||
import { expectedSlotsForSchedule } from "./expects";
|
import { expectedSlotsForSchedule } from "./expects";
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
import { describe, test, vi } from "vitest";
|
import { describe, test, vi } from "vitest";
|
||||||
import type { z } from "zod";
|
import type { z } from "zod";
|
||||||
|
|
||||||
import { getAvailableSlotsService } from "@calcom/lib/di/containers/available-slots";
|
import { getAvailableSlotsService } from "@calcom/lib/di/containers/AvailableSlots";
|
||||||
import type { getScheduleSchema } from "@calcom/trpc/server/routers/viewer/slots/types";
|
import type { getScheduleSchema } from "@calcom/trpc/server/routers/viewer/slots/types";
|
||||||
|
|
||||||
import { expect } from "./expects";
|
import { expect } from "./expects";
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import type { IncomingMessage } from "http";
|
|||||||
import { describe, test, beforeEach, vi } from "vitest";
|
import { describe, test, beforeEach, vi } from "vitest";
|
||||||
import type { z } from "zod";
|
import type { z } from "zod";
|
||||||
|
|
||||||
import { getAvailableSlotsService } from "@calcom/lib/di/containers/available-slots";
|
import { getAvailableSlotsService } from "@calcom/lib/di/containers/AvailableSlots";
|
||||||
import { prisma } from "@calcom/prisma";
|
import { prisma } from "@calcom/prisma";
|
||||||
import type { getScheduleSchema, GetScheduleOptions } from "@calcom/trpc/server/routers/viewer/slots/types";
|
import type { getScheduleSchema, GetScheduleOptions } from "@calcom/trpc/server/routers/viewer/slots/types";
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ import {
|
|||||||
enrichHostsWithDelegationCredentials,
|
enrichHostsWithDelegationCredentials,
|
||||||
getFirstDelegationConferencingCredentialAppLocation,
|
getFirstDelegationConferencingCredentialAppLocation,
|
||||||
} from "@calcom/lib/delegationCredential/server";
|
} from "@calcom/lib/delegationCredential/server";
|
||||||
import { getCheckBookingAndDurationLimitsService } from "@calcom/lib/di/containers/booking-limits";
|
import { getCheckBookingAndDurationLimitsService } from "@calcom/lib/di/containers/BookingLimits";
|
||||||
import { getCacheService } from "@calcom/lib/di/containers/cache";
|
import { getCacheService } from "@calcom/lib/di/containers/Cache";
|
||||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||||
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
||||||
import { getEventName, updateHostInEventName } from "@calcom/lib/event";
|
import { getEventName, updateHostInEventName } from "@calcom/lib/event";
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import dayjs from "@calcom/dayjs";
|
|||||||
import type { Dayjs } from "@calcom/dayjs";
|
import type { Dayjs } from "@calcom/dayjs";
|
||||||
import { checkForConflicts } from "@calcom/features/bookings/lib/conflictChecker/checkForConflicts";
|
import { checkForConflicts } from "@calcom/features/bookings/lib/conflictChecker/checkForConflicts";
|
||||||
import { buildDateRanges } from "@calcom/lib/date-ranges";
|
import { buildDateRanges } from "@calcom/lib/date-ranges";
|
||||||
import { getBusyTimesService } from "@calcom/lib/di/containers/busy-times";
|
import { getBusyTimesService } from "@calcom/lib/di/containers/BusyTimes";
|
||||||
import { getUserAvailabilityService } from "@calcom/lib/di/containers/get-user-availability";
|
import { getUserAvailabilityService } from "@calcom/lib/di/containers/GetUserAvailability";
|
||||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||||
import { parseBookingLimit } from "@calcom/lib/intervalLimits/isBookingLimits";
|
import { parseBookingLimit } from "@calcom/lib/intervalLimits/isBookingLimits";
|
||||||
import { parseDurationLimit } from "@calcom/lib/intervalLimits/isDurationLimits";
|
import { parseDurationLimit } from "@calcom/lib/intervalLimits/isDurationLimits";
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import type { Prisma } from "@prisma/client";
|
|||||||
import type { Logger } from "tslog";
|
import type { Logger } from "tslog";
|
||||||
|
|
||||||
import { checkIfUsersAreBlocked } from "@calcom/features/watchlist/operations/check-if-users-are-blocked.controller";
|
import { checkIfUsersAreBlocked } from "@calcom/features/watchlist/operations/check-if-users-are-blocked.controller";
|
||||||
import { findQualifiedHostsWithDelegationCredentials } from "@calcom/lib/bookings/findQualifiedHostsWithDelegationCredentials";
|
|
||||||
import { enrichUsersWithDelegationCredentials } from "@calcom/lib/delegationCredential/server";
|
import { enrichUsersWithDelegationCredentials } from "@calcom/lib/delegationCredential/server";
|
||||||
|
import { getQualifiedHostsService } from "@calcom/lib/di/containers/QualifiedHosts";
|
||||||
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
|
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
|
||||||
import { HttpError } from "@calcom/lib/http-error";
|
import { HttpError } from "@calcom/lib/http-error";
|
||||||
import { getPiiFreeUser } from "@calcom/lib/piiFreeData";
|
import { getPiiFreeUser } from "@calcom/lib/piiFreeData";
|
||||||
@@ -142,8 +142,9 @@ const _loadAndValidateUsers = async ({
|
|||||||
? false
|
? false
|
||||||
: user.isFixed || eventType.schedulingType !== SchedulingType.ROUND_ROBIN,
|
: user.isFixed || eventType.schedulingType !== SchedulingType.ROUND_ROBIN,
|
||||||
}));
|
}));
|
||||||
|
const qualifiedHostsService = getQualifiedHostsService();
|
||||||
const { qualifiedRRHosts, allFallbackRRHosts, fixedHosts } =
|
const { qualifiedRRHosts, allFallbackRRHosts, fixedHosts } =
|
||||||
await findQualifiedHostsWithDelegationCredentials({
|
await qualifiedHostsService.findQualifiedHostsWithDelegationCredentials({
|
||||||
eventType,
|
eventType,
|
||||||
routedTeamMemberIds: routedTeamMemberIds || [],
|
routedTeamMemberIds: routedTeamMemberIds || [],
|
||||||
rescheduleUid,
|
rescheduleUid,
|
||||||
@@ -159,7 +160,7 @@ const _loadAndValidateUsers = async ({
|
|||||||
},
|
},
|
||||||
{} as {
|
{} as {
|
||||||
[key: number]: Awaited<
|
[key: number]: Awaited<
|
||||||
ReturnType<typeof findQualifiedHostsWithDelegationCredentials>
|
ReturnType<ReturnType<typeof getQualifiedHostsService>["findQualifiedHostsWithDelegationCredentials"]>
|
||||||
>["qualifiedRRHosts"][number];
|
>["qualifiedRRHosts"][number];
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import {
|
|||||||
routingRepositoryBaseInputSchema,
|
routingRepositoryBaseInputSchema,
|
||||||
bookingRepositoryBaseInputSchema,
|
bookingRepositoryBaseInputSchema,
|
||||||
} from "@calcom/features/insights/server/raw-data.schema";
|
} from "@calcom/features/insights/server/raw-data.schema";
|
||||||
import { getInsightsBookingService } from "@calcom/lib/di/containers/insights-booking";
|
import { getInsightsBookingService } from "@calcom/lib/di/containers/InsightsBooking";
|
||||||
import { getInsightsRoutingService } from "@calcom/lib/di/containers/insights-routing";
|
import { getInsightsRoutingService } from "@calcom/lib/di/containers/InsightsRouting";
|
||||||
import type { readonlyPrisma } from "@calcom/prisma";
|
import type { readonlyPrisma } from "@calcom/prisma";
|
||||||
import { BookingStatus } from "@calcom/prisma/enums";
|
import { BookingStatus } from "@calcom/prisma/enums";
|
||||||
import authedProcedure from "@calcom/trpc/server/procedures/authedProcedure";
|
import authedProcedure from "@calcom/trpc/server/procedures/authedProcedure";
|
||||||
|
|||||||
@@ -1,31 +1,29 @@
|
|||||||
|
import type { Mock } from "vitest";
|
||||||
import { describe, expect, it, vi, afterEach } from "vitest";
|
import { describe, expect, it, vi, afterEach } from "vitest";
|
||||||
|
|
||||||
import prisma from "@calcom/prisma";
|
import type { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||||
|
|
||||||
import { filterHostsBySameRoundRobinHost } from "./filterHostsBySameRoundRobinHost";
|
import { FilterHostsService } from "./filterHostsBySameRoundRobinHost";
|
||||||
|
|
||||||
// Mocking setup
|
const mockBookingRepo = {
|
||||||
const prismaMock = {
|
findOriginalRescheduledBookingUserId: vi.fn(),
|
||||||
booking: {
|
} as unknown as BookingRepository;
|
||||||
findFirst: vi.fn(), // Mock the findFirst method
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Use `vi.spyOn` to make `prisma.booking.groupBy` call the mock instead
|
const filterHostsService = new FilterHostsService({
|
||||||
vi.spyOn(prisma.booking, "findFirst").mockImplementation(prismaMock.booking.findFirst);
|
bookingRepo: mockBookingRepo,
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
// Clear call history before each test to avoid cross-test interference
|
|
||||||
prismaMock.booking.findFirst.mockClear();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("filterHostsBySameRoundRobinHost", () => {
|
afterEach(() => {
|
||||||
|
(mockBookingRepo.findOriginalRescheduledBookingUserId as Mock).mockClear();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FilterHostsService", () => {
|
||||||
it("skips filter if rescheduleWithSameRoundRobinHost set to false", async () => {
|
it("skips filter if rescheduleWithSameRoundRobinHost set to false", async () => {
|
||||||
const hosts = [
|
const hosts = [
|
||||||
{ isFixed: false as const, createdAt: new Date(), user: { id: 1, email: "[email protected]" } },
|
{ isFixed: false as const, createdAt: new Date(), user: { id: 1, email: "[email protected]" } },
|
||||||
];
|
];
|
||||||
expect(
|
expect(
|
||||||
filterHostsBySameRoundRobinHost({
|
filterHostsService.filterHostsBySameRoundRobinHost({
|
||||||
hosts,
|
hosts,
|
||||||
rescheduleUid: "some-uid",
|
rescheduleUid: "some-uid",
|
||||||
rescheduleWithSameRoundRobinHost: false,
|
rescheduleWithSameRoundRobinHost: false,
|
||||||
@@ -35,10 +33,10 @@ describe("filterHostsBySameRoundRobinHost", () => {
|
|||||||
});
|
});
|
||||||
it("skips filter if rerouting", async () => {
|
it("skips filter if rerouting", async () => {
|
||||||
const hosts = [
|
const hosts = [
|
||||||
{ isFixed: true as const, createdAt: new Date(), user: { id: 1, email: "[email protected]" } },
|
{ isFixed: false as const, createdAt: new Date(), user: { id: 1, email: "[email protected]" } },
|
||||||
];
|
];
|
||||||
expect(
|
expect(
|
||||||
filterHostsBySameRoundRobinHost({
|
filterHostsService.filterHostsBySameRoundRobinHost({
|
||||||
hosts,
|
hosts,
|
||||||
rescheduleUid: "some-uid",
|
rescheduleUid: "some-uid",
|
||||||
rescheduleWithSameRoundRobinHost: true,
|
rescheduleWithSameRoundRobinHost: true,
|
||||||
@@ -48,15 +46,14 @@ describe("filterHostsBySameRoundRobinHost", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("correctly selects the same host if the filter applies and the host is in the RR users", async () => {
|
it("correctly selects the same host if the filter applies and the host is in the RR users", async () => {
|
||||||
prismaMock.booking.findFirst.mockResolvedValue({ userId: 1 });
|
(mockBookingRepo.findOriginalRescheduledBookingUserId as Mock).mockResolvedValue({ userId: 1 });
|
||||||
|
|
||||||
const hosts = [
|
const hosts = [
|
||||||
{ isFixed: false as const, createdAt: new Date(), user: { id: 1, email: "[email protected]" } },
|
{ isFixed: false as const, createdAt: new Date(), user: { id: 1, email: "[email protected]" } },
|
||||||
{ isFixed: false as const, createdAt: new Date(), user: { id: 2, email: "[email protected]" } },
|
{ isFixed: false as const, createdAt: new Date(), user: { id: 2, email: "[email protected]" } },
|
||||||
];
|
];
|
||||||
// Same host should be selected
|
|
||||||
expect(
|
expect(
|
||||||
filterHostsBySameRoundRobinHost({
|
filterHostsService.filterHostsBySameRoundRobinHost({
|
||||||
hosts,
|
hosts,
|
||||||
rescheduleUid: "some-uid",
|
rescheduleUid: "some-uid",
|
||||||
rescheduleWithSameRoundRobinHost: true,
|
rescheduleWithSameRoundRobinHost: true,
|
||||||
@@ -68,7 +65,7 @@ describe("filterHostsBySameRoundRobinHost", () => {
|
|||||||
// Tests for bookings that have more than one host
|
// Tests for bookings that have more than one host
|
||||||
describe("Fixed hosts and round robin groups support", () => {
|
describe("Fixed hosts and round robin groups support", () => {
|
||||||
it("should return organizer and attendee hosts", async () => {
|
it("should return organizer and attendee hosts", async () => {
|
||||||
prismaMock.booking.findFirst.mockResolvedValue({
|
(mockBookingRepo.findOriginalRescheduledBookingUserId as Mock).mockResolvedValue({
|
||||||
userId: 1,
|
userId: 1,
|
||||||
attendees: [
|
attendees: [
|
||||||
{ email: "[email protected]" },
|
{ email: "[email protected]" },
|
||||||
@@ -84,7 +81,7 @@ describe("filterHostsBySameRoundRobinHost", () => {
|
|||||||
{ isFixed: false as const, createdAt: new Date(), user: { id: 4, email: "[email protected]" } },
|
{ isFixed: false as const, createdAt: new Date(), user: { id: 4, email: "[email protected]" } },
|
||||||
];
|
];
|
||||||
|
|
||||||
const result = await filterHostsBySameRoundRobinHost({
|
const result = await filterHostsService.filterHostsBySameRoundRobinHost({
|
||||||
hosts,
|
hosts,
|
||||||
rescheduleUid: "some-uid",
|
rescheduleUid: "some-uid",
|
||||||
rescheduleWithSameRoundRobinHost: true,
|
rescheduleWithSameRoundRobinHost: true,
|
||||||
@@ -101,7 +98,7 @@ describe("filterHostsBySameRoundRobinHost", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should return only organizer host when no attendees match current hosts", async () => {
|
it("should return only organizer host when no attendees match current hosts", async () => {
|
||||||
prismaMock.booking.findFirst.mockResolvedValue({
|
(mockBookingRepo.findOriginalRescheduledBookingUserId as Mock).mockResolvedValue({
|
||||||
userId: 1,
|
userId: 1,
|
||||||
attendees: [
|
attendees: [
|
||||||
{ email: "[email protected]" }, // Non-host attendee
|
{ email: "[email protected]" }, // Non-host attendee
|
||||||
@@ -114,7 +111,7 @@ describe("filterHostsBySameRoundRobinHost", () => {
|
|||||||
{ isFixed: false as const, createdAt: new Date(), user: { id: 2, email: "[email protected]" } },
|
{ isFixed: false as const, createdAt: new Date(), user: { id: 2, email: "[email protected]" } },
|
||||||
];
|
];
|
||||||
|
|
||||||
const result = await filterHostsBySameRoundRobinHost({
|
const result = await filterHostsService.filterHostsBySameRoundRobinHost({
|
||||||
hosts,
|
hosts,
|
||||||
rescheduleUid: "some-uid",
|
rescheduleUid: "some-uid",
|
||||||
rescheduleWithSameRoundRobinHost: true,
|
rescheduleWithSameRoundRobinHost: true,
|
||||||
|
|||||||
@@ -1,57 +1,53 @@
|
|||||||
import { prisma } from "@calcom/prisma";
|
import type { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||||
import { BookingStatus } from "@calcom/prisma/enums";
|
|
||||||
|
|
||||||
import { isRerouting } from "./routing/utils";
|
import { isRerouting } from "./routing/utils";
|
||||||
|
|
||||||
export const filterHostsBySameRoundRobinHost = async <
|
export interface IFilterHostsService {
|
||||||
T extends {
|
bookingRepo: BookingRepository;
|
||||||
isFixed: false; // ensure no fixed hosts are passed.
|
}
|
||||||
user: { id: number; email: string };
|
|
||||||
}
|
|
||||||
>({
|
|
||||||
hosts,
|
|
||||||
rescheduleUid,
|
|
||||||
rescheduleWithSameRoundRobinHost,
|
|
||||||
routedTeamMemberIds,
|
|
||||||
}: {
|
|
||||||
hosts: T[];
|
|
||||||
rescheduleUid: string | null;
|
|
||||||
rescheduleWithSameRoundRobinHost: boolean;
|
|
||||||
routedTeamMemberIds: number[] | null;
|
|
||||||
}) => {
|
|
||||||
if (
|
|
||||||
!rescheduleUid ||
|
|
||||||
!rescheduleWithSameRoundRobinHost ||
|
|
||||||
isRerouting({ rescheduleUid, routedTeamMemberIds })
|
|
||||||
) {
|
|
||||||
return hosts;
|
|
||||||
}
|
|
||||||
const originalRescheduledBooking = await prisma.booking.findFirst({
|
|
||||||
where: {
|
|
||||||
uid: rescheduleUid,
|
|
||||||
status: {
|
|
||||||
in: [BookingStatus.ACCEPTED, BookingStatus.CANCELLED, BookingStatus.PENDING],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
select: {
|
|
||||||
userId: true,
|
|
||||||
attendees: {
|
|
||||||
select: {
|
|
||||||
email: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!originalRescheduledBooking) {
|
export class FilterHostsService {
|
||||||
return hosts;
|
constructor(public readonly dependencies: IFilterHostsService) {}
|
||||||
|
|
||||||
|
async filterHostsBySameRoundRobinHost<
|
||||||
|
T extends {
|
||||||
|
isFixed: false; // ensure no fixed hosts are passed.
|
||||||
|
user: { id: number; email: string };
|
||||||
|
}
|
||||||
|
>({
|
||||||
|
hosts,
|
||||||
|
rescheduleUid,
|
||||||
|
rescheduleWithSameRoundRobinHost,
|
||||||
|
routedTeamMemberIds,
|
||||||
|
}: {
|
||||||
|
hosts: T[];
|
||||||
|
rescheduleUid: string | null;
|
||||||
|
rescheduleWithSameRoundRobinHost: boolean;
|
||||||
|
routedTeamMemberIds: number[] | null;
|
||||||
|
}) {
|
||||||
|
if (
|
||||||
|
!rescheduleUid ||
|
||||||
|
!rescheduleWithSameRoundRobinHost ||
|
||||||
|
isRerouting({ rescheduleUid, routedTeamMemberIds })
|
||||||
|
) {
|
||||||
|
return hosts;
|
||||||
|
}
|
||||||
|
|
||||||
|
const originalRescheduledBooking =
|
||||||
|
await this.dependencies.bookingRepo.findOriginalRescheduledBookingUserId({
|
||||||
|
rescheduleUid,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!originalRescheduledBooking) {
|
||||||
|
return hosts;
|
||||||
|
}
|
||||||
|
|
||||||
|
const attendeeEmails = originalRescheduledBooking.attendees?.map((attendee) => attendee.email) || [];
|
||||||
|
|
||||||
|
return hosts.filter((host) => {
|
||||||
|
const isOrganizer = host.user.id === originalRescheduledBooking.userId;
|
||||||
|
const isAttendee = attendeeEmails.includes(host.user.email);
|
||||||
|
return isOrganizer || isAttendee;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const attendeeEmails = originalRescheduledBooking.attendees?.map((attendee) => attendee.email) || [];
|
|
||||||
|
|
||||||
return hosts.filter((host) => {
|
|
||||||
const isOrganizer = host.user.id === originalRescheduledBooking.userId;
|
|
||||||
const isAttendee = attendeeEmails.includes(host.user.email);
|
|
||||||
return isOrganizer || isAttendee;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@@ -1,16 +1,24 @@
|
|||||||
|
import type { FilterHostsService } from "@calcom/lib/bookings/filterHostsBySameRoundRobinHost";
|
||||||
import {
|
import {
|
||||||
findMatchingHostsWithEventSegment,
|
findMatchingHostsWithEventSegment,
|
||||||
getNormalizedHostsWithDelegationCredentials,
|
getNormalizedHostsWithDelegationCredentials,
|
||||||
} from "@calcom/lib/bookings/getRoutedUsers";
|
} from "@calcom/lib/bookings/getRoutedUsers";
|
||||||
import type { EventType } from "@calcom/lib/bookings/getRoutedUsers";
|
import type { EventType } from "@calcom/lib/bookings/getRoutedUsers";
|
||||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||||
|
import type { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||||
|
import type { PrismaClient } from "@calcom/prisma";
|
||||||
import type { SelectedCalendar } from "@calcom/prisma/client";
|
import type { SelectedCalendar } from "@calcom/prisma/client";
|
||||||
import type { SchedulingType } from "@calcom/prisma/enums";
|
import type { SchedulingType } from "@calcom/prisma/enums";
|
||||||
import type { CredentialForCalendarService, CredentialPayload } from "@calcom/types/Credential";
|
import type { CredentialForCalendarService, CredentialPayload } from "@calcom/types/Credential";
|
||||||
|
|
||||||
import type { RoutingFormResponse } from "../server/getLuckyUser";
|
import type { RoutingFormResponse } from "../server/getLuckyUser";
|
||||||
import { filterHostsByLeadThreshold } from "./filterHostsByLeadThreshold";
|
import { filterHostsByLeadThreshold } from "./filterHostsByLeadThreshold";
|
||||||
import { filterHostsBySameRoundRobinHost } from "./filterHostsBySameRoundRobinHost";
|
|
||||||
|
export interface IQualifiedHostsService {
|
||||||
|
prisma: PrismaClient;
|
||||||
|
bookingRepo: BookingRepository;
|
||||||
|
filterHostsService: FilterHostsService;
|
||||||
|
}
|
||||||
|
|
||||||
type Host<T> = {
|
type Host<T> = {
|
||||||
isFixed: boolean;
|
isFixed: boolean;
|
||||||
@@ -48,6 +56,178 @@ const isFixedHost = <T extends { isFixed: boolean }>(host: T): host is T & { isF
|
|||||||
return host.isFixed;
|
return host.isFixed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export class QualifiedHostsService {
|
||||||
|
constructor(public readonly dependencies: IQualifiedHostsService) {}
|
||||||
|
|
||||||
|
async _findQualifiedHostsWithDelegationCredentials<
|
||||||
|
T extends {
|
||||||
|
email: string;
|
||||||
|
id: number;
|
||||||
|
credentials: CredentialPayload[];
|
||||||
|
userLevelSelectedCalendars: SelectedCalendar[];
|
||||||
|
} & Record<string, unknown>
|
||||||
|
>({
|
||||||
|
eventType,
|
||||||
|
rescheduleUid,
|
||||||
|
routedTeamMemberIds,
|
||||||
|
contactOwnerEmail,
|
||||||
|
routingFormResponse,
|
||||||
|
}: {
|
||||||
|
eventType: {
|
||||||
|
id: number;
|
||||||
|
maxLeadThreshold?: number | null;
|
||||||
|
hosts?: Host<T>[];
|
||||||
|
users: T[];
|
||||||
|
schedulingType: SchedulingType | null;
|
||||||
|
isRRWeightsEnabled: boolean;
|
||||||
|
rescheduleWithSameRoundRobinHost: boolean;
|
||||||
|
includeNoShowInRRCalculation: boolean;
|
||||||
|
} & EventType;
|
||||||
|
rescheduleUid: string | null;
|
||||||
|
routedTeamMemberIds: number[];
|
||||||
|
contactOwnerEmail: string | null;
|
||||||
|
routingFormResponse: RoutingFormResponse | null;
|
||||||
|
}): Promise<{
|
||||||
|
qualifiedRRHosts: {
|
||||||
|
isFixed: boolean;
|
||||||
|
createdAt: Date | null;
|
||||||
|
priority?: number | null;
|
||||||
|
weight?: number | null;
|
||||||
|
user: Omit<T, "credentials"> & { credentials: CredentialForCalendarService[] };
|
||||||
|
}[];
|
||||||
|
fixedHosts: {
|
||||||
|
isFixed: boolean;
|
||||||
|
createdAt: Date | null;
|
||||||
|
priority?: number | null;
|
||||||
|
weight?: number | null;
|
||||||
|
user: Omit<T, "credentials"> & { credentials: CredentialForCalendarService[] };
|
||||||
|
}[];
|
||||||
|
// all hosts we want to fallback to including the qualifiedRRHosts (fairness + crm contact owner)
|
||||||
|
allFallbackRRHosts?: {
|
||||||
|
isFixed: boolean;
|
||||||
|
createdAt: Date | null;
|
||||||
|
priority?: number | null;
|
||||||
|
weight?: number | null;
|
||||||
|
user: Omit<T, "credentials"> & { credentials: CredentialForCalendarService[] };
|
||||||
|
}[];
|
||||||
|
}> {
|
||||||
|
const { hosts: normalizedHosts, fallbackHosts: fallbackUsers } =
|
||||||
|
await getNormalizedHostsWithDelegationCredentials({
|
||||||
|
eventType,
|
||||||
|
});
|
||||||
|
// not a team event type, or some other reason - segment matching isn't necessary.
|
||||||
|
if (!normalizedHosts) {
|
||||||
|
const fixedHosts = fallbackUsers.filter(isFixedHost);
|
||||||
|
const roundRobinHosts = fallbackUsers.filter(isRoundRobinHost);
|
||||||
|
return { qualifiedRRHosts: roundRobinHosts, fixedHosts };
|
||||||
|
}
|
||||||
|
|
||||||
|
const fixedHosts = normalizedHosts.filter(isFixedHost);
|
||||||
|
const roundRobinHosts = normalizedHosts.filter(isRoundRobinHost);
|
||||||
|
|
||||||
|
// If it is rerouting, we should not force reschedule with same host.
|
||||||
|
const hostsAfterRescheduleWithSameRoundRobinHost = applyFilterWithFallback(
|
||||||
|
roundRobinHosts,
|
||||||
|
await this.dependencies.filterHostsService.filterHostsBySameRoundRobinHost({
|
||||||
|
hosts: roundRobinHosts,
|
||||||
|
rescheduleUid,
|
||||||
|
rescheduleWithSameRoundRobinHost: eventType.rescheduleWithSameRoundRobinHost,
|
||||||
|
routedTeamMemberIds,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hostsAfterRescheduleWithSameRoundRobinHost.length === 1) {
|
||||||
|
return {
|
||||||
|
qualifiedRRHosts: hostsAfterRescheduleWithSameRoundRobinHost,
|
||||||
|
fixedHosts,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const hostsAfterSegmentMatching = applyFilterWithFallback(
|
||||||
|
hostsAfterRescheduleWithSameRoundRobinHost,
|
||||||
|
(await findMatchingHostsWithEventSegment({
|
||||||
|
eventType,
|
||||||
|
hosts: hostsAfterRescheduleWithSameRoundRobinHost,
|
||||||
|
})) as typeof hostsAfterRescheduleWithSameRoundRobinHost
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hostsAfterSegmentMatching.length === 1) {
|
||||||
|
return {
|
||||||
|
qualifiedRRHosts: hostsAfterSegmentMatching,
|
||||||
|
fixedHosts,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//if segment matching doesn't return any hosts we fall back to all round robin hosts
|
||||||
|
const officalRRHosts = hostsAfterSegmentMatching.length
|
||||||
|
? hostsAfterSegmentMatching
|
||||||
|
: hostsAfterRescheduleWithSameRoundRobinHost;
|
||||||
|
|
||||||
|
const hostsAfterContactOwnerMatching = applyFilterWithFallback(
|
||||||
|
officalRRHosts,
|
||||||
|
officalRRHosts.filter((host) => host.user.email === contactOwnerEmail)
|
||||||
|
);
|
||||||
|
|
||||||
|
const hostsAfterRoutedTeamMemberIdsMatching = applyFilterWithFallback(
|
||||||
|
officalRRHosts,
|
||||||
|
officalRRHosts.filter((host) => routedTeamMemberIds.includes(host.user.id))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hostsAfterRoutedTeamMemberIdsMatching.length === 1) {
|
||||||
|
if (hostsAfterContactOwnerMatching.length === 1) {
|
||||||
|
return {
|
||||||
|
qualifiedRRHosts: hostsAfterContactOwnerMatching,
|
||||||
|
allFallbackRRHosts: getFallBackWithContactOwner(
|
||||||
|
hostsAfterRoutedTeamMemberIdsMatching,
|
||||||
|
hostsAfterContactOwnerMatching[0]
|
||||||
|
),
|
||||||
|
fixedHosts,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
qualifiedRRHosts: hostsAfterRoutedTeamMemberIdsMatching,
|
||||||
|
fixedHosts,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const hostsAfterFairnessMatching = applyFilterWithFallback(
|
||||||
|
hostsAfterRoutedTeamMemberIdsMatching,
|
||||||
|
await filterHostsByLeadThreshold({
|
||||||
|
eventType,
|
||||||
|
hosts: hostsAfterRoutedTeamMemberIdsMatching,
|
||||||
|
maxLeadThreshold: eventType.maxLeadThreshold ?? null,
|
||||||
|
routingFormResponse,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hostsAfterContactOwnerMatching.length === 1) {
|
||||||
|
return {
|
||||||
|
qualifiedRRHosts: hostsAfterContactOwnerMatching,
|
||||||
|
allFallbackRRHosts: getFallBackWithContactOwner(
|
||||||
|
hostsAfterFairnessMatching,
|
||||||
|
hostsAfterContactOwnerMatching[0]
|
||||||
|
),
|
||||||
|
fixedHosts,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
qualifiedRRHosts: hostsAfterFairnessMatching,
|
||||||
|
// only if fairness filtering is active
|
||||||
|
allFallbackRRHosts:
|
||||||
|
hostsAfterFairnessMatching.length !== hostsAfterRoutedTeamMemberIdsMatching.length
|
||||||
|
? hostsAfterRoutedTeamMemberIdsMatching
|
||||||
|
: undefined,
|
||||||
|
fixedHosts,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
findQualifiedHostsWithDelegationCredentials = withReporting(
|
||||||
|
this._findQualifiedHostsWithDelegationCredentials.bind(this),
|
||||||
|
"findQualifiedHostsWithDelegationCredentials"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const _findQualifiedHostsWithDelegationCredentials = async <
|
const _findQualifiedHostsWithDelegationCredentials = async <
|
||||||
T extends {
|
T extends {
|
||||||
email: string;
|
email: string;
|
||||||
@@ -64,154 +244,45 @@ const _findQualifiedHostsWithDelegationCredentials = async <
|
|||||||
}: {
|
}: {
|
||||||
eventType: {
|
eventType: {
|
||||||
id: number;
|
id: number;
|
||||||
maxLeadThreshold: number | null;
|
schedulingType: SchedulingType | null;
|
||||||
hosts?: Host<T>[];
|
hosts?: Host<T>[];
|
||||||
users: T[];
|
users: T[];
|
||||||
schedulingType: SchedulingType | null;
|
maxLeadThreshold?: number | null;
|
||||||
|
team?: {
|
||||||
|
parentId?: number | null;
|
||||||
|
rrResetInterval: string | null;
|
||||||
|
rrTimestampBasis: string | null;
|
||||||
|
} | null;
|
||||||
isRRWeightsEnabled: boolean;
|
isRRWeightsEnabled: boolean;
|
||||||
rescheduleWithSameRoundRobinHost: boolean;
|
rescheduleWithSameRoundRobinHost: boolean;
|
||||||
|
teamId?: number;
|
||||||
includeNoShowInRRCalculation: boolean;
|
includeNoShowInRRCalculation: boolean;
|
||||||
} & EventType;
|
} & EventType;
|
||||||
rescheduleUid: string | null;
|
rescheduleUid: string | null;
|
||||||
routedTeamMemberIds: number[];
|
routedTeamMemberIds: number[];
|
||||||
contactOwnerEmail: string | null;
|
contactOwnerEmail: string | null;
|
||||||
routingFormResponse: RoutingFormResponse | null;
|
routingFormResponse: RoutingFormResponse | null;
|
||||||
}): Promise<{
|
}) => {
|
||||||
qualifiedRRHosts: {
|
const { prisma } = await import("@calcom/prisma");
|
||||||
isFixed: boolean;
|
const { BookingRepository } = await import("@calcom/lib/server/repository/booking");
|
||||||
createdAt: Date | null;
|
const { FilterHostsService } = await import("@calcom/lib/bookings/filterHostsBySameRoundRobinHost");
|
||||||
priority?: number | null;
|
|
||||||
weight?: number | null;
|
|
||||||
groupId?: string | null;
|
|
||||||
user: Omit<T, "credentials"> & { credentials: CredentialForCalendarService[] };
|
|
||||||
}[];
|
|
||||||
fixedHosts: {
|
|
||||||
isFixed: boolean;
|
|
||||||
createdAt: Date | null;
|
|
||||||
priority?: number | null;
|
|
||||||
weight?: number | null;
|
|
||||||
groupId?: string | null;
|
|
||||||
user: Omit<T, "credentials"> & { credentials: CredentialForCalendarService[] };
|
|
||||||
}[];
|
|
||||||
// all hosts we want to fallback to including the qualifiedRRHosts (fairness + crm contact owner)
|
|
||||||
allFallbackRRHosts?: {
|
|
||||||
isFixed: boolean;
|
|
||||||
createdAt: Date | null;
|
|
||||||
priority?: number | null;
|
|
||||||
weight?: number | null;
|
|
||||||
groupId?: string | null;
|
|
||||||
user: Omit<T, "credentials"> & { credentials: CredentialForCalendarService[] };
|
|
||||||
}[];
|
|
||||||
}> => {
|
|
||||||
const { hosts: normalizedHosts, fallbackHosts: fallbackUsers } =
|
|
||||||
await getNormalizedHostsWithDelegationCredentials({
|
|
||||||
eventType,
|
|
||||||
});
|
|
||||||
// not a team event type, or some other reason - segment matching isn't necessary.
|
|
||||||
if (!normalizedHosts) {
|
|
||||||
const fixedHosts = fallbackUsers.filter(isFixedHost);
|
|
||||||
const roundRobinHosts = fallbackUsers.filter(isRoundRobinHost);
|
|
||||||
return { qualifiedRRHosts: roundRobinHosts, fixedHosts };
|
|
||||||
}
|
|
||||||
|
|
||||||
const fixedHosts = normalizedHosts.filter(isFixedHost);
|
const bookingRepo = new BookingRepository(prisma);
|
||||||
const roundRobinHosts = normalizedHosts.filter(isRoundRobinHost);
|
const filterHostsService = new FilterHostsService({ bookingRepo });
|
||||||
|
|
||||||
// If it is rerouting, we should not force reschedule with same host.
|
const service = new QualifiedHostsService({
|
||||||
const hostsAfterRescheduleWithSameRoundRobinHost = applyFilterWithFallback(
|
prisma,
|
||||||
roundRobinHosts,
|
bookingRepo,
|
||||||
await filterHostsBySameRoundRobinHost({
|
filterHostsService,
|
||||||
hosts: roundRobinHosts,
|
});
|
||||||
rescheduleUid,
|
|
||||||
rescheduleWithSameRoundRobinHost: eventType.rescheduleWithSameRoundRobinHost,
|
|
||||||
routedTeamMemberIds,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
if (hostsAfterRescheduleWithSameRoundRobinHost.length === 1) {
|
return service.findQualifiedHostsWithDelegationCredentials({
|
||||||
return {
|
eventType,
|
||||||
qualifiedRRHosts: hostsAfterRescheduleWithSameRoundRobinHost,
|
rescheduleUid,
|
||||||
fixedHosts,
|
routedTeamMemberIds,
|
||||||
};
|
contactOwnerEmail,
|
||||||
}
|
routingFormResponse,
|
||||||
|
});
|
||||||
const hostsAfterSegmentMatching = applyFilterWithFallback(
|
|
||||||
hostsAfterRescheduleWithSameRoundRobinHost,
|
|
||||||
(await findMatchingHostsWithEventSegment({
|
|
||||||
eventType,
|
|
||||||
hosts: hostsAfterRescheduleWithSameRoundRobinHost,
|
|
||||||
})) as typeof hostsAfterRescheduleWithSameRoundRobinHost
|
|
||||||
);
|
|
||||||
|
|
||||||
if (hostsAfterSegmentMatching.length === 1) {
|
|
||||||
return {
|
|
||||||
qualifiedRRHosts: hostsAfterSegmentMatching,
|
|
||||||
fixedHosts,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//if segment matching doesn't return any hosts we fall back to all round robin hosts
|
|
||||||
const officalRRHosts = hostsAfterSegmentMatching.length
|
|
||||||
? hostsAfterSegmentMatching
|
|
||||||
: hostsAfterRescheduleWithSameRoundRobinHost;
|
|
||||||
|
|
||||||
const hostsAfterContactOwnerMatching = applyFilterWithFallback(
|
|
||||||
officalRRHosts,
|
|
||||||
officalRRHosts.filter((host) => host.user.email === contactOwnerEmail)
|
|
||||||
);
|
|
||||||
|
|
||||||
const hostsAfterRoutedTeamMemberIdsMatching = applyFilterWithFallback(
|
|
||||||
officalRRHosts,
|
|
||||||
officalRRHosts.filter((host) => routedTeamMemberIds.includes(host.user.id))
|
|
||||||
);
|
|
||||||
|
|
||||||
if (hostsAfterRoutedTeamMemberIdsMatching.length === 1) {
|
|
||||||
if (hostsAfterContactOwnerMatching.length === 1) {
|
|
||||||
return {
|
|
||||||
qualifiedRRHosts: hostsAfterContactOwnerMatching,
|
|
||||||
allFallbackRRHosts: getFallBackWithContactOwner(
|
|
||||||
hostsAfterRoutedTeamMemberIdsMatching,
|
|
||||||
hostsAfterContactOwnerMatching[0]
|
|
||||||
),
|
|
||||||
fixedHosts,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
qualifiedRRHosts: hostsAfterRoutedTeamMemberIdsMatching,
|
|
||||||
fixedHosts,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const hostsAfterFairnessMatching = applyFilterWithFallback(
|
|
||||||
hostsAfterRoutedTeamMemberIdsMatching,
|
|
||||||
await filterHostsByLeadThreshold({
|
|
||||||
eventType,
|
|
||||||
hosts: hostsAfterRoutedTeamMemberIdsMatching,
|
|
||||||
maxLeadThreshold: eventType.maxLeadThreshold,
|
|
||||||
routingFormResponse,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
if (hostsAfterContactOwnerMatching.length === 1) {
|
|
||||||
return {
|
|
||||||
qualifiedRRHosts: hostsAfterContactOwnerMatching,
|
|
||||||
allFallbackRRHosts: getFallBackWithContactOwner(
|
|
||||||
hostsAfterFairnessMatching,
|
|
||||||
hostsAfterContactOwnerMatching[0]
|
|
||||||
),
|
|
||||||
fixedHosts,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
qualifiedRRHosts: hostsAfterFairnessMatching,
|
|
||||||
// only if fairness filtering is active
|
|
||||||
allFallbackRRHosts:
|
|
||||||
hostsAfterFairnessMatching.length !== hostsAfterRoutedTeamMemberIdsMatching.length
|
|
||||||
? hostsAfterRoutedTeamMemberIdsMatching
|
|
||||||
: undefined,
|
|
||||||
fixedHosts,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findQualifiedHostsWithDelegationCredentials = withReporting(
|
export const findQualifiedHostsWithDelegationCredentials = withReporting(
|
||||||
|
|||||||
+14
-14
@@ -5,20 +5,20 @@ import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
|||||||
import { prismaModule } from "@calcom/prisma/prisma.module";
|
import { prismaModule } from "@calcom/prisma/prisma.module";
|
||||||
import type { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/slots/util";
|
import type { AvailableSlotsService } from "@calcom/trpc/server/routers/viewer/slots/util";
|
||||||
|
|
||||||
import { availableSlotsModule } from "../modules/available-slots";
|
import { availableSlotsModule } from "../modules/AvailableSlots";
|
||||||
import { bookingRepositoryModule } from "../modules/booking";
|
import { bookingRepositoryModule } from "../modules/Booking";
|
||||||
import { busyTimesModule } from "../modules/busy-times";
|
import { busyTimesModule } from "../modules/BusyTimes";
|
||||||
import { cacheModule } from "../modules/cache";
|
import { cacheModule } from "../modules/Cache";
|
||||||
import { checkBookingLimitsModule } from "../modules/check-booking-limits";
|
import { checkBookingLimitsModule } from "../modules/CheckBookingLimits";
|
||||||
import { eventTypeRepositoryModule } from "../modules/eventType";
|
import { eventTypeRepositoryModule } from "../modules/EventType";
|
||||||
import { featuresRepositoryModule } from "../modules/features";
|
import { featuresRepositoryModule } from "../modules/Features";
|
||||||
import { getUserAvailabilityModule } from "../modules/get-user-availability";
|
import { getUserAvailabilityModule } from "../modules/GetUserAvailability";
|
||||||
import { oooRepositoryModule } from "../modules/ooo";
|
import { oooRepositoryModule } from "../modules/Ooo";
|
||||||
import { routingFormResponseRepositoryModule } from "../modules/routingFormResponse";
|
import { routingFormResponseRepositoryModule } from "../modules/RoutingFormResponse";
|
||||||
import { scheduleRepositoryModule } from "../modules/schedule";
|
import { scheduleRepositoryModule } from "../modules/Schedule";
|
||||||
import { selectedSlotsRepositoryModule } from "../modules/selectedSlots";
|
import { selectedSlotsRepositoryModule } from "../modules/SelectedSlots";
|
||||||
import { teamRepositoryModule } from "../modules/team";
|
import { teamRepositoryModule } from "../modules/Team";
|
||||||
import { userRepositoryModule } from "../modules/user";
|
import { userRepositoryModule } from "../modules/User";
|
||||||
|
|
||||||
const container = createContainer();
|
const container = createContainer();
|
||||||
container.load(DI_TOKENS.REDIS_CLIENT, redisModule);
|
container.load(DI_TOKENS.REDIS_CLIENT, redisModule);
|
||||||
+3
-3
@@ -5,9 +5,9 @@ import { prismaModule } from "@calcom/prisma/prisma.module";
|
|||||||
|
|
||||||
import type { CheckBookingAndDurationLimitsService } from "../../../features/bookings/lib/handleNewBooking/checkBookingAndDurationLimits";
|
import type { CheckBookingAndDurationLimitsService } from "../../../features/bookings/lib/handleNewBooking/checkBookingAndDurationLimits";
|
||||||
import type { CheckBookingLimitsService } from "../../intervalLimits/server/checkBookingLimits";
|
import type { CheckBookingLimitsService } from "../../intervalLimits/server/checkBookingLimits";
|
||||||
import { bookingRepositoryModule } from "../modules/booking";
|
import { bookingRepositoryModule } from "../modules/Booking";
|
||||||
import { checkBookingAndDurationLimitsModule } from "../modules/check-booking-and-duration-limits";
|
import { checkBookingAndDurationLimitsModule } from "../modules/CheckBookingAndDurationLimits";
|
||||||
import { checkBookingLimitsModule } from "../modules/check-booking-limits";
|
import { checkBookingLimitsModule } from "../modules/CheckBookingLimits";
|
||||||
|
|
||||||
const container = createContainer();
|
const container = createContainer();
|
||||||
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
||||||
@@ -4,8 +4,8 @@ import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
|||||||
import { prismaModule } from "@calcom/prisma/prisma.module";
|
import { prismaModule } from "@calcom/prisma/prisma.module";
|
||||||
|
|
||||||
import type { BusyTimesService } from "../../getBusyTimes";
|
import type { BusyTimesService } from "../../getBusyTimes";
|
||||||
import { bookingRepositoryModule } from "../modules/booking";
|
import { bookingRepositoryModule } from "../modules/Booking";
|
||||||
import { busyTimesModule } from "../modules/busy-times";
|
import { busyTimesModule } from "../modules/BusyTimes";
|
||||||
|
|
||||||
const container = createContainer();
|
const container = createContainer();
|
||||||
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
||||||
@@ -4,8 +4,8 @@ import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
|||||||
import { prismaModule } from "@calcom/prisma/prisma.module";
|
import { prismaModule } from "@calcom/prisma/prisma.module";
|
||||||
|
|
||||||
import type { CacheService } from "../../../features/calendar-cache/lib/getShouldServeCache";
|
import type { CacheService } from "../../../features/calendar-cache/lib/getShouldServeCache";
|
||||||
import { cacheModule } from "../modules/cache";
|
import { cacheModule } from "../modules/Cache";
|
||||||
import { featuresRepositoryModule } from "../modules/features";
|
import { featuresRepositoryModule } from "../modules/Features";
|
||||||
|
|
||||||
const container = createContainer();
|
const container = createContainer();
|
||||||
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { createContainer } from "@evyweb/ioctopus";
|
||||||
|
|
||||||
|
import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
||||||
|
import { prismaModule } from "@calcom/prisma/prisma.module";
|
||||||
|
|
||||||
|
import type { FilterHostsService } from "../../bookings/filterHostsBySameRoundRobinHost";
|
||||||
|
import { bookingRepositoryModule } from "../modules/Booking";
|
||||||
|
import { filterHostsModule } from "../modules/FilterHosts";
|
||||||
|
|
||||||
|
const container = createContainer();
|
||||||
|
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
||||||
|
container.load(DI_TOKENS.BOOKING_REPOSITORY_MODULE, bookingRepositoryModule);
|
||||||
|
container.load(DI_TOKENS.FILTER_HOSTS_SERVICE_MODULE, filterHostsModule);
|
||||||
|
|
||||||
|
export function getFilterHostsService() {
|
||||||
|
return container.get<FilterHostsService>(DI_TOKENS.FILTER_HOSTS_SERVICE);
|
||||||
|
}
|
||||||
+5
-5
@@ -5,11 +5,11 @@ import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
|||||||
import { prismaModule } from "@calcom/prisma/prisma.module";
|
import { prismaModule } from "@calcom/prisma/prisma.module";
|
||||||
|
|
||||||
import type { UserAvailabilityService } from "../../getUserAvailability";
|
import type { UserAvailabilityService } from "../../getUserAvailability";
|
||||||
import { bookingRepositoryModule } from "../modules/booking";
|
import { bookingRepositoryModule } from "../modules/Booking";
|
||||||
import { busyTimesModule } from "../modules/busy-times";
|
import { busyTimesModule } from "../modules/BusyTimes";
|
||||||
import { eventTypeRepositoryModule } from "../modules/eventType";
|
import { eventTypeRepositoryModule } from "../modules/EventType";
|
||||||
import { getUserAvailabilityModule } from "../modules/get-user-availability";
|
import { getUserAvailabilityModule } from "../modules/GetUserAvailability";
|
||||||
import { oooRepositoryModule } from "../modules/ooo";
|
import { oooRepositoryModule } from "../modules/Ooo";
|
||||||
|
|
||||||
const container = createContainer();
|
const container = createContainer();
|
||||||
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
||||||
+1
-1
@@ -9,7 +9,7 @@ import type {
|
|||||||
import type { InsightsBookingService } from "@calcom/lib/server/service/InsightsBookingDIService";
|
import type { InsightsBookingService } from "@calcom/lib/server/service/InsightsBookingDIService";
|
||||||
import { prismaModule } from "@calcom/prisma/prisma.module";
|
import { prismaModule } from "@calcom/prisma/prisma.module";
|
||||||
|
|
||||||
import { insightsBookingModule } from "../modules/insights-booking";
|
import { insightsBookingModule } from "../modules/InsightsBooking";
|
||||||
|
|
||||||
export function getInsightsBookingService({
|
export function getInsightsBookingService({
|
||||||
options,
|
options,
|
||||||
+1
-1
@@ -9,7 +9,7 @@ import type {
|
|||||||
import type { InsightsRoutingService } from "@calcom/lib/server/service/insightsRoutingDI";
|
import type { InsightsRoutingService } from "@calcom/lib/server/service/insightsRoutingDI";
|
||||||
import { prismaModule } from "@calcom/prisma/prisma.module";
|
import { prismaModule } from "@calcom/prisma/prisma.module";
|
||||||
|
|
||||||
import { insightsRoutingModule } from "../modules/insights-routing";
|
import { insightsRoutingModule } from "../modules/InsightsRouting";
|
||||||
|
|
||||||
export function getInsightsRoutingService({
|
export function getInsightsRoutingService({
|
||||||
options,
|
options,
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { createContainer } from "@evyweb/ioctopus";
|
||||||
|
|
||||||
|
import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
||||||
|
import { prismaModule } from "@calcom/prisma/prisma.module";
|
||||||
|
|
||||||
|
import type { QualifiedHostsService } from "../../bookings/findQualifiedHostsWithDelegationCredentials";
|
||||||
|
import { bookingRepositoryModule } from "../modules/Booking";
|
||||||
|
import { filterHostsModule } from "../modules/FilterHosts";
|
||||||
|
import { qualifiedHostsModule } from "../modules/QualifiedHosts";
|
||||||
|
|
||||||
|
const container = createContainer();
|
||||||
|
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
||||||
|
container.load(DI_TOKENS.BOOKING_REPOSITORY_MODULE, bookingRepositoryModule);
|
||||||
|
container.load(DI_TOKENS.FILTER_HOSTS_SERVICE_MODULE, filterHostsModule);
|
||||||
|
container.load(DI_TOKENS.QUALIFIED_HOSTS_SERVICE_MODULE, qualifiedHostsModule);
|
||||||
|
|
||||||
|
export function getQualifiedHostsService() {
|
||||||
|
return container.get<QualifiedHostsService>(DI_TOKENS.QUALIFIED_HOSTS_SERVICE);
|
||||||
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,10 @@
|
|||||||
|
import { createModule } from "@evyweb/ioctopus";
|
||||||
|
|
||||||
|
import type { IFilterHostsService } from "../../bookings/filterHostsBySameRoundRobinHost";
|
||||||
|
import { FilterHostsService } from "../../bookings/filterHostsBySameRoundRobinHost";
|
||||||
|
import { DI_TOKENS } from "../tokens";
|
||||||
|
|
||||||
|
export const filterHostsModule = createModule();
|
||||||
|
filterHostsModule.bind(DI_TOKENS.FILTER_HOSTS_SERVICE).toClass(FilterHostsService, {
|
||||||
|
bookingRepo: DI_TOKENS.BOOKING_REPOSITORY,
|
||||||
|
} satisfies Record<keyof IFilterHostsService, symbol>);
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,12 @@
|
|||||||
|
import { createModule } from "@evyweb/ioctopus";
|
||||||
|
|
||||||
|
import type { IQualifiedHostsService } from "../../bookings/findQualifiedHostsWithDelegationCredentials";
|
||||||
|
import { QualifiedHostsService } from "../../bookings/findQualifiedHostsWithDelegationCredentials";
|
||||||
|
import { DI_TOKENS } from "../tokens";
|
||||||
|
|
||||||
|
export const qualifiedHostsModule = createModule();
|
||||||
|
qualifiedHostsModule.bind(DI_TOKENS.QUALIFIED_HOSTS_SERVICE).toClass(QualifiedHostsService, {
|
||||||
|
prisma: DI_TOKENS.PRISMA_CLIENT,
|
||||||
|
bookingRepo: DI_TOKENS.BOOKING_REPOSITORY,
|
||||||
|
filterHostsService: DI_TOKENS.FILTER_HOSTS_SERVICE,
|
||||||
|
} satisfies Record<keyof IQualifiedHostsService, symbol>);
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -37,4 +37,8 @@ export const DI_TOKENS = {
|
|||||||
GET_USER_AVAILABILITY_SERVICE_MODULE: Symbol("GetUserAvailabilityModule"),
|
GET_USER_AVAILABILITY_SERVICE_MODULE: Symbol("GetUserAvailabilityModule"),
|
||||||
BUSY_TIMES_SERVICE: Symbol("BusyTimesService"),
|
BUSY_TIMES_SERVICE: Symbol("BusyTimesService"),
|
||||||
BUSY_TIMES_SERVICE_MODULE: Symbol("BusyTimesServiceModule"),
|
BUSY_TIMES_SERVICE_MODULE: Symbol("BusyTimesServiceModule"),
|
||||||
|
QUALIFIED_HOSTS_SERVICE: Symbol("QualifiedHostsService"),
|
||||||
|
QUALIFIED_HOSTS_SERVICE_MODULE: Symbol("QualifiedHostsServiceModule"),
|
||||||
|
FILTER_HOSTS_SERVICE: Symbol("FilterHostsService"),
|
||||||
|
FILTER_HOSTS_SERVICE_MODULE: Symbol("FilterHostsServiceModule"),
|
||||||
};
|
};
|
||||||
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
|
|||||||
|
|
||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
|
|
||||||
import { getBusyTimesService } from "./di/containers/busy-times";
|
import { getBusyTimesService } from "./di/containers/BusyTimes";
|
||||||
|
|
||||||
const startOfTomorrow = dayjs().add(1, "day").startOf("day");
|
const startOfTomorrow = dayjs().add(1, "day").startOf("day");
|
||||||
const tomorrowDate = startOfTomorrow.format("YYYY-MM-DD");
|
const tomorrowDate = startOfTomorrow.format("YYYY-MM-DD");
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
|||||||
import type { EventBusyDetails, IntervalLimitUnit } from "@calcom/types/Calendar";
|
import type { EventBusyDetails, IntervalLimitUnit } from "@calcom/types/Calendar";
|
||||||
import type { TimeRange } from "@calcom/types/schedule";
|
import type { TimeRange } from "@calcom/types/schedule";
|
||||||
|
|
||||||
import { getBusyTimesService } from "./di/containers/busy-times";
|
import { getBusyTimesService } from "./di/containers/BusyTimes";
|
||||||
import { getPeriodStartDatesBetween as getPeriodStartDatesBetweenUtil } from "./intervalLimits/utils/getPeriodStartDatesBetween";
|
import { getPeriodStartDatesBetween as getPeriodStartDatesBetweenUtil } from "./intervalLimits/utils/getPeriodStartDatesBetween";
|
||||||
import { withReporting } from "./sentryWrapper";
|
import { withReporting } from "./sentryWrapper";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { Dayjs } from "@calcom/dayjs";
|
import type { Dayjs } from "@calcom/dayjs";
|
||||||
import dayjs from "@calcom/dayjs";
|
import dayjs from "@calcom/dayjs";
|
||||||
import { getCheckBookingLimitsService } from "@calcom/lib/di/containers/booking-limits";
|
import { getCheckBookingLimitsService } from "@calcom/lib/di/containers/BookingLimits";
|
||||||
import { getBusyTimesService } from "@calcom/lib/di/containers/busy-times";
|
import { getBusyTimesService } from "@calcom/lib/di/containers/BusyTimes";
|
||||||
import type { EventType } from "@calcom/lib/getUserAvailability";
|
import type { EventType } from "@calcom/lib/getUserAvailability";
|
||||||
import { getPeriodStartDatesBetween } from "@calcom/lib/intervalLimits/utils/getPeriodStartDatesBetween";
|
import { getPeriodStartDatesBetween } from "@calcom/lib/intervalLimits/utils/getPeriodStartDatesBetween";
|
||||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||||
|
|||||||
@@ -935,4 +935,23 @@ export class BookingRepository {
|
|||||||
}
|
}
|
||||||
return totalBookingTime.totalMinutes ?? 0;
|
return totalBookingTime.totalMinutes ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findOriginalRescheduledBookingUserId({ rescheduleUid }: { rescheduleUid: string }) {
|
||||||
|
return await this.prismaClient.booking.findFirst({
|
||||||
|
where: {
|
||||||
|
uid: rescheduleUid,
|
||||||
|
status: {
|
||||||
|
in: [BookingStatus.ACCEPTED, BookingStatus.CANCELLED, BookingStatus.PENDING],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
userId: true,
|
||||||
|
attendees: {
|
||||||
|
select: {
|
||||||
|
email: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getUserAvailabilityService } from "@calcom/lib/di/containers/get-user-availability";
|
import { getUserAvailabilityService } from "@calcom/lib/di/containers/GetUserAvailability";
|
||||||
|
|
||||||
import type { TrpcSessionUser } from "../../../types";
|
import type { TrpcSessionUser } from "../../../types";
|
||||||
import type { TUserInputSchema } from "./user.schema";
|
import type { TUserInputSchema } from "./user.schema";
|
||||||
@@ -11,7 +11,7 @@ type UserOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const userHandler = async ({ input }: UserOptions) => {
|
export const userHandler = async ({ input }: UserOptions) => {
|
||||||
const userAvailabilityService = getUserAvailabilityService()
|
const userAvailabilityService = getUserAvailabilityService();
|
||||||
return userAvailabilityService.getUserAvailability(
|
return userAvailabilityService.getUserAvailability(
|
||||||
{ returnDateOverrides: true, bypassBusyCalendarTimes: false, ...input },
|
{ returnDateOverrides: true, bypassBusyCalendarTimes: false, ...input },
|
||||||
undefined
|
undefined
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { IncomingMessage } from "http";
|
import type { IncomingMessage } from "http";
|
||||||
|
|
||||||
import { getAvailableSlotsService } from "@calcom/lib/di/containers/available-slots";
|
import { getAvailableSlotsService } from "@calcom/lib/di/containers/AvailableSlots";
|
||||||
|
|
||||||
import type { TGetTeamScheduleInputSchema } from "./getTeamSchedule.schema";
|
import type { TGetTeamScheduleInputSchema } from "./getTeamSchedule.schema";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getAvailableSlotsService } from "@calcom/lib/di/containers/available-slots";
|
import { getAvailableSlotsService } from "@calcom/lib/di/containers/AvailableSlots";
|
||||||
|
|
||||||
import type { GetScheduleOptions } from "./types";
|
import type { GetScheduleOptions } from "./types";
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ import { checkForConflicts } from "@calcom/features/bookings/lib/conflictChecker
|
|||||||
import { isEventTypeLoggingEnabled } from "@calcom/features/bookings/lib/isEventTypeLoggingEnabled";
|
import { isEventTypeLoggingEnabled } from "@calcom/features/bookings/lib/isEventTypeLoggingEnabled";
|
||||||
import type { CacheService } from "@calcom/features/calendar-cache/lib/getShouldServeCache";
|
import type { CacheService } from "@calcom/features/calendar-cache/lib/getShouldServeCache";
|
||||||
import type { IRedisService } from "@calcom/features/redis/IRedisService";
|
import type { IRedisService } from "@calcom/features/redis/IRedisService";
|
||||||
import { findQualifiedHostsWithDelegationCredentials } from "@calcom/lib/bookings/findQualifiedHostsWithDelegationCredentials";
|
|
||||||
import { shouldIgnoreContactOwner } from "@calcom/lib/bookings/routing/utils";
|
import { shouldIgnoreContactOwner } from "@calcom/lib/bookings/routing/utils";
|
||||||
import { RESERVED_SUBDOMAINS } from "@calcom/lib/constants";
|
import { RESERVED_SUBDOMAINS } from "@calcom/lib/constants";
|
||||||
import { buildDateRanges } from "@calcom/lib/date-ranges";
|
import { buildDateRanges } from "@calcom/lib/date-ranges";
|
||||||
import { getUTCOffsetByTimezone } from "@calcom/lib/dayjs";
|
import { getUTCOffsetByTimezone } from "@calcom/lib/dayjs";
|
||||||
import { getDefaultEvent } from "@calcom/lib/defaultEvents";
|
import { getDefaultEvent } from "@calcom/lib/defaultEvents";
|
||||||
import type { getBusyTimesService } from "@calcom/lib/di/containers/busy-times";
|
import type { getBusyTimesService } from "@calcom/lib/di/containers/BusyTimes";
|
||||||
|
import { getQualifiedHostsService } from "@calcom/lib/di/containers/QualifiedHosts";
|
||||||
import { getAggregatedAvailability } from "@calcom/lib/getAggregatedAvailability";
|
import { getAggregatedAvailability } from "@calcom/lib/getAggregatedAvailability";
|
||||||
import type { BusyTimesService } from "@calcom/lib/getBusyTimes";
|
import type { BusyTimesService } from "@calcom/lib/getBusyTimes";
|
||||||
import type {
|
import type {
|
||||||
@@ -1027,9 +1027,9 @@ export class AvailableSlotsService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: DI findQualifiedHostsWithDelegationCredentials
|
const qualifiedHostsService = getQualifiedHostsService();
|
||||||
const { qualifiedRRHosts, allFallbackRRHosts, fixedHosts } =
|
const { qualifiedRRHosts, allFallbackRRHosts, fixedHosts } =
|
||||||
await findQualifiedHostsWithDelegationCredentials({
|
await qualifiedHostsService.findQualifiedHostsWithDelegationCredentials({
|
||||||
eventType,
|
eventType,
|
||||||
rescheduleUid: input.rescheduleUid ?? null,
|
rescheduleUid: input.rescheduleUid ?? null,
|
||||||
routedTeamMemberIds,
|
routedTeamMemberIds,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { enrichUserWithDelegationCredentialsIncludeServiceAccountKey } from "@calcom/lib/delegationCredential/server";
|
import { enrichUserWithDelegationCredentialsIncludeServiceAccountKey } from "@calcom/lib/delegationCredential/server";
|
||||||
import { getUserAvailabilityService } from "@calcom/lib/di/containers/get-user-availability";
|
import { getUserAvailabilityService } from "@calcom/lib/di/containers/GetUserAvailability";
|
||||||
import { isTeamMember } from "@calcom/lib/server/queries/teams";
|
import { isTeamMember } from "@calcom/lib/server/queries/teams";
|
||||||
import { MembershipRepository } from "@calcom/lib/server/repository/membership";
|
import { MembershipRepository } from "@calcom/lib/server/repository/membership";
|
||||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||||
@@ -16,7 +16,7 @@ type GetMemberAvailabilityOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getMemberAvailabilityHandler = async ({ ctx, input }: GetMemberAvailabilityOptions) => {
|
export const getMemberAvailabilityHandler = async ({ ctx, input }: GetMemberAvailabilityOptions) => {
|
||||||
const userAvailabilityService = getUserAvailabilityService()
|
const userAvailabilityService = getUserAvailabilityService();
|
||||||
const team = await isTeamMember(ctx.user?.id, input.teamId);
|
const team = await isTeamMember(ctx.user?.id, input.teamId);
|
||||||
if (!team) throw new TRPCError({ code: "UNAUTHORIZED" });
|
if (!team) throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||||
|
|
||||||
|
|||||||
@@ -2500,7 +2500,7 @@ __metadata:
|
|||||||
"@axiomhq/winston": ^1.2.0
|
"@axiomhq/winston": ^1.2.0
|
||||||
"@calcom/platform-constants": "*"
|
"@calcom/platform-constants": "*"
|
||||||
"@calcom/platform-enums": "*"
|
"@calcom/platform-enums": "*"
|
||||||
"@calcom/platform-libraries": "npm:@calcom/[email protected]4"
|
"@calcom/platform-libraries": "npm:@calcom/[email protected]8"
|
||||||
"@calcom/platform-types": "*"
|
"@calcom/platform-types": "*"
|
||||||
"@calcom/platform-utils": "*"
|
"@calcom/platform-utils": "*"
|
||||||
"@calcom/prisma": "*"
|
"@calcom/prisma": "*"
|
||||||
@@ -3558,13 +3558,13 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@calcom/platform-libraries@npm:@calcom/[email protected]4":
|
"@calcom/platform-libraries@npm:@calcom/[email protected]8":
|
||||||
version: 0.0.294
|
version: 0.0.298
|
||||||
resolution: "@calcom/platform-libraries@npm:0.0.294"
|
resolution: "@calcom/platform-libraries@npm:0.0.298"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@calcom/features": "*"
|
"@calcom/features": "*"
|
||||||
"@calcom/lib": "*"
|
"@calcom/lib": "*"
|
||||||
checksum: ce7beda30e629e87d560386bf1f117280ec3466ba7dfa2089de79c2d03c46d24ee3a5388a63974ba084b6624e863c2feb5e02f42ef08c72daefc7c51e771d5f8
|
checksum: 63401c90d15ce05a17905f68eb36e655c6368b430ee8c28df371c2b91d5033cab846e96406e28d2c716e8e361eefaf96caf2c3a26fa63bc239ec97632b0b7613
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user