rez_core 2.0.89 → 2.0.90

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": "rez_core",
3
- "version": "2.0.89",
3
+ "version": "2.0.90",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -49,6 +49,7 @@ export class FilterController {
49
49
  sortby,
50
50
  page,
51
51
  size,
52
+ user_id: userData.id,
52
53
  level_type: userData.level_type,
53
54
  level_id: userData.level_id,
54
55
  });
@@ -23,6 +23,7 @@ export interface FilterRequestDto {
23
23
  tabs?: TabsConfig;
24
24
  page?: number;
25
25
  size?: number;
26
+ user_id?: string | null;
26
27
  level_type?: string | null;
27
28
  level_id?: string | null;
28
29
  }
@@ -19,7 +19,7 @@ export class FilterService {
19
19
  @Inject('SavedFilterService')
20
20
  private readonly savedFilterService: SavedFilterService,
21
21
  ) {}
22
- private readonly skipLevelFilterEntities = ['USR','UPR'];
22
+ private readonly skipLevelFilterEntities = ['USR', 'UPR'];
23
23
 
24
24
  private async gettab_value_counts(
25
25
  tableName: string,
@@ -77,6 +77,7 @@ export class FilterService {
77
77
  attributeFilter,
78
78
  tabs,
79
79
  sortby,
80
+ user_id,
80
81
  level_type,
81
82
  level_id,
82
83
  } = dto;
@@ -142,13 +143,55 @@ export class FilterService {
142
143
  });
143
144
  }
144
145
 
145
- // Build query for tab counts (no tab.value filter here)
146
+ const layoutPreference = await this.dataSource.query(
147
+ `SELECT layout_json
148
+ FROM cr_layout_preference
149
+ WHERE user_id = ? AND mapped_entity_type = ?`,
150
+ [user_id, entity_type],
151
+ );
152
+
146
153
  const allTabs = await this.gettab_value_counts(
147
154
  getTableMeta.data_source,
148
155
  tabs?.columnName,
149
156
  baseWhere,
150
157
  );
151
158
 
159
+ // Extract layout preference
160
+ const layout = layoutPreference?.[0]?.layout_json?.quick_tab || {};
161
+ let showList = layout?.show_list?.map((val) => val.toLowerCase()) || [];
162
+
163
+ // If 'All' is selected, include 'all'
164
+ if (layout?.isAllSelected) {
165
+ if (!showList.includes('all')) {
166
+ showList.push('all');
167
+ }
168
+ }
169
+
170
+ // Filter `allTabs` using showList (case-insensitive)
171
+ const filteredTabs = allTabs.filter((tab) =>
172
+ showList.includes(tab.tab_value.toLowerCase()),
173
+ );
174
+
175
+ // If combine other is enabled
176
+ if (layout?.isCombineOther) {
177
+ const allTab = allTabs.find(
178
+ (tab) => tab.tab_value.toLowerCase() === 'all',
179
+ );
180
+ const allCount = allTab?.tab_value_count ?? 0;
181
+
182
+ // Calculate sum of filtered (excluding 'All')
183
+ const knownTabCountSum = filteredTabs
184
+ .filter((tab) => tab.tab_value.toLowerCase() !== 'all')
185
+ .reduce((acc, tab) => acc + tab.tab_value_count, 0);
186
+
187
+ const othersCount = allCount - knownTabCountSum;
188
+
189
+ filteredTabs.push({
190
+ tab_value: 'OTHERS',
191
+ tab_value_count: othersCount < 0 ? 0 : othersCount, // safe fallback
192
+ });
193
+ }
194
+
152
195
  // Add tab.value filter only if present
153
196
  const dataWhere = [...baseWhere];
154
197
  if (tabs?.columnName && tabs?.value) {
@@ -177,8 +220,17 @@ export class FilterService {
177
220
  qb.andWhere(clause.query, clause.params);
178
221
  });
179
222
 
