-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.js
More file actions
28 lines (27 loc) · 707 Bytes
/
delete.js
File metadata and controls
28 lines (27 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var keystone = require('../../../');
module.exports = function(req, res) {
if (!keystone.security.csrf.validate(req)) {
return res.apiError('invalid csrf');
}
if (req.list.get('nodelete')) {
return res.apiError('nodelete');
}
if (req.user && req.params.id === req.user.id) {
return res.apiError('not allowed', 'You can not delete yourself');
}
req.list.model.findById(req.params.id).exec(function (err, item) {
if (err) {
return res.apiError('database error', err);
}
if (!item) {
return res.apiError(404);
}
item.remove(function (err) {
if (err) return res.apiError('database error', err);
return res.json({
success: true,
id: req.params.id
});
});
});
};