rez_core 5.0.152 → 5.0.154

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.
Files changed (76) hide show
  1. package/dist/config/bull.config.js +4 -4
  2. package/dist/config/bull.config.js.map +1 -1
  3. package/dist/core.module.js +2 -5
  4. package/dist/core.module.js.map +1 -1
  5. package/dist/module/entity_json/entity_json.module.js +1 -1
  6. package/dist/module/entity_json/entity_json.module.js.map +1 -1
  7. package/dist/module/entity_json/service/entity_json.service.js +1 -1
  8. package/dist/module/entity_json/service/entity_json.service.js.map +1 -1
  9. package/dist/module/filter/controller/filter.controller.d.ts +0 -12
  10. package/dist/module/filter/controller/filter.controller.js +1 -1
  11. package/dist/module/filter/controller/filter.controller.js.map +1 -1
  12. package/dist/module/filter/entity/saved-filter-master.entity.d.ts +2 -1
  13. package/dist/module/filter/entity/saved-filter-master.entity.js +6 -2
  14. package/dist/module/filter/entity/saved-filter-master.entity.js.map +1 -1
  15. package/dist/module/filter/filter.module.js +2 -9
  16. package/dist/module/filter/filter.module.js.map +1 -1
  17. package/dist/module/filter/repository/saved-filter.repository.d.ts +1 -5
  18. package/dist/module/filter/repository/saved-filter.repository.js +1 -5
  19. package/dist/module/filter/repository/saved-filter.repository.js.map +1 -1
  20. package/dist/module/filter/service/filter.service.d.ts +1 -37
  21. package/dist/module/filter/service/filter.service.js +2 -30
  22. package/dist/module/filter/service/filter.service.js.map +1 -1
  23. package/dist/module/integration/service/wrapper.service.d.ts +3 -1
  24. package/dist/module/integration/service/wrapper.service.js +24 -2
  25. package/dist/module/integration/service/wrapper.service.js.map +1 -1
  26. package/dist/module/linked_attributes/controller/linked_attributes.controller.d.ts +0 -19
  27. package/dist/module/linked_attributes/controller/linked_attributes.controller.js +0 -77
  28. package/dist/module/linked_attributes/controller/linked_attributes.controller.js.map +1 -1
  29. package/dist/module/linked_attributes/linked_attributes.module.js +1 -8
  30. package/dist/module/linked_attributes/linked_attributes.module.js.map +1 -1
  31. package/dist/module/linked_attributes/service/linked_attributes.service.d.ts +1 -41
  32. package/dist/module/linked_attributes/service/linked_attributes.service.js +2 -266
  33. package/dist/module/linked_attributes/service/linked_attributes.service.js.map +1 -1
  34. package/dist/module/meta/dto/entity-table.dto.d.ts +1 -4
  35. package/dist/module/meta/dto/entity-table.dto.js.map +1 -1
  36. package/dist/module/meta/service/media-data.service.js +18 -5
  37. package/dist/module/meta/service/media-data.service.js.map +1 -1
  38. package/dist/module/workflow/service/action.service.js +2 -10
  39. package/dist/module/workflow/service/action.service.js.map +1 -1
  40. package/dist/table.config.d.ts +1 -3
  41. package/dist/table.config.js +0 -2
  42. package/dist/table.config.js.map +1 -1
  43. package/dist/tsconfig.build.tsbuildinfo +1 -1
  44. package/package.json +1 -1
  45. package/src/config/bull.config.ts +4 -4
  46. package/src/core.module.ts +2 -5
  47. package/src/module/entity_json/entity_json.module.ts +1 -1
  48. package/src/module/entity_json/service/entity_json.service.ts +1 -1
  49. package/src/module/filter/controller/filter.controller.ts +3 -1
  50. package/src/module/filter/entity/saved-filter-master.entity.ts +5 -2
  51. package/src/module/filter/filter.module.ts +2 -9
  52. package/src/module/filter/repository/saved-filter.repository.ts +9 -5
  53. package/src/module/filter/service/filter.service.ts +0 -49
  54. package/src/module/integration/service/wrapper.service.ts +37 -0
  55. package/src/module/linked_attributes/controller/linked_attributes.controller.ts +0 -86
  56. package/src/module/linked_attributes/linked_attributes.module.ts +2 -9
  57. package/src/module/linked_attributes/service/linked_attributes.service.ts +3 -548
  58. package/src/module/meta/dto/entity-table.dto.ts +3 -1
  59. package/src/module/meta/service/media-data.service.ts +27 -9
  60. package/src/module/workflow/service/action.service.ts +6 -10
  61. package/src/table.config.ts +0 -2
  62. package/dist/migrations/1732612800000-AddEntityJsonGinIndex.d.ts +0 -6
  63. package/dist/migrations/1732612800000-AddEntityJsonGinIndex.js +0 -32
  64. package/dist/migrations/1732612800000-AddEntityJsonGinIndex.js.map +0 -1
  65. package/dist/module/filter/service/flatjson-filter.service.d.ts +0 -30
  66. package/dist/module/filter/service/flatjson-filter.service.js +0 -615
  67. package/dist/module/filter/service/flatjson-filter.service.js.map +0 -1
  68. package/dist/module/linked_attributes/dto/create-linked-attribute-smart.dto.d.ts +0 -13
  69. package/dist/module/linked_attributes/dto/create-linked-attribute-smart.dto.js +0 -64
  70. package/dist/module/linked_attributes/dto/create-linked-attribute-smart.dto.js.map +0 -1
  71. package/src/migrations/1732612800000-AddEntityJsonGinIndex.ts +0 -41
  72. package/src/module/entity_json/docs/FlatJson_Filterin_System.md +0 -2804
  73. package/src/module/filter/service/flatjson-filter.service.ts +0 -888
  74. package/src/module/filter/test/flatjson-filter.service.spec.ts +0 -415
  75. package/src/module/linked_attributes/dto/create-linked-attribute-smart.dto.ts +0 -54
  76. package/src/module/linked_attributes/test/linked-attributes.service.spec.ts +0 -244
