rez_core 2.1.17 → 2.1.19

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 (28) hide show
  1. package/dist/module/enterprise/controller/organization.controller.d.ts +1 -3
  2. package/dist/module/enterprise/controller/organization.controller.js +3 -6
  3. package/dist/module/enterprise/controller/organization.controller.js.map +1 -1
  4. package/dist/module/enterprise/enterprise.module.js +5 -0
  5. package/dist/module/enterprise/enterprise.module.js.map +1 -1
  6. package/dist/module/enterprise/repository/school.repository.d.ts +1 -1
  7. package/dist/module/enterprise/repository/school.repository.js +75 -109
  8. package/dist/module/enterprise/repository/school.repository.js.map +1 -1
  9. package/dist/module/enterprise/service/brand.service.d.ts +2 -0
  10. package/dist/module/enterprise/service/brand.service.js +17 -0
  11. package/dist/module/enterprise/service/brand.service.js.map +1 -0
  12. package/dist/module/enterprise/service/organization.service.d.ts +1 -1
  13. package/dist/module/enterprise/service/organization.service.js +2 -2
  14. package/dist/module/enterprise/service/organization.service.js.map +1 -1
  15. package/dist/module/listmaster/service/list-master.service.d.ts +1 -0
  16. package/dist/module/listmaster/service/list-master.service.js +12 -7
  17. package/dist/module/listmaster/service/list-master.service.js.map +1 -1
  18. package/dist/module/meta/controller/entity.controller.js +1 -1
  19. package/dist/module/meta/controller/entity.controller.js.map +1 -1
  20. package/dist/tsconfig.build.tsbuildinfo +1 -1
  21. package/package.json +1 -1
  22. package/src/module/enterprise/controller/organization.controller.ts +2 -5
  23. package/src/module/enterprise/enterprise.module.ts +5 -0
  24. package/src/module/enterprise/repository/school.repository.ts +94 -136
  25. package/src/module/enterprise/service/brand.service.ts +4 -0
  26. package/src/module/enterprise/service/organization.service.ts +2 -2
  27. package/src/module/listmaster/service/list-master.service.ts +17 -10
  28. package/src/module/meta/controller/entity.controller.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.17",
3
+ "version": "2.1.19",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -23,10 +23,7 @@ export class OrganizationController {
23
23
 
24
24
  @UseGuards(JwtAuthGuard)
25
25
  @Get('hierarchy')
26
- async getOrganizationHierarchy(@Req() req: Request & { user: any }) {
27
- const userId = req.user.userData?.id;
28
- const appcode = req.user.userData?.appcode;
29
-
30
- return await this.orgService.getOrganizationHierarchy(userId, appcode);
26
+ async getOrganizationHierarchy(): Promise<any[]> {
27
+ return await this.orgService.getOrganizationHierarchy();
31
28
  }
32
29
  }
@@ -11,6 +11,7 @@ import { SchoolData } from './entity/school.entity';
11
11
  import { BrandRepository } from './repository/brand.repository';
12
12
  import { SchoolRepository } from './repository/school.repository';
13
13
  import { UtilsModule } from 'src/utils/utils.module';
14
+ import { BrandService } from './service/brand.service';
14
15
 
15
16
  @Module({
16
17
  imports: [
@@ -29,6 +30,10 @@ import { UtilsModule } from 'src/utils/utils.module';
29
30
  OrganizationAppMappingService,
30
31
  BrandRepository,
31
32
  SchoolRepository,
33
+ {
34
+ provide: 'BrandService',
35
+ useClass: BrandService,
36
+ },
32
37
  ],
33
38
  exports: [OrganizationService],
34
39
  })
@@ -24,153 +24,111 @@ export class SchoolRepository {
24
24
  });
25
25
  }
26
26
 
