*** WIP WIP *** woks now for live and havg
This commit is contained in:
+29
-4
@@ -1,16 +1,33 @@
|
||||
import express from 'express'
|
||||
|
||||
import {getData4map} from "../actions/data4map.js"
|
||||
import * as cTable from "../utilities/commands.js"
|
||||
import * as tables from "../utilities/tables.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();
|
||||
|
||||
|
||||
export const dispatchCommand = async (cmd, table, query, res) => {
|
||||
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(query)
|
||||
let erg = await c.func(params)
|
||||
if (typeof erg === 'string') {
|
||||
res.type('text')
|
||||
res.send(erg)
|
||||
@@ -25,6 +42,14 @@ export const dispatchCommand = async (cmd, table, query, res) => {
|
||||
|
||||
// normal routes called from javascript client
|
||||
apiRouter.get('/:cmd', async (req, res) => {
|
||||
await dispatchCommand(req.params.cmd, cTable.cmdTable, req.query, res)
|
||||
const params = req.query
|
||||
params.chart = false
|
||||
await dispatchCommand(req.params.cmd, cmdTable, params, res)
|
||||
})
|
||||
|
||||
// normal routes called from javascript client
|
||||
chartapiRouter.get('/:cmd', async (req, res) => {
|
||||
const params = req.query
|
||||
params.chart = true
|
||||
await dispatchCommand(req.params.cmd, cmdTable, params, res)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user