rez_core 3.1.20 → 3.1.21
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/filter/controller/filter.controller.d.ts +1 -1
- package/dist/module/filter/service/filter.service.d.ts +2 -2
- package/dist/module/filter/service/filter.service.js +12 -1
- package/dist/module/filter/service/filter.service.js.map +1 -1
- package/dist/module/meta/service/resolver.service.d.ts +1 -0
- package/dist/module/meta/service/resolver.service.js +53 -0
- package/dist/module/meta/service/resolver.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/filter/service/filter.service.ts +26 -1
- package/src/module/meta/service/resolver.service.ts +87 -0
package/package.json
CHANGED
|
@@ -585,6 +585,31 @@ const resolvedEntityList = await Promise.all(
|
|
|
585
585
|
),
|
|
586
586
|
);
|
|
587
587
|
|
|
588
|
+
|
|
589
|
+
// 6. Resolve tab values (tab_value field)
|
|
590
|
+
const resolvedTabs = await Promise.all(
|
|
591
|
+
filteredTabs.map(async (tab) => {
|
|
592
|
+
// pick attribute used for tabs
|
|
593
|
+
const tabAttrKey = layout?.attribute || tabs?.columnName;
|
|
594
|
+
|
|
595
|
+
if (!tabAttrKey || tab.tab_value?.toLowerCase() === 'all' || tab.tab_value?.toLowerCase() === 'others') {
|
|
596
|
+
return tab; // skip special cases
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
const resolvedVal = await this.resolverService.getResolvedValue(
|
|
600
|
+
loggedInUser,
|
|
601
|
+
tabAttrKey,
|
|
602
|
+
tab.tab_value,
|
|
603
|
+
entity_type,
|
|
604
|
+
);
|
|
605
|
+
|
|
606
|
+
return {
|
|
607
|
+
...tab,
|
|
608
|
+
tab_value: resolvedVal ?? tab.tab_value,
|
|
609
|
+
};
|
|
610
|
+
}),
|
|
611
|
+
);
|
|
612
|
+
|
|
588
613
|
// Count query (without pagination)
|
|
589
614
|
const countQb = this.dataSource
|
|
590
615
|
.createQueryBuilder()
|
|
@@ -599,7 +624,7 @@ const resolvedEntityList = await Promise.all(
|
|
|
599
624
|
return {
|
|
600
625
|
success: true,
|
|
601
626
|
data: {
|
|
602
|
-
entity_tabs:
|
|
627
|
+
entity_tabs: resolvedTabs,
|
|
603
628
|
entity_list: resolvedEntityList,
|
|
604
629
|
pagination: {
|
|
605
630
|
total,
|
|
@@ -107,4 +107,91 @@ export class ResolverService {
|
|
|
107
107
|
|
|
108
108
|
return resolvedEntityData;
|
|
109
109
|
}
|
|
110
|
+
|
|
111
|
+
async getResolvedValue(
|
|
112
|
+
loggedInUser: UserData,
|
|
113
|
+
attrKey: string,
|
|
114
|
+
rawValue: any,
|
|
115
|
+
entityType: string,
|
|
116
|
+
): Promise<any> {
|
|
117
|
+
if (rawValue === null || rawValue === undefined || rawValue === '') {
|
|
118
|
+
return rawValue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// fetch attribute meta only for the given attributeKey
|
|
122
|
+
const [attr] = await this.dataSource.query(
|
|
123
|
+
`SELECT * FROM cr_attribute_master WHERE mapped_entity_type = ? AND organization_id = ? AND attribute_key = ?`,
|
|
124
|
+
[entityType, loggedInUser.organization_id, attrKey],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if (!attr) return rawValue;
|
|
128
|
+
|
|
129
|
+
// -------- ENTITY data_source_type --------
|
|
130
|
+
if (attr.data_source_type === 'entity') {
|
|
131
|
+
const [entityDef] = await this.dataSource.query(
|
|
132
|
+
`SELECT * FROM cr_entity_master WHERE mapped_entity_type = ? AND organization_id = ?`,
|
|
133
|
+
[attr.datasource_list, loggedInUser.organization_id],
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
if (!entityDef) return rawValue;
|
|
137
|
+
|
|
138
|
+
const tableName = entityDef.db_table_name;
|
|
139
|
+
|
|
140
|
+
if (Array.isArray(rawValue)) {
|
|
141
|
+
const resolvedValues: string[] = [];
|
|
142
|
+
for (const code of rawValue) {
|
|
143
|
+
const query =
|
|
144
|
+
tableName === 'cr_organization'
|
|
145
|
+
? `SELECT * FROM ${tableName} WHERE code = ?`
|
|
146
|
+
: `SELECT * FROM ${tableName} WHERE id = ? AND organization_id = ?`;
|
|
147
|
+
|
|
148
|
+
const params =
|
|
149
|
+
tableName === 'cr_organization'
|
|
150
|
+
? [code]
|
|
151
|
+
: [code, loggedInUser.organization_id];
|
|
152
|
+
|
|
153
|
+
const [item] = await this.dataSource.query(query, params);
|
|
154
|
+
resolvedValues.push(item?.[attr.data_source_attribute] ?? code);
|
|
155
|
+
}
|
|
156
|
+
return resolvedValues;
|
|
157
|
+
} else {
|
|
158
|
+
const query =
|
|
159
|
+
tableName === 'cr_organization'
|
|
160
|
+
? `SELECT * FROM ${tableName} WHERE id = ?`
|
|
161
|
+
: `SELECT * FROM ${tableName} WHERE id = ? AND organization_id = ?`;
|
|
162
|
+
|
|
163
|
+
const params =
|
|
164
|
+
tableName === 'cr_organization'
|
|
165
|
+
? [rawValue]
|
|
166
|
+
: [rawValue, loggedInUser.organization_id];
|
|
167
|
+
|
|
168
|
+
const [item] = await this.dataSource.query(query, params);
|
|
169
|
+
return item?.[attr.data_source_attribute] ?? rawValue;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// -------- MASTER data_source_type --------
|
|
174
|
+
else if (attr.data_source_type === 'master') {
|
|
175
|
+
if (Array.isArray(rawValue)) {
|
|
176
|
+
const resolvedValues: string[] = [];
|
|
177
|
+
for (const code of rawValue) {
|
|
178
|
+
const [item] = await this.dataSource.query(
|
|
179
|
+
`SELECT * FROM cr_list_master_items WHERE id = ? AND organization_id = ?`,
|
|
180
|
+
[code, loggedInUser.organization_id],
|
|
181
|
+
);
|
|
182
|
+
resolvedValues.push(item?.[attr.data_source_attribute] ?? code);
|
|
183
|
+
}
|
|
184
|
+
return resolvedValues;
|
|
185
|
+
} else {
|
|
186
|
+
const [item] = await this.dataSource.query(
|
|
187
|
+
`SELECT * FROM cr_list_master_items WHERE id = ? AND organization_id = ?`,
|
|
188
|
+
[rawValue, loggedInUser.organization_id],
|
|
189
|
+
);
|
|
190
|
+
return item?.[attr.data_source_attribute] ?? rawValue;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return rawValue;
|
|
195
|
+
}
|
|
196
|
+
|
|
110
197
|
}
|