rez_core 1.0.43 → 1.0.45

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 (29) hide show
  1. package/dist/constant/global.constant.d.ts +2 -0
  2. package/dist/constant/global.constant.js +3 -1
  3. package/dist/constant/global.constant.js.map +1 -1
  4. package/dist/core.module.js +3 -0
  5. package/dist/core.module.js.map +1 -1
  6. package/dist/module/meta/entity/view-master.entity.d.ts +11 -0
  7. package/dist/module/meta/entity/view-master.entity.js +55 -0
  8. package/dist/module/meta/entity/view-master.entity.js.map +1 -0
  9. package/dist/module/meta/service/view-master.service.d.ts +10 -0
  10. package/dist/module/meta/service/view-master.service.js +35 -0
  11. package/dist/module/meta/service/view-master.service.js.map +1 -0
  12. package/dist/module/module/controller/module-access.controller.d.ts +14 -0
  13. package/dist/module/module/controller/module-access.controller.js +11 -0
  14. package/dist/module/module/controller/module-access.controller.js.map +1 -1
  15. package/dist/module/module/repository/module-access.repository.d.ts +15 -0
  16. package/dist/module/module/repository/module-access.repository.js +66 -12
  17. package/dist/module/module/repository/module-access.repository.js.map +1 -1
  18. package/dist/module/module/service/module-access.service.d.ts +14 -0
  19. package/dist/module/module/service/module-access.service.js +11 -0
  20. package/dist/module/module/service/module-access.service.js.map +1 -1
  21. package/dist/tsconfig.build.tsbuildinfo +1 -1
  22. package/package.json +1 -1
  23. package/src/constant/global.constant.ts +4 -0
  24. package/src/core.module.ts +4 -0
  25. package/src/module/meta/entity/view-master.entity.ts +32 -0
  26. package/src/module/meta/service/view-master.service.ts +41 -0
  27. package/src/module/module/controller/module-access.controller.ts +26 -10
  28. package/src/module/module/repository/module-access.repository.ts +95 -36
  29. package/src/module/module/service/module-access.service.ts +20 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -20,3 +20,7 @@ export const secretKey: string = process.env.secret_key || '';
20
20
  export const STATUS_ACTIVE = 'ACTIVE';
21
21
  export const STATUS_INACTIVE = 'INACTIVE';
22
22
  export const STATUS_PENDING = 'PENDING';
23
+
24
+ // Entity Status
25
+ export const ENTITYSTATUS_TO_BE_PUBLISHED = 'to_be_published';
26
+ export const ENTITYSTATUS_PUBLISHED = 'published';
@@ -7,6 +7,7 @@ import { EntityModule } from './module/meta/entity.module';
7
7
  import { ModuleModule } from './module/module/module.module';
8
8
  import { NotificationModule } from './module/notification/notification.module';
9
9
  import { LayoutModule } from './module/layout/layout.module';
10
+ import { ListMasterModule } from './module/listmaster/listmaster.module';
10
11
 
11
12
  @Global()
12
13
  @Module({})
@@ -28,6 +29,7 @@ export class CoreModule {
28
29
  ModuleModule,
29
30
  NotificationModule,
30
31
  LayoutModule,
32
+ ListMasterModule,
31
33
  ],
32
34
  exports: [
33
35
  ConfigModule,
@@ -39,6 +41,8 @@ export class CoreModule {
39
41
  ModuleModule,
40
42
  NotificationModule,
41
43
  LayoutModule,
44
+ ListMasterModule,
45
+
42
46
  ],
43
47
  };
44
48
  }
