Skip to content

Commit

Permalink
Clean up http routes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkfranz committed Nov 14, 2017
1 parent 0ede648 commit 56421dc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
55 changes: 28 additions & 27 deletions src/server/routes/api/document/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const provider = require('./reach');
const uuid = require('uuid');
const { makeCyEles, getCyLayoutOpts } = require('../../../../util');
const Cytoscape = require('cytoscape');
const http = require('express').Router();

let newDoc = ({ docDb, eleDb, id, secret }) => {
return new Document( _.assign( {}, docDb, {
Expand Down Expand Up @@ -74,30 +75,30 @@ let runLayout = doc => {
return Promise.try( runLayout ).then( savePositions ).then( getDoc );
};

module.exports = function( http ){
// get existing doc
http.get('/document/:id', function( req, res ){
let id = req.params.id;

( Promise.try( loadTables )
.then( json => _.assign( {}, json, { id } ) )
.then( loadDoc )
.then( getDocJson )
.then( json => res.json( json ) )
);
});

// create new doc
http.post('/document', function( req, res ){
let text = req.body.text;
let secret = uuid();

( Promise.try( loadTables )
.then( ({ docDb, eleDb }) => createDoc({ docDb, eleDb, secret }) )
.then( doc => fillDoc( doc, text ) )
.then( runLayout )
.then( getDocJson )
.then( json => res.json( json ) )
);
});
};
// get existing doc
http.get('/:id', function( req, res ){
let id = req.params.id;

( Promise.try( loadTables )
.then( json => _.assign( {}, json, { id } ) )
.then( loadDoc )
.then( getDocJson )
.then( json => res.json( json ) )
);
});

// create new doc
http.post('/', function( req, res ){
let text = req.body.text;
let secret = uuid();

( Promise.try( loadTables )
.then( ({ docDb, eleDb }) => createDoc({ docDb, eleDb, secret }) )
.then( doc => fillDoc( doc, text ) )
.then( runLayout )
.then( getDocJson )
.then( json => res.json( json ) )
);
});

module.exports = http;
17 changes: 9 additions & 8 deletions src/server/routes/api/element-association/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const provider = require('./uniprot');
const jsonifyResult = response => ( result => response.json( result ) );
const http = require('express').Router();

module.exports = function( http ){
http.get('/element-association/search', function( req, res ){
provider.search( req.query ).then( jsonifyResult(res) );
});
http.get('/search', function( req, res ){
provider.search( req.query ).then( jsonifyResult(res) );
});

http.get('/element-association/get', function( req, res ){
provider.get( req.query ).then( jsonifyResult(res) );
});
};
http.get('/get', function( req, res ){
provider.get( req.query ).then( jsonifyResult(res) );
});

module.exports = http;
6 changes: 2 additions & 4 deletions src/server/routes/api/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
let http = require('express').Router();

[
require('./document'),
require('./element-association')
].forEach( defineRoutes => defineRoutes( http ) );
http.use('/element-association', require('./element-association'));
http.use('/document', require('./document'));

module.exports = http;

0 comments on commit 56421dc

Please sign in to comment.