All files / src/messager index.mailer.ts

75% Statements 27/36
84.61% Branches 22/26
64.7% Functions 11/17
83.87% Lines 26/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42  7x 20x 20x 20x   40x 20x     7x 7x   7x 7x 7x 7x 7x 7x     10x 10x 10x 10x     10x   10x 10x 10x 10x                  
import appConfig from '@/config/app.config';
import { HBSTemplateManager, HBSTemplates } from '@/services/handlebars.service';
import { MailerService } from '@/services/mail.service';
import { sendSMS } from '@/services/sms.service';
export class InternalMessager {
  protected html: string = '';
  protected text: string = '';
 
  constructor(
    protected receivers: string[],
    protected subject: string
  ) {}
 
  protected async generateMail(type: HBSTemplates, body: Record<string, string>) {
    const _template = new HBSTemplateManager(type);
    await _template.parseTemplate(body);
    this.html = _template.getHTMLTemplate() ?? '';
    this.text = _template.getTxtTemplate() ?? '';
  }
 
  getHTML() {
    return this.html;
  }
  getTEXT() {
    return this.text;
  }
  async sendEmail() {
    return await MailerService.getInstance().sendEmail({
      receivers: this.receivers,
      subject: `${appConfig.appName} | ${this.subject}`,
      html: this.html,
      text: this.text,
    });
  }
  async sendSMS() {
    return sendSMS({
      phoneNumber: this.receivers[0],
      message: this.text,
    });
  }
}