rez_core 2.1.88 → 2.1.90

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 (28) hide show
  1. package/dist/module/filter/dto/filter-request.dto.d.ts +2 -7
  2. package/dist/module/filter/service/filter.service.js +0 -2
  3. package/dist/module/filter/service/filter.service.js.map +1 -1
  4. package/dist/module/meta/controller/entity.controller.d.ts +3 -1
  5. package/dist/module/meta/controller/entity.controller.js +5 -3
  6. package/dist/module/meta/controller/entity.controller.js.map +1 -1
  7. package/dist/module/meta/repository/entity-table.repository.d.ts +1 -1
  8. package/dist/module/meta/repository/entity-table.repository.js +2 -4
  9. package/dist/module/meta/repository/entity-table.repository.js.map +1 -1
  10. package/dist/module/meta/service/entity-service-impl.service.d.ts +1 -1
  11. package/dist/module/meta/service/entity-service-impl.service.js +4 -4
  12. package/dist/module/meta/service/entity-service-impl.service.js.map +1 -1
  13. package/dist/module/meta/service/entity-table.service.d.ts +1 -1
  14. package/dist/module/meta/service/entity-table.service.js +2 -2
  15. package/dist/module/meta/service/entity-table.service.js.map +1 -1
  16. package/dist/module/meta/service/entity.service.d.ts +1 -1
  17. package/dist/module/meta/service/populate-meta.service.js +43 -10
  18. package/dist/module/meta/service/populate-meta.service.js.map +1 -1
  19. package/dist/tsconfig.build.tsbuildinfo +1 -1
  20. package/package.json +1 -1
  21. package/src/module/filter/dto/filter-request.dto.ts +3 -7
  22. package/src/module/filter/service/filter.service.ts +0 -3
  23. package/src/module/meta/controller/entity.controller.ts +4 -0
  24. package/src/module/meta/repository/entity-table.repository.ts +2 -4
  25. package/src/module/meta/service/entity-service-impl.service.ts +4 -0
  26. package/src/module/meta/service/entity-table.service.ts +2 -2
  27. package/src/module/meta/service/entity.service.ts +1 -0
  28. package/src/module/meta/service/populate-meta.service.ts +108 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.88",
3
+ "version": "2.1.90",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -1,3 +1,5 @@
1
+ import { UserData } from 'src/module/user/entity/user.entity';
2
+
1
3
  // src/module/filter/dto/filter-request.dto.ts
2
4
  export interface FilterCondition {
3
5
  filter_attribute: string;
@@ -23,11 +25,5 @@ export interface FilterRequestDto {
23
25
  tabs?: TabsConfig;
24
26
  page?: number;
25
27
  size?: number;
26
- loggedInUser?: {
27
- id: string;
28
- level_type: string;
29
- level_id: string;
30
- appcode: string;
31
- organization_id?: number; // Optional, if applicable
32
- };
28
+ loggedInUser: UserData;
33
29
  }
@@ -153,9 +153,6 @@ export class FilterService {
153
153
  });
154
154
  }
155
155
 
156
- if (user_id === '1') {
157
- }
158
-
159
156
  // if (!this.skipAppCodeFilterEntities.includes(entity_type)) {
160
157
  // baseWhere.push({
161
158
  // query: 'e.appcode = :appcode',
