Merge pull request #32 in ~VLE2FE/definma-api from develop to master
* commit 'fd5c0d2c74fb40c206daabad9d4a39fe0c1a09d3': allow null values for filters
This commit is contained in:
commit
ce200327ef
@ -227,9 +227,12 @@ router.get('/samples', async (req, res, next) => {
|
||||
queryPtr.push({$lookup: {
|
||||
from: 'measurements', let: {sId: '$_id'},
|
||||
pipeline: [{$match: {$expr: {$and: [
|
||||
{$eq: ['$sample_id', '$$sId']},
|
||||
{$in: ['$measurement_template', measurementTemplates.map(e => mongoose.Types.ObjectId(e._id))]}
|
||||
]}}}],
|
||||
{$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; }, {})}
|
||||
],
|
||||
as: 'measurements'
|
||||
}});
|
||||
const groupedMeasurementTemplates = measurementTemplates.reduce((s, e) => {
|
||||
@ -322,9 +325,12 @@ router.get('/samples', async (req, res, next) => {
|
||||
queryPtr.push({$lookup: {
|
||||
from: 'measurements', let: {sId: '$_id'},
|
||||
pipeline: [{$match: {$expr: {$and: [
|
||||
{$eq: ['$sample_id', '$$sId']},
|
||||
{$in: ['$measurement_template', measurementTemplates.map(e => mongoose.Types.ObjectId(e._id))]}
|
||||
]}}}],
|
||||
{$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; }, {})}
|
||||
],
|
||||
as: 'measurements'
|
||||
}});
|
||||
}
|
||||
|
@ -195,6 +195,9 @@ export default class SampleValidate {
|
||||
// data.filters[i] = JSON.parse(decodeURIComponent(data.filters[i]));
|
||||
data.filters[i] = JSON.parse(data.filters[i]);
|
||||
data.filters[i].values = data.filters[i].values.map(e => { // validate filter values
|
||||
if (e === null) { // null values are always allowed
|
||||
return null;
|
||||
}
|
||||
let validator;
|
||||
let field = data.filters[i].field
|
||||
if (/material\./.test(field)) { // select right validation model
|
||||
@ -253,7 +256,7 @@ export default class SampleValidate {
|
||||
new RegExp('^(' + this.fieldKeys.join('|').replace(/\./g, '\\.').replace(/\*/g, '.+') + ')$', 'm')
|
||||
).messages({'string.pattern.base': 'Invalid filter field name'}),
|
||||
values: Joi.array().items(Joi.alternatives().try(
|
||||
Joi.string().max(128), Joi.number(), Joi.boolean(), Joi.date().iso(), Joi.object()
|
||||
Joi.string().max(128), Joi.number(), Joi.boolean(), Joi.date().iso(), Joi.object(), null
|
||||
)).min(1)
|
||||
})).default([])
|
||||
}).with('to-page', 'page-size').validate(data);
|
||||
|
Reference in New Issue
Block a user