rez_core 4.0.293 → 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.293",
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
  }
@@ -1,5 +0,0 @@
1
- {
2
- "recommendations": [
3
- "dbaeumer.vscode-eslint"
4
- ]
5
- }