rez_core 1.0.83 → 1.0.85
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/layout/entity/header-items.entity.d.ts +1 -1
- package/dist/module/layout/entity/header-items.entity.js +1 -1
- package/dist/module/layout/entity/header-items.entity.js.map +1 -1
- package/dist/module/master/service/master.service.d.ts +0 -1
- package/dist/module/master/service/master.service.js +60 -8
- package/dist/module/master/service/master.service.js.map +1 -1
- package/dist/resources/properties.yaml.js +1 -1
- package/dist/resources/properties.yaml.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/layout/entity/header-items.entity.ts +1 -1
- package/src/module/master/service/master.service.ts +115 -42
- package/src/resources/dev.properties.yaml +3 -2
- package/src/resources/properties.yaml.ts +5 -5
- package/src/resources/uat.properties.yaml +2 -2
package/package.json
CHANGED
|
@@ -14,8 +14,8 @@ export class MasterService {
|
|
|
14
14
|
private readonly entityMasterService: EntityMasterService,
|
|
15
15
|
private readonly attributeMasterService: AttributeMasterService,
|
|
16
16
|
private readonly excelUtil: ExcelUtil,
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
private reflectionHelper: ReflectionHelper,
|
|
18
|
+
|
|
19
19
|
private readonly entityServiceImpl: EntityServiceImpl,
|
|
20
20
|
) {}
|
|
21
21
|
|
|
@@ -24,6 +24,9 @@ export class MasterService {
|
|
|
24
24
|
'cr_attribute_master',
|
|
25
25
|
'cr_list_master',
|
|
26
26
|
'cr_list_master_items',
|
|
27
|
+
'cr_entity_table',
|
|
28
|
+
'cr_entity_table_column',
|
|
29
|
+
'cr_view_master',
|
|
27
30
|
];
|
|
28
31
|
private readonly sequence = [
|
|
29
32
|
{
|
|
@@ -42,6 +45,58 @@ export class MasterService {
|
|
|
42
45
|
table: 'cr_list_master_items',
|
|
43
46
|
unique_fields: ['listtype', 'code'],
|
|
44
47
|
},
|
|
48
|
+
{
|
|
49
|
+
table: 'cr_entity_table',
|
|
50
|
+
unique_fields: ['list_type', 'mapped_entity_type'],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
table: 'cr_entity_table_column',
|
|
54
|
+
unique_fields: ['parent_id', 'parent_type', 'attribute_key'],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
table: 'cr_view_master',
|
|
58
|
+
unique_fields: ['mapped_entity_type'],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
table: 'cr_user',
|
|
62
|
+
unique_fields: ['email_id', 'mobile', 'code'],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
table: 'cr_header_items',
|
|
66
|
+
unique_fields: ['code', 'section_id'],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
table: 'cr_module_access',
|
|
70
|
+
unique_fields: ['module_code', 'action_type', 'role_code'],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
table: 'cr_module_action',
|
|
74
|
+
unique_fields: ['module_code', 'action_type'],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
table: 'cr_menu',
|
|
78
|
+
unique_fields: ['module_code'],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
table: 'cr_module',
|
|
82
|
+
unique_fields: ['module_code'],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
table: 'cr_role',
|
|
86
|
+
unique_fields: ['code'],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
table: 'cr_header_sections',
|
|
90
|
+
unique_fields: ['section_name'],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
table: 'cr_user_role_mapping',
|
|
94
|
+
unique_fields: ['user_id', 'role_id'],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
table: 'cr_organization',
|
|
98
|
+
unique_fields: ['code'],
|
|
99
|
+
},
|
|
45
100
|
];
|
|
46
101
|
private readonly dataSequence = [
|
|
47
102
|
{
|
|
@@ -77,10 +132,8 @@ export class MasterService {
|
|
|
77
132
|
console.log(`Sheet ${table} not found in the Excel file.`);
|
|
78
133
|
continue;
|
|
79
134
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
await this.upsertData(table, unique_fields, sheetData);
|
|
83
|
-
}
|
|
135
|
+
console.log(`Processing sheet: ${table}`);
|
|
136
|
+
await this.upsertData(table, unique_fields, sheetData);
|
|
84
137
|
}
|
|
85
138
|
return {
|
|
86
139
|
message: 'Data uploaded successfully',
|
|
@@ -134,58 +187,78 @@ export class MasterService {
|
|
|
134
187
|
};
|
|
135
188
|
}
|
|
136
189
|
|
|
137
|
-
async uploadEntityData(
|
|
190
|
+
async uploadEntityData(
|
|
191
|
+
file,
|
|
192
|
+
entityType,
|
|
193
|
+
loggedInUser,
|
|
194
|
+
duplicateHandling: 'skip_duplicates' | 'overwrite_items',
|
|
195
|
+
) {
|
|
138
196
|
const data = ExcelUtil.readExcel(file.buffer);
|
|
139
|
-
const entityMaster =
|
|
197
|
+
const entityMaster =
|
|
198
|
+
await this.entityMasterService.findByMappedEntityType(entityType);
|
|
140
199
|
if (!entityMaster) {
|
|
141
200
|
throw new Error(`Entity master not found for entityType: ${entityType}`);
|
|
142
201
|
}
|
|
143
|
-
|
|
202
|
+
|
|
144
203
|
const tableName = entityMaster.db_table_name;
|
|
145
204
|
const sheetData = data[tableName];
|
|
146
205
|
if (!sheetData) {
|
|
147
206
|
throw new Error(`Sheet for ${tableName} not found in uploaded file`);
|
|
148
207
|
}
|
|
149
|
-
|
|
150
|
-
const attributes =
|
|
151
|
-
|
|
152
|
-
|
|
208
|
+
|
|
209
|
+
const attributes =
|
|
210
|
+
await this.attributeMasterService.findAttributesByMappedEntityType(
|
|
211
|
+
entityType,
|
|
212
|
+
);
|
|
213
|
+
const uniqueFields = attributes
|
|
214
|
+
.filter((attr) => attr.is_unique)
|
|
215
|
+
.map((attr) => attr.attribute_key);
|
|
216
|
+
|
|
153
217
|
if (uniqueFields.length === 0) {
|
|
154
218
|
throw new Error(`No unique fields found for entityType: ${entityType}`);
|
|
155
219
|
}
|
|
156
|
-
|
|
220
|
+
|
|
157
221
|
for (const row of sheetData) {
|
|
158
222
|
if (row.parent_type && row.parent_id) {
|
|
159
223
|
await this.resolveParent(row);
|
|
160
224
|
}
|
|
161
|
-
|
|
225
|
+
|
|
162
226
|
for (const attr of attributes) {
|
|
163
227
|
if (attr.data_source_type === 'entity' && row[attr.attribute_key]) {
|
|
164
|
-
const refEntity = await this.entityMasterService.getEntityData(
|
|
228
|
+
const refEntity = await this.entityMasterService.getEntityData(
|
|
229
|
+
attr.datasource_list,
|
|
230
|
+
);
|
|
165
231
|
const refData = await this.entityManager.query(
|
|
166
232
|
`SELECT * FROM ${refEntity.db_table_name} WHERE code = ? LIMIT 1`,
|
|
167
233
|
[row[attr.attribute_key]],
|
|
168
234
|
);
|
|
169
|
-
|
|
235
|
+
|
|
170
236
|
if (!refData.length) {
|
|
171
|
-
throw new Error(
|
|
237
|
+
throw new Error(
|
|
238
|
+
`Reference entity not found for code: ${row[attr.attribute_key]}`,
|
|
239
|
+
);
|
|
172
240
|
}
|
|
173
|
-
|
|
241
|
+
|
|
174
242
|
row[attr.attribute_key] = refData[0].id;
|
|
175
243
|
}
|
|
176
244
|
}
|
|
177
245
|
}
|
|
178
|
-
|
|
179
|
-
await this.upsertViaService(
|
|
180
|
-
|
|
246
|
+
|
|
247
|
+
await this.upsertViaService(
|
|
248
|
+
entityType,
|
|
249
|
+
sheetData,
|
|
250
|
+
attributes,
|
|
251
|
+
uniqueFields,
|
|
252
|
+
loggedInUser,
|
|
253
|
+
duplicateHandling,
|
|
254
|
+
);
|
|
255
|
+
|
|
181
256
|
return { message: 'Entity data uploaded successfully' };
|
|
182
257
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
258
|
|
|
186
|
-
private isMetaSheet(sheetName: string): boolean {
|
|
187
|
-
|
|
188
|
-
}
|
|
259
|
+
// private isMetaSheet(sheetName: string): boolean {
|
|
260
|
+
// return this.metaSheets.includes(sheetName.toLowerCase());
|
|
261
|
+
// }
|
|
189
262
|
|
|
190
263
|
private async resolveParent(row: any): Promise<void> {
|
|
191
264
|
const parentType = row.parent_type; // (Future use maybe)
|
|
@@ -269,35 +342,39 @@ export class MasterService {
|
|
|
269
342
|
loggedInUser: any,
|
|
270
343
|
duplicateHandling: 'skip_duplicates' | 'overwrite_items',
|
|
271
344
|
): Promise<void> {
|
|
272
|
-
const entityMaster =
|
|
273
|
-
|
|
274
|
-
|
|
345
|
+
const entityMaster =
|
|
346
|
+
await this.entityMasterService.findByMappedEntityType(entityType);
|
|
347
|
+
if (!entityMaster)
|
|
348
|
+
throw new Error(`Entity master not found for ${entityType}`);
|
|
349
|
+
|
|
275
350
|
const serviceName = entityMaster.entity_service;
|
|
276
|
-
const entityService =
|
|
277
|
-
|
|
278
|
-
|
|
351
|
+
const entityService =
|
|
352
|
+
await this.reflectionHelper.getBean<EntityServiceImpl>(serviceName);
|
|
353
|
+
if (!entityService)
|
|
354
|
+
throw new Error(`Entity service not found for ${entityType}`);
|
|
355
|
+
|
|
279
356
|
for (const row of data) {
|
|
280
357
|
const qb = this.entityManager
|
|
281
358
|
.createQueryBuilder()
|
|
282
359
|
.select('*')
|
|
283
360
|
.from(entityMaster.db_table_name, entityMaster.db_table_name);
|
|
284
|
-
|
|
361
|
+
|
|
285
362
|
// Build OR conditions dynamically for unique fields
|
|
286
363
|
uniqueFields.forEach((field, index) => {
|
|
287
364
|
const condition = `${entityMaster.db_table_name}.${field} = :val${index}`;
|
|
288
365
|
const param = { [`val${index}`]: row[field] };
|
|
289
|
-
|
|
366
|
+
|
|
290
367
|
if (index === 0) {
|
|
291
368
|
qb.where(condition, param);
|
|
292
369
|
} else {
|
|
293
370
|
qb.orWhere(condition, param);
|
|
294
371
|
}
|
|
295
372
|
});
|
|
296
|
-
|
|
373
|
+
|
|
297
374
|
const existing = await qb.limit(1).getRawOne();
|
|
298
|
-
|
|
375
|
+
|
|
299
376
|
row.entity_type = entityType;
|
|
300
|
-
|
|
377
|
+
|
|
301
378
|
if (existing) {
|
|
302
379
|
if (duplicateHandling === 'skip_duplicates') {
|
|
303
380
|
continue; // Skip this row
|
|
@@ -310,8 +387,4 @@ export class MasterService {
|
|
|
310
387
|
}
|
|
311
388
|
}
|
|
312
389
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
390
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
DB_HOST: "13.234.25.234"
|
|
1
|
+
# DB_HOST: "13.234.25.234"
|
|
2
|
+
DB_HOST: "localhost"
|
|
2
3
|
DB_PORT: "3306"
|
|
3
4
|
DB_USER: "root"
|
|
4
|
-
DB_PASS: "
|
|
5
|
+
DB_PASS: "root"
|
|
5
6
|
DB_NAME: "core"
|
|
6
7
|
MASTER_KEY: "0QZ2eRJv5oVILYnyBlC+FbSGVQiWKReh"
|
|
7
8
|
MASTER_IV: "heuUQf5uPVtkotrFAOKUVw=="
|
|
@@ -2,10 +2,10 @@ import { readFileSync } from 'fs';
|
|
|
2
2
|
import * as yaml from 'js-yaml';
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
|
|
5
|
-
const YAML_CONFIG = `/
|
|
5
|
+
const YAML_CONFIG = `/uat.properties.yaml`;
|
|
6
6
|
|
|
7
7
|
export default () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
8
|
+
return yaml.load(
|
|
9
|
+
readFileSync(join(__dirname, YAML_CONFIG), 'utf8'),
|
|
10
|
+
) as Record<string, any>;
|
|
11
|
+
};
|