@@ -1,33 +1,15 @@
1
- import { Injectable, Inject, BadRequestException, NotFoundException } from '@nestjs/common';
1
+ import { Injectable } from '@nestjs/common';
2
2
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
3
- import { BaseEntity, DataSource } from 'typeorm';
3
+ import { DataSource } from 'typeorm';
4
4
  import { LinkedAttributes } from '../entity/linked_attribute.entity';
5
- import { EntityMasterService } from 'src/module/meta/service/entity-master.service';
6
- import { AttributeMasterService } from 'src/module/meta/service/attribute-master.service';
7
- import { SavedFilterService } from 'src/module/filter/service/saved-filter.service';
8
- import { SavedFilterDetailRepository } from 'src/module/filter/repository/saved.filter-detail.repository';
9
- import { EntityJSONService } from 'src/module/entity_json/service/entity_json.service';
10
- import { CreateLinkedAttributeSmartDto } from '../dto/create-linked-attribute-smart.dto';
11
- import { EntityJson } from 'src/module/entity_json/entity/entityJson.entity';
12
5
 
13
6
  @Injectable()
14
7
  export class LinkedAttributesService extends EntityServiceImpl {
15
- constructor(
16
- private readonly dataSource: DataSource,
17
- entityMasterService: EntityMasterService,
18
- private readonly attributeMasterService: AttributeMasterService,
19
- @Inject('SavedFilterService')
20
- private readonly savedFilterService: SavedFilterService,
21
- private readonly entityJsonService: EntityJSONService,
22
- ) {
8
+ constructor(private readonly dataSource: DataSource) {
23
9
  super();
24
10
  }
25
11
 
26
12
  async createEntity(payload: any, loggedInUser: any): Promise<any> {
27
- console.warn(
28
- '[DEPRECATED] Use createLinkedAttributeSmart() instead of createEntity()',
29
- );
30
-
31
13
  // Auto-generate attribute_key if missing OR empty
32
14
  if (!payload.attribute_key || payload.attribute_key.trim() === '') {
33
15
  payload.attribute_key = payload.field_name
@@ -90,531 +72,4 @@ export class LinkedAttributesService extends EntityServiceImpl {
90
72
 
91
73
  return newlyCreated;
92
74
  }
93
-
94
- /**
95
- * Generate the next sequence number for a linked attribute
96
- * @param mapped_entity_type - Main entity type (e.g., "LEAD")
97
- * @param applicable_entity_type - Source 1:M entity (e.g., "LFMG")
98
- * @param applicable_attribute_key - Source attribute (e.g., "name")
99
- * @param organization_id - Organization ID
100
- * @returns Next available sequence number
101
- */
102
- private async generateNextSequence(
103
- mapped_entity_type: string,
104
- applicable_entity_type: string,
105
- applicable_attribute_key: string,
106
- organization_id: number,
107
- ): Promise<number> {
108
- const result = await this.dataSource
109
- .getRepository(LinkedAttributes)
110
- .createQueryBuilder('fla')
111
- .select('MAX(fla.sequence)', 'max_sequence')
112
- .where('fla.mapped_entity_type = :mapped_entity_type', {
113
- mapped_entity_type,
114
- })
115
- .andWhere('fla.applicable_entity_type = :applicable_entity_type', {
116
- applicable_entity_type,
117
- })
118
- .andWhere('fla.applicable_attribute_key = :applicable_attribute_key', {
119
- applicable_attribute_key,
120
- })
121
- .andWhere('fla.organization_id = :organization_id', { organization_id })
122
- .getRawOne();
123
-
124
- const maxSequence = result?.max_sequence;
125
-
126
- // If no records exist or max is null, return 1; otherwise return max + 1
127
- return maxSequence ? maxSequence + 1 : 1;
128
- }
129
-
130
- /**
131
- * Generate a flatjson attribute key in format: ENTITY__attribute__N
132
- * @param applicable_entity_type - Entity code (e.g., "LFMG")
133
- * @param applicable_attribute_key - Attribute key (e.g., "name")
134
- * @param sequence - Sequence number (e.g., 1)
135
- * @returns Generated key (e.g., "LFMG__name__1")
136
- * @example generateAttributeKey('LFMG', 'name', 1) => 'LFMG__name__1'
137
- */
138
- public generateAttributeKey(
139
- applicable_entity_type: string,
140
- applicable_attribute_key: string,
141
- sequence: number,
142
- ): string {
143
- // Validate inputs
144
- if (!applicable_entity_type || applicable_entity_type.trim() === '') {
145
- throw new Error('applicable_entity_type is required and cannot be empty');
146
- }
147
-
148
- if (!applicable_attribute_key || applicable_attribute_key.trim() === '') {
149
- throw new Error(
150
- 'applicable_attribute_key is required and cannot be empty',
151
- );
152
- }
153
-
154
- if (!sequence || sequence < 1 || !Number.isInteger(sequence)) {
155
- throw new Error('sequence must be a positive integer greater than 0');
156
- }
157
-
158
- // Generate and return formatted key
159
- return `${applicable_entity_type}__${applicable_attribute_key}__${sequence}`;
160
- }
161
-
162
- /**
163
- * Create a SavedFilter for a linked attribute
164
- * @param entity_type - Entity type to filter (e.g., "LFMG")
165
- * @param conditions - Array of filter conditions
166
- * @param attribute_key - Linked attribute key (for naming)
167
- * @param loggedInUser - Current user context
168
- * @returns Generated filter code
169
- */
170
- private async createFilterForLinkedAttribute(
171
- entity_type: string,
172
- conditions: Array<{
173
- filter_attribute: string;
174
- filter_operator: string;
175
- filter_value: any;
176
- }>,
177
- attribute_key: string,
178
- loggedInUser: any,
179
- ): Promise<string> {
180
- return await this.dataSource.transaction(async (transactionManager) => {
181
- // Step 1: Generate unique filter code
182
- const timestamp = Date.now();
183
- const filterCode = `LA_${entity_type}_${attribute_key}_${timestamp}`;
184
-
185
- // Step 2: Create SavedFilterMaster
186
- const filterMasterData = {
187
- name: `Auto Filter - ${attribute_key}`,
188
- code: filterCode,
189
- mapped_entity_type: entity_type,
190
- filter_scope: 'FILTER' as const,
191
- organization_id: loggedInUser.organization_id,
192
- level_type: loggedInUser.level_type,
193
- level_id: loggedInUser.level_id,
194
- user_id: loggedInUser.id,
195
- };
196
-
197
- const filterMaster = await this.savedFilterService.createEntity(
198
- filterMasterData,
199
- loggedInUser,
200
- );
201
-
202
- // Step 3: Create SavedFilterDetail records
203
- const detailPromises = conditions.map((condition) => {
204
- const detailData = {
205
- mapped_filter_code: filterMaster.code,
206
- filter_entity_type: entity_type,
207
- filter_attribute: condition.filter_attribute,
208
- filter_operator: condition.filter_operator,
209
- filter_value: String(condition.filter_value),
210
- organization_id: loggedInUser.organization_id,
211
- level_type: loggedInUser.level_type,
212
- level_id: loggedInUser.level_id,
213
- };
214
-
215
- return transactionManager.save('SavedFilterDetail', detailData);
216
- });
217
-
218
- await Promise.all(detailPromises);
219
-
220
- // Step 4: Return the generated filter code
221
- return filterMaster.code;
222
- });
223
- }
224
-
225
- /**
226
- * Smart creation of linked attribute with auto-generation
227
- * @param payload - Linked attribute data
228
- * @param loggedInUser - Current user context
229
- * @returns Created LinkedAttribute entity
230
- */
231
- async createLinkedAttributeSmart(
232
- payload: CreateLinkedAttributeSmartDto,
233
- loggedInUser: any,
234
- ): Promise<LinkedAttributes> {
235
- // Step 1: Validate input
236
- const validation = await this.validateLinkedAttribute(
237
- {
238
- field_name: payload.field_name,
239
- mapped_entity_type: payload.mapped_entity_type,
240
- applicable_entity_type: payload.applicable_entity_type,
241
- applicable_attribute_key: payload.applicable_attribute_key,
242
- organization_id: loggedInUser.organization_id,
243
- },
244
- loggedInUser,
245
- );
246
-
247
- if (!validation.valid) {
248
- throw new BadRequestException(validation.errors.join(', '));
249
- }
250
-
251
- // Step 2: Generate sequence number
252
- const sequence = await this.generateNextSequence(
253
- payload.mapped_entity_type,
254
- payload.applicable_entity_type,
255
- payload.applicable_attribute_key,
256
- loggedInUser.organization_id,
257
- );
258
-
259
- // Step 3: Generate attribute_key
260
- const attribute_key = this.generateAttributeKey(
261
- payload.applicable_entity_type,
262
- payload.applicable_attribute_key,
263
- sequence,
264
- );
265
-
266
- // Step 4: Create saved filter if conditions provided
267
- let saved_filter_code: string | null = payload.saved_filter_code || null;
268
- // if (payload.filter_conditions && payload.filter_conditions.length > 0) {
269
- // saved_filter_code = await this.createFilterForLinkedAttribute(
270
- // payload.applicable_entity_type,
271
- // payload.filter_conditions,
272
- // attribute_key,
273
- // loggedInUser,
274
- // );
275
- // }
276
-
277
- // Step 5: Create LinkedAttribute entity
278
- let linkedAttrData:any = {
279
- field_name: payload.field_name,
280
- attribute_key,
281
- applicable_entity_type: payload.applicable_entity_type,
282
- applicable_attribute_key: payload.applicable_attribute_key,
283
- mapped_entity_type: payload.mapped_entity_type,
284
- saved_filter_code,
285
- sequence,
286
- organization_id: loggedInUser.organization_id,
287
- level_type: loggedInUser.level_type,
288
- level_id: loggedInUser.level_id,
289
- entity_type:'LNATR'
290
- };
291
-
292
- const linkedAttribute = (await super.createEntity(
293
- linkedAttrData,
294
- loggedInUser,
295
- )) as LinkedAttributes;
296
-
297
- // Step 6: Trigger backfill if requested (async, don't await)
298
- if (payload.backfill) {
299
- this.backfillLinkedAttribute(linkedAttribute.id, loggedInUser).catch(
300
- (err) =>
301
- console.error(
302
- `Backfill failed for linked attribute ${linkedAttribute.id}:`,
303
- err,
304
- ),
305
- );
306
- }
307
-
308
- return linkedAttribute;
309
- }
310
-
311
- /**
312
- * Validate linked attribute payload before creation
313
- * @param payload - Linked attribute data to validate
314
- * @param loggedInUser - Current user context
315
- * @returns Validation result with errors array
316
- */
317
- async validateLinkedAttribute(
318
- payload: {
319
- field_name: string;
320
- mapped_entity_type: string;
321
- applicable_entity_type: string;
322
- applicable_attribute_key: string;
323
- attribute_key?: string;
324
- organization_id: number;
325
- },
326
- loggedInUser: any,
327
- ): Promise<{ valid: boolean; errors: string[] }> {
328
- const errors: string[] = [];
329
-
330
- // Run all validations in parallel
331
- const [
332
- duplicateError,
333
- mappedEntityError,
334
- applicableEntityError,
335
- attributeError,
336
- ] = await Promise.all([
337
- this.checkDuplicateAttributeKey(
338
- payload.attribute_key,
339
- payload.organization_id,
340
- ),
341
- this.validateEntityTypeExists(
342
- payload.mapped_entity_type,
343
- loggedInUser,
344
- ),
345
- this.validateEntityTypeExists(
346
- payload.applicable_entity_type,
347
- loggedInUser,
348
- ),
349
- this.validateAttributeKeyExists(
350
- payload.applicable_entity_type,
351
- payload.applicable_attribute_key,
352
- loggedInUser,
353
- ),
354
- ]);
355
-
356
- // Collect errors
357
- if (duplicateError) errors.push(duplicateError);
358
- if (mappedEntityError) errors.push(mappedEntityError);
359
- if (applicableEntityError) errors.push(applicableEntityError);
360
- if (attributeError) errors.push(attributeError);
361
-
362
- // Validate required fields
363
- this.validateRequiredFields(payload, errors);
364
-
365
- return { valid: errors.length === 0, errors };
366
- }
367
-
368
- /**
369
- * Validate that all required fields are present and not empty
370
- * @param payload - Payload to validate
371
- * @param errors - Array to collect error messages
372
- */
373
- private validateRequiredFields(
374
- payload: {
375
- field_name: string;
376
- mapped_entity_type: string;
377
- applicable_entity_type: string;
378
- applicable_attribute_key: string;
379
- },
380
- errors: string[],
381
- ): void {
382
- const requiredFields = [
383
- { field: 'field_name', value: payload.field_name },
384
- { field: 'mapped_entity_type', value: payload.mapped_entity_type },
385
- { field: 'applicable_entity_type', value: payload.applicable_entity_type },
386
- { field: 'applicable_attribute_key', value: payload.applicable_attribute_key },
387
- ];
388
-
389
- for (const { field, value } of requiredFields) {
390
- if (!value || (typeof value === 'string' && value.trim() === '')) {
391
- errors.push(`Required field '${field}' is missing or empty`);
392
- }
393
- }
394
- }
395
-
396
- /**
397
- * Check if attribute_key already exists for the organization
398
- * @param attribute_key - Attribute key to check
399
- * @param organization_id - Organization ID
400
- * @returns Error message if duplicate exists, null otherwise
401
- */
402
- private async checkDuplicateAttributeKey(
403
- attribute_key: string | undefined,
404
- organization_id: number,
405
- ): Promise<string | null> {
406
- // Skip check if attribute_key is not provided (will be auto-generated)
407
- if (!attribute_key || attribute_key.trim() === '') {
408
- return null;
409
- }
410
-
411
- const existing = await this.dataSource
412
- .getRepository(LinkedAttributes)
413
- .createQueryBuilder('fla')
414
- .where('fla.attribute_key = :attribute_key', { attribute_key })
415
- .andWhere('fla.organization_id = :organization_id', { organization_id })
416
- .getOne();
417
-
418
- if (existing) {
419
- return `Attribute key '${attribute_key}' already exists for this organization`;
420
- }
421
-
422
- return null;
423
- }
424
-
425
- /**
426
- * Validate that entity type exists in frm_entity_master
427
- * @param entity_type - Entity type to validate
428
- * @param loggedInUser - Current user context
429
- * @returns Error message if entity doesn't exist, null otherwise
430
- */
431
- private async validateEntityTypeExists(
432
- entity_type: string,
433
- loggedInUser: any,
434
- ): Promise<string | null> {
435
- if (!entity_type || entity_type.trim() === '') {
436
- return null; // Will be caught by required field validation
437
- }
438
-
439
- try {
440
- await this.entityMasterService.getEntityData(entity_type, loggedInUser);
441
- return null; // Entity exists
442
- } catch (error) {
443
- return `Entity type '${entity_type}' does not exist`;
444
- }
445
- }
446
-
447
- /**
448
- * Validate that attribute exists in frm_attribute_master for the given entity
449
- * @param entity_type - Entity type
450
- * @param attribute_key - Attribute key to validate
451
- * @param loggedInUser - Current user context
452
- * @returns Error message if attribute doesn't exist, null otherwise
453
- */
454
- private async validateAttributeKeyExists(
455
- entity_type: string,
456
- attribute_key: string,
457
- loggedInUser: any,
458
- ): Promise<string | null> {
459
- if (!entity_type || !attribute_key) {
460
- return null; // Will be caught by required field validation
461
- }
462
-
463
- try {
464
- const attributes =
465
- await this.attributeMasterService.findAttributesByMappedEntityType(
466
- entity_type,
467
- loggedInUser,
468
- );
469
-
470
- const attributeExists = attributes.some(
471
- (attr) => attr.attribute_key === attribute_key,
472
- );
473
-
474
- if (!attributeExists) {
475
- return `Attribute '${attribute_key}' does not exist in entity '${entity_type}'`;
476
- }
477
-
478
- return null;
479
- } catch (error) {
480
- return `Error validating attribute '${attribute_key}' in entity '${entity_type}': ${error.message}`;
481
- }
482
- }
483
-
484
- /**
485
- * Backfill existing entities with a new linked attribute
486
- * @param linked_attribute_id - ID of the linked attribute to backfill
487
- * @param loggedInUser - Current user context
488
- * @returns Summary of backfill operation
489
- */
490
- async backfillLinkedAttribute(
491
- linked_attribute_id: number,
492
- loggedInUser: any,
493
- ): Promise<{
494
- total: number;
495
- updated: number;
496
- failed: number;
497
- errors: Array<{ entity_id: number; error: string }>;
498
- }> {
499
- // Step 1: Load linked attribute
500
- const linkedAttr = await this.dataSource
501
- .getRepository(LinkedAttributes)
502
- .findOne({ where: { id: linked_attribute_id } });
503
-
504
- if (!linkedAttr) {
505
- throw new NotFoundException(
506
- `LinkedAttribute with ID ${linked_attribute_id} not found`,
507
- );
508
- }
509
-
510
- // Step 2: Get all entities of this type
511
- const entityJsonRecords = await this.dataSource
512
- .getRepository(EntityJson)
513
- .createQueryBuilder('ej')
514
- .select(['ej.entity_id'])
515
- .where('ej.entity_type = :entityType', {
516
- entityType: linkedAttr.mapped_entity_type,
517
- })
518
- .andWhere('ej.organization_id = :orgId', {
519
- orgId: loggedInUser.organization_id,
520
- })
521
- .getMany();
522
-
523
- // Step 3: Process in batches
524
- const batchSize = 100;
525
- const results = {
526
- total: entityJsonRecords.length,
527
- updated: 0,
528
- failed: 0,
529
- errors: [] as Array<{ entity_id: number; error: string }>,
530
- };
531
-
532
- for (let i = 0; i < entityJsonRecords.length; i += batchSize) {
533
- const batch = entityJsonRecords.slice(i, i + batchSize);
534
-
535
- for (const record of batch) {
536
- try {
537
- await this.entityJsonService.updateEntityJSON(
538
- linkedAttr.mapped_entity_type,
539
- record.entity_id,
540
- loggedInUser,
541
- );
542
- results.updated++;
543
- } catch (error) {
544
- results.failed++;
545
- results.errors.push({
546
- entity_id: record.entity_id,
547
- error: error.message,
548
- });
549
- console.error(
550
- `Failed to update entity ${record.entity_id}:`,
551
- error,
552
- );
553
- }
554
- }
555
-
556
- // Log progress
557
- console.log(
558
- `Backfill progress: ${Math.min(i + batchSize, results.total)}/${results.total}`,
559
- );
560
- }
561
-
562
- return results;
563
- }
564
-
565
- /**
566
- * Backfill all linked attributes for an entity type
567
- * @param mapped_entity_type - Entity type to backfill
568
- * @param loggedInUser - Current user context
569
- * @returns Summary of backfill operation
570
- */
571
- async backfillAllForEntity(
572
- mapped_entity_type: string,
573
- loggedInUser: any,
574
- ): Promise<{ updated: number; failed: number }> {
575
- // Get all entities of this type
576
- const entityJsonRecords = await this.dataSource
577
- .getRepository(EntityJson)
578
- .createQueryBuilder('ej')
579
- .select(['ej.entity_id'])
580
- .where('ej.entity_type = :entityType', { entityType: mapped_entity_type })
581
- .andWhere('ej.organization_id = :orgId', {
582
- orgId: loggedInUser.organization_id,
583
- })
584
- .getMany();
585
-
586
- const batchSize = 100;
587
- const results = {
588
- updated: 0,
589
- failed: 0,
590
- };
591
-
592
- for (let i = 0; i < entityJsonRecords.length; i += batchSize) {
593
- const batch = entityJsonRecords.slice(i, i + batchSize);
594
-
595
- for (const record of batch) {
596
- try {
597
- await this.entityJsonService.updateEntityJSON(
598
- mapped_entity_type,
599
- record.entity_id,
600
- loggedInUser,
601
- );
602
- results.updated++;
603
- } catch (error) {
604
- results.failed++;
605
- console.error(
606
- `Failed to update entity ${record.entity_id}:`,
607
- error,
608
- );
609
- }
610
- }
611
-
612
- // Log progress
613
- console.log(
614
- `Backfill all progress: ${Math.min(i + batchSize, entityJsonRecords.length)}/${entityJsonRecords.length}`,
615
- );
616
- }
617
-
618
- return results;
619
- }
620
75
  }
@@ -6,5 +6,7 @@ export class EntityTableDto extends EntityTable {
6
6
  operation_list: {};
7
7
  default_filter: {} | null;
8
8
  saved_filter: { label: string; value: number }[] | null;
9
- shared_filter: { label: string; value: number }[] | null;
9
+ // shared_filter: { label: string; value: number }[] | null;
10
+ shared_filter: any[] | null;
11
+ // saved_filter: any[] | null;
10
12
  }
@@ -129,6 +129,17 @@ export class MediaDataService extends EntityServiceImpl {
129
129
  jpg: 'image/jpeg',
130
130
  jpeg: 'image/jpeg',
131
131
  png: 'image/png',
132
+ gif: 'image/gif',
133
+ webp: 'image/webp',
134
+ txt: 'text/plain',
135
+ html: 'text/html',
136
+ htm: 'text/html',
137
+ doc: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
138
+ docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
139
+ xls: 'application/vnd.ms-excel',
140
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
141
+ ppt: 'application/vnd.ms-powerpoint',
142
+ pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
132
143
  };
133
144
  return map[ext] || 'application/octet-stream';
134
145
  }
@@ -171,7 +182,6 @@ export class MediaDataService extends EntityServiceImpl {
171
182
  }
172
183
  }
173
184
 
174
- // media-data.service.ts
175
185
  async getMediaInlineUrl(id: number, loggedInUser, expiresIn?: number) {
176
186
  try {
177
187
  const entityData = await this.getEntityData(
@@ -181,6 +191,13 @@ export class MediaDataService extends EntityServiceImpl {
181
191
  );
182
192
  const mediaData = entityData as MediaData;
183
193
  let fileSize: number | undefined;
194
+
195
+ if (!mediaData) {
196
+ throw new Error('Media not found');
197
+ }
198
+
199
+ const ext = mediaData.file_name.split('.').pop()?.toLowerCase() || '';
200
+
184
201
  if (this.bucketName) {
185
202
  const head = await this.s3
186
203
  .headObject({
@@ -191,22 +208,23 @@ export class MediaDataService extends EntityServiceImpl {
191
208
  fileSize = head.ContentLength;
192
209
  }
193
210
 
194
- if (!mediaData) {
195
- throw new Error('Media not found');
196
- }
197
-
198
211
  const signedUrl = await this.s3.getSignedUrlPromise('getObject', {
199
212
  Bucket: this.bucketName,
200
213
  Key: mediaData.media_url,
201
214
  Expires: Number(expiresIn) || 60 * 5,
202
215
  ResponseContentDisposition: 'inline',
203
- ResponseContentType: this.getContentType(
204
- mediaData.file_name.split('.').pop() || '',
205
- ),
216
+ ResponseContentType: this.getContentType(ext),
206
217
  });
207
218
 
219
+ let previewUrl = signedUrl;
220
+ // if (ext === 'doc' || ext === 'docx') {
221
+ // previewUrl =
222
+ // `https://view.officeapps.live.com/op/embed.aspx?src=` +
223
+ // encodeURIComponent(signedUrl);
224
+ // }
225
+
208
226
  return {
209
- signedUrl,
227
+ signedUrl: previewUrl,
210
228
  fileName: mediaData.file_name,
211
229
  id: mediaData.id,
212
230
  size: fileSize,
@@ -36,23 +36,19 @@ export class ActionService extends EntityServiceImpl {
36
36
  }
37
37
 
38
38
  let actionResourceMappingRepo = this.reflectionHelper.getRepoService('ActionResourcesMapping');
39
- await actionResourceMappingRepo.find({
40
- where: {},
41
- });
42
39
 
43
40
  const result = await actionResourceMappingRepo
44
41
  .createQueryBuilder('arm')
42
+ .leftJoin(
43
+ 'frm_wf_stage_action_mapping',
44
+ 'sam',
45
+ 'sam.id = arm.stg_act_mapping_id'
46
+ )
45
47
  .select([
46
48
  'arm.template_code AS template_code',
47
49
  'arm.form_id AS form_id',
48
50
  ])
49
- .where(`arm.stg_act_mapping_id IN (
50
- SELECT sam.id
51
- FROM frm_wf_stage_action_mapping sam
52
- WHERE sam.action_id = :actionId
53
- AND sam.entity_type = 'WFSA'
54
- )`)
55
- .setParameter('actionId', actionData.id)
51
+ .where('sam.action_id = :actionId', { actionId: actionData.id })
56
52
  .getRawMany();
57
53
 
58
54
  const templates = result
@@ -3,7 +3,6 @@ import { WidgetMaster } from './module/dashboard/entity/widget_master.entity';
3
3
  import { EnterpriseData } from './module/enterprise/entity/enterprise.entity';
4
4
  import { OrganizationAppMapping } from './module/enterprise/entity/organization-app-mapping.entity';
5
5
  import { OrganizationData } from './module/enterprise/entity/organization.entity';
6
- import { EntityJson } from './module/entity_json/entity/entityJson.entity';
7
6
  import { SavedFilterDetail } from './module/filter/entity/saved-filter-detail.entity';
8
7
  import { SavedFilterMaster } from './module/filter/entity/saved-filter-master.entity';
9
8
  import { IntegrationConfig } from './module/integration/entity/integration-config.entity';
@@ -88,7 +87,6 @@ export const frameworkTables = [
88
87
  UserIntegration,
89
88
  ViewMaster,
90
89
  LinkedAttributes,
91
- EntityJson
92
90
  ];
93
91
 
94
92
  export const workflowTables = [
@@ -1,6 +0,0 @@
1
- import { MigrationInterface, QueryRunner } from 'typeorm';
2
- export declare class AddEntityJsonGinIndex1732612800000 implements MigrationInterface {
3
- name: string;
4
- up(queryRunner: QueryRunner): Promise<void>;
5
- down(queryRunner: QueryRunner): Promise<void>;
6
- }