rez_core 4.0.292 → 4.0.295

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": "4.0.292",
3
+ "version": "4.0.295",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -9,9 +9,14 @@ import { EntityJson } from './entity/entityJson.entity';
9
9
  import { EntityJSONRepository } from './service/entityJson.repository';
10
10
 
11
11
  @Module({
12
- imports: [EntityModule, TypeOrmModule.forFeature([EntityJson]),FilterModule,UtilsModule],
12
+ imports: [
13
+ EntityModule,
14
+ TypeOrmModule.forFeature([EntityJson]),
15
+ FilterModule,
16
+ UtilsModule,
17
+ ],
13
18
  controllers: [EntityJSONController],
14
- providers: [EntityJSONService,EntityJSONRepository],
19
+ providers: [EntityJSONService, EntityJSONRepository],
15
20
  exports: [],
16
21
  })
17
22
  export class EntityJSONModule {}
@@ -29,6 +29,9 @@ export class LinkedAttributesController {
29
29
  @UseGuards(JwtAuthGuard)
30
30
  async upsertLinkedAttributes(@Req() req: any, @Body() payload: any) {
31
31
  const loggedInUser = req.user?.userData;
32
- return this.linkedAttributesService.upsert(payload, loggedInUser);
32
+ return this.linkedAttributesService.upsertLinkedAttributes(
33
+ payload,
34
+ loggedInUser,
35
+ );
33
36
  }
34
37
  }
@@ -15,7 +15,7 @@ export class LinkedAttributesService extends EntityServiceImpl {
15
15
  payload.attribute_key = payload.field_name
16
16
  .trim()
17
17
  .toLowerCase()
18
- .replace(/\s+/g, '_'); // replace spaces with underscore
18
+ .replace(/\s+/g, '_');
19
19
  }
20
20
 
21
21
  // Pass to base class create method
@@ -32,71 +32,44 @@ export class LinkedAttributesService extends EntityServiceImpl {
32
32
  .getMany();
33
33
  }
34
34
 
35
- async upsert(payloadList: any[], loggedInUser: any) {
35
+ async upsertLinkedAttributes(payloadList: any[], loggedInUser: any) {
36
36
  const orgId = loggedInUser.organization_id;
37
- const output: any[] = [];
38
37
 
39
- for (const payload of payloadList) {
40
- payload.organization_id = orgId;
41
-
42
- // ------------------------------------
43
- // UPDATE CASE
44
- // ------------------------------------
45
- if (payload.id) {
46
- const existing = await this.dataSource
47
- .getRepository(LinkedAttributes)
48
- .createQueryBuilder('la')
49
- .where('la.id = :id', { id: payload.id })
50
- .andWhere('la.organization_id = :orgId', { orgId })
51
- .getOne();
52
-
53
- if (!existing) {
54
- continue;
55
- }
56
-
57
- await this.dataSource
58
- .createQueryBuilder()
59
- .update(LinkedAttributes)
60
- .set(payload)
61
- .where('id = :id', { id: payload.id })
62
- .andWhere('organization_id = :orgId', { orgId })
63
- .execute();
64
-
65
- // fetch updated object
66
- const updated = await this.dataSource
67
- .getRepository(LinkedAttributes)
68
- .createQueryBuilder('la')
69
- .where('la.id = :id', { id: payload.id })
70
- .andWhere('la.organization_id = :orgId', { orgId })
71
- .getOne();
72
-
73
- output.push(updated);
74
- continue;
75
- }
76
-
77
- // ------------------------------------
78
- // CREATE CASE
79
- // ------------------------------------
80
- const insertResult = await this.dataSource
81
- .createQueryBuilder()
82
- .insert()
83
- .into(LinkedAttributes)
84
- .values(payload)
85
- .execute();
86
-
87
- const newId = insertResult.identifiers[0].id;
88
-
89
- // fetch the created object
90
- const created = await this.dataSource
91
- .getRepository(LinkedAttributes)
92
- .createQueryBuilder('la')
93
- .where('la.id = :id', { id: newId })
94
- .andWhere('la.organization_id = :orgId', { orgId })
95
- .getOne();
96
-
97
- output.push(created);
98
- }
38
+ // Step 1: Delete all existing rows for this organization
39
+ await this.dataSource
40
+ .createQueryBuilder()
41
+ .delete()
42
+ .from(LinkedAttributes)
43
+ .where('organization_id = :orgId', { orgId })
44
+ .execute();
45
+
46
+ // Step 2: Normalize & prepare payloads
47
+ const newPayloads = payloadList.map((item) => ({
48
+ ...item,
49
+ organization_id: orgId,
50
+ attribute_key: item.attribute_key
51
+ ? item.attribute_key.trim().toLowerCase().replace(/\s+/g, '_')
52
+ : item.field_name.trim().toLowerCase().replace(/\s+/g, '_'),
53
+ }));
54
+
55
+ // Step 3: Bulk Insert
56
+ const insertResult = await this.dataSource
57
+ .createQueryBuilder()
58
+ .insert()
59
+ .into(LinkedAttributes)
60
+ .values(newPayloads)
61
+ .execute();
62
+
63
+ // Step 4: Return inserted list
64
+ const ids = insertResult.identifiers.map((i) => i.id);
65
+
66
+ const newlyCreated = await this.dataSource
67
+ .getRepository(LinkedAttributes)
68
+ .createQueryBuilder('la')
69
+ .where('la.id IN (:...ids)', { ids })
70
+ .andWhere('la.organization_id = :orgId', { orgId })
71
+ .getMany();
99
72
 
100
- return output;
73
+ return newlyCreated;
101
74
  }
102
75
  }
