Browse Source

Add formatting to /measurements

main
Haris Razis 4 years ago
parent
commit
f803ddc135
No known key found for this signature in database GPG Key ID: 86A4D290ED03FAB4
  1. 6
      server/src/class/Database.ts
  2. 18
      server/src/routes/Routes.ts

6
server/src/class/Database.ts

@ -68,7 +68,11 @@ export class Database {
let formatedData: Array<{}> = []; let formatedData: Array<{}> = [];
rawData.forEach((element: any) => { rawData.forEach((element: any) => {
formatedData.push({ time: element._time, value: element._value }); formatedData.push({
client: element.client,
time: element._time,
value: element._value,
});
}); });
return formatedData; return formatedData;

18
server/src/routes/Routes.ts

@ -1,5 +1,4 @@
import * as express from 'express'; import * as express from 'express';
import { Database } from '../class/Database';
import { Service } from '../class/Service'; import { Service } from '../class/Service';
export class Routes { export class Routes {
@ -39,17 +38,14 @@ export class Routes {
private measurements(): void { private measurements(): void {
this.app.get('/measurements', async (req, res) => { this.app.get('/measurements', async (req, res) => {
req.on('data', async (data) => { const points = await this.service.database.query('temperature', '1h');
const { filter, timeFrame } = JSON.parse(data);
const points = await this.service.database.query('temperature', '5m');
res.header('Content-Type', 'application/json'); res.header('Content-Type', 'application/json');
if (points) { if (points) {
res.send(JSON.stringify(points)); res.send(JSON.stringify(points));
} else { } else {
res.send(JSON.stringify({})); res.send(JSON.stringify({}));
} }
});
}); });
} }

Loading…
Cancel
Save