rez_core 5.0.11 → 5.0.13
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/dist/module/meta/service/entity-dynamic.service.js +126 -150
- package/dist/module/meta/service/entity-dynamic.service.js.map +1 -1
- package/dist/module/meta/service/entity-service-impl.service.js +2 -2
- package/dist/module/meta/service/entity-service-impl.service.js.map +1 -1
- package/dist/module/workflow/service/action-template-mapping.service.js +3 -3
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/meta/service/entity-dynamic.service.ts +182 -197
- package/src/module/meta/service/entity-service-impl.service.ts +3 -3
- package/src/module/workflow/service/action-template-mapping.service.ts +3 -3
package/package.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { level } from 'winston';
|
|
2
1
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
3
|
-
import {
|
|
4
|
-
ENTITYTYPE_ENTITYMASTER,
|
|
5
|
-
STATUS_ACTIVE,
|
|
6
|
-
} from 'src/constant/global.constant';
|
|
2
|
+
import { STATUS_ACTIVE } from 'src/constant/global.constant';
|
|
7
3
|
import { DataSource } from 'typeorm';
|
|
8
4
|
import { UserData } from 'src/module/user/entity/user.entity';
|
|
9
5
|
import { MediaDataService } from './media-data.service';
|
|
10
6
|
import { ResolverService } from './resolver.service';
|
|
11
7
|
import { ConfigService } from '@nestjs/config';
|
|
12
|
-
import { EntityMasterService } from './entity-master.service';
|
|
13
8
|
import { EntityMasterRepository } from '../repository/entity-master.repository';
|
|
14
9
|
|
|
15
10
|
@Injectable()
|
|
@@ -20,7 +15,8 @@ export class EntityDynamicService {
|
|
|
20
15
|
private readonly resolverService: ResolverService,
|
|
21
16
|
private readonly configService: ConfigService,
|
|
22
17
|
private readonly entityMasterRepo: EntityMasterRepository,
|
|
23
|
-
) {
|
|
18
|
+
) {
|
|
19
|
+
}
|
|
24
20
|
|
|
25
21
|
// -----------------------------
|
|
26
22
|
async createEntity(
|
|
@@ -32,120 +28,124 @@ export class EntityDynamicService {
|
|
|
32
28
|
const organizationId = loggedInUser.organization_id;
|
|
33
29
|
|
|
34
30
|
const tableName = await this.getTableName(entityType, organizationId);
|
|
35
|
-
const validAttributes = await this.getAttributeCodes(
|
|
36
|
-
entityType,
|
|
37
|
-
organizationId,
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const statusList = await this.dataSource.query(
|
|
41
|
-
`SELECT id FROM frm_list_master_items WHERE code = $1 AND organization_id = $2`,
|
|
42
|
-
[STATUS_ACTIVE, loggedInUser?.organization_id || 0],
|
|
43
|
-
);
|
|
31
|
+
const validAttributes = await this.getAttributeCodes(entityType, organizationId);
|
|
44
32
|
|
|
33
|
+
// -------------------------------------------------------
|
|
34
|
+
// AUTO fields
|
|
35
|
+
// -------------------------------------------------------
|
|
45
36
|
entityData.created_date = new Date();
|
|
37
|
+
|
|
46
38
|
if (loggedInUser) {
|
|
47
39
|
entityData.created_by = loggedInUser.id;
|
|
40
|
+
|
|
48
41
|
if (!entityData.organization_id)
|
|
49
42
|
entityData.organization_id = loggedInUser.organization_id;
|
|
43
|
+
|
|
50
44
|
if (!entityData.enterprise_id)
|
|
51
45
|
entityData.enterprise_id = loggedInUser.enterprise_id;
|
|
46
|
+
|
|
52
47
|
if (!entityData.level_type)
|
|
53
48
|
entityData.level_type = loggedInUser.level_type;
|
|
54
|
-
|
|
55
|
-
if (!entityData.
|
|
56
|
-
|
|
49
|
+
|
|
50
|
+
if (!entityData.level_id)
|
|
51
|
+
entityData.level_id = loggedInUser.level_id;
|
|
52
|
+
|
|
53
|
+
if (!entityData.entity_type)
|
|
54
|
+
entityData.entity_type = entityType;
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
// -------------------------------------------------------
|
|
58
|
+
// STATUS
|
|
59
|
+
// -------------------------------------------------------
|
|
60
|
+
const statusList = await this.dataSource.query(
|
|
61
|
+
`
|
|
62
|
+
SELECT id
|
|
63
|
+
FROM frm_list_master_items
|
|
64
|
+
WHERE code = $1
|
|
65
|
+
AND organization_id = $2
|
|
66
|
+
`,
|
|
67
|
+
[STATUS_ACTIVE, organizationId],
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
if (!entityData.status) entityData.status = statusList[0]?.id;
|
|
71
|
+
|
|
72
|
+
// -------------------------------------------------------
|
|
73
|
+
// AUTO-CODE GENERATION (POSTGRES SAFE)
|
|
74
|
+
// -------------------------------------------------------
|
|
75
|
+
if (!entityData.code && entityData.entity_type) {
|
|
76
|
+
// Extract integer suffix
|
|
60
77
|
const result = await this.dataSource.query(
|
|
61
|
-
`
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
`
|
|
79
|
+
SELECT MAX(id) AS max_seq_no
|
|
80
|
+
FROM ${tableName}
|
|
81
|
+
WHERE entity_type = $1
|
|
82
|
+
`,
|
|
64
83
|
[entityData.entity_type],
|
|
65
84
|
);
|
|
66
85
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
maxSeqNo += 1;
|
|
71
|
-
entityData.code = `${entityData.entity_type}${maxSeqNo}`;
|
|
86
|
+
let maxSeq = Number(result?.[0]?.max_seq_no) || 0;
|
|
87
|
+
maxSeq++;
|
|
88
|
+
entityData.code = `${entityData.entity_type}${maxSeq}`;
|
|
72
89
|
}
|
|
73
90
|
|
|
74
|
-
//
|
|
91
|
+
// -------------------------------------------------------
|
|
92
|
+
// Parent ID
|
|
93
|
+
// -------------------------------------------------------
|
|
75
94
|
if (mainID) {
|
|
76
95
|
entityData.parent_id = mainID;
|
|
77
96
|
}
|
|
78
97
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
attribute_key: 'organization_id',
|
|
94
|
-
db_datatype: 'datetime',
|
|
95
|
-
element_type: 'date',
|
|
96
|
-
is_hidden: false,
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
attribute_key: 'enterprise_id',
|
|
100
|
-
db_datatype: 'int',
|
|
101
|
-
element_type: 'number',
|
|
102
|
-
is_hidden: false,
|
|
103
|
-
},
|
|
104
|
-
{ attribute_key: 'level_type', db_datatype: 'int', element_type: 'text', is_hidden: false },
|
|
105
|
-
{ attribute_key: 'level_id', db_datatype: 'int', element_type: 'number', is_hidden: false },
|
|
106
|
-
{ attribute_key: 'status', db_datatype: 'varchar', element_type: 'text', is_hidden: false },
|
|
107
|
-
{
|
|
108
|
-
attribute_key: 'entity_type',
|
|
109
|
-
db_datatype: 'varchar',
|
|
110
|
-
element_type: 'text',
|
|
111
|
-
is_hidden: false,
|
|
112
|
-
},
|
|
113
|
-
{ attribute_key: 'code', db_datatype: 'varchar', element_type: 'text', is_hidden: false },
|
|
114
|
-
{
|
|
115
|
-
attribute_key: 'parent_id',
|
|
116
|
-
db_datatype: 'int',
|
|
117
|
-
element_type: 'number',
|
|
118
|
-
is_hidden: false,
|
|
119
|
-
},
|
|
98
|
+
// -------------------------------------------------------
|
|
99
|
+
// BYPASS COLUMNS
|
|
100
|
+
// -------------------------------------------------------
|
|
101
|
+
const bypassColumns = [
|
|
102
|
+
'created_date',
|
|
103
|
+
'created_by',
|
|
104
|
+
'organization_id',
|
|
105
|
+
'enterprise_id',
|
|
106
|
+
'level_type',
|
|
107
|
+
'level_id',
|
|
108
|
+
'status',
|
|
109
|
+
'entity_type',
|
|
110
|
+
'code',
|
|
111
|
+
'parent_id',
|
|
120
112
|
];
|
|
121
113
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
114
|
+
for (const col of bypassColumns) {
|
|
115
|
+
if (!validAttributes.some(a => a.attribute_key === col)) {
|
|
116
|
+
validAttributes.push({
|
|
117
|
+
attribute_key: col,
|
|
118
|
+
is_hidden: false,
|
|
119
|
+
db_datatype: 'text',
|
|
120
|
+
element_type: 'text',
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
130
124
|
|
|
125
|
+
// -------------------------------------------------------
|
|
126
|
+
// BUILD INSERT QUERY (POSTGRES FORMAT)
|
|
127
|
+
// -------------------------------------------------------
|
|
131
128
|
const columns: string[] = [];
|
|
132
129
|
const values: any[] = [];
|
|
130
|
+
let idx = 1;
|
|
131
|
+
const placeholders: string[] = [];
|
|
133
132
|
|
|
134
|
-
|
|
133
|
+
for (const attr of validAttributes) {
|
|
135
134
|
columns.push(attr.attribute_key);
|
|
136
|
-
values.push(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
: null,
|
|
140
|
-
);
|
|
141
|
-
});
|
|
135
|
+
values.push(entityData[attr.attribute_key] ?? null);
|
|
136
|
+
placeholders.push(`$${idx++}`);
|
|
137
|
+
}
|
|
142
138
|
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const insertQuery = `INSERT INTO \`${tableName}\` (${escapedColumns}) VALUES (${placeholders})`;
|
|
139
|
+
const colList = columns.map(c => `"${c}"`).join(', ');
|
|
140
|
+
const placeholderList = placeholders.join(', ');
|
|
146
141
|
|
|
147
|
-
const
|
|
148
|
-
|
|
142
|
+
const sql = `
|
|
143
|
+
INSERT INTO ${tableName} (${colList})
|
|
144
|
+
VALUES (${placeholderList}) RETURNING id
|
|
145
|
+
`;
|
|
146
|
+
|
|
147
|
+
const result = await this.dataSource.query(sql, values);
|
|
148
|
+
return result[0];
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// ----------------------------- get entity with relations
|
|
@@ -159,7 +159,10 @@ export class EntityDynamicService {
|
|
|
159
159
|
const organizationId = loggedInUser.organization_id;
|
|
160
160
|
|
|
161
161
|
const getRelation = await this.dataSource.query(
|
|
162
|
-
`SELECT *
|
|
162
|
+
`SELECT *
|
|
163
|
+
FROM frm_entity_relation
|
|
164
|
+
WHERE organization_id = $1
|
|
165
|
+
AND source_entity_type = $2`,
|
|
163
166
|
[organizationId, entityType],
|
|
164
167
|
);
|
|
165
168
|
|
|
@@ -200,7 +203,9 @@ export class EntityDynamicService {
|
|
|
200
203
|
);
|
|
201
204
|
|
|
202
205
|
await this.dataSource.query(
|
|
203
|
-
`INSERT INTO frm_entity_relation_data (organization_id, source_entity_id, source_entity_type,
|
|
206
|
+
`INSERT INTO frm_entity_relation_data (organization_id, source_entity_id, source_entity_type,
|
|
207
|
+
target_entity_id, target_entity_type, relation_type)
|
|
208
|
+
VALUES ($1, $2, $3, $4, $5, $6)`,
|
|
204
209
|
[
|
|
205
210
|
organizationId,
|
|
206
211
|
mainID,
|
|
@@ -236,8 +241,10 @@ export class EntityDynamicService {
|
|
|
236
241
|
);
|
|
237
242
|
|
|
238
243
|
const relatedEntities = await this.dataSource.query(
|
|
239
|
-
`SELECT *
|
|
240
|
-
|
|
244
|
+
`SELECT *
|
|
245
|
+
FROM frm_entity_relation_data
|
|
246
|
+
WHERE source_entity_id = $1
|
|
247
|
+
AND target_entity_type IN (SELECT target_entity_type FROM frm_entity_relation WHERE source_entity_type = $2)`,
|
|
241
248
|
[id, entityType],
|
|
242
249
|
);
|
|
243
250
|
|
|
@@ -308,7 +315,10 @@ export class EntityDynamicService {
|
|
|
308
315
|
|
|
309
316
|
if (mappedEntities) {
|
|
310
317
|
const getRelationDefs = await this.dataSource.query(
|
|
311
|
-
`SELECT *
|
|
318
|
+
`SELECT *
|
|
319
|
+
FROM frm_entity_relation
|
|
320
|
+
WHERE organization_id = $1
|
|
321
|
+
AND source_entity_type = $2`,
|
|
312
322
|
[organizationId, entityType],
|
|
313
323
|
);
|
|
314
324
|
|
|
@@ -327,7 +337,11 @@ export class EntityDynamicService {
|
|
|
327
337
|
|
|
328
338
|
// Delete previous relations and related entities
|
|
329
339
|
const existingRelationsForType = await this.dataSource.query(
|
|
330
|
-
`SELECT *
|
|
340
|
+
`SELECT *
|
|
341
|
+
FROM frm_entity_relation_data
|
|
342
|
+
WHERE source_entity_type = $1
|
|
343
|
+
AND source_entity_id = $2
|
|
344
|
+
AND target_entity_type = $3`,
|
|
331
345
|
[entityType, id, targetEntityType],
|
|
332
346
|
);
|
|
333
347
|
|
|
@@ -384,9 +398,10 @@ export class EntityDynamicService {
|
|
|
384
398
|
|
|
385
399
|
// Insert relation as per new entity created
|
|
386
400
|
await this.dataSource.query(
|
|
387
|
-
`INSERT INTO frm_entity_relation_data
|
|
388
|
-
|
|
389
|
-
|
|
401
|
+
`INSERT INTO frm_entity_relation_data
|
|
402
|
+
(organization_id, source_entity_id, source_entity_type, target_entity_id, target_entity_type,
|
|
403
|
+
relation_type)
|
|
404
|
+
VALUES ($1, $2, $3, $4, $5, $6)`,
|
|
390
405
|
[
|
|
391
406
|
organizationId,
|
|
392
407
|
id,
|
|
@@ -435,100 +450,59 @@ export class EntityDynamicService {
|
|
|
435
450
|
const organizationId = loggedInUser.organization_id;
|
|
436
451
|
|
|
437
452
|
const tableName = await this.getTableName(entityType, organizationId);
|
|
438
|
-
const validAttributes = await this.getAttributeCodes(
|
|
439
|
-
entityType,
|
|
440
|
-
organizationId,
|
|
441
|
-
);
|
|
453
|
+
const validAttributes = await this.getAttributeCodes(entityType, organizationId);
|
|
442
454
|
|
|
443
455
|
const updates: string[] = [];
|
|
444
456
|
const values: any[] = [];
|
|
457
|
+
let idx = 1;
|
|
445
458
|
|
|
459
|
+
// Auto fields
|
|
446
460
|
entityData.modified_date = new Date();
|
|
447
461
|
if (loggedInUser) {
|
|
448
462
|
entityData.modified_by = loggedInUser.id;
|
|
463
|
+
|
|
449
464
|
if (!entityData.organization_id && entityData.entity_type !== 'ORG')
|
|
450
465
|
entityData.organization_id = loggedInUser.organization_id;
|
|
466
|
+
|
|
451
467
|
if (!entityData.enterprise_id)
|
|
452
468
|
entityData.enterprise_id = loggedInUser.enterprise_id;
|
|
453
469
|
}
|
|
454
470
|
|
|
455
|
-
// Set parent_id if mainID is provided
|
|
456
471
|
if (mainID) {
|
|
457
472
|
entityData.parent_id = mainID;
|
|
458
473
|
}
|
|
459
474
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
attribute_key: 'modified_date',
|
|
475
|
-
db_datatype: 'datetime',
|
|
476
|
-
element_type: 'date',
|
|
477
|
-
is_hidden: false,
|
|
478
|
-
},
|
|
479
|
-
{
|
|
480
|
-
attribute_key: 'modified_by',
|
|
481
|
-
db_datatype: 'int',
|
|
482
|
-
element_type: 'number',
|
|
483
|
-
is_hidden: false,
|
|
484
|
-
},
|
|
485
|
-
{
|
|
486
|
-
attribute_key: 'organization_id',
|
|
487
|
-
db_datatype: 'int',
|
|
488
|
-
element_type: 'number',
|
|
489
|
-
is_hidden: false,
|
|
490
|
-
},
|
|
491
|
-
{
|
|
492
|
-
attribute_key: 'enterprise_id',
|
|
493
|
-
db_datatype: 'int',
|
|
494
|
-
element_type: 'number',
|
|
495
|
-
is_hidden: false,
|
|
496
|
-
},
|
|
497
|
-
{
|
|
498
|
-
attribute_key: 'level_type',
|
|
499
|
-
db_datatype: 'varchar',
|
|
500
|
-
element_type: 'text',
|
|
501
|
-
is_hidden: false,
|
|
502
|
-
},
|
|
503
|
-
{ attribute_key: 'level_id', db_datatype: 'int', element_type: 'number', is_hidden: false },
|
|
504
|
-
{ attribute_key: 'status', db_datatype: 'varchar', element_type: 'text', is_hidden: false },
|
|
505
|
-
{
|
|
506
|
-
attribute_key: 'entity_type',
|
|
507
|
-
db_datatype: 'varchar',
|
|
508
|
-
element_type: 'text',
|
|
509
|
-
is_hidden: false,
|
|
510
|
-
},
|
|
511
|
-
{ attribute_key: 'code', db_datatype: 'varchar', element_type: 'text', is_hidden: false },
|
|
512
|
-
{
|
|
513
|
-
attribute_key: 'parent_id',
|
|
514
|
-
db_datatype: 'int',
|
|
515
|
-
element_type: 'number',
|
|
516
|
-
is_hidden: false,
|
|
517
|
-
},
|
|
475
|
+
// Add bypass columns if needed
|
|
476
|
+
const bypassColumns = [
|
|
477
|
+
'created_date',
|
|
478
|
+
'created_by',
|
|
479
|
+
'modified_date',
|
|
480
|
+
'modified_by',
|
|
481
|
+
'organization_id',
|
|
482
|
+
'enterprise_id',
|
|
483
|
+
'level_type',
|
|
484
|
+
'level_id',
|
|
485
|
+
'status',
|
|
486
|
+
'entity_type',
|
|
487
|
+
'code',
|
|
488
|
+
'parent_id',
|
|
518
489
|
];
|
|
519
490
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
491
|
+
for (const col of bypassColumns) {
|
|
492
|
+
if (!validAttributes.some((attr) => attr.attribute_key === col)) {
|
|
493
|
+
validAttributes.push({
|
|
494
|
+
attribute_key: col,
|
|
495
|
+
db_datatype: 'text',
|
|
496
|
+
element_type: 'text',
|
|
497
|
+
is_hidden: false,
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
}
|
|
528
501
|
|
|
502
|
+
// Build SET clause
|
|
529
503
|
for (const key of Object.keys(entityData)) {
|
|
530
504
|
if (validAttributes.some((attr) => attr.attribute_key === key)) {
|
|
531
|
-
updates.push(
|
|
505
|
+
updates.push(`${key} = $${idx++}`);
|
|
532
506
|
values.push(entityData[key]);
|
|
533
507
|
}
|
|
534
508
|
}
|
|
@@ -537,11 +511,17 @@ export class EntityDynamicService {
|
|
|
537
511
|
throw new Error('No valid attributes to update.');
|
|
538
512
|
}
|
|
539
513
|
|
|
540
|
-
|
|
541
|
-
|
|
514
|
+
// WHERE clause placeholder
|
|
515
|
+
const idPlaceholder = `$${idx}`;
|
|
516
|
+
values.push(id);
|
|
542
517
|
|
|
543
|
-
const
|
|
544
|
-
|
|
518
|
+
const updateQuery = `
|
|
519
|
+
UPDATE ${tableName}
|
|
520
|
+
SET ${updates.join(', ')}
|
|
521
|
+
WHERE id = ${idPlaceholder}
|
|
522
|
+
`;
|
|
523
|
+
|
|
524
|
+
return await this.dataSource.query(updateQuery, values);
|
|
545
525
|
}
|
|
546
526
|
|
|
547
527
|
async getEntityByDataSource(
|
|
@@ -564,7 +544,9 @@ export class EntityDynamicService {
|
|
|
564
544
|
const columns = validAttributes
|
|
565
545
|
.map((attr) => `${attr.attribute_key}`)
|
|
566
546
|
.join(', ');
|
|
567
|
-
const selectQuery = `SELECT ${columns}
|
|
547
|
+
const selectQuery = `SELECT ${columns}
|
|
548
|
+
FROM ${dataSource}
|
|
549
|
+
WHERE id = $1`;
|
|
568
550
|
|
|
569
551
|
const result = await this.dataSource.query(selectQuery, [id]);
|
|
570
552
|
if (!result.length) return null;
|
|
@@ -585,15 +567,16 @@ export class EntityDynamicService {
|
|
|
585
567
|
row[attr.attribute_key] =
|
|
586
568
|
row[attr.attribute_key] != null
|
|
587
569
|
? await this.mediaDataService.getMediaDownloadUrl(
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
570
|
+
Number(row[attr.attribute_key]),
|
|
571
|
+
loggedInUser,
|
|
572
|
+
)
|
|
591
573
|
: null;
|
|
592
574
|
}
|
|
593
575
|
}
|
|
594
576
|
|
|
595
577
|
return row;
|
|
596
578
|
}
|
|
579
|
+
|
|
597
580
|
// -----------------------------
|
|
598
581
|
//TODO : make it normal getEntity function make another function if for resolve data
|
|
599
582
|
async getEntity(
|
|
@@ -616,7 +599,9 @@ export class EntityDynamicService {
|
|
|
616
599
|
const columns = validAttributes
|
|
617
600
|
.map((attr) => `${attr.attribute_key}`)
|
|
618
601
|
.join(', ');
|
|
619
|
-
const selectQuery = `SELECT ${columns}
|
|
602
|
+
const selectQuery = `SELECT ${columns}
|
|
603
|
+
FROM ${tableName}
|
|
604
|
+
WHERE id = $1`;
|
|
620
605
|
|
|
621
606
|
const result = await this.dataSource.query(selectQuery, [id]);
|
|
622
607
|
if (!result.length) return null;
|
|
@@ -637,9 +622,9 @@ export class EntityDynamicService {
|
|
|
637
622
|
row[attr.attribute_key] =
|
|
638
623
|
row[attr.attribute_key] != null
|
|
639
624
|
? await this.mediaDataService.getMediaDownloadUrl(
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
625
|
+
Number(row[attr.attribute_key]),
|
|
626
|
+
loggedInUser,
|
|
627
|
+
)
|
|
643
628
|
: null;
|
|
644
629
|
}
|
|
645
630
|
}
|
|
@@ -718,7 +703,9 @@ export class EntityDynamicService {
|
|
|
718
703
|
|
|
719
704
|
const tableName = await this.getTableName(entityType, organizationId);
|
|
720
705
|
|
|
721
|
-
const deleteQuery = `DELETE
|
|
706
|
+
const deleteQuery = `DELETE
|
|
707
|
+
FROM \`${tableName}\`
|
|
708
|
+
WHERE id = $1`;
|
|
722
709
|
const result = await this.dataSource.query(deleteQuery, [id]);
|
|
723
710
|
return result;
|
|
724
711
|
}
|
|
@@ -731,7 +718,9 @@ export class EntityDynamicService {
|
|
|
731
718
|
): Promise<any> {
|
|
732
719
|
const organizationId = loggedInUser.organization_id;
|
|
733
720
|
|
|
734
|
-
let query = `SELECT name as label,mapped_entity_type as value
|
|
721
|
+
let query = `SELECT name as label, mapped_entity_type as value
|
|
722
|
+
FROM frm_entity_master
|
|
723
|
+
WHERE organization_id = $1`;
|
|
735
724
|
const params = [organizationId];
|
|
736
725
|
|
|
737
726
|
if (appcode) {
|
|
@@ -747,26 +736,22 @@ export class EntityDynamicService {
|
|
|
747
736
|
const organizationId = loggedInUser.organization_id;
|
|
748
737
|
|
|
749
738
|
// 1. Get db_table_name from entity master
|
|
750
|
-
const result = await this.dataSource.query(
|
|
751
|
-
`SELECT db_table_name
|
|
752
|
-
FROM frm_entity_master
|
|
753
|
-
WHERE mapped_entity_type = $1 AND organization_id = $2`,
|
|
754
|
-
[entityType, organizationId],
|
|
755
|
-
);
|
|
756
739
|
|
|
757
|
-
|
|
740
|
+
const result = await this.entityMasterRepo.getEntityByMappedEntityType(entityType, organizationId);
|
|
741
|
+
|
|
742
|
+
if (!result) {
|
|
758
743
|
throw new Error(
|
|
759
744
|
`Entity type '${entityType}' not found in frm_entity_master for org '${organizationId}'`,
|
|
760
745
|
);
|
|
761
746
|
}
|
|
762
747
|
|
|
763
|
-
const tableName = result
|
|
748
|
+
const tableName = result.db_table_name;
|
|
764
749
|
|
|
765
750
|
// 2. Get current max sequence number from that table
|
|
766
751
|
const seqResult = await this.dataSource.query(
|
|
767
|
-
`SELECT MAX(
|
|
768
|
-
|
|
769
|
-
|
|
752
|
+
`SELECT MAX(id) AS max_seq_no
|
|
753
|
+
FROM \`${tableName}\`
|
|
754
|
+
WHERE entity_type = $1`,
|
|
770
755
|
[entityType],
|
|
771
756
|
);
|
|
772
757
|
|
|
@@ -824,7 +809,7 @@ export class EntityDynamicService {
|
|
|
824
809
|
|
|
825
810
|
async queryWithSchema(sql: string, params: any[] = []) {
|
|
826
811
|
await this.dataSource.query('BEGIN');
|
|
827
|
-
const schema = this.configService.get<string>('DB_SCHEMA')
|
|
812
|
+
const schema = this.configService.get<string>('DB_SCHEMA');
|
|
828
813
|
await this.dataSource.query(`SET LOCAL search_path TO ${schema}`);
|
|
829
814
|
const result = await this.dataSource.query(sql, params);
|
|
830
815
|
await this.dataSource.query('COMMIT');
|
|
@@ -102,9 +102,9 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
|
|
|
102
102
|
const statusList = await repo.query(
|
|
103
103
|
`SELECT id
|
|
104
104
|
FROM frm_list_master_items
|
|
105
|
-
WHERE code =
|
|
106
|
-
AND organization_id =
|
|
107
|
-
[STATUS_ACTIVE, loggedInUser?.organization_id ||
|
|
105
|
+
WHERE code = $1
|
|
106
|
+
AND organization_id = $2`,
|
|
107
|
+
[STATUS_ACTIVE, loggedInUser?.organization_id || 0],
|
|
108
108
|
);
|
|
109
109
|
|
|
110
110
|
console.log('Status List:', statusList); // Debug log
|
|
@@ -35,7 +35,7 @@ export class ActionTemplateMappingService extends EntityServiceImpl {
|
|
|
35
35
|
SELECT id
|
|
36
36
|
FROM frm_list_master_items
|
|
37
37
|
WHERE organization_id = $1
|
|
38
|
-
AND listtype =
|
|
38
|
+
AND listtype = 'MOD' AND code = $2
|
|
39
39
|
`,
|
|
40
40
|
[loggedInUser.organization_id, 'email'],
|
|
41
41
|
);
|
|
@@ -46,7 +46,7 @@ export class ActionTemplateMappingService extends EntityServiceImpl {
|
|
|
46
46
|
`
|
|
47
47
|
SELECT code as value, name as label , id
|
|
48
48
|
FROM frm_wf_comm_template
|
|
49
|
-
WHERE mode = $1 AND organization_id = $2 AND level_type = $3 AND level_id = $4 AND status IN (SELECT id FROM frm_list_master_items WHERE code =
|
|
49
|
+
WHERE mode = $1 AND organization_id = $2 AND level_type = $3 AND level_id = $4 AND status IN (SELECT id FROM frm_list_master_items WHERE code = 'STATUS_ACTIVE' AND organization_id = $5)
|
|
50
50
|
`,
|
|
51
51
|
[
|
|
52
52
|
modeId,
|
|
@@ -89,7 +89,7 @@ export class ActionTemplateMappingService extends EntityServiceImpl {
|
|
|
89
89
|
`
|
|
90
90
|
SELECT code as value, name as label , id
|
|
91
91
|
FROM frm_wf_comm_template
|
|
92
|
-
WHERE code IN ($1) AND mode = $2 AND organization_id = $3 AND level_type = $4 AND level_id = $5 AND status IN (SELECT id FROM frm_list_master_items WHERE code =
|
|
92
|
+
WHERE code IN ($1) AND mode = $2 AND organization_id = $3 AND level_type = $4 AND level_id = $5 AND status IN (SELECT id FROM frm_list_master_items WHERE code = 'STATUS_ACTIVE' AND organization_id = $6)
|
|
93
93
|
`,
|
|
94
94
|
[
|
|
95
95
|
templateCodes,
|