Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/juadariasmar/inventory_project/llms.txt

Use this file to discover all available pages before exploring further.

Inventory System keeps your team informed through a built-in notification system that creates targeted alerts whenever important inventory or user-management events occur. Notifications are stored in the database, scoped to the company, and optionally targeted at a specific user. A badge in the navigation header shows the unread count and updates on each page load.

Notification types

The TipoNotificacion enum defines six event categories. The table below describes when each one fires:
ValueFires when…
STOCK_BAJOA product’s cantidad falls at or below stockMinimo + MARGEN_ALERTA_STOCK (i.e. quantity ≤ stockMinimo + 2) after a sale or movement. The product still has units remaining but is approaching the reorder threshold.
STOCK_CRITICOA product’s cantidad falls at or below stockMinimo + MARGEN_ALERTA_STOCK (i.e. quantity ≤ stockMinimo + 2) — the same threshold as STOCK_BAJO. Generated by NotificacionesService.generarAlertasStock, which batches up to 10 critical-stock notifications at a time and includes a calculated purchase suggestion in the message body.
COTIZACION_POR_VENCERA quote’s validaHasta is within 24 hours of the current time. Prompts the sales team to either convert the quote to a sale or contact the customer before the reservation automatically expires.
PRODUCTO_SIN_MOVIMIENTOA product with a positive quantity has had no stock entries or exits for 30 or more days. Surfaces potentially forgotten or slow-moving inventory.
INVITACION_ACEPTADAA user completed the invitation flow and joined the company. Allows admins to know when a pending invitation has been acted on.
USUARIO_REGISTRADOA new user finished registration and is waiting for admin approval (their status is PENDIENTE). Prompts admins to review and activate the new account.

Notificacion model

FieldTypeDescription
idIntAuto-incremented primary key
tipoTipoNotificacionThe event category (see table above)
tituloStringShort heading shown in the notification bell
mensajeString?Optional longer description with contextual detail
linkString?Optional relative URL the user can navigate to for more context (e.g. /productos/42)
leidaBooleanfalse until the user marks it read (default false)
leidaEnDateTime?Timestamp set when leida transitions to true
usuarioIdString?FK to a specific Usuario; null for company-wide broadcasts
empresaIdStringTenant key — all notifications are company-scoped
creadoEnDateTimeUTC creation timestamp

Notification scoping

User-scoped notifications

usuarioId is set to a specific user’s ID. Only that user sees the notification in their personal feed. Used for INVITACION_ACEPTADA and USUARIO_REGISTRADO events where the relevant audience is the admin who sent the invitation or triggered the registration flow.

Company-wide notifications

usuarioId is null. Every active user in the company sees the notification. Used for inventory alerts (STOCK_BAJO, STOCK_CRITICO, COTIZACION_POR_VENCER, PRODUCTO_SIN_MOVIMIENTO) where any team member may need to act.
When GET /api/notificaciones is called, the service returns both notifications directly addressed to the authenticated user and all company-wide notifications (those with usuarioId = null). This means a user always sees the full relevant picture without receiving notifications meant only for colleagues.

API endpoints

List notifications

GET /api/notificaciones
Returns up to 50 notifications ordered by creadoEn descending.
Query parameterTypeDescription
soloNoLeidas"true" | "false"When true, only unread notifications are returned
contador"true"When present, returns { "count": <number> } instead of the full list — useful for populating the header badge
[
  {
    "id": 301,
    "tipo": "STOCK_CRITICO",
    "titulo": "Stock crítico: Agua Mineral 500ml",
    "mensaje": "Quedan 2 unidades (mínimo 20). Sugerencia: comprar 52.",
    "link": "/productos/42",
    "leida": false,
    "leidaEn": null,
    "usuarioId": null,
    "empresaId": "clx9t2k0f0000abcde12fgh34",
    "creadoEn": "2024-11-20T09:15:00.000Z"
  }
]

Mark a single notification as read

PATCH /api/notificaciones/[id]
Sets leida = true and leidaEn = now() for the notification with the given id. Returns the updated Notificacion object.
{
  "leida": true,
  "leidaEn": "2024-11-20T10:02:45.123Z"
}

Mark all notifications as read

POST /api/notificaciones/marcar-todas
Calls NotificacionesService.marcarTodasLeidas, which updates all unread notifications for the authenticated user — both those directly addressed to them and company-wide ones — in a single updateMany call. Returns a Prisma BatchPayload with a count of how many records were updated:
{ "count": 7 }
Call GET /api/notificaciones?contador=true after marking all as read to confirm the badge count has dropped to zero before updating the UI.

Build docs developers (and LLMs) love