Refactoring
This commit is contained in:
@@ -20,6 +20,9 @@ router.param('application', function (req, res, next, slug) {
|
|||||||
}).catch(next);
|
}).catch(next);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return all applications
|
||||||
|
*/
|
||||||
router.get('/', auth.required, function (req, res, next) {
|
router.get('/', auth.required, function (req, res, next) {
|
||||||
let query = {};
|
let query = {};
|
||||||
let limit = 25;
|
let limit = 25;
|
||||||
@@ -68,6 +71,9 @@ router.get('/', auth.required, function (req, res, next) {
|
|||||||
}).catch(next);
|
}).catch(next);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* save an application
|
||||||
|
*/
|
||||||
router.post('/', auth.required, function (req, res, next) {
|
router.post('/', auth.required, function (req, res, next) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
User.findById(req.payload.id),
|
User.findById(req.payload.id),
|
||||||
@@ -106,7 +112,9 @@ router.post('/', auth.required, function (req, res, next) {
|
|||||||
}).catch(next);
|
}).catch(next);
|
||||||
});
|
});
|
||||||
|
|
||||||
// return an application
|
/**
|
||||||
|
* return an application
|
||||||
|
*/
|
||||||
router.get('/:application', auth.required, function (req, res, next) {
|
router.get('/:application', auth.required, function (req, res, next) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
req.payload ? User.findById(req.payload.id) : null,
|
req.payload ? User.findById(req.payload.id) : null,
|
||||||
@@ -117,6 +125,9 @@ router.get('/:application', auth.required, function (req, res, next) {
|
|||||||
}).catch(next);
|
}).catch(next);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update an application
|
||||||
|
*/
|
||||||
router.put('/:application', auth.required, function (req, res, next) {
|
router.put('/:application', auth.required, function (req, res, next) {
|
||||||
User.findById(req.payload.id).then(function (user) {
|
User.findById(req.payload.id).then(function (user) {
|
||||||
if (req.application.author._id.toString() === req.payload.id.toString()) {
|
if (req.application.author._id.toString() === req.payload.id.toString()) {
|
||||||
@@ -141,7 +152,9 @@ router.put('/:application', auth.required, function (req, res, next) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// delete application
|
/**
|
||||||
|
* delete an application
|
||||||
|
*/
|
||||||
router.delete('/:application', auth.required, function (req, res, next) {
|
router.delete('/:application', auth.required, function (req, res, next) {
|
||||||
User.findById(req.payload.id).then(function (user) {
|
User.findById(req.payload.id).then(function (user) {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
@@ -149,7 +162,7 @@ router.delete('/:application', auth.required, function (req, res, next) {
|
|||||||
}
|
}
|
||||||
if (user.role == 'Admin' || req.application.author._id.toString() === req.payload.id.toString()) {
|
if (user.role == 'Admin' || req.application.author._id.toString() === req.payload.id.toString()) {
|
||||||
return req.application.remove().then(function () {
|
return req.application.remove().then(function () {
|
||||||
return res.sendStatus(204);
|
return res.json({ deleted: true });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return res.status(403).json({ errors: { "Forbidden": "Vous ne disposez pas des autorisations suffisantes" } });
|
return res.status(403).json({ errors: { "Forbidden": "Vous ne disposez pas des autorisations suffisantes" } });
|
||||||
|
|||||||
+1
-1
@@ -610,7 +610,7 @@ router.delete('/:jump', auth.required, function (req, res, next) {
|
|||||||
}
|
}
|
||||||
if (req.jump.author._id.toString() === req.payload.id.toString()) {
|
if (req.jump.author._id.toString() === req.payload.id.toString()) {
|
||||||
return req.jump.remove().then(function () {
|
return req.jump.remove().then(function () {
|
||||||
return res.sendStatus(204);
|
return res.json({ deleted: true });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return res.status(403).json({ errors: { "Forbidden": "Vous ne disposez pas des autorisations suffisantes" } });
|
return res.status(403).json({ errors: { "Forbidden": "Vous ne disposez pas des autorisations suffisantes" } });
|
||||||
|
|||||||
Reference in New Issue
Block a user