diff --git a/backend/routes/routesToucan.js b/backend/routes/routesToucan.js index 25d6ce7c5d238b8dc8a61ef2d9ae63f0a5ac0ac0..048d7c54a6997604955df3fbb0afd96ebf8f6f7f 100644 --- a/backend/routes/routesToucan.js +++ b/backend/routes/routesToucan.js @@ -149,5 +149,31 @@ router.get('/pdf/:year/:title', (req, res) => { }); }); +router.get('/pdf/lastToucan', (res) => { + Toucan.find() + .exec(function(err, toucans){ + if(err) {res.send(err);} + else{ + var max = new Date(toucans[0].date); + var idMax = toucans[0]._id; + const nbToucans = toucans.length; + var value = toucans[0]; + for (let i = 1; i < nbToucans; i++){ + value = new Date(toucans[i].date); + if (value > max){ + max = value; + idMax = toucans[i]._id; + } + res.send(idMax); + } + } + } + + ); + +} + +) + module.exports = router; \ No newline at end of file