@@ -0,0 +1,32 @@
1
+ import { BaseEntity } from './base-entity.entity';
2
+ import { Column, Entity } from 'typeorm';
3
+ import { ENTITYTYPE_VIEWMASTER } from '../../../constant/global.constant';
4
+
5
+ @Entity({ name: 'cr_view_master' })
6
+ export class ViewMaster extends BaseEntity {
7
+ constructor() {
8
+ super();
9
+ this.entity_type = ENTITYTYPE_VIEWMASTER;
10
+ }
11
+
12
+ @Column({ length: 50, nullable: true })
13
+ mapped_entity_type: string;
14
+
15
+ @Column({type: 'varchar', nullable: true})
16
+ section_layout: string;
17
+
18
+ @Column({nullable: true})
19
+ section_information: string;
20
+
21
+ @Column({nullable: true})
22
+ description: string;
23
+
24
+ @Column({type: 'json', nullable: true})
25
+ published_form_layout: string;
26
+
27
+ @Column({type: 'json', nullable: true})
28
+ published_form_fields: string;
29
+
30
+ @Column({type: 'int'})
31
+ is_default: number;
32
+ }
@@ -0,0 +1,41 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { EntityServiceImpl } from './entity-service-impl.service';
3
+ import { BaseEntity } from '../entity/base-entity.entity';
4
+ import { UserData } from '../../user/entity/user.entity';
5
+ import { EntityManager } from 'typeorm';
6
+ import { ViewMaster } from '../entity/view-master.entity';
7
+
8
+ @Injectable()
9
+ export class ViewMasterService extends EntityServiceImpl {
10
+ constructor() {
11
+ super();
12
+ }
13
+
14
+ async createEntity(
15
+ entityData: BaseEntity,
16
+ loggedInUser: UserData | null,
17
+ manager?: EntityManager,
18
+ ): Promise<BaseEntity> {
19
+ const entityMaster = await this.entityMasterService.getEntityData(
20
+ entityData.entity_type,
21
+ );
22
+ entityData.parent_id = entityMaster.id;
23
+ entityData.parent_type = entityMaster.entity_type;
24
+
25
+ const savedEntity = await super.createEntity(
26
+ entityData,
27
+ loggedInUser,
28
+ manager,
29
+ );
30
+ return savedEntity;
31
+ }
32
+
33
+ async updateEntity(
34
+ entityData: ViewMaster,
35
+ loggedInUserData: UserData | null,
36
+ ): Promise<BaseEntity> {
37
+
38
+ return entityData;
39
+ }
40
+
41
+ }
@@ -1,4 +1,4 @@
1
- import { Body, Controller, Get, Post, Query, UseGuards } from '@nestjs/common';
1
+ import { Body, Controller, Get, Param, Post, Query, UseGuards } from '@nestjs/common';
2
2
  import { ModuleAccessService } from '../service/module-access.service';
3
3
  import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
4
4
 
