Browse Source

deleteRouter -> `DELETE /api/tasks`

pull/3/head
rozetko 2 years ago
parent
commit
ee16249004
  1. 2
      src/routes/api.ts
  2. 25
      src/routes/delete.ts
  3. 27
      src/routes/tasks.ts

2
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));

25
src/routes/delete.ts

@ -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);

27
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);

Loading…
Cancel
Save