paradigm-core
Version:
Paradigm Core Modules
45 lines (32 loc) • 2.03 kB
JavaScript
const {
Dispatcher: {dispatch},
} = require('structure-core')
const DocumentController = require('../controllers/document')
const controller = new DocumentController()
const express = require('express')
const routes = express.Router()
const bulkUpdateSchema = require('../schemas/bulk-update')
const updateSchema = require('../schemas/update')
const createSchema = require('../schemas/create')
routes.get('/existence/:key/:value', dispatch(controller, 'checkExistence'))
routes.post(`/fork/template/:id`, dispatch(controller, 'forkTemplate'))
routes.post(`/fork/:id`, dispatch(controller, 'fork'))
routes.get(`/permalink/:permalink*`, dispatch(controller, 'getByPermalink'))
routes.get(`/slug/:slug`, dispatch(controller, 'getBySlug'))
routes.get(`/:id/categories`, dispatch(controller, 'getCategories'))
routes.get(`/:id`, dispatch(controller, 'getById'))
routes.get(`/`, dispatch(controller, 'getAll', {collectionName: false}))
routes.get(`/user/:id`, dispatch(controller, 'getAllByUser', {collectionName: false}))
routes.post(`/:id/publish`, dispatch(controller, 'publishById'))
routes.post(`/:id/purge`, dispatch(controller, 'purgeById'))
routes.post(`/:id/unpublish`, dispatch(controller, 'unpublishById'))
routes.patch(`/:id`, updateSchema, dispatch(controller, 'updateById'))
routes.patch('/', bulkUpdateSchema, dispatch(controller, 'updateMany'))
routes.post(`/`, createSchema, dispatch(controller, 'create'))
routes.delete(`/:id`, dispatch(controller, 'deleteById'))
module.exports = function documentRoutesHandler(options = {}) {
return {
routeName: 'documents',
routes
}
}