• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 8421654220

25 Mar 2024 02:22PM UTC coverage: 79.934% (+53.8%) from 26.087%
8421654220

Pull #495

github

web-flow
Merge 4faeebea5 into 1869c986d
Pull Request #495: chore: add licenses for non-NPM packages

3256 of 3853 branches covered (84.51%)

25152 of 31466 relevant lines covered (79.93%)

1188.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.14
/apps/nestjs-backend/src/features/automation/actions/mail-sender/mail-sender.ts
1
import { Injectable, Logger, Scope } from '@nestjs/common';
2✔
2
import type { Almanac, Event, RuleResult } from 'json-rules-engine';
2✔
3
import MarkdownIt from 'markdown-it';
2✔
4
import { MailSenderService } from '../../../mail-sender/mail-sender.service';
2✔
5
import type { IActionResponse, IObjectArraySchema, ITemplateSchema } from '../action-core';
2✔
6
import { actionConst, ActionCore, ActionResponseStatus } from '../action-core';
2✔
7

2✔
8
export const markdownIt = MarkdownIt({
2✔
9
  html: true,
2✔
10
  breaks: true,
2✔
11
  // eslint-disable-next-line @typescript-eslint/no-var-requires
2✔
12
}).use(require('markdown-it-sanitizer'));
2✔
13

2✔
14
export interface IMailSenderSchema extends Record<string, unknown> {
2✔
15
  to: IObjectArraySchema;
2✔
16
  cc?: IObjectArraySchema;
2✔
17
  bcc?: IObjectArraySchema;
2✔
18
  replyTo?: IObjectArraySchema;
2✔
19
  subject: ITemplateSchema;
2✔
20
  message: ITemplateSchema;
2✔
21
}
2✔
22

2✔
23
export interface IMailSenderOptions {
2✔
24
  to: string[];
2✔
25
  cc?: string[];
2✔
26
  bcc?: string[];
2✔
27
  replyTo?: string[];
2✔
28
  subject: string;
2✔
29
  message: string;
2✔
30
}
2✔
31

2✔
32
@Injectable({ scope: Scope.REQUEST })
2✔
33
export class MailSender extends ActionCore {
2✔
34
  private logger = new Logger(MailSender.name);
×
35

×
36
  constructor(private readonly mailSenderService: MailSenderService) {
×
37
    super();
×
38
  }
×
39

×
40
  bindParams(id: string, params: IMailSenderSchema, priority?: number): this {
×
41
    return this.setName(id).setEvent({ type: id, params: params }).setPriority(priority);
×
42
  }
×
43

×
44
  onSuccess = async (event: Event, almanac: Almanac, _ruleResult: RuleResult): Promise<void> => {
×
45
    const { to, cc, bcc, replyTo, subject, message } =
×
46
      await this.parseInputSchema<IMailSenderOptions>(event.params as IMailSenderSchema, almanac);
×
47

×
48
    const html = markdownIt.render(message);
×
49

×
50
    const mailOptions = { to, cc, bcc, replyTo, subject, html };
×
51

×
52
    let outPut: IActionResponse<unknown>;
×
53
    await this.mailSenderService
×
54
      .sendMail(mailOptions)
×
55
      .then((senderResult) => {
×
56
        outPut = { data: { senderResult }, status: ActionResponseStatus.OK };
×
57
      })
×
58
      .catch((error) => {
×
59
        this.logger.error(error.message, error?.stack);
×
60
        outPut = {
×
61
          error: error.message,
×
62
          data: undefined,
×
63
          status: ActionResponseStatus.InternalServerError,
×
64
        };
×
65
      })
×
66
      .finally(() => {
×
67
        almanac.addRuntimeFact(`${actionConst.OutPutFlag}${this.name}`, outPut);
×
68
      });
×
69
  };
×
70
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc