From 19fff0e085aae8d0dc2ed31e36224216daa57f03 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 17:12:32 +0100
Subject: [PATCH] Last toucan

---
 backend/routes/routesToucan.js | 50 +++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/backend/routes/routesToucan.js b/backend/routes/routesToucan.js
index fc5aff3..82d21ba 100644
--- a/backend/routes/routesToucan.js
+++ b/backend/routes/routesToucan.js
@@ -143,7 +143,7 @@ router.get('/pdf/:year/:title', (req, res) => {
     var title = req.params.title;
     var year = parseInt(req.params.year);
     var nextyear = year + 1;
-    var title = new RegExp((title.split("-")).join("."));
+    title = new RegExp('^'+(title.split("-")).join(".")+'$');
     console.log(title);
 
     Toucan.find(
@@ -163,5 +163,53 @@ router.get('/pdf/:year/:title', (req, res) => {
             });
 });
 
+router.get('/pdf-lastToucan', (req, 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.sendFile(path.resolve(env.savedExtensions[1].path,idMax+".pdf"));  
+              }
+          }
+          
+          );
+});
+
+router.get('/img-lastToucan', (req, 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.redirect('img/'+idMax);
+              }
+          }
+          
+          );
+});
+
     
 module.exports = router;
\ No newline at end of file
-- 
GitLab