Ajout initial des fichiers du projet
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
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('/', auth.required, function (req, res, next) {
|
||||
let query = {};
|
||||
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;
|
||||
}
|
||||
if (typeof req.query.slug !== 'undefined') {
|
||||
query.slug = req.query.slug;
|
||||
}
|
||||
|
||||
User.findById(req.payload.id).then(function (user) {
|
||||
if (!user) {
|
||||
return res.status(401).json({ errors: { "Unauthorized": "autentification requise" } });
|
||||
}
|
||||
if (user.role == 'Admin') {
|
||||
return res.status(403).json({ errors: { "Forbidden": "Vous ne disposez pas des autorisations suffisantes" } });
|
||||
}
|
||||
Jump.find(query)
|
||||
.skip(Number(offset))
|
||||
.limit(Number(limit))
|
||||
.exec()
|
||||
.then(function (result) {
|
||||
let canopies = result;
|
||||
return res.json({
|
||||
canopies: canopies,
|
||||
canopiesCount: canopies.length
|
||||
});
|
||||
}).catch(next);
|
||||
}).catch(next);
|
||||
});
|
||||
|
||||
router.get('/allBySize', auth.required, function (req, res, next) {
|
||||
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;
|
||||
}
|
||||
|
||||
User.findById(req.payload.id).then(function (user) {
|
||||
if (!user) {
|
||||
return res.status(401).json({ errors: { "Unauthorized": "autentification requise" } });
|
||||
}
|
||||
let query = queries.getCanopiesBySizeQuery(user._id.toString());
|
||||
Jump.aggregate(query)
|
||||
.skip(Number(offset))
|
||||
.limit(Number(limit))
|
||||
.exec()
|
||||
.then(function (result) {
|
||||
let canopies = result.map(function (data) {
|
||||
return { taille: data._id.taille, count: data.count };
|
||||
});
|
||||
return res.json({
|
||||
canopies: canopies,
|
||||
canopiesCount: canopies.length
|
||||
});
|
||||
}).catch(next);
|
||||
}).catch(next);
|
||||
});
|
||||
|
||||
router.get('/allBySizeByYear', 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.getCanopiesBySizeByYearQuery(user._id.toString());
|
||||
Jump.aggregate(query)
|
||||
.skip(Number(offset))
|
||||
.limit(Number(limit))
|
||||
.exec()
|
||||
.then(function (result) {
|
||||
let canopies = result.map(function (data) {
|
||||
return { taille: data._id.taille, year: data._id.year, count: data.count };
|
||||
});
|
||||
//console.log(dropzones);
|
||||
return res.json({
|
||||
canopies: canopies,
|
||||
canopiesCount: canopies.length
|
||||
});
|
||||
}).catch(next);
|
||||
}).catch(next);
|
||||
});
|
||||
|
||||
router.get('/allBySizeByModel', auth.required, function (req, res, next) {
|
||||
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;
|
||||
}
|
||||
|
||||
User.findById(req.payload.id).then(function (user) {
|
||||
if (!user) {
|
||||
return res.status(401).json({ errors: { "Unauthorized": "autentification requise" } });
|
||||
}
|
||||
let query = queries.getCanopiesBySizeByModelQuery(user._id.toString());
|
||||
Jump.aggregate(query)
|
||||
.skip(Number(offset))
|
||||
.limit(Number(limit))
|
||||
.exec()
|
||||
.then(function (result) {
|
||||
let canopies = result.map(function (data) {
|
||||
return { taille: data._id.taille, voile: data._id.voile, count: data.count };
|
||||
});
|
||||
return res.json({
|
||||
canopies: canopies,
|
||||
canopiesCount: canopies.length
|
||||
});
|
||||
}).catch(next);
|
||||
}).catch(next);
|
||||
});
|
||||
|
||||
router.get('/allBySizeByModelByYear', 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.getCanopiesBySizeByModelByYearQuery(user._id.toString());
|
||||
Jump.aggregate(query)
|
||||
.skip(Number(offset))
|
||||
.limit(Number(limit))
|
||||
.exec()
|
||||
.then(function (result) {
|
||||
let canopies = result.map(function (data) {
|
||||
return { taille: data._id.taille, voile: data._id.voile, year: data._id.year, count: data.count };
|
||||
});
|
||||
return res.json({
|
||||
canopies: canopies,
|
||||
canopiesCount: canopies.length
|
||||
});
|
||||
}).catch(next);
|
||||
}).catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user