@solidstarters/solid-core 1.2.33 → 1.2.36

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.33",
3
+ "version": "1.2.36",
4
4
  "description": "This module is a NestJS module containing all the required core providers required by a Solid application",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -173,7 +173,7 @@ export class CrudHelperService {
173
173
  if (normalizedFields && normalizedFields.length) {
174
174
  qb.select(normalizedFields.map(field => {
175
175
  // If the field contains a (, do not prefix the entity alias
176
- return this.isAggregateField(field) ? field : `${entityAlias}.${field}`;
176
+ return this.wrapFieldWithAlias(field, entityAlias);
177
177
  }));
178
178
  }
179
179
 
@@ -220,6 +220,15 @@ export class CrudHelperService {
220
220
  return qb;
221
221
  }
222
222
 
223
+ private wrapFieldWithAlias(field: string, entityAlias: string): string {
224
+ if (!this.isAggregateField(field)) return `${entityAlias}.${field}`;
225
+ // For aggregate fields, extract the field name from the aggregate function & wrap it with the entity alias, if it is not already wrapped
226
+ const fieldParts = field.split('(');
227
+ const aggregateFunction = fieldParts[0];
228
+ const fieldName = fieldParts[1].replace(')', '');
229
+ return `${aggregateFunction}(${entityAlias}.${fieldName})`;
230
+ }
231
+
223
232
  isAggregateField(field: string): boolean {
224
233
  return field.includes('(');
225
234
  }
@@ -303,6 +312,11 @@ export class CrudHelperService {
303
312
  const matchingPermssions = activeUser.permissions.filter((p) => permissionNames.includes(p));
304
313
  return matchingPermssions.length > 0
305
314
  }
315
+ hasRecoverPermissionOnModel = (activeUser: ActiveUserData, modelName: string) => {
316
+ const permissionNames = [`${classify(modelName)}Controller.recover`, `${classify(modelName)}Controller.recoverMany`];
317
+ const matchingPermssions = activeUser.permissions.filter((p) => permissionNames.includes(p));
318
+ return matchingPermssions.length > 0
319
+ }
306
320
 
307
321
 
308
322
 
@@ -701,8 +701,17 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
701
701
  // return removedEntities
702
702
  }
703
703
 
704
- async recover(id: number) {
704
+ async recover(id: number,solidRequestContext: any = {}) {
705
705
  try {
706
+ const loadedmodel = await this.loadModel();
707
+ // Check wheather user has update permission for model
708
+ if (solidRequestContext.activeUser) {
709
+ const hasPermission = this.crudHelperService.hasRecoverPermissionOnModel(solidRequestContext.activeUser, loadedmodel.singularName);
710
+ if (!hasPermission) {
711
+ throw new BadRequestException('Forbidden');
712
+ }
713
+ }
714
+
706
715
  const softDeletedRows = await this.repo.findOne({
707
716
  where: {
708
717
  //@ts-ignore
@@ -732,8 +741,17 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
732
741
  }
733
742
  }
734
743
 
735
- async recoverMany(ids: number[]) {
744
+ async recoverMany(ids: number[],solidRequestContext: any = {}) {
736
745
  try {
746
+ const loadedmodel = await this.loadModel();
747
+ // Check wheather user has update permission for model
748
+ if (solidRequestContext.activeUser) {
749
+ const hasPermission = this.crudHelperService.hasRecoverPermissionOnModel(solidRequestContext.activeUser, loadedmodel.singularName);
750
+ if (!hasPermission) {
751
+ throw new BadRequestException('Forbidden');
752
+ }
753
+ }
754
+
737
755
  if (!ids || ids.length === 0) {
738
756
  throw new Error("No IDs provided for recovery.");
739
757
  }