Skip to content

Commit

Permalink
fix: productivity email order
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Oct 29, 2024
1 parent cb6b776 commit 3bd0f62
Showing 1 changed file with 45 additions and 45 deletions.
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

0 comments on commit 3bd0f62

Please sign in to comment.