rez_core 2.1.24 → 2.1.26

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 (26) hide show
  1. package/dist/module/filter/service/filter.service.js +31 -8
  2. package/dist/module/filter/service/filter.service.js.map +1 -1
  3. package/dist/module/layout_preference/service/layout_preference.service.js +1 -0
  4. package/dist/module/layout_preference/service/layout_preference.service.js.map +1 -1
  5. package/dist/module/module/service/module-access.service.js +9 -1
  6. package/dist/module/module/service/module-access.service.js.map +1 -1
  7. package/dist/module/user/entity/user.entity.d.ts +2 -0
  8. package/dist/module/user/entity/user.entity.js +8 -0
  9. package/dist/module/user/entity/user.entity.js.map +1 -1
  10. package/dist/module/user/service/login.service.d.ts +2 -2
  11. package/dist/module/user/service/login.service.js +22 -10
  12. package/dist/module/user/service/login.service.js.map +1 -1
  13. package/dist/module/user/service/user-session.service.js +1 -1
  14. package/dist/module/user/service/user-session.service.js.map +1 -1
  15. package/dist/module/user/service/user.service.d.ts +1 -0
  16. package/dist/module/user/service/user.service.js +9 -0
  17. package/dist/module/user/service/user.service.js.map +1 -1
  18. package/dist/tsconfig.build.tsbuildinfo +1 -1
  19. package/package.json +1 -1
  20. package/src/module/filter/service/filter.service.ts +48 -17
  21. package/src/module/layout_preference/service/layout_preference.service.ts +2 -0
  22. package/src/module/module/service/module-access.service.ts +28 -1
  23. package/src/module/user/entity/user.entity.ts +6 -0
  24. package/src/module/user/service/login.service.ts +33 -17
  25. package/src/module/user/service/user-session.service.ts +2 -2
  26. package/src/module/user/service/user.service.ts +17 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.24",
3
+ "version": "2.1.26",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -153,16 +153,25 @@ export class FilterService {
153
153
  [user_id, entity_type],
154
154
  );
155
155
 
156
- const allTabs = await this.gettab_value_counts(
157
- getTableMeta.data_source,
158
- tabs?.columnName,
159
- baseWhere,
160
- );
161
-
162
156
  // Extract layout preference
163
157
  const layout = layoutPreference?.[0]?.layout_json?.quick_tab || {};
164
158
  let showList = layout?.show_list?.map((val) => val.toLowerCase()) || [];
165
159
 
160
+ let allTabs;
161
+ if (layout.attribute) {
162
+ allTabs = await this.gettab_value_counts(
163
+ getTableMeta.data_source,
164
+ layout.attribute,
165
+ baseWhere,
166
+ );
167
+ } else {
168
+ allTabs = await this.gettab_value_counts(
169
+ getTableMeta.data_source,
170
+ tabs?.columnName,
171
+ baseWhere,
172
+ );
173
+ }
174
+
166
175
  let filteredTabs;
167
176
 
