minor fixes
This commit is contained in:
parent
758eb0e143
commit
3dda3d77a1
@ -11,8 +11,8 @@ const kfDoc = 'C:\\Users\\vle2fe\\Documents\\Data\\Rng_200707\\kf.csv';
|
|||||||
const vzDoc = 'C:\\Users\\vle2fe\\Documents\\Data\\Rng_200707\\vz.csv';
|
const vzDoc = 'C:\\Users\\vle2fe\\Documents\\Data\\Rng_200707\\vz.csv';
|
||||||
const nmDocs = 'C:\\Users\\vle2fe\\Documents\\Data\\Rng_200707\\nmDocs'; // NormMaster Documents
|
const nmDocs = 'C:\\Users\\vle2fe\\Documents\\Data\\Rng_200707\\nmDocs'; // NormMaster Documents
|
||||||
const dptFiles = 'C:\\Users\\vle2fe\\Documents\\Data\\Rng_200707\\DPT'; // Spectrum files
|
const dptFiles = 'C:\\Users\\vle2fe\\Documents\\Data\\Rng_200707\\DPT'; // Spectrum files
|
||||||
// const host = 'http://localhost:3000';
|
const host = 'http://localhost:3000';
|
||||||
const host = 'https://definma-api.apps.de1.bosch-iot-cloud.com';
|
// const host = 'https://definma-api.apps.de1.bosch-iot-cloud.com';
|
||||||
let data = []; // metadata contents
|
let data = []; // metadata contents
|
||||||
let materials = {};
|
let materials = {};
|
||||||
let samples = [];
|
let samples = [];
|
||||||
@ -127,6 +127,16 @@ async function allDpts() {
|
|||||||
measurement_template
|
measurement_template
|
||||||
};
|
};
|
||||||
data.values.dpt = f.split('\r\n').map(e => e.split(','));
|
data.values.dpt = f.split('\r\n').map(e => e.split(','));
|
||||||
|
let rescale = false;
|
||||||
|
for (let i in data.values.dpt) {
|
||||||
|
if (data.values.dpt[i][1] > 2) {
|
||||||
|
rescale = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rescale) {
|
||||||
|
data.values.dpt = data.values.dpt.map(e => [e[0], e[1] / 100]);
|
||||||
|
}
|
||||||
await axios({
|
await axios({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: host + '/measurement/new',
|
url: host + '/measurement/new',
|
||||||
|
@ -17,6 +17,7 @@ router.get('/authorized', (req, res) => {
|
|||||||
res.json({status: 'Authorization successful', method: req.authDetails.method});
|
res.json({status: 'Authorization successful', method: req.authDetails.method});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: evaluate exact changelog functionality (restoring, delting after time, etc.)
|
||||||
router.get('/changelog/:timestamp/:page?/:pagesize?', (req, res, next) => {
|
router.get('/changelog/:timestamp/:page?/:pagesize?', (req, res, next) => {
|
||||||
if (!req.auth(res, ['maintain', 'admin'], 'basic')) return;
|
if (!req.auth(res, ['maintain', 'admin'], 'basic')) return;
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ router.get('/samples', async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
queryPtr[0].$match.$and.push({measurement_template: mongoose.Types.ObjectId(measurementTemplate._id)}); // find measurements to sort
|
queryPtr[0].$match.$and.push({measurement_template: mongoose.Types.ObjectId(measurementTemplate._id)}); // find measurements to sort
|
||||||
if (filters.filters.find(e => e.field === filters.sort[0])) { // sorted measurement should also be filtered
|
if (filters.filters.find(e => e.field === filters.sort[0])) { // sorted measurement should also be filtered
|
||||||
queryPtr[0].$match.$and.push(...filterQueries(filters.filters.find(e => e.field === filters.sort[0])));
|
queryPtr[0].$match.$and.push(...filterQueries(filters.filters.filter(e => e.field === filters.sort[0]).map(e => {e.field = 'values.' + e.field.split('.')[2]; return e; })));
|
||||||
}
|
}
|
||||||
queryPtr.push(
|
queryPtr.push(
|
||||||
...sortQuery(filters, ['values.' + measurementParam, 'sample_id'], sortStartValue), // sort measurements
|
...sortQuery(filters, ['values.' + measurementParam, 'sample_id'], sortStartValue), // sort measurements
|
||||||
@ -764,6 +764,7 @@ function addFilterQueries (queryPtr, filters) { // returns array of match queri
|
|||||||
}
|
}
|
||||||
|
|
||||||
function filterQueries (filters) {
|
function filterQueries (filters) {
|
||||||
|
console.log(filters);
|
||||||
return filters.map(e => {
|
return filters.map(e => {
|
||||||
if (e.mode === 'or') { // allow or queries (needed for $ne added)
|
if (e.mode === 'or') { // allow or queries (needed for $ne added)
|
||||||
return {['$' + e.mode]: e.values};
|
return {['$' + e.mode]: e.values};
|
||||||
|
@ -182,8 +182,8 @@ export default class SampleValidate {
|
|||||||
validator = Joi.object({
|
validator = Joi.object({
|
||||||
value: Joi.alternatives()
|
value: Joi.alternatives()
|
||||||
.try(
|
.try(
|
||||||
Joi.string().max(128),
|
|
||||||
Joi.number(),
|
Joi.number(),
|
||||||
|
Joi.string().max(128),
|
||||||
Joi.boolean(),
|
Joi.boolean(),
|
||||||
Joi.array()
|
Joi.array()
|
||||||
)
|
)
|
||||||
@ -195,6 +195,7 @@ export default class SampleValidate {
|
|||||||
validator = Joi.object(this.sample);
|
validator = Joi.object(this.sample);
|
||||||
}
|
}
|
||||||
const {value, error} = validator.validate({[field]: e});
|
const {value, error} = validator.validate({[field]: e});
|
||||||
|
console.log(value);
|
||||||
if (error) throw error; // reject invalid values // TODO: return exact error description, handle in frontend filters
|
if (error) throw error; // reject invalid values // TODO: return exact error description, handle in frontend filters
|
||||||
return value[field];
|
return value[field];
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import Joi from '@hapi/joi';
|
import Joi from '@hapi/joi';
|
||||||
import IdValidate from './id';
|
import IdValidate from './id';
|
||||||
|
|
||||||
|
// TODO: do not allow a . in the name
|
||||||
export default class TemplateValidate {
|
export default class TemplateValidate {
|
||||||
private static template = {
|
private static template = {
|
||||||
name: Joi.string()
|
name: Joi.string()
|
||||||
|
Reference in New Issue
Block a user