law-common 10.19.1-beta.6 → 10.19.1-beta.8
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.
|
@@ -245,7 +245,7 @@ BillingEntityModel.relationConfigs = [
|
|
|
245
245
|
},
|
|
246
246
|
{
|
|
247
247
|
name: entity_utils_interface_1.EntityEnum.BILLING_TRANSACTION,
|
|
248
|
-
relation: relation_type_enum_1.RelationType.
|
|
248
|
+
relation: relation_type_enum_1.RelationType.MANY,
|
|
249
249
|
key: "billingTransactions",
|
|
250
250
|
mapKeyConfig: {
|
|
251
251
|
relationKey: "billingId",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityEnum, EnumEntityType, IBaseEntityServiceResponse, IEntityFilterData } from "../entities";
|
|
1
|
+
import { EntityEnum, EnumEntityType, IBaseEntityServiceResponse, IEntityFilterData, IEntityServiceResponse } from "../entities";
|
|
2
2
|
import { Modify } from "../misc";
|
|
3
3
|
export declare function groupByFunction<T, K>(list: T[], keyGetter: (input: T) => K): Map<K, T[]>;
|
|
4
4
|
export declare function groupByOneToOneFunction<T, K>(list: T[], keyGetter: (input: T) => K): Map<K, T>;
|
|
@@ -176,6 +176,42 @@ export declare function transformDate<T extends {
|
|
|
176
176
|
export declare function capitalizeFirstWord(str: string): string;
|
|
177
177
|
export declare function getEntitiesFromSearchV2Response<E extends EntityEnum, // Enum key like EntityEnum.USER, EntityEnum.PROJECT, etc.
|
|
178
178
|
T extends EnumEntityType<E>>(searchResponseV2: IBaseEntityServiceResponse<EnumEntityType<EntityEnum>>, entityEnumKey: E, EntityClass: new () => T): T[];
|
|
179
|
+
/**
|
|
180
|
+
* Recursively searches for entities of a specific type within a nested `relatedEntities` structure.
|
|
181
|
+
*
|
|
182
|
+
* This function traverses the `relatedEntities` tree, looking for a target entity key.
|
|
183
|
+
* When found, it collects all `baseEntities` for that key and instantiates them
|
|
184
|
+
* as instances of the provided `EntityClass`. The function continues to traverse
|
|
185
|
+
* all nested `relatedEntities` recursively, accumulating all matches.
|
|
186
|
+
*
|
|
187
|
+
* @template E - The enum type representing the target entity key (`EntityEnum`).
|
|
188
|
+
* @template T - The corresponding entity type for the target key (`EnumEntityType<E>`).
|
|
189
|
+
*
|
|
190
|
+
* @param relatedEntities - The nested `relatedEntities` structure, typically from a
|
|
191
|
+
* `IBaseEntityServiceResponse`. Can be undefined, in which case an empty array is returned.
|
|
192
|
+
* @param targetKey - The entity key (`EntityEnum`) to search for in the nested structure.
|
|
193
|
+
* @param EntityClass - A constructor function for the entity type `T`. Used to
|
|
194
|
+
* instantiate new objects from the raw base entity data.
|
|
195
|
+
*
|
|
196
|
+
* @returns An array of entities of type `T` found at any level of the nested structure.
|
|
197
|
+
* If no entities are found, an empty array is returned.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* const billingEntities = findEntitiesAtAnyLevel(
|
|
202
|
+
* projectUserMappingsOfCurrentUser.relatedEntities,
|
|
203
|
+
* EntityEnum.BILLING,
|
|
204
|
+
* BillingEntity
|
|
205
|
+
* );
|
|
206
|
+
*
|
|
207
|
+
* console.log(billingEntities); // [BillingEntity {...}, BillingEntity {...}]
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @note
|
|
211
|
+
* - This function preserves the type of entities by mapping the raw objects to the provided `EntityClass`.
|
|
212
|
+
* - It can handle deeply nested `relatedEntities` structures.
|
|
213
|
+
*/
|
|
214
|
+
export declare function findEntitiesFromSearchV2RelatedEntities<E extends EntityEnum, T extends EnumEntityType<E>>(relatedEntities: IEntityServiceResponse | undefined, targetKey: EntityEnum, EntityClass: new () => T): T[];
|
|
179
215
|
/**
|
|
180
216
|
* Checks if two decimal numbers are approximately equal within a given tolerance.
|
|
181
217
|
*
|
|
@@ -33,6 +33,7 @@ exports.createKeyLabelMap = createKeyLabelMap;
|
|
|
33
33
|
exports.transformDate = transformDate;
|
|
34
34
|
exports.capitalizeFirstWord = capitalizeFirstWord;
|
|
35
35
|
exports.getEntitiesFromSearchV2Response = getEntitiesFromSearchV2Response;
|
|
36
|
+
exports.findEntitiesFromSearchV2RelatedEntities = findEntitiesFromSearchV2RelatedEntities;
|
|
36
37
|
exports.areDecimalNumbersEqual = areDecimalNumbersEqual;
|
|
37
38
|
exports.formatIndianNumber = formatIndianNumber;
|
|
38
39
|
exports.findDuplicateIds = findDuplicateIds;
|
|
@@ -399,6 +400,58 @@ function getEntitiesFromSearchV2Response(searchResponseV2, entityEnumKey, Entity
|
|
|
399
400
|
}
|
|
400
401
|
return (((_a = searchResponseV2.relatedEntities[entityEnumKey]) === null || _a === void 0 ? void 0 : _a.baseEntities) || []).map((entity) => Object.assign(new EntityClass(), entity));
|
|
401
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Recursively searches for entities of a specific type within a nested `relatedEntities` structure.
|
|
405
|
+
*
|
|
406
|
+
* This function traverses the `relatedEntities` tree, looking for a target entity key.
|
|
407
|
+
* When found, it collects all `baseEntities` for that key and instantiates them
|
|
408
|
+
* as instances of the provided `EntityClass`. The function continues to traverse
|
|
409
|
+
* all nested `relatedEntities` recursively, accumulating all matches.
|
|
410
|
+
*
|
|
411
|
+
* @template E - The enum type representing the target entity key (`EntityEnum`).
|
|
412
|
+
* @template T - The corresponding entity type for the target key (`EnumEntityType<E>`).
|
|
413
|
+
*
|
|
414
|
+
* @param relatedEntities - The nested `relatedEntities` structure, typically from a
|
|
415
|
+
* `IBaseEntityServiceResponse`. Can be undefined, in which case an empty array is returned.
|
|
416
|
+
* @param targetKey - The entity key (`EntityEnum`) to search for in the nested structure.
|
|
417
|
+
* @param EntityClass - A constructor function for the entity type `T`. Used to
|
|
418
|
+
* instantiate new objects from the raw base entity data.
|
|
419
|
+
*
|
|
420
|
+
* @returns An array of entities of type `T` found at any level of the nested structure.
|
|
421
|
+
* If no entities are found, an empty array is returned.
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```ts
|
|
425
|
+
* const billingEntities = findEntitiesAtAnyLevel(
|
|
426
|
+
* projectUserMappingsOfCurrentUser.relatedEntities,
|
|
427
|
+
* EntityEnum.BILLING,
|
|
428
|
+
* BillingEntity
|
|
429
|
+
* );
|
|
430
|
+
*
|
|
431
|
+
* console.log(billingEntities); // [BillingEntity {...}, BillingEntity {...}]
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* @note
|
|
435
|
+
* - This function preserves the type of entities by mapping the raw objects to the provided `EntityClass`.
|
|
436
|
+
* - It can handle deeply nested `relatedEntities` structures.
|
|
437
|
+
*/
|
|
438
|
+
function findEntitiesFromSearchV2RelatedEntities(relatedEntities, targetKey, EntityClass) {
|
|
439
|
+
if (!relatedEntities)
|
|
440
|
+
return [];
|
|
441
|
+
let result = [];
|
|
442
|
+
for (const key of Object.keys(relatedEntities)) {
|
|
443
|
+
const value = relatedEntities[key];
|
|
444
|
+
// If this key is the target and has baseEntities
|
|
445
|
+
if (key === targetKey && (value === null || value === void 0 ? void 0 : value.baseEntities)) {
|
|
446
|
+
result.push(...value.baseEntities.map((entity) => Object.assign(new EntityClass(), entity)));
|
|
447
|
+
}
|
|
448
|
+
// If value has relatedEntities, recurse
|
|
449
|
+
if (value === null || value === void 0 ? void 0 : value.relatedEntities) {
|
|
450
|
+
result.push(...findEntitiesFromSearchV2RelatedEntities(value.relatedEntities, targetKey, EntityClass));
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return result;
|
|
454
|
+
}
|
|
402
455
|
/**
|
|
403
456
|
* Checks if two decimal numbers are approximately equal within a given tolerance.
|
|
404
457
|
*
|