Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/BladimirGS/judicial-backend/llms.txt

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

Judicial Backend’s search and statistics endpoints return potentially large result sets. To keep response sizes predictable, every listing endpoint that can return multiple records accepts page and limit query parameters and embeds pagination metadata directly in the response envelope. The logic is centralized in a small utility (parsePaginacion) and two shared TypeScript interfaces so every controller applies the same defaults and computes offsets consistently.

Type Definitions

Two interfaces live in src/core/types/pagination.types.ts:
export interface PaginationQuery {
    page?: string;
    limit?: string;
}

export interface Paginacion {
    page: number;
    limit: number;
}
PaginationQuery mirrors req.query — Express query string values are always string (or string[]), so both fields are typed as string | undefined. Paginacion holds the parsed, numeric values returned by the utility function.
The Paginacion interface does not include a skip field. Instead, services compute skip inline as (page - 1) * limit when slicing result arrays or building TypeORM queries.

parsePaginacion Utility

import { Paginacion, PaginationQuery } from '../types/pagination.types';

export function parsePaginacion(query: PaginationQuery, defaultPage = 1, defaultLimit = 10): Paginacion {
    const page  = Math.max(1, Number(query.page)  || defaultPage);
    const limit = Math.max(1, Number(query.limit) || defaultLimit);

    return { page, limit };
}
The function:
  1. Parses query.page and query.limit with Number() — values that are undefined, empty strings, or non-numeric become NaN, which the || fallback converts to the default.
  2. Clamps both values to a minimum of 1 with Math.max(1, ...) so negative or zero values are silently corrected.
  3. Returns the Paginacion object; callers compute skip themselves as (page - 1) * limit.

Default values

ParameterDefaultMinimum
page11
limit101

Query Parameters

page
number
default:"1"
The 1-indexed page number to retrieve. Values below 1 are clamped to 1. Non-numeric values fall back to the default.
limit
number
default:"10"
The maximum number of records to return per page. Values below 1 are clamped to 1. Non-numeric values fall back to 10.

How Controllers Use parsePaginacion

Controllers destructure the result and pass page and limit directly to the service:
import { parsePaginacion } from '../../../core/utils/pagination.util';

export const BusquedaApelacionController = {
    getApelaciones: asyncHandler(async (req: Request, res: Response) => {
        const { page, limit } = parsePaginacion(req.query);
        const dto = req.query as unknown as ApelacionFiltrosDTO;

        const resultados = await BusquedaApelacionService.getApelaciones(dto, page, limit);

        return responseUtil.success(res, resultados);
    }),
};

How Services Apply Pagination

Services receive page and limit as plain numbers and apply the offset calculation themselves:
async getApelaciones(dto: ApelacionFiltrosDTO, page: number, limit: number) {
    const entidades = await busquedaRepo.findApelaciones(payload);
    const apelaciones = ApelacionMapper.toDTOList(entidades);

    const total  = apelaciones.length;
    const inicio = (page - 1) * limit;          // compute skip inline
    const paginado = apelaciones.slice(inicio, inicio + limit);

    return { apelaciones: paginado, total, page, limit };
}
The current implementation fetches all matching records from the database and slices the array in memory. For very large datasets, consider pushing the skip/take constraints down to the TypeORM QueryBuilder (.skip(inicio).take(limit)) to reduce data transfer from the database.

Paginated Response Shape

Services return pagination metadata alongside the data array. The controller wraps this in the standard responseUtil.success envelope:
{
  "status": "success",
  "message": "Operación exitosa",
  "data": {
    "apelaciones": [...],
    "total": 245,
    "page": 1,
    "limit": 10
  }
}
The fields embedded in the data object by each service are:
FieldTypeDescription
totalnumberTotal number of records matching the applied filters.
pagenumberThe current page number as received (or defaulted).
limitnumberThe page size as received (or defaulted).
apelaciones / planos / historicosarrayThe sliced result set for the requested page.
Consumers can compute the total number of pages as Math.ceil(total / limit).

Endpoints That Support Pagination

MethodPathService
GET/api/busquedasBusquedaApelacionService.getApelaciones
GET/api/busquedas/planoBusquedaPlanoService.getPlanos
GET/api/busquedas/historicoBusquedaHistoricoService.getHistoricos
GET/api/estadisticas/planoEstadisticaService.getReportePlano
All four endpoints require at least one valid filter criterion in addition to the pagination parameters. If no filter is provided, they return 400 Bad Request before pagination is applied.

Build docs developers (and LLMs) love