templates/app/routes/route.hbs
const express = require('express');
const { PermissionMiddlewareCreator } = require('forest-express-{{#if isMongoDB }}mongoose{{else}}sequelize{{/if}}');
const { {{ modelName }} } = require('../models');
const router = express.Router();
const permissionMiddlewareCreator = new PermissionMiddlewareCreator('{{ modelName }}');
// This file contains the logic of every route in Forest Admin for the collection {{ modelName }}:
// - Native routes are already generated but can be extended/overriden - Learn how to extend a route here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/extend-a-route
// - Smart action routes will need to be added as you create new Smart Actions - Learn how to create a Smart Action here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/actions/create-and-manage-smart-actions
// Create a {{ modelNameReadableSingular }}
router.post('/{{ modelName }}', permissionMiddlewareCreator.create(), (request, response, next) => {
// Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#create-a-record
next();
});
// Update a {{ modelNameReadableSingular }}
router.put('/{{ modelName }}/:recordId', permissionMiddlewareCreator.update(), (request, response, next) => {
// Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#update-a-record
next();
});
// Delete a {{ modelNameReadableSingular }}
router.delete('/{{ modelName }}/:recordId', permissionMiddlewareCreator.delete(), (request, response, next) => {
// Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#delete-a-record
next();
});
// Get a list of {{ modelNameReadablePlural }}
router.get('/{{ modelName }}', permissionMiddlewareCreator.list(), (request, response, next) => {
// Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#get-a-list-of-records
next();
});
// Get a number of {{ modelNameReadablePlural }}
router.get('/{{ modelName }}/count', permissionMiddlewareCreator.list(), (request, response, next) => {
// Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#get-a-number-of-records
next();
});
// Get a {{ modelNameReadableSingular }}
router.get('/{{ modelName }}/:recordId(?!count)', permissionMiddlewareCreator.details(), (request, response, next) => {
// Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#get-a-record
next();
});
// Export a list of {{ modelNameReadablePlural }}
router.get('/{{ modelName }}.csv', permissionMiddlewareCreator.export(), (request, response, next) => {
// Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#export-a-list-of-records
next();
});
// Delete a list of {{ modelNameReadablePlural }}
router.delete('/{{ modelName }}', permissionMiddlewareCreator.delete(), (request, response, next) => {
// Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#delete-a-list-of-records
next();
});
module.exports = router;