Skip to content

Commit

Permalink
Publish v2.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Shady Khalifa committed Feb 20, 2022
1 parent 62b2799 commit 3cce0b0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/decorators/user-roles.decorators.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
*
* You can pass an optional property key to the decorator to get it from the user object
* e.g `@UserRoles('permissions')` will return the `req.user.permissions` instead.
* In case that the request is missing User object the function will return null
*/
export declare const UserRoles: (...dataOrPipes: (string | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
9 changes: 6 additions & 3 deletions lib/decorators/user-roles.decorators.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function userFactory(ctx) {
// do something that is only important in the context of Websockets requests
throw new Error('Websockets context is not implemented yet');
}
else if (ctx.getType() === 'graphql') {
else if (contextType === 'graphql') {
// inline require here, since we don't want to require the graphql module in the pacakge.
const { GqlExecutionContext } = require('@nestjs/graphql');
// do something that is only important in the context of GraphQL requests
Expand All @@ -31,8 +31,11 @@ function userFactory(ctx) {
*
* You can pass an optional property key to the decorator to get it from the user object
* e.g `@UserRoles('permissions')` will return the `req.user.permissions` instead.
* In case that the request is missing User object the function will return null
*/
exports.UserRoles = (0, common_1.createParamDecorator)((data, ctx) => {
exports.UserRoles = (0, common_1.createParamDecorator)((propertyKey, ctx) => {
const user = userFactory(ctx);
return data ? user[data] : user.roles;
if (!user)
return null;
return propertyKey ? user[propertyKey] : user.roles;
});
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
"accesscontrol": "^2.2.1"
},
"peerDependencies": {
"graphql": "15.0.0",
"@apollo/gateway": "^0.45.1",
"@nestjs/graphql": "^7.6.18",
"apollo-server-core": "^3.6.1",
"graphql": "15.0.0",
"ts-morph": "^13.0.2"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nest-access-control",
"version": "2.0.3",
"version": "2.0.4",
"description": "Access Control Module For Nestjs Framework",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 3cce0b0

Please sign in to comment.