Skip to content

Instantly share code, notes, and snippets.

@ndugger
Created June 29, 2017 15:27
Show Gist options
  • Save ndugger/f6b39a62d56b20ac3809d75652f21153 to your computer and use it in GitHub Desktop.
Save ndugger/f6b39a62d56b20ac3809d75652f21153 to your computer and use it in GitHub Desktop.
import router from 'redshirt';
import { admin, body } from '../middleware';
import { db, json, slugify } from '../util';
router.group('/forums/categories')
.get('/', async () => {
return json(await db.forums.categories.all());
})
.post('/', [ admin, body ], async request => {
const category = JSON.parse(request.body.toString());
const slug = slugify(category.title);
const created = await db.forums.categories.create({ ...category, slug });
return json(created);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment