Archived
2

Merge pull request #33 in ~VLE2FE/definma-api from develop to master

* commit '37a5ba1bfd6db80f27df879fa28d8d43966dc9c0':
  fixed measurements lookup pipeline
This commit is contained in:
Veit Lukas (PEA4-Fe) 2020-08-17 15:12:02 +02:00
commit b104727c07

View File

@ -230,8 +230,11 @@ router.get('/samples', async (req, res, next) => {
{$eq: ['$sample_id', '$$sId']}, {$eq: ['$sample_id', '$$sId']},
{$in: ['$measurement_template', measurementTemplates.map(e => mongoose.Types.ObjectId(e._id))]} {$in: ['$measurement_template', measurementTemplates.map(e => mongoose.Types.ObjectId(e._id))]}
]}}}, ]}}},
{$project: filters.fields.filter(e => /measurements\./.test(e)) {$project: _.merge(
.map(e => 'values.' + e.replace('measurements.', '')).reduce((s, e) => {s[e] = true; return s; }, {})} filters.fields.filter(e => /measurements\./.test(e))
.map(e => 'values.' + e.split('.')[2]).reduce((s, e) => {s[e] = true; return s; }, {}),
{measurement_template: true, status: true, sample_id: true}
)}
], ],
as: 'measurements' as: 'measurements'
}}); }});
@ -328,8 +331,11 @@ router.get('/samples', async (req, res, next) => {
{$eq: ['$sample_id', '$$sId']}, {$eq: ['$sample_id', '$$sId']},
{$in: ['$measurement_template', measurementTemplates.map(e => mongoose.Types.ObjectId(e._id))]} {$in: ['$measurement_template', measurementTemplates.map(e => mongoose.Types.ObjectId(e._id))]}
]}}}, ]}}},
{$project: filters.fields.filter(e => /measurements\./.test(e)) {$project: _.merge(
.map(e => 'values.' + e.replace('measurements.', '')).reduce((s, e) => {s[e] = true; return s; }, {})} filters.fields.filter(e => /measurements\./.test(e))
.map(e => 'values.' + e.split('.')[2]).reduce((s, e) => {s[e] = true; return s; }, {}),
{measurement_template: true, status: true, sample_id: true}
)}
], ],
as: 'measurements' as: 'measurements'
}}); }});