Created
May 30, 2015 19:17
-
-
Save nim23/4bedb57965a663dd0c79 to your computer and use it in GitHub Desktop.
Book shelf koa
This file contains hidden or 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
'use strict'; | |
const router = require('koa-router')(); | |
const Projects = require('../collection/projects'); //Bookshelf collection/model | |
router | |
.get('/projects', function *() { | |
this.body = yield Projects.forge().fetch(); | |
}) | |
.post('/projects', function *() { | |
const project = this.request.body; | |
try { | |
this.body = yield Projects.forge(project).save(); | |
this.status = 200; | |
} catch (err) { | |
this.body = err; | |
this.status = 500; | |
this.throw(500, err); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment