@@ -20,6 +20,7 @@ import {
2020 WebhookLogRepository ,
2121 WebhookDestinationRepository ,
2222 FailedWebhookRetryRequestsRepository ,
23+ EnvironmentRepository ,
2324} from '@impler/dal' ;
2425
2526import { BaseConsumer } from './base.consumer' ;
@@ -40,6 +41,7 @@ export class SendWebhookDataConsumer extends BaseConsumer {
4041 private emailService : EmailService = getEmailServiceClass ( ) ;
4142 private failedWebhookRetryRequestsRepository : FailedWebhookRetryRequestsRepository =
4243 new FailedWebhookRetryRequestsRepository ( ) ;
44+ private environmentRepository : EnvironmentRepository = new EnvironmentRepository ( ) ;
4345
4446 async message ( message : { content : string } ) {
4547 const data = JSON . parse ( message . content ) as SendWebhookData ;
@@ -91,9 +93,9 @@ export class SendWebhookDataConsumer extends BaseConsumer {
9193
9294 await this . makeResponseEntry ( {
9395 data : response ,
96+ projectId : cachedData . projectId ,
9497 importName : cachedData . name ,
9598 url : cachedData . callbackUrl ,
96- userEmail : cachedData . email ,
9799 retryInterval : cachedData . retryInterval ,
98100 retryCount : cachedData . retryCount ,
99101 allData,
@@ -207,6 +209,7 @@ export class SendWebhookDataConsumer extends BaseConsumer {
207209
208210 return {
209211 _templateId : uploadata . _templateId ,
212+ projectId : templateData . _projectId ,
210213 callbackUrl : webhookDestination ?. callbackUrl ,
211214 chunkSize : webhookDestination ?. chunkSize ,
212215 name : templateData . name ,
@@ -230,22 +233,26 @@ export class SendWebhookDataConsumer extends BaseConsumer {
230233 private async makeResponseEntry ( {
231234 data,
232235 importName,
236+ projectId,
233237 url,
234238 allData,
235- userEmail,
236239 retryInterval,
237240 retryCount,
238241 } : {
239242 data : Partial < WebhookLogEntity > ;
240243 importName : string ;
244+ projectId : string ;
241245 url : string ;
242- userEmail : string ;
243246 retryCount ?: number ;
244247 retryInterval ?: number ;
245248 allData : Record < string , any > ;
246249 } ) {
247250 const webhookLog = await this . webhookLogRepository . create ( data ) ;
248251 if ( data . status === StatusEnum . FAILED ) {
252+ const environment = await this . environmentRepository . getProjectTeamMembers ( projectId ) ;
253+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
254+ // @ts -ignore
255+ const teamMemberEmails = environment . map ( ( teamMember ) => teamMember . _userId . email ) ;
249256 const emailContents = this . emailService . getEmailContent ( {
250257 type : 'ERROR_SENDING_WEBHOOK_DATA' ,
251258 data : {
@@ -256,13 +263,14 @@ export class SendWebhookDataConsumer extends BaseConsumer {
256263 importId : data . _uploadId ,
257264 } ,
258265 } ) ;
259-
260- await this . emailService . sendEmail ( {
261- to : userEmail ,
262- subject : `${ EMAIL_SUBJECT . ERROR_SENDING_WEBHOOK_DATA } ${ importName } ` ,
263- html : emailContents ,
264- from : process . env . ALERT_EMAIL_FROM ,
265- senderName : process . env . EMAIL_FROM_NAME ,
266+ teamMemberEmails . forEach ( async ( email ) => {
267+ await this . emailService . sendEmail ( {
268+ to : email ,
269+ subject : `${ EMAIL_SUBJECT . ERROR_SENDING_WEBHOOK_DATA } ${ importName } ` ,
270+ html : emailContents ,
271+ from : process . env . ALERT_EMAIL_FROM ,
272+ senderName : process . env . EMAIL_FROM_NAME ,
273+ } ) ;
266274 } ) ;
267275
268276 if ( retryCount && retryInterval ) {
0 commit comments