rez_core 2.1.37 → 2.1.39

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.1.37",
3
+ "version": "2.1.39",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -7,6 +7,8 @@ import { DataSource } from 'typeorm';
7
7
  import { FilterRequestDto } from '../dto/filter-request.dto';
8
8
  import { SavedFilterService } from './saved-filter.service';
9
9
 
10
+ import * as moment from 'moment';
11
+
10
12
  @Injectable()
11
13
  export class FilterService {
12
14
  constructor(
@@ -310,6 +312,41 @@ export class FilterService {
310
312
  // Get paginated data
311
313
  const entity_list = await qb.getRawMany();
312
314
 
315
+ // const formatDatesInRow = (row: any) => {
316
+ // const formattedRow = { ...row };
317
+ // for (const key of Object.keys(row)) {
318
+ // if (key.endsWith('_date') && row[key]) {
319
+ // formattedRow[key] = moment(row[key]).format('MMM DD, YYYY');
320
+ // }
321
+ // }
322
+ // return formattedRow;
323
+ // };
324
+
325
+ // 1. Extract all date-type attribute keys
326
+ const dateAttributes = Object.entries(attributeMetaMap)
327
+ .filter(([_, attr]) => attr.data_type === 'date')
328
+ .map(([key]) => key); // only the keys (e.g., 'created_date', 'modified_date')
329
+
330
+ // 2. Format function using moment
331
+ const formatDate = (dateStr: string | null): string | null => {
332
+ if (!dateStr) return null;
333
+ return moment(dateStr).format('MMM DD, YYYY'); // e.g., "Jun 25, 2025"
334
+ };
335
+
336
+ // 3. Function to format only those keys in each entity row
337
+ const formatDatesInRow = (row: any): any => {
338
+ const formattedRow = { ...row };
339
+ for (const key of dateAttributes) {
340
+ if (formattedRow[key]) {
341
+ formattedRow[key] = formatDate(formattedRow[key]);
342
+ }
343
+ }
344
+ return formattedRow;
345
+ };
346
+
347
+ // 4. Final transformation
348
+ const formattedEntityList = entity_list.map(formatDatesInRow);
349
+
313
350
  // Count query (without pagination)
314
351
  const countQb = this.dataSource
315
352
  .createQueryBuilder()
@@ -325,7 +362,7 @@ export class FilterService {
325
362
  success: true,
326
363
  data: {
327
364
  entity_tabs: filteredTabs,
328
- entity_list,
365
+ formattedEntityList,
329
366
  pagination: {
330
367
  total,
331
368
  page,
@@ -117,11 +117,35 @@ export class UserSessionService {
117
117
  }
118
118
 
119
119
  async getUserRoleMappingForApp(userId: number, appcode: string) {
120
- return await this.dataSource
120
+ const mapping = await this.dataSource
121
121
  .getRepository(UserRoleMapping)
122
122
  .createQueryBuilder('cr_user_role_mapping')
123
123
  .where('cr_user_role_mapping.user_id = :userId', { userId })
124
124
  .andWhere('cr_user_role_mapping.appcode = :appcode', { appcode })
125
- .getOne(); // You can return .getMany() if you want to let user choose
125
+ .getOne();
126
+
127
+ // If not found or is already ORG/SCH, return directly
128
+ if (!mapping || mapping.level_type !== 'BRN') {
129
+ return mapping;
130
+ }
131
+
132
+ //DONE
133
+ // If BRN, resolve first SCH under this brand
134
+ const schools = await this.dataSource.query(
135
+ `SELECT id FROM cr_school WHERE brand_id = ? ORDER BY id ASC LIMIT 1`,
136
+ [mapping.level_id],
137
+ );
138
+
139
+ if (schools.length) {
140
+ return {
141
+ ...mapping,
142
+ level_type: 'SCH',
143
+ level_id: schools[0].id,
144
+ };
145
+ }
146
+
147
+ // No SCH found under BRN
148
+ return null;
126
149
  }
150
+
127
151
  }