You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
707 B

6 years ago
import { Target } from '../target'
import * as express from 'express'
async function addTask(req, res) {
let body = req.body;
let from = parseInt(body.from);
let to = parseInt(body.to);
if(isNaN(from) || isNaN(to)) {
res.status(500).send('Range error: please fill both "from" and "to" fields');
} else if(from >= to) {
res.status(500).send('Range error: "from" should be less than "to"');
} else {
res.status(200).send('Task added');
let grafanaUrl = req.get('origin');
let target = new Target(grafanaUrl, body.user, body.datasource, body.measurement, body.query, from, to);
target.export();
}
}
export const router = express.Router();
router.post('/', addTask);