Skip to content

Scheduling infrastructure for absolutely everyone.

fix: `getAttributeRoutingConfig` find the route based on the chosenRouteId (#17867)

Joe Au-Yeungbe2f0f986e81
diff --git a/apps/web/lib/__tests__/getTeamMemberEmailFromCrm.test.ts b/apps/web/lib/__tests__/getTeamMemberEmailFromCrm.test.ts
index aded368c300..a1337a6c044 100644
--- a/apps/web/lib/__tests__/getTeamMemberEmailFromCrm.test.ts
+++ b/apps/web/lib/__tests__/getTeamMemberEmailFromCrm.test.ts
@@ -79,6 +79,8 @@ async function createRoutingFormWithResponse({
},
});
+ const routeId = v4();
+
const form = await prismock.app_RoutingForms_Form.create({
data: {
...formData,
@@ -88,7 +90,7 @@ async function createRoutingFormWithResponse({
id: v4(),
type: "group",
},
- id: v4(),
+ id: routeId,
...route,
})),
user: {
@@ -101,6 +103,7 @@ async function createRoutingFormWithResponse({
const responseRecord = await prismock.app_RoutingForms_FormResponse.create({
data: {
+ chosenRouteId: routeId,
response: {},
form: {
connect: {
diff --git a/apps/web/lib/getTeamMemberEmailFromCrm.ts b/apps/web/lib/getTeamMemberEmailFromCrm.ts
index 3237cbcc0a6..0abc54e904c 100644
--- a/apps/web/lib/getTeamMemberEmailFromCrm.ts
+++ b/apps/web/lib/getTeamMemberEmailFromCrm.ts
@@ -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;
}
});