rez_core 5.0.12 → 5.0.14
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 +56 -75
- package/dist/module/meta/service/entity-dynamic.service.js.map +1 -1
- package/dist/module/workflow/service/action-template-mapping.service.js +5 -5
- package/dist/module/workflow/service/action-template-mapping.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/meta/service/entity-dynamic.service.ts +92 -97
- package/src/module/workflow/service/action-template-mapping.service.ts +5 -5
package/package.json
CHANGED
|
@@ -28,124 +28,124 @@ export class EntityDynamicService {
|
|
|
28
28
|
const organizationId = loggedInUser.organization_id;
|
|
29
29
|
|
|
30
30
|
const tableName = await this.getTableName(entityType, organizationId);
|
|
31
|
-
const validAttributes = await this.getAttributeCodes(
|
|
32
|
-
entityType,
|
|
33
|
-
organizationId,
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const statusList = await this.dataSource.query(
|
|
37
|
-
`SELECT id
|
|
38
|
-
FROM frm_list_master_items
|
|
39
|
-
WHERE code = $1
|
|
40
|
-
AND organization_id = $2`,
|
|
41
|
-
[STATUS_ACTIVE, loggedInUser?.organization_id || 0],
|
|
42
|
-
);
|
|
31
|
+
const validAttributes = await this.getAttributeCodes(entityType, organizationId);
|
|
43
32
|
|
|
33
|
+
// -------------------------------------------------------
|
|
34
|
+
// AUTO fields
|
|
35
|
+
// -------------------------------------------------------
|
|
44
36
|
entityData.created_date = new Date();
|
|
37
|
+
|
|
45
38
|
if (loggedInUser) {
|
|
46
39
|
entityData.created_by = loggedInUser.id;
|
|
40
|
+
|
|
47
41
|
if (!entityData.organization_id)
|
|
48
42
|
entityData.organization_id = loggedInUser.organization_id;
|
|
43
|
+
|
|
49
44
|
if (!entityData.enterprise_id)
|
|
50
45
|
entityData.enterprise_id = loggedInUser.enterprise_id;
|
|
46
|
+
|
|
51
47
|
if (!entityData.level_type)
|
|
52
48
|
entityData.level_type = loggedInUser.level_type;
|
|
53
|
-
|
|
54
|
-
if (!entityData.
|
|
55
|
-
|
|
49
|
+
|
|
50
|
+
if (!entityData.level_id)
|
|
51
|
+
entityData.level_id = loggedInUser.level_id;
|
|
52
|
+
|
|
53
|
+
if (!entityData.entity_type)
|
|
54
|
+
entityData.entity_type = entityType;
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
|
|
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
|
|
59
77
|
const result = await this.dataSource.query(
|
|
60
|
-
`
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
`
|
|
79
|
+
SELECT MAX(id) AS max_seq_no
|
|
80
|
+
FROM ${tableName}
|
|
81
|
+
WHERE entity_type = $1
|
|
82
|
+
`,
|
|
63
83
|
[entityData.entity_type],
|
|
64
84
|
);
|
|
65
85
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
maxSeqNo += 1;
|
|
70
|
-
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}`;
|
|
71
89
|
}
|
|
72
90
|
|
|
73
|
-
//
|
|
91
|
+
// -------------------------------------------------------
|
|
92
|
+
// Parent ID
|
|
93
|
+
// -------------------------------------------------------
|
|
74
94
|
if (mainID) {
|
|
75
95
|
entityData.parent_id = mainID;
|
|
76
96
|
}
|
|
77
97
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
attribute_key: 'organization_id',
|
|
93
|
-
db_datatype: 'datetime',
|
|
94
|
-
element_type: 'date',
|
|
95
|
-
is_hidden: false,
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
attribute_key: 'enterprise_id',
|
|
99
|
-
db_datatype: 'int',
|
|
100
|
-
element_type: 'number',
|
|
101
|
-
is_hidden: false,
|
|
102
|
-
},
|
|
103
|
-
{ attribute_key: 'level_type', db_datatype: 'int', element_type: 'text', is_hidden: false },
|
|
104
|
-
{ attribute_key: 'level_id', db_datatype: 'int', element_type: 'number', is_hidden: false },
|
|
105
|
-
{ attribute_key: 'status', db_datatype: 'varchar', element_type: 'text', is_hidden: false },
|
|
106
|
-
{
|
|
107
|
-
attribute_key: 'entity_type',
|
|
108
|
-
db_datatype: 'varchar',
|
|
109
|
-
element_type: 'text',
|
|
110
|
-
is_hidden: false,
|
|
111
|
-
},
|
|
112
|
-
{ attribute_key: 'code', db_datatype: 'varchar', element_type: 'text', is_hidden: false },
|
|
113
|
-
{
|
|
114
|
-
attribute_key: 'parent_id',
|
|
115
|
-
db_datatype: 'int',
|
|
116
|
-
element_type: 'number',
|
|
117
|
-
is_hidden: false,
|
|
118
|
-
},
|
|
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',
|
|
119
112
|
];
|
|
120
113
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
}
|
|
129
124
|
|
|
125
|
+
// -------------------------------------------------------
|
|
126
|
+
// BUILD INSERT QUERY (POSTGRES FORMAT)
|
|
127
|
+
// -------------------------------------------------------
|
|
130
128
|
const columns: string[] = [];
|
|
131
129
|
const values: any[] = [];
|
|
130
|
+
let idx = 1;
|
|
131
|
+
const placeholders: string[] = [];
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
for (const attr of validAttributes) {
|
|
134
134
|
columns.push(attr.attribute_key);
|
|
135
|
-
values.push(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
: null,
|
|
139
|
-
);
|
|
140
|
-
});
|
|
135
|
+
values.push(entityData[attr.attribute_key] ?? null);
|
|
136
|
+
placeholders.push(`$${idx++}`);
|
|
137
|
+
}
|
|
141
138
|
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const insertQuery = `INSERT INTO ${tableName} (${escapedColumns})
|
|
145
|
-
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
|
|
@@ -736,25 +736,20 @@ export class EntityDynamicService {
|
|
|
736
736
|
const organizationId = loggedInUser.organization_id;
|
|
737
737
|
|
|
738
738
|
// 1. Get db_table_name from entity master
|
|
739
|
-
const result = await this.dataSource.query(
|
|
740
|
-
`SELECT db_table_name
|
|
741
|
-
FROM frm_entity_master
|
|
742
|
-
WHERE mapped_entity_type = $1
|
|
743
|
-
AND organization_id = $2`,
|
|
744
|
-
[entityType, organizationId],
|
|
745
|
-
);
|
|
746
739
|
|
|
747
|
-
|
|
740
|
+
const result = await this.entityMasterRepo.getEntityByMappedEntityType(entityType, organizationId);
|
|
741
|
+
|
|
742
|
+
if (!result) {
|
|
748
743
|
throw new Error(
|
|
749
744
|
`Entity type '${entityType}' not found in frm_entity_master for org '${organizationId}'`,
|
|
750
745
|
);
|
|
751
746
|
}
|
|
752
747
|
|
|
753
|
-
const tableName = result
|
|
748
|
+
const tableName = result.db_table_name;
|
|
754
749
|
|
|
755
750
|
// 2. Get current max sequence number from that table
|
|
756
751
|
const seqResult = await this.dataSource.query(
|
|
757
|
-
`SELECT MAX(
|
|
752
|
+
`SELECT MAX(id) AS max_seq_no
|
|
758
753
|
FROM \`${tableName}\`
|
|
759
754
|
WHERE entity_type = $1`,
|
|
760
755
|
[entityType],
|
|
@@ -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,15 +89,15 @@ 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,
|
|
96
96
|
mode,
|
|
97
97
|
loggedInUser.organization_id,
|
|
98
98
|
loggedInUser.level_type,
|
|
99
|
-
loggedInUser.level_id,
|
|
100
|
-
loggedInUser.organization_id,
|
|
99
|
+
Number(loggedInUser.level_id),
|
|
100
|
+
Number(loggedInUser.organization_id),
|
|
101
101
|
],
|
|
102
102
|
);
|
|
103
103
|
|