From 092c547fffbfbf95a026915324e4e2f845888dc4 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 20 Aug 2020 10:42:55 +0200 Subject: [PATCH] small fixes --- data_import/import.js | 407 ++++++++++++++++++++++++++++++------------ src/models/model.ts | 2 +- src/routes/sample.ts | 4 +- 3 files changed, 296 insertions(+), 117 deletions(-) diff --git a/data_import/import.js b/data_import/import.js index 38f4526..f8e34e6 100644 --- a/data_import/import.js +++ b/data_import/import.js @@ -9,27 +9,204 @@ const _ = require('lodash'); const stages = { materials: true, - samples: false, - dpt: false + samples: true, + dpt: true, + dptFromList: false // ignores dpts not on the dptList } +const dptList = [ + 'Eh01_Eh3001_01_csv.DPT', + 'Eh01_Eh3001_02_csv.DPT', + 'Eh01_Eh3001_03_csv.DPT', + 'Eh01_Eh3002_01_csv.DPT', + 'Eh01_Eh3002_02_csv.DPT', + 'Eh01_Eh3002_03_csv.DPT', + 'Eh01_Eh3003_01_csv.DPT', + 'Eh01_Eh3003_02_csv.DPT', + 'Eh01_Eh3003_03_csv.DPT', + 'Eh01_Eh3004_01_csv.DPT', + 'Eh01_Eh3004_02_csv.DPT', + 'Eh01_Eh3004_03_csv.DPT', + 'Eh01_Eh3005_01_csv.DPT', + 'Eh01_Eh3005_02_csv.DPT', + 'Eh01_Eh3005_03_csv.DPT', + 'Eh01_Eh3005_04_csv.DPT', + 'Eh01_Eh3005_05_csv.DPT', + 'Eh01_Eh3005_06_csv.DPT', + 'Eh01_Eh3005_07_csv.DPT', + 'Eh01_Eh3005_08_csv.DPT', + 'Eh01_Eh3005_09_csv.DPT', + 'Eh01_Eh3006_01_csv.DPT', + 'Eh01_Eh3006_02_csv.DPT', + 'Eh01_Eh3006_03_csv.DPT', + 'Eh01_Eh3007_01_csv.DPT', + 'Eh01_Eh3007_02_csv.DPT', + 'Eh01_Eh3007_03_csv.DPT', + 'Eh01_Eh3008_01_csv.DPT', + 'Eh01_Eh3008_02_csv.DPT', + 'Eh01_Eh3008_03_csv.DPT', + 'Eh01_Eh3009_01_csv.DPT', + 'Eh01_Eh3009_02_csv.DPT', + 'Eh01_Eh3009_03_csv.DPT', + 'Eh01_Eh3010_01_csv.DPT', + 'Eh01_Eh3010_02_csv.DPT', + 'Eh01_Eh3010_03_csv.DPT', + 'Eh01_Eh3011_01_csv.DPT', + 'Eh01_Eh3011_02_csv.DPT', + 'Eh01_Eh3011_03_csv.DPT', + 'Eh01_Eh3012_01_csv.DPT', + 'Eh01_Eh3012_02_csv.DPT', + 'Eh01_Eh3012_03_csv.DPT', + 'Eh01_Eh3013_01_csv.DPT', + 'Eh01_Eh3013_02_csv.DPT', + 'Eh01_Eh3013_03_csv.DPT', + 'Eh01_Eh3013_04_csv.DPT', + 'Eh01_Eh3013_05_csv.DPT', + 'Eh01_Eh3013_06_csv.DPT', + 'Eh01_Eh3013_07_csv.DPT', + 'Eh01_Eh3013_08_csv.DPT', + 'Eh01_Eh3013_09_csv.DPT', + 'Eh01_Eh3014_01_csv.DPT', + 'Eh01_Eh3014_02_csv.DPT', + 'Eh01_Eh3014_03_csv.DPT', + 'Eh01_Eh3015_01_csv.DPT', + 'Eh01_Eh3015_02_csv.DPT', + 'Eh01_Eh3015_03_csv.DPT', + 'Eh01_Eh3016_01_csv.DPT', + 'Eh01_Eh3016_02_csv.DPT', + 'Eh01_Eh3016_03_csv.DPT', + 'Eh01_Eh3017_01_csv.DPT', + 'Eh01_Eh3017_02_csv.DPT', + 'Eh01_Eh3017_03_csv.DPT', + 'Eh01_Eh3018_01_csv.DPT', + 'Eh01_Eh3018_02_csv.DPT', + 'Eh01_Eh3018_03_csv.DPT', + 'Eh01_Eh3019_01_csv.DPT', + 'Eh01_Eh3019_02_csv.DPT', + 'Eh01_Eh3019_03_csv.DPT', + 'Eh01_Eh3020_01_csv.DPT', + 'Eh01_Eh3020_02_csv.DPT', + 'Eh01_Eh3020_03_csv.DPT', + 'Eh01_Eh3021_01_csv.DPT', + 'Eh01_Eh3021_02_csv.DPT', + 'Eh01_Eh3021_03_csv.DPT', + 'Eh01_Eh3022_01_csv.DPT', + 'Eh01_Eh3022_02_csv.DPT', + 'Eh01_Eh3022_03_csv.DPT', + 'Eh01_Eh4001_01_csv.DPT', + 'Eh01_Eh4001_02_csv.DPT', + 'Eh01_Eh4001_03_csv.DPT', + 'Eh01_Eh4001_04_csv.DPT', + 'Eh01_Eh4001_05_csv.DPT', + 'Eh01_Eh4001_06_csv.DPT', + 'Eh01_Eh4001_07_csv.DPT', + 'Eh01_Eh4001_08_csv.DPT', + 'Eh01_Eh4001_09_csv.DPT', + 'Eh01_Eh4002_01_csv.DPT', + 'Eh01_Eh4002_02_csv.DPT', + 'Eh01_Eh4002_03_csv.DPT', + 'Eh01_Eh4003_01_csv.DPT', + 'Eh01_Eh4003_02_csv.DPT', + 'Eh01_Eh4003_03_csv.DPT', + 'Eh01_Eh4003_04_csv.DPT', + 'Eh01_Eh4003_05_csv.DPT', + 'Eh01_Eh4003_06_csv.DPT', + 'Eh01_Eh4003_07_csv.DPT', + 'Eh01_Eh4003_08_csv.DPT', + 'Eh01_Eh4003_09_csv.DPT', + 'Eh01_Eh4004_01_csv.DPT', + 'Eh01_Eh4004_02_csv.DPT', + 'Eh01_Eh4004_03_csv.DPT', + 'Eh01_Eh4004_04_csv.DPT', + 'Eh01_Eh4004_05_csv.DPT', + 'Eh01_Eh4004_06_csv.DPT', + 'Eh01_Eh4004_07_csv.DPT', + 'Eh01_Eh4004_08_csv.DPT', + 'Eh01_Eh4004_09_csv.DPT', + 'Eh01_Eh4005_01_csv.DPT', + 'Eh01_Eh4005_02_csv.DPT', + 'Eh01_Eh4005_03_csv.DPT', + 'Eh01_Eh4005_04_csv.DPT', + 'Eh01_Eh4005_05_csv.DPT', + 'Eh01_Eh4005_06_csv.DPT', + 'Eh01_Eh4005_07_csv.DPT', + 'Eh01_Eh4005_08_csv.DPT', + 'Eh01_Eh4005_09_csv.DPT', + 'Eh01_Eh4006_01_csv.DPT', + 'Eh01_Eh4006_02_csv.DPT', + 'Eh01_Eh4006_03_csv.DPT', + 'Eh01_Eh4006_04_csv.DPT', + 'Eh01_Eh4006_05_csv.DPT', + 'Eh01_Eh4006_06_csv.DPT', + 'Eh01_Eh4006_07_csv.DPT', + 'Eh01_Eh4006_08_csv.DPT', + 'Eh01_Eh4006_09_csv.DPT', + 'Eh01_Eh4007_01_csv.DPT', + 'Eh01_Eh4007_02_csv.DPT', + 'Eh01_Eh4007_03_csv.DPT', + 'Eh01_Eh4007_04_csv.DPT', + 'Eh01_Eh4007_05_csv.DPT', + 'Eh01_Eh4007_06_csv.DPT', + 'Eh01_Eh4007_07_csv.DPT', + 'Eh01_Eh4007_08_csv.DPT', + 'Eh01_Eh4007_09_csv.DPT', + 'Eh01_Eh4008_01_csv.DPT', + 'Eh01_Eh4008_02_csv.DPT', + 'Eh01_Eh4008_03_csv.DPT', + 'Eh01_Eh4008_04_csv.DPT', + 'Eh01_Eh4008_05_csv.DPT', + 'Eh01_Eh4008_06_csv.DPT', + 'Eh01_Eh4008_07_csv.DPT', + 'Eh01_Eh4008_08_csv.DPT', + 'Eh01_Eh4008_09_csv.DPT', + 'Eh01_Eh4009_01_csv.DPT', + 'Eh01_Eh4009_02_csv.DPT', + 'Eh01_Eh4009_03_csv.DPT', + 'Eh01_Eh4009_04_csv.DPT', + 'Eh01_Eh4009_05_csv.DPT', + 'Eh01_Eh4009_06_csv.DPT', + 'Eh01_Eh4009_07_csv.DPT', + 'Eh01_Eh4009_08_csv.DPT', + 'Eh01_Eh4009_09_csv.DPT', + 'Eh01_Eh4010_01_csv.DPT', + 'Eh01_Eh4010_02_csv.DPT', + 'Eh01_Eh4010_03_csv.DPT', + 'Eh01_Eh4010_04_csv.DPT', + 'Eh01_Eh4010_05_csv.DPT', + 'Eh01_Eh4010_06_csv.DPT', + 'Eh01_Eh4010_07_csv.DPT', + 'Eh01_Eh4010_08_csv.DPT', + 'Eh01_Eh4010_09_csv.DPT', + 'Eh01_Eh4011_01_csv.DPT', + 'Eh01_Eh4011_02_csv.DPT', + 'Eh01_Eh4011_03_csv.DPT', + 'Eh01_Eh4011_04_csv.DPT', + 'Eh01_Eh4011_05_csv.DPT', + 'Eh01_Eh4011_06_csv.DPT', + 'Eh01_Eh4011_07_csv.DPT', + 'Eh01_Eh4011_08_csv.DPT', + 'Eh01_Eh4011_09_csv.DPT' +]; + const docs = [ - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2.csv", - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_A.csv", - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_B.csv", - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Ap.csv", - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Bj.csv", - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh.csv", - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_B.csv", - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_Duroplasten.csv", - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell.csv", - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell_A.csv", - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell_B.csv", - "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_WaP.csv", + "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\DPPD_DPPD-frei.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_A.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata__AnP2_B.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Ap.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Bj.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_B.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Eh_Duroplasten.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell_A.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_Rng_aktuell_B.csv", + // "C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\Metadata_WaP.csv", ]; const errors = []; const nmDocs = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\nmDocs'; // NormMaster Documents -const dptFiles = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\DPT'; // Spectrum files +// const dptFiles = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\DPT'; // Spectrum files +const dptFiles = 'C:\\Users\\vle2fe\\Documents\\Data\\All_200807\\DPT_DPPD'; // Spectrum files const host = 'http://localhost:3000'; // const host = 'https://definma-api.apps.de1.bosch-iot-cloud.com'; const requiredProperties = ['samplenumber','materialnumber','materialname','supplier','reinforcementmaterial','material','granulate/part','color','charge/batch','comments']; @@ -81,7 +258,7 @@ async function main() { for (let i in docs) { await importCsv(docs[i]); await allMaterials(); - // await saveMaterials(); + await saveMaterials(); } fs.writeFileSync('./data_import/numberToColor.json', JSON.stringify(numberToColor)); fs.writeFileSync('./data_import/duplicateMNames.json', JSON.stringify(duplicateMNamesLog)); @@ -140,6 +317,7 @@ async function importCsv(doc) { 'charge/batchgranulate/part': 'charge/batch', 'charge': 'charge/batch', 'anmerkung': 'comments', + 'vz': 'vz(ml/g)', 'vz[ml/g]': 'vz(ml/g)', 'vz[cm³/g]': 'vz(ml/g)', 'abbau(%)': 'degradation(%)', @@ -247,116 +425,118 @@ async function allDpts() { res.data.forEach(sample => { sampleIds[sample.number] = sample._id; }); - const dptRegex = /(.*?)_(.*?)_(\d+|[a-zA-Z0-9]+[_.]\d+)(_JDX)?[.]{1,2}(DPT|csv|CSV|JDX)/; + const dptRegex = /(.*?)_(.*?)_(\d+|[a-zA-Z0-9]+[_.]\d+)(_JDX|_csv)?[.]{1,2}(DPT|csv|CSV|JDX)/; const dpts = fs.readdirSync(dptFiles); for (let i in dpts) { - let regexInput; - const bjRes = /^(Bj[FT]?)\s?([a-z0-9_]*)_JDX.DPT/.exec(dpts[i]); - if (bjRes) { // correct Bj numbers with space - regexInput = `Bj01_${bjRes[1]}${bjRes[2]}_0.DPT`; - } - else { // remove _JDX from name - regexInput = dpts[i].replace(/_JDX.*\./, '.'); - } - const regexRes = dptRegex.exec(regexInput); - if (regexRes && !sampleIds[regexRes[2]]) { // when sample number includes an additional _x instead of having _x_x for spectrum description - regexRes[2] = `${regexRes[2]}_${regexRes[3].split('_')[0]}`; - } - let baseSample = null; - if (regexRes) { - baseSample = regexRes[2].split('_')[0]; - if (baseSample === 'Wa11') { // as Wa11 samples use all the same material - baseSample = 'Wa11_B0_1'; + if (!stages.dptFromList || dptList.indexOf(dpts[i]) >= 0) { // if list option active, only use from filter + let regexInput; + const bjRes = /^(Bj[FT]?)\s?([a-z0-9_]*)_JDX.DPT/.exec(dpts[i]); + if (bjRes) { // correct Bj numbers with space + regexInput = `Bj01_${bjRes[1]}${bjRes[2]}_0.DPT`; } - } - if (regexRes && !sampleIds[regexRes[2]] && sampleIds[baseSample]) { // when number_abx does not exist but number - dptSampleAddLog.push(`Trying to find ${baseSample}`); - dptSampleAddLog.push(host + '/sample/' + sampleIds[baseSample]); - res = await axios({ // get base sample - method: 'get', - url: host + '/sample/' + stripSpaces(sampleIds[baseSample]), - auth: { - username: 'admin', - password: 'Abc123!#' + else { // remove _JDX from name + regexInput = dpts[i].replace(/_JDX.*\./, '.'); + } + const regexRes = dptRegex.exec(regexInput); + if (regexRes && !sampleIds[regexRes[2]]) { // when sample number includes an additional _x instead of having _x_x for spectrum description + regexRes[2] = `${regexRes[2]}_${regexRes[3].split('_')[0]}`; + } + let baseSample = null; + if (regexRes) { + baseSample = regexRes[2].split('_')[0]; + if (baseSample === 'Wa11') { // as Wa11 samples use all the same material + baseSample = 'Wa11_B0_1'; } - }).catch(err => { - if (err.response) { - console.error(err.response.data); - errors.push(`DPT Could not fetch sample ${baseSample}: ${JSON.stringify(err.response.data)}`); - } - }); - if (res) { - const data = _.merge(_.pick(res.data, ['color', 'type', 'batch']), - {number: regexRes[2], condition: {}, notes: {}, material_id: res.data.material._id}); - res = await axios({ - method: 'post', - url: host + '/sample/new', + } + if (regexRes && !sampleIds[regexRes[2]] && sampleIds[baseSample]) { // when number_abx does not exist but number + dptSampleAddLog.push(`Trying to find ${baseSample}`); + dptSampleAddLog.push(host + '/sample/' + sampleIds[baseSample]); + res = await axios({ // get base sample + method: 'get', + url: host + '/sample/' + stripSpaces(sampleIds[baseSample]), auth: { - username: res.data.user, - password: res.data.user === 'admin' ? 'Abc123!#' : '2020DeFinMachen!' - }, - data + username: 'admin', + password: 'Abc123!#' + } }).catch(err => { if (err.response) { console.error(err.response.data); - errors.push(`DPT Could not save sample ${data}: ${err.response.data}`); + errors.push(`DPT Could not fetch sample ${baseSample}: ${JSON.stringify(err.response.data)}`); } }); - if (res.data) { - dptSampleAddLog.push(`${regexRes[2]} from ${baseSample}`) - sampleIds[regexRes[2]] = res.data._id; + if (res) { + const data = _.merge(_.pick(res.data, ['color', 'type', 'batch']), + {number: regexRes[2], condition: {}, notes: {}, material_id: res.data.material._id}); + res = await axios({ + method: 'post', + url: host + '/sample/new', + auth: { + username: res.data.user, + password: res.data.user === 'admin' ? 'Abc123!#' : '2020DeFinMachen!' + }, + data + }).catch(err => { + if (err.response) { + console.error(err.response.data); + errors.push(`DPT Could not save sample ${data}: ${err.response.data}`); + } + }); + if (res.data) { + dptSampleAddLog.push(`${regexRes[2]} from ${baseSample}`) + sampleIds[regexRes[2]] = res.data._id; + } } } - } - if (regexRes && sampleIds[regexRes[2]]) { // found matching sample - console.log(`${i}/${dpts.length} ${dpts[i]} -> ${regexRes[2]}`); - dptLog.push(`${dpts[i]}, ${regexRes[2]}`); - const f = fs.readFileSync(dptFiles + '\\' + dpts[i], 'utf-8'); - const data = { - sample_id: sampleIds[regexRes[2]], - values: {}, - measurement_template - }; - data.values.device = regexRes[1]; - data.values.filename = dpts[i]; - data.values.dpt = f.split('\r\n').map(e => e.split(',').map(e => parseFloat(e))); - let rescale = false; - for (let i in data.values.dpt) { - if (data.values.dpt[i][1] > 10) { - rescale = true; - break; + if (regexRes && sampleIds[regexRes[2]]) { // found matching sample + console.log(`${i}/${dpts.length} ${dpts[i]} -> ${regexRes[2]}`); + dptLog.push(`${dpts[i]}, ${regexRes[2]}`); + const f = fs.readFileSync(dptFiles + '\\' + dpts[i], 'utf-8'); + const data = { + sample_id: sampleIds[regexRes[2]], + values: {}, + measurement_template + }; + data.values.device = regexRes[1]; + data.values.filename = dpts[i]; + data.values.dpt = f.split('\r\n').map(e => e.split(',').map(e => parseFloat(e))); + let rescale = false; + for (let i in data.values.dpt) { + if (data.values.dpt[i][1] > 10) { + rescale = true; + break; + } } - } - if (rescale) { - data.values.dpt = data.values.dpt.map(e => [e[0], e[1] / 100]); - } - await axios({ - method: 'post', - url: host + '/measurement/new', - auth: { - username: 'admin', - password: 'Abc123!#' - }, - data - }).catch(err => { - console.log(dpts[i]); - if (err.response) { - console.error(err.response.data); - errors.push(`Could not upload ${dpts[i]} for sample ${regexRes[2]}: ${err.response.data}`); + if (rescale) { + data.values.dpt = data.values.dpt.map(e => [e[0], e[1] / 100]); } - else { - console.error(err); - errors.push(`Could not upload ${dpts[i]} for sample ${regexRes[2]}: ${JSON.stringify(err)}`); - } - }); - } - else { - console.log(`Could not find sample for ${dpts[i]}`); - if (regexRes) { - errors.push(`Could not find sample for ${dpts[i]}; [DEBUG] ${regexRes[2]}, ${!sampleIds[regexRes[2]]}, ${sampleIds[baseSample]}`); + await axios({ + method: 'post', + url: host + '/measurement/new', + auth: { + username: 'admin', + password: 'Abc123!#' + }, + data + }).catch(err => { + console.log(dpts[i]); + if (err.response) { + console.error(err.response.data); + errors.push(`Could not upload ${dpts[i]} for sample ${regexRes[2]}: ${err.response.data}`); + } + else { + console.error(err); + errors.push(`Could not upload ${dpts[i]} for sample ${regexRes[2]}: ${JSON.stringify(err)}`); + } + }); } else { - errors.push(`Could not find sample for ${dpts[i]} (did not match RegEx)`); + console.log(`Could not find sample for ${dpts[i]}`); + if (regexRes) { + errors.push(`Could not find sample for ${dpts[i]}; [DEBUG] ${regexRes[2]}, ${!sampleIds[regexRes[2]]}, ${sampleIds[baseSample]}`); + } + else { + errors.push(`Could not find sample for ${dpts[i]} (did not match RegEx)`); + } } } } @@ -399,6 +579,7 @@ async function allMcVn() { for (let index in data) { console.info(`MC/VN ${index}/${data.length}`); let sample = data[index]; + console.log(sample); sample['samplenumber'] = sample['samplenumber'].replace(/[A-Z][a-z]0\d_/, ''); let credentials = ['admin', 'Abc123!#']; if (sampleDevices[sample['samplenumber']]) { @@ -671,10 +852,6 @@ async function allMaterials() { // process all samples for (let index in data) { let sample = data[index]; - // TODO: remove next if, only for duplicate m names - if (duplicateMNames.indexOf(sample['materialname']) >= 0) { - duplicateMNamesLog.push(sample); - } if (sample['supplier'] === '') { // empty supplier fields sample['supplier'] = 'unknown'; } @@ -700,7 +877,7 @@ async function allMaterials() { } } else { // new material - // console.info(`MATERIAL LOAD ${index}/${data.length} ${sample['materialname']}`); + console.info(`MATERIAL LOAD ${index}/${data.length} ${sample['materialname']}`); materials[sample['materialname']] = { name: trim(sample['materialname']), supplier: trim(sample['supplier']), diff --git a/src/models/model.ts b/src/models/model.ts index 4f2eed9..92d555d 100644 --- a/src/models/model.ts +++ b/src/models/model.ts @@ -4,7 +4,7 @@ import db from '../db'; const ModelSchema = new mongoose.Schema({ group: {type: String, index: {unique: true}}, models: [new mongoose.Schema({ - name: {type: String, index: {unique: true}}, + name: String, url: String, label: String } ,{ _id : false })] diff --git a/src/routes/sample.ts b/src/routes/sample.ts index 7bd98ef..e7a0b03 100644 --- a/src/routes/sample.ts +++ b/src/routes/sample.ts @@ -262,7 +262,9 @@ router.get('/samples', async (req, res, next) => { // count total number of items before $skip and $limit, only works when from-id is not specified and spectra are not // included - if (!filters.fields.find(e => e.indexOf(globals.spectrum.spectrum + '.') >= 0) && !filters['from-id']) { + if (!filters.fields.find(e => + e.indexOf(globals.spectrum.spectrum + '.' + globals.spectrum.dpt) >= 0) && !filters['from-id'] + ) { queryPtr.push({$facet: {count: [{$count: 'count'}], samples: []}}); queryPtr = queryPtr[queryPtr.length - 1].$facet.samples; // add rest of aggregation pipeline into $facet }