rez_core 2.1.89 → 2.1.91
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/dist/module/meta/entity/entity-table-column.entity.d.ts +1 -0
- package/dist/module/meta/entity/entity-table-column.entity.js +4 -0
- package/dist/module/meta/entity/entity-table-column.entity.js.map +1 -1
- package/dist/module/meta/service/populate-meta.service.js +46 -15
- package/dist/module/meta/service/populate-meta.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/meta/entity/entity-table-column.entity.ts +3 -2
- package/src/module/meta/service/populate-meta.service.ts +96 -16
package/package.json
CHANGED
|
@@ -9,8 +9,6 @@ export class EntityTableColumn extends BaseEntity {
|
|
|
9
9
|
this.entity_type = ENTITYTYPE_ENTITYTABLECOLUMN;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
12
|
@Column({ name: 'mapped_entity_type', nullable: true })
|
|
15
13
|
mapped_entity_type: string;
|
|
16
14
|
|
|
@@ -51,4 +49,7 @@ export class EntityTableColumn extends BaseEntity {
|
|
|
51
49
|
|
|
52
50
|
@Column({ name: 'visible', nullable: true })
|
|
53
51
|
visible: string;
|
|
52
|
+
|
|
53
|
+
@Column({ nullable: true })
|
|
54
|
+
display_type: string;
|
|
54
55
|
}
|
|
@@ -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
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
30
|
-
|
|
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,52 @@ export class PopulateMetaService {
|
|
|
46
80
|
.execute();
|
|
47
81
|
}
|
|
48
82
|
|
|
83
|
+
const entityTables = await this.dataSource.query(
|
|
84
|
+
`SELECT * FROM cr_entity_table WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1`,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
for (let entityTable of entityTables) {
|
|
88
|
+
const { id, mapped_entity_type, display_type, ...rest } = entityTable;
|
|
89
|
+
entityTable = {
|
|
90
|
+
...rest,
|
|
91
|
+
organization_id,
|
|
92
|
+
mapped_entity_type: mapped_entity_type,
|
|
93
|
+
level_type: 'ORG',
|
|
94
|
+
level_id: organization_id,
|
|
95
|
+
display_type: display_type,
|
|
96
|
+
};
|
|
97
|
+
const insertResult = await this.dataSource
|
|
98
|
+
.createQueryBuilder()
|
|
99
|
+
.insert()
|
|
100
|
+
.into('cr_entity_table')
|
|
101
|
+
.values(entityTable)
|
|
102
|
+
.execute();
|
|
103
|
+
|
|
104
|
+
const newId = insertResult.identifiers[0].id; // or insertResult.raw.insertId if needed
|
|
105
|
+
|
|
106
|
+
const entityTableColumns = await this.dataSource.query(
|
|
107
|
+
`SELECT * FROM cr_entity_table_column WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1 AND mapped_entity_type = '${mapped_entity_type}' AND display_type = '${display_type}'`,
|
|
108
|
+
);
|
|
109
|
+
for (const column of entityTableColumns) {
|
|
110
|
+
const { id, created_date, modified_date, ...columnRest } = column;
|
|
111
|
+
const newColumn = {
|
|
112
|
+
...columnRest,
|
|
113
|
+
organization_id,
|
|
114
|
+
parent_id: newId,
|
|
115
|
+
level_type: 'ORG',
|
|
116
|
+
level_id: organization_id,
|
|
117
|
+
mapped_entity_type: mapped_entity_type,
|
|
118
|
+
display_type: display_type,
|
|
119
|
+
};
|
|
120
|
+
await this.dataSource
|
|
121
|
+
.createQueryBuilder()
|
|
122
|
+
.insert()
|
|
123
|
+
.into('cr_entity_table_column')
|
|
124
|
+
.values(newColumn)
|
|
125
|
+
.execute();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
49
129
|
return {
|
|
50
130
|
message: 'Metadata populated successfully',
|
|
51
131
|
status: 'success',
|