Add data extract controllers and routes
This commit is contained in:
parent
1008c09905
commit
6733d02876
@ -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')
|
||||
|
23
app/src/api/controllers/extractController.ts
Normal file
23
app/src/api/controllers/extractController.ts
Normal 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' });
|
||||
}
|
||||
});
|
10
app/src/api/routes/extractsRouter.ts
Normal file
10
app/src/api/routes/extractsRouter.ts
Normal 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;
|
Loading…
Reference in New Issue
Block a user