Mise à jour de routes

This commit is contained in:
Julien Gautier
2024-01-11 16:53:43 +01:00
parent 54524591dd
commit e1a0ba340c
6 changed files with 503 additions and 43 deletions
+67 -1
View File
@@ -7,7 +7,7 @@ const auth = require('../auth');
router.get('/', auth.required, function (req, res, next) {
var limit = 20;
var limit = 25;
var offset = 0;
if (typeof req.query.limit !== 'undefined') {
limit = req.query.limit;
@@ -37,6 +37,11 @@ router.get('/', auth.required, function (req, res, next) {
'$sum': 1
}
}
}, {
'$sort':
{
'_id': 1
},
}
];
Promise.all([
@@ -62,7 +67,68 @@ router.get('/', auth.required, function (req, res, next) {
*/
}).catch(next);
}).catch(next);
});
router.get('/allByDate', auth.required, function (req, res, next) {
User.findById(req.payload.id).then(function (user) {
if (!user) {
return res.sendStatus(401);
}
var limit = 50;
var offset = 0;
if (typeof req.query.limit !== 'undefined') {
limit = req.query.limit;
}
if (typeof req.query.offset !== 'undefined') {
offset = req.query.offset;
}
var query = [
{
'$match': {
'$expr': {
'$eq': [ '$author' , { '$toObjectId': user._id.toString() } ]
}
}
}, {
'$project': {
'_id': 0,
'aeronef': 1,
'imat': 1,
'year': {
'$year': '$date'
}
}
}, {
'$group': {
'_id': {
'aeronef': '$aeronef',
'imat': '$imat',
'year': '$year'
},
'count': {
'$sum': 1
}
}
}, {
'$sort': {
'_id': 1
}
}
];
Jump.aggregate(query)
.limit(Number(limit))
.skip(Number(offset))
.exec()
.then(function (result) {
var aeronefs = result;
//console.log(aeronefs);
return res.json({
aeronefs: aeronefs,
aeronefsCount: aeronefs.length
});
}).catch(next);
}).catch(next);
});
module.exports = router;