1
1
import { Injectable , Logger } from '@nestjs/common' ;
2
2
import { ModuleRef } from '@nestjs/core' ;
3
- import inlineCss from 'inline-css' ;
4
3
import { addBreadcrumb } from '@sentry/node' ;
4
+ import inlineCss from 'inline-css' ;
5
5
6
6
import {
7
- MessageRepository ,
8
- SubscriberRepository ,
7
+ CompileEmailTemplate ,
8
+ CompileEmailTemplateCommand ,
9
+ CreateExecutionDetails ,
10
+ CreateExecutionDetailsCommand ,
11
+ DetailEnum ,
12
+ FeatureFlagsService ,
13
+ GetNovuProviderCredentials ,
14
+ InstrumentUsecase ,
15
+ MailFactory ,
16
+ SelectIntegration ,
17
+ SelectVariant ,
18
+ } from '@novu/application-generic' ;
19
+ import {
20
+ EnvironmentEntity ,
9
21
EnvironmentRepository ,
10
22
IntegrationEntity ,
11
- MessageEntity ,
12
23
LayoutRepository ,
13
- EnvironmentEntity ,
24
+ MessageEntity ,
25
+ MessageRepository ,
14
26
OrganizationEntity ,
27
+ SubscriberRepository ,
15
28
UserEntity ,
16
29
} from '@novu/dal' ;
30
+ import { EmailOutput } from '@novu/framework/internal' ;
17
31
import {
18
32
ChannelTypeEnum ,
19
33
EmailProviderIdEnum ,
20
34
ExecutionDetailsSourceEnum ,
21
35
ExecutionDetailsStatusEnum ,
36
+ FeatureFlagsKeysEnum ,
22
37
IAttachmentOptions ,
23
38
IEmailOptions ,
24
- FeatureFlagsKeysEnum ,
25
39
} from '@novu/shared' ;
26
- import {
27
- InstrumentUsecase ,
28
- DetailEnum ,
29
- SelectIntegration ,
30
- CompileEmailTemplate ,
31
- CompileEmailTemplateCommand ,
32
- MailFactory ,
33
- GetNovuProviderCredentials ,
34
- SelectVariant ,
35
- CreateExecutionDetails ,
36
- CreateExecutionDetailsCommand ,
37
- FeatureFlagsService ,
38
- } from '@novu/application-generic' ;
39
- import { EmailOutput } from '@novu/framework/internal' ;
40
40
41
- import { SendMessageCommand } from './send-message.command' ;
42
- import { SendMessageBase } from './send-message.base' ;
43
41
import { PlatformException } from '../../../shared/utils' ;
44
42
import { SendMessageResult } from './send-message-type.usecase' ;
43
+ import { SendMessageBase } from './send-message.base' ;
44
+ import { SendMessageCommand } from './send-message.command' ;
45
45
46
46
const LOG_CONTEXT = 'SendMessageEmail' ;
47
47
@@ -76,6 +76,8 @@ export class SendMessageEmail extends SendMessageBase {
76
76
@InstrumentUsecase ( )
77
77
public async execute ( command : SendMessageCommand ) : Promise < SendMessageResult > {
78
78
let integration : IntegrationEntity | undefined ;
79
+ const { subscriber } = command . compileContext ;
80
+ const email = command . overrides ?. email ?. toRecipient || subscriber . email ;
79
81
80
82
const overrideSelectedIntegration = command . overrides ?. email ?. integrationIdentifier ;
81
83
try {
@@ -84,16 +86,23 @@ export class SendMessageEmail extends SendMessageBase {
84
86
environmentId : command . environmentId ,
85
87
channelType : ChannelTypeEnum . EMAIL ,
86
88
userId : command . userId ,
89
+ recipientEmail : email ,
87
90
identifier : overrideSelectedIntegration as string ,
88
91
filterData : {
89
92
tenant : command . job . tenant ,
90
93
} ,
91
94
} ) ;
92
95
} catch ( e ) {
96
+ let detailEnum = DetailEnum . LIMIT_PASSED_NOVU_INTEGRATION ;
97
+
98
+ if ( e . message . includes ( 'does not match the current logged-in user' ) ) {
99
+ detailEnum = DetailEnum . SUBSCRIBER_NOT_MEMBER_OF_ORGANIZATION ;
100
+ }
101
+
93
102
await this . createExecutionDetails . execute (
94
103
CreateExecutionDetailsCommand . create ( {
95
104
...CreateExecutionDetailsCommand . getDetailsFromJob ( command . job ) ,
96
- detail : DetailEnum . LIMIT_PASSED_NOVU_INTEGRATION ,
105
+ detail : detailEnum ,
97
106
source : ExecutionDetailsSourceEnum . INTERNAL ,
98
107
status : ExecutionDetailsStatusEnum . FAILED ,
99
108
raw : JSON . stringify ( { message : e . message } ) ,
@@ -113,9 +122,6 @@ export class SendMessageEmail extends SendMessageBase {
113
122
if ( ! step ) throw new PlatformException ( 'Email channel step not found' ) ;
114
123
if ( ! step . template ) throw new PlatformException ( 'Email channel template not found' ) ;
115
124
116
- const { subscriber } = command . compileContext ;
117
- const email = command . overrides ?. email ?. toRecipient || subscriber . email ;
118
-
119
125
addBreadcrumb ( {
120
126
message : 'Sending Email' ,
121
127
} ) ;
0 commit comments