Files
sensorapi/routes/api.js
T
admin 2cf418756d corrected problem with havg
api.js
   - unnecessary export deleted
   - import of logit added

actions/data4map.js
   - logits removed

databases/influx.js
   - logits removed

databases/mongo.js
   - logits removed

sensorspecials/noise.js
   - repeated code put to a function
   - correctred hour count at havg

package.json
  "version": "1.2.2",
  "date": "2023-04-24",
2023-04-24 11:54:30 +02:00

49 lines
1.4 KiB
JavaScript

import express from 'express'
import {getData4map} from "../actions/data4map.js"
import * as ERR from "../utilities/errortexts.js"
import * as getData from "../actions/getsensorData.js";
import * as getProps from "../actions/getproperties.js";
import * as getAKWs from "../actions/getAKWData.js";
import * as holAddr from "../actions/getaddress.js";
export const apiRouter = express.Router();
import { logit, logerror } from '../utilities/logit.js'
const cmdTable = [
{cmd: 'getactdata', func: getData.getActData},
{cmd: 'getlongavg', func: getData.getLongAvg},
{cmd: 'getavgdata', func: getData.getAvgData},
{cmd: 'getoneproperty', func: getProps.getOneProperty},
{cmd: 'getakwdata', func: getAKWs.getakwdata},
{cmd: 'getaddress', func: holAddr.getAddress},
{cmd: 'getsensordata', func: getData.getSensorData},
{cmd: 'getmapdata', func: getData4map}
]
export const dispatchCommand = async (cmd, table, params, res) => {
for (let c of table) {
if (c.cmd === cmd) {
let erg = await c.func(params)
if (typeof erg === 'string') {
res.type('text')
res.send(erg)
} else {
res.json(erg)
}
return
}
}
res.json({err: ERR.CMNDUNKOWN})
}
// normal routes called from javascript client
apiRouter.get('/:cmd', async (req, res) => {
const params = req.query
params.chart = false
await dispatchCommand(req.params.cmd, cmdTable, params, res)
})