180
- // Optional sorting
223
+ //prefernec.sort_by.length>0 if()
224
+
225
+ // "sortby": [
226
+ // {
227
+ // "order": "asc",
228
+ // "column": "customer_name"
229
+ // }
230
+ // ],
231
+
181
232
  if (Array.isArray(sortby)) {
233
+ // Optional sorting
182
234
  sortby.forEach(({ sortColum, sortType }) => {
183
235
  qb.addOrderBy(
184
236
  `e.${sortColum}`,
@@ -187,6 +239,20 @@ export class FilterService {
187
239
  });
188
240
  }
189
241
 
242
+ if (layoutPreference[0]?.layout_json.sorting.sortby.length > 0) {
243
+ if (Array.isArray(layoutPreference[0]?.layout_json.sorting.sortby)) {
244
+ // Optional sorting
245
+ layoutPreference[0]?.layout_json.sorting.sortby.forEach(
246
+ ({ column, order }) => {
247
+ qb.addOrderBy(
248
+ `e.${column}`,
249
+ order?.toUpperCase() === 'DSC' ? 'DESC' : 'ASC',
250
+ );
251
+ },
252
+ );
253
+ }
254
+ }
255
+
190
256
  // Pagination
191
257
  const page = dto.page && dto.page > 0 ? dto.page : 1;
192
258
  const size = dto.size && dto.size > 0 ? dto.size : 10;
@@ -209,7 +275,7 @@ export class FilterService {
209
275
  return {
210
276
  success: true,
211
277
  data: {
212
- entity_tabs: allTabs,
278
+ entity_tabs: filteredTabs,
213
279
  entity_list,
214
280
  pagination: {
215
281
  total,
@@ -295,7 +361,7 @@ export class FilterService {
295
361
  case 'contains':
296
362
  return {
297
363
  query: `LOWER(e.${attr}) LIKE :${key}`,
298
- params: { [key]: `%${val?val.toLowerCase():""}%` },
364
+ params: { [key]: `%${val ? val.toLowerCase() : ''}%` },
299
365
  };
300
366
  case 'equal':
301
367
  return {
@@ -369,7 +435,7 @@ export class FilterService {
369
435
  throw new BadRequestException(`Unsupported operator for date: ${op}`);
370
436
  }
371
437
  }
372
-
438
+
373
439
  private buildSelectCondition(
374
440
  attr: string,
375
441
  op: string,
@@ -22,6 +22,8 @@ export class LayoutPreferenceService extends EntityServiceImpl {
22
22
  throw new Error('User ID is required to create layout preference.');
23
23
  }
24
24
 
25
+ console.log('userId', userId);
26
+
25
27
  const existingLayoutPreference =
26
28
  await this.layoutPreferenceRepository.findByEntityUserId(
27
29
  mapped_entity_type,
@@ -21,17 +21,21 @@ export class MenuService {
21
21
  ): Promise<{ menu: any[] }> {
22
22
  // Step 1: Resolve roles (with fallback logic inside)
23
23
  const roleCodes = await this.menuRepository.resolveUserRoles(userId, appcode, levelType, levelId);
24
+ console.log(roleCodes)
24
25
  if (!roleCodes.length) return { menu: [] };
25
26
 
26
27
  // Step 2: Get accessible modules
27
28
  const moduleCodes = await this.menuRepository.getAccessibleModules(roleCodes, appcode);
29
+ console.log(moduleCodes)
28
30
  if (!moduleCodes.length) return { menu: [] };
29
31
 
30
32
  // Step 3: Get menu items for the given level type
31
33
  const menuItems = await this.menuRepository.getMenuItems(moduleCodes, appcode, levelType);
34
+ console.log(menuItems)
32
35
 
33
36
  // Step 4: Build hierarchy
34
37
  const menuTree = this.buildMenuHierarchy(menuItems);
38
+
35
39
  return { menu: menuTree };
36
40
  }
37
41