Skip to content

Commit 6b34725

Browse files
committed
feat(shared): adiciona render para template de e-mail
1 parent afcb4ca commit 6b34725

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
<h2>{{value}}</h2>
3+
</div>

packages/account/domain/src/server/use-cases/send-user-code.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class SendUserCodeUseCase implements UseCase<string, ResponseMessage> {
2424

2525
const mail = createMail(
2626
user.contact.email,
27+
// render('user-code.html', code)
2728
`<h2>${code.value}</h2>`,
2829
`Código de autenticação`
2930
);
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from './templates';
12
export * from './providers';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './render';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { readFileSync } from 'node:fs';
2+
import { join } from 'node:path';
3+
4+
type Filename = `${string}.html`;
5+
6+
type Context = Record<string, unknown>;
7+
8+
/**
9+
* O template deve estar no diretório `apps/server/src/assets/templates/`
10+
* O contexto deve satisfazer aos valores {{property}} como no template
11+
*/
12+
export const render = <T extends Context>(file: Filename, context: T) => {
13+
const template = readFileSync(join(__dirname, 'assets', 'templates', file));
14+
return template.toString('utf-8').replace(/\{\{(\w+)\}\}/g, (_, key) => {
15+
return context[key] ? String(context[key]) : '';
16+
});
17+
};

0 commit comments

Comments
 (0)