From c8d4f5acbf4e7701fb4a545b89cba7fe769a66c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?In=C3=A8s=20Yeterian?= <ines.yeterian@student-cs.fr> Date: Mon, 14 Feb 2022 15:25:48 +0100 Subject: [PATCH] try to find last toucan in a fast way --- backend/routes/routesToucan.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/backend/routes/routesToucan.js b/backend/routes/routesToucan.js index 25d6ce7..048d7c5 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 -- GitLab