@@ -246,14 +246,18 @@ export class EntityController {
246
246
  @Query('sample_export') sampleExport: boolean,
247
247
  @Query() filterCriteria: Record<string, any>,
248
248
  @Res() res: Response, // Express Response for file handling
249
+ @Req() req: Request & { user: any },
249
250
  ) {
250
251
  try {
252
+ const loggedInUser = req.user.userData;
253
+
251
254
  const filePath = await this.entityService.generateExcelReport(
252
255
  entityType,
253
256
  filterCriteria,
254
257
  listEntityType,
255
258
  displayType,
256
259
  sampleExport,
260
+ loggedInUser,
257
261
  );
258
262
 
259
263
  if (!filePath || !fs.existsSync(filePath)) {
@@ -34,16 +34,14 @@ export class EntityTableRepository {
34
34
  entityType: string,
35
35
  listType: string,
36
36
  displayType: string,
37
- organization_id: number | null = null,
37
+ organization_id: number,
38
38
  ) {
39
39
  const whereCondition: any = {
40
40
  mapped_entity_type: entityType,
41
41
  list_type: listType,
42
42
  display_type: displayType,
43
+ organization_id: organization_id,
43
44
  };
44
- if (organization_id !== null) {
45
- whereCondition.organization_id = organization_id;
46
- }
47
45
 
48
46
  return await this.entityTableRepository.findOne({
49
47
  where: {
@@ -282,6 +282,7 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
282
282
  listEntityType: string,
283
283
  displayType: string,
284
284
  sampleExport: boolean,
285
+ loggedInUser: UserData,
285
286
  ): Promise<string | null> {
286
287
  let fileName: string;
287
288
  try {
@@ -293,6 +294,7 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
293
294
  listEntityType,
294
295
  displayType,
295
296
  sampleExport,
297
+ loggedInUser,
296
298
  );
297
299
 
298
300
  const modifiedDate = new Date().toISOString().replace(/[-T:.Z]/g, '');
@@ -316,12 +318,14 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
316
318
  listEntityType: string,
317
319
  displayType: string,
318
320
  sampleExport: boolean,
321
+ loggedInUser: UserData,
319
322
  ) {
320
323
  const entityTable =
321
324
  await this.entityTableService.findByEntityTypeAndListTypeAndDisplayType(
322
325
  entityType,
323
326
  listEntityType,
324
327
  displayType,
328
+ loggedInUser.organization_id,
325
329
  );
326
330
  const sheet: ExcelsheetData = {
327
331
  sheetName: entityTable?.data_source || 'sheet',
@@ -52,13 +52,13 @@ export class EntityTableService {
52
52
  entityType: string,
53
53
  listType: string,
54
54
  displayType: string,
55
- organization_id: number | null = null,
55
+ organization_id: number,
56
56
  ) {
57
57
  return await this.entityTableRepository.findByEntityTypeAndListTypeAndDisplayType(
58
58
  entityType,
59
59
  listType,
60
60
  displayType,
61
- organization_id ? organization_id : null,
61
+ organization_id,
62
62
  );
63
63
  }
64
64
 
@@ -56,5 +56,6 @@ export interface EntityService<T extends BaseEntity> {
56
56
  listEntityType: string,
57
57
  displayType: string,
58
58
  sampleExport: boolean,
59
+ loggedInUser: UserData,
59
60
  ): Promise<string | null>;
60
61
  }
@@ -9,16 +9,53 @@ export class PopulateMetaService {
9
9
  private readonly entityServiceImpl: EntityServiceImpl,
10
10
  ) {}
11
11
 
12
+ // async populateMetaData(organization_id: number) {
13
+ // // Define metadata tables
14
+ // const metadataTables = [
15
+ // 'cr_entity_master',
16
+ // 'cr_attribute_master',
17
+ // 'cr_entity_table',
18
+ // ];
19
+
20
+ // // Fetch and transform all factory data
21
+ // for (const table of metadataTables) {
22
+ // const factoryData = await this.dataSource.query(
23
+ // `SELECT * FROM ${table} WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1`,
24
+ // );
25
+
26
+ // if (!factoryData.length) continue;
27
+
28
+ // // Clean and transform data for insertion
29
+ // const transformedData = factoryData.map((row) => {
30
+ // const { id, created_date, modified_date, ...rest } = row;
31
+ // return {
32
+ // ...rest,
33
+ // organization_id,
34
+ // level_type: 'ORG',
35
+ // level_id: organization_id,
36
+ // };
37
+ // });
38
+
39
+ // // Perform bulk insert into the same table
40
+ // await this.dataSource
41
+ // .createQueryBuilder()
42
+ // .insert()
43
+ // .into(table)
44
+ // .values(transformedData)
45
+ // .execute();
46
+ // }
47
+
48
+ // return {
49
+ // message: 'Metadata populated successfully',
50
+ // status: 'success',
51
+ // };
52
+ // }
53
+
12
54
  async populateMetaData(organization_id: number) {
13
- // Define metadata tables
14
- const metadataTables = [
15
- 'cr_entity_master',
16
- 'cr_attribute_master',
17
- 'cr_entity_table',
18
- 'cr_entity_table_column',
19
- ];
20
-
21
- // Fetch and transform all factory data
55
+ const metadataTables = ['cr_entity_master', 'cr_attribute_master'];
56
+ const entityTypeToNewIdMap = new Map<string, number>();
57
+
58
+ // Step 1: Insert basic metadata tables
22
59
  for (const table of metadataTables) {
23
60
  const factoryData = await this.dataSource.query(
24
61
  `SELECT * FROM ${table} WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1`,
@@ -26,18 +63,15 @@ export class PopulateMetaService {
26
63
 
27
64
  if (!factoryData.length) continue;
28
65
 
29
- // Clean and transform data for insertion
30
- const transformedData = factoryData.map((row) => {
31
- const { id, created_date, modified_date, ...rest } = row;
32
- return {
66
+ const transformedData = factoryData.map(
67
+ ({ id, created_date, modified_date, ...rest }) => ({
33
68
  ...rest,
34
69
  organization_id,
35
70
  level_type: 'ORG',
36
71
  level_id: organization_id,
37
- };
38
- });
72
+ }),
73
+ );
39
74
 
40
- // Perform bulk insert into the same table
41
75
  await this.dataSource
42
76
  .createQueryBuilder()
43
77
  .insert()
@@ -46,6 +80,64 @@ export class PopulateMetaService {
46
80
  .execute();
47
81
  }
48
82
 
83
+ // Step 2: Insert cr_entity_table and map mapped_entity_type -> new ID
84
+ const factoryEntityData = await this.dataSource.query(
85
+ `SELECT * FROM cr_entity_table WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1`,
86
+ );
87
+
88
+ if (factoryEntityData.length) {
89
+ const transformedEntityData = factoryEntityData.map(
90
+ ({ id, created_date, modified_date, ...rest }) => ({
91
+ ...rest,
92
+ organization_id,
93
+ level_type: 'ORG',
94
+ level_id: organization_id,
95
+ }),
96
+ );
97
+
98
+ const insertResult = await this.dataSource
99
+ .createQueryBuilder()
100
+ .insert()
101
+ .into('cr_entity_table')
102
+ .values(transformedEntityData)
103
+ .execute();
104
+
105
+ // Build mapped_entity_type -> new id mapping
106
+ for (let i = 0; i < factoryEntityData.length; i++) {
107
+ const key = factoryEntityData[i].mapped_entity_type;
108
+ const newId = insertResult.identifiers[i].id;
109
+ entityTypeToNewIdMap.set(key, newId);
110
+ }
111
+ }
112
+
113
+ // Step 3: Insert cr_entity_table_column with parent_id from mapped_entity_type
114
+ const factoryColumnData = await this.dataSource.query(
115
+ `SELECT * FROM cr_entity_table_column WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1`,
116
+ );
117
+
118
+ if (factoryColumnData.length) {
119
+ const transformedColumnData = factoryColumnData.map(
120
+ ({ id, created_date, modified_date, ...rest }) => {
121
+ const mappedEntityType = rest.mapped_entity_type;
122
+ const newParentId = entityTypeToNewIdMap.get(mappedEntityType);
123
+ return {
124
+ ...rest,
125
+ parent_id: newParentId ?? null,
126
+ organization_id,
127
+ level_type: 'ORG',
128
+ level_id: organization_id,
129
+ };
130
+ },
131
+ );
132
+
133
+ await this.dataSource
134
+ .createQueryBuilder()
135
+ .insert()
136
+ .into('cr_entity_table_column')
137
+ .values(transformedColumnData)
138
+ .execute();
139
+ }
140
+
49
141
  return {
50
142
  message: 'Metadata populated successfully',
51
143
  status: 'success',