/docs -> /documents; documents router refactoring

This commit is contained in:
tmshv committed 2016-02-24 18:02:52 +03:00
1 parent 5244beecf8
commit c426e5a8d8
3 files changed
+15 -30

No files matched your search

+14 -24
View File
@@ -1,42 +1,32 @@
/**
* Created by tmshv on 22/11/14.
*/
import co from 'co';
import route from 'koa-route';
import router from './';
import {index, json} from './';
import db from '../core/db';
export default function (app) {
[
[
'/documents',
router.accepts({
'text/html': router.index(),
'text/plain': router.index(),
'application/json': function *() {
let query = {};
this.body = yield db.c('documents')
.find(query)
.toArray();
}
json(function *() {
let query = {};
this.body = yield db.c('documents')
.find(query)
.toArray();
})
],
[
'/documents/:type',
router.accepts({
'text/html': router.index(),
'text/plain': router.index(),
'application/json': function *(type) {
this.body = yield db.c(type)
.find()
.toArray();
}
json(function *(type) {
this.body = yield db.c(type)
.find()
.toArray();
})
],
[
'/document/:doc',
index('../templates/document.html')
]
].forEach(item => {
//let {path, fn} = item;
let [path, fn] = item;
app.use(route.get(path, fn));
});