@@ -2,27 +2,40 @@ import { Injectable } from '@nestjs/common';
2
2
import { UserSessionData , WorkflowStatusEnum } from '@novu/shared' ;
3
3
import { NotificationTemplateEntity , NotificationTemplateRepository } from '@novu/dal' ;
4
4
import { GetWorkflowWithPreferencesUseCase , WorkflowWithPreferencesResponseDto } from '@novu/application-generic' ;
5
+ import { SendWebhookMessage } from '../../../webhooks/usecases/send-webhook-message/send-webhook-message.usecase' ;
5
6
import { PatchWorkflowCommand } from './patch-workflow.command' ;
6
7
import { GetWorkflowUseCase } from '../get-workflow' ;
7
8
import { WorkflowResponseDto } from '../../dtos' ;
9
+ import { WebhookEventEnum , WebhookObjectTypeEnum } from '../../../webhooks/dtos/webhook-payload.dto' ;
8
10
9
11
@Injectable ( )
10
12
export class PatchWorkflowUsecase {
11
13
constructor (
12
14
private getWorkflowWithPreferencesUseCase : GetWorkflowWithPreferencesUseCase ,
13
15
private notificationTemplateRepository : NotificationTemplateRepository ,
14
- private getWorkflowUseCase : GetWorkflowUseCase
16
+ private getWorkflowUseCase : GetWorkflowUseCase ,
17
+ private sendWebhookMessage : SendWebhookMessage
15
18
) { }
16
19
17
20
async execute ( command : PatchWorkflowCommand ) : Promise < WorkflowResponseDto > {
18
21
const persistedWorkflow = await this . fetchWorkflow ( command ) ;
19
22
const transientWorkflow = this . patchWorkflowFields ( persistedWorkflow , command ) ;
20
23
await this . persistWorkflow ( transientWorkflow , command . user ) ;
21
24
22
- return await this . getWorkflowUseCase . execute ( {
25
+ const updatedWorkflow = await this . getWorkflowUseCase . execute ( {
23
26
workflowIdOrInternalId : command . workflowIdOrInternalId ,
24
27
user : command . user ,
25
28
} ) ;
29
+
30
+ await this . sendWebhookMessage . execute ( {
31
+ eventType : WebhookEventEnum . WORKFLOW_UPDATED ,
32
+ objectType : WebhookObjectTypeEnum . WORKFLOW ,
33
+ payload : updatedWorkflow ,
34
+ organizationId : command . user . organizationId ,
35
+ environmentId : command . user . environmentId ,
36
+ } ) ;
37
+
38
+ return updatedWorkflow ;
26
39
}
27
40
28
41
private patchWorkflowFields (
0 commit comments