fix(flow): LeadCaptura para oportunidades y apartados en flujo Monday

- convertirLeadEndpoint: crea LeadCaptura OPORTUNIDADES al convertir lead
- escaneoOportunidades: crea LeadCaptura APARTADO al crear apartado
- Mi día: esMio para apartados incluye oportunidadId del usuario
- Flujo completo verificado: Lead → Contactado → Agendo → Aparto
This commit is contained in:
2026-09-07 19:55:56 +00:00
parent 9021733455
commit 586498c845
3 changed files with 43 additions and 1 deletions

View File

@@ -751,6 +751,25 @@ export async function convertirLeadEndpoint(req: Request, res: Response): Promis
}
try {
const { oportunidadId } = await convertirLead(mondayService, itemId, usuarioSub, body.fecha)
// Crear LeadCaptura local para la oportunidad (Mi día las necesita)
try {
const leadLocal = await prisma.leadCaptura.findFirst({ where: { leadId: itemId } })
await prisma.leadCaptura.upsert({
where: { leadId: oportunidadId },
update: { board: 'OPORTUNIDADES', etapa: 'Agendo Cita' },
create: {
leadId: oportunidadId,
board: 'OPORTUNIDADES',
etapa: 'Agendo Cita',
nombreLead: leadLocal?.nombreLead ?? '',
telefono: leadLocal?.telefono ?? null,
email: leadLocal?.email ?? null,
usuarioId: usuarioSub ?? 'sistema',
mondayItemId: oportunidadId,
pendienteSync: false,
},
})
} catch { /* best effort */ }
res.status(201).json({ leadId: itemId, oportunidadId, etapa: 'Agendo Cita' })
auditoria.registrar(usuarioSub ?? 'sistema', 'CONVERTIR_LEAD', 'lead', itemId)
} catch (err) {