fix(routes): reorder Express routes placing specific sub-routes before generic :id parameter routes
This commit is contained in:
@@ -13,16 +13,23 @@ import {
|
||||
|
||||
const router = Router();
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/v1/channels:
|
||||
* get:
|
||||
* summary: Retrieve all channels
|
||||
* tags: [Channels]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Success
|
||||
*/
|
||||
// 1. Static Bulk Routes (MUST BE FIRST)
|
||||
router.post(
|
||||
'/syndicate-all',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
audit('TRIGGER_BULK_SYNDICATION'),
|
||||
controller.syndicateAll
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/jobs/:jobId',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
controller.getJobById
|
||||
);
|
||||
|
||||
// 2. Base Collection Routes
|
||||
router.get(
|
||||
'/',
|
||||
authenticate,
|
||||
@@ -30,41 +37,6 @@ router.get(
|
||||
controller.getAll
|
||||
);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/v1/channels/{id}:
|
||||
* get:
|
||||
* summary: Retrieve a single channel
|
||||
* tags: [Channels]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Success
|
||||
*/
|
||||
router.get(
|
||||
'/:id',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
getByIdValidation,
|
||||
validate,
|
||||
controller.getById
|
||||
);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/v1/channels:
|
||||
* post:
|
||||
* summary: Create a channel
|
||||
* tags: [Channels]
|
||||
* responses:
|
||||
* 201:
|
||||
* description: Success
|
||||
*/
|
||||
router.post(
|
||||
'/',
|
||||
authenticate,
|
||||
@@ -75,52 +47,49 @@ router.post(
|
||||
controller.create
|
||||
);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/v1/channels/{id}:
|
||||
* put:
|
||||
* summary: Update a channel
|
||||
* tags: [Channels]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Success
|
||||
*/
|
||||
router.put(
|
||||
'/:id',
|
||||
// 3. Sub-resource Routes for Specific Channel
|
||||
router.get(
|
||||
'/:id/mappings',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
updateValidation,
|
||||
validate,
|
||||
audit('UPDATE_CHANNEL'),
|
||||
controller.update
|
||||
controller.getMappings
|
||||
);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/v1/channels/{id}:
|
||||
* delete:
|
||||
* summary: Delete a channel
|
||||
* tags: [Channels]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Success
|
||||
*/
|
||||
router.delete(
|
||||
'/:id',
|
||||
router.put(
|
||||
'/:id/mappings',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
deleteValidation,
|
||||
validate,
|
||||
audit('DELETE_CHANNEL'),
|
||||
controller.delete
|
||||
audit('UPDATE_CHANNEL_MAPPINGS'),
|
||||
controller.upsertMappings
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/:id/syndicate',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
audit('TRIGGER_CHANNEL_SYNDICATION'),
|
||||
controller.triggerSyndication
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/:id/jobs',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
controller.getJobs
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/:id/preview',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
controller.previewPayload
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/:id/test-connection',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
controller.testConnection
|
||||
);
|
||||
|
||||
router.post(
|
||||
@@ -143,65 +112,34 @@ router.post(
|
||||
controller.restore
|
||||
);
|
||||
|
||||
// Channel Field Mappings
|
||||
// 4. Generic Parameterized Channel ID Routes (MUST BE LAST)
|
||||
router.get(
|
||||
'/:id/mappings',
|
||||
'/:id',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
controller.getMappings
|
||||
getByIdValidation,
|
||||
validate,
|
||||
controller.getById
|
||||
);
|
||||
|
||||
router.put(
|
||||
'/:id/mappings',
|
||||
'/:id',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
audit('UPDATE_CHANNEL_MAPPINGS'),
|
||||
controller.upsertMappings
|
||||
updateValidation,
|
||||
validate,
|
||||
audit('UPDATE_CHANNEL'),
|
||||
controller.update
|
||||
);
|
||||
|
||||
// Syndication Jobs & Execution
|
||||
router.post(
|
||||
'/:id/syndicate',
|
||||
router.delete(
|
||||
'/:id',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
audit('TRIGGER_CHANNEL_SYNDICATION'),
|
||||
controller.triggerSyndication
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/:id/jobs',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
controller.getJobs
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/jobs/:jobId',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
controller.getJobById
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/:id/preview',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
controller.previewPayload
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/syndicate-all',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
audit('TRIGGER_BULK_SYNDICATION'),
|
||||
controller.syndicateAll
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/:id/test-connection',
|
||||
authenticate,
|
||||
authorize(['settings.integrations']),
|
||||
controller.testConnection
|
||||
deleteValidation,
|
||||
validate,
|
||||
audit('DELETE_CHANNEL'),
|
||||
controller.delete
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user