Skip to content

Commit

Permalink
update logic of how to handle update of event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoMruz committed Aug 3, 2023
1 parent 727da25 commit 2a7f5c2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
28 changes: 24 additions & 4 deletions src/helpers/event-handler.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,34 @@ function makeFromGraphQLToApiEventHandlerAction(eventHandlerAction: EventHandler
};
}

export function makeFromGraphQLToApiEventHandler(eventHandler: EventHandlerGraphQL): ApiEventHandler {
export function makeFromGraphQLToApiEventHandler(
eventHandler: EventHandlerGraphQL,
oldEventHandler: ApiEventHandler | null = null,
): ApiEventHandler {
if (oldEventHandler == null) {
return {
name: eventHandler.name,
event: eventHandler.event,
actions: eventHandler.actions.map(makeFromGraphQLToApiEventHandlerAction),
condition: eventHandler.condition || undefined,
active: eventHandler.isActive || undefined,
evaluatorType: eventHandler.evaluatorType || undefined,
};
}

return {
name: eventHandler.name,
event: eventHandler.event,
active: eventHandler.isActive || undefined,
condition: eventHandler.condition || undefined,
actions: eventHandler.actions.map(makeFromGraphQLToApiEventHandlerAction),
evaluatorType: eventHandler.evaluatorType || undefined,
...(eventHandler.condition == null
? { condition: oldEventHandler.condition || undefined }
: { condition: eventHandler.condition }),
...(eventHandler.isActive == null
? { active: oldEventHandler.active || undefined }
: { active: eventHandler.isActive }),
...(eventHandler.evaluatorType == null
? { evaluatorType: oldEventHandler.evaluatorType || undefined }
: { evaluatorType: eventHandler.evaluatorType }),
};
}

Expand Down
30 changes: 18 additions & 12 deletions src/schema/event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,29 @@ export const UpdateEventHandlerMutation = mutationField('updateEventHandler', {
if (input.actions == null || input.actions.length === 0) {
await conductorAPI.updateEventHandler(config.conductorApiURL, {
...oldEventHandler,
...makeFromGraphQLToApiEventHandler({
...input,
actions: [],
name,
event,
}),
...makeFromGraphQLToApiEventHandler(
{
...input,
actions: [],
name,
event,
},
oldEventHandler,
),
actions: oldEventHandler.actions,
});
} else {
await conductorAPI.updateEventHandler(config.conductorApiURL, {
...oldEventHandler,
...makeFromGraphQLToApiEventHandler({
...input,
actions: input.actions,
name,
event,
}),
...makeFromGraphQLToApiEventHandler(
{
...input,
actions: input.actions,
name,
event,
},
oldEventHandler,
),
});
}

Expand Down

0 comments on commit 2a7f5c2

Please sign in to comment.