nfp_sites/api/router.mjs

55 lines
2.6 KiB
JavaScript
Raw Normal View History

2019-02-19 11:34:52 +00:00
/* eslint max-len: 0 */
import Router from 'koa-router'
2019-09-14 19:03:38 +00:00
import access from './access/index.mjs'
import AuthRoutes from './authentication/routes.mjs'
import MediaRoutes from './media/routes.mjs'
import FileRoutes from './file/routes.mjs'
import PageRoutes from './page/routes.mjs'
import ArticleRoutes from './article/routes.mjs'
import StaffRoutes from './staff/routes.mjs'
2019-09-14 19:03:38 +00:00
import { restrict } from './access/middleware.mjs'
2019-02-19 11:34:52 +00:00
const router = new Router()
// API Authentication
2019-02-20 16:10:37 +00:00
const authentication = new AuthRoutes()
router.post('/api/login', authentication.login.bind(authentication))
router.post('/api/login/user', authentication.loginUser.bind(authentication))
2019-02-20 16:10:37 +00:00
// API Media
const media = new MediaRoutes()
2019-09-13 13:33:10 +00:00
router.get('/api/media', restrict(access.Manager), media.getAllMedia.bind(media))
2019-02-20 16:10:37 +00:00
router.post('/api/media', restrict(access.Manager), media.upload.bind(media))
2019-09-13 13:33:10 +00:00
router.del('/api/media/:id', restrict(access.Manager), media.removeMedia.bind(media))
// API File
const file = new FileRoutes()
router.get('/api/file', restrict(access.Manager), file.getAllFiles.bind(file))
router.post('/api/articles/:articleId/file', restrict(access.Manager), file.upload.bind(file))
router.del('/api/file/:id', restrict(access.Manager), file.removeFile.bind(file))
const page = new PageRoutes()
router.get('/api/pages', page.getAllPages.bind(page))
router.get('/api/pages/:id', page.getSinglePage.bind(page))
router.post('/api/pages', restrict(access.Manager), page.createPage.bind(page))
router.put('/api/pages/:id', restrict(access.Manager), page.updatePage.bind(page))
router.del('/api/pages/:id', restrict(access.Manager), page.removePage.bind(page))
const article = new ArticleRoutes()
router.get('/api/articles', article.getAllArticles.bind(article))
2019-09-14 19:03:38 +00:00
router.get('/api/pages/:pageId/articles', article.getAllPageArticles.bind(article))
2019-09-13 13:33:10 +00:00
router.get('/api/articles/:id', article.getSingleArticle.bind(article))
router.post('/api/articles', restrict(access.Manager), article.createArticle.bind(article))
router.put('/api/articles/:id', restrict(access.Manager), article.updateArticle.bind(article))
router.del('/api/articles/:id', restrict(access.Manager), article.removeArticle.bind(article))
2019-02-19 11:34:52 +00:00
const staff = new StaffRoutes()
router.get('/api/staff', restrict(access.Admin), staff.getAllStaff.bind(staff))
router.get('/api/staff/:id', restrict(access.Admin), staff.getSingleStaff.bind(staff))
router.post('/api/staff', restrict(access.Admin), staff.createStaff.bind(staff))
router.put('/api/staff/:id', restrict(access.Admin), staff.updateStaff.bind(staff))
router.del('/api/staff/:id', restrict(access.Admin), staff.removeStaff.bind(staff))
2019-02-19 11:34:52 +00:00
export default router