@tomei/sso 0.8.5 → 0.8.7

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": "@tomei/sso",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -100,24 +100,24 @@ export class LoginUser extends ObjectBase implements IPerson {
100
100
  {
101
101
  model: Staff,
102
102
  },
103
- {
104
- model: SystemPrivilege,
105
- Include: {
106
- model: SystemPrivilege,
107
- },
108
- },
103
+ // {
104
+ // model: SystemPrivilege,
105
+ // Include: {
106
+ // model: SystemPrivilege,
107
+ // },
108
+ // },
109
109
  ],
110
110
  });
111
111
 
112
112
  if (user) {
113
113
  const userInfo: IUserInfo = {
114
114
  ObjectId: user.id.toString(),
115
- FullName: user.Staff[0].name,
116
- IDNo: user.Staff[0].idNo,
117
- ContactNo: user.Staff[0].contactNo,
118
- Email: user.Staff[0].email,
115
+ FullName: user.Staff.FullName,
116
+ IDNo: user.Staff.IdNo,
117
+ ContactNo: user.Staff.Mobile,
118
+ Email: user.Staff.Email,
119
119
  Password: user.Password,
120
- staffs: user.Staff[0],
120
+ staffs: user.Staff,
121
121
  };
122
122
 
123
123
  return new LoginUser(sessionService, dbTransaction, userInfo);
@@ -216,15 +216,19 @@ export class LoginUser extends ObjectBase implements IPerson {
216
216
  userId: string,
217
217
  systemId: number,
218
218
  ): Promise<void> {
219
- const systemAccess = await LoginUser._SystemAccessRepository.findOne({
220
- where: {
221
- userId: userId,
222
- systemId: systemId,
223
- },
224
- });
225
-
226
- if (!systemAccess) {
227
- throw new Error("User don't have access to the system.");
219
+ try {
220
+ const systemAccess = await LoginUser._SystemAccessRepository.findOne({
221
+ where: {
222
+ UserId: userId,
223
+ SystemId: systemId,
224
+ },
225
+ });
226
+
227
+ if (!systemAccess) {
228
+ throw new Error("User don't have access to the system.");
229
+ }
230
+ } catch (error) {
231
+ throw error;
228
232
  }
229
233
  }
230
234
 
@@ -287,7 +291,7 @@ export class LoginUser extends ObjectBase implements IPerson {
287
291
  try {
288
292
  const system = await LoginUser._SystemRepository.findOne({
289
293
  where: {
290
- code: systemCode,
294
+ Code: systemCode,
291
295
  },
292
296
  });
293
297
 
@@ -352,17 +356,17 @@ export class LoginUser extends ObjectBase implements IPerson {
352
356
  // Add privileges from the userGroup to the privileges array
353
357
  privileges = [
354
358
  ...privileges,
355
- ...userGroup.groupSystemPrivileges.map((g) => g.systemPrivilege.code),
356
- ...userGroup.groupRolePrivileges.map((g) => g.systemPrivilege.code),
359
+ ...userGroup.GroupSystemPrivileges.map((g) => g.SystemPrivilege.Code),
360
+ ...userGroup.GroupRolePrivileges.map((g) => g.SystemPrivilege.Code),
357
361
  ];
358
362
 
359
363
  // Recursive call if conditions are not met and ParentGroupCode exists
360
364
  const isContinue =
361
- userGroup.groupLevel !== 0 &&
362
- userGroup.allowInheritFromParentYN === 'Y';
365
+ userGroup.GroupLevel !== 0 &&
366
+ userGroup.AllowInheritFromParentYN === 'Y';
363
367
  if (isContinue) {
364
368
  const recursivePrivileges = await this.getPrivilegesFromUserGroup(
365
- userGroup.parentGroupCode,
369
+ userGroup.ParentGroupCode,
366
370
  );
367
371
  privileges = privileges.concat(recursivePrivileges);
368
372
  }
@@ -378,7 +382,7 @@ export class LoginUser extends ObjectBase implements IPerson {
378
382
  try {
379
383
  const userGroup = await LoginUser._UserGroupRepository.findOne({
380
384
  where: {
381
- groupCode: groupCode,
385
+ GroupCode: groupCode,
382
386
  },
383
387
  include: [
384
388
  {
@@ -405,8 +409,8 @@ export class LoginUser extends ObjectBase implements IPerson {
405
409
  try {
406
410
  return await LoginUser._UserUserGroupRepository.findAll({
407
411
  where: {
408
- userId: this.ObjectId,
409
- systemId: systemCode,
412
+ UserId: this.ObjectId,
413
+ SystemId: systemCode,
410
414
  },
411
415
  include: {
412
416
  model: UserGroup,
@@ -438,10 +442,7 @@ export class LoginUser extends ObjectBase implements IPerson {
438
442
  id: this.ObjectId,
439
443
  },
440
444
  include: {
441
- model: UserSystemPrivileges,
442
- include: {
443
- model: SystemPrivilege,
444
- },
445
+ model: SystemPrivilege,
445
446
  },
446
447
  });
447
448
 
@@ -463,25 +464,29 @@ export class LoginUser extends ObjectBase implements IPerson {
463
464
  systemCode: string,
464
465
  privilegeName: string,
465
466
  ): Promise<boolean> {
466
- if (!this.ObjectId) {
467
- throw new Error('ObjectId(UserId) is not set');
468
- }
467
+ try {
468
+ if (!this.ObjectId) {
469
+ throw new Error('ObjectId(UserId) is not set');
470
+ }
469
471
 
470
- const userSession = await this._SessionService.retrieveUserSession(
471
- this.ObjectId,
472
- );
472
+ const userSession = await this._SessionService.retrieveUserSession(
473
+ this.ObjectId,
474
+ );
473
475
 
474
- const systemLogin = userSession.systemLogins.find(
475
- (system) => system.code === systemCode,
476
- );
476
+ const systemLogin = userSession.systemLogins.find(
477
+ (system) => system.code === systemCode,
478
+ );
477
479
 
478
- if (!systemLogin) {
479
- return false;
480
- }
480
+ if (!systemLogin) {
481
+ return false;
482
+ }
481
483
 
482
- const privileges = systemLogin.privileges;
483
- const hasPrivilege = privileges.includes(privilegeName);
484
- return hasPrivilege;
484
+ const privileges = systemLogin.privileges;
485
+ const hasPrivilege = privileges.includes(privilegeName);
486
+ return hasPrivilege;
487
+ } catch (error) {
488
+ throw error;
489
+ }
485
490
  }
486
491
 
487
492
  async checkSession(
@@ -36,7 +36,7 @@ export default class UserGroup extends Model {
36
36
  @ForeignKey(() => Department)
37
37
  @Column({
38
38
  type: DataType.STRING,
39
- field: 'password',
39
+ field: 'DepartmentId',
40
40
  })
41
41
  DepartmentId: string;
42
42
 
@@ -24,6 +24,7 @@ export default class UserSystemPrivileges extends Model {
24
24
  primaryKey: true,
25
25
  allowNull: false,
26
26
  type: DataType.INTEGER,
27
+ field: 'UserId',
27
28
  })
28
29
  UserId: number;
29
30