Ajout initial des fichiers du projet
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
var router = require('express').Router(),
|
||||
mongoose = require('mongoose'),
|
||||
Jump = mongoose.model('Jump'),
|
||||
User = mongoose.model('User');
|
||||
const auth = require('../auth'),
|
||||
queries = require('../queries');
|
||||
|
||||
|
||||
router.get('/allByOaci', auth.required, function (req, res, next) {
|
||||
User.findById(req.payload.id).then(function (user) {
|
||||
if (!user) {
|
||||
return res.status(401).json({ errors: { "Unauthorized": "autentification requise" } });
|
||||
}
|
||||
let limit = 25;
|
||||
let offset = 0;
|
||||
if (typeof req.query.limit !== 'undefined') {
|
||||
limit = req.query.limit;
|
||||
}
|
||||
if (typeof req.query.offset !== 'undefined') {
|
||||
offset = req.query.offset;
|
||||
}
|
||||
let query = queries.getDropZonesByOaciQuery(user._id.toString());
|
||||
Jump.aggregate(query)
|
||||
.skip(Number(offset))
|
||||
.limit(Number(limit))
|
||||
.exec()
|
||||
.then(function (result) {
|
||||
let dropzones = result.map(function (data) {
|
||||
return { lieu: data._id.lieu, oaci: data._id.oaci, count: data.count };
|
||||
});
|
||||
return res.json({
|
||||
dropzones: dropzones,
|
||||
dropzonesCount: dropzones.length
|
||||
});
|
||||
}).catch(next);
|
||||
}).catch(next);
|
||||
});
|
||||
|
||||
router.get('/allByOaciByYear', auth.required, function (req, res, next) {
|
||||
User.findById(req.payload.id).then(function (user) {
|
||||
if (!user) {
|
||||
return res.status(401).json({ errors: { "Unauthorized": "autentification requise" } });
|
||||
}
|
||||
let limit = 25;
|
||||
let offset = 0;
|
||||
if (typeof req.query.limit !== 'undefined') {
|
||||
limit = req.query.limit;
|
||||
}
|
||||
if (typeof req.query.offset !== 'undefined') {
|
||||
offset = req.query.offset;
|
||||
}
|
||||
let query = queries.getDropZonesByOaciByYearQuery(user._id.toString());
|
||||
Jump.aggregate(query)
|
||||
.skip(Number(offset))
|
||||
.limit(Number(limit))
|
||||
.exec()
|
||||
.then(function (result) {
|
||||
let dropzones = result.map(function (data) {
|
||||
return { lieu: data._id.lieu, oaci: data._id.oaci, year: data._id.year, count: data.count };
|
||||
});
|
||||
return res.json({
|
||||
dropzones: dropzones,
|
||||
dropzonesCount: dropzones.length
|
||||
});
|
||||
}).catch(next);
|
||||
}).catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user