@@ -87,6 +87,20 @@ export class ListMasterService {
87
87
  config.appcode != loggedInUser?.appcode &&
88
88
  !publicCall
89
89
  ) {
90
+ const client = this.factory.getClient(config.appcode);
91
+
92
+ if (!client) {
93
+ return;
94
+ }
95
+
96
+ const res = await firstValueFrom(
97
+ client.send('listmaster.getDropdownData', {
98
+ type,
99
+ loggedInUser,
100
+ }),
101
+ );
102
+
103
+ console.log(res, '-------------------');
90
104
  // Call internal API for appcode mismatch
91
105
  try {
92
106
  const baseUrl = this.configService.get<string>('REDIRECT_BE_URL');
@@ -443,12 +457,16 @@ export class ListMasterService {
443
457
  return await this.listMasterRepo.findAllItems(organizationId, search);
444
458
  }
445
459
 
446
- async getDropDownData(entity_type: string,
447
- attribute_key: string,
448
- loggedInUser: UserData,
449
- body: Record<string, string>
450
- ) {
451
- let entityMaster = await this.entityMasterService.getEntityData(entity_type, loggedInUser);
460
+ async getDropDownData(
461
+ entity_type: string,
462
+ attribute_key: string,
463
+ loggedInUser: UserData,
464
+ body: Record<string, string>,
465
+ ) {
466
+ let entityMaster = await this.entityMasterService.getEntityData(
467
+ entity_type,
468
+ loggedInUser,
469
+ );
452
470
  let appCode = entityMaster.appcode;
453
471
 
454
472
  const { inactiveIds, ...params } = body;
@@ -460,11 +478,12 @@ export class ListMasterService {
460
478
  const currentAppCode = this.configService.get<string>('appcode');
461
479
 
462
480
  if (currentAppCode === appCode || !currentAppCode) {
463
- const entityAttribute = await this.attributeMasterService.findByMappedEntityTypeAndAttributeKey(
464
- entity_type,
465
- attribute_key,
466
- loggedInUser
467
- );
481
+ const entityAttribute =
482
+ await this.attributeMasterService.findByMappedEntityTypeAndAttributeKey(
483
+ entity_type,
484
+ attribute_key,
485
+ loggedInUser,
486
+ );
468
487
 
469
488
  if (entityAttribute && entityAttribute.data_source_type) {
470
489
  const listMaster = await this.listMasterRepo.findByType(
@@ -514,7 +533,9 @@ export class ListMasterService {
514
533
  }
515
534
 
516
535
  default:
517
- throw new BadRequestException(`Unknown source: ${listMaster.source}`);
536
+ throw new BadRequestException(
537
+ `Unknown source: ${listMaster.source}`,
538
+ );
518
539
  }
519
540
  }
520
541
  } else {
@@ -524,12 +545,14 @@ export class ListMasterService {
524
545
  return;
525
546
  }
526
547
 
527
- return client.send('getDropdownData', {
528
- entity_type,
529
- attribute_key,
530
- loggedInUser,
531
- body,
532
- }).toPromise();
548
+ return client
549
+ .send('getDropdownData', {
550
+ entity_type,
551
+ attribute_key,
552
+ loggedInUser,
553
+ body,
554
+ })
555
+ .toPromise();
533
556
  }
534
557
  }
535
558
  }