*** 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)
|
||||
})
|
||||
|
||||
+8
-34
@@ -1,40 +1,14 @@
|
||||
import express from 'express'
|
||||
import * as tables from "../utilities/tables.js"
|
||||
import { dispatchCommand } from "./api.js"
|
||||
|
||||
import {getData4map} from "../actions/data4map.js"
|
||||
import * as cTable from "../utilities/commands.js"
|
||||
import * as ERR from "../utilities/errortexts.js"
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
/* GET home page. */
|
||||
const chartapiRouter = express.Router();
|
||||
|
||||
// normal routes called from javascript client
|
||||
router.get('/:cmd', async (req, res) => {
|
||||
const cmd = req.params.cmd
|
||||
let table
|
||||
for (let c of cTable.chartcmdTable) {
|
||||
if (c.cmd === cmd) {
|
||||
let erg = await c.func(req.query)
|
||||
if (typeof erg === 'string') {
|
||||
res.type('text')
|
||||
res.send(erg)
|
||||
} else {
|
||||
res.json(erg)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
res.json({err: ERR.CMNDUNKOWN})
|
||||
chartapiRouter.get('/:cmd', async (req, res) => {
|
||||
const params = req.query
|
||||
params.kind = 'chart'
|
||||
await dispatchCommand(req.params.cmd, tables.cmdTable, params, res)
|
||||
})
|
||||
|
||||
router.post('/:cmd', async (req, res) => {
|
||||
const cmd = req.params.cmd
|
||||
if (cmd === 'getdata4maps') {
|
||||
const erg = await getData4map(req.body)
|
||||
res.json(erg)
|
||||
} else {
|
||||
res.json({err: ERR.CMNDUNKOWN})
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
export default chartapiRouter
|
||||
@@ -1,7 +1,4 @@
|
||||
import express from 'express'
|
||||
|
||||
import {getData4map} from "../actions/data4map.js"
|
||||
import * as cTable from "../utilities/commands.js"
|
||||
import * as ERR from "../utilities/errortexts.js"
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
Reference in New Issue
Block a user