rez_core 4.0.222 → 4.0.225

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.222",
3
+ "version": "4.0.225",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -103,7 +103,6 @@ export class EntityJSONService extends EntityServiceImpl {
103
103
  'attr.id',
104
104
  'attr.name',
105
105
  'attr.attribute_key',
106
- 'fla.saved_filter_code',
107
106
  ])
108
107
  .where('attr.organization_id = :orgId', { orgId })
109
108
  .getRawMany();
@@ -212,33 +211,27 @@ export class EntityJSONService extends EntityServiceImpl {
212
211
  }
213
212
 
214
213
  // 5. Merge linked attributes using saved filters
215
- // 5. Merge linked attributes using saved filters
216
- for (const linkAttr of safeAttributes.linkedAttributes) {
217
- const childEntityType = linkAttr.fla_applicable_entity_type;
218
- const childAttributeKey = linkAttr.attr_attribute_key;
219
-
220
- if (!childEntityType || !childAttributeKey) continue;
221
-
222
- // mappingValue can come from mainData or relatedData if you have parent key
223
- const mappingValue = mainData?.[childAttributeKey] ?? null;
224
-
225
- const value = await this.applyLinkedFilterUsingSavedFilter(
226
- childEntityType,
227
- linkAttr.fla_saved_filter_code, // make sure this column exists in your query
228
- childAttributeKey,
229
- mappingValue,
230
- childAttributeKey, // target attribute in flatJson
231
- loggedInUser,
232
- entityId
233
- );
234
-
235
- if (value !== null && value !== undefined) {
236
- // Use attrMap if flat_json_key exists
237
- const flatKey = attrMap[childAttributeKey] || childAttributeKey;
238
- flatJson[flatKey] = value;
239
- }
240
- }
241
-
214
+ for (const linkAttr of safeAttributes.linkedAttributes) {
215
+ if (!linkAttr.applicable_entity_type || !linkAttr.applicable_attribute_key) continue;
216
+
217
+ const mappingValue = mainData?.[linkAttr.parent_attribute_key || ''] ?? null;
218
+ const value = await this.applyLinkedFilterUsingSavedFilter(
219
+ linkAttr.applicable_entity_type,
220
+ linkAttr.saved_filter_code,
221
+ linkAttr.applicable_attribute_key,
222
+ mappingValue,
223
+ linkAttr.target_attribute_key || linkAttr.applicable_attribute_key,
224
+ loggedInUser,
225
+ entityId,
226
+ );
227
+
228
+ if (value !== null && value !== undefined) {
229
+ const flatKey = attrMap[linkAttr.target_attribute_key || linkAttr.applicable_attribute_key]
230
+ || (linkAttr.target_attribute_key || linkAttr.applicable_attribute_key);
231
+ flatJson[flatKey] = value;
232
+ }
233
+ }
234
+
242
235
  // 6. Save JSON
243
236
  await this.dataSource.query(
244
237
  `INSERT INTO frm_entity_json (entity_type, entity_id, json_data, created_by)
@@ -1,4 +1,12 @@
1
- import { Controller, Get, Inject, Req, UseGuards } from '@nestjs/common';
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Get,
5
+ Inject,
6
+ Post,
7
+ Req,
8
+ UseGuards,
9
+ } from '@nestjs/common';
2
10
  import { LinkedAttributesService } from '../service/linked_attributes.service';
3
11
  import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
4
12
 
@@ -16,4 +24,11 @@ export class LinkedAttributesController {
16
24
 
17
25
  return this.linkedAttributesService.getAllLinkedAttributes(loggedInUser);
18
26
  }
27
+
28
+ @Post('upsert')
29
+ @UseGuards(JwtAuthGuard)
30
+ async upsertLinkedAttributes(@Req() req: any, @Body() payload: any) {
31
+ const loggedInUser = req.user?.userData;
32
+ return this.linkedAttributesService.upsert(payload, loggedInUser);
33
+ }
19
34
  }
@@ -31,4 +31,72 @@ export class LinkedAttributesService extends EntityServiceImpl {
31
31
  .where('fla.organization_id = :orgId', { orgId })
32
32
  .getMany();
33
33
  }
34
+
35
+ async upsert(payloadList: any[], loggedInUser: any) {
36
+ const orgId = loggedInUser.organization_id;
37
+ const output: any[] = [];
38
+
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
+ }
99
+
100
+ return output;
101
+ }
34
102
  }