-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<IEmailEnvelope> { | ||
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 || | ||
'[email protected]', | ||
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<IEmailEnvelope> { | ||
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 || | ||
'[email protected]', | ||
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: '', | ||
}); | ||
|