law-common 10.27.0 → 10.28.0
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/src/api/interface/billing.transaction.create.dto.interface.d.ts +7 -2
- package/dist/src/api/interface/billing.transaction.entity.response.d.ts +24 -1
- package/dist/src/api/interface/billing.transaction.update.dto.interface.d.ts +13 -2
- package/dist/src/constants/entity_constants.d.ts +1 -0
- package/dist/src/constants/entity_constants.js +2 -1
- package/dist/src/entities/enums/billing-transaction-action.enum.d.ts +5 -0
- package/dist/src/entities/enums/billing-transaction-action.enum.js +15 -0
- package/dist/src/entities/enums/billing-transaction-status.enum.d.ts +6 -0
- package/dist/src/entities/enums/billing-transaction-status.enum.js +10 -0
- package/dist/src/entities/index.d.ts +5 -1
- package/dist/src/entities/index.js +5 -2
- package/dist/src/entities/interface/billing-transaction-history.entity.d.ts +7 -0
- package/dist/src/entities/interface/billing-transaction-history.entity.js +2 -0
- package/dist/src/entities/interface/billing.entity.interface.d.ts +1 -0
- package/dist/src/entities/interface/billing_transaction.entity.interface.d.ts +7 -0
- package/dist/src/entities/interface/entity.utils.interface.d.ts +14 -5
- package/dist/src/entities/interface/entity.utils.interface.js +1 -0
- package/dist/src/entities/model/base.entity.model.d.ts +8 -2
- package/dist/src/entities/model/base.entity.model.js +53 -34
- package/dist/src/entities/model/billing-reimbursement-expense.entity.model.d.ts +1 -1
- package/dist/src/entities/model/billing-reimbursement-expense.entity.model.js +1 -1
- package/dist/src/entities/model/billing-timesheet.entity.model.d.ts +1 -1
- package/dist/src/entities/model/billing-timesheet.entity.model.js +1 -1
- package/dist/src/entities/model/billing-transaction.model.d.ts +38 -0
- package/dist/src/entities/model/billing-transaction.model.js +71 -0
- package/dist/src/entities/model/billing.entity.model.d.ts +4 -1
- package/dist/src/entities/model/billing.entity.model.js +9 -0
- package/dist/src/entities/model/entity.model.interface.d.ts +12 -1
- package/dist/src/entities/model/entity.model.interface.js +46 -2
- package/dist/src/entities/model/holiday.entity.model.d.ts +14 -1
- package/dist/src/entities/model/holiday.entity.model.js +26 -42
- package/dist/src/entities/model/leave.entity.model.d.ts +50 -3
- package/dist/src/entities/model/leave.entity.model.js +169 -21
- package/dist/src/entities/model/leave_count.entity.model.d.ts +19 -0
- package/dist/src/entities/model/leave_count.entity.model.js +60 -0
- package/dist/src/utils/entity.flow.util.d.ts +32 -0
- package/dist/src/utils/entity.flow.util.js +83 -0
- package/dist/src/utils/helper.fn.util.d.ts +37 -1
- package/dist/src/utils/helper.fn.util.js +53 -0
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/index.js +2 -0
- package/dist/src/utils/string.util.d.ts +1 -0
- package/dist/src/utils/string.util.js +14 -0
- package/package.json +1 -1
- package/dist/src/entities/func/convert-to-common-entity.func.d.ts +0 -15
- package/dist/src/entities/func/convert-to-common-entity.func.js +0 -24
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPermittedActions = getPermittedActions;
|
|
4
|
+
/**
|
|
5
|
+
* Converts an action or combined action to a value-label pair
|
|
6
|
+
* @param action - The action or combined action key
|
|
7
|
+
* @param actionLabels - Object mapping actions to custom labels
|
|
8
|
+
* @returns Object with label and value
|
|
9
|
+
*/
|
|
10
|
+
function convertToValueLabel(action, actionLabels) {
|
|
11
|
+
return {
|
|
12
|
+
label: actionLabels[action] || action,
|
|
13
|
+
value: action,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Filters actions based on user permissions and visibility conditions
|
|
18
|
+
* @param actionConfig - The actions configuration for the current status
|
|
19
|
+
* @param userPermissions - Array of permissions the user has
|
|
20
|
+
* @param data - Optional function to provide additional visibility conditions
|
|
21
|
+
* @returns Array of permitted action keys
|
|
22
|
+
* @throws Error if multiple permissions are found for a single action
|
|
23
|
+
*/
|
|
24
|
+
function _getPermittedActions(actionConfig, userPermissions, data) {
|
|
25
|
+
return Object.entries(actionConfig)
|
|
26
|
+
.filter(([actionKey, config]) => {
|
|
27
|
+
var _a;
|
|
28
|
+
const actionRequiredPermissions = (_a = config === null || config === void 0 ? void 0 : config.permissions) !== null && _a !== void 0 ? _a : [];
|
|
29
|
+
const matchingPermissions = actionRequiredPermissions.filter((permission) => userPermissions.includes(permission));
|
|
30
|
+
if (matchingPermissions.length > 1) {
|
|
31
|
+
throw new Error(`Multiple permissions found for action ${actionKey}: ${matchingPermissions.join(", ")}`);
|
|
32
|
+
}
|
|
33
|
+
return (matchingPermissions.length > 0 &&
|
|
34
|
+
(!data ||
|
|
35
|
+
!data({})[matchingPermissions[0]] ||
|
|
36
|
+
data({})[matchingPermissions[0]]()));
|
|
37
|
+
})
|
|
38
|
+
.map(([actionKey, _]) => actionKey);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Combines specified actions into a single action if all are present
|
|
42
|
+
* @param permittedActions - Array of permitted action keys
|
|
43
|
+
* @param combineActions - Array of actions to combine
|
|
44
|
+
* @returns Array of action keys, with combined action if applicable
|
|
45
|
+
*/
|
|
46
|
+
function combinePermittedActions(permittedActions, combineActions) {
|
|
47
|
+
if (combineActions.length === 0) {
|
|
48
|
+
return permittedActions;
|
|
49
|
+
}
|
|
50
|
+
const isCombinedActionPresent = combineActions.every((action) => permittedActions.includes(action));
|
|
51
|
+
if (isCombinedActionPresent) {
|
|
52
|
+
const combinedValue = combineActions.join("_");
|
|
53
|
+
return [
|
|
54
|
+
...permittedActions.filter((action) => !combineActions.includes(action)),
|
|
55
|
+
combinedValue,
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
return permittedActions;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Gets available actions for a leave based on current status and user permissions
|
|
62
|
+
* @param entityFlowConfig - The flow configuration for the entity
|
|
63
|
+
* @param currentStatus - The current status of the leave
|
|
64
|
+
* @param userPermissions - Array of permissions the user has
|
|
65
|
+
* @param combineActions - Array of action values to combine into a single action
|
|
66
|
+
* @param actionLabels - Object mapping actions to custom labels
|
|
67
|
+
* @param data - Optional function to provide additional visibility conditions
|
|
68
|
+
* @returns Array of available actions with labels and values
|
|
69
|
+
*/
|
|
70
|
+
function getPermittedActions(entityFlowConfig, currentStatus, userPermissions, combineActions = [], actionLabels = {}, data = (_) => ({})) {
|
|
71
|
+
var _a;
|
|
72
|
+
// Handle invalid inputs
|
|
73
|
+
if (!currentStatus || !entityFlowConfig[currentStatus]) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
const actionConfig = ((_a = entityFlowConfig[currentStatus]) === null || _a === void 0 ? void 0 : _a.actions) || {};
|
|
77
|
+
// Get permitted actions
|
|
78
|
+
const permittedActions = _getPermittedActions(actionConfig, userPermissions, data);
|
|
79
|
+
// Combine actions if specified
|
|
80
|
+
const finalActions = combinePermittedActions(permittedActions, combineActions);
|
|
81
|
+
// Convert to value-label pairs
|
|
82
|
+
return finalActions.map((action) => convertToValueLabel(action, actionLabels));
|
|
83
|
+
}
|
|
@@ -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;
|
|
@@ -403,6 +404,58 @@ function getEntitiesFromSearchV2Response(searchResponseV2, entityEnumKey, Entity
|
|
|
403
404
|
}
|
|
404
405
|
return (((_a = searchResponseV2.relatedEntities[entityEnumKey]) === null || _a === void 0 ? void 0 : _a.baseEntities) || []).map((entity) => Object.assign(new EntityClass(), entity));
|
|
405
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* Recursively searches for entities of a specific type within a nested `relatedEntities` structure.
|
|
409
|
+
*
|
|
410
|
+
* This function traverses the `relatedEntities` tree, looking for a target entity key.
|
|
411
|
+
* When found, it collects all `baseEntities` for that key and instantiates them
|
|
412
|
+
* as instances of the provided `EntityClass`. The function continues to traverse
|
|
413
|
+
* all nested `relatedEntities` recursively, accumulating all matches.
|
|
414
|
+
*
|
|
415
|
+
* @template E - The enum type representing the target entity key (`EntityEnum`).
|
|
416
|
+
* @template T - The corresponding entity type for the target key (`EnumEntityType<E>`).
|
|
417
|
+
*
|
|
418
|
+
* @param relatedEntities - The nested `relatedEntities` structure, typically from a
|
|
419
|
+
* `IBaseEntityServiceResponse`. Can be undefined, in which case an empty array is returned.
|
|
420
|
+
* @param targetKey - The entity key (`EntityEnum`) to search for in the nested structure.
|
|
421
|
+
* @param EntityClass - A constructor function for the entity type `T`. Used to
|
|
422
|
+
* instantiate new objects from the raw base entity data.
|
|
423
|
+
*
|
|
424
|
+
* @returns An array of entities of type `T` found at any level of the nested structure.
|
|
425
|
+
* If no entities are found, an empty array is returned.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```ts
|
|
429
|
+
* const billingEntities = findEntitiesAtAnyLevel(
|
|
430
|
+
* projectUserMappingsOfCurrentUser.relatedEntities,
|
|
431
|
+
* EntityEnum.BILLING,
|
|
432
|
+
* BillingEntity
|
|
433
|
+
* );
|
|
434
|
+
*
|
|
435
|
+
* console.log(billingEntities); // [BillingEntity {...}, BillingEntity {...}]
|
|
436
|
+
* ```
|
|
437
|
+
*
|
|
438
|
+
* @note
|
|
439
|
+
* - This function preserves the type of entities by mapping the raw objects to the provided `EntityClass`.
|
|
440
|
+
* - It can handle deeply nested `relatedEntities` structures.
|
|
441
|
+
*/
|
|
442
|
+
function findEntitiesFromSearchV2RelatedEntities(relatedEntities, targetKey, EntityClass) {
|
|
443
|
+
if (!relatedEntities)
|
|
444
|
+
return [];
|
|
445
|
+
let result = [];
|
|
446
|
+
for (const key of Object.keys(relatedEntities)) {
|
|
447
|
+
const value = relatedEntities[key];
|
|
448
|
+
// If this key is the target and has baseEntities
|
|
449
|
+
if (key === targetKey && (value === null || value === void 0 ? void 0 : value.baseEntities)) {
|
|
450
|
+
result.push(...value.baseEntities.map((entity) => Object.assign(new EntityClass(), entity)));
|
|
451
|
+
}
|
|
452
|
+
// If value has relatedEntities, recurse
|
|
453
|
+
if (value === null || value === void 0 ? void 0 : value.relatedEntities) {
|
|
454
|
+
result.push(...findEntitiesFromSearchV2RelatedEntities(value.relatedEntities, targetKey, EntityClass));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return result;
|
|
458
|
+
}
|
|
406
459
|
/**
|
|
407
460
|
* Checks if two decimal numbers are approximately equal within a given tolerance.
|
|
408
461
|
*
|
package/dist/src/utils/index.js
CHANGED
|
@@ -17,3 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./date.util"), exports);
|
|
18
18
|
__exportStar(require("./helper.fn.util"), exports);
|
|
19
19
|
__exportStar(require("./models/date-code.model.util"), exports);
|
|
20
|
+
__exportStar(require("./string.util"), exports);
|
|
21
|
+
__exportStar(require("./entity.flow.util"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatString(input: string): string;
|
|
@@ -1 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatString = formatString;
|
|
4
|
+
function formatString(input) {
|
|
5
|
+
if (input.includes('_')) {
|
|
6
|
+
return input
|
|
7
|
+
.split('_')
|
|
8
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
9
|
+
.join(' ');
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
// For single-word strings, capitalize the first letter
|
|
13
|
+
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Modify } from "../../misc/interface/modify.interface";
|
|
2
|
-
export declare function ConvertToCommonEntity<T extends {
|
|
3
|
-
createdOn: Date;
|
|
4
|
-
updatedOn: Date;
|
|
5
|
-
}, R extends Modify<T, {
|
|
6
|
-
createdOn: string;
|
|
7
|
-
updatedOn: string;
|
|
8
|
-
}>>(obj: T): R;
|
|
9
|
-
export declare function ConvertApiToEntity<T extends {
|
|
10
|
-
createdOn: string;
|
|
11
|
-
updatedOn: string;
|
|
12
|
-
}, R extends Modify<T, {
|
|
13
|
-
createdOn: Date;
|
|
14
|
-
updatedOn: Date;
|
|
15
|
-
}>>(obj: T): R;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.ConvertToCommonEntity = ConvertToCommonEntity;
|
|
15
|
-
exports.ConvertApiToEntity = ConvertApiToEntity;
|
|
16
|
-
function ConvertToCommonEntity(obj) {
|
|
17
|
-
var _a, _b;
|
|
18
|
-
const { createdOn: _, updatedOn: __ } = obj, objectToAssign = __rest(obj, ["createdOn", "updatedOn"]);
|
|
19
|
-
return Object.assign({ createdOn: (_a = obj.createdOn) === null || _a === void 0 ? void 0 : _a.toISOString(), updatedOn: (_b = obj.updatedOn) === null || _b === void 0 ? void 0 : _b.toISOString() }, objectToAssign);
|
|
20
|
-
}
|
|
21
|
-
function ConvertApiToEntity(obj) {
|
|
22
|
-
const { createdOn: _, updatedOn: __ } = obj, objectToAssign = __rest(obj, ["createdOn", "updatedOn"]);
|
|
23
|
-
return Object.assign({ createdOn: new Date(obj.createdOn), updatedOn: new Date(obj.updatedOn) }, objectToAssign);
|
|
24
|
-
}
|