diff --git a/apps/api/v1/pages/api/slots/_get.ts b/apps/api/v1/pages/api/slots/_get.ts index e4323d0037..16dc7f8aaf 100644 --- a/apps/api/v1/pages/api/slots/_get.ts +++ b/apps/api/v1/pages/api/slots/_get.ts @@ -27,12 +27,13 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { isColdStart = false; } - const { usernameList, ...rest } = req.query; + const { usernameList, isTeamEvent, ...rest } = req.query; + const parsedIsTeamEvent = String(isTeamEvent).toLowerCase() === "true"; let slugs = usernameList; if (!Array.isArray(usernameList)) { slugs = usernameList ? [usernameList] : undefined; } - const input = getScheduleSchema.parse({ usernameList: slugs, ...rest }); + const input = getScheduleSchema.parse({ usernameList: slugs, isTeamEvent: parsedIsTeamEvent, ...rest }); const timeZoneSupported = input.timeZone ? isSupportedTimeZone(input.timeZone) : false; const availableSlots = await getAvailableSlots({ ctx: await createContext({ req, res }), input }); const slotsInProvidedTimeZone = timeZoneSupported diff --git a/apps/web/test/lib/getSchedule.test.ts b/apps/web/test/lib/getSchedule.test.ts index 4946c304f6..d8f87e846c 100644 --- a/apps/web/test/lib/getSchedule.test.ts +++ b/apps/web/test/lib/getSchedule.test.ts @@ -1526,21 +1526,20 @@ describe("getSchedule", () => { }); const scenario = await createBookingScenario( - getScenarioData({ - eventTypes: [ - { - id: 1, - slotInterval: 45, - length: 45, - users: [ - { - id: 101, - }, - ], - }, - ], - organizer, - }) + getScenarioData( + { + eventTypes: [ + { + id: 1, + slotInterval: 45, + length: 45, + userId: 101, + }, + ], + organizer, + }, + { id: org.id } + ) ); const { dateString: plus1DateString } = getDate({ dateIncrement: 1 }); diff --git a/apps/web/test/utils/bookingScenario/bookingScenario.ts b/apps/web/test/utils/bookingScenario/bookingScenario.ts index 7f35c254c9..b186aa8050 100644 --- a/apps/web/test/utils/bookingScenario/bookingScenario.ts +++ b/apps/web/test/utils/bookingScenario/bookingScenario.ts @@ -145,6 +145,7 @@ export type InputEventType = { length?: number; offsetStart?: number; slotInterval?: number; + userId?: number; minimumBookingNotice?: number; /** * These user ids are `ScenarioData["users"]["id"]` @@ -1249,7 +1250,6 @@ export function getScenarioData( ]; }); } - eventTypes.forEach((eventType) => { if ( eventType.users?.filter((eventTypeUser) => { diff --git a/packages/lib/server/repository/user.ts b/packages/lib/server/repository/user.ts index e42e2025c5..924fd3d57f 100644 --- a/packages/lib/server/repository/user.ts +++ b/packages/lib/server/repository/user.ts @@ -175,27 +175,26 @@ export class UserRepository { organization: getParsedTeam(profile.organization), })) : null; - - const where = profiles - ? { - // Get UserIds from profiles - id: { - in: profiles.map((profile) => profile.user.id), - }, - } - : { - username: { - in: usernameList, - }, - ...(orgSlug - ? { - organization: whereClauseForOrgWithSlugOrRequestedSlug(orgSlug), - } - : { - organization: null, - }), - }; - + const where = + profiles && profiles.length > 0 + ? { + // Get UserIds from profiles + id: { + in: profiles.map((profile) => profile.user.id), + }, + } + : { + username: { + in: usernameList, + }, + ...(orgSlug + ? { + organization: whereClauseForOrgWithSlugOrRequestedSlug(orgSlug), + } + : { + organization: null, + }), + }; return { where, profiles }; } diff --git a/packages/trpc/server/routers/viewer/slots/util.ts b/packages/trpc/server/routers/viewer/slots/util.ts index 73c3732d21..1ddc26e403 100644 --- a/packages/trpc/server/routers/viewer/slots/util.ts +++ b/packages/trpc/server/routers/viewer/slots/util.ts @@ -113,6 +113,7 @@ async function getEventTypeId({ organizationDetails ?? { currentOrgDomain: null, isValidOrgDomain: false } ); } + if (!userId && !teamId) throw new TRPCError({ code: "NOT_FOUND" }); const eventType = await prisma.eventType.findFirst({ where: { slug: eventTypeSlug,