@@ -14,6 +14,7 @@ import {
14
14
UpdateWorkflowCommand ,
15
15
UpsertControlValuesCommand ,
16
16
UpsertControlValuesUseCase ,
17
+ SendWebhookMessage ,
17
18
} from '@novu/application-generic' ;
18
19
import {
19
20
ControlSchemas ,
@@ -26,6 +27,8 @@ import {
26
27
ControlValuesLevelEnum ,
27
28
DEFAULT_WORKFLOW_PREFERENCES ,
28
29
slugify ,
30
+ WebhookEventEnum ,
31
+ WebhookObjectTypeEnum ,
29
32
WorkflowCreationSourceEnum ,
30
33
WorkflowOriginEnum ,
31
34
WorkflowTypeEnum ,
@@ -37,8 +40,6 @@ import { BuildStepIssuesUsecase } from '../build-step-issues/build-step-issues.u
37
40
import { GetWorkflowCommand , GetWorkflowUseCase } from '../get-workflow' ;
38
41
import { UpsertStepDataCommand , UpsertWorkflowCommand } from './upsert-workflow.command' ;
39
42
import { StepIssuesDto , WorkflowResponseDto } from '../../dtos' ;
40
- import { SendWebhookMessage } from '../../../webhooks/usecases/send-webhook-message/send-webhook-message.usecase' ;
41
- import { WebhookEventEnum , WebhookObjectTypeEnum } from '../../../webhooks/dtos/webhook-payload.dto' ;
42
43
43
44
@Injectable ( )
44
45
export class UpsertWorkflowUseCase {
@@ -94,13 +95,28 @@ export class UpsertWorkflowUseCase {
94
95
} )
95
96
) ;
96
97
97
- await this . sendWebhookMessage . execute ( {
98
- eventType : WebhookEventEnum . WORKFLOW_UPDATED ,
99
- objectType : WebhookObjectTypeEnum . WORKFLOW ,
100
- payload : updatedWorkflow ,
101
- organizationId : command . user . organizationId ,
102
- environmentId : command . user . environmentId ,
103
- } ) ;
98
+ if ( existingWorkflow ) {
99
+ await this . sendWebhookMessage . execute ( {
100
+ eventType : WebhookEventEnum . WORKFLOW_UPDATED ,
101
+ objectType : WebhookObjectTypeEnum . WORKFLOW ,
102
+ payload : {
103
+ object : updatedWorkflow ,
104
+ previousObject : existingWorkflow ,
105
+ } ,
106
+ organizationId : command . user . organizationId ,
107
+ environmentId : command . user . environmentId ,
108
+ } ) ;
109
+ } else {
110
+ await this . sendWebhookMessage . execute ( {
111
+ eventType : WebhookEventEnum . WORKFLOW_CREATED ,
112
+ objectType : WebhookObjectTypeEnum . WORKFLOW ,
113
+ payload : {
114
+ object : updatedWorkflow ,
115
+ } ,
116
+ organizationId : command . user . organizationId ,
117
+ environmentId : command . user . environmentId ,
118
+ } ) ;
119
+ }
104
120
105
121
return updatedWorkflow ;
106
122
}
0 commit comments