diff --git a/api/sample.yaml b/api/sample.yaml index b6689d9..52b5705 100644 --- a/api/sample.yaml +++ b/api/sample.yaml @@ -66,7 +66,8 @@ %5D%7D"]' responses: 200: - description: samples overview (if the csv parameter is set, this is in CSV instead of JSON format) + description: samples overview (output depends on the fields specified)
+ if the csv parameter is set, this is in CSV instead of JSON format headers: x-total-items: description: Total number of available items when from-id is not specified and spectrum field is not @@ -79,7 +80,7 @@ schema: type: array items: - $ref: 'api.yaml#/components/schemas/SampleRefs' + $ref: 'api.yaml#/components/schemas/SampleDetail' 400: $ref: 'api.yaml#/components/responses/400' 401: diff --git a/api/schemas.yaml b/api/schemas.yaml index c1645da..16c11a3 100644 --- a/api/schemas.yaml +++ b/api/schemas.yaml @@ -106,6 +106,10 @@ SampleDetail: user: type: string example: admin + status: + type: string + description: can be deleted/new/validated + example: new Material: allOf: diff --git a/src/db.ts b/src/db.ts index 8f72f81..bba4cb2 100644 --- a/src/db.ts +++ b/src/db.ts @@ -7,7 +7,7 @@ import ChangelogModel from './models/changelog'; // database urls, prod db url is retrieved automatically const TESTING_URL = 'mongodb://localhost/dfopdb_test'; const DEV_URL = 'mongodb://localhost/dfopdb'; -const debugging = false; +const debugging = true; if (process.env.NODE_ENV !== 'production' && debugging) { mongoose.set('debug', true); // enable mongoose debug diff --git a/src/globals.ts b/src/globals.ts index f51bf57..2928a89 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -6,11 +6,11 @@ const globals = { 'admin' ], - status: { // document statuses - deleted: -1, - new: 0, - validated: 10, - } + status: [ // document statuses + 'deleted', + 'new', + 'validated', + ] }; export default globals; \ No newline at end of file diff --git a/src/models/material.ts b/src/models/material.ts index 0c1629a..4790a44 100644 --- a/src/models/material.ts +++ b/src/models/material.ts @@ -9,7 +9,7 @@ const MaterialSchema = new mongoose.Schema({ group_id: {type: mongoose.Schema.Types.ObjectId, ref: MaterialGroupsModel}, properties: mongoose.Schema.Types.Mixed, numbers: [String], - status: Number + status: String }, {minimize: false}); // changelog query helper diff --git a/src/models/measurement.ts b/src/models/measurement.ts index 55267ec..d83c466 100644 --- a/src/models/measurement.ts +++ b/src/models/measurement.ts @@ -9,7 +9,7 @@ const MeasurementSchema = new mongoose.Schema({ sample_id: {type: mongoose.Schema.Types.ObjectId, ref: SampleModel}, values: mongoose.Schema.Types.Mixed, measurement_template: {type: mongoose.Schema.Types.ObjectId, ref: MeasurementTemplateModel}, - status: Number + status: String }, {minimize: false}); // changelog query helper diff --git a/src/models/sample.ts b/src/models/sample.ts index 8eec7bd..fd8f53e 100644 --- a/src/models/sample.ts +++ b/src/models/sample.ts @@ -14,7 +14,7 @@ const SampleSchema = new mongoose.Schema({ material_id: {type: mongoose.Schema.Types.ObjectId, ref: MaterialModel}, note_id: {type: mongoose.Schema.Types.ObjectId, ref: NoteModel}, user_id: {type: mongoose.Schema.Types.ObjectId, ref: UserModel}, - status: Number + status: String }, {minimize: false}); // changelog query helper diff --git a/src/routes/material.spec.ts b/src/routes/material.spec.ts index fa97483..0f362ae 100644 --- a/src/routes/material.spec.ts +++ b/src/routes/material.spec.ts @@ -23,7 +23,7 @@ describe('/material', () => { }).end((err, res) => { if (err) return done(err); const json = require('../test/db.json'); - should(res.body).have.lengthOf(json.collections.materials.filter(e => e.status === globals.status.validated).length); + should(res.body).have.lengthOf(json.collections.materials.filter(e => e.status === 'validated').length); should(res.body).matchEach(material => { should(material).have.only.keys('_id', 'name', 'supplier', 'group', 'properties', 'numbers'); should(material).have.property('_id').be.type('string'); @@ -45,7 +45,7 @@ describe('/material', () => { }).end((err, res) => { if (err) return done(err); const json = require('../test/db.json'); - should(res.body).have.lengthOf(json.collections.materials.filter(e => e.status === globals.status.validated).length); + should(res.body).have.lengthOf(json.collections.materials.filter(e => e.status === 'validated').length); should(res.body).matchEach(material => { should(material).have.only.keys('_id', 'name', 'supplier', 'group', 'properties', 'numbers'); should(material).have.property('_id').be.type('string'); @@ -67,7 +67,7 @@ describe('/material', () => { }).end((err, res) => { if (err) return done(err); const json = require('../test/db.json'); - should(res.body).have.lengthOf(json.collections.materials.filter(e => e.status === globals.status.new).length); + should(res.body).have.lengthOf(json.collections.materials.filter(e => e.status === 'new').length); should(res.body).matchEach(material => { should(material).have.only.keys('_id', 'name', 'supplier', 'group', 'properties', 'numbers'); should(material).have.property('_id').be.type('string'); @@ -109,7 +109,7 @@ describe('/material', () => { if (err) return done(err); const json = require('../test/db.json'); let asyncCounter = res.body.length; - should(res.body).have.lengthOf(json.collections.materials.filter(e => e.status ===globals.status.new).length); + should(res.body).have.lengthOf(json.collections.materials.filter(e => e.status ==='new').length); should(res.body).matchEach(material => { should(material).have.only.keys('_id', 'name', 'supplier', 'group', 'properties', 'numbers'); should(material).have.property('_id').be.type('string'); @@ -119,7 +119,7 @@ describe('/material', () => { should(material.properties).have.property('material_template').be.type('string'); should(material.numbers).be.instanceof(Array); MaterialModel.findById(material._id).lean().exec((err, data) => { - should(data).have.property('status',globals.status.new); + should(data).have.property('status','new'); if (--asyncCounter === 0) { done(); } @@ -137,7 +137,7 @@ describe('/material', () => { if (err) return done(err); const json = require('../test/db.json'); let asyncCounter = res.body.length; - should(res.body).have.lengthOf(json.collections.materials.filter(e => e.status ===globals.status.deleted).length); + should(res.body).have.lengthOf(json.collections.materials.filter(e => e.status ==='deleted').length); should(res.body).matchEach(material => { should(material).have.only.keys('_id', 'name', 'supplier', 'group', 'properties', 'numbers'); should(material).have.property('_id').be.type('string'); @@ -147,7 +147,7 @@ describe('/material', () => { should(material.properties).have.property('material_template').be.type('string'); should(material.numbers).be.instanceof(Array); MaterialModel.findById(material._id).lean().exec((err, data) => { - should(data).have.property('status',globals.status.deleted); + should(data).have.property('status','deleted'); if (--asyncCounter === 0) { done(); } @@ -273,7 +273,7 @@ describe('/material', () => { should(res.body).be.eql({_id: '100000000000000000000001', name: 'Stanyl TW 200 F8', supplier: 'DSM', group: 'PA46', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 40, carbon_fiber: 0}, numbers: ['5514263423', '5514263422']}); MaterialModel.findById('100000000000000000000001').lean().exec((err, data) => { if (err) return done(err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); MaterialGroupModel.find({name: 'PA46'}).lean().exec((err, data) => { if (err) return done(err); should(data).have.lengthOf(1); @@ -300,7 +300,7 @@ describe('/material', () => { should(res.body).be.eql({_id: '100000000000000000000001', name: 'Stanyl TW 200 F8', supplier: 'DSM', group: 'PA46', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 40, carbon_fiber: 0}, numbers: ['5514263423', '5514263422']}); MaterialModel.findById('100000000000000000000001').lean().exec((err, data) => { if (err) return done(err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); done(); }); }); @@ -317,7 +317,7 @@ describe('/material', () => { should(res.body).be.eql({_id: '100000000000000000000001', name: 'Stanyl TW 200 F8', supplier: 'DSM', group: 'PA46', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 40, carbon_fiber: 0}, numbers: ['5514263423', '5514263422']}); MaterialModel.findById('100000000000000000000001').lean().exec((err, data) => { if (err) return done(err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); done(); }); }); @@ -337,7 +337,7 @@ describe('/material', () => { data._id = data._id.toString(); data.group_id = data.group_id.toString(); data.supplier_id = data.supplier_id.toString(); - should(data).be.eql({_id: '100000000000000000000001', name: 'UltramidTKR4355G7_2', supplier_id: '110000000000000000000002', group_id: '900000000000000000000002', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 35, carbon_fiber: 0}, numbers: ['5514212901', '5514612901'], status: 0, __v: 0}); + should(data).be.eql({_id: '100000000000000000000001', name: 'UltramidTKR4355G7_2', supplier_id: '110000000000000000000002', group_id: '900000000000000000000002', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 35, carbon_fiber: 0}, numbers: ['5514212901', '5514612901'], status: 'new', __v: 0}); MaterialGroupModel.find({name: 'PA6/6T'}).lean().exec((err, data) => { if (err) return done(err); should(data).have.lengthOf(1); @@ -364,7 +364,7 @@ describe('/material', () => { dataAdd: { group_id: '900000000000000000000002', supplier_id: '110000000000000000000002', - status: 0 + status: 'new' }, dataIgn: ['supplier', 'group'] } @@ -541,7 +541,7 @@ describe('/material', () => { data.group_id = data.group_id.toString(); data.supplier_id = data.supplier_id.toString(); data.properties.material_template = data.properties.material_template.toString(); - should(data).be.eql({_id: '100000000000000000000002', name: 'Ultramid T KR 4355 G7', supplier_id: '110000000000000000000002', group_id: '900000000000000000000002', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 35, carbon_fiber: 0}, numbers: ['5514212901', '5514612901'], status: -1, __v: 0} + should(data).be.eql({_id: '100000000000000000000002', name: 'Ultramid T KR 4355 G7', supplier_id: '110000000000000000000002', group_id: '900000000000000000000002', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 35, carbon_fiber: 0}, numbers: ['5514212901', '5514612901'], status: 'deleted', __v: 0} ); done(); }); @@ -555,7 +555,7 @@ describe('/material', () => { httpStatus: 200, log: { collection: 'materials', - dataAdd: { status: -1} + dataAdd: { status: 'deleted'} } }); }); @@ -622,7 +622,7 @@ describe('/material', () => { should(res.body).be.eql({status: 'OK'}); MaterialModel.findById('100000000000000000000008').lean().exec((err, data: any) => { if (err) return done(err); - should(data).have.property('status',globals.status.new); + should(data).have.property('status','new'); done(); }); }); @@ -637,7 +637,7 @@ describe('/material', () => { log: { collection: 'materials', dataAdd: { - status: 0 + status: 'new' } } }); @@ -692,7 +692,7 @@ describe('/material', () => { should(res.body).be.eql({status: 'OK'}); MaterialModel.findById('100000000000000000000007').lean().exec((err, data: any) => { if (err) return done(err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); done(); }); }); @@ -707,7 +707,7 @@ describe('/material', () => { log: { collection: 'materials', dataAdd: { - status: 10 + status: 'validated' } } }); @@ -790,7 +790,7 @@ describe('/material', () => { should(materialData[0].properties).have.property('mineral', 0); should(materialData[0].properties).have.property('glass_fiber', 30); should(materialData[0].properties).have.property('carbon_fiber', 0); - should(materialData[0]).have.property('status',globals.status.new); + should(materialData[0]).have.property('status','new'); should(materialData[0].numbers).have.lengthOf(0); MaterialGroupModel.findById(materialData[0].group_id).lean().exec((err, data) => { if (err) return done(err); @@ -813,7 +813,7 @@ describe('/material', () => { req: {name: 'Crastin CE 2510', supplier: 'Du Pont', group: 'PBT', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 30, carbon_fiber: 0}, numbers: []}, log: { collection: 'materials', - dataAdd: {status: 0}, + dataAdd: {status: 'new'}, dataIgn: ['group_id', 'supplier_id', 'group', 'supplier'] } }); diff --git a/src/routes/material.ts b/src/routes/material.ts index dfd7cbf..1d9f135 100644 --- a/src/routes/material.ts +++ b/src/routes/material.ts @@ -28,14 +28,14 @@ router.get('/materials', (req, res, next) => { if (filters.hasOwnProperty('status')) { if(filters.status === 'all') { - conditions = {$or: [{status: globals.status.validated}, {status: globals.status.new}]} + conditions = {$or: [{status: 'validated'}, {status: 'new'}]} } else { - conditions = {status: globals.status[filters.status]}; + conditions = {status: filters.status}; } } else { // default - conditions = {status: globals.status.validated}; + conditions = {status: 'validated'}; } MaterialModel.find(conditions).populate('group_id').populate('supplier_id').lean().exec((err, data) => { @@ -49,7 +49,7 @@ router.get('/materials', (req, res, next) => { router.get('/materials/:state(new|deleted)', (req, res, next) => { if (!req.auth(res, ['dev', 'admin'], 'basic')) return; - MaterialModel.find({status: globals.status[req.params.state]}).populate('group_id').populate('supplier_id') + MaterialModel.find({status: req.params.state}).populate('group_id').populate('supplier_id') .lean().exec((err, data) => { if (err) return next(err); @@ -69,7 +69,7 @@ router.get('/material/' + IdValidate.parameter(), (req, res, next) => { } // deleted materials only available for dev/admin - if (data.status === globals.status.deleted && !req.auth(res, ['dev', 'admin'], 'all')) return; + if (data.status === 'deleted' && !req.auth(res, ['dev', 'admin'], 'all')) return; res.json(MaterialValidate.output(data)); }); }); @@ -84,7 +84,7 @@ router.put('/material/' + IdValidate.parameter(), (req, res, next) => { if (!materialData) { return res.status(404).json({status: 'Not found'}); } - if (materialData.status === globals.status.deleted) { + if (materialData.status === 'deleted') { return res.status(403).json({status: 'Forbidden'}); } if (material.hasOwnProperty('name') && material.name !== materialData.name) { @@ -105,7 +105,7 @@ router.put('/material/' + IdValidate.parameter(), (req, res, next) => { // check for changes if (!_.isEqual(_.pick(IdValidate.stringify(materialData), _.keys(material)), IdValidate.stringify(material))) { - material.status = globals.status.new; // set status to new + material.status = 'new'; // set status to new } await MaterialModel.findByIdAndUpdate(req.params.id, material, {new: true}) @@ -125,7 +125,7 @@ router.delete('/material/' + IdValidate.parameter(), (req, res, next) => { if (data.length) { return res.status(400).json({status: 'Material still in use'}); } - MaterialModel.findByIdAndUpdate(req.params.id, {status:globals.status.deleted}) + MaterialModel.findByIdAndUpdate(req.params.id, {status:'deleted'}) .log(req).populate('group_id').populate('supplier_id').lean().exec((err, data) => { if (err) return next(err); if (data) { @@ -141,13 +141,13 @@ router.delete('/material/' + IdValidate.parameter(), (req, res, next) => { router.put('/material/restore/' + IdValidate.parameter(), (req, res, next) => { if (!req.auth(res, ['dev', 'admin'], 'basic')) return; - setStatus(globals.status.new, req, res, next); + setStatus('new', req, res, next); }); router.put('/material/validate/' + IdValidate.parameter(), (req, res, next) => { if (!req.auth(res, ['dev', 'admin'], 'basic')) return; - setStatus(globals.status.validated, req, res, next); + setStatus('validated', req, res, next); }); router.post('/material/new', async (req, res, next) => { @@ -163,7 +163,7 @@ router.post('/material/new', async (req, res, next) => { if (!material) return; if (!await propertiesCheck(material.properties, 'new', res, next)) return; - material.status = globals.status.new; // set status to new + material.status = 'new'; // set status to new await new MaterialModel(material).save(async (err, data) => { if (err) return next(err); db.log(req, 'materials', {_id: data._id}, data.toObject()); diff --git a/src/routes/measurement.spec.ts b/src/routes/measurement.spec.ts index e3d0d68..3b1c5ee 100644 --- a/src/routes/measurement.spec.ts +++ b/src/routes/measurement.spec.ts @@ -104,7 +104,7 @@ describe('/measurement', () => { should(res.body).be.eql({_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]], device: 'Alpha I'}, measurement_template: '300000000000000000000001'}); MeasurementModel.findById('800000000000000000000001').lean().exec((err, data: any) => { if (err) return done(err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); done(); }); }); @@ -121,7 +121,7 @@ describe('/measurement', () => { should(res.body).be.eql({_id: '800000000000000000000002', sample_id: '400000000000000000000002', values: {'weight %': 0.5, 'standard deviation': 0.2}, measurement_template: '300000000000000000000002'}); MeasurementModel.findById('800000000000000000000002').lean().exec((err, data: any) => { if (err) return done(err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); done(); }); }); @@ -140,7 +140,7 @@ describe('/measurement', () => { should(data).have.only.keys('_id', 'sample_id', 'values', 'measurement_template', 'status', '__v'); should(data.sample_id.toString()).be.eql('400000000000000000000001'); should(data.measurement_template.toString()).be.eql('300000000000000000000001'); - should(data).have.property('status',globals.status.new); + should(data).have.property('status','new'); should(data).have.property('values'); should(data.values).have.property('dpt', [[1,2],[3,4],[5,6]]); done(); @@ -159,7 +159,7 @@ describe('/measurement', () => { dataAdd: { measurement_template: '300000000000000000000001', sample_id: '400000000000000000000001', - status: 0 + status: 'new' } } }); @@ -328,7 +328,7 @@ describe('/measurement', () => { should(res.body).be.eql({status: 'OK'}); MeasurementModel.findById('800000000000000000000001').lean().exec((err, data) => { if (err) return done(err); - should(data).have.property('status',globals.status.deleted); + should(data).have.property('status','deleted'); done(); }); }); @@ -342,7 +342,7 @@ describe('/measurement', () => { log: { collection: 'measurements', dataAdd: { - status: -1 + status: 'deleted' } } }); @@ -418,7 +418,7 @@ describe('/measurement', () => { should(res.body).be.eql({status: 'OK'}); MeasurementModel.findById('800000000000000000000004').lean().exec((err, data: any) => { if (err) return done(err); - should(data).have.property('status',globals.status.new); + should(data).have.property('status','new'); done(); }); }); @@ -433,7 +433,7 @@ describe('/measurement', () => { log: { collection: 'measurements', dataAdd: { - status: 0 + status: 'new' } } }); @@ -488,7 +488,7 @@ describe('/measurement', () => { should(res.body).be.eql({status: 'OK'}); MeasurementModel.findById('800000000000000000000003').lean().exec((err, data: any) => { if (err) return done(err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); done(); }); }); @@ -503,7 +503,7 @@ describe('/measurement', () => { log: { collection: 'measurements', dataAdd: { - status: 10 + status: 'validated' } } }); @@ -579,7 +579,7 @@ describe('/measurement', () => { should(data).have.only.keys('_id', 'sample_id', 'values', 'measurement_template', 'status', '__v'); should(data.sample_id.toString()).be.eql('400000000000000000000001'); should(data.measurement_template.toString()).be.eql('300000000000000000000002'); - should(data).have.property('status', 0); + should(data).have.property('status', 'new'); should(data).have.property('values'); should(data.values).have.property('weight %', 0.8); should(data.values).have.property('standard deviation', 0.1); @@ -597,7 +597,7 @@ describe('/measurement', () => { log: { collection: 'measurements', dataAdd: { - status: 0 + status: 'new' } } }); diff --git a/src/routes/measurement.ts b/src/routes/measurement.ts index 5078379..352a98d 100644 --- a/src/routes/measurement.ts +++ b/src/routes/measurement.ts @@ -23,7 +23,7 @@ router.get('/measurement/' + IdValidate.parameter(), (req, res, next) => { return res.status(404).json({status: 'Not found'}); } // deleted measurements only available for dev/admin - if (data.status === globals.status.deleted && !req.auth(res, ['dev', 'admin'], 'all')) return; + if (data.status === 'deleted' && !req.auth(res, ['dev', 'admin'], 'all')) return; res.json(MeasurementValidate.output(data, req)); }); @@ -40,7 +40,7 @@ router.put('/measurement/' + IdValidate.parameter(), async (req, res, next) => { if (!data) { return res.status(404).json({status: 'Not found'}); } - if (data.status === globals.status.deleted) { + if (data.status === 'deleted') { return res.status(403).json({status: 'Forbidden'}); } @@ -53,7 +53,7 @@ router.put('/measurement/' + IdValidate.parameter(), async (req, res, next) => { if (measurement.values) { // fill not changed values from database measurement.values = _.assign({}, data.values, measurement.values); if (!_.isEqual(measurement.values, data.values)) { - measurement.status = globals.status.new; // set status to new + measurement.status = 'new'; // set status to new } } @@ -74,7 +74,7 @@ router.delete('/measurement/' + IdValidate.parameter(), (req, res, next) => { return res.status(404).json({status: 'Not found'}); } if (!await sampleIdCheck(data, req, res, next)) return; - await MeasurementModel.findByIdAndUpdate(req.params.id, {status:globals.status.deleted}) + await MeasurementModel.findByIdAndUpdate(req.params.id, {status:'deleted'}) .log(req).lean().exec(err => { if (err) return next(err); return res.json({status: 'OK'}); @@ -85,13 +85,13 @@ router.delete('/measurement/' + IdValidate.parameter(), (req, res, next) => { router.put('/measurement/restore/' + IdValidate.parameter(), (req, res, next) => { if (!req.auth(res, ['dev', 'admin'], 'basic')) return; - setStatus(globals.status.new, req, res, next); + setStatus('new', req, res, next); }); router.put('/measurement/validate/' + IdValidate.parameter(), (req, res, next) => { if (!req.auth(res, ['dev', 'admin'], 'basic')) return; - setStatus(globals.status.validated, req, res, next); + setStatus('validated', req, res, next); }); router.post('/measurement/new', async (req, res, next) => { @@ -104,7 +104,7 @@ router.post('/measurement/new', async (req, res, next) => { measurement.values = await templateCheck(measurement, 'new', res, next); if (!measurement.values) return; - measurement.status = 0; + measurement.status = 'new'; await new MeasurementModel(measurement).save((err, data) => { if (err) return next(err); db.log(req, 'measurements', {_id: data._id}, data.toObject()); diff --git a/src/routes/sample.spec.ts b/src/routes/sample.spec.ts index 9c6b2ec..c32146a 100644 --- a/src/routes/sample.spec.ts +++ b/src/routes/sample.spec.ts @@ -4,7 +4,6 @@ import NoteModel from '../models/note'; import NoteFieldModel from '../models/note_field'; import MeasurementModel from '../models/measurement'; import TestHelper from "../test/helper"; -import globals from '../globals'; import mongoose from 'mongoose'; @@ -31,7 +30,7 @@ describe('/sample', () => { }).end((err, res) => { if (err) return done(err); const json = require('../test/db.json'); - should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ===globals.status.validated).length); + should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ==='validated').length); should(res.body).matchEach(sample => { should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added'); should(sample).have.property('_id').be.type('string'); @@ -58,7 +57,7 @@ describe('/sample', () => { }).end((err, res) => { if (err) return done(err); const json = require('../test/db.json'); - should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ===globals.status.validated).length); + should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ==='validated').length); should(res.body).matchEach(sample => { should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added'); should(sample).have.property('_id').be.type('string'); @@ -85,7 +84,7 @@ describe('/sample', () => { }).end((err, res) => { if (err) return done(err); const json = require('../test/db.json'); - should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ===globals.status.new).length); + should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ==='new').length); should(res.body).matchEach(sample => { should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added'); should(sample).have.property('_id').be.type('string'); @@ -245,6 +244,19 @@ describe('/sample', () => { done(); }); }); + it('adds the status if specified', done => { + TestHelper.request(server, done, { + method: 'get', + url: '/samples?status=all&fields[]=number&fields[]=status', + auth: {basic: 'janedoe'}, + httpStatus: 200 + }).end((err, res) => { + if (err) return done(err); + should(res.body.find(e => e.number === '1')).have.property('status', 'validated'); + should(res.body.find(e => e.number === 'Rng36')).have.property('status', 'new'); + done(); + }); + }); it('adds the specified measurements', done => { TestHelper.request(server, done, { method: 'get', @@ -549,9 +561,9 @@ describe('/sample', () => { if (err) return done(err); const json = require('../test/db.json'); let asyncCounter = res.body.length; - should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ===globals.status.new).length); + should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ==='new').length); should(res.body).matchEach(sample => { - should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added'); + should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added'); should(sample).have.property('_id').be.type('string'); should(sample).have.property('number').be.type('string'); should(sample).have.property('type').be.type('string'); @@ -565,8 +577,9 @@ describe('/sample', () => { should(sample).have.property('note_id'); should(sample).have.property('user_id').be.type('string'); should(sample).have.property('added').be.type('string'); + should(sample).have.property('status').be.type('string'); SampleModel.findById(sample._id).lean().exec((err, data) => { - should(data).have.property('status',globals.status.new); + should(data).have.property('status','new'); if (--asyncCounter === 0) { done(); } @@ -584,9 +597,9 @@ describe('/sample', () => { if (err) return done(err); const json = require('../test/db.json'); let asyncCounter = res.body.length; - should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status === -1).length); + should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status === 'deleted').length); should(res.body).matchEach(sample => { - should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added'); + should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added'); should(sample).have.property('_id').be.type('string'); should(sample).have.property('number').be.type('string'); should(sample).have.property('type').be.type('string'); @@ -600,8 +613,9 @@ describe('/sample', () => { should(sample).have.property('note_id'); should(sample).have.property('user_id').be.type('string'); should(sample).have.property('added').be.type('string'); + should(sample).have.property('status').be.type('string'); SampleModel.findById(sample._id).lean().exec((err, data) => { - should(data).have.property('status',globals.status.deleted); + should(data).have.property('status','deleted'); if (--asyncCounter === 0) { done(); } @@ -677,7 +691,7 @@ describe('/sample', () => { url: '/sample/400000000000000000000003', auth: {basic: 'janedoe'}, httpStatus: 200, - res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], user: 'admin'} + res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], status: 'new', user: 'admin'} }); }); it('works with an API key', done => { @@ -686,7 +700,7 @@ describe('/sample', () => { url: '/sample/400000000000000000000003', auth: {key: 'janedoe'}, httpStatus: 200, - res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], user: 'admin'} + res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], status: 'new', user: 'admin'} }); }); it ('filters out spectral data for a write user', done => { @@ -695,7 +709,7 @@ describe('/sample', () => { url: '/sample/400000000000000000000001', auth: {basic: 'janedoe'}, httpStatus: 200, - res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {device: 'Alpha II'}, measurement_template: '300000000000000000000001'}]} + res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {device: 'Alpha II'}, measurement_template: '300000000000000000000001'}], status: 'validated'} }); }); it ('returns spectral data for an admin user', done => { @@ -704,7 +718,7 @@ describe('/sample', () => { url: '/sample/400000000000000000000001', auth: {basic: 'admin'}, httpStatus: 200, - res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[ 3997.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]],device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {dpt: [[ 3996.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]], device: 'Alpha II'}, measurement_template: '300000000000000000000001'}]} + res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[ 3997.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]],device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {dpt: [[ 3996.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]], device: 'Alpha II'}, measurement_template: '300000000000000000000001'}], status: 'validated'} }); }); it('returns a deleted sample for a dev/admin user', done => { @@ -713,7 +727,7 @@ describe('/sample', () => { url: '/sample/400000000000000000000005', auth: {basic: 'admin'}, httpStatus: 200, - res: {_id: '400000000000000000000005', number: 'Rng33', type: 'granulate', color: 'black', batch: '1653000308', condition: {condition_template: '200000000000000000000003'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {}, measurements: [], user: 'admin'} + res: {_id: '400000000000000000000005', number: 'Rng33', type: 'granulate', color: 'black', batch: '1653000308', condition: {condition_template: '200000000000000000000003'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {}, measurements: [], status: 'deleted', user: 'admin'} }); }); it('returns 403 for a write user when requesting a deleted sample', done => { @@ -757,7 +771,7 @@ describe('/sample', () => { auth: {basic: 'janedoe'}, httpStatus: 200, req: {}, - res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'} + res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'} }); }); it('keeps unchanged properties', done => { @@ -769,7 +783,7 @@ describe('/sample', () => { req: {type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', notes: {}} }).end((err, res) => { if (err) return done(err); - should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'}); + should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'}); SampleModel.findById('400000000000000000000001').lean().exec((err, data: any) => { if (err) return done (err); should(data).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', '__v'); @@ -781,7 +795,7 @@ describe('/sample', () => { should(data).have.property('condition', {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}); should(data.material_id.toString()).be.eql('100000000000000000000004'); should(data.user_id.toString()).be.eql('000000000000000000000002'); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); should(data).have.property('note_id', null); done(); }); @@ -796,10 +810,10 @@ describe('/sample', () => { req: {type: 'granulate'} }).end((err, res) => { if (err) return done(err); - should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'}); + should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'}); SampleModel.findById('400000000000000000000001').lean().exec((err, data: any) => { if (err) return done (err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); done(); }); }); @@ -813,10 +827,10 @@ describe('/sample', () => { req: {condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}} }).end((err, res) => { if (err) return done(err); - should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'}); + should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'}); SampleModel.findById('400000000000000000000001').lean().exec((err, data: any) => { if (err) return done (err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); done(); }); }); @@ -830,7 +844,7 @@ describe('/sample', () => { req: {notes: {comment: 'Stoff gesperrt', sample_references: []}} }).end((err, res) => { if (err) return done(err); - should(res.body).be.eql({_id: '400000000000000000000002', number: '21', type: 'granulate', color: 'natural', batch: '1560237365', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', note_id: '500000000000000000000001', user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'}); + should(res.body).be.eql({_id: '400000000000000000000002', number: '21', type: 'granulate', color: 'natural', batch: '1560237365', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', note_id: '500000000000000000000001', user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'}); SampleModel.findById('400000000000000000000002').lean().exec((err, data: any) => { if (err) return done (err); should(data).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', '__v'); @@ -844,7 +858,7 @@ describe('/sample', () => { should(data.condition.condition_template.toString()).be.eql('200000000000000000000001'); should(data.material_id.toString()).be.eql('100000000000000000000001'); should(data.user_id.toString()).be.eql('000000000000000000000002'); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); should(data.note_id.toString()).be.eql('500000000000000000000001'); done(); }); @@ -870,7 +884,7 @@ describe('/sample', () => { should(data).have.property('condition', {condition_template: '200000000000000000000003'}); should(data.material_id.toString()).be.eql('100000000000000000000002'); should(data.user_id.toString()).be.eql('000000000000000000000002'); - should(data).have.property('status',globals.status.new); + should(data).have.property('status','new'); should(data).have.property('note_id'); NoteModel.findById(data.note_id).lean().exec((err, data: any) => { if (err) return done (err); @@ -895,7 +909,7 @@ describe('/sample', () => { log: { collection: 'samples', dataAdd: { - status: 0 + status: 'new' }, dataIgn: ['notes', 'note_id'] } @@ -1097,7 +1111,7 @@ describe('/sample', () => { auth: {basic: 'janedoe'}, httpStatus: 200, req: {condition: {}}, - res: {_id: '400000000000000000000006', number: 'Rng36', type: 'granulate', color: 'black', batch: '', condition: {}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'} + res: {_id: '400000000000000000000006', number: 'Rng36', type: 'granulate', color: 'black', batch: '', condition: {}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'new', added: '2004-01-10T13:37:04.000Z'} }); }); it('rejects an old version of a condition template', done => { @@ -1117,7 +1131,7 @@ describe('/sample', () => { auth: {basic: 'admin'}, httpStatus: 200, req: {condition: {p1: 36, condition_template: '200000000000000000000004'}}, - res: {_id: '400000000000000000000004', number: '32', type: 'granulate', color: 'black', batch: '1653000308', condition: {p1: 36, condition_template: '200000000000000000000004'}, material_id: '100000000000000000000005', note_id: '500000000000000000000003', user_id: '000000000000000000000003', added: '2004-01-10T13:37:04.000Z'} + res: {_id: '400000000000000000000004', number: '32', type: 'granulate', color: 'black', batch: '1653000308', condition: {p1: 36, condition_template: '200000000000000000000004'}, material_id: '100000000000000000000005', note_id: '500000000000000000000003', user_id: '000000000000000000000003', status: 'new', added: '2004-01-10T13:37:04.000Z'} }); }); it('rejects changing back to an empty condition', done => { @@ -1164,7 +1178,7 @@ describe('/sample', () => { auth: {basic: 'admin'}, httpStatus: 200, req: {}, - res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {condition_template: '200000000000000000000001', material: 'copper', weeks: 3}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'} + res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {condition_template: '200000000000000000000001', material: 'copper', weeks: 3}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'} }); }); it('rejects requests from a read user', done => { @@ -1218,7 +1232,7 @@ describe('/sample', () => { should(data.condition.condition_template.toString()).be.eql('200000000000000000000001'); should(data.material_id.toString()).be.eql('100000000000000000000004'); should(data.user_id.toString()).be.eql('000000000000000000000002'); - should(data).have.property('status',globals.status.deleted); + should(data).have.property('status','deleted'); should(data).have.property('note_id', null); done(); }); @@ -1233,7 +1247,7 @@ describe('/sample', () => { log: { collection: 'samples', skip: 1, - dataAdd: {status: -1} + dataAdd: {status: 'deleted'} } }); }); @@ -1307,7 +1321,7 @@ describe('/sample', () => { should(res.body).be.eql({status: 'OK'}); SampleModel.findById('400000000000000000000001').lean().exec((err, data) => { if (err) return done(err); - should(data).have.property('status',globals.status.deleted); + should(data).have.property('status','deleted'); done(); }); }); @@ -1324,7 +1338,7 @@ describe('/sample', () => { 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); + should(sample).have.property('status', 'deleted'); }); done(); }); @@ -1386,7 +1400,7 @@ describe('/sample', () => { url: '/sample/number/33', auth: {basic: 'janedoe'}, httpStatus: 200, - res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], user: 'admin'} + res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], status: 'new', user: 'admin'} }); }); it('works with an API key', done => { @@ -1395,7 +1409,7 @@ describe('/sample', () => { url: '/sample/number/33', auth: {key: 'janedoe'}, httpStatus: 200, - res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], user: 'admin'} + res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], status: 'new', user: 'admin'} }); }); it('returns a deleted sample for a dev/admin user', done => { @@ -1404,7 +1418,7 @@ describe('/sample', () => { url: '/sample/number/Rng33', auth: {basic: 'admin'}, httpStatus: 200, - res: {_id: '400000000000000000000005', number: 'Rng33', type: 'granulate', color: 'black', batch: '1653000308', condition: {condition_template: '200000000000000000000003'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {}, measurements: [], user: 'admin'} + res: {_id: '400000000000000000000005', number: 'Rng33', type: 'granulate', color: 'black', batch: '1653000308', condition: {condition_template: '200000000000000000000003'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {}, measurements: [], status: 'deleted', user: 'admin'} }); }); it ('filters out spectral data for a write user', done => { @@ -1413,7 +1427,7 @@ describe('/sample', () => { url: '/sample/number/1', auth: {basic: 'janedoe'}, httpStatus: 200, - res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {device: 'Alpha II'}, measurement_template: '300000000000000000000001'}]} + res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {device: 'Alpha II'}, measurement_template: '300000000000000000000001'}], status: 'validated'} }); }); it ('returns spectral data for an admin user', done => { @@ -1422,7 +1436,7 @@ describe('/sample', () => { url: '/sample/number/1', auth: {basic: 'admin'}, httpStatus: 200, - res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[ 3997.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]],device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {dpt: [[ 3996.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]], device: 'Alpha II'}, measurement_template: '300000000000000000000001'}]} + res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[ 3997.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]],device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {dpt: [[ 3996.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]], device: 'Alpha II'}, measurement_template: '300000000000000000000001'}], status: 'validated'} }); }); it('returns 403 for a write user when requesting a deleted sample', done => { @@ -1471,7 +1485,7 @@ describe('/sample', () => { should(res.body).be.eql({status: 'OK'}); SampleModel.findById('400000000000000000000005').lean().exec((err, data: any) => { if (err) return done(err); - should(data).have.property('status',globals.status.new); + should(data).have.property('status','new'); done(); }); }); @@ -1488,7 +1502,7 @@ describe('/sample', () => { dataAdd: { group_id: '900000000000000000000002', supplier_id: '110000000000000000000002', - status: 0 + status: 'new' }, dataIgn: ['group_id', 'supplier_id'] } @@ -1544,7 +1558,7 @@ describe('/sample', () => { should(res.body).be.eql({status: 'OK'}); SampleModel.findById('400000000000000000000003').lean().exec((err, data: any) => { if (err) return done(err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); done(); }); }); @@ -1561,7 +1575,7 @@ describe('/sample', () => { dataAdd: { group_id: '900000000000000000000002', supplier_id: '110000000000000000000002', - status: 10 + status: 'validated' }, dataIgn: ['group_id', 'supplier_id'] } @@ -1579,7 +1593,7 @@ describe('/sample', () => { should(res.body).be.eql({status: 'OK'}); SampleModel.findById('400000000000000000000006').lean().exec((err, data: any) => { if (err) return done(err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); done(); }); }); @@ -1596,7 +1610,7 @@ describe('/sample', () => { should(res.body).be.eql({status: 'OK'}); SampleModel.findById('400000000000000000000004').lean().exec((err, data: any) => { if (err) return done(err); - should(data).have.property('status',globals.status.validated); + should(data).have.property('status','validated'); done(); }); }); @@ -1648,7 +1662,7 @@ describe('/sample', () => { req: {color: 'black', type: 'granulate', batch: '1560237365', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}} }).end((err, res) => { if (err) return done (err); - should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added'); + should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added'); should(res.body).have.property('_id').be.type('string'); should(res.body).have.property('number', 'Rng37'); should(res.body).have.property('color', 'black'); @@ -1658,6 +1672,7 @@ describe('/sample', () => { should(res.body).have.property('material_id', '100000000000000000000001'); should(res.body).have.property('note_id').be.type('string'); should(res.body).have.property('user_id', '000000000000000000000002'); + should(res.body).have.property('status', 'new'); should(res.body).have.property('added').be.type('string'); should(new Date().getTime() - new Date(res.body.added).getTime()).be.below(1000); done(); @@ -1684,7 +1699,7 @@ describe('/sample', () => { should(data[0]).have.property('condition', {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}); should(data[0].material_id.toString()).be.eql('100000000000000000000001'); should(data[0].user_id.toString()).be.eql('000000000000000000000002'); - should(data[0]).have.property('status',globals.status.new); + should(data[0]).have.property('status','new'); should(data[0]).have.property('note_id'); NoteModel.findById(data[0].note_id).lean().exec((err, data: any) => { if (err) return done (err); @@ -1711,7 +1726,7 @@ describe('/sample', () => { dataAdd: { number: 'Rng37', user_id: '000000000000000000000002', - status: 0 + status: 'new' }, dataIgn: ['notes', 'note_id'] } @@ -1763,7 +1778,7 @@ describe('/sample', () => { req: {color: 'black', type: 'granulate', batch: '1560237365', material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}} }).end((err, res) => { if (err) return done (err); - should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added'); + should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added'); should(res.body).have.property('_id').be.type('string'); should(res.body).have.property('number', 'Fe1'); should(res.body).have.property('color', 'black'); @@ -1772,6 +1787,7 @@ describe('/sample', () => { should(res.body).have.property('material_id', '100000000000000000000001'); should(res.body).have.property('note_id').be.type('string'); should(res.body).have.property('user_id', '000000000000000000000004'); + should(res.body).have.property('status', 'new'); should(res.body).have.property('added').be.type('string'); should(new Date().getTime() - new Date(res.body.added).getTime()).be.below(1500); done(); @@ -1786,7 +1802,7 @@ describe('/sample', () => { req: {color: 'black', type: 'granulate', batch: '1560237365', material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}} }).end((err, res) => { if (err) return done (err); - should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added'); + should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added'); should(res.body).have.property('_id').be.type('string'); should(res.body).have.property('number', 'Rng37'); should(res.body).have.property('color', 'black'); @@ -1796,6 +1812,7 @@ describe('/sample', () => { should(res.body).have.property('material_id', '100000000000000000000001'); should(res.body).have.property('note_id').be.type('string'); should(res.body).have.property('user_id', '000000000000000000000002'); + should(res.body).have.property('status', 'new'); should(res.body).have.property('added').be.type('string'); should(new Date().getTime() - new Date(res.body.added).getTime()).be.below(1000); done(); @@ -1830,7 +1847,7 @@ describe('/sample', () => { req: {number: 'Rng34', color: 'black', type: 'granulate', batch: '1560237365', material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}}, }).end((err, res) => { if (err) return done (err); - should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added'); + should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added'); should(res.body).have.property('_id').be.type('string'); should(res.body).have.property('number', 'Rng34'); should(res.body).have.property('color', 'black'); @@ -1840,6 +1857,7 @@ describe('/sample', () => { should(res.body).have.property('material_id', '100000000000000000000001'); should(res.body).have.property('note_id').be.type('string'); should(res.body).have.property('user_id', '000000000000000000000003'); + should(res.body).have.property('status', 'new'); should(res.body).have.property('added').be.type('string'); should(new Date().getTime() - new Date(res.body.added).getTime()).be.below(1000); done(); diff --git a/src/routes/sample.ts b/src/routes/sample.ts index 9b93aaa..3bbfe9c 100644 --- a/src/routes/sample.ts +++ b/src/routes/sample.ts @@ -14,7 +14,6 @@ import IdValidate from './validate/id'; import mongoose from 'mongoose'; import ConditionTemplateModel from '../models/condition_template'; import ParametersValidate from './validate/parameters'; -import globals from '../globals'; import db from '../db'; import csv from '../helpers/csv'; @@ -431,7 +430,7 @@ router.get('/samples', async (req, res, next) => { router.get('/samples/:state(new|deleted)', (req, res, next) => { if (!req.auth(res, ['dev', 'admin'], 'basic')) return; - SampleModel.find({status: globals.status[req.params.state]}).lean().exec((err, data) => { + SampleModel.find({status: req.params.state}).lean().exec((err, data) => { if (err) return next(err); // validate all and filter null values from validation errors res.json(_.compact(data.map(e => SampleValidate.output(e)))); @@ -469,7 +468,7 @@ router.put('/sample/' + IdValidate.parameter(), (req, res, next) => { if (!sampleData) { return res.status(404).json({status: 'Not found'}); } - if (sampleData.status === globals.status.deleted) { + if (sampleData.status === 'deleted') { return res.status(403).json({status: 'Forbidden'}); } @@ -520,7 +519,7 @@ router.put('/sample/' + IdValidate.parameter(), (req, res, next) => { // check for changes if (!_.isEqual(_.pick(IdValidate.stringify(sampleData), _.keys(sample)), _.omit(sample, ['notes']))) { - sample.status = globals.status.new; + sample.status = 'new'; } await SampleModel.findByIdAndUpdate(req.params.id, sample, {new: true}).log(req).lean().exec((err, data: any) => { @@ -544,11 +543,11 @@ router.delete('/sample/' + IdValidate.parameter(), (req, res, next) => { if (sampleData.user_id.toString() !== req.authDetails.id && !req.auth(res, ['dev', 'admin'], 'basic')) return; // set sample status - await SampleModel.findByIdAndUpdate(req.params.id, {status:globals.status.deleted}).log(req).lean().exec(err => { + await SampleModel.findByIdAndUpdate(req.params.id, {status:'deleted'}).log(req).lean().exec(err => { if (err) return next(err); // set status of associated measurements also to deleted - MeasurementModel.updateMany({sample_id: mongoose.Types.ObjectId(req.params.id)}, {status: -1}) + MeasurementModel.updateMany({sample_id: mongoose.Types.ObjectId(req.params.id)}, {status: 'deleted'}) .log(req).lean().exec(err => { if (err) return next(err); @@ -582,7 +581,7 @@ router.get('/sample/number/:number', (req, res, next) => { router.put('/sample/restore/' + IdValidate.parameter(), (req, res, next) => { if (!req.auth(res, ['dev', 'admin'], 'basic')) return; - SampleModel.findByIdAndUpdate(req.params.id, {status: globals.status.new}).log(req).lean().exec((err, data) => { + SampleModel.findByIdAndUpdate(req.params.id, {status: 'new'}).log(req).lean().exec((err, data) => { if (err) return next(err); if (!data) { @@ -595,7 +594,7 @@ router.put('/sample/restore/' + IdValidate.parameter(), (req, res, next) => { router.put('/sample/validate/' + IdValidate.parameter(), (req, res, next) => { if (!req.auth(res, ['dev', 'admin'], 'basic')) return; - SampleModel.findByIdAndUpdate(req.params.id, {status: globals.status.validated}).log(req).lean().exec((err, data) => { + SampleModel.findByIdAndUpdate(req.params.id, {status: 'validated'}).log(req).lean().exec((err, data) => { if (err) return next(err); if (!data) { return res.status(404).json({status: 'Not found'}); @@ -628,7 +627,7 @@ router.post('/sample/new', async (req, res, next) => { if (!await conditionCheck(sample.condition, 'change', res, next)) return; } - sample.status = globals.status.new; // set status to new + sample.status = 'new'; // set status to new if (sample.hasOwnProperty('number')) { if (!await numberCheck(sample, res, next)) return; } @@ -827,14 +826,14 @@ function sortQuery(filters, sortKeys, sortStartValue) { // sortKeys = ['primary function statusQuery(filters, field) { if (filters.hasOwnProperty('status')) { if(filters.status === 'all') { - return {$or: [{[field]: globals.status.validated}, {[field]: globals.status.new}]}; + return {$or: [{[field]: 'validated'}, {[field]: 'new'}]}; } else { - return {[field]: globals.status[filters.status]}; + return {[field]: filters.status}; } } else { // default - return {[field]: globals.status.validated}; + return {[field]: 'validated'}; } } @@ -888,13 +887,13 @@ async function sampleReturn (sampleData, req, res, next) { sampleData = sampleData.toObject(); // deleted samples only available for dev/admin - if (sampleData.status === globals.status.deleted && !req.auth(res, ['dev', 'admin'], 'all')) return; + if (sampleData.status === 'deleted' && !req.auth(res, ['dev', 'admin'], 'all')) return; sampleData.material = sampleData.material_id; // map data to right keys sampleData.material.group = sampleData.material.group_id.name; sampleData.material.supplier = sampleData.material.supplier_id.name; sampleData.user = sampleData.user_id.name; sampleData.notes = sampleData.note_id ? sampleData.note_id : {}; - MeasurementModel.find({sample_id: sampleData._id, status: {$ne: globals.status.deleted}}) + MeasurementModel.find({sample_id: sampleData._id, status: {$ne: 'deleted'}}) .lean().exec((err, data) => { sampleData.measurements = data; if (['dev', 'admin'].indexOf(req.authDetails.level) < 0) { // strip dpt values if not dev or admin diff --git a/src/routes/validate/sample.ts b/src/routes/validate/sample.ts index 5431429..e831fc1 100644 --- a/src/routes/validate/sample.ts +++ b/src/routes/validate/sample.ts @@ -4,6 +4,7 @@ import IdValidate from './id'; import UserValidate from './user'; import MaterialValidate from './material'; import MeasurementValidate from './measurement'; +import globals from '../../globals'; export default class SampleValidate { private static sample = { @@ -49,7 +50,10 @@ export default class SampleValidate { added: Joi.date() .iso() - .min('1970-01-01T00:00:00.000Z') + .min('1970-01-01T00:00:00.000Z'), + + status: Joi.string() + .valid(...globals.status) }; private static sortKeys = [ @@ -59,6 +63,7 @@ export default class SampleValidate { 'type', 'batch', 'added', + 'status', 'material.name', 'material.supplier', 'material.group', @@ -137,7 +142,8 @@ export default class SampleValidate { note_id: IdValidate.get().allow(null), notes: this.sample.notes, user_id: IdValidate.get(), - added: this.sample.added + added: this.sample.added, + status: this.sample.status }; } else if(param === 'details') { @@ -151,7 +157,8 @@ export default class SampleValidate { material: MaterialValidate.outputV(), measurements: Joi.array().items(MeasurementValidate.outputV()), notes: this.sample.notes, - user: UserValidate.username() + user: UserValidate.username(), + status: this.sample.status } } else { @@ -161,6 +168,7 @@ export default class SampleValidate { joiObject[param] = Joi.any(); }); const {value, error} = Joi.object(joiObject).validate(data, {stripUnknown: true}); + console.log(error); return error !== undefined? null : value; } diff --git a/src/test/db.json b/src/test/db.json index 82f3a14..ea037b1 100644 --- a/src/test/db.json +++ b/src/test/db.json @@ -15,7 +15,7 @@ "material_id": {"$oid":"100000000000000000000004"}, "note_id": null, "user_id": {"$oid":"000000000000000000000002"}, - "status": 10, + "status": "validated", "__v": 0 }, { @@ -32,7 +32,7 @@ "material_id": {"$oid":"100000000000000000000001"}, "note_id": {"$oid":"500000000000000000000001"}, "user_id": {"$oid":"000000000000000000000002"}, - "status": 10, + "status": "validated", "__v": 0 }, { @@ -49,7 +49,7 @@ "material_id": {"$oid":"100000000000000000000005"}, "note_id": {"$oid":"500000000000000000000002"}, "user_id": {"$oid":"000000000000000000000003"}, - "status": 0, + "status": "new", "__v": 0 }, { @@ -65,7 +65,7 @@ "material_id": {"$oid":"100000000000000000000005"}, "note_id": {"$oid":"500000000000000000000003"}, "user_id": {"$oid":"000000000000000000000003"}, - "status": 0, + "status": "new", "__v": 0 }, { @@ -80,7 +80,7 @@ "material_id": {"$oid":"100000000000000000000005"}, "note_id": null, "user_id": {"$oid":"000000000000000000000003"}, - "status": -1, + "status": "deleted", "__v": 0 }, { @@ -93,7 +93,7 @@ "material_id": {"$oid":"100000000000000000000004"}, "note_id": null, "user_id": {"$oid":"000000000000000000000002"}, - "status": 0, + "status": "new", "__v": 0 }, { @@ -106,7 +106,7 @@ "material_id": {"$oid":"100000000000000000000009"}, "note_id": null, "user_id": {"$oid":"000000000000000000000002"}, - "status": 0, + "status": "new", "__v": 0 } ], @@ -173,7 +173,7 @@ "5514263423", "5514263422" ], - "status": 10, + "status": "validated", "__v": 0 }, { @@ -191,7 +191,7 @@ "5514212901", "5514612901" ], - "status": 10, + "status": "validated", "__v": 0 }, { @@ -207,7 +207,7 @@ }, "numbers": [ ], - "status": 10, + "status": "validated", "__v": 0 }, { @@ -224,7 +224,7 @@ "numbers": [ "5513933405" ], - "status": 10, + "status": "validated", "__v": 0 }, { @@ -241,7 +241,7 @@ "numbers": [ "5514262406" ], - "status": 10, + "status": "validated", "__v": 0 }, { @@ -258,7 +258,7 @@ "numbers": [ "1000000000" ], - "status": -1, + "status": "deleted", "__v": 0 }, { @@ -274,7 +274,7 @@ }, "numbers": [ ], - "status": 0, + "status": "new", "__v": 0 }, { @@ -291,7 +291,7 @@ "numbers": [ "5513943509" ], - "status": -1, + "status": "deleted", "__v": 0 }, { @@ -306,7 +306,7 @@ "numbers": [ "5513943509" ], - "status": 0, + "status": "new", "__v": 0 }, { @@ -321,7 +321,7 @@ "numbers": [ "5513943509" ], - "status": 0, + "status": "new", "__v": 0 } ], @@ -406,7 +406,7 @@ ], "device": "Alpha I" }, - "status": 10, + "status": "validated", "measurement_template": {"$oid":"300000000000000000000001"}, "__v": 0 }, @@ -417,7 +417,7 @@ "weight %": 0.5, "standard deviation": 0.2 }, - "status": 10, + "status": "validated", "measurement_template": {"$oid":"300000000000000000000002"}, "__v": 0 }, @@ -427,7 +427,7 @@ "values": { "val1": 1 }, - "status": 0, + "status": "new", "measurement_template": {"$oid":"300000000000000000000003"}, "__v": 0 }, @@ -437,7 +437,7 @@ "values": { "val1": 1 }, - "status": -1, + "status": "deleted", "measurement_template": {"$oid":"300000000000000000000003"}, "__v": 0 }, @@ -448,7 +448,7 @@ "weight %": 0.5, "standard deviation":null }, - "status": 10, + "status": "validated", "measurement_template": {"$oid":"300000000000000000000002"}, "__v": 0 }, @@ -459,7 +459,7 @@ "weight %": 0.6, "standard deviation":null }, - "status": 0, + "status": "new", "measurement_template": {"$oid":"300000000000000000000002"}, "__v": 0 }, @@ -474,7 +474,7 @@ ], "device": "Alpha II" }, - "status": 10, + "status": "validated", "measurement_template": {"$oid":"300000000000000000000001"}, "__v": 0 }