// Collezione di tutte le api che usando influxdb e la telemetria della barca

//api.mebboat.it/data

const router = require('express').Router();

const { write, query, writeBatch } = require('../storage/influx');

router.post('/write', async (req, res) => {
    const { measurement, sensor, data } = req.body;
    await write(measurement, sensor, data);
    res.json({ status: "ok" });
});

router.post('/write/batch', async (req, res) => {
    const { points } = req.body;
    await writeBatch(points);
    res.json({ result: "added" });
});

router.get('/query', async (req, res) => {
    const { collection, timeFromNow, measurement, sensor, field } = req.query;
    const result = await query(collection, timeFromNow, measurement, sensor, field);
    res.json(result);
});

module.exports = router;