rez_core 2.1.17 → 2.1.18
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/dist/module/enterprise/controller/organization.controller.d.ts +1 -3
- package/dist/module/enterprise/controller/organization.controller.js +3 -6
- package/dist/module/enterprise/controller/organization.controller.js.map +1 -1
- package/dist/module/enterprise/repository/school.repository.d.ts +1 -1
- package/dist/module/enterprise/repository/school.repository.js +75 -109
- package/dist/module/enterprise/repository/school.repository.js.map +1 -1
- package/dist/module/enterprise/service/organization.service.d.ts +1 -1
- package/dist/module/enterprise/service/organization.service.js +2 -2
- package/dist/module/enterprise/service/organization.service.js.map +1 -1
- package/dist/module/meta/controller/entity.controller.js +1 -1
- package/dist/module/meta/controller/entity.controller.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/enterprise/controller/organization.controller.ts +2 -5
- package/src/module/enterprise/repository/school.repository.ts +94 -136
- package/src/module/enterprise/service/organization.service.ts +2 -2
- package/src/module/meta/controller/entity.controller.ts +1 -1
package/package.json
CHANGED
|
@@ -23,10 +23,7 @@ export class OrganizationController {
|
|
|
23
23
|
|
|
24
24
|
@UseGuards(JwtAuthGuard)
|
|
25
25
|
@Get('hierarchy')
|
|
26
|
-
async getOrganizationHierarchy(
|
|
27
|
-
|
|
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
|
}
|
|
@@ -24,153 +24,111 @@ export class SchoolRepository {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
async getUserContextDropdown(
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
65
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
}
|
|
@@ -78,7 +78,7 @@ export class OrganizationService {
|
|
|
78
78
|
await repo.delete(id);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
async getOrganizationHierarchy(
|
|
82
|
-
return await this.schoolRepository.getUserContextDropdown(
|
|
81
|
+
async getOrganizationHierarchy(): Promise<any[]> {
|
|
82
|
+
return await this.schoolRepository.getUserContextDropdown();
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -165,7 +165,7 @@ export class EntityController {
|
|
|
165
165
|
loggedInUser as UserData,
|
|
166
166
|
);
|
|
167
167
|
|
|
168
|
-
if (!updatedEntity
|
|
168
|
+
if (!updatedEntity) {
|
|
169
169
|
return response.status(HttpStatus.BAD_REQUEST).json({
|
|
170
170
|
success: false,
|
|
171
171
|
error: updatedEntity?.error || 'Entity creation failed',
|