rez_core 2.1.16 → 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.
Files changed (42) 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/repository/school.repository.d.ts +1 -1
  5. package/dist/module/enterprise/repository/school.repository.js +75 -109
  6. package/dist/module/enterprise/repository/school.repository.js.map +1 -1
  7. package/dist/module/enterprise/service/organization.service.d.ts +1 -1
  8. package/dist/module/enterprise/service/organization.service.js +2 -2
  9. package/dist/module/enterprise/service/organization.service.js.map +1 -1
  10. package/dist/module/filter/repository/saved-filter.repository.d.ts +1 -1
  11. package/dist/module/filter/repository/saved-filter.repository.js +6 -5
  12. package/dist/module/filter/repository/saved-filter.repository.js.map +1 -1
  13. package/dist/module/filter/service/saved-filter.service.d.ts +1 -1
  14. package/dist/module/filter/service/saved-filter.service.js +13 -2
  15. package/dist/module/filter/service/saved-filter.service.js.map +1 -1
  16. package/dist/module/layout_preference/service/layout_preference.service.js +0 -1
  17. package/dist/module/layout_preference/service/layout_preference.service.js.map +1 -1
  18. package/dist/module/meta/controller/entity.controller.js +5 -6
  19. package/dist/module/meta/controller/entity.controller.js.map +1 -1
  20. package/dist/module/meta/service/entity-service-impl.service.js +1 -1
  21. package/dist/module/meta/service/entity-service-impl.service.js.map +1 -1
  22. package/dist/module/meta/service/section-master.service.js +0 -1
  23. package/dist/module/meta/service/section-master.service.js.map +1 -1
  24. package/dist/module/module/repository/menu.repository.js +9 -8
  25. package/dist/module/module/repository/menu.repository.js.map +1 -1
  26. package/dist/module/user/controller/login.controller.js +0 -4
  27. package/dist/module/user/controller/login.controller.js.map +1 -1
  28. package/dist/tsconfig.build.tsbuildinfo +1 -1
  29. package/dist/utils/service/encryptUtil.service.js +1 -1
  30. package/package.json +1 -1
  31. package/src/module/enterprise/controller/organization.controller.ts +2 -5
  32. package/src/module/enterprise/repository/school.repository.ts +94 -136
  33. package/src/module/enterprise/service/organization.service.ts +2 -2
  34. package/src/module/filter/repository/saved-filter.repository.ts +12 -10
  35. package/src/module/filter/service/saved-filter.service.ts +14 -12
  36. package/src/module/layout_preference/service/layout_preference.service.ts +0 -2
  37. package/src/module/meta/controller/entity.controller.ts +5 -15
  38. package/src/module/meta/service/entity-service-impl.service.ts +1 -1
  39. package/src/module/meta/service/section-master.service.ts +0 -1
  40. package/src/module/module/repository/menu.repository.ts +38 -32
  41. package/src/module/user/controller/login.controller.ts +0 -10
  42. package/src/utils/service/encryptUtil.service.ts +1 -1
@@ -41,7 +41,7 @@ let EncryptUtilService = class EncryptUtilService {
41
41
  return decrypted;
42
42
  }
43
43
  catch (error) {
44
- throw new common_1.InternalServerErrorException('Encryption process failed');
44
+ throw new common_1.InternalServerErrorException('Decryption process failed');
45
45
  }
46
46
  }
47
47
  static encryptCBC(data, Datakey, Dataiv) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.16",
3
+ "version": "2.1.18",
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
  }
@@ -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
  }
@@ -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
  }
@@ -13,19 +13,21 @@ export class SavedFilterRepositoryService {
13
13
  private readonly savedFilterDetailRepo: Repository<SavedFilterDetail>,
14
14
  ) {}
15
15
 
16
- async isFilterNameExists(
17
- name: string,
18
- orgId: number,
19
- entId: number,
20
- excludeId?: number,
21
- ): Promise<boolean> {
16
+ async isFilterNameExists({
17
+ name,
18
+ organization_id,
19
+ id,
20
+ level_type,
21
+ level_id,
22
+ }: any): Promise<boolean> {
22
23
  const where: any = {
23
24
  name,
24
- organization_id: orgId,
25
- enterprise_id: entId,
25
+ organization_id: organization_id,
26
+ level_type: level_type,
27
+ level_id: level_id,
26
28
  };
27
- if (excludeId) {
28
- where.id = Not(excludeId);
29
+ if (id) {
30
+ where.id = Not(id);
29
31
  }
30
32
 
31
33
  const existing = await this.savedFilterMasterRepo.findOne({ where });
@@ -15,15 +15,17 @@ export class SavedFilterService extends EntityServiceImpl {
15
15
 
16
16
  async createEntity(
17
17
  entityData: any,
18
- loggedInUser: UserData | null,
18
+ loggedInUser: UserData,
19
19
  ): Promise<BaseEntity> {
20
20
  const master = entityData as SavedFilterMaster;
21
21
 
22
- const exists = await this.savedFilterRepo.isFilterNameExists(
23
- master.name,
24
- master.organization_id,
25
- master.enterprise_id,
26
- );
22
+ const exists = await this.savedFilterRepo.isFilterNameExists({
23
+ name: master.name,
24
+ organization_id: loggedInUser.organization_id,
25
+ id: master.id,
26
+ level_type: loggedInUser?.level_type,
27
+ level_id: loggedInUser?.level_id,
28
+ });
27
29
 
28
30
  if (exists) {
29
31
  throw new BadRequestException('Saved filter name already exists.');
@@ -68,12 +70,12 @@ export class SavedFilterService extends EntityServiceImpl {
68
70
  throw new BadRequestException('Saved filter not found.');
69
71
  }
70
72
 
71
- const nameExists = await this.savedFilterRepo.isFilterNameExists(
72
- master.name,
73
- master.organization_id,
74
- master.enterprise_id,
75
- master.id,
76
- );
73
+ const nameExists = await this.savedFilterRepo.isFilterNameExists({
74
+ name: master.name,
75
+ organization_id: master.organization_id,
76
+ enterprise_id: master.enterprise_id,
77
+ id: master.id, // Include ID to check for updates
78
+ });
77
79
 
78
80
  if (nameExists) {
79
81
  throw new BadRequestException('Saved filter name already exists.');
@@ -22,8 +22,6 @@ 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
-
27
25
  const existingLayoutPreference =
28
26
  await this.layoutPreferenceRepository.findByEntityUserId(
29
27
  mapped_entity_type,
@@ -60,7 +60,6 @@ export class EntityController {
60
60
  }
61
61
 
62
62
  @Post('create')
63
- // @Roles('USR', 'VIEW')
64
63
  async create(
65
64
  @Body() entityData: BaseEntity,
66
65
  @Query('entity_type') entityType: string,
@@ -68,18 +67,9 @@ export class EntityController {
68
67
  @Req() req: Request & { user: any },
69
68
  ) {
70
69
  try {
71
- let requestedUser = req.user.userData;
72
- let appcode = requestedUser.appcode;
73
- // let loggedInUser = await this.entityService.getEntityData(
74
- // ENTITYTYPE_USER,
75
- // requestedUser.userId,
76
- // );
77
70
  let loggedInUser = req.user.userData;
71
+ let appcode = req.user.userData.appcode;
78
72
  if (!entityType) {
79
- // throw new BadRequestException(
80
- // 'Query parameter "entity_type" is required',
81
- // );
82
-
83
73
  return res.status(HttpStatus.BAD_REQUEST).json({
84
74
  success: false,
85
75
  error: 'Query parameter "entity_type" is required',
@@ -96,7 +86,7 @@ export class EntityController {
96
86
  if (!entityService) {
97
87
  return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
98
88
  success: false,
99
- error: `No service found for entity_type "${entityType}"`,
89
+ error: `No service found for Entity Type ${entityType}`,
100
90
  });
101
91
  }
102
92
  const createdEntity = await entityService.createEntity(
@@ -106,7 +96,7 @@ export class EntityController {
106
96
  appcode,
107
97
  );
108
98
 
109
- if (!createdEntity || !createdEntity.success) {
99
+ if (!createdEntity) {
110
100
  return res.status(HttpStatus.BAD_REQUEST).json({
111
101
  success: false,
112
102
  error: createdEntity?.error || 'Entity creation failed',
@@ -115,7 +105,7 @@ export class EntityController {
115
105
 
116
106
  return res.status(HttpStatus.OK).json({
117
107
  success: true,
118
- data: createdEntity.data,
108
+ data: createdEntity,
119
109
  });
120
110
  } catch (error) {
121
111
  return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
@@ -175,7 +165,7 @@ export class EntityController {
175
165
  loggedInUser as UserData,
176
166
  );
177
167
 
178
- if (!updatedEntity || !updatedEntity.success) {
168
+ if (!updatedEntity) {
179
169
  return response.status(HttpStatus.BAD_REQUEST).json({
180
170
  success: false,
181
171
  error: updatedEntity?.error || 'Entity creation failed',
@@ -51,7 +51,7 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
51
51
  );
52
52
  if (validationErrors.length > 0) {
53
53
  throw new BadRequestException({
54
- success: false,
54
+ message: 'Validation failed',
55
55
  errors: validationErrors,
56
56
  });
57
57
  }
@@ -52,7 +52,6 @@ export class SectionMasterService extends EntityServiceImpl {
52
52
 
53
53
  if (layoutJson?.form?.children && Array.isArray(layoutJson.form.children)) {
54
54
  const firstChild = layoutJson.form.children[0];
55
- console.log('First Child:', firstChild);
56
55
 
57
56
  if (firstChild.type === 'wizard' && Array.isArray(firstChild.steps)) {
58
57
  console.log('Wizard Steps:', firstChild.steps);
@@ -8,8 +8,9 @@ import { InjectRepository } from '@nestjs/typeorm';
8
8
 
9
9
  @Injectable()
10
10
  export class MenuRepository extends Repository<MenuData> {
11
- constructor(private readonly dataSource: DataSource,
12
- @InjectRepository(MenuData) private readonly menuData: Repository<MenuData>
11
+ constructor(
12
+ private readonly dataSource: DataSource,
13
+ @InjectRepository(MenuData) private readonly menuData: Repository<MenuData>,
13
14
  ) {
14
15
  super(MenuData, dataSource.createEntityManager());
15
16
  }
@@ -27,7 +28,10 @@ export class MenuRepository extends Repository<MenuData> {
27
28
  return roles.map((r) => r.urm_role_id);
28
29
  }
29
30
 
30
- async getAccessibleModules(roleIds: number[], appCode: string): Promise<string[]> {
31
+ async getAccessibleModules(
32
+ roleIds: number[],
33
+ appCode: string,
34
+ ): Promise<string[]> {
31
35
  const roleCodes = await this.dataSource
32
36
  .getRepository(Role)
33
37
  .createQueryBuilder('role')
@@ -35,11 +39,9 @@ export class MenuRepository extends Repository<MenuData> {
35
39
  .where('role.id IN (:...roleIds)', { roleIds })
36
40
  .getMany();
37
41
 
38
- console.log(roleCodes,"ROLE CODES")
39
-
40
42
  const codes = roleCodes.map((role) => role.code);
41
43
  if (codes.length === 0) return [];
42
-
44
+
43
45
  const modules = await this.dataSource
44
46
  .getRepository(ModuleAccess)
45
47
  .createQueryBuilder('moduleAccess')
@@ -49,16 +51,17 @@ export class MenuRepository extends Repository<MenuData> {
49
51
  .andWhere('LOWER(moduleAccess.appcode) = LOWER(:appCode)', { appCode })
50
52
  .getMany();
51
53
 
52
- console.log(modules,"MODULES")
53
-
54
54
  return Array.from(new Set(modules.map((module) => module.module_code)));
55
55
  }
56
-
57
56
 
58
57
  /**
59
58
  * ✅ FIXED: Use this.createQueryBuilder() instead of this.menuData.createQueryBuilder()
60
59
  */
61
- async getMenuItems(moduleCodes: string[], appcode: string, levelType: string) {
60
+ async getMenuItems(
61
+ moduleCodes: string[],
62
+ appcode: string,
63
+ levelType: string,
64
+ ) {
62
65
  return await this.menuData
63
66
  .createQueryBuilder('menu')
64
67
  .leftJoin(
@@ -68,7 +71,7 @@ export class MenuRepository extends Repository<MenuData> {
68
71
  menu.module_code = module.module_code
69
72
  AND LOWER(menu.appcode) = LOWER(module.appcode)
70
73
  AND menu.level_type = module.level_type
71
- `
74
+ `,
72
75
  )
73
76
  .where('menu.module_code IN (:...moduleCodes)', { moduleCodes })
74
77
  .andWhere('LOWER(menu.appcode) = LOWER(:appcode)', { appcode })
@@ -83,8 +86,7 @@ export class MenuRepository extends Repository<MenuData> {
83
86
  ])
84
87
  .getRawMany();
85
88
  }
86
-
87
-
89
+
88
90
  async resolveUserRoles(
89
91
  userId: number,
90
92
  appcode: string,
@@ -92,9 +94,10 @@ export class MenuRepository extends Repository<MenuData> {
92
94
  levelId: number,
93
95
  ): Promise<number[]> {
94
96
  const repo = this.dataSource.getRepository(UserRoleMapping);
95
-
97
+
96
98
  // 1. Try exact level match
97
- let roles = await repo.createQueryBuilder('urm')
99
+ let roles = await repo
100
+ .createQueryBuilder('urm')
98
101
  .innerJoin('cr_role', 'role', 'role.id = urm.role_id')
99
102
  .select('urm.role_id')
100
103
  .where('urm.user_id = :userId', { userId })
@@ -102,23 +105,26 @@ export class MenuRepository extends Repository<MenuData> {
102
105
  .andWhere('urm.level_id = :levelId', { levelId })
103
106
  .andWhere('role.appcode = :appcode', { appcode })
104
107
  .getRawMany();
105
-
106
- if (roles.length) return roles.map(r => r.urm_role_id);
107
-
108
+
109
+ if (roles.length) return roles.map((r) => r.urm_role_id);
110
+
108
111
  // 2. If SCH fallback → BRN → ORG
109
112
  if (levelType === 'SCH') {
110
- const [sch] = await this.dataSource.query(`
113
+ const [sch] = await this.dataSource.query(
114
+ `
111
115
  SELECT s.brand_id, s.organization_id
112
116
  FROM cr_school s
113
117
  WHERE s.id = ?
114
- `, [levelId]);
115
-
116
-
118
+ `,
119
+ [levelId],
120
+ );
121
+
117
122
  const brandId = sch?.brand_id;
118
123
  const orgId = sch?.organization_id;
119
-
124
+
120
125
  if (brandId) {
121
- roles = await repo.createQueryBuilder('urm')
126
+ roles = await repo
127
+ .createQueryBuilder('urm')
122
128
  .innerJoin('cr_role', 'role', 'role.id = urm.role_id')
123
129
  .select('urm.role_id')
124
130
  .where('urm.user_id = :userId', { userId })
@@ -126,12 +132,13 @@ export class MenuRepository extends Repository<MenuData> {
126
132
  .andWhere('urm.level_id = :levelId', { levelId: brandId })
127
133
  .andWhere('role.appcode = :appcode', { appcode })
128
134
  .getRawMany();
129
-
130
- if (roles.length) return roles.map(r => r.urm_role_id);
135
+
136
+ if (roles.length) return roles.map((r) => r.urm_role_id);
131
137
  }
132
-
138
+
133
139
  if (orgId) {
134
- roles = await repo.createQueryBuilder('urm')
140
+ roles = await repo
141
+ .createQueryBuilder('urm')
135
142
  .innerJoin('cr_role', 'role', 'role.id = urm.role_id')
136
143
  .select('urm.role_id')
137
144
  .where('urm.user_id = :userId', { userId })
@@ -139,12 +146,11 @@ export class MenuRepository extends Repository<MenuData> {
139
146
  .andWhere('urm.level_id = :levelId', { levelId: orgId })
140
147
  .andWhere('role.appcode = :appcode', { appcode })
141
148
  .getRawMany();
142
-
143
- if (roles.length) return roles.map(r => r.urm_role_id);
149
+
150
+ if (roles.length) return roles.map((r) => r.urm_role_id);
144
151
  }
145
152
  }
146
-
153
+
147
154
  return [];
148
155
  }
149
-
150
156
  }
@@ -71,11 +71,8 @@ export class LoginController {
71
71
  const currentUser = req.user.userData;
72
72
  const currentAppcode = currentUser.appcode;
73
73
 
74
- console.log(currentUser, 'DEBUG USER', data);
75
-
76
74
  // If appcode is changing, validate the new level_id/level_type
77
75
  if (data.appcode !== currentAppcode) {
78
- console.log('inside if', data.appcode, currentAppcode);
79
76
  const isValidAccess = await this.userSessionService.checkIfUserHasMapping(
80
77
  currentUser.id,
81
78
  data.appcode,
@@ -83,8 +80,6 @@ export class LoginController {
83
80
  data.level_id,
84
81
  );
85
82
 
86
- console.log('isValidAccess', isValidAccess);
87
-
88
83
  if (!isValidAccess) {
89
84
  // If not valid, fetch the default one
90
85
  const userMapping =
@@ -102,11 +97,6 @@ export class LoginController {
102
97
  data.level_type = userMapping.level_type;
103
98
  data.level_id = userMapping.level_id;
104
99
  }
105
- console.log(
106
- data.level_type,
107
- data.level_id,
108
- 'data.level_type, data.level_id',
109
- );
110
100
  }
111
101
 
112
102
  return await this.userSessionService.switchCurrentLevelService(
@@ -32,7 +32,7 @@ export class EncryptUtilService {
32
32
  let decrypted = decipher.update(data, 'utf8') + decipher.final('utf8');
33
33
  return decrypted;
34
34
  } catch (error) {
35
- throw new InternalServerErrorException('Encryption process failed');
35
+ throw new InternalServerErrorException('Decryption process failed');
36
36
  }
37
37
  }
38
38