validation for sample
This commit is contained in:
@ -182,6 +182,34 @@ router.put('/sample/restore/' + IdValidate.parameter(), (req, res, next) => {
|
||||
});
|
||||
});
|
||||
|
||||
router.put('/sample/validate/' + IdValidate.parameter(), (req, res, next) => {
|
||||
if (!req.auth(res, ['maintain', 'admin'], 'basic')) return;
|
||||
|
||||
SampleModel.findById(req.params.id).lean().exec((err, data: any) => {
|
||||
if (err) return next(err);
|
||||
|
||||
if (!data) {
|
||||
return res.status(404).json({status: 'Not found'});
|
||||
}
|
||||
if (Object.keys(data.condition).length === 0) {
|
||||
return res.status(400).json({status: 'Sample without condition cannot be valid'});
|
||||
}
|
||||
|
||||
MeasurementModel.find({sample_id: mongoose.Types.ObjectId(req.params.id)}).lean().exec((err, data) => {
|
||||
if (err) return next(err);
|
||||
|
||||
if (data.length === 0) {
|
||||
return res.status(400).json({status: 'Sample without measurements cannot be valid'});
|
||||
}
|
||||
|
||||
SampleModel.findByIdAndUpdate(req.params.id, {status: globals.status.validated}).lean().exec(err => {
|
||||
if (err) return next(err);
|
||||
res.json({status: 'OK'});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
router.post('/sample/new', async (req, res, next) => {
|
||||
if (!req.auth(res, ['write', 'maintain', 'dev', 'admin'], 'basic')) return;
|
||||
|
||||
|
Reference in New Issue
Block a user