chore: salesforce for Router / Booker atoms and api v2 (#19217)
* wip * small refactor * small refactor * fixup! Merge branch 'main' into enable-salesforce-router-apiv2-atom * crm props * fixup! crm props * bump platform libraries * bump platform libraries
This commit is contained in:
1 parent
3a29327761
commit
486e3a386e
14 files changed
+241
-122
No files matched your search
@@ -30,7 +30,7 @@
|
||||
"@axiomhq/winston": "^1.2.0",
|
||||
"@calcom/platform-constants": "*",
|
||||
"@calcom/platform-enums": "*",
|
||||
"@calcom/platform-libraries": "npm:@calcom/[email protected]5",
|
||||
"@calcom/platform-libraries": "npm:@calcom/[email protected]9",
|
||||
"@calcom/platform-libraries-0.0.2": "npm:@calcom/[email protected]",
|
||||
"@calcom/platform-types": "*",
|
||||
"@calcom/platform-utils": "*",
|
||||
|
||||
@@ -169,4 +169,19 @@ export class CreateBookingInput_2024_04_15 {
|
||||
label?: string | undefined;
|
||||
}
|
||||
>;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiPropertyOptional()
|
||||
teamMemberEmail?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiPropertyOptional()
|
||||
crmAppSlug?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiPropertyOptional()
|
||||
crmOwnerRecordType?: string;
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
import { API_VERSIONS_VALUES } from "@/lib/api-versions";
|
||||
import { TeamsEventTypesRepository } from "@/modules/teams/event-types/teams-event-types.repository";
|
||||
import { Controller, Req, NotFoundException, Param, Post, Body } from "@nestjs/common";
|
||||
import { ApiTags as DocsTags, ApiExcludeController as DocsExcludeController } from "@nestjs/swagger";
|
||||
import { Request } from "express";
|
||||
|
||||
import { getRoutedUrl } from "@calcom/platform-libraries";
|
||||
import {
|
||||
getRoutedUrl,
|
||||
getTeamMemberEmailForResponseOrContactUsingUrlQuery,
|
||||
} from "@calcom/platform-libraries";
|
||||
import { ApiResponse } from "@calcom/platform-types";
|
||||
|
||||
@Controller({
|
||||
@@ -13,6 +17,8 @@ import { ApiResponse } from "@calcom/platform-types";
|
||||
@DocsTags("Router controller")
|
||||
@DocsExcludeController(true)
|
||||
export class RouterController {
|
||||
constructor(private readonly teamsEventTypesRepository: TeamsEventTypesRepository) {}
|
||||
|
||||
@Post("/forms/:formId/submit")
|
||||
async getRoutingFormResponse(
|
||||
@Req() request: Request,
|
||||
@@ -27,13 +33,54 @@ export class RouterController {
|
||||
}
|
||||
|
||||
if (routedUrlData?.redirect?.destination) {
|
||||
return { status: "success", data: routedUrlData?.redirect?.destination, redirect: true };
|
||||
return this.handleRedirect(routedUrlData.redirect.destination);
|
||||
}
|
||||
|
||||
if (routedUrlData?.props) {
|
||||
return { status: "success", data: { message: routedUrlData?.props?.message ?? "" }, redirect: false };
|
||||
return { status: "success", data: { message: routedUrlData.props.message ?? "" }, redirect: false };
|
||||
}
|
||||
|
||||
return { status: "success", data: { message: "No Route nor custom message found." }, redirect: false };
|
||||
}
|
||||
|
||||
private async handleRedirect(destination: string): Promise<ApiResponse<unknown> & { redirect: boolean }> {
|
||||
const routingUrl = new URL(destination);
|
||||
const routingSearchParams = routingUrl.searchParams;
|
||||
if (
|
||||
routingSearchParams.get("cal.action") === "eventTypeRedirectUrl" &&
|
||||
routingSearchParams.has("email") &&
|
||||
routingSearchParams.has("cal.teamId") &&
|
||||
!routingSearchParams.has("cal.skipContactOwner")
|
||||
) {
|
||||
return this.handleRedirectWithContactOwner(routingUrl, routingSearchParams);
|
||||
}
|
||||
|
||||
return { status: "success", data: destination, redirect: true };
|
||||
}
|
||||
|
||||
private async handleRedirectWithContactOwner(
|
||||
routingUrl: URL,
|
||||
routingSearchParams: URLSearchParams
|
||||
): Promise<ApiResponse<unknown> & { redirect: boolean }> {
|
||||
const pathNameParams = routingUrl.pathname.split("/");
|
||||
const eventTypeSlug = pathNameParams[pathNameParams.length - 1];
|
||||
const teamId = Number(routingSearchParams.get("cal.teamId"));
|
||||
const eventTypeData = this.teamsEventTypesRepository.getTeamEventTypeBySlug(teamId, eventTypeSlug, 3);
|
||||
|
||||
// get the salesforce record owner email for the email given as a form response.
|
||||
const {
|
||||
email: teamMemberEmail,
|
||||
recordType: crmOwnerRecordType,
|
||||
crmAppSlug,
|
||||
} = await getTeamMemberEmailForResponseOrContactUsingUrlQuery({
|
||||
query: Object.fromEntries(routingSearchParams),
|
||||
eventData: eventTypeData,
|
||||
});
|
||||
|
||||
Boolean(teamMemberEmail) && routingUrl.searchParams.set("cal.teamMemberEmail", teamMemberEmail);
|
||||
Boolean(crmOwnerRecordType) && routingUrl.searchParams.set("cal.crmOwnerRecordType", crmOwnerRecordType);
|
||||
Boolean(crmAppSlug) && routingUrl.searchParams.set("cal.crmAppSlug", crmAppSlug);
|
||||
|
||||
return { status: "success", data: routingUrl.toString(), redirect: true };
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import { PrismaModule } from "@/modules/prisma/prisma.module";
|
||||
import { RouterController } from "@/modules/router/controllers/router.controller";
|
||||
import { TeamsEventTypesRepository } from "@/modules/teams/event-types/teams-event-types.repository";
|
||||
import { Module } from "@nestjs/common";
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
providers: [],
|
||||
providers: [TeamsEventTypesRepository],
|
||||
exports: [],
|
||||
controllers: [RouterController],
|
||||
})
|
||||
|
||||
@@ -5593,6 +5593,14 @@
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "teamMemberEmail",
|
||||
"required": false,
|
||||
"in": "query",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
||||
Reference in new issue
Block a user