-
Notifications
You must be signed in to change notification settings - Fork 398
Closed
Labels
status: awaiting answerAwaiting answer from the author of issue or PR.Awaiting answer from the author of issue or PR.
Description
I was trying to...
I have a very specific scenario giving the following situation where I need to check on all my routes if a param resourceType exists or not add some params to the request object giving my param value:
app.param('resourceType', (req, res, next, resourceType) => {
try {
const {
getResource,
getResources,
getUsers,
getRoles,
updateRole,
deleteRole,
createSuperAdmin,
deleteSuperAdmin,
} = getResourceRoutersParams(resourceType);
req.resource = {
getResource,
getResources,
getUsers,
getRoles,
updateRole,
deleteRole,
createSuperAdmin,
deleteSuperAdmin,
};
next();
} catch (e) {
logger.error(e);
throw new ResourceNotFoundError();
}
})I'm solving the issue using the app.param API
The problem:
All my routes contain a :resourceType param:
- GET
/resources/:resourceType/:resourceId/users - GET
/resources/:resourceType/roles - GET/PUT/DELETE
/users/:userId/:resourceType - GET/PUT/DELETE
/users/:userId/:resourceType/:resourceId
There is any way to implement it other than adding a middleware for each route?
Metadata
Metadata
Assignees
Labels
status: awaiting answerAwaiting answer from the author of issue or PR.Awaiting answer from the author of issue or PR.