rez_core 2.2.126 → 2.2.128

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.2.126",
3
+ "version": "2.2.128",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -15,7 +15,7 @@ export class MySqlConfiguration implements TypeOrmOptionsFactory {
15
15
  password: this.configService.get('DB_PASS') || 'Rezolut@123',
16
16
  database: this.configService.get('DB_NAME') || 'core',
17
17
  entities: [__dirname + '/../module/**/*.entity.{ts,js}'],
18
- synchronize: true,
18
+ synchronize: false,
19
19
  autoLoadEntities: true,
20
20
  poolSize: 5,
21
21
  };
@@ -235,16 +235,104 @@ export class MasterService {
235
235
  throw new Error(`No unique fields found for entityType: ${entityType}`);
236
236
  }
237
237
 
238
- for (const row of sheetData) {
238
+ // for (const row of sheetData) {
239
+
240
+ // if (row.parent_type && row.parent_id) {
241
+ // await this.resolveParent(row);
242
+ // }
243
+
244
+ // for (const attr of attributes) {
245
+ // console.log('inside for loop attr');
246
+ // if (attr.data_source_type === 'entity' && row[attr.attribute_key]) {
247
+ // console.log('inside if condition');
248
+
249
+ // const refEntity = await this.entityMasterService.getEntityData(
250
+ // attr.datasource_list,
251
+ // loggedInUser,
252
+ // );
253
+ // const refData = await this.entityManager.query(
254
+ // `SELECT * FROM ${refEntity.db_table_name} WHERE code = ? LIMIT 1`,
255
+ // [row[attr.attribute_key]],
256
+ // );
257
+
258
+ // //you will check the org id of refData and loggedInUser.organization_id
259
+
260
+ // if (!refData.length) {
261
+ // throw new Error(
262
+ // `Reference entity not found for code: ${row[attr.attribute_key]}`,
263
+ // );
264
+ // }
265
+
266
+ // row[attr.attribute_key] = refData[0].id;
267
+ // }
268
+ // }
269
+ // }
270
+
271
+ // const errors: any[] = [];
272
+
273
+ // for (let i = 0; i < sheetData.length; i++) {
274
+ // const row = sheetData[i];
275
+
276
+ // if (row.parent_type && row.parent_id) {
277
+ // await this.resolveParent(row);
278
+ // }
279
+
280
+ // for (const attr of attributes) {
281
+ // if (attr.data_source_type === 'entity' && row[attr.attribute_key]) {
282
+ // const refEntity = await this.entityMasterService.getEntityData(
283
+ // attr.datasource_list,
284
+ // loggedInUser,
285
+ // );
286
+ // const refData = await this.entityManager.query(
287
+ // `SELECT * FROM ${refEntity.db_table_name} WHERE code = ? LIMIT 1`,
288
+ // [row[attr.attribute_key]],
289
+ // );
290
+ // if (!refData.length) {
291
+ // throw new Error(
292
+ // `Reference entity not found for code: ${row[attr.attribute_key]}`,
293
+ // );
294
+ // }
295
+ // row[attr.attribute_key] = refData[0].id;
296
+ // }
297
+ // }
298
+
299
+ // const rowErrors = await this.entityValidationService.validateEntityData(
300
+ // row,
301
+ // entityMaster,
302
+ // loggedInUser,
303
+ // );
304
+
305
+ // if (rowErrors && rowErrors.length > 0) {
306
+ // errors.push({
307
+ // row: i + 1,
308
+ // errors: rowErrors,
309
+ // });
310
+ // }
311
+ // }
312
+
313
+ // await this.upsertViaService(
314
+ // entityType,
315
+ // sheetData,
316
+ // attributes,
317
+ // uniqueFields,
318
+ // loggedInUser,
319
+ // duplicateHandling,
320
+ // );
321
+
322
+ // return { message: 'Entity data uploaded successfully' };
323
+ const errors: any[] = [];
324
+
325
+ // ✅ Iterate row by row
326
+ for (let i = 0; i < sheetData.length; i++) {
327
+ const row = sheetData[i];
328
+
239
329
  if (row.parent_type && row.parent_id) {
240
330
  await this.resolveParent(row);
241
331
  }
242
332
 
333
+ // handle reference entity replacement
243
334
  for (const attr of attributes) {
244
- console.log('inside for loop attr');
245
335
  if (attr.data_source_type === 'entity' && row[attr.attribute_key]) {
246
- console.log('inside if condition');
247
-
248
336
  const refEntity = await this.entityMasterService.getEntityData(
249
337
  attr.datasource_list,
250
338
  loggedInUser,
@@ -254,19 +342,39 @@ export class MasterService {
254
342
  [row[attr.attribute_key]],
255
343
  );
256
344
 
257
- //you will check the org id of refData and loggedInUser.organization_id
258
-
259
345
  if (!refData.length) {
260
- throw new Error(
261
- `Reference entity not found for code: ${row[attr.attribute_key]}`,
262
- );
346
+ errors.push({
347
+ row: i + 1,
348
+ errors: [
349
+ `Reference entity not found for code: ${row[attr.attribute_key]}`,
350
+ ],
351
+ });
352
+ continue; // skip further processing for this row
263
353
  }
264
354
 
355
+ // replace with reference id
265
356
  row[attr.attribute_key] = refData[0].id;
266
357
  }
267
358
  }
359
+
360
+ // ✅ validate single row
361
+ const rowErrors = await this.entityValidationService.validateEntityData(
362
+ row,
363
+ entityMaster,
364
+ loggedInUser,
365
+ );
366
+
367
+ if (rowErrors.length > 0) {
368
+ errors.push({ row: i + 1, errors: rowErrors });
369
+ }
268
370
  }
269
371
 
372
+ // ✅ if any row failed, return errors instead of inserting
373
+ if (errors.length > 0) {
374
+ return { message: 'Validation errors found', errors };
375
+ }
376
+
377
+ // ✅ only upsert if no validation errors
270
378
  await this.upsertViaService(
271
379
  entityType,
272
380
  sheetData,
@@ -357,6 +465,7 @@ export class MasterService {
357
465
  }
358
466
  }
359
467
  }
468
+
360
469
  async upsertViaService(
361
470
  entityType: string,
362
471
  data: any[],
@@ -96,4 +96,16 @@ export class EntityDynamicController {
96
96
 
97
97
  return entity;
98
98
  }
99
+
100
+ @Get('getDropdownList')
101
+ async getAttributesDropdownList(
102
+ @Req() req: Request & { user: any },
103
+ @Query('appcode') appcode?: string,
104
+ ) {
105
+ let loggedInUser = req.user.userData;
106
+ return await this.entityDynamicService.getEntitiesDropdownList(
107
+ loggedInUser,
108
+ appcode,
109
+ );
110
+ }
99
111
  }
@@ -575,4 +575,24 @@ export class EntityDynamicService {
575
575
  const result = await this.dataSource.query(deleteQuery, [id]);
576
576
  return result;
577
577
  }
578
+
579
+ // -----------------------------
580
+
581
+ async getEntitiesDropdownList(
582
+ loggedInUser: any,
583
+ appcode?: string,
584
+ ): Promise<any> {
585
+ const organizationId = loggedInUser.organization_id;
586
+
587
+ let query = `SELECT name as label,mapped_entity_type as value FROM cr_entity_master WHERE organization_id = ?`;
588
+ let params = [organizationId];
589
+
590
+ if (appcode) {
591
+ query += ` AND appcode = ?`;
592
+ params.push(appcode);
593
+ }
594
+
595
+ const dropdown = await this.dataSource.query(query, params);
596
+ return dropdown;
597
+ }
578
598
  }