@tomei/sso 0.58.11 → 0.59.0

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.58.11",
3
+ "version": "0.59.0",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -22,6 +22,7 @@ import { User } from '../login-user/user';
22
22
  import GroupReportingUserModel from '../../models/group-reporting-user.entity';
23
23
  import GroupModel from '../../models/group.entity';
24
24
  import UserModel from '../../models/user.entity';
25
+ import { UserGroup } from 'components/user-group';
25
26
 
26
27
  export class Group extends TreeNodeBase<Group> {
27
28
  ObjectId: string;
@@ -2192,4 +2193,46 @@ export class Group extends TreeNodeBase<Group> {
2192
2193
  throw error;
2193
2194
  }
2194
2195
  }
2196
+
2197
+ public async unassignUser(
2198
+ UserId: number,
2199
+ loginUser: LoginUser,
2200
+ dbTransaction: Transaction,
2201
+ ) {
2202
+ try {
2203
+ const systemCode =
2204
+ ApplicationConfig.getComponentConfigValue('system-code');
2205
+ const isPrivileged = await loginUser.checkPrivileges(
2206
+ systemCode,
2207
+ 'GROUP_UPDATE',
2208
+ );
2209
+
2210
+ if (!isPrivileged) {
2211
+ throw new ClassError(
2212
+ 'Group',
2213
+ 'GroupErrMsg05',
2214
+ 'You do not have the privilege to update group',
2215
+ );
2216
+ }
2217
+
2218
+ const userGroup = await UserGroup.findOne(
2219
+ dbTransaction,
2220
+ loginUser,
2221
+ this.GroupCode,
2222
+ UserId,
2223
+ );
2224
+
2225
+ if (!userGroup) {
2226
+ throw new ClassError(
2227
+ 'Group',
2228
+ 'GroupErrMsg07',
2229
+ 'User is not assigned to this group',
2230
+ );
2231
+ }
2232
+
2233
+ await userGroup.delete(loginUser, dbTransaction);
2234
+ } catch (error) {
2235
+ throw error;
2236
+ }
2237
+ }
2195
2238
  }
@@ -8,4 +8,12 @@ export class UserGroupRepository
8
8
  constructor() {
9
9
  super(UserGroupModel);
10
10
  }
11
+
12
+ async delete(options: any) {
13
+ try {
14
+ return UserGroupModel.destroy(options);
15
+ } catch (error) {
16
+ throw error;
17
+ }
18
+ }
11
19
  }
@@ -647,51 +647,117 @@ export class UserGroup extends ObjectBase {
647
647
  }
648
648
  }
649
649
 
