banana
/
definma-api
Archived
2
Fork 0

fixed deleting materials

This commit is contained in:
VLE2FE 2020-08-31 14:51:43 +02:00
parent b59b3ea9ea
commit 8f88023da2
1 changed files with 2 additions and 1 deletions

View File

@ -122,7 +122,8 @@ router.delete('/material/' + IdValidate.parameter(), (req, res, next) => {
if (!req.auth(res, ['write', 'dev', 'admin'], 'basic')) return;
// check if there are still samples referencing this material
SampleModel.find({'material_id': new mongoose.Types.ObjectId(req.params.id)}).lean().exec((err, data) => {
SampleModel.find({'material_id': new mongoose.Types.ObjectId(req.params.id), status: {$ne: globals.status.del}})
.lean().exec((err, data) => {
if (err) return next(err);
if (data.length) {
return res.status(400).json({status: 'Material still in use'});