Skip to content

Latest commit

 

History

History
60 lines (55 loc) · 1.69 KB

challenge-2.md

File metadata and controls

60 lines (55 loc) · 1.69 KB

Challenge: Añadir validadores y filtros de búsqueda /paginación

  • Lanza con postman el endpoint para obtener candidatos con filtros de paginación GET http://localhost:3000/candidates?limit=2&offset=1 y su respuesta debe devolver los documentos de la colección de Candidates paginados.
  • Si los query params son érroneos deber devolver un error 400 Bad Request

Ejemplo respuesta paginada:

{
    "data": [
        {
            "_id": "5e8b47ace9ea099dbf055bff",
            "name": "Anna Morcillo",
            "photo": "https://randomuser.me/api/portraits/women/95.jpg",
            "birthDate": "21/07/1985",
            "gender": "F",
            "city": "Mataro",
            "coordinates": {
                "lat": 41.54,
                "long": 2.45
            }
        },
        {
            "_id": "5e8b47ace9ea099dbf055c00",
            "name": "Jesús Antón",
            "photo": "https://randomuser.me/api/portraits/men/83.jpg",
            "birthDate": "12/03/1997",
            "gender": "M",
            "city": "Salamanca",
            "coordinates": {
                "lat": 40.9704,
                "long": -5.67
            }
        }
    ],
    "pagination": {
        "limit": "2",
        "offset": "1"
    }
}

Ejemplo error filtros érroneos:

{
    "status": 400,
    "code": "kaitinder-1",
    "description": "The server cannot or will not process the request due to an apparent client error.",
    "data": {
        "errors": [
            {
                "field": "limit",
                "type": "string.pattern.base",
                "message": "\"limit\" with value \"foo\" fails to match the required pattern: /^\\d+$/"
            }
        ]
    }
}