From 7154349e9ef09aa8d26fd6493dd68ef6a46c31dc Mon Sep 17 00:00:00 2001 From: Leo Giovanetti Date: Fri, 15 Sep 2023 13:06:56 -0300 Subject: [PATCH] fix: org username check for dynamic and signup (#11390) --- packages/app-store/salesforce/lib/CalendarService.ts | 1 - packages/lib/validateUsername.ts | 4 +++- packages/trpc/server/routers/viewer/slots/util.ts | 11 +++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/app-store/salesforce/lib/CalendarService.ts b/packages/app-store/salesforce/lib/CalendarService.ts index ab09fff1e7..4b16bb4c4d 100644 --- a/packages/app-store/salesforce/lib/CalendarService.ts +++ b/packages/app-store/salesforce/lib/CalendarService.ts @@ -196,7 +196,6 @@ export default class SalesforceCalendarService implements Calendar { } async createEvent(event: CalendarEvent): Promise { - debugger; const contacts = await this.salesforceContactSearch(event); if (contacts.length) { if (contacts.length == event.attendees.length) { diff --git a/packages/lib/validateUsername.ts b/packages/lib/validateUsername.ts index 12acb7572a..74687725d6 100644 --- a/packages/lib/validateUsername.ts +++ b/packages/lib/validateUsername.ts @@ -9,7 +9,9 @@ export const validateUsername = async (username: string, email: string, organiza where: { ...(organizationId ? { organizationId } : {}), OR: [ - { username }, + // When inviting to org, invited user gets created with username now, so in an org context we + // can't check for username as it will exist on signup + ...(!organizationId ? [{ username }] : [{}]), { AND: [ { email }, diff --git a/packages/trpc/server/routers/viewer/slots/util.ts b/packages/trpc/server/routers/viewer/slots/util.ts index 61d5d5cac3..38062a6bc9 100644 --- a/packages/trpc/server/routers/viewer/slots/util.ts +++ b/packages/trpc/server/routers/viewer/slots/util.ts @@ -202,7 +202,11 @@ export async function getEventType( }; } -export async function getDynamicEventType(input: TGetScheduleInputSchema) { +export async function getDynamicEventType( + input: TGetScheduleInputSchema, + organizationDetails: { currentOrgDomain: string | null; isValidOrgDomain: boolean } +) { + const { currentOrgDomain, isValidOrgDomain } = organizationDetails; // 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({ @@ -220,6 +224,7 @@ export async function getDynamicEventType(input: TGetScheduleInputSchema) { ? [input.usernameList] : [], }, + organization: isValidOrgDomain && currentOrgDomain ? getSlugOrRequestedSlug(currentOrgDomain) : null, }, select: { allowDynamicBooking: true, @@ -246,7 +251,9 @@ export function getRegularOrDynamicEventType( organizationDetails: { currentOrgDomain: string | null; isValidOrgDomain: boolean } ) { const isDynamicBooking = input.usernameList && input.usernameList.length > 1; - return isDynamicBooking ? getDynamicEventType(input) : getEventType(input, organizationDetails); + return isDynamicBooking + ? getDynamicEventType(input, organizationDetails) + : getEventType(input, organizationDetails); } export async function getAvailableSlots({ input, ctx }: GetScheduleOptions) {