feat: routing forms integration for booker atom (#18726)
* update booker atom for routing form * remove logs * hide routing form properties from docs * fixup * add comments to explain why certain fields are not defined for routing forms in v2 * chore: routing for handler return team and org id * bump libraries platform * fixup! bump libraries platform * chore: get routing form params to embed * logs to remove * fix import path * chore: handle routing form params in booker embed * wip need router api v2 endpoint * resolve merge conflicts * fixup * fixup! Merge branch 'main' into remove-redirect-on-success-for-platform * fixup! fixup! Merge branch 'main' into remove-redirect-on-success-for-platform * router atom * fix libraries version * cleanup * remove console logs * bump libraries --------- Co-authored-by: Morgan Vernay <morgan@cal.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
This commit is contained in:
co-authored by
Morgan Vernay
Morgan
parent
9608669f98
commit
8615ccb1aa
@@ -1,7 +1,7 @@
|
||||
import { API_VERSIONS_VALUES } from "@/lib/api-versions";
|
||||
import { Controller, Get, Req, NotFoundException, Res, Query, Param } from "@nestjs/common";
|
||||
import { Controller, Req, NotFoundException, Param, Post, Body } from "@nestjs/common";
|
||||
import { ApiTags as DocsTags, ApiExcludeController as DocsExcludeController } from "@nestjs/swagger";
|
||||
import { Request, Response } from "express";
|
||||
import { Request } from "express";
|
||||
|
||||
import { getRoutedUrl } from "@calcom/platform-libraries";
|
||||
import { ApiResponse } from "@calcom/platform-types";
|
||||
@@ -13,27 +13,27 @@ import { ApiResponse } from "@calcom/platform-types";
|
||||
@DocsTags("Router controller")
|
||||
@DocsExcludeController(true)
|
||||
export class RouterController {
|
||||
@Get("/forms/:formId")
|
||||
@Post("/forms/:formId/submit")
|
||||
async getRoutingFormResponse(
|
||||
@Req() request: Request,
|
||||
@Res() res: Response,
|
||||
@Param("formId") formId: string,
|
||||
@Query() query: Record<string, string>
|
||||
): Promise<void | ApiResponse<unknown>> {
|
||||
const routedUrlData = await getRoutedUrl({ req: request, query: { ...query, form: formId } });
|
||||
@Body() body?: Record<string, string>
|
||||
): Promise<void | (ApiResponse<unknown> & { redirect: boolean })> {
|
||||
const params = Object.fromEntries(new URLSearchParams(body ?? {}));
|
||||
const routedUrlData = await getRoutedUrl({ req: request, query: { ...params, form: formId } });
|
||||
|
||||
if (routedUrlData?.notFound) {
|
||||
throw new NotFoundException("Route not found. Please check the provided form parameter.");
|
||||
}
|
||||
|
||||
if (routedUrlData?.redirect?.destination) {
|
||||
return res.redirect(307, routedUrlData.redirect.destination);
|
||||
return { status: "success", data: routedUrlData?.redirect?.destination, redirect: true };
|
||||
}
|
||||
|
||||
if (routedUrlData?.props) {
|
||||
return { status: "success", data: routedUrlData.props };
|
||||
return { status: "success", data: { message: routedUrlData?.props?.message ?? "" }, redirect: false };
|
||||
}
|
||||
|
||||
return { status: "success", data: "route nor custom message found" };
|
||||
return { status: "success", data: { message: "No Route nor custom message found." }, redirect: false };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user