Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: productivity email order #8573

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 45 additions & 45 deletions src/lib/services/email-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
Expand All @@ -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,
),
);
Expand All @@ -593,7 +593,7 @@ export class EmailService {
from: this.sender,
to: userEmail,
bcc: '',
subject: PRODUCTIVITY_REPORT,
subject: ORDER_ENVIRONMENTS_SUBJECT,
html: '',
text: '',
});
Expand Down
Loading