Files
sensorapi/routes/api.js
T
admin c3a4ff0b4a Preparation for charts moved from here to laerm app
routes/api.js
   - removed unnecessary table entry

app.js
   - removed unnecessary calls

actions/ddata4maps.js
   - return options as object

sensorspecials/noise.js
   - removed all references to xxxxxData-Calls
   - removed checks for /chart/...

removed route/chartapi.js,  sensorspecials/noisCharts.js and utilites/tables.js
2023-04-07 15:28:42 +02:00

48 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();
export const chartapiRouter = express.Router();
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)
})