fix: get slot logic for v1 API (#16620)
* fix faulty slug match * Allow team event slot * pass it to getSchedule --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
This commit is contained in:
co-authored by
Keith Williams
parent
a5191d1e5a
commit
e3b478f5b1
@@ -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
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user