Price alerts let coffee producers stop manually refreshing the price board. Set a minimum price threshold once, and CoffePrice will send you an email the moment any buyer (or a specific buyer you choose) publishes a price at or above your target. Alerts work passively in the background — every time a buyer creates or updates a price record, the system checks all active alerts automatically.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/JaiderT/CoffeePrice/llms.txt
Use this file to discover all available pages before exploring further.
How Alerts Work
Producer creates an alert
A producer sets
precioMinimo (the minimum price they want to be notified about) and optionally pins the alert to a single comprador ID. If comprador is null, the alert watches all buyers in the system.Buyer posts or updates a price
When a buyer calls
POST /api/precios or PUT /api/precios/:id, the price controller calls verificarAlertas(compradorId, preciocarga) synchronously.System matches alerts
The backend queries for active alerts where:
activa: trueprecioMinimo <= preciocarga(the posted price meets or exceeds the threshold)compradoreither equals the posting buyer’s ID or isnull(catch-all)
Email notification dispatched
For each matched alert where
canales.email: true and the user has a valid email address, the system sends a transactional email via Nodemailer containing:- Producer’s full name
- Buyer’s company name (
nombreempresa) - The alert’s minimum price threshold
- The actual price just posted
ultimaNotificacion is updated to new Date() on each trigger.Alert Fields
| Field | Type | Required | Description |
|---|---|---|---|
usuario | ObjectId | ✅ | Reference to the producer (usuario collection) who owns this alert |
comprador | ObjectId | ❌ | Pin alert to a specific buyer; null = watch all buyers |
precioMinimo | number | ✅ | Minimum price (COP/carga) that triggers notification |
activa | boolean | — | Whether the alert is active. Default: true |
canales.email | boolean | — | Send email notifications. Default: false |
canales.whatsapp | boolean | — | WhatsApp channel (future). Default: true |
canales.sms | boolean | — | SMS channel (future). Default: false |
canales.push | boolean | — | Push notification channel. Default: true |
ultimaNotificacion | Date | — | Timestamp of the last triggered notification. Default: null |
Set
canales.email: true when creating or updating an alert to receive email notifications. The other channel flags (whatsapp, sms, push) are reserved for future delivery channels and do not currently send messages.Toggling an Alert On/Off
Producers can pause and resume an alert without deleting it:activa boolean. A paused alert (activa: false) is excluded from all buyer-price checks until re-activated.
Role Restriction
Only users with theproductor or admin role can access the alerts API. Buyers (comprador role) cannot create or view alerts.
| Route | Roles |
|---|---|
GET /api/alertas/usuario/:usuarioId | productor, admin |
GET /api/alertas/:id | productor, admin |
POST /api/alertas | productor, admin |
PUT /api/alertas/:id | productor, admin |
PUT /api/alertas/:id/toggle | productor, admin |
DELETE /api/alertas/:id | productor, admin |
Spam Prevention
ultimaNotificacion is recorded every time an alert fires. The /api/alertas/verificar/:usuarioId endpoint returns only alerts that triggered within the last 60 seconds — this is used by the frontend to display real-time notification badges without polling MongoDB continuously.
CRUD Summary
For the full request/response schema of each endpoint, see the API → Alerts reference.Create Alert
POST /api/alertas — Send { precioMinimo, comprador?, canales } in the request body. The usuario field is inferred from the authenticated JWT.Update Alert
PUT /api/alertas/:id — Update any mutable field: precioMinimo, comprador, canales, or activa.Toggle Alert
PUT /api/alertas/:id/toggle — Flip activa without modifying any other fields.Delete Alert
DELETE /api/alertas/:id — Permanently removes the alert. Ownership or admin role required.