Skip to content

Commit

Permalink
fix: getAttributeRoutingConfig find the route based on the chosenRo…
Browse files Browse the repository at this point in the history
…uteId (calcom#17867)

## What does this PR do?

<!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. -->

We were parsing routes based on `eventTypeId` but routes could be pointing to the same event type. This was causing misroutings.

- Fixes #XXXX (GitHub issue number)
- Fixes CAL-XXXX (Linear issue number - should be visible at the bottom of the GitHub issue description)

<!-- Please provide a loom video for visual changes to speed up reviews
 Loom Video: https://www.loom.com/
-->

## Mandatory Tasks (DO NOT REMOVE)

- [x] I have self-reviewed the code (A decent size PR without self-review might be rejected).
- [ ] I have updated the developer docs in /docs if this PR makes changes that would require a [documentation change](https://cal.com/docs). If N/A, write N/A here and check the checkbox.
- [ ] I confirm automated tests are in place that prove my fix is effective or that my feature works.
  • Loading branch information
joeauyeung authored Nov 28, 2024
1 parent 589c1dc commit be2f0f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
5 changes: 4 additions & 1 deletion apps/web/lib/__tests__/getTeamMemberEmailFromCrm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ async function createRoutingFormWithResponse({
},
});

const routeId = v4();

const form = await prismock.app_RoutingForms_Form.create({
data: {
...formData,
Expand All @@ -88,7 +90,7 @@ async function createRoutingFormWithResponse({
id: v4(),
type: "group",
},
id: v4(),
id: routeId,
...route,
})),
user: {
Expand All @@ -101,6 +103,7 @@ async function createRoutingFormWithResponse({

const responseRecord = await prismock.app_RoutingForms_FormResponse.create({
data: {
chosenRouteId: routeId,
response: {},
form: {
connect: {
Expand Down
23 changes: 12 additions & 11 deletions apps/web/lib/getTeamMemberEmailFromCrm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,29 @@ async function getAttributeRoutingConfig(
return data.route.attributeRoutingConfig ?? null;
}
const { routingFormResponseId, eventTypeId } = data;
const routingFormQuery = await prisma.app_RoutingForms_Form.findFirst({

const routingFormResponseQuery = await prisma.app_RoutingForms_FormResponse.findFirst({
where: {
responses: {
some: {
id: routingFormResponseId,
id: routingFormResponseId,
},
include: {
form: {
select: {
routes: true,
},
},
},
select: {
routes: true,
},
});
if (!routingFormQuery || !routingFormQuery?.routes) return null;
const parsedRoutes = routesSchema.safeParse(routingFormQuery.routes);

if (!routingFormResponseQuery || !routingFormResponseQuery?.form.routes) return null;
const parsedRoutes = routesSchema.safeParse(routingFormResponseQuery?.form.routes);

if (!parsedRoutes.success || !parsedRoutes.data) return null;

// Find the route with the attributeRoutingConfig
// FIXME: There could be multiple routes with same action.eventTypeId, we should actually ensure we have the chosenRouteId in here and use that route.
const route = parsedRoutes.data.find((route) => {
if ("action" in route) {
return route.action.eventTypeId === eventTypeId;
return route.id === routingFormResponseQuery.chosenRouteId;
}
});

Expand Down

0 comments on commit be2f0f9

Please sign in to comment.