feat: Custom host location (#25916)
* chore: save progress * chore: * feat: add input dialog * fix: type error * feat: mass apply dialog * test: per host location * test: fix test * fix: address Cubic AI review feedback (confidence >= 9/10) - Remove PII (address, phone number) from tracing logs in RegularBookingService.ts - Constrain HostLocation.type to EventLocationType["type"] for compile-time validation Co-Authored-By: unknown <> * fix: translation * refactor: improvements * fix: correct grammar in custom host locations tooltip Change 'custom host locations is enabled' to 'custom host locations are enabled' (plural subject requires plural verb). Addresses Cubic AI review feedback (confidence 9/10). Co-Authored-By: unknown <> * refactor: improvements * fix: auth * fix: check * refactor: improvements * fix: address Cubic AI review feedback (confidence >= 9/10) - Add scheduleId to newly created hosts in update.handler.ts to persist host-specific schedules during create operations - Change host location deletion filter from !host.location to host.location === null to only delete when explicitly set to null - Fix static-link per-host locations to use actual link instead of type in locationBodyString for bookingLocationService.ts Co-Authored-By: unknown <> * fix: preserve existing host scheduleId when not explicitly provided Change scheduleId handling for existing hosts from 'host.scheduleId ?? null' to 'host.scheduleId === undefined ? undefined : host.scheduleId' so that when the client doesn't provide a scheduleId, the existing value is preserved instead of being cleared to null. Co-Authored-By: unknown <> * fix; type erro * fix; type erro * fix; type erro * refactor: move repository * refactor: move repository * fix: add singular/plural translations for location_applied_to_hosts Addresses Cubic AI review feedback (confidence 9/10) to fix '1 hosts' rendering as '1 host' by using i18next plural format with _one and _other suffixes. Co-Authored-By: unknown <> * refactor: feedback * fix: type err * fix: use uuid in schema and remove attendee locaiton * fix: type err * fix: type err * fix: validate eventTypeId as integer in massApplyHostLocation schema Co-Authored-By: unknown <> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
33 files changed
+2625
-68
No files matched your search
@@ -127,6 +127,7 @@ const getEventTypesFromDBSelect = {
|
||||
timeZone: true,
|
||||
},
|
||||
},
|
||||
enablePerHostLocations: true,
|
||||
hosts: {
|
||||
select: {
|
||||
isFixed: true,
|
||||
@@ -134,6 +135,16 @@ const getEventTypesFromDBSelect = {
|
||||
weight: true,
|
||||
createdAt: true,
|
||||
groupId: true,
|
||||
location: {
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
credentialId: true,
|
||||
link: true,
|
||||
address: true,
|
||||
phoneNumber: true,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
select: {
|
||||
credentials: {
|
||||
|
||||
@@ -0,0 +1,776 @@
|
||||
import {
|
||||
getBooker,
|
||||
TestData,
|
||||
getOrganizer,
|
||||
createBookingScenario,
|
||||
Timezones,
|
||||
getScenarioData,
|
||||
mockSuccessfulVideoMeetingCreation,
|
||||
BookingLocations,
|
||||
getDate,
|
||||
getGoogleCalendarCredential,
|
||||
getZoomAppCredential,
|
||||
mockCalendarToHaveNoBusySlots,
|
||||
} from "@calcom/testing/lib/bookingScenario/bookingScenario";
|
||||
import { expectBookingToBeInDatabase } from "@calcom/testing/lib/bookingScenario/expects";
|
||||
import { getMockRequestDataForBooking } from "@calcom/testing/lib/bookingScenario/getMockRequestDataForBooking";
|
||||
import { setupAndTeardown } from "@calcom/testing/lib/bookingScenario/setupAndTeardown";
|
||||
|
||||
import { describe, test, expect } from "vitest";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
|
||||
import { getNewBookingHandler } from "./getNewBookingHandler";
|
||||
|
||||
describe("Per-Host Locations - handleNewBooking", () => {
|
||||
setupAndTeardown();
|
||||
|
||||
describe("Round-Robin with enablePerHostLocations enabled", () => {
|
||||
test("should use host's Zoom credential when host has credentialId", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
name: "Booker",
|
||||
});
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
defaultScheduleId: null,
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
credentials: [getGoogleCalendarCredential(), getZoomAppCredential()],
|
||||
selectedCalendars: [TestData.selectedCalendars.google],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
await createBookingScenario(
|
||||
getScenarioData({
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 30,
|
||||
schedulingType: SchedulingType.ROUND_ROBIN,
|
||||
length: 30,
|
||||
enablePerHostLocations: true,
|
||||
users: [{ id: organizer.id }],
|
||||
hosts: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
isFixed: false,
|
||||
location: {
|
||||
type: "integrations:zoom",
|
||||
credentialId: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["google-calendar"], TestData.apps["daily-video"], TestData.apps["zoomvideo"]],
|
||||
})
|
||||
);
|
||||
|
||||
mockSuccessfulVideoMeetingCreation({
|
||||
metadataLookupKey: "zoomvideo",
|
||||
videoMeetingData: {
|
||||
id: "MOCK_ZOOM_ID",
|
||||
password: "MOCK_ZOOM_PASS",
|
||||
url: `https://zoom.us/j/123456789`,
|
||||
},
|
||||
});
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
id: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
start: `${getDate({ dateIncrement: 1 }).dateString}T09:00:00.000Z`,
|
||||
end: `${getDate({ dateIncrement: 1 }).dateString}T09:30:00.000Z`,
|
||||
eventTypeId: 1,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
name: booker.name,
|
||||
location: { optionValue: "", value: BookingLocations.CalVideo },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const createdBooking = await handleNewBooking({
|
||||
bookingData: mockBookingData,
|
||||
});
|
||||
|
||||
expect(createdBooking).toBeDefined();
|
||||
expect(createdBooking.location).toBe("integrations:zoom");
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
uid: createdBooking.uid,
|
||||
location: "integrations:zoom",
|
||||
});
|
||||
});
|
||||
|
||||
test("should use Cal Video when host location is integrations:daily", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
name: "Booker",
|
||||
});
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
defaultScheduleId: null,
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
credentials: [getGoogleCalendarCredential()],
|
||||
selectedCalendars: [TestData.selectedCalendars.google],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
await createBookingScenario(
|
||||
getScenarioData({
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 30,
|
||||
schedulingType: SchedulingType.ROUND_ROBIN,
|
||||
length: 30,
|
||||
enablePerHostLocations: true,
|
||||
users: [{ id: organizer.id }],
|
||||
hosts: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
isFixed: false,
|
||||
location: {
|
||||
type: "integrations:daily",
|
||||
},
|
||||
},
|
||||
],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["google-calendar"], TestData.apps["daily-video"]],
|
||||
})
|
||||
);
|
||||
|
||||
mockSuccessfulVideoMeetingCreation({
|
||||
metadataLookupKey: "dailyvideo",
|
||||
videoMeetingData: {
|
||||
id: "MOCK_DAILY_ID",
|
||||
password: "MOCK_DAILY_PASS",
|
||||
url: `http://mock-dailyvideo.example.com/meeting-1`,
|
||||
},
|
||||
});
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
id: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
start: `${getDate({ dateIncrement: 1 }).dateString}T09:00:00.000Z`,
|
||||
end: `${getDate({ dateIncrement: 1 }).dateString}T09:30:00.000Z`,
|
||||
eventTypeId: 1,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
name: booker.name,
|
||||
location: { optionValue: "", value: BookingLocations.CalVideo },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const createdBooking = await handleNewBooking({
|
||||
bookingData: mockBookingData,
|
||||
});
|
||||
|
||||
expect(createdBooking).toBeDefined();
|
||||
expect(createdBooking.location).toBe("integrations:daily");
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
uid: createdBooking.uid,
|
||||
location: "integrations:daily",
|
||||
});
|
||||
});
|
||||
|
||||
test("should use stored link when host location type is link", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
name: "Booker",
|
||||
});
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
defaultScheduleId: null,
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
credentials: [getGoogleCalendarCredential()],
|
||||
selectedCalendars: [TestData.selectedCalendars.google],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
const customLink = "https://custom-meeting.example.com/room123";
|
||||
|
||||
await createBookingScenario(
|
||||
getScenarioData({
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 30,
|
||||
schedulingType: SchedulingType.ROUND_ROBIN,
|
||||
length: 30,
|
||||
enablePerHostLocations: true,
|
||||
users: [{ id: organizer.id }],
|
||||
hosts: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
isFixed: false,
|
||||
location: {
|
||||
type: "link",
|
||||
link: customLink,
|
||||
},
|
||||
},
|
||||
],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["google-calendar"], TestData.apps["daily-video"]],
|
||||
})
|
||||
);
|
||||
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
id: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
start: `${getDate({ dateIncrement: 1 }).dateString}T09:00:00.000Z`,
|
||||
end: `${getDate({ dateIncrement: 1 }).dateString}T09:30:00.000Z`,
|
||||
eventTypeId: 1,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
name: booker.name,
|
||||
location: { optionValue: "", value: "link" },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const createdBooking = await handleNewBooking({
|
||||
bookingData: mockBookingData,
|
||||
});
|
||||
|
||||
expect(createdBooking).toBeDefined();
|
||||
expect(createdBooking.location).toBe(customLink);
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
uid: createdBooking.uid,
|
||||
location: customLink,
|
||||
});
|
||||
});
|
||||
|
||||
test("should use stored address when host location type is inPerson", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
name: "Booker",
|
||||
});
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
defaultScheduleId: null,
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
credentials: [getGoogleCalendarCredential()],
|
||||
selectedCalendars: [TestData.selectedCalendars.google],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
const officeAddress = "123 Main St, San Francisco, CA 94102";
|
||||
|
||||
await createBookingScenario(
|
||||
getScenarioData({
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 30,
|
||||
schedulingType: SchedulingType.ROUND_ROBIN,
|
||||
length: 30,
|
||||
enablePerHostLocations: true,
|
||||
users: [{ id: organizer.id }],
|
||||
hosts: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
isFixed: false,
|
||||
location: {
|
||||
type: "inPerson",
|
||||
address: officeAddress,
|
||||
},
|
||||
},
|
||||
],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["google-calendar"], TestData.apps["daily-video"]],
|
||||
})
|
||||
);
|
||||
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
id: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
start: `${getDate({ dateIncrement: 1 }).dateString}T09:00:00.000Z`,
|
||||
end: `${getDate({ dateIncrement: 1 }).dateString}T09:30:00.000Z`,
|
||||
eventTypeId: 1,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
name: booker.name,
|
||||
location: { optionValue: "", value: "inPerson" },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const createdBooking = await handleNewBooking({
|
||||
bookingData: mockBookingData,
|
||||
});
|
||||
|
||||
expect(createdBooking).toBeDefined();
|
||||
expect(createdBooking.location).toBe(officeAddress);
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
uid: createdBooking.uid,
|
||||
location: officeAddress,
|
||||
});
|
||||
});
|
||||
|
||||
test("should auto-link credential when host has location type but no credential", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
name: "Booker",
|
||||
});
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
defaultScheduleId: null,
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
credentials: [getGoogleCalendarCredential(), getZoomAppCredential()],
|
||||
selectedCalendars: [TestData.selectedCalendars.google],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
await createBookingScenario(
|
||||
getScenarioData({
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 30,
|
||||
schedulingType: SchedulingType.ROUND_ROBIN,
|
||||
length: 30,
|
||||
enablePerHostLocations: true,
|
||||
users: [{ id: organizer.id }],
|
||||
hosts: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
isFixed: false,
|
||||
location: {
|
||||
type: "integrations:zoom",
|
||||
credentialId: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["google-calendar"], TestData.apps["daily-video"], TestData.apps["zoomvideo"]],
|
||||
})
|
||||
);
|
||||
|
||||
mockSuccessfulVideoMeetingCreation({
|
||||
metadataLookupKey: "zoomvideo",
|
||||
videoMeetingData: {
|
||||
id: "MOCK_ZOOM_ID",
|
||||
password: "MOCK_ZOOM_PASS",
|
||||
url: `https://zoom.us/j/123456789`,
|
||||
},
|
||||
});
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
id: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
start: `${getDate({ dateIncrement: 1 }).dateString}T09:00:00.000Z`,
|
||||
end: `${getDate({ dateIncrement: 1 }).dateString}T09:30:00.000Z`,
|
||||
eventTypeId: 1,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
name: booker.name,
|
||||
location: { optionValue: "", value: BookingLocations.CalVideo },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const createdBooking = await handleNewBooking({
|
||||
bookingData: mockBookingData,
|
||||
});
|
||||
|
||||
expect(createdBooking).toBeDefined();
|
||||
expect(createdBooking.location).toBe("integrations:zoom");
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
uid: createdBooking.uid,
|
||||
location: "integrations:zoom",
|
||||
});
|
||||
|
||||
const hostLocation = await prisma.hostLocation.findUnique({
|
||||
where: {
|
||||
userId_eventTypeId: {
|
||||
userId: organizer.id,
|
||||
eventTypeId: 1,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
credentialId: true,
|
||||
},
|
||||
});
|
||||
expect(hostLocation?.credentialId).not.toBeNull();
|
||||
});
|
||||
|
||||
test("should fallback to Cal Video when no matching credential found", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
name: "Booker",
|
||||
});
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
defaultScheduleId: null,
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
credentials: [getGoogleCalendarCredential()],
|
||||
selectedCalendars: [TestData.selectedCalendars.google],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
await createBookingScenario(
|
||||
getScenarioData({
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 30,
|
||||
schedulingType: SchedulingType.ROUND_ROBIN,
|
||||
length: 30,
|
||||
enablePerHostLocations: true,
|
||||
users: [{ id: organizer.id }],
|
||||
hosts: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
isFixed: false,
|
||||
location: {
|
||||
type: "integrations:zoom",
|
||||
credentialId: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["google-calendar"], TestData.apps["daily-video"]],
|
||||
})
|
||||
);
|
||||
|
||||
mockSuccessfulVideoMeetingCreation({
|
||||
metadataLookupKey: "dailyvideo",
|
||||
videoMeetingData: {
|
||||
id: "MOCK_DAILY_ID",
|
||||
password: "MOCK_DAILY_PASS",
|
||||
url: `http://mock-dailyvideo.example.com/meeting-1`,
|
||||
},
|
||||
});
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
id: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
start: `${getDate({ dateIncrement: 1 }).dateString}T09:00:00.000Z`,
|
||||
end: `${getDate({ dateIncrement: 1 }).dateString}T09:30:00.000Z`,
|
||||
eventTypeId: 1,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
name: booker.name,
|
||||
location: { optionValue: "", value: BookingLocations.CalVideo },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const createdBooking = await handleNewBooking({
|
||||
bookingData: mockBookingData,
|
||||
});
|
||||
|
||||
expect(createdBooking).toBeDefined();
|
||||
expect(createdBooking.location).toBe("integrations:daily");
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
uid: createdBooking.uid,
|
||||
location: "integrations:daily",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Feature flag behavior", () => {
|
||||
test("should ignore per-host locations when enablePerHostLocations is false", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
name: "Booker",
|
||||
});
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
defaultScheduleId: null,
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
credentials: [getGoogleCalendarCredential(), getZoomAppCredential()],
|
||||
selectedCalendars: [TestData.selectedCalendars.google],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
await createBookingScenario(
|
||||
getScenarioData({
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 30,
|
||||
schedulingType: SchedulingType.ROUND_ROBIN,
|
||||
length: 30,
|
||||
enablePerHostLocations: false,
|
||||
users: [{ id: organizer.id }],
|
||||
hosts: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
isFixed: false,
|
||||
location: {
|
||||
type: "integrations:zoom",
|
||||
credentialId: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["google-calendar"], TestData.apps["daily-video"], TestData.apps["zoomvideo"]],
|
||||
})
|
||||
);
|
||||
|
||||
mockSuccessfulVideoMeetingCreation({
|
||||
metadataLookupKey: "dailyvideo",
|
||||
videoMeetingData: {
|
||||
id: "MOCK_DAILY_ID",
|
||||
password: "MOCK_DAILY_PASS",
|
||||
url: `http://mock-dailyvideo.example.com/meeting-1`,
|
||||
},
|
||||
});
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
id: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
start: `${getDate({ dateIncrement: 1 }).dateString}T09:00:00.000Z`,
|
||||
end: `${getDate({ dateIncrement: 1 }).dateString}T09:30:00.000Z`,
|
||||
eventTypeId: 1,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
name: booker.name,
|
||||
location: { optionValue: "", value: BookingLocations.CalVideo },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const createdBooking = await handleNewBooking({
|
||||
bookingData: mockBookingData,
|
||||
});
|
||||
|
||||
expect(createdBooking).toBeDefined();
|
||||
expect(createdBooking.location).toBe("integrations:daily");
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
uid: createdBooking.uid,
|
||||
location: "integrations:daily",
|
||||
});
|
||||
});
|
||||
|
||||
test("should ignore per-host locations for non-round-robin events", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
name: "Booker",
|
||||
});
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
defaultScheduleId: null,
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
credentials: [getGoogleCalendarCredential(), getZoomAppCredential()],
|
||||
selectedCalendars: [TestData.selectedCalendars.google],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
await createBookingScenario(
|
||||
getScenarioData({
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 30,
|
||||
schedulingType: SchedulingType.COLLECTIVE,
|
||||
length: 30,
|
||||
enablePerHostLocations: true,
|
||||
users: [{ id: organizer.id }],
|
||||
hosts: [
|
||||
{
|
||||
userId: organizer.id,
|
||||
isFixed: true,
|
||||
location: {
|
||||
type: "integrations:zoom",
|
||||
credentialId: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
destinationCalendar: {
|
||||
integration: TestData.apps["google-calendar"].type,
|
||||
externalId: "[email protected]",
|
||||
},
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["google-calendar"], TestData.apps["daily-video"], TestData.apps["zoomvideo"]],
|
||||
})
|
||||
);
|
||||
|
||||
mockSuccessfulVideoMeetingCreation({
|
||||
metadataLookupKey: "dailyvideo",
|
||||
videoMeetingData: {
|
||||
id: "MOCK_DAILY_ID",
|
||||
password: "MOCK_DAILY_PASS",
|
||||
url: `http://mock-dailyvideo.example.com/meeting-1`,
|
||||
},
|
||||
});
|
||||
mockCalendarToHaveNoBusySlots("googlecalendar", {
|
||||
create: {
|
||||
id: "MOCKED_GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID: "MOCKED_GOOGLE_CALENDAR_ICS_ID",
|
||||
},
|
||||
});
|
||||
|
||||
const mockBookingData = getMockRequestDataForBooking({
|
||||
data: {
|
||||
start: `${getDate({ dateIncrement: 1 }).dateString}T09:00:00.000Z`,
|
||||
end: `${getDate({ dateIncrement: 1 }).dateString}T09:30:00.000Z`,
|
||||
eventTypeId: 1,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
name: booker.name,
|
||||
location: { optionValue: "", value: BookingLocations.CalVideo },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const createdBooking = await handleNewBooking({
|
||||
bookingData: mockBookingData,
|
||||
});
|
||||
|
||||
expect(createdBooking).toBeDefined();
|
||||
expect(createdBooking.location).toBe("integrations:daily");
|
||||
|
||||
await expectBookingToBeInDatabase({
|
||||
uid: createdBooking.uid,
|
||||
location: "integrations:daily",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -46,6 +46,7 @@ import { getSpamCheckService } from "@calcom/features/di/watchlist/containers/Sp
|
||||
import { CreditService } from "@calcom/features/ee/billing/credit-service";
|
||||
import { getBookerBaseUrl } from "@calcom/features/ee/organizations/lib/getBookerUrlServer";
|
||||
import AssignmentReasonRecorder from "@calcom/features/ee/round-robin/assignmentReason/AssignmentReasonRecorder";
|
||||
import { BookingLocationService } from "@calcom/features/ee/round-robin/lib/bookingLocationService";
|
||||
import { getAllWorkflowsFromEventType } from "@calcom/features/ee/workflows/lib/getAllWorkflowsFromEventType";
|
||||
import { WorkflowService } from "@calcom/features/ee/workflows/lib/service/WorkflowService";
|
||||
import { WorkflowRepository } from "@calcom/features/ee/workflows/repositories/WorkflowRepository";
|
||||
@@ -1299,9 +1300,40 @@ async function handler(
|
||||
|
||||
const isManagedEventType = !!eventType.parentId;
|
||||
|
||||
// Track credential ID for per-host locations
|
||||
let perHostCredentialId: number | undefined = undefined;
|
||||
|
||||
// Handle per-host custom locations for round-robin events
|
||||
if (
|
||||
eventType.enablePerHostLocations &&
|
||||
eventType.schedulingType === SchedulingType.ROUND_ROBIN &&
|
||||
organizerUser
|
||||
) {
|
||||
const organizerHost = eventType.hosts.find((host) => host.user.id === organizerUser.id);
|
||||
if (organizerHost?.location) {
|
||||
const result = await BookingLocationService.getPerHostLocation({
|
||||
hostLocation: organizerHost.location,
|
||||
allCredentials,
|
||||
eventTypeId: eventType.id,
|
||||
userId: organizerUser.id,
|
||||
prismaClient: deps.prismaClient,
|
||||
});
|
||||
|
||||
locationBodyString = result.locationBodyString;
|
||||
organizerOrFirstDynamicGroupMemberDefaultLocationUrl = result.organizerDefaultLocationUrl;
|
||||
perHostCredentialId = result.perHostCredentialId;
|
||||
|
||||
tracingLogger.info("Using per-host location", {
|
||||
userId: organizerUser.id,
|
||||
locationType: result.locationBodyString,
|
||||
credentialId: result.perHostCredentialId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// If location passed is empty , use default location of event
|
||||
// If location of event is not set , use host default
|
||||
if (locationBodyString.trim().length == 0) {
|
||||
if (locationBodyString.trim().length === 0) {
|
||||
if (eventType.locations.length > 0) {
|
||||
locationBodyString = eventType.locations[0].type;
|
||||
} else {
|
||||
@@ -1396,12 +1428,16 @@ async function handler(
|
||||
|
||||
// For static link based video apps, it would have the static URL value instead of it's type(e.g. integrations:campfire_video)
|
||||
// This ensures that createMeeting isn't called for static video apps as bookingLocation becomes just a regular value for them.
|
||||
const { bookingLocation, conferenceCredentialId } = organizerOrFirstDynamicGroupMemberDefaultLocationUrl
|
||||
? {
|
||||
bookingLocation: organizerOrFirstDynamicGroupMemberDefaultLocationUrl,
|
||||
conferenceCredentialId: undefined,
|
||||
}
|
||||
: getLocationValueForDB(locationBodyString, eventType.locations);
|
||||
const { bookingLocation, conferenceCredentialId: eventTypeCredentialId } =
|
||||
organizerOrFirstDynamicGroupMemberDefaultLocationUrl
|
||||
? {
|
||||
bookingLocation: organizerOrFirstDynamicGroupMemberDefaultLocationUrl,
|
||||
conferenceCredentialId: undefined,
|
||||
}
|
||||
: getLocationValueForDB(locationBodyString, eventType.locations);
|
||||
|
||||
// Use per-host credential if available, otherwise fall back to event type credential
|
||||
const conferenceCredentialId = perHostCredentialId ?? eventTypeCredentialId;
|
||||
|
||||
tracingLogger.info("locationBodyString", locationBodyString);
|
||||
tracingLogger.info("event type locations", eventType.locations);
|
||||
|
||||
@@ -41,6 +41,7 @@ export type BookerEvent = Pick<
|
||||
| "recurringEvent"
|
||||
| "entity"
|
||||
| "locations"
|
||||
| "enablePerHostLocations"
|
||||
| "metadata"
|
||||
| "isDynamic"
|
||||
| "requiresConfirmation"
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
|
||||
import { getLocationValueForDB, OrganizerDefaultConferencingAppType } from "@calcom/app-store/locations";
|
||||
import { CalVideoLocationType, type LocationObject } from "@calcom/app-store/locations";
|
||||
import { getAppFromSlug } from "@calcom/app-store/utils";
|
||||
import { HostLocationRepository } from "@calcom/features/host/repositories/HostLocationRepository";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
|
||||
type GetOrganizerDefaultConferencingAppLocationParams = {
|
||||
@@ -86,6 +89,28 @@ type GetLocationDetailsFromTypeResult = {
|
||||
conferenceCredentialId: number | null;
|
||||
};
|
||||
|
||||
type HostLocation = {
|
||||
type: string;
|
||||
credentialId: number | null;
|
||||
link: string | null;
|
||||
address: string | null;
|
||||
phoneNumber: string | null;
|
||||
};
|
||||
|
||||
type GetPerHostLocationParams = {
|
||||
hostLocation: HostLocation;
|
||||
allCredentials: { id: number; type: string }[];
|
||||
eventTypeId: number;
|
||||
userId: number;
|
||||
prismaClient: PrismaClient;
|
||||
};
|
||||
|
||||
type GetPerHostLocationResult = {
|
||||
locationBodyString: string;
|
||||
organizerDefaultLocationUrl: string | null;
|
||||
perHostCredentialId: number | undefined;
|
||||
};
|
||||
|
||||
export class BookingLocationService {
|
||||
/**
|
||||
* Determines the booking location based on the Organizer's Default Conferencing App.
|
||||
@@ -244,4 +269,100 @@ export class BookingLocationService {
|
||||
|
||||
return { bookingLocation, conferenceCredentialId: conferenceCredentialId ?? null };
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the location for a per-host custom location in round-robin events.
|
||||
*
|
||||
* Handles different location types:
|
||||
* - Credential-based apps (Zoom, Teams, etc.) - Uses the host's stored credential
|
||||
* - Cal Video - No credential needed
|
||||
* - Static links - Returns the stored link
|
||||
* - In-person - Returns the stored address
|
||||
* - Phone locations - Returns the stored phone number or type
|
||||
* - Unknown apps - Attempts to find and link a credential, falls back to Cal Video
|
||||
*/
|
||||
static async getPerHostLocation({
|
||||
hostLocation,
|
||||
allCredentials,
|
||||
eventTypeId,
|
||||
userId,
|
||||
prismaClient,
|
||||
}: GetPerHostLocationParams): Promise<GetPerHostLocationResult> {
|
||||
if (hostLocation.credentialId) {
|
||||
return {
|
||||
locationBodyString: hostLocation.type,
|
||||
organizerDefaultLocationUrl: null,
|
||||
perHostCredentialId: hostLocation.credentialId,
|
||||
};
|
||||
}
|
||||
|
||||
if (hostLocation.type === CalVideoLocationType) {
|
||||
return {
|
||||
locationBodyString: hostLocation.type,
|
||||
organizerDefaultLocationUrl: null,
|
||||
perHostCredentialId: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
if (hostLocation.link) {
|
||||
return {
|
||||
locationBodyString: hostLocation.link,
|
||||
organizerDefaultLocationUrl: hostLocation.link,
|
||||
perHostCredentialId: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
if (hostLocation.type === "inPerson") {
|
||||
return {
|
||||
locationBodyString: hostLocation.address || hostLocation.type,
|
||||
organizerDefaultLocationUrl: null,
|
||||
perHostCredentialId: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
if (hostLocation.type === "userPhone") {
|
||||
return {
|
||||
locationBodyString: hostLocation.phoneNumber || hostLocation.type,
|
||||
organizerDefaultLocationUrl: null,
|
||||
perHostCredentialId: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
if (hostLocation.type === "attendeeInPerson" || hostLocation.type === "phone") {
|
||||
return {
|
||||
locationBodyString: hostLocation.type,
|
||||
organizerDefaultLocationUrl: null,
|
||||
perHostCredentialId: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
const appMetaForLocation = Object.values(appStoreMetadata).find(
|
||||
(app) => app.appData?.location?.type === hostLocation.type
|
||||
);
|
||||
|
||||
if (appMetaForLocation) {
|
||||
const matchingCredential = allCredentials.find((cred) => cred.type === appMetaForLocation.type);
|
||||
|
||||
if (matchingCredential) {
|
||||
const hostLocationRepository = new HostLocationRepository(prismaClient);
|
||||
await hostLocationRepository.linkCredential({
|
||||
userId,
|
||||
eventTypeId,
|
||||
credentialId: matchingCredential.id,
|
||||
});
|
||||
|
||||
return {
|
||||
locationBodyString: hostLocation.type,
|
||||
organizerDefaultLocationUrl: null,
|
||||
perHostCredentialId: matchingCredential.id,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
locationBodyString: CalVideoLocationType,
|
||||
organizerDefaultLocationUrl: null,
|
||||
perHostCredentialId: undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -115,6 +115,7 @@ export const roundRobinManualReassignment = async ({
|
||||
schedule: null,
|
||||
createdAt: new Date(0), // use earliest possible date as fallback
|
||||
groupId: null,
|
||||
location: null,
|
||||
}));
|
||||
|
||||
const fixedHost = eventTypeHosts.find((host) => host.isFixed);
|
||||
|
||||
@@ -113,6 +113,7 @@ export const roundRobinReassignment = async ({
|
||||
schedule: null,
|
||||
createdAt: new Date(0), // use earliest possible date as fallback
|
||||
groupId: null,
|
||||
location: null,
|
||||
}));
|
||||
|
||||
if (eventType.hosts.length === 0) {
|
||||
|
||||
@@ -154,6 +154,7 @@ const commons = {
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
rrHostSubsetEnabled: false,
|
||||
enablePerHostLocations: false,
|
||||
};
|
||||
|
||||
export const dynamicEvent = {
|
||||
|
||||
@@ -70,6 +70,7 @@ export const getPublicEventSelect = (fetchAllUsers: boolean) => {
|
||||
schedulingType: true,
|
||||
length: true,
|
||||
locations: true,
|
||||
enablePerHostLocations: true,
|
||||
customInputs: true,
|
||||
disableGuests: true,
|
||||
metadata: true,
|
||||
|
||||
@@ -27,6 +27,17 @@ export type AvailabilityOption = {
|
||||
export type EventTypeSetupProps = RouterOutputs["viewer"]["eventTypes"]["get"];
|
||||
export type EventTypeSetup = RouterOutputs["viewer"]["eventTypes"]["get"]["eventType"];
|
||||
export type EventTypeApps = RouterOutputs["viewer"]["apps"]["integrations"];
|
||||
export type HostLocation = {
|
||||
id?: string;
|
||||
userId: number;
|
||||
eventTypeId: number;
|
||||
type: EventLocationType["type"];
|
||||
credentialId?: number | null;
|
||||
link?: string | null;
|
||||
address?: string | null;
|
||||
phoneNumber?: string | null;
|
||||
};
|
||||
|
||||
export type Host = {
|
||||
isFixed: boolean;
|
||||
userId: number;
|
||||
@@ -34,6 +45,7 @@ export type Host = {
|
||||
weight: number;
|
||||
scheduleId?: number | null;
|
||||
groupId: string | null;
|
||||
location?: HostLocation | null;
|
||||
};
|
||||
export type TeamMember = {
|
||||
value: string;
|
||||
@@ -177,6 +189,7 @@ export type FormValues = {
|
||||
restrictionScheduleName: string | null;
|
||||
calVideoSettings?: CalVideoSettings;
|
||||
maxActiveBookingPerBookerOfferReschedule: boolean;
|
||||
enablePerHostLocations: boolean;
|
||||
};
|
||||
|
||||
export type LocationFormValues = Pick<FormValues, "id" | "locations" | "bookingFields" | "seatsPerTimeSlot">;
|
||||
|
||||
@@ -713,6 +713,16 @@ export class EventTypeRepository implements IEventTypesRepository {
|
||||
weight: true,
|
||||
scheduleId: true,
|
||||
groupId: true,
|
||||
location: {
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
credentialId: true,
|
||||
link: true,
|
||||
address: true,
|
||||
phoneNumber: true,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
select: {
|
||||
timeZone: true,
|
||||
@@ -720,6 +730,7 @@ export class EventTypeRepository implements IEventTypesRepository {
|
||||
},
|
||||
},
|
||||
},
|
||||
enablePerHostLocations: true,
|
||||
userId: true,
|
||||
price: true,
|
||||
children: {
|
||||
@@ -1013,6 +1024,16 @@ export class EventTypeRepository implements IEventTypesRepository {
|
||||
priority: true,
|
||||
weight: true,
|
||||
scheduleId: true,
|
||||
location: {
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
credentialId: true,
|
||||
link: true,
|
||||
address: true,
|
||||
phoneNumber: true,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
select: {
|
||||
timeZone: true,
|
||||
@@ -1020,6 +1041,7 @@ export class EventTypeRepository implements IEventTypesRepository {
|
||||
},
|
||||
},
|
||||
},
|
||||
enablePerHostLocations: true,
|
||||
userId: true,
|
||||
price: true,
|
||||
children: {
|
||||
@@ -1589,6 +1611,16 @@ export class EventTypeRepository implements IEventTypesRepository {
|
||||
});
|
||||
}
|
||||
|
||||
async findByIdWithTeamId({ id }: { id: number }) {
|
||||
return await this.prismaClient.eventType.findUnique({
|
||||
where: { id },
|
||||
select: {
|
||||
id: true,
|
||||
teamId: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findByIdWithParent(eventTypeId: number) {
|
||||
return this.prismaClient.eventType.findUnique({
|
||||
where: { id: eventTypeId },
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
|
||||
export class HostLocationRepository {
|
||||
constructor(private prismaClient: PrismaClient) {}
|
||||
|
||||
async linkCredential({
|
||||
userId,
|
||||
eventTypeId,
|
||||
credentialId,
|
||||
}: {
|
||||
userId: number;
|
||||
eventTypeId: number;
|
||||
credentialId: number;
|
||||
}) {
|
||||
return await this.prismaClient.hostLocation.update({
|
||||
where: {
|
||||
userId_eventTypeId: {
|
||||
userId,
|
||||
eventTypeId,
|
||||
},
|
||||
},
|
||||
data: {
|
||||
credentialId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async upsertMany(
|
||||
locations: {
|
||||
userId: number;
|
||||
eventTypeId: number;
|
||||
type: string;
|
||||
link: string | null;
|
||||
address: string | null;
|
||||
phoneNumber: string | null;
|
||||
credentialId: number | null;
|
||||
}[]
|
||||
) {
|
||||
return await Promise.all(
|
||||
locations.map((location) =>
|
||||
this.prismaClient.hostLocation.upsert({
|
||||
where: {
|
||||
userId_eventTypeId: {
|
||||
userId: location.userId,
|
||||
eventTypeId: location.eventTypeId,
|
||||
},
|
||||
},
|
||||
create: location,
|
||||
update: {
|
||||
type: location.type,
|
||||
link: location.link,
|
||||
address: location.address,
|
||||
phoneNumber: location.phoneNumber,
|
||||
credentialId: location.credentialId,
|
||||
},
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { AppCategories } from "@calcom/prisma/enums";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { safeCredentialSelect } from "@calcom/prisma/selects/credential";
|
||||
|
||||
export class HostRepository {
|
||||
constructor(private prismaClient: PrismaClient) {}
|
||||
@@ -37,4 +39,133 @@ export class HostRepository {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findHostsWithLocationOptions(eventTypeId: number) {
|
||||
return await this.prismaClient.host.findMany({
|
||||
where: {
|
||||
eventTypeId,
|
||||
},
|
||||
select: {
|
||||
userId: true,
|
||||
isFixed: true,
|
||||
priority: true,
|
||||
location: {
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
credentialId: true,
|
||||
link: true,
|
||||
address: true,
|
||||
phoneNumber: true,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
avatarUrl: true,
|
||||
metadata: true,
|
||||
credentials: {
|
||||
where: {
|
||||
app: {
|
||||
categories: {
|
||||
hasSome: [AppCategories.conferencing, AppCategories.video],
|
||||
},
|
||||
},
|
||||
},
|
||||
select: safeCredentialSelect,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: [{ user: { name: "asc" } }, { priority: "desc" }],
|
||||
});
|
||||
}
|
||||
|
||||
async findHostsWithLocationOptionsPaginated({
|
||||
eventTypeId,
|
||||
cursor,
|
||||
limit = 10,
|
||||
}: {
|
||||
eventTypeId: number;
|
||||
cursor?: number;
|
||||
limit?: number;
|
||||
}) {
|
||||
const hosts = await this.prismaClient.host.findMany({
|
||||
where: {
|
||||
eventTypeId,
|
||||
...(cursor && { userId: { gt: cursor } }),
|
||||
},
|
||||
take: limit + 1,
|
||||
select: {
|
||||
userId: true,
|
||||
isFixed: true,
|
||||
priority: true,
|
||||
location: {
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
credentialId: true,
|
||||
link: true,
|
||||
address: true,
|
||||
phoneNumber: true,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
avatarUrl: true,
|
||||
metadata: true,
|
||||
credentials: {
|
||||
where: {
|
||||
app: {
|
||||
categories: {
|
||||
hasSome: [AppCategories.conferencing, AppCategories.video],
|
||||
},
|
||||
},
|
||||
},
|
||||
select: safeCredentialSelect,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: [{ userId: "asc" }],
|
||||
});
|
||||
|
||||
const hasMore = hosts.length > limit;
|
||||
const items = hasMore ? hosts.slice(0, -1) : hosts;
|
||||
const nextCursor = hasMore ? items[items.length - 1].userId : undefined;
|
||||
|
||||
return { items, nextCursor, hasMore };
|
||||
}
|
||||
|
||||
async findHostsWithConferencingCredentials(eventTypeId: number) {
|
||||
return await this.prismaClient.host.findMany({
|
||||
where: { eventTypeId },
|
||||
select: {
|
||||
userId: true,
|
||||
user: {
|
||||
select: {
|
||||
credentials: {
|
||||
where: {
|
||||
app: {
|
||||
categories: {
|
||||
hasSome: [AppCategories.conferencing, AppCategories.video],
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
appId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user