-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from Saca-la-Bici/ModificacionObtenerRodadaID
Fix: Funcion de obtener rodada
- Loading branch information
Showing
3 changed files
with
28 additions
and
42 deletions.
There are no files selected for viewing
44 changes: 19 additions & 25 deletions
44
modules/rodadas/controllers/obtenerRodadaPorId.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
const Rodada = require('../../../models/actividades/rodada.model'); | ||
|
||
const getRodadaByActividadId = async (idActividad) => { | ||
exports.getRodadaYRutaPorActividad = async (request, response) => { | ||
const { actividadId } = request.params; // Obtener el id de la actividad desde los parámetros de la URL | ||
|
||
try { | ||
// Buscar la rodada que contiene la actividad con el ID proporcionado en 'informacion' | ||
const rodada = await Rodada.findOne({ | ||
'informacion._id': idActividad // Buscar dentro del array 'informacion' | ||
}) | ||
.populate('ruta') // Poblar el campo 'ruta' para obtener detalles completos de la ruta | ||
.exec(); // Aseguramos que la consulta se ejecute correctamente | ||
// Buscar la rodada que contiene la actividad específica | ||
const rodada = await Rodada.findOne({ 'informacion._id': actividadId }).populate('ruta'); | ||
|
||
if (!rodada) { | ||
return { | ||
message: 'Rodada no encontrada para esta actividad', | ||
error: true | ||
}; | ||
return response.status(404).json({ | ||
message: 'No se encontró ninguna rodada con la actividad proporcionada' | ||
}); | ||
} | ||
|
||
// Obtener el ID de la rodada y el ID de la ruta | ||
const idRodada = rodada._id; | ||
const idRuta = rodada.ruta ? rodada.ruta._id : null; // Validar si tiene ruta | ||
// Obtener los IDs de la rodada y de la ruta | ||
const rodadaId = rodada._id; | ||
const rutaId = rodada.ruta._id; | ||
|
||
return { | ||
idRodada, | ||
idRuta | ||
}; | ||
response.status(200).json({ | ||
rodadaId: rodadaId, | ||
rutaId: rutaId, | ||
}); | ||
} catch (error) { | ||
console.log(`Error al obtener la rodada y la ruta: ${error.message}`); | ||
return { | ||
message: 'Error al obtener los datos', | ||
console.error('Error al obtener la rodada y la ruta:', error.message); | ||
response.status(500).json({ | ||
message: 'Error al obtener la rodada y la ruta', | ||
error: error.message | ||
}; | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getRodadaByActividadId | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.