feat: Ports getSchedule to public API (#9254)

* Ports getSchedule to public API

* Typefix
This commit is contained in:
Omar López authored and GitHub committed 2023-05-31 20:46:54 +00:00
1 parent 8618df09e5
commit 290ff79c86
4 files changed
+55 -7

No files matched your search

@@ -7,13 +7,13 @@ export const getScheduleSchema = z
// endTime ISOString
endTime: z.string(),
// Event type ID
eventTypeId: z.number().int().optional(),
eventTypeId: z.coerce.number().int().optional(),
// Event type slug
eventTypeSlug: z.string(),
eventTypeSlug: z.string().optional(),
// invitee timezone
timeZone: z.string().optional(),
// or list of users (for dynamic events)
usernameList: z.array(z.string()).optional(),
usernameList: z.union([z.string(), z.array(z.string())]).optional(),
debug: z.boolean().optional(),
// to handle event types with multiple duration options
duration: z
@@ -21,9 +21,16 @@ export const getScheduleSchema = z
.optional()
.transform((val) => val && parseInt(val)),
})
.transform((val) => {
// Need this so we can pass a single username in the query string form public API
if (val.usernameList) {
val.usernameList = Array.isArray(val.usernameList) ? val.usernameList : [val.usernameList];
}
return val;
})
.refine(
(data) => !!data.eventTypeId || !!data.usernameList,
"Either usernameList or eventTypeId should be filled in."
(data) => !!data.eventTypeId || (!!data.usernameList && !!data.eventTypeSlug),
"You need to either pass an eventTypeId OR an usernameList/eventTypeSlug combination"
);
export const reserveSlotSchema = z
@@ -11,8 +11,7 @@ import isTimeOutOfBounds from "@calcom/lib/isOutOfBounds";
import logger from "@calcom/lib/logger";
import { performance } from "@calcom/lib/server/perfObserver";
import getTimeSlots from "@calcom/lib/slots";
import { availabilityUserSelect } from "@calcom/prisma";
import prisma from "@calcom/prisma";
import prisma, { availabilityUserSelect } from "@calcom/prisma";
import { SchedulingType } from "@calcom/prisma/enums";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
import type { EventBusyDate } from "@calcom/types/Calendar";
@@ -140,6 +139,12 @@ export async function getEventType(input: TGetScheduleInputSchema) {
export async function getDynamicEventType(input: TGetScheduleInputSchema) {
// For dynamic booking, we need to get and update user credentials, schedule and availability in the eventTypeObject as they're required in the new availability logic
if (!input.eventTypeSlug) {
throw new TRPCError({
message: "eventTypeSlug is required for dynamic booking",
code: "BAD_REQUEST",
});
}
const dynamicEventType = getDefaultEvent(input.eventTypeSlug);
const users = await prisma.user.findMany({
where: {