nomeDaCopia (followup/nome-da-copia.ts)

DeskcommCRM · lib/followup/nome-da-copia.ts · typescript · MIT
crm

Generates a unique copy name for a flow, respecting length limits.

// Source: https://github.com/melgarafael/DeskcommCRM | License: MIT | Copyright 2026 Rafael Melgaço
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Nome da cópia de um fluxo. `followup_flow_pointers` tem
 * `unique (organization_id, name)` — duplicar "Foo" duas vezes não pode
 * tentar gravar "Foo (cópia)" de novo.
 *
 * Teto: 80 caracteres (o mesmo do `createFollowupFlowSchema`). Se o original
 * já está no limite, o sufixo come o final do nome, não estoura a coluna.
 */
export const MAX_FOLLOWUP_FLOW_NAME = 80;

export function nomeDaCopia(original: string, ocupados: Iterable<string>): string {
  const taken = new Set(ocupados);
  const raiz = original.trim() || "Fluxo";
  for (let n = 1; n < 1000; n++) {
    const sufixo = n === 1 ? " (cópia)" : ` (cópia ${n})`;

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key