rez_core 2.0.1 → 2.0.2

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.
Files changed (39) hide show
  1. package/dist/module/meta/controller/entity.controller.d.ts +1 -1
  2. package/dist/module/meta/controller/entity.controller.js +14 -11
  3. package/dist/module/meta/controller/entity.controller.js.map +1 -1
  4. package/dist/module/meta/service/entity-list.service.d.ts +2 -2
  5. package/dist/module/meta/service/entity-list.service.js +18 -7
  6. package/dist/module/meta/service/entity-list.service.js.map +1 -1
  7. package/dist/module/meta/service/entity-service-impl.service.d.ts +3 -3
  8. package/dist/module/meta/service/entity-service-impl.service.js +4 -4
  9. package/dist/module/meta/service/entity-service-impl.service.js.map +1 -1
  10. package/dist/module/meta/service/entity.service.d.ts +2 -2
  11. package/dist/module/module/controller/module-access.controller.d.ts +5 -5
  12. package/dist/module/module/controller/module-access.controller.js +28 -16
  13. package/dist/module/module/controller/module-access.controller.js.map +1 -1
  14. package/dist/module/module/repository/module-access.repository.d.ts +10 -6
  15. package/dist/module/module/repository/module-access.repository.js +45 -29
  16. package/dist/module/module/repository/module-access.repository.js.map +1 -1
  17. package/dist/module/module/service/module-access.service.d.ts +9 -5
  18. package/dist/module/module/service/module-access.service.js +12 -10
  19. package/dist/module/module/service/module-access.service.js.map +1 -1
  20. package/dist/module/user/dto/create-user.dto.d.ts +1 -0
  21. package/dist/module/user/dto/create-user.dto.js.map +1 -1
  22. package/dist/module/user/service/role.service.d.ts +1 -1
  23. package/dist/module/user/service/role.service.js +4 -1
  24. package/dist/module/user/service/role.service.js.map +1 -1
  25. package/dist/module/user/service/user.service.d.ts +1 -1
  26. package/dist/module/user/service/user.service.js +4 -1
  27. package/dist/module/user/service/user.service.js.map +1 -1
  28. package/dist/tsconfig.build.tsbuildinfo +1 -1
  29. package/package.json +1 -1
  30. package/src/module/meta/controller/entity.controller.ts +27 -12
  31. package/src/module/meta/service/entity-list.service.ts +29 -7
  32. package/src/module/meta/service/entity-service-impl.service.ts +29 -17
  33. package/src/module/meta/service/entity.service.ts +2 -1
  34. package/src/module/module/controller/module-access.controller.ts +48 -21
  35. package/src/module/module/repository/module-access.repository.ts +69 -50
  36. package/src/module/module/service/module-access.service.ts +15 -13
  37. package/src/module/user/dto/create-user.dto.ts +1 -0
  38. package/src/module/user/service/role.service.ts +5 -1
  39. package/src/module/user/service/user.service.ts +4 -0
@@ -21,36 +21,42 @@ export class ModuleAccessRepository {
21
21
  private readonly moduleActionRepo: Repository<ModuleAction>,
22
22
  ) {}
23
23
 
