rez_core 2.0.0 → 2.0.2

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 (93) hide show
  1. package/dist/module/enterprise/entity/enterprise.entity.d.ts +1 -1
  2. package/dist/module/enterprise/entity/enterprise.entity.js +2 -2
  3. package/dist/module/enterprise/entity/enterprise.entity.js.map +1 -1
  4. package/dist/module/enterprise/entity/organization.entity.d.ts +1 -1
  5. package/dist/module/enterprise/entity/organization.entity.js +2 -2
  6. package/dist/module/enterprise/entity/organization.entity.js.map +1 -1
  7. package/dist/module/filter/entity/saved-filter-master.entity.d.ts +0 -1
  8. package/dist/module/filter/entity/saved-filter-master.entity.js +0 -4
  9. package/dist/module/filter/entity/saved-filter-master.entity.js.map +1 -1
  10. package/dist/module/master/service/master.service.js +31 -15
  11. package/dist/module/master/service/master.service.js.map +1 -1
  12. package/dist/module/meta/controller/entity.controller.d.ts +1 -1
  13. package/dist/module/meta/controller/entity.controller.js +14 -11
  14. package/dist/module/meta/controller/entity.controller.js.map +1 -1
  15. package/dist/module/meta/entity/entity-table-column.entity.d.ts +0 -1
  16. package/dist/module/meta/entity/entity-table-column.entity.js +0 -4
  17. package/dist/module/meta/entity/entity-table-column.entity.js.map +1 -1
  18. package/dist/module/meta/entity/entity-table.entity.d.ts +0 -1
  19. package/dist/module/meta/entity/entity-table.entity.js +0 -4
  20. package/dist/module/meta/entity/entity-table.entity.js.map +1 -1
  21. package/dist/module/meta/service/entity-list.service.d.ts +2 -2
  22. package/dist/module/meta/service/entity-list.service.js +18 -7
  23. package/dist/module/meta/service/entity-list.service.js.map +1 -1
  24. package/dist/module/meta/service/entity-service-impl.service.d.ts +3 -3
  25. package/dist/module/meta/service/entity-service-impl.service.js +4 -4
  26. package/dist/module/meta/service/entity-service-impl.service.js.map +1 -1
  27. package/dist/module/meta/service/entity.service.d.ts +2 -2
  28. package/dist/module/module/controller/menu.controller.js +2 -1
  29. package/dist/module/module/controller/menu.controller.js.map +1 -1
  30. package/dist/module/module/controller/module-access.controller.d.ts +5 -5
  31. package/dist/module/module/controller/module-access.controller.js +30 -17
  32. package/dist/module/module/controller/module-access.controller.js.map +1 -1
  33. package/dist/module/module/entity/menu.entity.d.ts +1 -0
  34. package/dist/module/module/entity/menu.entity.js +4 -0
  35. package/dist/module/module/entity/menu.entity.js.map +1 -1
  36. package/dist/module/module/entity/module-access.entity.d.ts +1 -1
  37. package/dist/module/module/entity/module-access.entity.js +1 -1
  38. package/dist/module/module/entity/module-access.entity.js.map +1 -1
  39. package/dist/module/module/entity/module.entity.d.ts +1 -0
  40. package/dist/module/module/entity/module.entity.js +4 -0
  41. package/dist/module/module/entity/module.entity.js.map +1 -1
  42. package/dist/module/module/repository/menu.repository.d.ts +3 -3
  43. package/dist/module/module/repository/menu.repository.js +12 -8
  44. package/dist/module/module/repository/menu.repository.js.map +1 -1
  45. package/dist/module/module/repository/module-access.repository.d.ts +10 -6
  46. package/dist/module/module/repository/module-access.repository.js +45 -29
  47. package/dist/module/module/repository/module-access.repository.js.map +1 -1
  48. package/dist/module/module/service/menu.service.d.ts +1 -1
  49. package/dist/module/module/service/menu.service.js +4 -4
  50. package/dist/module/module/service/menu.service.js.map +1 -1
  51. package/dist/module/module/service/module-access.service.d.ts +9 -5
  52. package/dist/module/module/service/module-access.service.js +12 -10
  53. package/dist/module/module/service/module-access.service.js.map +1 -1
  54. package/dist/module/user/dto/create-user.dto.d.ts +1 -0
  55. package/dist/module/user/dto/create-user.dto.js.map +1 -1
  56. package/dist/module/user/entity/role.entity.d.ts +0 -1
  57. package/dist/module/user/entity/role.entity.js +0 -4
  58. package/dist/module/user/entity/role.entity.js.map +1 -1
  59. package/dist/module/user/entity/user-role-mapping.entity.d.ts +1 -0
  60. package/dist/module/user/entity/user-role-mapping.entity.js +4 -0
  61. package/dist/module/user/entity/user-role-mapping.entity.js.map +1 -1
  62. package/dist/module/user/service/role.service.d.ts +1 -1
  63. package/dist/module/user/service/role.service.js +6 -3
  64. package/dist/module/user/service/role.service.js.map +1 -1
  65. package/dist/module/user/service/user.service.d.ts +1 -1
  66. package/dist/module/user/service/user.service.js +4 -1
  67. package/dist/module/user/service/user.service.js.map +1 -1
  68. package/dist/tsconfig.build.tsbuildinfo +1 -1
  69. package/package.json +1 -1
  70. package/src/module/enterprise/entity/enterprise.entity.ts +2 -2
  71. package/src/module/enterprise/entity/organization.entity.ts +2 -2
  72. package/src/module/filter/entity/saved-filter-master.entity.ts +0 -3
  73. package/src/module/master/service/master.service.ts +31 -15
  74. package/src/module/meta/controller/entity.controller.ts +27 -12
  75. package/src/module/meta/entity/entity-table-column.entity.ts +1 -2
  76. package/src/module/meta/entity/entity-table.entity.ts +0 -2
  77. package/src/module/meta/service/entity-list.service.ts +29 -7
  78. package/src/module/meta/service/entity-service-impl.service.ts +29 -17
  79. package/src/module/meta/service/entity.service.ts +2 -1
  80. package/src/module/module/controller/menu.controller.ts +2 -1
  81. package/src/module/module/controller/module-access.controller.ts +49 -22
  82. package/src/module/module/entity/menu.entity.ts +3 -0
  83. package/src/module/module/entity/module-access.entity.ts +1 -1
  84. package/src/module/module/entity/module.entity.ts +3 -0
  85. package/src/module/module/repository/menu.repository.ts +48 -43
  86. package/src/module/module/repository/module-access.repository.ts +69 -50
  87. package/src/module/module/service/menu.service.ts +4 -4
  88. package/src/module/module/service/module-access.service.ts +15 -13
  89. package/src/module/user/dto/create-user.dto.ts +1 -0
  90. package/src/module/user/entity/role.entity.ts +0 -3
  91. package/src/module/user/entity/user-role-mapping.entity.ts +3 -0
  92. package/src/module/user/service/role.service.ts +7 -3
  93. package/src/module/user/service/user.service.ts +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -29,8 +29,8 @@ export class EnterpriseData {
29
29
  @Column({ name: 'modified_date', type: 'datetime', nullable: true })
30
30
  modified_date: Date;
31
31
 
32
- @Column({ name: 'app_code', type: 'varchar', nullable: true, length: 50 })
33
- app_code: string;
32
+ @Column({ name: 'appcode', type: 'varchar', nullable: true, length: 50 })
33
+ appcode: string;
34
34
 
35
35
  @Column({ name: 'app_url_name', type: 'varchar', nullable: true, length: 50 })
36
36
  app_url_name: string;
@@ -11,8 +11,8 @@ export class OrganizationData {
11
11
  @Column({ name: 'code', nullable: true })
12
12
  code: string;
13
13
 
14
- @Column({ name: 'app_code', nullable: true })
15
- appCode: string;
14
+ @Column({ name: 'appcode', nullable: true })
15
+ appcode: string;
16
16
 
17
17
  @Column({ name: 'name', nullable: true })
18
18
  name: string;
@@ -9,9 +9,6 @@ export class SavedFilterMaster extends BaseEntity {
9
9
  this.entity_type = ENTITYTYPE_SAVEDFILTERMASTER;
10
10
  }
11
11
 
12
- @Column({ length: 50, type: 'varchar', nullable: true })
13
- app_code: string;
14
-
15
12
  @Column({ length: 50, type: 'varchar', nullable: true })
16
13
  mapped_entity_type: string;
17
14
 
@@ -257,17 +257,27 @@ export class MasterService {
257
257
  continue;
258
258
  }
259
259
 
260
+ const existingError = errors.find((e) => e.row === i + 1);
261
+
260
262
  if (refData[0].organization_id !== loggedInUser.organization_id) {
261
- errors.push({
262
- row: i + 1,
263
- errors: [
264
- {
265
- field: attr.name,
266
- message: `Reference entity with code ${row[attr.attribute_key]} does not belong to the organization`,
267
- },
268
- ],
269
- });
270
- continue;
263
+ if (existingError) {
264
+ existingError.errors.push({
265
+ field: attr.name,
266
+ message: `Reference entity not found for code: ${row[attr.attribute_key]} does not belong to the organization`,
267
+ });
268
+ continue;
269
+ } else {
270
+ errors.push({
271
+ row: i + 1,
272
+ errors: [
273
+ {
274
+ field: attr.name,
275
+ message: `Reference entity with code ${row[attr.attribute_key]} does not belong to the organization`,
276
+ },
277
+ ],
278
+ });
279
+ continue;
280
+ }
271
281
  }
272
282
 
273
283
  row[attr.attribute_key] = refData[0].id;
@@ -407,11 +417,17 @@ export class MasterService {
407
417
  entityMaster,
408
418
  );
409
419
 
420
+ const existingError = errors.find((e) => e.row === i + 1);
421
+
410
422
  if (rowErrors?.length > 0) {
411
- errors.push({
412
- row: i + 1,
413
- errors: rowErrors,
414
- });
423
+ if (existingError) {
424
+ existingError.errors.push(...rowErrors);
425
+ } else {
426
+ errors.push({
427
+ row: i + 1,
428
+ errors: rowErrors,
429
+ });
430
+ }
415
431
  }
416
432
  }
417
433
 
@@ -419,7 +435,7 @@ export class MasterService {
419
435
  throw new BadRequestException({
420
436
  status: false,
421
437
  message: `Validation errors found in the uploaded data.`,
422
- details: errors,
438
+ error: errors,
423
439
  });
424
440
  }
425
441
 
@@ -2,14 +2,17 @@ import {
2
2
  BadRequestException,
3
3
  Body,
4
4
  Controller,
5
- Get, HttpCode,
5
+ Get,
6
+ HttpCode,
6
7
  HttpStatus,
7
8
  Param,
8
9
  Post,
9
10
  Query,
10
11
  Res,
11
12
  Req,
12
- UseGuards, Inject,
13
+ UseGuards,
14
+ Inject,
15
+ Request,
13
16
  } from '@nestjs/common';
14
17
  import { EntityServiceImpl } from '../service/entity-service-impl.service';
15
18
  import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
@@ -62,11 +65,11 @@ export class EntityController {
62
65
  @Body() entityData: BaseEntity,
63
66
  @Query('entity_type') entityType: string,
64
67
  @Res() res: Response,
65
- @Req() req: Request & {user: any}
68
+ @Req() req: Request & { user: any },
66
69
  ) {
67
70
  let requestedUser = req.user;
71
+ let appcode = requestedUser.appcode;
68
72
  let loggedInUser = await this.entityService.getEntityData(ENTITYTYPE_USER,requestedUser.userId);
69
-
70
73
  if (!entityType) {
71
74
  throw new BadRequestException(
72
75
  'Query parameter "entity_type" is required',
@@ -83,7 +86,7 @@ export class EntityController {
83
86
  if (entityService) {
84
87
  return res
85
88
  .status(HttpStatus.OK)
86
- .json(await entityService.createEntity(entityData, loggedInUser as UserData));
89
+ .json(await entityService.createEntity(entityData, loggedInUser as UserData,null,appcode));
87
90
  }
88
91
  }
89
92
 
@@ -93,10 +96,13 @@ export class EntityController {
93
96
  @Body() entityData: BaseEntity,
94
97
  @Query('entity_type') entityType: string,
95
98
  @Res() response: Response,
96
- @Req() req: Request & {user: any}
99
+ @Req() req: Request & { user: any },
97
100
  ) {
98
101
  let requestedUser = req.user;
99
- let loggedInUser = await this.entityService.getEntityData(ENTITYTYPE_USER,requestedUser.userId);
102
+ let loggedInUser = await this.entityService.getEntityData(
103
+ ENTITYTYPE_USER,
104
+ requestedUser.userId,
105
+ );
100
106
  if (!entityType) {
101
107
  throw new BadRequestException(
102
108
  'Query parameter "entity_type" is required',
@@ -117,7 +123,10 @@ export class EntityController {
117
123
  }
118
124
  // let mergeEntity = JsonUtil.merge(existingEntity, entityData);
119
125
 
120
- entityData = await entityService.updateEntity(entityData, loggedInUser as UserData);
126
+ entityData = await entityService.updateEntity(
127
+ entityData,
128
+ loggedInUser as UserData,
129
+ );
121
130
  return response.status(HttpStatus.OK).json(entityData);
122
131
  }
123
132
  }
@@ -127,6 +136,7 @@ export class EntityController {
127
136
  @Param('entity_type') entityType: string,
128
137
  @Query('list_type') listType: string,
129
138
  @Res() res: Response,
139
+ @Request() req,
130
140
  @Body() filters: Record<string, any> = {},
131
141
  @Query('sort_column') sortColumn?: string,
132
142
  @Query('sort_order') sortOrder?: string,
@@ -135,6 +145,8 @@ export class EntityController {
135
145
  @Query('tab_column') tabColumn?: string,
136
146
  @Query('tab_value') tabValue?: string,
137
147
  ) {
148
+ const appcode = req.user.appcode;
149
+
138
150
  return res
139
151
  .status(HttpStatus.OK)
140
152
  .json(
@@ -147,7 +159,8 @@ export class EntityController {
147
159
  page,
148
160
  size,
149
161
  tabColumn,
150
- tabValue
162
+ tabValue,
163
+ appcode,
151
164
  ),
152
165
  );
153
166
  }
@@ -164,13 +177,12 @@ export class EntityController {
164
177
  @Res() res: Response, // Express Response for file handling
165
178
  ) {
166
179
  try {
167
-
168
180
  const filePath = await this.entityService.generateExcelReport(
169
181
  entityType,
170
182
  filterCriteria,
171
183
  listEntityType,
172
184
  displayType,
173
- sampleExport
185
+ sampleExport,
174
186
  );
175
187
 
176
188
  if (!filePath || !fs.existsSync(filePath)) {
@@ -181,7 +193,10 @@ export class EntityController {
181
193
  'Content-Disposition',
182
194
  `attachment; filename=${path.basename(filePath)}`,
183
195
  );
184
- res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
196
+ res.setHeader(
197
+ 'Content-Type',
198
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
199
+ );
185
200
 
186
201
  const fileStream = fs.createReadStream(filePath);
187
202
  fileStream.pipe(res);
@@ -9,8 +9,7 @@ export class EntityTableColumn extends BaseEntity {
9
9
  this.entity_type = ENTITYTYPE_ENTITYTABLECOLUMN;
10
10
  }
11
11
 
12
- @Column({ name: 'app_code', nullable: true })
13
- app_code: string;
12
+
14
13
 
15
14
  @Column({ name: 'mapped_entity_type', nullable: true })
16
15
  mapped_entity_type: string;
@@ -9,8 +9,6 @@ export class EntityTable extends BaseEntity {
9
9
  this.entity_type = ENTITYTYPE_ENTITYTABLE;
10
10
  }
11
11
 
12
- @Column({ name: 'app_code', nullable: true })
13
- app_code: string;
14
12
 
15
13
  @Column({ name: 'mapped_entity_type', nullable: true })
16
14
  mapped_entity_type: string;
@@ -25,6 +25,7 @@ export class EntityListService {
25
25
  pageSize: number,
26
26
  tabColumn?: string,
27
27
  tabValue?: string,
28
+ appcode?: string,
28
29
  ): Promise<EntityListData> {
29
30
  let entityListData = new EntityListData();
30
31
 
@@ -35,7 +36,11 @@ export class EntityListService {
35
36
 
36
37
  if (entityTable) {
37
38
  if (1 != entityTable.is_proc) {
38
- let totalCount = await this.getTotalCount(entityTable, filters);
39
+ let totalCount = await this.getTotalCount(
40
+ entityTable,
41
+ filters,
42
+ appcode,
43
+ );
39
44
  entityListData.entity_tabs = totalCount as EntityTab[];
40
45
 
41
46
  if (tabColumn && tabValue) {
@@ -48,6 +53,7 @@ export class EntityListService {
48
53
  sortOrder,
49
54
  pageNumber,
50
55
  pageSize,
56
+ appcode,
51
57
  );
52
58
  }
53
59
  }
@@ -62,7 +68,13 @@ export class EntityListService {
62
68
  sortOrder: string | undefined,
63
69
  pageNumber: number | undefined,
64
70
  pageSize: number | undefined,
71
+ appcode?: string,
65
72
  ) {
73
+ // Add appcode to filters if provided
74
+ if (appcode) {
75
+ filters = { ...filters, appcode };
76
+ }
77
+
66
78
  let query = this.getQuery(entityTable.data_source, null);
67
79
  let whereClause = await this.getWhereClause(entityTable, filters);
68
80
  if (whereClause.query) {
@@ -80,31 +92,31 @@ export class EntityListService {
80
92
  private async getTotalCount(
81
93
  entityTable: EntityTable,
82
94
  filters: Record<string, any>,
95
+ appcode?: string,
83
96
  ) {
84
97
  let query = this.getQuery(entityTable.data_source, entityTable.tab_column);
85
- let whereClause = await this.getWhereClause(entityTable, filters);
98
+ let whereClause = await this.getWhereClause(entityTable, filters, appcode);
86
99
  if (whereClause.query) {
87
100
  query += whereClause.query;
88
101
  }
89
102
  query += ' GROUP BY ' + entityTable.tab_column;
90
-
103
+
91
104
  let tabs = await this.entityManager.query(query, whereClause.argumentList);
92
-
105
+
93
106
  let all = 0;
94
107
  for (const i in tabs) {
95
108
  let tab = tabs[i] as EntityTab;
96
109
  tab.tab_value = String(tab.tab_value).toUpperCase(); // Capitalize tab_value
97
110
  all += parseInt(String(tab.tab_value_count));
98
111
  }
99
-
112
+
100
113
  let entityTab = new EntityTab();
101
114
  entityTab.tab_value = 'ALL';
102
115
  entityTab.tab_value_count = all;
103
116
  tabs.push(entityTab);
104
-
117
+
105
118
  return tabs.reverse();
106
119
  }
107
-
108
120
 
109
121
  private getQuery(source: string, groupByColumn: string | null) {
110
122
  if (groupByColumn) {
@@ -119,6 +131,7 @@ export class EntityListService {
119
131
  private async getWhereClause(
120
132
  entityTable: EntityTable,
121
133
  filterCriteria?: Record<string, any>,
134
+ appcode?: string,
122
135
  ) {
123
136
  let query = ' WHERE 1=1 ';
124
137
  const argsObjectList: any[] = [];
@@ -155,6 +168,15 @@ export class EntityListService {
155
168
  }
156
169
  }
157
170
 
171
+ // Explicitly check for appcode if provided
172
+ if (appcode) {
173
+ query += ` AND appcode = ?`;
174
+ argsObjectList.push(appcode);
175
+ } else if (filterCriteria && filterCriteria.appcode) {
176
+ query += ` AND appcode = ?`;
177
+ argsObjectList.push(filterCriteria.appcode);
178
+ }
179
+
158
180
  return { query, argumentList: argsObjectList };
159
181
  }
160
182
 
@@ -28,13 +28,13 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
28
28
  @Inject() protected readonly entityListService: EntityListService;
29
29
  @Inject() protected readonly loggingService: LoggingService;
30
30
  @Inject()
31
- protected readonly entityValidationService: EntityValidationService;
32
-
31
+ protected readonly entityValidationService: EntityValidationService;
33
32
 
34
33
  async createEntity(
35
34
  entityData: BaseEntity,
36
35
  loggedInUser: UserData | null,
37
- manager?: EntityManager,
36
+ manager?: EntityManager | null,
37
+ appcode?: string,
38
38
  ){
39
39
  if (!entityData.entity_type) {
40
40
  throw new BadRequestException(`EntityType is missing`);
@@ -43,14 +43,16 @@ protected readonly entityValidationService: EntityValidationService;
43
43
  entityData.entity_type,
44
44
  );
45
45
 
46
- const validationErrors = await this.entityValidationService.validateEntityData(entityData,entityMaster);
46
+ const validationErrors =
47
+ await this.entityValidationService.validateEntityData(
48
+ entityData,
49
+ entityMaster,
50
+ );
47
51
  if (validationErrors.length > 0) {
48
-
49
- return {
52
+ return {
50
53
  success: false,
51
54
  errors: validationErrors,
52
55
  };
53
-
54
56
  }
55
57
 
56
58
  const repo = manager
@@ -127,24 +129,32 @@ protected readonly entityValidationService: EntityValidationService;
127
129
  return await repoService.findOne({ where: { id: id } });
128
130
  }
129
131
 
130
- async getEntityList(entityType: string, filters: Record<string, any> = {}): Promise<BaseEntity[]> {
132
+ async getEntityList(
133
+ entityType: string,
134
+ filters: Record<string, any> = {},
135
+ ): Promise<BaseEntity[]> {
131
136
  const entityData = await this.entityMasterService.getEntityData(entityType);
132
- const repoService = this.reflectionHelper.getRepoService(entityData.entity_data_class);
133
-
137
+ const repoService = this.reflectionHelper.getRepoService(
138
+ entityData.entity_data_class,
139
+ );
140
+
134
141
  if (!repoService) {
135
- throw new Error(`Repository service not found for entityType: ${entityType}`);
142
+ throw new Error(
143
+ `Repository service not found for entityType: ${entityType}`,
144
+ );
136
145
  }
137
-
146
+
138
147
  const result = await repoService.find({
139
148
  where: filters,
140
149
  });
141
-
150
+
142
151
  return result;
143
152
  }
144
-
153
+
145
154
  async updateEntity(
146
155
  entityData: BaseEntity,
147
156
  loggedInUser: UserData | null,
157
+ appcode?: string,
148
158
  ): Promise<BaseEntity> {
149
159
  const entityMaster = await this.entityMasterService.getEntityData(
150
160
  entityData.entity_type,
@@ -181,6 +191,7 @@ protected readonly entityValidationService: EntityValidationService;
181
191
  pageSize: number,
182
192
  tabColumn?: string,
183
193
  tabValue?: string,
194
+ appcode?: string,
184
195
  ): Promise<EntityListData> {
185
196
  return await this.entityListService.getFilterDataWithTabs(
186
197
  entityType,
@@ -191,7 +202,8 @@ protected readonly entityValidationService: EntityValidationService;
191
202
  pageNumber,
192
203
  pageSize,
193
204
  tabColumn,
194
- tabValue
205
+ tabValue,
206
+ appcode,
195
207
  );
196
208
  }
197
209
 
@@ -211,7 +223,7 @@ protected readonly entityValidationService: EntityValidationService;
211
223
  filterCriteria,
212
224
  listEntityType,
213
225
  displayType,
214
- sampleExport
226
+ sampleExport,
215
227
  );
216
228
 
217
229
  const modifiedDate = new Date().toISOString().replace(/[-T:.Z]/g, '');
@@ -261,7 +273,7 @@ protected readonly entityValidationService: EntityValidationService;
261
273
  );
262
274
 
263
275
  let filteredList: any[] = [];
264
- if(!sampleExport) {
276
+ if (!sampleExport) {
265
277
  filteredList = await this.entityListService.getFilteredList(
266
278
  entityTable,
267
279
  filterCriteria,
@@ -8,6 +8,7 @@ export interface EntityService<T extends BaseEntity> {
8
8
  entityData: T,
9
9
  loggedInUser: UserData,
10
10
  manager?: EntityManager,
11
+ appcode?: string,
11
12
  ): Promise<BaseEntity>;
12
13
 
13
14
  getEntityData(
@@ -17,7 +18,7 @@ export interface EntityService<T extends BaseEntity> {
17
18
 
18
19
  getEntityList(entityType: string): Promise<BaseEntity[]>;
19
20
 
20
- updateEntity(entityData: T, loggedInUserData: UserData): Promise<BaseEntity>;
21
+ updateEntity(entityData: T, loggedInUserData: UserData,app_code?:string): Promise<BaseEntity>;
21
22
 
22
23
  deleteEntity(
23
24
  entityType: string,
@@ -10,6 +10,7 @@ export class MenuController {
10
10
  @Get()
11
11
  async getMenu(@Request() req) {
12
12
  const userId = req.user.userId;
13
- return this.menuService.getUserMenu(userId);
13
+ const appcode = req.user.appcode;
14
+ return this.menuService.getUserMenu(userId,appcode);
14
15
  }
15
16
  }
@@ -1,4 +1,16 @@
1
- import { BadRequestException, Body, Controller, Get, Inject, Param, Post, Query, Req, Request, UseGuards } from '@nestjs/common';
1
+ import {
2
+ BadRequestException,
3
+ Body,
4
+ Controller,
5
+ Get,
6
+ Inject,
7
+ Param,
8
+ Post,
9
+ Query,
10
+ Req,
11
+ Request,
12
+ UseGuards,
13
+ } from '@nestjs/common';
2
14
  import { ModuleAccessService } from '../service/module-access.service';
3
15
  import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
4
16
  import { ENTITYTYPE_USER } from '../../../constant/global.constant';
@@ -9,52 +21,67 @@ import { MenuRepository } from '../repository/menu.repository';
9
21
  @Controller('module-access')
10
22
  @UseGuards(JwtAuthGuard)
11
23
  export class ModuleAccessController {
12
- constructor(private readonly moduleAccessService: ModuleAccessService,
13
- private readonly menuRepository: MenuRepository
24
+ constructor(
25
+ private readonly moduleAccessService: ModuleAccessService,
26
+ private readonly menuRepository: MenuRepository,
14
27
  ) {}
15
28
 
16
29
  @Get('roles')
17
- async getRoles() {
18
- return this.moduleAccessService.getRoles();
30
+ async getRoles(@Request() req) {
31
+ const appcode = req.user.appcode;
32
+ return this.moduleAccessService.getRoles({ appcode });
19
33
  }
20
34
 
21
35
  @Get('modules')
22
- async getModules() {
23
- return this.moduleAccessService.getModules();
36
+ async getModules(@Request() req) {
37
+ const appcode = req.user.appcode;
38
+
39
+ return this.moduleAccessService.getModules({
40
+ appcode,
41
+ });
24
42
  }
25
43
 
26
44
  @Get('access-listing')
27
- async getAccessListing(@Query('roles') roleIds: string) {
45
+ async getAccessListing(@Query('roles') roleIds: string, @Request() req) {
28
46
  const roleIdArray = roleIds.split(',').map(Number);
29
- return this.moduleAccessService.getAccessListing(roleIdArray);
47
+ const appcode = req.user.appcode;
48
+ return this.moduleAccessService.getAccessListing(roleIdArray, appcode);
30
49
  }
31
50
 
32
51
  @Get('menu-listing')
33
- async getMenuListing(@Query('mainmod') mainModIds: string) {
52
+ async getMenuListing(@Query('mainmod') mainModIds: string, @Request() req) {
34
53
  const mainModArray = mainModIds.split(',').map(String);
35
- return this.moduleAccessService.getMenuListing(mainModArray);
54
+ const appcode = req.user.appcode;
55
+ return this.moduleAccessService.getMenuListing(mainModArray, appcode);
36
56
  }
37
57
 
38
58
  @Post('update')
39
- async updateModuleAccess(@Body() moduleAccessData: any[]) {
40
- return this.moduleAccessService.updateModuleAccess(moduleAccessData);
59
+ async updateModuleAccess(@Body() moduleAccessData: any[], @Request() req) {
60
+ const appcode = req.user.appcode;
61
+ return this.moduleAccessService.updateModuleAccess(
62
+ moduleAccessData,
63
+ appcode,
64
+ );
41
65
  }
42
66
 
43
67
  // src/module/module-access/controller/module-access.controller.ts
44
68
 
45
69
  @Get('ui-config')
46
- async getModuleUIConfig(@Query('module_code') moduleCode: string, @Request() req) {
70
+ async getModuleUIConfig(
71
+ @Query('module_code') moduleCode: string,
72
+ @Request() req,
73
+ ) {
47
74
  const userId = req.user.userId;
48
-
49
- const roles = await this.menuRepository.getUserRoles(userId); // returns ['1', '4']
50
-
75
+ const appcode = req.user.appcode;
76
+ const roles = await this.menuRepository.getUserRoles(userId, appcode); // returns ['1', '4']
77
+
51
78
  if (!roles || roles.length === 0) {
52
79
  throw new BadRequestException('User has no roles');
53
80
  }
54
-
55
- return this.moduleAccessService.getModuleUIConfig(moduleCode, roles.map(id => Number(id)));
56
- }
57
-
58
-
59
81
 
82
+ return this.moduleAccessService.getModuleUIConfig(
83
+ moduleCode,
84
+ roles.map((id) => Number(id)),
85
+ );
86
+ }
60
87
  }
@@ -34,4 +34,7 @@ export class MenuData {
34
34
 
35
35
  @Column({ type: 'int', nullable: true })
36
36
  ui_visible: number;
37
+
38
+ @Column({ type: 'varchar', nullable: true })
39
+ appcode: string;
37
40
  }
@@ -18,5 +18,5 @@ export class ModuleAccess {
18
18
  action_type: string;
19
19
 
20
20
  @Column({type: 'varchar', length: 100, nullable: true})
21
- app_code: string;
21
+ appcode: string;
22
22
  }
@@ -40,4 +40,7 @@ export class ModuleData {
40
40
 
41
41
  @Column({ type: 'json', nullable: true })
42
42
  ui_config: JSON;
43
+
44
+ @Column({ type: 'varchar', length: 100, nullable: true })
45
+ appcode: string;
43
46
  }