@punks/backend-entity-manager 0.0.195 → 0.0.197

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.
package/dist/cjs/index.js CHANGED
@@ -2835,11 +2835,21 @@ class QueryClauseBuilder {
2835
2835
  }
2836
2836
  }
2837
2837
 
2838
+ class PermissionsChecker {
2839
+ hasAny(context, permissions) {
2840
+ return (context.userPermissions?.some((p) => permissions.includes(p.uid)) ?? false);
2841
+ }
2842
+ hasAll(context, permissions) {
2843
+ return (permissions.every((p) => context.userPermissions?.some((up) => up.uid === p)) ?? false);
2844
+ }
2845
+ }
2846
+
2838
2847
  class TypeOrmQueryBuilder extends QueryBuilderBase {
2839
2848
  constructor(services) {
2840
2849
  super();
2841
2850
  this.services = services;
2842
2851
  this.clause = new QueryClauseBuilder();
2852
+ this.permissions = new PermissionsChecker();
2843
2853
  }
2844
2854
  async get(id, context) {
2845
2855
  return await this.getRepository().get(id, {
@@ -3176,6 +3186,9 @@ class TypeOrmRepository {
3176
3186
  }
3177
3187
 
3178
3188
  class NestEntityAuthorizationMiddleware {
3189
+ constructor() {
3190
+ this.permissions = new PermissionsChecker();
3191
+ }
3179
3192
  }
3180
3193
 
3181
3194
  class NestEntityActions {