Many changes to have Noise Live Chart

This commit is contained in:
rxf
2023-03-20 20:01:22 +01:00
parent acad6d8276
commit 088005c040
8 changed files with 282 additions and 97 deletions
+11 -15
View File
@@ -14,6 +14,8 @@ if (mockdb) {
} else {
readProperties = mongo.readProperties
}
// Read properties for sensorid and properties for all other sensors on same location
export const getOneProperty = async (params) => {
let properties = {props: {}, err: null}
let {opts, err} = checkParams(params, {mandatory:[{name:'sensorid', type: 'int'}], optional:[]})
@@ -22,31 +24,25 @@ export const getOneProperty = async (params) => {
}
let sensorEntries = [];
try {
let pp = await readProperties({sid: opts.sensorid});
if ((pp.values == null) || (pp.error)) {
let pp = await readProperties({sid: opts.sensorid}); // read for given sensorID
if ((pp.properties == null) || (pp.error)) {
return returnOnError(properties, ERR.NOPROPSREAD.replace('xx', opts.sensorid), getOneProperty.name)
}
// now find sensors with same location
let query
if (pp.values.location_id !== undefined) {
query = {location_id: pp.values.location_id}
} else {
query = {id: pp.values.id}
}
let query = {"location.0.id": pp.properties.location[0].id}
let others = await readProperties(query)
if (others.error) {
return returnOnError(properties, ERR.NOPROPSREAD.replace('xx',others.errortext), getOneProperty.name)
}
if (others.values.length > 0) {
for (const x of others.values) {
if(x.name[0].name === undefined) {
sensorEntries.push({name: x.name, sid: x._id})
} else {
sensorEntries.push({name: x.name[0].name, sid: x._id})
if (others.properties.length > 0) {
for (const x of others.properties) {
if(x._id === pp.properties._id) {
continue
}
sensorEntries.push({name: x.name[0].name, sid: x._id})
}
}
properties.props = pp.values
properties.props = pp.properties
properties.props.othersensors = sensorEntries;
} catch (e) {
return returnOnError(properties, e, getOneProperty.name)