Created
August 1, 2018 10:13
-
-
Save tlaitinen/f52fe5b66d6266a25e20b7f039025182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as express from 'express'; | |
import {processRequest} from '../db/admin-api'; | |
import db from '../db/sbas-db'; | |
import {validationFailed} from './errors'; | |
import authRoute from './auth-route'; | |
import {RequestT} from '../db/admin-api-types'; | |
const router = express.Router(); | |
router.post('/admin/:requestType', authRoute(async (auth, req, res, next) => { | |
try { | |
const payload = Object.assign({}, req.body, {type: req.params.requestType}); | |
RequestT.decode(payload).fold(validationFailed, async request => { | |
try { | |
const r = await processRequest(db, auth, request); | |
res.json(r); | |
} catch (e) { | |
next(e); | |
} | |
}); | |
} catch (e) { | |
next(e); | |
} | |
})); | |
export default router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment