Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
fix: updating workflow with new step and new active event type (calco…
Browse files Browse the repository at this point in the history
…m#12592)

* correctly filter event types to avoid null values

* clean up all filters

* re-add reverted fix

---------

Co-authored-by: CarinaWolli <[email protected]>
  • Loading branch information
CarinaWolli and CarinaWolli authored Nov 29, 2023
1 parent ea8437b commit d0f7085
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions packages/trpc/server/routers/viewer/workflows/update.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,15 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
)
.flat();

const newActiveEventTypes = activeOn.filter((eventType) => {
if (
const newActiveEventTypes = activeOn.filter(
(eventType) =>
!oldActiveOnEventTypes ||
!oldActiveOnEventTypes
.map((oldEventType) => {
return oldEventType.eventTypeId;
})
.includes(eventType)
) {
return eventType;
}
});
);

//check if new event types belong to user or team
for (const newEventTypeId of newActiveEventTypes) {
Expand Down Expand Up @@ -177,11 +174,9 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
}

//remove all scheduled Email and SMS reminders for eventTypes that are not active any more
const removedEventTypes = oldActiveOnEventTypeIds.filter((eventTypeId) => {
if (!activeOnWithChildren.includes(eventTypeId)) {
return eventTypeId;
}
});
const removedEventTypes = oldActiveOnEventTypeIds.filter(
(eventTypeId) => !activeOnWithChildren.includes(eventTypeId)
);

const remindersToDeletePromise: Prisma.PrismaPromise<
{
Expand Down Expand Up @@ -471,11 +466,9 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
},
});
//cancel all reminders of step and create new ones (not for newEventTypes)
const remindersToUpdate = remindersFromStep.filter((reminder) => {
if (reminder.booking?.eventTypeId && !newEventTypes.includes(reminder.booking?.eventTypeId)) {
return reminder;
}
});
const remindersToUpdate = remindersFromStep.filter(
(reminder) => reminder.booking?.eventTypeId && !newEventTypes.includes(reminder.booking?.eventTypeId)
);

//cancel all workflow reminders from steps that were edited
// FIXME: async calls into ether
Expand All @@ -488,11 +481,10 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
deleteScheduledWhatsappReminder(reminder.id, reminder.referenceId);
}
});
const eventTypesToUpdateReminders = activeOn.filter((eventTypeId) => {
if (!newEventTypes.includes(eventTypeId)) {
return eventTypeId;
}
});

const eventTypesToUpdateReminders = activeOn.filter(
(eventTypeId) => !newEventTypes.includes(eventTypeId)
);
if (
eventTypesToUpdateReminders &&
(trigger === WorkflowTriggerEvents.BEFORE_EVENT || trigger === WorkflowTriggerEvents.AFTER_EVENT)
Expand Down Expand Up @@ -629,11 +621,9 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
});

if (addedSteps) {
const eventTypesToCreateReminders = activeOn.map((activeEventType) => {
if (activeEventType && !newEventTypes.includes(activeEventType)) {
return activeEventType;
}
});
const eventTypesToCreateReminders = activeOn.filter(
(activeEventType) => activeEventType && !newEventTypes.includes(activeEventType)
);
const promiseAddedSteps = addedSteps.map(async (step) => {
if (step) {
const { senderName, ...newStep } = step;
Expand Down

0 comments on commit d0f7085

Please sign in to comment.