delete measurements with sample
This commit is contained in:
parent
54168e4500
commit
d58026426c
@ -69,7 +69,7 @@
|
|||||||
put:
|
put:
|
||||||
summary: change sample
|
summary: change sample
|
||||||
description: 'Auth: basic, levels: write, maintain, dev, admin <br>Only maintain and admin are allowed to edit samples created by another user'
|
description: 'Auth: basic, levels: write, maintain, dev, admin <br>Only maintain and admin are allowed to edit samples created by another user'
|
||||||
x-doc: status is reset to 0 on any changes, deleted samples cannot be changed # TODO
|
x-doc: status is reset to 0 on any changes, deleted samples cannot be changed
|
||||||
tags:
|
tags:
|
||||||
- /sample
|
- /sample
|
||||||
security:
|
security:
|
||||||
|
@ -2,13 +2,15 @@ import should from 'should/as-function';
|
|||||||
import SampleModel from '../models/sample';
|
import SampleModel from '../models/sample';
|
||||||
import NoteModel from '../models/note';
|
import NoteModel from '../models/note';
|
||||||
import NoteFieldModel from '../models/note_field';
|
import NoteFieldModel from '../models/note_field';
|
||||||
|
import MeasurementModel from '../models/measurement';
|
||||||
import TestHelper from "../test/helper";
|
import TestHelper from "../test/helper";
|
||||||
import globals from '../globals';
|
import globals from '../globals';
|
||||||
|
import mongoose from 'mongoose';
|
||||||
|
|
||||||
// TODO: generate output for ML in format DPT -> data, implement filtering, field selection
|
// TODO: generate output for ML in format DPT -> data, implement filtering, field selection
|
||||||
|
// TODO: generate csv
|
||||||
// TODO: filter by not completely filled/no measurements
|
// TODO: filter by not completely filled/no measurements
|
||||||
// TODO: write script for data import
|
// TODO: write script for data import
|
||||||
// TODO: delete everything (measurements, condition) with sample
|
|
||||||
// TODO: allow adding sample numbers for existing samples
|
// TODO: allow adding sample numbers for existing samples
|
||||||
// TODO: Do not allow validation or measurement entry without condition
|
// TODO: Do not allow validation or measurement entry without condition
|
||||||
|
|
||||||
@ -752,6 +754,24 @@ describe('/sample', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('deletes associated measurements', done => {
|
||||||
|
TestHelper.request(server, done, {
|
||||||
|
method: 'delete',
|
||||||
|
url: '/sample/400000000000000000000001',
|
||||||
|
auth: {basic: 'janedoe'},
|
||||||
|
httpStatus: 200
|
||||||
|
}).end((err, res) => {
|
||||||
|
if (err) return done(err);
|
||||||
|
should(res.body).be.eql({status: 'OK'});
|
||||||
|
MeasurementModel.find({sample_id: mongoose.Types.ObjectId('400000000000000000000001')}).lean().exec((err, data: any) => {
|
||||||
|
if (err) return done(err);
|
||||||
|
should(data).matchEach(sample => {
|
||||||
|
should(sample).have.property('status', -1);
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
it('rejects deleting samples of other users for write users', done => {
|
it('rejects deleting samples of other users for write users', done => {
|
||||||
TestHelper.request(server, done, {
|
TestHelper.request(server, done, {
|
||||||
method: 'delete',
|
method: 'delete',
|
||||||
@ -768,7 +788,6 @@ describe('/sample', () => {
|
|||||||
httpStatus: 404
|
httpStatus: 404
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('rejects deleting a sample referenced by conditions'); // TODO after decision
|
|
||||||
it('rejects requests from a read user', done => {
|
it('rejects requests from a read user', done => {
|
||||||
TestHelper.request(server, done, {
|
TestHelper.request(server, done, {
|
||||||
method: 'delete',
|
method: 'delete',
|
||||||
|
@ -10,7 +10,7 @@ import MaterialModel from '../models/material';
|
|||||||
import NoteModel from '../models/note';
|
import NoteModel from '../models/note';
|
||||||
import NoteFieldModel from '../models/note_field';
|
import NoteFieldModel from '../models/note_field';
|
||||||
import IdValidate from './validate/id';
|
import IdValidate from './validate/id';
|
||||||
import mongoose from "mongoose";
|
import mongoose from 'mongoose';
|
||||||
import ConditionTemplateModel from '../models/condition_template';
|
import ConditionTemplateModel from '../models/condition_template';
|
||||||
import ParametersValidate from './validate/parameters';
|
import ParametersValidate from './validate/parameters';
|
||||||
import globals from '../globals';
|
import globals from '../globals';
|
||||||
@ -141,18 +141,24 @@ router.delete('/sample/' + IdValidate.parameter(), (req, res, next) => {
|
|||||||
|
|
||||||
await SampleModel.findByIdAndUpdate(req.params.id, {status:globals.status.deleted}).lean().exec(err => { // set sample status
|
await SampleModel.findByIdAndUpdate(req.params.id, {status:globals.status.deleted}).lean().exec(err => { // set sample status
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
if (sampleData.note_id !== null) { // handle notes
|
|
||||||
NoteModel.findById(sampleData.note_id).lean().exec((err, data: any) => { // find notes to update note_fields
|
// set status of associated measurements also to deleted
|
||||||
if (err) return next(err);
|
MeasurementModel.update({sample_id: mongoose.Types.ObjectId(req.params.id)}, {status: -1}).lean().exec(err => {
|
||||||
if (data.hasOwnProperty('custom_fields')) { // update note_fields
|
if (err) return next(err);
|
||||||
customFieldsChange(Object.keys(data.custom_fields), -1);
|
|
||||||
}
|
if (sampleData.note_id !== null) { // handle notes
|
||||||
|
NoteModel.findById(sampleData.note_id).lean().exec((err, data: any) => { // find notes to update note_fields
|
||||||
|
if (err) return next(err);
|
||||||
|
if (data.hasOwnProperty('custom_fields')) { // update note_fields
|
||||||
|
customFieldsChange(Object.keys(data.custom_fields), -1);
|
||||||
|
}
|
||||||
|
res.json({status: 'OK'});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
res.json({status: 'OK'});
|
res.json({status: 'OK'});
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
else {
|
|
||||||
res.json({status: 'OK'});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user