| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 32 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { Injectable } from '@nestjs/common'; |
||
| 2 | import { IMail } from 'src/Application/IMail'; |
||
| 3 | import { IMailer } from 'src/Application/IMailer'; |
||
| 4 | import { send, setApiKey } from '@sendgrid/mail'; |
||
| 5 | import { ConfigService } from '@nestjs/config'; |
||
| 6 | |||
| 7 | @Injectable() |
||
| 8 | export class MailerAdapter implements IMailer { |
||
| 9 | constructor( |
||
| 10 | private readonly configService: ConfigService |
||
| 11 | ) {} |
||
| 12 | |||
| 13 | public async send(mail: IMail): Promise<void> { |
||
| 14 | const baseUrl = this.configService.get<string>('BASE_URL'); |
||
| 15 | |||
| 16 | try { |
||
| 17 | setApiKey(this.configService.get<string>('SENDGRID_API_KEY')); |
||
| 18 | await send({ |
||
| 19 | to: mail.to, |
||
| 20 | from: this.configService.get<string>('MAIL_SENDER'), |
||
| 21 | templateId: mail.templateId, |
||
| 22 | dynamicTemplateData: { |
||
| 23 | ...mail.payload, |
||
| 24 | baseUrl |
||
| 25 | } |
||
| 26 | }); |
||
| 27 | } catch (error) { |
||
| 28 | console.warn(error); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | } |
||
| 32 |