rez_core 2.1.3 → 2.1.6

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.3",
3
+ "version": "2.1.6",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -4,15 +4,12 @@ import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
4
4
 
5
5
  @Injectable()
6
6
  export class MySqlConfiguration implements TypeOrmOptionsFactory {
7
-
8
- constructor(
9
- private configService: ConfigService,
10
- ){}
7
+ constructor(private configService: ConfigService) {}
11
8
 
12
9
  createTypeOrmOptions(): TypeOrmModuleOptions {
13
10
  return {
14
11
  type: 'mysql',
15
- host: this.configService.get('DB_HOST')|| '13.234.25.234',
12
+ host: this.configService.get('DB_HOST') || '13.234.25.234',
16
13
  port: parseInt(this.configService.get('DB_PORT') || '3306', 10),
17
14
  username: this.configService.get('DB_USER') || 'root',
18
15
  password: this.configService.get('DB_PASS') || 'Rezolut@123',
@@ -20,6 +17,7 @@ export class MySqlConfiguration implements TypeOrmOptionsFactory {
20
17
  entities: [__dirname + '/../module/**/*.entity.{ts,js}'],
21
18
  synchronize: true,
22
19
  autoLoadEntities: true,
20
+ poolSize: 5,
23
21
  };
24
22
  }
25
23
  }
@@ -0,0 +1,6 @@
1
+ // dto/service-result.dto.ts
2
+ export interface ServiceResult<T = any> {
3
+ success: boolean;
4
+ data?: T;
5
+ error?: string;
6
+ }
@@ -469,10 +469,6 @@ export class MasterService {
469
469
 
470
470
  const existing = await qb.limit(1).getRawOne();
471
471
 
472
- row.entity_type = entityType;
473
- row.organization_id = loggedInUser.organization_id;
474
- row.status = 'ACTIVE';
475
- let errors = [];
476
472
  if (existing) {
477
473
  if (duplicateHandling === 'skip_duplicates') continue;
478
474
  if (duplicateHandling === 'overwrite_items') {
@@ -483,5 +479,11 @@ export class MasterService {
483
479
  await entityService.createEntity(row, loggedInUser);
484
480
  }
485
481
  }
482
+
483
+ // if (errors.length > 0) {
484
+ // throw new Error(
485
+ // `Validation errors found in the uploaded data: ${JSON.stringify(errors)}`,
486
+ // );
487
+ // }
486
488
  }
487
489
  }
@@ -177,7 +177,7 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
177
177
  entityData: BaseEntity,
178
178
  loggedInUser: UserData | null,
179
179
  appcode?: string,
180
- ): Promise<BaseEntity> {
180
+ ) {
181
181
  const entityMaster = await this.entityMasterService.getEntityData(
182
182
  entityData.entity_type,
183
183
  );
@@ -4,7 +4,7 @@ import { RoleRepository } from 'src/module/user/repository/role.repository';
4
4
  import { RoleService } from '../../user/service/role.service';
5
5
  import { ENTITYTYPE_ROLE } from '../../../constant/global.constant';
6
6
  import { Role } from '../../user/entity/role.entity';
7
- import { EntityManager } from 'typeorm';
7
+ import { DataSource, EntityManager } from 'typeorm';
8
8
  import { UserData } from 'src/module/user/entity/user.entity';
9
9
  import { MenuRepository } from '../repository/menu.repository';
10
10
 
@@ -13,8 +13,8 @@ export class ModuleAccessService {
13
13
  constructor(
14
14
  private readonly moduleAccessRepository: ModuleAccessRepository,
15
15
  private readonly menuRepository: MenuRepository,
16
+ private readonly dataSource: DataSource,
16
17
  ) {}
17
-
18
18
  async getRoles({
19
19
  appcode,
20
20
  level_type,
@@ -24,12 +24,31 @@ export class ModuleAccessService {
24
24
  level_type?: string;
25
25
  level_id?: number;
26
26
  }) {
27
- return this.moduleAccessRepository.getRoles({
28
- appcode,
29
- level_type,
30
- level_id,
31
- });
27
+ const query = this.dataSource
28
+ .createQueryBuilder()
29
+ .select('*')
30
+ .from('cr_role', 'role')
31
+ .where('role.appcode = :appcode', { appcode })
32
+ .andWhere('(role.is_factory IS NULL OR role.is_factory != 1)');
33
+
34
+
35
+ if (level_type) {
36
+ query.andWhere('role.level_type = :level_type', { level_type });
37
+ }
38
+
39
+ if (level_id !== undefined) {
40
+ query.andWhere('role.level_id = :level_id', { level_id: String(level_id) });
41
+ }
42
+
43
+ const roles = await query.getRawMany(); // use getRawMany since you're selecting from a raw table
44
+
45
+ return roles.map((role) => ({
46
+ label: role.name,
47
+ value: role.id,
48
+ }));
32
49
  }
50
+
51
+
33
52
 
34
53
  async getModules({ appcode }: { appcode: string }) {
35
54
  return this.moduleAccessRepository.getModules({
@@ -120,9 +120,15 @@ export class LoginService {
120
120
  user.last_name = name.familyName;
121
121
 
122
122
  user.name = user.first_name + ' ' + user.last_name;
123
- let savedUser = await this.userService.createEntity(user, null);
124
-
125
- user = savedUser as UserData;
123
+ let savedUserResponse = await this.userService.createEntity(user, null);
124
+
125
+ if (savedUserResponse.success) {
126
+ user = savedUserResponse.data as UserData;
127
+ } else {
128
+ throw new BadRequestException(
129
+ savedUserResponse.error || 'Failed to create user',
130
+ );
131
+ }
126
132
  }
127
133
 
128
134
  // Create session (Same as JWT login flow)
@@ -13,12 +13,11 @@ import {
13
13
  import { CreateUserDto } from '../dto/create-user.dto';
14
14
  import { UserRoleMappingService } from './user-role-mapping.service';
15
15
  import { UserRoleMapping } from '../entity/user-role-mapping.entity';
16
- import { plainToInstance } from 'class-transformer';
17
16
  import { EntityManager } from 'typeorm';
18
17
  import { UpdateUserDto } from '../dto/update-user.dto';
19
18
  import { ConfigService } from '@nestjs/config';
20
19
  import { UserAppMappingService } from 'src/module/meta/service/user-app-mapping.service';
21
- import { Role } from '../entity/role.entity';
20
+ import { ServiceResult } from 'src/dtos/response.dto';
22
21
 
23
22
  @Injectable()
24
23
  export class UserService extends EntityServiceImpl {
@@ -40,7 +39,7 @@ export class UserService extends EntityServiceImpl {
40
39
  entityData: BaseEntity,
41
40
  loggedInUser: UserData | null,
42
41
  manager?: EntityManager,
43
- ): Promise<BaseEntity> {
42
+ ): Promise<ServiceResult<BaseEntity>> {
44
43
  let userData = entityData as CreateUserDto;
45
44
 
46
45
  let existingUser = await this.userRepository.findByEmailId(
@@ -48,7 +47,7 @@ export class UserService extends EntityServiceImpl {
48
47
  loggedInUser?.organization_id,
49
48
  );
50
49
  if (existingUser) {
51
- throw new BadRequestException('User already exists');
50
+ return { success: false, error: 'User with this email already exists' };
52
51
  }
53
52
 
54
53
  existingUser = await this.userRepository.findByMobile(
@@ -56,33 +55,24 @@ export class UserService extends EntityServiceImpl {
56
55
  loggedInUser?.organization_id,
57
56
  );
58
57
  if (existingUser) {
59
- throw new BadRequestException('User already exists');
58
+ return { success: false, error: 'User with this mobile already exists' };
60
59
  }
61
- userData.name =
62
- (userData.first_name ? userData.first_name : '') +
63
- (userData.last_name ? userData.last_name : '');
64
- let password;
65
- if (userData.password) {
66
- password = EncryptUtilService.encryptGCM(
67
- userData.password,
68
- this.masterKey,
69
- this.masterIv,
70
- );
71
- } else {
72
- password = EncryptUtilService.encryptGCM(
73
- 'Admin@123',
74
- this.masterKey,
75
- this.masterIv,
76
- );
77
- }
78
- userData.password = password;
60
+
61
+ userData.name = (userData.first_name || '') + (userData.last_name || '');
62
+ userData.password = EncryptUtilService.encryptGCM(
63
+ userData.password || 'Admin@123',
64
+ this.masterKey,
65
+ this.masterIv,
66
+ );
79
67
  userData.is_firstlogin = 1;
80
68
  userData.roles = [];
81
69
  userData.invitation_status = 'SENT';
82
70
  userData.status = STATUS_ACTIVE;
71
+
83
72
  const savedData = await super.createEntity(userData, loggedInUser);
84
73
 
85
- const insertPromises: any = [];
74
+ const insertPromises: Promise<UserRoleMapping | void | null | undefined>[] =
75
+ [];
86
76
 
87
77
  for (const entry of userData.access || []) {
88
78
  const { level_type, level_ids, app_code, role_id } = entry;
@@ -94,7 +84,7 @@ export class UserService extends EntityServiceImpl {
94
84
  !app_code ||
95
85
  !role_id
96
86
  ) {
97
- throw new BadRequestException('Invalid access level entry');
87
+ return { success: false, error: 'Invalid access level entry' };
98
88
  }
99
89
 
100
90
  for (const levelId of level_ids) {
@@ -115,10 +105,10 @@ export class UserService extends EntityServiceImpl {
115
105
  }
116
106
  } catch (error) {
117
107
  console.error('Error adding access levels:', error);
118
- throw new BadRequestException('Failed to add access levels');
108
+ return { success: false, error: 'Failed to add access levels' };
119
109
  }
120
110
 
121
- return savedData;
111
+ return { success: true, data: savedData };
122
112
  }
123
113
 
124
114
  async getEntityData(
@@ -148,12 +138,13 @@ export class UserService extends EntityServiceImpl {
148
138
  async updateEntity(
149
139
  entityData: BaseEntity,
150
140
  loggedInUserData: UserData,
151
- ): Promise<BaseEntity> {
141
+ ): Promise<ServiceResult<BaseEntity>> {
152
142
  const userDto = entityData as UpdateUserDto;
153
143
 
154
144
  const existingUser = await this.userRepository.findById(entityData.id);
145
+
155
146
  if (!existingUser) {
156
- throw new BadRequestException('User not found');
147
+ return { success: false, error: 'User not found' };
157
148
  }
158
149
 
159
150
  if (userDto.password) {
@@ -164,9 +155,10 @@ export class UserService extends EntityServiceImpl {
164
155
  );
165
156
 
166
157
  if (decryptedPassword === userDto.password) {
167
- throw new BadRequestException(
168
- 'New password cannot be the same as the current password',
169
- );
158
+ return {
159
+ success: false,
160
+ error: 'New password cannot be the same as the current password',
161
+ };
170
162
  }
171
163
 
172
164
  userDto.password = EncryptUtilService.encryptGCM(
@@ -186,7 +178,6 @@ export class UserService extends EntityServiceImpl {
186
178
 
187
179
  // Handle updated access levels
188
180
  if (userDto.access && userDto.access.length > 0) {
189
- // delete all the existing user role mapping
190
181
  await this.userRoleMappingService.deleteByUserId(existingUser.id);
191
182
 
192
183
  const insertPromises: any[] = [];
@@ -195,18 +186,17 @@ export class UserService extends EntityServiceImpl {
195
186
  const { level_type, level_ids, app_code, role_id } = entry;
196
187
 
197
188
  if (!level_type || !app_code || !role_id || !Array.isArray(level_ids)) {
198
- throw new BadRequestException('Invalid access level entry');
189
+ return { success: false, error: 'Invalid access level entry' };
199
190
  }
200
191
 
201
192
  for (const levelId of level_ids) {
202
193
  const userRoleMapping = new UserRoleMapping(savedData.id, role_id);
203
-
204
194
  userRoleMapping.level_type = level_type;
205
195
  userRoleMapping.level_id = String(levelId);
206
196
  userRoleMapping.appcode = app_code;
207
- userRoleMapping.role_id = role_id;
208
197
  userRoleMapping.organization_id =
209
198
  loggedInUserData?.organization_id || 0;
199
+
210
200
  insertPromises.push(
211
201
  this.userRoleMappingService.assignUserRole(userRoleMapping),
212
202
  );
@@ -217,11 +207,11 @@ export class UserService extends EntityServiceImpl {
217
207
  await Promise.all(insertPromises);
218
208
  } catch (error) {
219
209
  console.error('Error updating access levels:', error);
220
- throw new BadRequestException('Failed to update access levels');
210
+ return { success: false, error: 'Failed to update access levels' };
221
211
  }
222
212
  }
223
213
 
224
- return savedData;
214
+ return { success: true, data: savedData };
225
215
  }
226
216
 
227
217
  async findByEmailId(