From 3bd0f62d79275d6650e30af7917cac7daa86a6e0 Mon Sep 17 00:00:00 2001 From: kwasniew Date: Tue, 29 Oct 2024 13:33:26 +0100 Subject: [PATCH] fix: productivity email order --- src/lib/services/email-service.ts | 90 +++++++++++++++---------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/lib/services/email-service.ts b/src/lib/services/email-service.ts index b46846c593a7..c10c2ff667c9 100644 --- a/src/lib/services/email-service.ts +++ b/src/lib/services/email-service.ts @@ -461,50 +461,59 @@ export class EmailService { }); } - async sendOrderEnvironmentEmail( + async sendProductivityReportEmail( userEmail: string, - customerId: string, - environments: OrderEnvironmentData[], + userName: string, + metrics: { + health: number; + flagsCreated: number; + productionUpdates: number; + }, ): Promise { if (this.configured()) { const context = { + userName, userEmail, - customerId, - environments: environments.map((data) => ({ - name: this.stripSpecialCharacters(data.name), - type: this.stripSpecialCharacters(data.type), - })), + ...metrics, + unleashUrl: this.config.server.unleashUrl, }; + const template = 'productivity-report'; + const bodyHtml = await this.compileTemplate( - 'order-environments', + template, TemplateFormat.HTML, context, ); const bodyText = await this.compileTemplate( - 'order-environments', + template, TemplateFormat.PLAIN, context, ); - const email = { + const email: IEmailEnvelope = { from: this.sender, to: userEmail, - bcc: - process.env.ORDER_ENVIRONMENTS_BCC || - 'pro-sales@getunleash.io', - subject: ORDER_ENVIRONMENTS_SUBJECT, + bcc: '', + subject: PRODUCTIVITY_REPORT, html: bodyHtml, text: bodyText, + attachments: [ + this.resolveTemplateAttachment( + template, + 'unleash-logo.png', + 'unleashLogo', + ), + ], }; process.nextTick(() => { this.mailer!.sendMail(email).then( () => this.logger.info( - 'Successfully sent order environments email', + 'Successfully sent productivity report email', ), (e) => this.logger.warn( - 'Failed to send order environments email', + 'Failed to send productivity report email', e, ), ); @@ -519,66 +528,57 @@ export class EmailService { from: this.sender, to: userEmail, bcc: '', - subject: ORDER_ENVIRONMENTS_SUBJECT, + subject: PRODUCTIVITY_REPORT, html: '', text: '', }); }); } - async sendProductivityReportEmail( - userName: string, + async sendOrderEnvironmentEmail( userEmail: string, - metrics: { - health: number; - flagsCreated: number; - productionUpdates: number; - }, + customerId: string, + environments: OrderEnvironmentData[], ): Promise { if (this.configured()) { const context = { - userName, userEmail, - ...metrics, - unleashUrl: this.config.server.unleashUrl, + customerId, + environments: environments.map((data) => ({ + name: this.stripSpecialCharacters(data.name), + type: this.stripSpecialCharacters(data.type), + })), }; - const template = 'productivity-report'; - const bodyHtml = await this.compileTemplate( - template, + 'order-environments', TemplateFormat.HTML, context, ); const bodyText = await this.compileTemplate( - template, + 'order-environments', TemplateFormat.PLAIN, context, ); - const email: IEmailEnvelope = { + const email = { from: this.sender, to: userEmail, - bcc: '', - subject: PRODUCTIVITY_REPORT, + bcc: + process.env.ORDER_ENVIRONMENTS_BCC || + 'pro-sales@getunleash.io', + subject: ORDER_ENVIRONMENTS_SUBJECT, html: bodyHtml, text: bodyText, - attachments: [ - this.resolveTemplateAttachment( - template, - 'unleash-logo.png', - 'unleashLogo', - ), - ], }; process.nextTick(() => { this.mailer!.sendMail(email).then( () => this.logger.info( - 'Successfully sent productivity report email', + 'Successfully sent order environments email', ), (e) => this.logger.warn( - 'Failed to send productivity report email', + 'Failed to send order environments email', e, ), ); @@ -593,7 +593,7 @@ export class EmailService { from: this.sender, to: userEmail, bcc: '', - subject: PRODUCTIVITY_REPORT, + subject: ORDER_ENVIRONMENTS_SUBJECT, html: '', text: '', });