Refactoring

This commit is contained in:
Rampeur
2024-05-09 02:20:52 +02:00
parent a4d2b76bc5
commit 2a40da8c8e
2 changed files with 17 additions and 4 deletions
+16 -3
View File
@@ -20,6 +20,9 @@ router.param('application', function (req, res, next, slug) {
}).catch(next);
});
/**
* return all applications
*/
router.get('/', auth.required, function (req, res, next) {
let query = {};
let limit = 25;
@@ -68,6 +71,9 @@ router.get('/', auth.required, function (req, res, next) {
}).catch(next);
});
/**
* save an application
*/
router.post('/', auth.required, function (req, res, next) {
Promise.all([
User.findById(req.payload.id),
@@ -106,7 +112,9 @@ router.post('/', auth.required, function (req, res, next) {
}).catch(next);
});
// return an application
/**
* return an application
*/
router.get('/:application', auth.required, function (req, res, next) {
Promise.all([
req.payload ? User.findById(req.payload.id) : null,
@@ -117,6 +125,9 @@ router.get('/:application', auth.required, function (req, res, next) {
}).catch(next);
});
/**
* update an application
*/
router.put('/:application', auth.required, function (req, res, next) {
User.findById(req.payload.id).then(function (user) {
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) {
User.findById(req.payload.id).then(function (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()) {
return req.application.remove().then(function () {
return res.sendStatus(204);
return res.json({ deleted: true });
});
} else {
return res.status(403).json({ errors: { "Forbidden": "Vous ne disposez pas des autorisations suffisantes" } });
+1 -1
View File
@@ -610,7 +610,7 @@ router.delete('/:jump', auth.required, function (req, res, next) {
}
if (req.jump.author._id.toString() === req.payload.id.toString()) {
return req.jump.remove().then(function () {
return res.sendStatus(204);
return res.json({ deleted: true });
});
} else {
return res.status(403).json({ errors: { "Forbidden": "Vous ne disposez pas des autorisations suffisantes" } });