fix(notas): notas persisten entre etapas via clienteClave

- Campo clienteClave en RecordatorioVendedor (hash nombre+telefono)
- Al crear nota: se calcula clienteClave del lead/cliente
- Al buscar notas: busca por leadId O clienteClave (no por nombre suelto)
- Mantiene compatibilidad: notas viejas sin clienteClave siguen por leadId
- Migración SQL aplicada
This commit is contained in:
2026-09-10 22:55:11 +00:00
parent 5a50243dff
commit b1e408f435
6 changed files with 35 additions and 4 deletions

View File

@@ -7,10 +7,18 @@ import { NotFoundError } from '../utils/errors.js'
* muestra en "Mis recordatorios" de Mi día.
*/
/** Calcula una clave estable del cliente: nombre normalizado + últimos 10 dígitos del teléfono */
export function calcularClienteClave(nombre?: string | null, telefono?: string | null): string {
const n = (nombre ?? '').trim().toLowerCase()
const t = (telefono ?? '').replace(/\s+/g, '').slice(-10)
return `${n}|${t}`
}
export interface DatosCrearRecordatorio {
titulo: string
descripcion?: string | null
leadId?: string | null
clienteClave?: string | null
fechaRecordar: string // ISO o YYYY-MM-DDTHH:mm
}
@@ -18,6 +26,7 @@ export interface OpcionesListarRecordatorio {
completados?: boolean
desde?: string | null // ISO
hasta?: string | null // ISO
clienteClave?: string | null
}
export class RecordatorioVendedorService {
@@ -28,6 +37,7 @@ export class RecordatorioVendedorService {
titulo: data.titulo.trim(),
descripcion: data.descripcion?.trim() ?? null,
leadId: data.leadId ?? null,
clienteClave: data.clienteClave ?? null,
fechaRecordar: new Date(data.fechaRecordar),
},
})
@@ -36,6 +46,9 @@ export class RecordatorioVendedorService {
async listar(usuarioId: string, opciones: OpcionesListarRecordatorio = {}) {
const where: Record<string, unknown> = { usuarioId }
if (opciones.clienteClave) {
where['clienteClave'] = opciones.clienteClave
}
if (opciones.completados !== undefined) {
where['completado'] = opciones.completados
}