168
177
  if (showList?.length > 0) {
@@ -201,20 +210,42 @@ export class FilterService {
201
210
  filteredTabs = allTabs;
202
211
  }
203
212
 
204
- // Add tab.value filter only if present
205
213
  const dataWhere = [...baseWhere];
214
+
206
215
  if (tabs?.columnName && tabs?.value) {
207
216
  const tabAttrMeta = attributeMetaMap[tabs.columnName];
208
- const tabCondition = this.buildCondition(
209
- {
210
- filter_attribute: tabs.columnName,
211
- filter_operator: 'equal',
212
- filter_value: tabs.value,
213
- },
214
- tabAttrMeta,
215
- );
216
- if (tabCondition) {
217
- if (tabs.value.toLowerCase() !== 'all') dataWhere.push(tabCondition);
217
+ const tabValue = tabs.value.toLowerCase();
218
+
219
+ if (tabValue === 'others') {
220
+ const valuesToExclude = showList.filter((v) => v !== 'all');
221
+ if (valuesToExclude.length > 0) {
222
+ valuesToExclude.forEach((value) => {
223
+ const tabCondition = this.buildCondition(
224
+ {
225
+ filter_attribute: tabs.columnName,
226
+ filter_operator: 'not_equal',
227
+ filter_value: value,
228
+ },
229
+ tabAttrMeta,
230
+ );
231
+ if (tabCondition) {
232
+ dataWhere.push(tabCondition);
233
+ }
234
+ });
235
+ }
236
+ } else if (tabValue !== 'all') {
237
+ // Normal case: filter by equality
238
+ const tabCondition = this.buildCondition(
239
+ {
240
+ filter_attribute: tabs.columnName,
241
+ filter_operator: 'equal',
242
+ filter_value: tabs.value,
243
+ },
244
+ tabAttrMeta,
245
+ );
246
+ if (tabCondition) {
247
+ dataWhere.push(tabCondition);
248
+ }
218
249
  }
219
250
  }
220
251
 
@@ -15,6 +15,8 @@ export class LayoutPreferenceService extends EntityServiceImpl {
15
15
  }
16
16
 
17
17
  async createEntity(entityData: BaseEntity, loggedInUser: UserData | null) {
18
+ console.log('lap api called', entityData);
19
+
18
20
  const { mapped_entity_type } = entityData as any;
19
21
  const userId = loggedInUser?.id;
20
22
 
@@ -129,6 +129,7 @@ export class ModuleAccessService {
129
129
  level_type: string;
130
130
  level_id: number;
131
131
  }) {
132
+ // Step 1: Resolve roles
132
133
  const roleCodes = await this.menuRepository.resolveUserRoles(
133
134
  userId,
134
135
  appcode,
@@ -141,8 +142,34 @@ export class ModuleAccessService {
141
142
  }
142
143
 
143
144
  const roleIds = roleCodes.map(Number);
144
- return this.moduleAccessRepository.getModuleAccessByRoles(roleIds, appcode);
145
+
146
+ // Step 2: Get full permissions
147
+ const allPermissions = await this.moduleAccessRepository.getModuleAccessByRoles(
148
+ roleIds,
149
+ appcode,
150
+ );
151
+
152
+ // Step 3: If level_type is SCH, check school status using raw query
153
+ if (level_type === 'SCH') {
154
+ const result = await this.dataSource.query(
155
+ `SELECT * FROM cr_school WHERE id = ${level_id}`,
156
+ [level_id],
157
+ );
158
+
159
+ const school = result?.[0];
160
+
161
+ if (!school || school.status === "INACTIVE") {
162
+ // Return only VIEW permissions
163
+ return allPermissions.filter(
164
+ (perm) => perm.action === 'VIEW'
165
+ );
166
+ }
167
+ }
168
+
169
+ // Step 4: Return all permissions normally
170
+ return allPermissions;
145
171
  }
146
172
 
147
173
 
174
+
148
175
  }
@@ -44,4 +44,10 @@ export class UserData extends BaseEntity {
44
44
 
45
45
  @Column({ type: 'varchar', nullable: true })
46
46
  last_app_access: string;
47
+
48
+ @Column({ type: 'varchar', nullable: true })
49
+ last_level_type: string;
50
+
51
+ @Column({ type: 'varchar', nullable: true })
52
+ last_level_id: string;
47
53
  }
@@ -59,25 +59,41 @@ export class LoginService {
59
59
  };
60
60
  }
61
61
 
62
- // ✅ Get user-role mappings for this app
63
- const roleMappings = await this.userRoleMappingRepository.find({
64
- where: {
65
- user_id: user.id,
66
- appcode: user.last_app_access,
67
- },
68
- });
62
+ let defaultAccess;
69
63
 
70
- if (!roleMappings.length) {
71
- throw new BadRequestException(
72
- 'User does not have any access mapped for this app.',
73
- );
74
- }
64
+ if (!user.last_level_type && !user.last_level_id) {
65
+ const roleMappings = await this.userRoleMappingRepository.find({
66
+ where: {
67
+ user_id: user.id,
68
+ appcode: user.last_app_access,
69
+ },
70
+ });
71
+
72
+ if (!roleMappings.length) {
73
+ throw new BadRequestException(
74
+ 'User does not have any access mapped for this app.',
75
+ );
76
+ }
75
77
 
76
- // ✅ Pick default access based on priority
77
- const priority = { org: 1, sch: 2, brn: 3 };
78
- const defaultAccess = roleMappings.sort(
79
- (a, b) => priority[a.level_type] - priority[b.level_type],
80
- )[0];
78
+ // ✅ Pick default access based on priority
79
+ const priority = { org: 1, sch: 2, brn: 3 };
80
+ defaultAccess = roleMappings.sort(
81
+ (a, b) => priority[a.level_type] - priority[b.level_type],
82
+ )[0];
83
+
84
+ if ((defaultAccess.level_type, defaultAccess.level_id)) {
85
+ await this.userService.setLastLevelTypeAndId(
86
+ user.id,
87
+ defaultAccess.level_type,
88
+ defaultAccess.level_id,
89
+ );
90
+ }
91
+ } else {
92
+ defaultAccess = {
93
+ level_type: user.last_level_type,
94
+ level_id: user.last_level_id,
95
+ };
96
+ }
81
97
 
82
98
  //appcode
83
99
 
@@ -85,8 +85,8 @@ export class UserSessionService {
85
85
  };
86
86
 
87
87
  await this.dataSource.query(
88
- `UPDATE cr_user SET last_app_access = ? WHERE id = ?`,
89
- [data.appcode, currentUser.id],
88
+ `UPDATE cr_user SET last_app_access = ? , last_level_type = ?, last_level_id = ? WHERE id = ?`,
89
+ [data.appcode, data.level_type, data.level_id, currentUser.id],
90
90
  );
91
91
 
92
92
  return {
@@ -249,4 +249,21 @@ export class UserService extends EntityServiceImpl {
249
249
 
250
250
  await this.userRepository.saveUser(user); // This persists the updated field
251
251
  }
252
+
253
+ async setLastLevelTypeAndId(
254
+ userId: number,
255
+ levelType: string,
256
+ levelId: string,
257
+ ): Promise<void> {
258
+ const user = await this.userRepository.findById(userId);
259
+
260
+ if (!user) {
261
+ throw new BadRequestException('User not found');
262
+ }
263
+
264
+ user.last_level_type = levelType;
265
+ user.last_level_id = levelId;
266
+
267
+ await this.userRepository.saveUser(user); // This persists the updated field
268
+ }
252
269
  }