Overview
The Client model represents customers in the Luis IT Repair system. It includes normalized fields for efficient fuzzy searching and can link to multiple service tickets.Firestore Collection
Collection Name:clientes
Core Fields
Customer’s full name as entered.
Customer’s phone number. Used as a primary lookup key.
Customer’s address for contact or delivery purposes.
Serial Number Preferences
Customer’s preferred device serial number. Automatically cleared if
omitirNumeroSerie is true.Flag indicating that the customer prefers not to provide serial numbers.
Loyalty Program
Customer loyalty points balance. Earned from purchases and can be redeemed for discounts.Earning Rate: Typically 1 point per peso spent on qualifying products.Redemption: Points can be used as currency (1 point = 1 peso discount) at checkout.
Search Optimization Fields
These fields are automatically generated and maintained by the system for efficient fuzzy search.Normalized version of
nombre for search indexing.Normalization:- Converts to lowercase
- Removes accents/diacritics
- Removes special characters
- Collapses multiple spaces to single space
- Separates camelCase words
"jose maria"Ultra-normalized version with all spaces removed for tight matching.Example: “José María” →
"josemaria"Timestamps
Client record creation timestamp. Set automatically by Firestore.
Last update timestamp. Updated automatically on every change.
Search Algorithm
The client search uses a two-phase approach:- Prefix Search: Query Firestore using
nombreNormwith range query (startAt,endAt) - Levenshtein Ranking: Calculate edit distance on
nombreCompactand sort by similarity
Example JSON
Related Functions
Client Management
crearCliente()- Create new client with automatic normalizationactualizarCliente()- Update client data (re-normalizes name fields)obtenerClientePorId()- Fetch client by document IDlistarClientes()- List recent clients (sorted byupdatedAt)
Search & Lookup
buscarClientesSimilares()- Fuzzy search by name with Levenshtein rankingbuscarClientePorTelefono()- Exact phone number lookuplistarServiciosPorClienteId()- Get all services for a client
Loyalty Integration
sumarPuntosCliente()- Add or subtract points (use negative value to deduct)
Usage Example
Data Migration Notes
Legacy Clients: Older records may have emptynombreNorm and nombreCompact fields. The search function includes a fallback that:
- Queries recent clients by
updatedAt - Performs in-memory normalization and filtering
- Merges with prefix search results
