eletrotupi / tcc/ commit / b544766

api: rework the baseline summary text for triggers

"Others" category was always feeling a bit off
Pedro Lucas Porcellis porcellis@eletrotupi.com 1 month ago b544766db036230d143f8dbc3f0cb7eeebb3d492
Parents: 0874e55
1 file(s) changed
  • api/src/lib/queue/processors/insights/triggerPattern.ts +12 -3
api/src/lib/queue/processors/insights/triggerPattern.ts
1 1
import { prisma } from "@app/lib/prisma";
2 2
import { InsightType, InsightPeriod, TriggerType } from "@prisma/client";
3 3
import { InsightPeriodPayload } from "@app/lib/queue/types";
4 4

5 5
const TRIGGER_LABEL: Record<TriggerType, string> = {
▸ 70 unchanged lines
76 76
}
77 77

78 78
function buildBody(top: TriggerType, count: number, total: number): string {
79 79
  const pct = Math.round((count / total) * 100);
80 80
  const label = TRIGGER_LABEL[top];
81 -
  return `
81 +
  let template = "";
82 +

83 +
  if (top == "OTHER") {
84 +
    template = `
85 +
    Gatilhos do tipo "${label}" foram os mais frequentes,
86 +
    representando ${pct}% dos registros do período.
87 +
  `
88 +
  } else {
89 +
    template = `
82 90
    Gatilhos de ${label} foram os mais frequentes,
83 91
    representando ${pct}% dos registros do período.
84 92
  `
85 -
    .replace(/\s*\n\s*/g, " ")
86 -
    .trim();
93 +
  }
94 +

95 +
  return template.replace(/\s*\n\s*/g, " ").trim();
87 96
}