nest-access-control 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,5 +3,6 @@
3
3
  *
4
4
  * You can pass an optional property key to the decorator to get it from the user object
5
5
  * e.g `@UserRoles('permissions')` will return the `req.user.permissions` instead.
6
+ * In case that the request is missing User object the function will return null
6
7
  */
7
8
  export declare const UserRoles: (...dataOrPipes: (string | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
@@ -17,7 +17,7 @@ function userFactory(ctx) {
17
17
  // do something that is only important in the context of Websockets requests
18
18
  throw new Error('Websockets context is not implemented yet');
19
19
  }
20
- else if (ctx.getType() === 'graphql') {
20
+ else if (contextType === 'graphql') {
21
21
  // inline require here, since we don't want to require the graphql module in the pacakge.
22
22
  const { GqlExecutionContext } = require('@nestjs/graphql');
23
23
  // do something that is only important in the context of GraphQL requests
@@ -31,8 +31,11 @@ function userFactory(ctx) {
31
31
  *
32
32
  * You can pass an optional property key to the decorator to get it from the user object
33
33
  * e.g `@UserRoles('permissions')` will return the `req.user.permissions` instead.
34
+ * In case that the request is missing User object the function will return null
34
35
  */
35
- exports.UserRoles = (0, common_1.createParamDecorator)((data, ctx) => {
36
+ exports.UserRoles = (0, common_1.createParamDecorator)((propertyKey, ctx) => {
36
37
  const user = userFactory(ctx);
37
- return data ? user[data] : user.roles;
38
+ if (!user)
39
+ return null;
40
+ return propertyKey ? user[propertyKey] : user.roles;
38
41
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nest-access-control",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Access Control Module For Nestjs Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {