// src/modules/tickets/models/glpi/implantacao.model.js function toGlpiPayload(ticket) { return { entities_id: ticket.entities_id || 0, name: buildTitle(ticket), content: buildHtml(ticket), status: resolveGlpiStatus(ticket.status_atendimento), date: ticket.created_at, date_mod: new Date(), users_id_recipient: process.env.GLPI_USER_ID || 0, urgency: 3, impact: 3, priority: 3, type: 2, date_creation: ticket.created_at || new Date(), itilcategories_id: 0, slas_id_ttr: 37, } } function resolveGlpiStatus(status) { const map = { 'Novo': 1, 'Pendente': 4, 'Em atendimento': 2, 'Resolvido': 5 } return map[status] || 1 } function buildTitle(ticket) { return `IMPLANTAÇÃO - ${ticket.codigo_cliente}-${ticket.codigo_servico} - ${ticket.nome_razaosocial} - ${ticket.servico_nome}` } function buildHtml(ticket) { const docLabel = ticket.tipo_pessoa === 'pf' ? 'CPF' : 'CNPJ' const documento = formatDocument(ticket.cpf_cnpj, ticket.tipo_pessoa) const servico = resolveService(ticket.servico_nome) return `
Dados Comercial
Nº de Operação ${ticket.protocolo_hub || "N/A"}
Gerente Responsável ${ticket.vendedor || "N/A"}
Código do Cliente ${ticket.codigo_cliente}
Dados Cliente
Cliente ${ticket.nome_razaosocial}
${docLabel} ${documento}
Nome Contato ${ticket.cliente_nome || "N/A"}
Email Contato ${ticket.email || "N/A"}
Telefone Contato ${ticket.telefone || "N/A"}
Endereço Instalação ${ticket.endereco || "N/A"}
Dados do Serviço Contratado
Produto Quantidade Descrição
${servico.produto} ${servico.qtd} ${servico.descricao || ""}
Observações
${nl2br(ticket.descricao_abertura) || "N/A"}
` } function formatCPF(cpf) { return cpf?.replace(/\D/g, '') .replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, '$1.$2.$3-$4') } function formatCNPJ(cnpj) { return cnpj?.replace(/\D/g, '') .replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, '$1.$2.$3/$4-$5') } function formatDocument(doc, tipo) { if (!doc) return 'N/A' return tipo === 'pf' ? formatCPF(doc) : formatCNPJ(doc) } const serviceDictionary = { // ---------- LAN-TO-LAN ---------- "Lan-to-Lan 50 Mbps": { produto: "Lan-to-Lan", qtd: 1, descricao: "50 Mbps" }, "Lan-to-Lan 100 Mbps": { produto: "Lan-to-Lan", qtd: 1, descricao: "100 Mbps" }, "Lan-to-Lan 200 Mbps": { produto: "Lan-to-Lan", qtd: 1, descricao: "200 Mbps" }, "Lan-to-Lan 300 Mbps": { produto: "Lan-to-Lan", qtd: 1, descricao: "300 Mbps" }, "Lan-to-Lan 500 Mbps": { produto: "Lan-to-Lan", qtd: 1, descricao: "500 Mbps" }, "Lan-to-Lan 700 Mbps": { produto: "Lan-to-Lan", qtd: 1, descricao: "700 Mbps" }, "Lan-to-Lan": { produto: "Lan-to-Lan", qtd: 1, descricao: null }, // ---------- LINK DEDICADO ---------- "Link de Internet Dedicado 20 Mbps Full Duplex": { produto: "Link de Internet Dedicado", qtd: 1, descricao: "20 Mbps Full Duplex" }, "Link de Internet Dedicado 100 Mbps Full Duplex": { produto: "Link de Internet Dedicado", qtd: 1, descricao: "100 Mbps Full Duplex" }, "Link de Internet Dedicado 1Gbps Full Duplex": { produto: "Link de Internet Dedicado", qtd: 1, descricao: "1 Gbps Full Duplex" }, "Link de Internet Dedicado 2 Gbps Full Duplex": { produto: "Link de Internet Dedicado", qtd: 1, descricao: "2 Gbps Full Duplex" }, // Default genérico caso venha coisa nova }; function resolveService(name) { return serviceDictionary[name] || { produto: name, qtd: 1, descricao: null } } function nl2br(text) { if (!text) return '' return text.replace(/\r\n|\n|\r/g, '
') } module.exports = { toGlpiPayload }