Skip to content

Instantly share code, notes, and snippets.

@tlaitinen
Created August 1, 2018 10:13
Show Gist options
  • Save tlaitinen/f52fe5b66d6266a25e20b7f039025182 to your computer and use it in GitHub Desktop.
Save tlaitinen/f52fe5b66d6266a25e20b7f039025182 to your computer and use it in GitHub Desktop.
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