-
Notifications
You must be signed in to change notification settings - Fork 15
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
4 changed files
with
104 additions
and
6 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
57 changes: 57 additions & 0 deletions
57
services/API-service/src/api/notification/email/mjml.service.ts
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import mjml2html from 'mjml'; | ||
|
||
import { ContentEventEmail } from '../dto/content-trigger-email.dto'; | ||
import { getMjmlHeader } from './mjml/header'; | ||
|
||
@Injectable() | ||
export class MjmlService { | ||
public getHtmlOutput({ | ||
emailContent, | ||
date, | ||
}: { | ||
emailContent: ContentEventEmail; | ||
date: Date; | ||
}): string { | ||
const { | ||
// disasterType, | ||
disasterTypeLabel, | ||
// indicatorMetadata, | ||
// linkEapSop, | ||
// dataPerEvent, | ||
// mapImageData, | ||
// defaultAdminLevel, | ||
// defaultAdminAreaLabel, | ||
// country, | ||
} = emailContent; | ||
|
||
const header = getMjmlHeader({ | ||
disasterTypeLabel, | ||
nrOfEvents: emailContent.dataPerEvent.length, | ||
sentOnDate: date.toISOString(), | ||
timeZone: 'UTC', | ||
}); | ||
|
||
// const bodyEventList = | ||
// this.emailTemplateService.getMjmlEventListBody(emailContent); | ||
|
||
const emailObject = { | ||
tagName: 'mjml', | ||
attributes: {}, | ||
children: [ | ||
{ | ||
tagName: 'mj-body', | ||
children: [ | ||
{ | ||
tagName: 'mj-column', | ||
children: [header], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
return mjml2html(emailObject).html; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
services/API-service/src/api/notification/email/mjml/header.ts
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export const getMjmlHeader = ({ | ||
disasterTypeLabel, | ||
nrOfEvents, | ||
sentOnDate, | ||
timeZone, | ||
}: { | ||
disasterTypeLabel: string; | ||
nrOfEvents: number; | ||
sentOnDate: string; | ||
timeZone: string; | ||
}): object => { | ||
const titleElement = { | ||
tagName: 'mj-text', | ||
attributes: { 'font-size': '36px', color: '#ffffff', align: 'center' }, | ||
content: `${nrOfEvents} ${disasterTypeLabel} alerts`, | ||
}; | ||
|
||
const subtitleElement = { | ||
tagName: 'mj-text', | ||
attributes: { 'font-size': '16px', color: '#ffffff', align: 'center' }, | ||
content: `IBF alert sent on ${sentOnDate} (${timeZone})`, | ||
}; | ||
|
||
return { | ||
tagName: 'mj-column', | ||
attributes: { | ||
'background-color': '#4f22d7', | ||
}, | ||
children: [titleElement, subtitleElement], | ||
}; | ||
}; |
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