diff --git a/src/routes/api.ts b/src/routes/api.ts index 8e55309..9c808d8 100644 --- a/src/routes/api.ts +++ b/src/routes/api.ts @@ -1,7 +1,6 @@ import { EXPORTED_PATH } from '../config'; import { router as tasksRouter } from '../routes/tasks'; import { router as statusRouter } from '../routes/status'; -import { router as deleteRouter } from '../routes/delete'; import * as express from 'express'; @@ -11,6 +10,5 @@ export const router = express.Router(); router.use('/status', statusRouter); router.use('/tasks', tasksRouter); -router.use('/delete', deleteRouter); router.use('/static', express.static(EXPORTED_PATH)); diff --git a/src/routes/delete.ts b/src/routes/delete.ts deleted file mode 100644 index 3079222..0000000 --- a/src/routes/delete.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { EXPORTED_PATH } from '../config' - -import * as express from 'express' -import * as fs from 'fs' -import * as path from 'path' - - -async function deleteTask(req, res) { - let filename = req.query.filename; - let csvFilePath = path.join(EXPORTED_PATH, `${filename}.csv`); - let jsonFilePath = path.join(EXPORTED_PATH, `${filename}.json`); - - if(fs.existsSync(csvFilePath)) { - fs.unlink(csvFilePath, err => console.error(err)); - } - if(fs.existsSync(jsonFilePath)) { - fs.unlink(jsonFilePath, err => console.error(err)); - } - - res.status(200).send({ status: 'OK' }); -} - -export const router = express.Router(); - -router.get('/', deleteTask); diff --git a/src/routes/tasks.ts b/src/routes/tasks.ts index 27fbed5..b4359d7 100644 --- a/src/routes/tasks.ts +++ b/src/routes/tasks.ts @@ -1,8 +1,13 @@ -import { Target } from '../types/target' +import { Target } from '../types/target'; +import { exporterFactory } from '../services/exporter.factory'; +import { EXPORTED_PATH } from '../config'; -import * as express from 'express' import { Datasource } from '@corpglory/tsdb-kit'; -import { exporterFactory } from '../services/exporter.factory'; + +import * as express from 'express'; + +import * as path from 'path'; +import * as fs from 'fs'; type TRequest = { body: { @@ -60,7 +65,23 @@ async function addTask(req: TRequest, res) { } } +async function deleteTask(req, res) { + let filename = req.query.filename; + let csvFilePath = path.join(EXPORTED_PATH, `${filename}.csv`); + let jsonFilePath = path.join(EXPORTED_PATH, `${filename}.json`); + + if(fs.existsSync(csvFilePath)) { + fs.unlink(csvFilePath, err => console.error(err)); + } + if(fs.existsSync(jsonFilePath)) { + fs.unlink(jsonFilePath, err => console.error(err)); + } + + res.status(200).send({ status: 'OK' }); +} + export const router = express.Router(); router.get('/', getTasks); router.post('/', addTask); +router.delete('/', deleteTask);