@tomei/sso 0.31.5 → 0.31.6

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.31.5",
3
+ "version": "0.31.6",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -7,6 +7,7 @@ import { IGroupSearchAttr } from '../../interfaces/group-search-attr.interface';
7
7
  import { ApplicationConfig } from '@tomei/config';
8
8
  import { Op } from 'sequelize';
9
9
  import { ActionEnum, Activity } from '@tomei/activity-history';
10
+ import { GroupSystemAccessRepository } from '../group-system-access/group-system-access.repository';
10
11
 
11
12
  export class Group extends ObjectBase {
12
13
  ObjectId: string;
@@ -27,6 +28,7 @@ export class Group extends ObjectBase {
27
28
  private _UpdatedById: number;
28
29
  private _UpdatedAt: Date;
29
30
  private static _Repo = new GroupRepository();
31
+ private static _SystemAccessRepo = new GroupSystemAccessRepository();
30
32
 
31
33
  get GroupCode(): string {
32
34
  return this.ObjectId;
@@ -331,7 +333,6 @@ export class Group extends ObjectBase {
331
333
  'GROUP_UPDATE',
332
334
  );
333
335
 
334
- //If user does not have privilege to update user, throw a ClassError
335
336
  if (!isPrivileged) {
336
337
  throw new ClassError(
337
338
  'Group',
@@ -444,4 +445,70 @@ export class Group extends ObjectBase {
444
445
  throw error;
445
446
  }
446
447
  }
448
+
449
+ public static async getSystemAccesses(
450
+ loginUser: LoginUser,
451
+ dbTransaction: any,
452
+ GroupCode: string,
453
+ Page: number,
454
+ Rows: number,
455
+ Search: {
456
+ SystemCode?: string;
457
+ Status?: string;
458
+ },
459
+ ) {
460
+ // Part 1: Privilege Checking
461
+ const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
462
+ const isPrivileged = await loginUser.checkPrivileges(
463
+ systemCode,
464
+ 'SYSTEM_ACCESS_VIEW',
465
+ );
466
+
467
+ if (!isPrivileged) {
468
+ throw new ClassError(
469
+ 'Group',
470
+ 'GroupErrMsg06',
471
+ 'You do not have the privilege to view system access',
472
+ );
473
+ }
474
+
475
+ try {
476
+ // Part 2: Validation
477
+ await Group.init(dbTransaction, GroupCode);
478
+
479
+ // Part 3: Retrieve System Access and returns
480
+ const queryObj: any = { GroupCode: GroupCode };
481
+
482
+ if (Search) {
483
+ Object.entries(Search).forEach(([key, value]) => {
484
+ queryObj[key] = {
485
+ [Op.eq]: value,
486
+ };
487
+ });
488
+ }
489
+
490
+ let options: any = {
491
+ where: queryObj,
492
+ distinct: true,
493
+ transaction: dbTransaction,
494
+ };
495
+
496
+ if (Page && Rows) {
497
+ options = {
498
+ ...options,
499
+ limit: Rows,
500
+ offset: Rows * (Page - 1),
501
+ order: [
502
+ ['CreatedAt', 'DESC'],
503
+ ['Status', 'Active'],
504
+ ],
505
+ };
506
+ }
507
+
508
+ const systemAccess = await Group._SystemAccessRepo.findAndCountAll();
509
+ return systemAccess;
510
+ } catch (error) {
511
+ return error;
512
+ }
513
+ }
447
514
  }
@@ -8,4 +8,22 @@ export class GroupSystemAccessRepository
8
8
  constructor() {
9
9
  super(GroupSystemAccessModel);
10
10
  }
11
+
12
+ async findAndCountAll(options?: any) {
13
+ try {
14
+ let GroupSystemAccess: any;
15
+ if (options) {
16
+ GroupSystemAccess = await GroupSystemAccessModel.findAndCountAll(
17
+ options,
18
+ );
19
+ } else {
20
+ GroupSystemAccess = await GroupSystemAccessModel.findAndCountAll();
21
+ }
22
+ return GroupSystemAccess;
23
+ } catch (error) {
24
+ throw new Error(
25
+ `An Error occured when retriving GroupSystemAccess: ${error.message}`,
26
+ );
27
+ }
28
+ }
11
29
  }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=login-user.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"login-user.spec.js","sourceRoot":"","sources":["../../../../../__tests__/unit/components/login-user/login-user.spec.ts"],"names":[],"mappings":""}