Add data extract controllers and routes

This commit is contained in:
Maciej Ziarkowski 2019-08-29 17:54:08 +01:00
parent 1008c09905
commit 6733d02876
3 changed files with 35 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import { queryLocation } from './services/search';
import buildingsRouter from './routes/buildingsRouter';
import usersRouter from './routes/usersRouter';
import extractsRouter from './routes/extractsRouter';
const server = express.Router();
@ -15,6 +16,7 @@ server.use(bodyParser.json());
server.use('/buildings', buildingsRouter);
server.use('/users', usersRouter);
server.use('/extracts', extractsRouter);
// GET own user info
server.route('/users/me')

View File

@ -0,0 +1,23 @@
import express from 'express';
import * as dataExtractService from '../services/dataExtract';
import asyncController from '../routes/asyncController';
export const getAllDataExtracts = asyncController(async function(req: express.Request, res: express.Response) {
try {
const dataExtracts = await dataExtractService.listDataExtracts();
res.send({ extracts: dataExtracts });
} catch (err) {
res.send({ error: 'Database error' });
}
});
export const getDataExtract = asyncController(async function(req: express.Request, res: express.Response) {
try {
const extractId = req.params.extract_id;
const extract = await dataExtractService.getDataExtractById(extractId);
res.send({ extract: extract });
} catch (err) {
res.send({ error: 'Database error' });
}
});

View File

@ -0,0 +1,10 @@
import express from 'express';
import * as extractController from '../controllers/extractController';
const router = express.Router();
router.get('/', extractController.getAllDataExtracts);
router.get('/:extract_id', extractController.getDataExtract);
export default router;