From 37a5ba1bfd6db80f27df879fa28d8d43966dc9c0 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Mon, 17 Aug 2020 15:11:40 +0200 Subject: [PATCH] fixed measurements lookup pipeline --- src/routes/sample.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/routes/sample.ts b/src/routes/sample.ts index adb645a..270389b 100644 --- a/src/routes/sample.ts +++ b/src/routes/sample.ts @@ -230,8 +230,11 @@ router.get('/samples', async (req, res, next) => { {$eq: ['$sample_id', '$$sId']}, {$in: ['$measurement_template', measurementTemplates.map(e => mongoose.Types.ObjectId(e._id))]} ]}}}, - {$project: filters.fields.filter(e => /measurements\./.test(e)) - .map(e => 'values.' + e.replace('measurements.', '')).reduce((s, e) => {s[e] = true; return s; }, {})} + {$project: _.merge( + 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' }}); @@ -328,8 +331,11 @@ router.get('/samples', async (req, res, next) => { {$eq: ['$sample_id', '$$sId']}, {$in: ['$measurement_template', measurementTemplates.map(e => mongoose.Types.ObjectId(e._id))]} ]}}}, - {$project: filters.fields.filter(e => /measurements\./.test(e)) - .map(e => 'values.' + e.replace('measurements.', '')).reduce((s, e) => {s[e] = true; return s; }, {})} + {$project: _.merge( + 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' }});