private updateTemplates()

in firestore-send-email/functions/src/templates.ts [59:113]


  private updateTemplates(snap: FirebaseFirestore.QuerySnapshot) {
    const all: TemplateData[] = snap.docs.map((doc) =>
      Object.assign({ name: doc.id }, doc.data())
    );
    const partials = all.filter((t) => t.partial);
    const templates = all.filter((t) => !t.partial);

    partials.forEach((p) => {
      if (p.subject) {
        subjHandlebars.registerPartial(p.name, p.subject);
      }
      if (p.html) {
        htmlHandlebars.registerPartial(p.name, p.html);
      }
      if (p.text) {
        textHandlebars.registerPartial(p.name, p.text);
      }
      if (p.amp) {
        ampHandlebars.registerPartial(p.name, p.amp);
      }
      if (p.attachments) {
        noPartialAttachmentSupport();
      }

      registeredPartial(p.name);
    });

    templates.forEach((t) => {
      const tgroup: TemplateGroup = {};
      if (t.subject) {
        tgroup.subject = subjHandlebars.compile(t.subject, { noEscape: true });
      }
      if (t.html) {
        tgroup.html = htmlHandlebars.compile(t.html);
      }
      if (t.text) {
        tgroup.text = textHandlebars.compile(t.text, { noEscape: true });
      }
      if (t.amp) {
        tgroup.amp = ampHandlebars.compile(t.amp);
      }
      if (t.attachments) {
        tgroup.attachments = attachmentsHandlebars.compile(
          JSON.stringify(t.attachments),
          { strict: true }
        );
      }

      this.templateMap[t.name] = tgroup;

      templateLoaded(t.name);
    });
    this.ready = true;
    this.waits.forEach((wait) => wait());
  }