Skip to content
Snippets Groups Projects
Commit c8d4f5ac authored by Inès Yeterian's avatar Inès Yeterian
Browse files

try to find last toucan in a fast way

parent 4d763cb5
Branches
No related tags found
1 merge request!6Last toucan
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment