rez_core 5.0.40 → 5.0.42
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/filter/service/filter.service.js +6 -6
- package/dist/module/filter/service/filter.service.js.map +1 -1
- package/dist/module/meta/repository/attribute-master.repository.js +1 -1
- package/dist/module/meta/repository/attribute-master.repository.js.map +1 -1
- package/dist/module/meta/service/populate-meta.service.d.ts +4 -2
- package/dist/module/meta/service/populate-meta.service.js +97 -36
- package/dist/module/meta/service/populate-meta.service.js.map +1 -1
- package/dist/module/workflow/controller/workflow.controller.d.ts +1 -1
- package/dist/module/workflow/service/populate-workflow.service.d.ts +1 -1
- package/dist/module/workflow/service/populate-workflow.service.js +93 -16
- package/dist/module/workflow/service/populate-workflow.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/filter/service/filter.service.ts +6 -6
- package/src/module/meta/repository/attribute-master.repository.ts +1 -1
- package/src/module/meta/service/populate-meta.service.ts +123 -94
- package/src/module/workflow/service/populate-workflow.service.ts +131 -104
package/package.json
CHANGED
|
@@ -885,8 +885,8 @@ export class FilterService {
|
|
|
885
885
|
}
|
|
886
886
|
|
|
887
887
|
private buildDateCondition(attr: string, op: string, val: any, key: string) {
|
|
888
|
-
const dateColumn = `
|
|
889
|
-
const monthColumn = `
|
|
888
|
+
const dateColumn = `e.${attr}::date`;
|
|
889
|
+
const monthColumn = `date_trunc('month', e.${attr})::date`;
|
|
890
890
|
|
|
891
891
|
const numVal = Number(val);
|
|
892
892
|
|
|
@@ -933,12 +933,12 @@ export class FilterService {
|
|
|
933
933
|
.startOf('month')
|
|
934
934
|
.format('YYYY-MM-DD');
|
|
935
935
|
return {
|
|
936
|
-
query: `${monthColumn} <
|
|
936
|
+
query: `${monthColumn} < date_trunc('month', :${key})::date`,
|
|
937
937
|
params: { [key]: target },
|
|
938
938
|
};
|
|
939
939
|
}
|
|
940
940
|
return {
|
|
941
|
-
query: `${monthColumn} <
|
|
941
|
+
query: `${monthColumn} < date_trunc('month', :${key})::date`,
|
|
942
942
|
params: { [key]: val },
|
|
943
943
|
};
|
|
944
944
|
|
|
@@ -949,12 +949,12 @@ export class FilterService {
|
|
|
949
949
|
.startOf('month')
|
|
950
950
|
.format('YYYY-MM-DD');
|
|
951
951
|
return {
|
|
952
|
-
query: `${monthColumn} >
|
|
952
|
+
query: `${monthColumn} > date_trunc('month', :${key})::date`,
|
|
953
953
|
params: { [key]: target },
|
|
954
954
|
};
|
|
955
955
|
}
|
|
956
956
|
return {
|
|
957
|
-
query: `${monthColumn} >
|
|
957
|
+
query: `${monthColumn} > date_trunc('month', :${key})::date`,
|
|
958
958
|
params: { [key]: val },
|
|
959
959
|
};
|
|
960
960
|
|
|
@@ -35,7 +35,7 @@ export class AttributeMasterRepository {
|
|
|
35
35
|
): Promise<AttributeMaster[]> {
|
|
36
36
|
return await this.attributeMasterRepository.find({
|
|
37
37
|
where: {
|
|
38
|
-
mapped_entity_type:
|
|
38
|
+
mapped_entity_type: entityType,
|
|
39
39
|
organization_id: loggedInUser.organization_id,
|
|
40
40
|
},
|
|
41
41
|
});
|
|
@@ -1,56 +1,16 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
2
|
import { DataSource } from 'typeorm';
|
|
3
3
|
import { EntityServiceImpl } from './entity-service-impl.service';
|
|
4
|
+
import { ReflectionHelper } from 'src/utils/service/reflection-helper.service';
|
|
4
5
|
|
|
5
6
|
@Injectable()
|
|
6
7
|
export class PopulateMetaService {
|
|
7
8
|
constructor(
|
|
8
9
|
private readonly dataSource: DataSource,
|
|
9
10
|
private readonly entityServiceImpl: EntityServiceImpl,
|
|
11
|
+
private readonly reflectionHelper: ReflectionHelper,
|
|
10
12
|
) {}
|
|
11
13
|
|
|
12
|
-
// async populateMetaData(organization_id: number) {
|
|
13
|
-
// // Define metadata tables
|
|
14
|
-
// const metadataTables = [
|
|
15
|
-
// 'frm_entity_master',
|
|
16
|
-
// 'frm_entity_attribute',
|
|
17
|
-
// 'frm_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
|
-
|
|
54
14
|
async populateMetaData(organization_id: number) {
|
|
55
15
|
const metadataTables = [
|
|
56
16
|
'frm_entity_master',
|
|
@@ -58,32 +18,64 @@ export class PopulateMetaService {
|
|
|
58
18
|
'frm_entity_view',
|
|
59
19
|
'frm_entity_relation',
|
|
60
20
|
];
|
|
61
|
-
const entityTypeToNewIdMap = new Map<string, number>();
|
|
62
21
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
22
|
+
const metaData = [
|
|
23
|
+
'EntityMaster',
|
|
24
|
+
'AttributeMaster',
|
|
25
|
+
'ViewMaster',
|
|
26
|
+
'EntityRelationData',
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const listMasterItemsRepo =
|
|
30
|
+
this.reflectionHelper.getRepoService('ListMasterItems');
|
|
31
|
+
const viewMasterRepo = this.reflectionHelper.getRepoService('ViewMaster');
|
|
32
|
+
const relationDataRepo =
|
|
33
|
+
this.reflectionHelper.getRepoService('EntityRelationData');
|
|
34
|
+
const relationRepo = this.reflectionHelper.getRepoService('EntityRelation');
|
|
35
|
+
const attributeMasterRepo =
|
|
36
|
+
this.reflectionHelper.getRepoService('AttributeMaster');
|
|
37
|
+
const entityMasterRepo =
|
|
38
|
+
this.reflectionHelper.getRepoService('EntityMaster');
|
|
39
|
+
|
|
40
|
+
if (!listMasterItemsRepo) return;
|
|
41
|
+
|
|
42
|
+
const getStatus = (await listMasterItemsRepo.find({
|
|
43
|
+
where: { organization_id: organization_id, code: 'STATUS_ACTIVE' },
|
|
44
|
+
})) as any[];
|
|
45
|
+
|
|
46
|
+
let status: any;
|
|
47
|
+
|
|
48
|
+
if (getStatus && getStatus.length > 0) {
|
|
49
|
+
status = getStatus[0].id;
|
|
50
|
+
} else {
|
|
51
|
+
status = 'ACTIVE';
|
|
52
|
+
}
|
|
67
53
|
|
|
68
|
-
let oneToManyId = await
|
|
69
|
-
|
|
70
|
-
)
|
|
54
|
+
let oneToManyId = await listMasterItemsRepo?.find({
|
|
55
|
+
where: { value: 'ONE_TO_MANY', organization_id: organization_id },
|
|
56
|
+
});
|
|
71
57
|
|
|
72
|
-
let oneToOneId = await
|
|
73
|
-
|
|
74
|
-
)
|
|
58
|
+
let oneToOneId = await listMasterItemsRepo?.find({
|
|
59
|
+
where: { value: 'ONE_TO_ONE', organization_id: organization_id },
|
|
60
|
+
});
|
|
75
61
|
|
|
76
62
|
// Step 1: Insert basic metadata tables
|
|
77
63
|
for (const table of metadataTables) {
|
|
78
|
-
const factoryData = await this.dataSource.query(
|
|
79
|
-
`SELECT * FROM ${table} WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1`,
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
if (!factoryData.length) continue;
|
|
83
|
-
|
|
84
64
|
let transformedData;
|
|
85
65
|
|
|
66
|
+
let transformRepo;
|
|
67
|
+
|
|
86
68
|
if (table === 'frm_entity_master') {
|
|
69
|
+
transformRepo = entityMasterRepo;
|
|
70
|
+
|
|
71
|
+
const factoryData = await transformRepo?.find({
|
|
72
|
+
where: {
|
|
73
|
+
organization_id: -1,
|
|
74
|
+
level_type: 'ORG',
|
|
75
|
+
level_id: -1,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
87
79
|
transformedData = factoryData.map(
|
|
88
80
|
({ id, created_date, modified_date, ...rest }) => ({
|
|
89
81
|
...rest,
|
|
@@ -95,31 +87,59 @@ export class PopulateMetaService {
|
|
|
95
87
|
}),
|
|
96
88
|
);
|
|
97
89
|
} else if (table === 'frm_entity_attribute') {
|
|
90
|
+
transformRepo = attributeMasterRepo;
|
|
91
|
+
const factoryData = await transformRepo?.find({
|
|
92
|
+
where: {
|
|
93
|
+
organization_id: -1,
|
|
94
|
+
level_type: 'ORG',
|
|
95
|
+
level_id: -1,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
98
99
|
transformedData = factoryData.map(
|
|
99
100
|
({ id, created_date, modified_date, ...rest }) => ({
|
|
100
101
|
...rest,
|
|
101
102
|
organization_id,
|
|
102
103
|
level_type: 'ORG',
|
|
103
104
|
level_id: organization_id,
|
|
104
|
-
is_unique: rest.is_unique == 1 ? true : false,
|
|
105
|
-
required: rest.required == 1 ? true : false,
|
|
106
|
-
is_hidden: rest.is_hidden == 1 ? true : false,
|
|
105
|
+
// is_unique: rest.is_unique == 1 ? true : false,
|
|
106
|
+
// required: rest.required == 1 ? true : false,
|
|
107
|
+
// is_hidden: rest.is_hidden == 1 ? true : false,
|
|
107
108
|
status: status,
|
|
108
109
|
}),
|
|
109
110
|
);
|
|
110
|
-
}
|
|
111
|
-
|
|
111
|
+
} else if (table === 'frm_entity_relation') {
|
|
112
|
+
if (!oneToManyId || !oneToOneId) continue;
|
|
113
|
+
transformRepo = relationRepo;
|
|
114
|
+
const factoryData = await transformRepo?.find({
|
|
115
|
+
where: {
|
|
116
|
+
organization_id: -1,
|
|
117
|
+
level_type: 'ORG',
|
|
118
|
+
level_id: -1,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
112
121
|
transformedData = factoryData.map(
|
|
113
122
|
({ id, created_date, modified_date, ...rest }) => ({
|
|
114
|
-
|
|
123
|
+
...rest,
|
|
115
124
|
organization_id,
|
|
116
125
|
level_type: 'ORG',
|
|
117
126
|
level_id: organization_id,
|
|
118
127
|
status: status,
|
|
119
|
-
relation_id:
|
|
128
|
+
// relation_id:
|
|
129
|
+
// rest.relation_type == 'ONE_TO_ONE'
|
|
130
|
+
// ? oneToOneId[0].id
|
|
131
|
+
// : oneToManyId[0].id,
|
|
120
132
|
}),
|
|
121
133
|
);
|
|
122
|
-
}else {
|
|
134
|
+
} else if (table === 'frm_entity_view') {
|
|
135
|
+
transformRepo = viewMasterRepo;
|
|
136
|
+
const factoryData = await transformRepo?.find({
|
|
137
|
+
where: {
|
|
138
|
+
organization_id: -1,
|
|
139
|
+
level_type: 'ORG',
|
|
140
|
+
level_id: -1,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
123
143
|
transformedData = factoryData.map(
|
|
124
144
|
({ id, created_date, modified_date, ...rest }) => ({
|
|
125
145
|
...rest,
|
|
@@ -131,17 +151,24 @@ export class PopulateMetaService {
|
|
|
131
151
|
);
|
|
132
152
|
}
|
|
133
153
|
|
|
134
|
-
await
|
|
135
|
-
.createQueryBuilder()
|
|
136
|
-
.insert()
|
|
137
|
-
.into(table)
|
|
138
|
-
.values(transformedData)
|
|
139
|
-
.execute();
|
|
154
|
+
await transformRepo?.save(transformedData);
|
|
140
155
|
}
|
|
141
156
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
);
|
|
157
|
+
// table population for entity tables and entity table columns
|
|
158
|
+
|
|
159
|
+
const entityTableRepo = this.reflectionHelper.getRepoService('EntityTable');
|
|
160
|
+
const entityTableColumnRepo =
|
|
161
|
+
this.reflectionHelper.getRepoService('EntityTableColumn');
|
|
162
|
+
|
|
163
|
+
if (!entityTableRepo || !entityTableColumnRepo) return;
|
|
164
|
+
|
|
165
|
+
const entityTables = await entityTableRepo.find({
|
|
166
|
+
where: {
|
|
167
|
+
organization_id: -1,
|
|
168
|
+
level_type: 'ORG',
|
|
169
|
+
level_id: -1,
|
|
170
|
+
},
|
|
171
|
+
});
|
|
145
172
|
|
|
146
173
|
for (let entityTable of entityTables) {
|
|
147
174
|
const { id, mapped_entity_type, display_type, ...rest } = entityTable;
|
|
@@ -153,18 +180,23 @@ export class PopulateMetaService {
|
|
|
153
180
|
level_id: organization_id,
|
|
154
181
|
display_type: display_type,
|
|
155
182
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
183
|
+
|
|
184
|
+
const insertResult = await entityTableRepo.save(entityTable);
|
|
185
|
+
|
|
186
|
+
const newId = insertResult.id;
|
|
187
|
+
|
|
188
|
+
const entityTableColumns = await entityTableColumnRepo.find({
|
|
189
|
+
where: {
|
|
190
|
+
organization_id: -1,
|
|
191
|
+
level_type: 'ORG',
|
|
192
|
+
level_id: -1,
|
|
193
|
+
mapped_entity_type: mapped_entity_type,
|
|
194
|
+
display_type: display_type,
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
let tableCloumnArray = [] as any[];
|
|
199
|
+
|
|
168
200
|
for (const column of entityTableColumns) {
|
|
169
201
|
const { id, created_date, modified_date, ...columnRest } = column;
|
|
170
202
|
const newColumn = {
|
|
@@ -176,13 +208,10 @@ export class PopulateMetaService {
|
|
|
176
208
|
mapped_entity_type: mapped_entity_type,
|
|
177
209
|
display_type: display_type,
|
|
178
210
|
};
|
|
179
|
-
|
|
180
|
-
.createQueryBuilder()
|
|
181
|
-
.insert()
|
|
182
|
-
.into('frm_entity_table_column')
|
|
183
|
-
.values(newColumn)
|
|
184
|
-
.execute();
|
|
211
|
+
tableCloumnArray.push(newColumn);
|
|
185
212
|
}
|
|
213
|
+
|
|
214
|
+
await entityTableColumnRepo.save(tableCloumnArray);
|
|
186
215
|
}
|
|
187
216
|
|
|
188
217
|
return {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { create } from 'domain';
|
|
2
|
+
import { CommTemplate } from './../entity/comm-template.entity';
|
|
1
3
|
import { ActionCategory } from './../entity/action-category.entity';
|
|
2
4
|
import { DataSource } from 'typeorm';
|
|
3
5
|
import { PopulateMetaService } from './../../meta/service/populate-meta.service';
|
|
@@ -26,79 +28,44 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
26
28
|
super();
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
// async populateWorkflowData(organization_id: number, loggedInUser: UserData) {
|
|
30
|
-
// // Define workflow tables
|
|
31
|
-
// const workflowTables = [
|
|
32
|
-
// { table: 'frm_wf_master', entityType: 'WRFW', service: 'workflowService' },
|
|
33
|
-
// {
|
|
34
|
-
// table: 'frm_wf_stage_group',
|
|
35
|
-
// entityType: 'WFSG',
|
|
36
|
-
// service: 'stageGroupService',
|
|
37
|
-
// },
|
|
38
|
-
// { table: 'frm_wf_stage', entityType: 'WFS', service: 'stageService' },
|
|
39
|
-
// { table: 'frm_wf_action', entityType: 'WFAC', service: 'actionService' },
|
|
40
|
-
// ];
|
|
41
|
-
|
|
42
|
-
// const getAllFactoryData = async (table: { table: string }) => {
|
|
43
|
-
// return this.dataSource.query(
|
|
44
|
-
// `SELECT * FROM ${table.table} WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1`,
|
|
45
|
-
// );
|
|
46
|
-
// };
|
|
47
|
-
|
|
48
|
-
// const factoryData = await Promise.all(
|
|
49
|
-
// workflowTables.map((table) => getAllFactoryData(table)),
|
|
50
|
-
// );
|
|
51
|
-
|
|
52
|
-
// // Step 1: Insert workflow metadata
|
|
53
|
-
// for (let i = 0; i < workflowTables.length; i++) {
|
|
54
|
-
// const table = workflowTables[i];
|
|
55
|
-
// const data = factoryData[i];
|
|
56
|
-
|
|
57
|
-
// if (!data.length) continue;
|
|
58
|
-
|
|
59
|
-
// // Clean and transform data for insertion
|
|
60
|
-
// const transformedData = data.map((row) => {
|
|
61
|
-
// const { id, created_date, modified_date, ...rest } = row;
|
|
62
|
-
// return {
|
|
63
|
-
// ...rest,
|
|
64
|
-
// organization_id: organization_id,
|
|
65
|
-
// level_id: organization_id,
|
|
66
|
-
// entity_type: table.entityType,
|
|
67
|
-
// };
|
|
68
|
-
// });
|
|
69
|
-
|
|
70
|
-
// const service = this[table.service];
|
|
71
|
-
|
|
72
|
-
// for (const record of transformedData) {
|
|
73
|
-
// await service.createEntity(record, loggedInUser);
|
|
74
|
-
// }
|
|
75
|
-
// }
|
|
76
|
-
|
|
77
|
-
// return {
|
|
78
|
-
// message: 'Workflow data populated successfully',
|
|
79
|
-
// status: 'success',
|
|
80
|
-
// };
|
|
81
|
-
// }
|
|
82
|
-
|
|
83
31
|
async populateWorkflowData(organization_id: number, loggedInUser: UserData) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
[organization_id],
|
|
87
|
-
);
|
|
32
|
+
const listMasterItemsRepo =
|
|
33
|
+
this.reflectionHelper.getRepoService('ListMasterItems');
|
|
88
34
|
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
35
|
+
if (!listMasterItemsRepo) return;
|
|
36
|
+
|
|
37
|
+
// let statusRow = await this.dataSource.query(
|
|
38
|
+
// `SELECT * FROM frm_list_master_items WHERE code='STATUS_ACTIVE' AND organization_id = $1`,
|
|
39
|
+
// [organization_id],
|
|
40
|
+
// );
|
|
41
|
+
|
|
42
|
+
let statusRow = await listMasterItemsRepo.findOne({
|
|
43
|
+
where: { code: 'STATUS_ACTIVE', organization_id: organization_id },
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (!statusRow) {
|
|
47
|
+
statusRow = await listMasterItemsRepo.findOne({
|
|
48
|
+
where: { code: 'STATUS_ACTIVE', organization_id: -1 },
|
|
49
|
+
});
|
|
93
50
|
}
|
|
94
51
|
|
|
95
|
-
const statusValue = statusRow
|
|
52
|
+
const statusValue = statusRow?.id;
|
|
96
53
|
|
|
97
54
|
// template populate
|
|
98
55
|
// Step 1: Fetch default frm_wf_comm_template
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
56
|
+
|
|
57
|
+
const commTemplateRepo =
|
|
58
|
+
this.reflectionHelper.getRepoService('CommTemplate');
|
|
59
|
+
|
|
60
|
+
if (!commTemplateRepo) return;
|
|
61
|
+
|
|
62
|
+
const defaultCommTemplates = await commTemplateRepo.find({
|
|
63
|
+
where: {
|
|
64
|
+
organization_id: -1,
|
|
65
|
+
level_type: 'ORG',
|
|
66
|
+
level_id: -1,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
102
69
|
|
|
103
70
|
if (defaultCommTemplates.length > 0) {
|
|
104
71
|
// Step 2: Insert default communication templates for the new organization
|
|
@@ -120,7 +87,11 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
120
87
|
}
|
|
121
88
|
|
|
122
89
|
const workflowTables = [
|
|
123
|
-
{
|
|
90
|
+
{
|
|
91
|
+
table: 'frm_wf_master',
|
|
92
|
+
entityType: 'WRFW',
|
|
93
|
+
service: 'workflowService',
|
|
94
|
+
},
|
|
124
95
|
{
|
|
125
96
|
table: 'frm_wf_stage_group',
|
|
126
97
|
entityType: 'WFSG',
|
|
@@ -130,18 +101,44 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
130
101
|
{ table: 'frm_wf_action', entityType: 'WFAC', service: 'actionService' },
|
|
131
102
|
];
|
|
132
103
|
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
104
|
+
const workFlowRepo = this.reflectionHelper.getRepoService('Workflow');
|
|
105
|
+
const stageGroupRepo = this.reflectionHelper.getRepoService('StageGroup');
|
|
106
|
+
const stageRepo = this.reflectionHelper.getRepoService('Stage');
|
|
107
|
+
const actionRepo = this.reflectionHelper.getRepoService('ActionEntity');
|
|
108
|
+
const stageActionMappingRepo =
|
|
109
|
+
this.reflectionHelper.getRepoService('StageActionMapping');
|
|
110
|
+
const workflowLevelMappingRepo = this.reflectionHelper.getRepoService(
|
|
111
|
+
'WorkflowLevelMappingEntity',
|
|
140
112
|
);
|
|
141
|
-
const
|
|
113
|
+
const listMasterRepo = this.reflectionHelper.getRepoService('ListMaster');
|
|
114
|
+
const actionCategoryRepo =
|
|
115
|
+
this.reflectionHelper.getRepoService('ActionCategory');
|
|
116
|
+
const viewMasterRepo = this.reflectionHelper.getRepoService('ViewMaster');
|
|
117
|
+
|
|
118
|
+
// Fetch all base data
|
|
119
|
+
// const getAllFactoryData = async (table: { table: string }) =>
|
|
120
|
+
// this.dataSource.query(
|
|
121
|
+
// `SELECT * FROM ${table.table} WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1`,
|
|
122
|
+
// );
|
|
123
|
+
// const factoryData = await Promise.all(
|
|
124
|
+
// workflowTables.map(getAllFactoryData),
|
|
125
|
+
// );
|
|
126
|
+
// const [workflows, stageGroups, stages] = factoryData;
|
|
142
127
|
|
|
143
128
|
// === 1. Workflow mapping
|
|
144
129
|
const workflowIdMap: Record<number, number> = {};
|
|
130
|
+
|
|
131
|
+
let transformRepo;
|
|
132
|
+
|
|
133
|
+
transformRepo = workFlowRepo;
|
|
134
|
+
|
|
135
|
+
const workflows = await transformRepo?.find({
|
|
136
|
+
where: {
|
|
137
|
+
organization_id: -1,
|
|
138
|
+
level_type: 'ORG',
|
|
139
|
+
level_id: -1,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
145
142
|
for (const row of workflows) {
|
|
146
143
|
const { id, ...rest } = row;
|
|
147
144
|
const newWf = await this.workflowService.createEntity(
|
|
@@ -156,10 +153,14 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
156
153
|
);
|
|
157
154
|
|
|
158
155
|
// adding new entry for workflow level mapping
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
156
|
+
|
|
157
|
+
if (!workflowLevelMappingRepo) continue;
|
|
158
|
+
|
|
159
|
+
await workflowLevelMappingRepo.create({
|
|
160
|
+
workflow_id: newWf.id,
|
|
161
|
+
mapped_level_id: organization_id.toString(),
|
|
162
|
+
mapped_level_type: 'ORG',
|
|
163
|
+
});
|
|
163
164
|
|
|
164
165
|
workflowIdMap[id] = newWf.id;
|
|
165
166
|
}
|
|
@@ -168,6 +169,17 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
168
169
|
const stageGroupIdMap: Record<number, number> = {};
|
|
169
170
|
// Include mapping from old stageGroupId to old workflowId to help with stage->workflow logic later:
|
|
170
171
|
const stageGroupToWorkflowMap: Record<number, number> = {};
|
|
172
|
+
|
|
173
|
+
transformRepo = stageGroupRepo;
|
|
174
|
+
|
|
175
|
+
const stageGroups = await transformRepo?.find({
|
|
176
|
+
where: {
|
|
177
|
+
organization_id: -1,
|
|
178
|
+
level_type: 'ORG',
|
|
179
|
+
level_id: -1,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
171
183
|
for (const row of stageGroups) {
|
|
172
184
|
const { id, workflow_id, ...rest } = row;
|
|
173
185
|
const newSg = await this.stageGroupService.createEntity(
|
|
@@ -188,6 +200,16 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
188
200
|
// === 3. Stage mapping — point to stageGroup and workflow
|
|
189
201
|
const stageIdMap: Record<number, number> = {};
|
|
190
202
|
const stageToStageGroupMap: Record<number, number> = {};
|
|
203
|
+
|
|
204
|
+
transformRepo = stageRepo;
|
|
205
|
+
const stages = await transformRepo?.find({
|
|
206
|
+
where: {
|
|
207
|
+
organization_id: -1,
|
|
208
|
+
level_type: 'ORG',
|
|
209
|
+
level_id: -1,
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
|
|
191
213
|
for (const row of stages) {
|
|
192
214
|
const { id, stage_group_id, ...rest } = row;
|
|
193
215
|
// Find the original parent workflow_id using the stageGroupToWorkflowMap
|
|
@@ -212,19 +234,21 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
212
234
|
// step 3 create new action with new stage_id and new workflow_id
|
|
213
235
|
// step 4 save new action
|
|
214
236
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
237
|
+
if (!stageActionMappingRepo) continue;
|
|
238
|
+
|
|
239
|
+
const stageIds = await stageActionMappingRepo.find({
|
|
240
|
+
where: {
|
|
241
|
+
stage_id: id,
|
|
242
|
+
},
|
|
243
|
+
});
|
|
219
244
|
|
|
220
245
|
const actionIds = stageIds.map((item) => item.action_id);
|
|
221
246
|
|
|
222
|
-
let actions = [];
|
|
247
|
+
let actions = [] as any[];
|
|
223
248
|
if (actionIds.length > 0) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
);
|
|
249
|
+
if (!actionRepo) continue;
|
|
250
|
+
|
|
251
|
+
actions = await actionRepo?.findByIds(actionIds);
|
|
228
252
|
} else {
|
|
229
253
|
// No actions to query
|
|
230
254
|
actions = [];
|
|
@@ -241,16 +265,16 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
241
265
|
const newWorkflowId = workflowIdMap[workflow_id];
|
|
242
266
|
|
|
243
267
|
// Step 1: Get the code of the old is_mandatory field
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
);
|
|
268
|
+
|
|
269
|
+
const [oldIsMandatory] = await listMasterItemsRepo.find({
|
|
270
|
+
where: { id: rest.action_requirement },
|
|
271
|
+
});
|
|
248
272
|
|
|
249
273
|
// Step 2: Get all new 'ACRQ' list master items for the organization
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
);
|
|
274
|
+
|
|
275
|
+
const newIsMandatoryList = await listMasterItemsRepo.find({
|
|
276
|
+
where: { organization_id: organization_id, listtype: 'ACRQ' },
|
|
277
|
+
});
|
|
254
278
|
|
|
255
279
|
console.log(
|
|
256
280
|
`Populating action for stage ${newStage.id} in workflow ${newWorkflowId}`,
|
|
@@ -266,16 +290,19 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
266
290
|
|
|
267
291
|
console.log(`Matched new mandatory item:`, matchedNewMandatory);
|
|
268
292
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
293
|
+
if (!actionCategoryRepo) continue;
|
|
294
|
+
|
|
295
|
+
const formActionCategory = await actionCategoryRepo.find({
|
|
296
|
+
where: { id: row.action_category, is_form: true },
|
|
297
|
+
});
|
|
273
298
|
|
|
274
299
|
//get view master form
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
300
|
+
|
|
301
|
+
if (!viewMasterRepo) continue;
|
|
302
|
+
|
|
303
|
+
const formViewMaster = await viewMasterRepo.find({
|
|
304
|
+
where: { code: 'LEAD_FORM', organization_id: organization_id },
|
|
305
|
+
});
|
|
279
306
|
|
|
280
307
|
// Step 4: Use the matched new item's id (if found)
|
|
281
308
|
await this.actionService.createEntity(
|