@@ -7,7 +7,6 @@ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
7
7
  export class ModuleAccessController {
8
8
  constructor(private readonly moduleAccessService: ModuleAccessService) {}
9
9
 
10
-
11
10
  @Get('roles')
12
11
  async getRoles() {
13
12
  return this.moduleAccessService.getRoles();
@@ -36,14 +35,31 @@ export class ModuleAccessController {
36
35
  }
37
36
 
38
37
  @Post('create-role')
39
- async createRole(@Body() body: {
40
- name: string;
41
- description?: string;
42
- status?: 'ACTIVE' | 'INACTIVE';
43
- copyFromRoleId?: number;
44
- }) {
45
- return this.moduleAccessService.createRole(body);
46
- }
38
+ async createRole(
39
+ @Body()
40
+ body: {
41
+ name: string;
42
+ description?: string;
43
+ status?: 'ACTIVE' | 'INACTIVE';
44
+ copyFromRoleId?: number;
45
+ },
46
+ ) {
47
+ return this.moduleAccessService.createRole(body);
48
+ }
47
49
 
50
+ @Post('update-role/:id')
51
+ async updateRole(
52
+ @Param('id') id: number,
53
+ @Body()
54
+ body: {
55
+ name?: string;
56
+ description?: string;
57
+ status?: 'ACTIVE' | 'INACTIVE';
58
+ copyFromRoleId?: number; // <-- ADD THIS
59
+ },
60
+ ) {
61
+ return this.moduleAccessService.updateRole(id, body);
62
+ }
63
+
48
64
 
49
65
  }
@@ -1,4 +1,4 @@
1
- import { Injectable } from '@nestjs/common';
1
+ import { BadRequestException, Injectable } from '@nestjs/common';
2
2
  import { InjectRepository } from '@nestjs/typeorm';
3
3
  import { In, Repository } from 'typeorm';
4
4
  import { Role } from 'src/module/user/entity/role.entity';
@@ -67,17 +67,22 @@ export class ModuleAccessRepository {
67
67
  }
68
68
 
69
69
  async getMenuListing(mainModIds: string[]) {
70
- // Get MAINMOD modules using their IDs
71
- const mainModules = await this.moduleRepo.find({
72
- where: { id: In(mainModIds), module_level: 'MAINMOD' },
73
- });
74
-
70
+ let mainModules: ModuleData[] = [];
71
+
72
+ if (mainModIds.length === 1 && mainModIds[0] === '-1') {
73
+ // Fetch ALL MAINMOD modules if "-1" is passed
74
+ mainModules = await this.moduleRepo.find({ where: { module_level: 'MAINMOD' } });
75
+ } else {
76
+ // Fetch selected MAINMOD modules
77
+ mainModules = await this.moduleRepo.find({
78
+ where: { id: In(mainModIds), module_level: 'MAINMOD' },
79
+ });
80
+ }
81
+
75
82
  if (!mainModules.length) return [];
76
-
77
- // Extract WBS codes of the MAINMOD modules
83
+
78
84
  const wbsCodes = mainModules.map((mod) => mod.wbs_code);
79
-
80
- // Fetch all related modules using `LIKE` for WBS structure
85
+
81
86
  const modules = await this.moduleRepo
82
87
  .createQueryBuilder('module')
83
88
  .where(
@@ -87,17 +92,15 @@ export class ModuleAccessRepository {
87
92
  Object.fromEntries(wbsCodes.map((code) => [`code${code}`, `${code}%`])),
88
93
  )
89
94
  .getMany();
90
-
91
- // Fetch module actions
95
+
92
96
  const moduleActions = await this.moduleActionRepo.find();
93
-
94
- // Function to recursively build module hierarchy
97
+
95
98
  const buildHierarchy = (parentWbs: string) => {
96
99
  return modules
97
- .filter(mod => {
98
- return mod.wbs_code.startsWith(parentWbs + '.') &&
99
- mod.wbs_code.split('.').length === parentWbs.split('.').length + 1;
100
- })
100
+ .filter(mod =>
101
+ mod.wbs_code.startsWith(parentWbs + '.') &&
102
+ mod.wbs_code.split('.').length === parentWbs.split('.').length + 1
103
+ )
101
104
  .map((mod) => ({
102
105
  name: mod.name,
103
106
  code: mod.module_code,
@@ -110,8 +113,7 @@ export class ModuleAccessRepository {
110
113
  submod: buildHierarchy(mod.wbs_code),
111
114
  }));
112
115
  };
113
-
114
- // Construct the final hierarchical response
116
+
115
117
  return mainModules.map((mod) => ({
116
118
  name: mod.name,
117
119
  code: mod.module_code,
@@ -124,6 +126,7 @@ export class ModuleAccessRepository {
124
126
  submod: buildHierarchy(mod.wbs_code),
125
127
  }));
126
128
  }
129
+
127
130
  async updateModuleAccess(moduleAccessData: any[]): Promise<boolean> {
128
131
  try {
129
132
  for (const access of moduleAccessData) {
@@ -154,17 +157,15 @@ export class ModuleAccessRepository {
154
157
  }
155
158
  }
156
159
 
157
-
158
- async createRole(body: {
159
- name: string;
160
- description?: string;
161
- status?: 'ACTIVE' | 'INACTIVE';
162
- copyFromRoleId?: number;
163
- }) {
160
+ async createRole(body: { name: string; description?: string; status?: 'ACTIVE' | 'INACTIVE'; copyFromRoleId?: number }) {
164
161
  const { name, description, status, copyFromRoleId } = body;
165
162
 
166
- const code = this.clockIDGenService.idGenerator('ROL');; // Replace with your custom clock ID generator
163
+ const nameExists = await this.isRoleNameExists(name);
164
+ if (nameExists) {
165
+ throw new BadRequestException('Role name already exists.');
166
+ }
167
167
 
168
+ const code = this.clockIDGenService.idGenerator('ROL');
168
169
  const newRole = this.roleRepo.create({
169
170
  name,
170
171
  code,
@@ -176,15 +177,10 @@ export class ModuleAccessRepository {
176
177
 
177
178
  if (copyFromRoleId) {
178
179
  const sourceRole = await this.roleRepo.findOne({ where: { id: copyFromRoleId } });
179
-
180
180
  if (!sourceRole) {
181
- throw new Error('Source role not found');
181
+ throw new BadRequestException('Source role not found');
182
182
  }
183
-
184
- const sourcePermissions = await this.moduleAccessRepo.find({
185
- where: { role_code: sourceRole.code },
186
- });
187
-
183
+ const sourcePermissions = await this.moduleAccessRepo.find({ where: { role_code: sourceRole.code } });
188
184
  const clonedPermissions = sourcePermissions.map((perm) =>
189
185
  this.moduleAccessRepo.create({
190
186
  role_code: code,
@@ -194,7 +190,6 @@ export class ModuleAccessRepository {
194
190
  app_code: perm.app_code,
195
191
  })
196
192
  );
197
-
198
193
  await this.moduleAccessRepo.save(clonedPermissions);
199
194
  }
200
195
 
@@ -208,4 +203,68 @@ export class ModuleAccessRepository {
208
203
  },
209
204
  };
210
205
  }
206
+
207
+
208
+ async updateRole(roleId: number, body: { name: string; description?: string; status?: 'ACTIVE' | 'INACTIVE'; copyFromRoleId?: number }) {
209
+ const { name, description, status, copyFromRoleId } = body;
210
+
211
+ const nameExists = await this.isRoleNameExists(name, roleId);
212
+ if (nameExists) {
213
+ throw new BadRequestException('Role name already exists.');
214
+ }
215
+
216
+ const role = await this.roleRepo.findOne({ where: { id: roleId } });
217
+ if (!role) {
218
+ throw new BadRequestException('Source role not found');
219
+ }
220
+
221
+ role.name = name;
222
+ role.description = description || "";
223
+ role.status = status || 'ACTIVE';
224
+ await this.roleRepo.save(role);
225
+
226
+ if (copyFromRoleId) {
227
+ await this.moduleAccessRepo.delete({ role_code: role.code });
228
+
229
+ const sourceRole = await this.roleRepo.findOne({ where: { id: copyFromRoleId } });
230
+ if (!sourceRole) {
231
+ throw new BadRequestException('Source role not found');
232
+ }
233
+
234
+ const sourcePermissions = await this.moduleAccessRepo.find({ where: { role_code: sourceRole.code } });
235
+ const clonedPermissions = sourcePermissions.map((perm) =>
236
+ this.moduleAccessRepo.create({
237
+ role_code: role.code,
238
+ module_code: perm.module_code,
239
+ action_type: perm.action_type,
240
+ access_flag: perm.access_flag,
241
+ app_code: perm.app_code,
242
+ })
243
+ );
244
+ await this.moduleAccessRepo.save(clonedPermissions);
245
+ }
246
+
247
+ return {
248
+ success: true,
249
+ msg: 'Role updated successfully',
250
+ role: {
251
+ id: role.id,
252
+ name: role.name,
253
+ code: role.code,
254
+ },
255
+ };
256
+ }
257
+
258
+ async isRoleNameExists(name: string, excludeRoleId?: number): Promise<boolean> {
259
+ const query = this.roleRepo.createQueryBuilder('role')
260
+ .where('role.name = :name', { name });
261
+
262
+ if (excludeRoleId) {
263
+ query.andWhere('role.id != :excludeRoleId', { excludeRoleId });
264
+ }
265
+
266
+ const existingRole = await query.getOne();
267
+ return !!existingRole;
268
+ }
269
+
211
270
  }
@@ -48,5 +48,25 @@ export class ModuleAccessService {
48
48
  }) {
49
49
  return this.moduleAccessRepository.createRole(body);
50
50
  }
51
+
52
+ async updateRole(id: number, body: {
53
+ name?: string;
54
+ description?: string;
55
+ status?: 'ACTIVE' | 'INACTIVE';
56
+ copyFromRoleId?: number;
57
+ }) {
58
+ if (!body.name) {
59
+ throw new Error('Role name is required');
60
+ }
61
+
62
+ return this.moduleAccessRepository.updateRole(id, {
63
+ name: body.name,
64
+ description: body.description,
65
+ status: body.status,
66
+ copyFromRoleId: body.copyFromRoleId,
67
+ });
68
+ }
69
+
70
+
51
71
 
52
72
  }