650
- public static isUserMemberOfGroup(
650
+ public static async isUserMemberOfGroup(
651
651
  dbTransaction: any,
652
652
  loginUser: LoginUser,
653
653
  UserId: number,
654
654
  GroupCode: string,
655
655
  ): Promise<boolean> {
656
- return new Promise(async (resolve, reject) => {
657
- try {
658
- // Part 1: Privilege Checking
659
- // Call loginUser.checkPrivileges() to ensure the user has permission to retrieve system access information.
660
- // SystemCode: Retrieve from app config.
661
- // PrivilegeCode: 'USER_GROUP_VIEW'.
662
- const systemCode =
663
- ApplicationConfig.getComponentConfigValue('system-code');
664
- const isPrivileged = await loginUser.checkPrivileges(
665
- systemCode,
666
- 'USER_GROUP_VIEW',
656
+ try {
657
+ // Part 1: Privilege Checking
658
+ // Call loginUser.checkPrivileges() to ensure the user has permission to retrieve system access information.
659
+ // SystemCode: Retrieve from app config.
660
+ // PrivilegeCode: 'USER_GROUP_VIEW'.
661
+ const systemCode =
662
+ ApplicationConfig.getComponentConfigValue('system-code');
663
+ const isPrivileged = await loginUser.checkPrivileges(
664
+ systemCode,
665
+ 'USER_GROUP_VIEW',
666
+ );
667
+ // If the privilege check fails, throw an error with a 403 Forbidden status.
668
+ if (!isPrivileged) {
669
+ throw new ClassError(
670
+ 'UserGroup',
671
+ 'UserGroupErrMsg0X',
672
+ 'User does not have privilege to view user group.',
673
+ 'isUserMemberOfGroup',
674
+ 403,
667
675
  );
668
- // If the privilege check fails, throw an error with a 403 Forbidden status.
669
- if (!isPrivileged) {
670
- throw new ClassError(
671
- 'UserGroup',
672
- 'UserGroupErrMsg0X',
673
- 'User does not have privilege to view user group.',
674
- 'isUserMemberOfGroup',
675
- 403,
676
- );
677
- }
678
- // Part 2: Retrieve User Group
679
- // Query the sso_UserGroup table to find the user group record with the given UserId and GroupCode.
680
- // If the record exists, return true; otherwise, return false.
681
- const userGroup = await UserGroup.findOne(
682
- dbTransaction,
683
- loginUser,
684
- GroupCode,
685
- UserId,
676
+ }
677
+ // Part 2: Retrieve User Group
678
+ // Query the sso_UserGroup table to find the user group record with the given UserId and GroupCode.
679
+ // If the record exists, return true; otherwise, return false.
680
+ const userGroup = await UserGroup.findOne(
681
+ dbTransaction,
682
+ loginUser,
683
+ GroupCode,
684
+ UserId,
685
+ );
686
+ return !!userGroup;
687
+ } catch (error) {
688
+ throw error;
689
+ }
690
+ }
691
+
692
+ public async delete(
693
+ loginUser: LoginUser,
694
+ dbTransaction: Transaction,
695
+ ): Promise<void> {
696
+ try {
697
+ // Part 1: Privilege Checking
698
+ // Call loginUser.checkPrivileges() to ensure the user has permission to delete user group records.
699
+ // SystemCode: Retrieve from app config.
700
+ // PrivilegeCode: 'USER_GROUP_DELETE'.
701
+ const systemCode =
702
+ ApplicationConfig.getComponentConfigValue('system-code');
703
+ const isPrivileged = await loginUser.checkPrivileges(
704
+ systemCode,
705
+ 'USER_GROUP_DELETE',
706
+ );
707
+ // If the privilege check fails, throw an error with a 403 Forbidden status.
708
+ if (!isPrivileged) {
709
+ throw new ClassError(
710
+ 'UserGroup',
711
+ 'UserGroupErrMsg0X',
712
+ 'User does not have privilege to delete user group.',
713
+ 'delete',
714
+ 403,
686
715
  );
687
- if (userGroup) {
688
- resolve(true);
689
- } else {
690
- resolve(false);
691
- }
692
- } catch (error) {
693
- reject(error);
694
716
  }
695
- });
717
+ // Part 2: Delete User Group
718
+ // Call the UserGroup._Repo.destroy() method to delete the user group record with the given UserGroupId.
719
+ // Pass the dbTransaction parameter to ensure the operation is part of the current transaction.
720
+ await UserGroup._Repository.delete({
721
+ where: {
722
+ UserGroupId: this.UserGroupId,
723
+ },
724
+ transaction: dbTransaction,
725
+ });
726
+ // Part 3: Record Activity History
727
+ // Initialize a variable entityValueBefore to store the current state of the record before the update.
728
+ const entityValueBefore = {
729
+ UserGroupId: this.UserGroupId,
730
+ UserId: this.UserId,
731
+ GroupCode: this.GroupCode,
732
+ Status: this.Status,
733
+ CreatedById: this._CreatedById,
734
+ CreatedAt: this._CreatedAt,
735
+ UpdatedById: this._UpdatedById,
736
+ UpdatedAt: this._UpdatedAt,
737
+ InheritGroupPrivilegeYN: this.InheritGroupPrivilegeYN,
738
+ InheritGroupSystemAccessYN: this.InheritGroupSystemAccessYN,
739
+ };
740
+ // Create an instance of the Activity class and set the following properties:
741
+ // ActivityId: Call activity.createId().
742
+ // Action: Set to ActionEnum.Delete.
743
+ // Description: Set to Delete User Group.
744
+ // EntityType: Set to UserGroup.
745
+ // EntityId: Use the ID of the deleted record.
746
+ // EntityValueBefore: Stringify entityValueBefore to capture the state before the delete.
747
+ // EntityValueAfter: Set to an empty string to indicate the record has been deleted.
748
+ const activity = new Activity();
749
+ activity.ActivityId = activity.createId();
750
+ activity.Action = ActionEnum.DELETE;
751
+ activity.Description = `Delete User Group ${this.UserGroupId}`;
752
+ activity.EntityType = 'UserGroup';
753
+ activity.EntityValueBefore = JSON.stringify(entityValueBefore);
754
+ activity.EntityValueAfter = JSON.stringify({});
755
+ // Call the activity create method with the following parameters:
756
+ // dbTransaction
757
+ // userId: loginUser.UserId
758
+ await activity.create(loginUser.ObjectId, dbTransaction);
759
+ } catch (error) {
760
+ throw error;
761
+ }
696
762
  }
697
763
  }
@@ -0,0 +1,6 @@
1
+ export enum BuildingTypeEnum {
2
+ OUTLET = 'Outlet',
3
+ OFFFICE = 'Office',
4
+ FULFILLMENT_CENTER = 'Fulfillment Center',
5
+ WAREHOUSE = 'Warehouse',
6
+ }
@@ -4,198 +4,100 @@ import {
4
4
  CreatedAt,
5
5
  DataType,
6
6
  ForeignKey,
7
- HasMany,
8
7
  Model,
9
8
  Table,
10
9
  UpdatedAt,
11
10
  } from 'sequelize-typescript';
12
-
13
- import User from './user.entity';
14
- import Staff from './staff.entity';
11
+ import { BuildingTypeEnum } from '../enum/building-type.enum';
12
+ import GroupModel from './group.entity';
15
13
 
16
14
  @Table({
17
- tableName: 'sso_buildings',
15
+ tableName: 'sso_Building',
18
16
  timestamps: true,
19
- createdAt: 'created_at',
20
- updatedAt: 'updated_at',
21
- underscored: true,
17
+ createdAt: 'CreatedAt',
18
+ updatedAt: 'UpdatedAt',
22
19
  })
23
- export default class Building extends Model {
20
+ export default class BuildingModel extends Model {
21
+ @ForeignKey(() => GroupModel)
24
22
  @Column({
25
23
  primaryKey: true,
26
24
  allowNull: false,
27
- autoIncrement: true,
28
- type: DataType.INTEGER,
29
- })
30
- id: number;
31
-
32
- @Column({
33
- allowNull: true,
34
- type: DataType.STRING,
35
- field: 'name',
36
- })
37
- Name: string;
38
-
39
- @Column({
40
- allowNull: false,
41
- type: DataType.STRING,
42
- field: 'code',
25
+ type: DataType.STRING(10),
43
26
  })
44
- Code: string;
45
-
46
- // @ForeignKey(() => BuildingType)
47
- // @Column({
48
- // allowNull: false,
49
- // type: DataType.INTEGER,
50
- // field: 'building_type_id',
51
- // })
52
- // BuildingTypeId: number;
27
+ GroupCode: string;
53
28
 
54
29
  @Column({
55
30
  allowNull: false,
56
- type: DataType.STRING,
57
- field: 'status',
31
+ type: DataType.STRING(100),
58
32
  })
59
- Status: string;
33
+ BuildingType: BuildingTypeEnum;
60
34
 
61
35
  @Column({
62
36
  allowNull: true,
63
- type: DataType.STRING,
64
- field: 'email',
37
+ type: DataType.STRING(200),
65
38
  })
66
39
  Email: string;
67
40
 
68
41
  @Column({
69
42
  allowNull: true,
70
- type: DataType.STRING,
71
- field: 'mobile',
43
+ type: DataType.STRING(20),
72
44
  })
73
45
  Mobile: string;
74
46
 
75
47
  @Column({
76
48
  allowNull: false,
77
- type: DataType.STRING,
78
- field: 'phone',
49
+ type: DataType.STRING(20),
79
50
  })
80
51
  Phone: string;
81
52
 
82
- @Column({
83
- allowNull: false,
84
- type: DataType.STRING,
85
- field: 'address',
86
- })
87
- Address: string;
88
-
89
53
  @Column({
90
54
  allowNull: true,
91
- type: DataType.STRING,
92
- field: 'latitude',
55
+ type: DataType.STRING(10),
93
56
  })
94
- Latitude: string;
57
+ Brand: string;
95
58
 
96
59
  @Column({
97
- allowNull: true,
98
- type: DataType.STRING,
99
- field: 'longitude',
60
+ allowNull: false,
61
+ type: DataType.INTEGER,
100
62
  })
101
- Longitude: string;
63
+ AreaManagerUserId: number;
102
64
 
103
65
  @Column({
104
66
  allowNull: false,
105
- type: DataType.STRING,
106
- field: 'postcode',
67
+ type: DataType.DATE,
107
68
  })
108
- PostCode: string;
109
-
110
- // @ForeignKey(() => Country)
111
- // @Column({
112
- // allowNull: false,
113
- // type: DataType.INTEGER,
114
- // field: 'country_id',
115
- // })
116
- // CountryId: number;
69
+ OpeningDate: Date;
117
70
 
118
71
  @Column({
119
72
  allowNull: false,
120
- type: DataType.STRING,
121
- field: 'state',
73
+ type: DataType.DATE,
122
74
  })
123
- State: string;
75
+ CeasedDate: Date;
124
76
 
125
77
  @Column({
126
- allowNull: false,
127
- type: DataType.STRING,
128
- field: 'city',
78
+ allowNull: true,
79
+ type: DataType.STRING(200),
129
80
  })
130
- City: string;
81
+ OpeningHours: string;
131
82
 
132
- @ForeignKey(() => User)
133
83
  @Column({
134
- allowNull: true,
84
+ allowNull: false,
135
85
  type: DataType.INTEGER,
136
- field: 'created_by_id',
137
86
  })
138
87
  CreatedById: number;
139
88
 
140
- @ForeignKey(() => User)
141
89
  @Column({
142
- allowNull: true,
90
+ allowNull: false,
143
91
  type: DataType.INTEGER,
144
- field: 'updated_by_id',
145
92
  })
146
93
  UpdatedById: number;
147
94
 
148
- @Column({
149
- allowNull: true,
150
- type: DataType.STRING,
151
- field: 'brand',
152
- })
153
- Brand: string;
154
-
155
- @Column({
156
- allowNull: true,
157
- type: DataType.STRING,
158
- field: 'area_staff_id',
159
- })
160
- AreaStaffId: string;
161
-
162
- @Column({
163
- allowNull: true,
164
- type: DataType.DATE,
165
- field: 'opening_date',
166
- })
167
- OpeningDate: Date;
168
-
169
- @Column({
170
- allowNull: true,
171
- type: DataType.DATE,
172
- field: 'ceased_date',
173
- })
174
- CeasedDate: Date;
175
-
176
- @Column({
177
- allowNull: true,
178
- type: DataType.STRING,
179
- field: 'opening_hours',
180
- })
181
- OpeningHours: string;
182
-
183
- @Column({
184
- allowNull: true,
185
- type: DataType.STRING,
186
- field: 'image',
187
- })
188
- Image: string;
189
-
190
95
  @CreatedAt
191
96
  CreatedAt: Date;
192
97
 
193
98
  @UpdatedAt
194
99
  UpdatedAt: Date;
195
100
 
196
- @BelongsTo(() => User, 'created_by_id')
197
- CreatedBy: User;
198
-
199
- @BelongsTo(() => User, 'updated_by_id')
200
- UpdatedBy: User;
101
+ @BelongsTo(() => GroupModel, 'GroupCode')
102
+ Group: GroupModel;
201
103
  }