24
- async getRoles() {
25
- const roles = await this.roleRepo.find();
26
- return roles.map(role => ({
24
+ async getRoles({ appcode }: { appcode: string }) {
25
+ const roles = await this.roleRepo.find({
26
+ where: { appcode: appcode },
27
+ });
28
+ return roles.map((role) => ({
27
29
  label: role.name,
28
30
  value: role.id,
29
31
  }));
30
32
  }
31
33
 
32
- async getModules() {
33
- const modules = await this.moduleRepo.find({ where: { module_level: 'MAINMOD' } });
34
- return modules.map(mod => ({
34
+ async getModules({ appcode }: { appcode: string }) {
35
+ const modules = await this.moduleRepo.find({
36
+ where: { module_level: 'MAINMOD', appcode: appcode },
37
+ });
38
+ return modules.map((mod) => ({
35
39
  label: mod.name,
36
40
  value: mod.id,
37
41
  }));
38
42
  }
39
43
 
40
- async getAccessListing(roleIds: number[]) {
41
- const roles = await this.roleRepo.find({ where: { id: In(roleIds) } });
42
- const roleCodes = roles.map(role => role.code);
44
+ async getAccessListing(roleIds: number[], appcode: string) {
45
+ const roles = await this.roleRepo.find({
46
+ where: { id: In(roleIds), appcode: appcode },
47
+ });
48
+ const roleCodes = roles.map((role) => role.code);
43
49
 
44
50
  const moduleAccesses = await this.moduleAccessRepo.find({
45
- where: { role_code: In(roleCodes) },
51
+ where: { role_code: In(roleCodes), appcode: appcode },
46
52
  });
47
53
 
48
- return roles.map(role => ({
54
+ return roles.map((role) => ({
49
55
  role_code: role.code,
50
56
  name: role.name,
51
57
  permission: moduleAccesses
52
- .filter(access => access.role_code === role.code)
53
- .map(access => ({
58
+ .filter((access) => access.role_code === role.code)
59
+ .map((access) => ({
54
60
  action: access.action_type,
55
61
  access: access.access_flag,
56
62
  code: access.module_code,
@@ -58,20 +64,31 @@ export class ModuleAccessRepository {
58
64
  }));
59
65
  }
60
66
 
61
- async getMenuListing(mainModIds: string[]) {
62
- const mainModules = mainModIds.length === 1 && mainModIds[0] === '-1'
63
- ? await this.moduleRepo.find({ where: { module_level: 'MAINMOD' } })
64
- : await this.moduleRepo.find({ where: { id: In(mainModIds), module_level: 'MAINMOD' } });
67
+ async getMenuListing(mainModIds: string[], appcode: string) {
68
+ const mainModules =
69
+ mainModIds.length === 1 && mainModIds[0] === '-1'
70
+ ? await this.moduleRepo.find({
71
+ where: { module_level: 'MAINMOD', appcode: appcode },
72
+ })
73
+ : await this.moduleRepo.find({
74
+ where: {
75
+ id: In(mainModIds),
76
+ module_level: 'MAINMOD',
77
+ appcode: appcode,
78
+ },
79
+ });
65
80
 
66
81
  if (!mainModules.length) return [];
67
82
 
68
- const wbsCodes = mainModules.map(mod => mod.wbs_code);
83
+ const wbsCodes = mainModules.map((mod) => mod.wbs_code);
69
84
 
70
85
  const modules = await this.moduleRepo
71
86
  .createQueryBuilder('module')
72
87
  .where(
73
- wbsCodes.map(code => `module.wbs_code LIKE :code${code}`).join(' OR '),
74
- Object.fromEntries(wbsCodes.map(code => [`code${code}`, `${code}%`])),
88
+ wbsCodes
89
+ .map((code) => `module.wbs_code LIKE :code${code}`)
90
+ .join(' OR '),
91
+ Object.fromEntries(wbsCodes.map((code) => [`code${code}`, `${code}%`])),
75
92
  )
76
93
  .getMany();
77
94
 
@@ -79,28 +96,29 @@ export class ModuleAccessRepository {
79
96
 
80
97
  const buildHierarchy = (parentWbs: string): any[] =>
81
98
  modules
82
- .filter(mod =>
83
- mod.wbs_code.startsWith(`${parentWbs}.`) &&
84
- mod.wbs_code.split('.').length === parentWbs.split('.').length + 1,
99
+ .filter(
100
+ (mod) =>
101
+ mod.wbs_code.startsWith(`${parentWbs}.`) &&
102
+ mod.wbs_code.split('.').length === parentWbs.split('.').length + 1,
85
103
  )
86
- .map(mod => ({
104
+ .map((mod) => ({
87
105
  name: mod.name,
88
106
  code: mod.module_code,
89
107
  permission: moduleActions
90
- .filter(action => action.module_code === mod.module_code)
91
- .map(action => ({
108
+ .filter((action) => action.module_code === mod.module_code)
109
+ .map((action) => ({
92
110
  action: action.action_type,
93
111
  name: action.action_type,
94
112
  })),
95
113
  submod: buildHierarchy(mod.wbs_code),
96
114
  }));
97
115
 
98
- return mainModules.map(mod => ({
116
+ return mainModules.map((mod) => ({
99
117
  name: mod.name,
100
118
  code: mod.module_code,
101
119
  permission: moduleActions
102
- .filter(action => action.module_code === mod.module_code)
103
- .map(action => ({
120
+ .filter((action) => action.module_code === mod.module_code)
121
+ .map((action) => ({
104
122
  action: action.action_type,
105
123
  name: action.action_type,
106
124
  })),
@@ -108,13 +126,16 @@ export class ModuleAccessRepository {
108
126
  }));
109
127
  }
110
128
 
111
- async updateModuleAccess(accessList: {
112
- role_code: string;
113
- module_code: string;
114
- action_type: string;
115
- access_flag: number;
116
- app_code: string;
117
- }[]): Promise<boolean> {
129
+ async updateModuleAccess(
130
+ accessList: {
131
+ role_code: string;
132
+ module_code: string;
133
+ action_type: string;
134
+ access_flag: number;
135
+ appcode: string;
136
+ }[],
137
+ appcode: string,
138
+ ): Promise<boolean> {
118
139
  try {
119
140
  for (const access of accessList) {
120
141
  const existing = await this.moduleAccessRepo.findOne({
@@ -122,7 +143,7 @@ export class ModuleAccessRepository {
122
143
  role_code: access.role_code,
123
144
  module_code: access.module_code,
124
145
  action_type: access.action_type,
125
- appcode: access.app_code,
146
+ appcode: access.appcode || appcode,
126
147
  },
127
148
  });
128
149
 
@@ -130,7 +151,9 @@ export class ModuleAccessRepository {
130
151
  existing.access_flag = access.access_flag;
131
152
  await this.moduleAccessRepo.save(existing);
132
153
  } else {
133
- await this.moduleAccessRepo.save(this.moduleAccessRepo.create(access));
154
+ await this.moduleAccessRepo.save(
155
+ this.moduleAccessRepo.create(access),
156
+ );
134
157
  }
135
158
  }
136
159
  return true;
@@ -140,24 +163,23 @@ export class ModuleAccessRepository {
140
163
  }
141
164
  }
142
165
 
143
-
144
166
  // src/module/module-access/repository/module-access.repository.ts
145
167
 
146
168
  async getModuleUIConfig(moduleCode: string, roleIds: number[]) {
147
169
  const module = await this.moduleRepo.findOne({
148
170
  where: { module_code: moduleCode },
149
171
  });
150
-
172
+
151
173
  if (!module) {
152
174
  throw new BadRequestException('Module not found');
153
175
  }
154
-
176
+
155
177
  const roles = await this.roleRepo.find({
156
178
  where: { id: In(roleIds) },
157
179
  });
158
-
159
- const roleCodes = roles.map(role => role.code);
160
-
180
+
181
+ const roleCodes = roles.map((role) => role.code);
182
+
161
183
  const actions = await this.moduleAccessRepo.find({
162
184
  where: {
163
185
  module_code: moduleCode,
@@ -165,9 +187,9 @@ export class ModuleAccessRepository {
165
187
  access_flag: 1,
166
188
  },
167
189
  });
168
-
169
- const uniqueActions = [...new Set(actions.map(a => a.action_type))];
170
-
190
+
191
+ const uniqueActions = [...new Set(actions.map((a) => a.action_type))];
192
+
171
193
  return {
172
194
  entity_type: module.entity_type,
173
195
  title: module.title,
@@ -175,7 +197,4 @@ export class ModuleAccessRepository {
175
197
  action: uniqueActions,
176
198
  };
177
199
  }
178
-
179
-
180
-
181
200
  }
@@ -13,31 +13,36 @@ export class ModuleAccessService {
13
13
  private readonly moduleAccessRepository: ModuleAccessRepository,
14
14
  ) {}
15
15
 
16
- async getRoles() {
17
- return this.moduleAccessRepository.getRoles();
16
+ async getRoles({ appcode }: { appcode: string }) {
17
+ return this.moduleAccessRepository.getRoles({ appcode });
18
18
  }
19
19
 
20
- async getModules() {
21
- return this.moduleAccessRepository.getModules();
20
+ async getModules({ appcode }: { appcode: string }) {
21
+ return this.moduleAccessRepository.getModules({
22
+ appcode,
23
+ });
22
24
  }
23
25
 
24
- async getAccessListing(roleIds: number[]) {
25
- return this.moduleAccessRepository.getAccessListing(roleIds);
26
+ async getAccessListing(roleIds: number[], appcode: string) {
27
+ return this.moduleAccessRepository.getAccessListing(roleIds, appcode);
26
28
  }
27
29
 
28
- async getMenuListing(mainModIds: string[]) {
29
- return this.moduleAccessRepository.getMenuListing(mainModIds);
30
+ async getMenuListing(mainModIds: string[], appcode: string) {
31
+ return this.moduleAccessRepository.getMenuListing(mainModIds, appcode);
30
32
  }
31
33
 
32
34
  async updateModuleAccess(
33
35
  moduleAccessData: any[],
36
+ appcode: string,
34
37
  ): Promise<{ success: boolean; msg: string }> {
35
38
  if (!moduleAccessData || moduleAccessData.length === 0) {
36
39
  return { success: false, msg: 'No data provided' };
37
40
  }
38
41
 
39
- const result =
40
- await this.moduleAccessRepository.updateModuleAccess(moduleAccessData);
42
+ const result = await this.moduleAccessRepository.updateModuleAccess(
43
+ moduleAccessData,
44
+ appcode,
45
+ );
41
46
 
42
47
  if (result) {
43
48
  return { success: true, msg: 'Module access updated successfully' };
@@ -51,7 +56,4 @@ export class ModuleAccessService {
51
56
  async getModuleUIConfig(moduleCode: string, roleIds: number[]) {
52
57
  return this.moduleAccessRepository.getModuleUIConfig(moduleCode, roleIds);
53
58
  }
54
-
55
-
56
-
57
59
  }
@@ -55,4 +55,5 @@ export class CreateUserDto extends BaseEntity {
55
55
  invitation_status: string;
56
56
  is_defaultadmin: number;
57
57
  is_customer: number;
58
+ appcode: string;
58
59
  }
@@ -24,9 +24,13 @@ export class RoleService extends EntityServiceImpl {
24
24
  async createEntity(
25
25
  entityData: BaseEntity,
26
26
  loggedInUser: UserData | null,
27
+ manager?: EntityManager,
28
+ appcode?: string,
27
29
  ): Promise<BaseEntity> {
28
30
  let role = entityData as Role;
29
-
31
+ if(appcode){
32
+ role.appcode = appcode ;
33
+ }
30
34
  if (await this.roleRepository.isRoleNameExists(role.name,{organization_id:entityData.organization_id})) {
31
35
  throw new BadRequestException('Role name already exists.');
32
36
  }
@@ -35,8 +35,12 @@ export class UserService extends EntityServiceImpl {
35
35
  entityData: BaseEntity,
36
36
  loggedInUser: UserData | null,
37
37
  manager?: EntityManager,
38
+ appcode?: string,
38
39
  ): Promise<BaseEntity> {
39
40
  let userData = entityData as CreateUserDto;
41
+ if(appcode){
42
+ userData.appcode = appcode;
43
+ }
40
44
  let existingUser = await this.userRepository.findByEmailId(
41
45
  userData.email_id,
42
46
  loggedInUser?.organization_id,