Skip to content

Instantly share code, notes, and snippets.

@NikolayGalkin
Created November 17, 2015 09:55
Show Gist options
  • Save NikolayGalkin/db0803a18b746d27cb05 to your computer and use it in GitHub Desktop.
Save NikolayGalkin/db0803a18b746d27cb05 to your computer and use it in GitHub Desktop.
'use strict';
const router = require('koa-router')({prefix: '/hooks'});
module.exports = router.routes();
router
.post('/', function*() {
yield this.db.raw('SELECT * FROM events_create(?, ?)', [this.request.body.webhookEvent, this.request.body]);
this.body = {};
})
.get('/', function*() {
const limit = this.request.query.limit;
const page = this.request.query.page;
const result = yield this.db.raw('SELECT * FROM events_list(?, ?)', [page, limit]);
this.body = result.rows;
})
.get('/count', function*() {
const result = yield this.db.raw('SELECT * FROM events_count()');
this.body = result.rows[0];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment