rez_core 2.1.60 → 2.1.62

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.60",
3
+ "version": "2.1.62",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -5,6 +5,7 @@ import { ModuleAccess } from '../entity/module-access.entity';
5
5
  import { UserRoleMapping } from 'src/module/user/entity/user-role-mapping.entity';
6
6
  import { Role } from 'src/module/user/entity/role.entity';
7
7
  import { InjectRepository } from '@nestjs/typeorm';
8
+ import { get } from 'http';
8
9
 
9
10
  @Injectable()
10
11
  export class MenuRepository extends Repository<MenuData> {
@@ -95,6 +96,23 @@ export class MenuRepository extends Repository<MenuData> {
95
96
  ): Promise<number[]> {
96
97
  const repo = this.dataSource.getRepository(UserRoleMapping);
97
98
 
99
+ if (userId) {
100
+ // Check if user has any role mappings for the given appcode
101
+ const getUserDetails = await this.dataSource.query(
102
+ `
103
+ SELECT * from cr_user where id = ?
104
+ `,
105
+ [userId],
106
+ );
107
+
108
+ if (
109
+ getUserDetails.length > 0 &&
110
+ getUserDetails[0].organization_id === 1
111
+ ) {
112
+ return [6];
113
+ }
114
+ }
115
+
98
116
  // 1. Try exact level match
99
117
  let roles = await repo
100
118
  .createQueryBuilder('urm')
@@ -84,6 +84,10 @@ export class UserSessionService {
84
84
  appcode: data.appcode,
85
85
  };
86
86
 
87
+ if (payload.organization_id === 1 && payload.level_type === 'ORG') {
88
+ payload.organization_id = payload.level_id;
89
+ }
90
+
87
91
  await this.dataSource.query(
88
92
  `UPDATE cr_user SET last_app_access = ? , last_level_type = ?, last_level_id = ? WHERE id = ?`,
89
93
  [data.appcode, data.level_type, data.level_id, currentUser.id],
@@ -123,19 +127,19 @@ export class UserSessionService {
123
127
  .where('cr_user_role_mapping.user_id = :userId', { userId })
124
128
  .andWhere('cr_user_role_mapping.appcode = :appcode', { appcode })
125
129
  .getOne();
126
-
130
+
127
131
  // If not found or is already ORG/SCH, return directly
128
132
  if (!mapping || mapping.level_type !== 'BRN') {
129
133
  return mapping;
130
134
  }
131
-
135
+
132
136
  //DONE
133
137
  // If BRN, resolve first SCH under this brand
134
138
  const schools = await this.dataSource.query(
135
139
  `SELECT id FROM cr_school WHERE brand_id = ? ORDER BY id ASC LIMIT 1`,
136
140
  [mapping.level_id],
137
141
  );
138
-
142
+
139
143
  if (schools.length) {
140
144
  return {
141
145
  ...mapping,
@@ -143,9 +147,8 @@ export class UserSessionService {
143
147
  level_id: schools[0].id,
144
148
  };
145
149
  }
146
-
150
+
147
151
  // No SCH found under BRN
148
152
  return null;
149
153
  }
150
-
151
154
  }