27
- async getUserContextDropdown(userId: number, appCode: string) {
28
- const userRoleRepo = this.dataSource.getRepository(UserRoleMapping);
29
-
30
- // Check if user has any org level access for the app
31
- const hasOrgAccess = await userRoleRepo
32
- .createQueryBuilder('urm')
33
- .where('urm.user_id = :userId', { userId })
34
- .andWhere('urm.appcode = :appCode', { appCode })
35
- .andWhere('urm.level_type = :levelType', { levelType: 'ORG' })
27
+ async getUserContextDropdown(): Promise<any[]> {
28
+ const data = await this.dataSource
29
+ .createQueryBuilder()
30
+ .select([
31
+ 'org.id AS org_id',
32
+ 'org.name AS org_name',
33
+ 'org.address AS org_address',
34
+
35
+ // Full brand columns
36
+ 'br.id AS brand_id',
37
+ 'br.entity_type AS brand_entity_type',
38
+ 'br.name AS brand_name',
39
+ 'br.status AS brand_status',
40
+ 'br.parent_type AS brand_parent_type',
41
+ 'br.parent_id AS brand_parent_id',
42
+ 'br.code AS brand_code',
43
+ 'br.created_by AS brand_created_by',
44
+ 'br.created_date AS brand_created_date',
45
+ 'br.modified_by AS brand_modified_by',
46
+ 'br.modified_date AS brand_modified_date',
47
+ 'br.enterprise_id AS brand_enterprise_id',
48
+ 'br.organization_id AS brand_organization_id',
49
+ 'br.appcode AS brand_appcode',
50
+ 'br.level_id AS brand_level_id',
51
+ 'br.level_type AS brand_level_type',
52
+ 'br.type AS brand_type',
53
+
54
+ // Full school columns
55
+ 'sch.id AS school_id',
56
+ 'sch.entity_type AS school_entity_type',
57
+ 'sch.name AS school_name',
58
+ 'sch.status AS school_status',
59
+ 'sch.parent_type AS school_parent_type',
60
+ 'sch.parent_id AS school_parent_id',
61
+ 'sch.code AS school_code',
62
+ 'sch.created_by AS school_created_by',
63
+ 'sch.created_date AS school_created_date',
64
+ 'sch.modified_by AS school_modified_by',
65
+ 'sch.modified_date AS school_modified_date',
66
+ 'sch.enterprise_id AS school_enterprise_id',
67
+ 'sch.organization_id AS school_organization_id',
68
+ 'sch.appcode AS school_appcode',
69
+ 'sch.level_id AS school_level_id',
70
+ 'sch.level_type AS school_level_type',
71
+ 'sch.type AS school_type',
72
+ ])
73
+ .from('cr_school', 'sch')
74
+ .innerJoin('cr_brand', 'br', 'sch.brand_id = br.id')
75
+ .innerJoin('cr_organization', 'org', 'br.organization_id = org.id')
76
+ .orderBy('org.id, br.id, sch.id')
36
77
  .getRawMany();
37
78
 
38
- if (hasOrgAccess.length > 0) {
39
- // Return nested Org -> Brand -> School structure
40
- const schools = await this.dataSource
41
- .createQueryBuilder()
42
- .select([
43
- 'org.id AS org_id',
44
- 'org.name AS org_name',
45
- 'org.address AS org_address',
46
- 'br.id AS brand_id',
47
- 'br.name AS brand_name',
48
- 'sch.id AS school_id',
49
- 'sch.name AS school_name',
50
- 'sch.location AS school_location',
51
- ])
52
- .from('cr_school', 'sch')
53
- .innerJoin('cr_brand', 'br', 'sch.brand_id = br.id')
54
- .innerJoin('cr_organization', 'org', 'br.organization_id = org.id')
55
- .where('org.id = :orgId', { orgId: hasOrgAccess[0].urm_level_id })
56
- .getRawMany();
57
- const result = {};
58
-
59
- for (const row of schools) {
60
- const {
79
+ const result = {};
80
+
81
+ for (const row of data) {
82
+ const {
83
+ org_id,
84
+ org_name,
85
+ org_address,
86
+
87
+ brand_id,
88
+ ...brandFields
89
+
90
+ // include only brand fields prefixed with brand_
91
+ } = row;
92
+
93
+ const {
94
+ school_id,
95
+ ...schoolFields
96
+
97
+ // include only school fields prefixed with school_
98
+ } = row;
99
+
100
+ if (!result[org_id]) {
101
+ result[org_id] = {
61
102
  org_id,
62
103
  org_name,
63
104
  org_address,
64
- brand_id,
65
- brand_name,
66
- school_id,
67
- school_name,
68
- school_location,
69
- } = row;
70
-
71
- if (!result[org_id]) {
72
- result[org_id] = {
73
- org_id,
74
- org_name,
75
- org_address,
76
- type: 'Organization',
77
- brands: {},
78
- };
79
- }
80
- if (!result[org_id].brands[brand_id]) {
81
- result[org_id].brands[brand_id] = {
82
- brand_id,
83
- brand_name,
84
- type: 'Brand',
85
- schools: [],
86
- };
87
- }
88
- result[org_id].brands[brand_id].schools.push({
89
- school_id,
90
- school_name,
91
- school_location,
92
- type: 'School',
93
- });
105
+ brands: {},
106
+ };
94
107
  }
95
108
 
96
- return Object.values(result).map((org: { [key: string]: any }) => ({
97
- ...org,
98
- brands: Object.values(org.brands),
99
- }));
100
- } else {
101
- // 1. Get schools via BRN-level access
102
- const brnMappings = await this.dataSource
103
- .createQueryBuilder()
104
- .select([
105
- 'brand.id AS brand_id',
106
- 'brand.name AS brand_name',
107
- 'school.id AS school_id',
108
- 'school.name AS school_name',
109
- 'school.location AS school_location',
110
- ])
111
- .from('cr_user_role_mapping', 'urm')
112
- .innerJoin('cr_brand', 'brand', 'brand.id = urm.level_id')
113
- .innerJoin('cr_school', 'school', 'school.brand_id = brand.id')
114
- .where('urm.user_id = :userId', { userId })
115
- .andWhere('urm.appcode = :appCode', { appCode })
116
- .andWhere('urm.level_type = :levelType', { levelType: 'BRN' })
117
- .getRawMany();
118
-
119
- // 2. Get directly mapped schools via SCH-level access
120
- const schMappings = await this.dataSource
121
- .createQueryBuilder()
122
- .select([
123
- 'brand.id AS brand_id',
124
- 'brand.name AS brand_name',
125
- 'school.id AS school_id',
126
- 'school.name AS school_name',
127
- ])
128
- .from('cr_user_role_mapping', 'urm')
129
- .innerJoin('cr_school', 'school', 'school.id = urm.level_id')
130
- .innerJoin('cr_brand', 'brand', 'brand.id = school.brand_id')
131
- .where('urm.user_id = :userId', { userId })
132
- .andWhere('urm.appcode = :appCode', { appCode })
133
- .andWhere('urm.level_type = :levelType', { levelType: 'SCH' })
134
- .getRawMany();
135
-
136
- // 3. Combine both mappings
137
- const allMappings = [...brnMappings, ...schMappings];
138
-
139
- // 4. Group by brand
140
- const result = {};
141
- for (const row of allMappings) {
142
- const {
143
- brand_id,
144
- brand_name,
145
- school_id,
146
- school_name,
147
- school_location,
148
- } = row;
149
-
150
- if (!result[brand_id]) {
151
- result[brand_id] = {
152
- brand_id,
153
- brand_name,
154
- type: 'Brand',
155
- schools: [],
156
- };
109
+ if (!result[org_id].brands[brand_id]) {
110
+ const brandInfo: any = {};
111
+ for (const key in row) {
112
+ if (key.startsWith('brand_')) {
113
+ brandInfo[key.replace('brand_', '')] = row[key];
114
+ }
157
115
  }
116
+ brandInfo.schools = [];
117
+ result[org_id].brands[brand_id] = brandInfo;
118
+ }
158
119
 
159
- // prevent duplicates if needed
160
- if (
161
- school_id &&
162
- !result[brand_id].schools.some((s) => s.school_id === school_id)
163
- ) {
164
- result[brand_id].schools.push({
165
- school_id,
166
- school_name,
167
- school_location,
168
- type: 'School',
169
- });
120
+ const schoolInfo: any = {};
121
+ for (const key in row) {
122
+ if (key.startsWith('school_')) {
123
+ schoolInfo[key.replace('school_', '')] = row[key];
170
124
  }
171
125
  }
172
-
173
- return Object.values(result);
126
+ result[org_id].brands[brand_id].schools.push(schoolInfo);
174
127
  }
128
+
129
+ return Object.values(result).map((org: any) => ({
130
+ ...org,
131
+ brands: Object.values(org.brands),
132
+ }));
175
133
  }
176
134
  }
@@ -0,0 +1,4 @@
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ @Injectable()
4
+ export class BrandService {}
@@ -78,7 +78,7 @@ export class OrganizationService {
78
78
  await repo.delete(id);
79
79
  }
80
80
 
81
- async getOrganizationHierarchy(userId: number, appCode: string) {
82
- return await this.schoolRepository.getUserContextDropdown(userId, appCode);
81
+ async getOrganizationHierarchy(): Promise<any[]> {
82
+ return await this.schoolRepository.getUserContextDropdown();
83
83
  }
84
84
  }
@@ -25,6 +25,8 @@ export class ListMasterService {
25
25
  private readonly httpService: HttpService,
26
26
  ) {}
27
27
 
28
+ private readonly skipLevelFilterEntities = ['BRN'];
29
+
28
30
  async getDropdownOptions(
29
31
  type: string,
30
32
  params: Record<string, string>,
@@ -77,19 +79,24 @@ export class ListMasterService {
77
79
  }
78
80
 
79
81
  if (loggedInUser?.level_type && loggedInUser?.level_id) {
80
- qb.andWhere(
81
- `${tableName}.level_type = :levelType AND ${tableName}.level_id = :levelId`,
82
- {
83
- levelType: loggedInUser.level_type,
84
- levelId: loggedInUser.level_id,
85
- },
86
- );
82
+ // Skip level filter for certain entities
83
+ if (!this.skipLevelFilterEntities.includes(sourceList)) {
84
+ qb.andWhere(
85
+ `${tableName}.level_type = :levelType AND ${tableName}.level_id = :levelId`,
86
+ {
87
+ levelType: loggedInUser.level_type,
88
+ levelId: loggedInUser.level_id,
89
+ },
90
+ );
91
+ }
87
92
  }
88
93
 
89
94
  if (loggedInUser?.appcode && sourceList === 'ROL') {
90
- qb.andWhere(`${tableName}.appcode = :appcode`, {
91
- appcode: loggedInUser.appcode,
92
- });
95
+ if (!this.skipLevelFilterEntities.includes(sourceList)) {
96
+ qb.andWhere(`${tableName}.appcode = :appcode`, {
97
+ appcode: loggedInUser.appcode,
98
+ });
99
+ }
93
100
  }
94
101
 
95
102
  for (const key in params) {
@@ -165,7 +165,7 @@ export class EntityController {
165
165
  loggedInUser as UserData,
166
166
  );
167
167
 
168
- if (!updatedEntity || !updatedEntity.success) {
168
+ if (!updatedEntity) {
169
169
  return response.status(HttpStatus.BAD_REQUEST).json({
170
170
  success: false,
171
171
  error: updatedEntity?.error || 'Entity creation failed',