law-common 10.19.1-beta.7 → 10.19.1-beta.9
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 +4 -1
- package/dist/src/api/interface/billing.transaction.update.dto.interface.d.ts +3 -0
- package/dist/src/entities/func/convert-to-common-entity.func.js +8 -2
- package/dist/src/entities/index.d.ts +1 -0
- package/dist/src/entities/index.js +1 -0
- package/dist/src/entities/interface/entity.utils.interface.d.ts +6 -3
- package/dist/src/entities/model/base.entity.model.d.ts +8 -2
- package/dist/src/entities/model/base.entity.model.js +43 -35
- package/dist/src/entities/model/entity.model.interface.d.ts +12 -2
- package/dist/src/entities/model/entity.model.interface.js +60 -19
- package/dist/src/entities/model/holiday.entity.model.d.ts +14 -1
- package/dist/src/entities/model/holiday.entity.model.js +25 -42
- package/dist/src/entities/model/leave.entity.model.d.ts +50 -3
- package/dist/src/entities/model/leave.entity.model.js +154 -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
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { BillingTransactionStatusEnum, IBillingTransactionEntity, IEntityCreateDto } from "../../entities";
|
|
1
|
+
import { BillingTransactionStatusEnum, IBillingEntity, IBillingTransactionEntity, IEntityCreateDto } from "../../entities";
|
|
2
2
|
export type IBillingTransactionExclude = "status";
|
|
3
3
|
export interface IBillingTransactionCreateDto extends Omit<IEntityCreateDto<IBillingTransactionEntity>, IBillingTransactionExclude> {
|
|
4
4
|
status?: BillingTransactionStatusEnum;
|
|
5
5
|
}
|
|
6
|
+
export interface IBillingTransactionCreateDtoValidationData {
|
|
7
|
+
billingEntity: IBillingEntity;
|
|
8
|
+
}
|
|
@@ -8,3 +8,6 @@ export interface IBillingTransactionActionDataDto {
|
|
|
8
8
|
export interface IBillingTransactionUpdateDto extends IEntityUpdateDto<IBillingTransactionEntity>, IBillingTransactionSupportingDocsDetails {
|
|
9
9
|
actionData?: IBillingTransactionActionDataDto;
|
|
10
10
|
}
|
|
11
|
+
export interface IBillingTransactionUpdateDtoValidationResult {
|
|
12
|
+
billingTransactionEntity: IBillingTransactionEntity;
|
|
13
|
+
}
|
|
@@ -14,9 +14,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.ConvertToCommonEntity = ConvertToCommonEntity;
|
|
15
15
|
exports.ConvertApiToEntity = ConvertApiToEntity;
|
|
16
16
|
function ConvertToCommonEntity(obj) {
|
|
17
|
-
var _a, _b;
|
|
18
17
|
const { createdOn: _, updatedOn: __ } = obj, objectToAssign = __rest(obj, ["createdOn", "updatedOn"]);
|
|
19
|
-
|
|
18
|
+
const dateTransformerObj = {};
|
|
19
|
+
if (obj.createdOn) {
|
|
20
|
+
dateTransformerObj["createdOn"] = obj.createdOn.toISOString();
|
|
21
|
+
}
|
|
22
|
+
if (obj.updatedOn) {
|
|
23
|
+
dateTransformerObj["updatedOn"] = obj.updatedOn.toISOString();
|
|
24
|
+
}
|
|
25
|
+
return Object.assign(Object.assign({}, dateTransformerObj), objectToAssign);
|
|
20
26
|
}
|
|
21
27
|
function ConvertApiToEntity(obj) {
|
|
22
28
|
const { createdOn: _, updatedOn: __ } = obj, objectToAssign = __rest(obj, ["createdOn", "updatedOn"]);
|
|
@@ -66,6 +66,7 @@ export * from "./interface/intermediary_bank.entity.interface";
|
|
|
66
66
|
export * from "./interface/holiday-list.entity.interface";
|
|
67
67
|
export * from "./interface/holiday.entity.interface";
|
|
68
68
|
export * from "./model/leave.entity.model";
|
|
69
|
+
export * from "./model/leave_count.entity.model";
|
|
69
70
|
export * from "./model/holiday.entity.model";
|
|
70
71
|
export * from "./enums/cron-jobs-name.enum";
|
|
71
72
|
export * from "./enums/cron-jobs-status.enum";
|
|
@@ -83,6 +83,7 @@ __exportStar(require("./interface/intermediary_bank.entity.interface"), exports)
|
|
|
83
83
|
__exportStar(require("./interface/holiday-list.entity.interface"), exports);
|
|
84
84
|
__exportStar(require("./interface/holiday.entity.interface"), exports);
|
|
85
85
|
__exportStar(require("./model/leave.entity.model"), exports);
|
|
86
|
+
__exportStar(require("./model/leave_count.entity.model"), exports);
|
|
86
87
|
__exportStar(require("./model/holiday.entity.model"), exports);
|
|
87
88
|
__exportStar(require("./enums/cron-jobs-name.enum"), exports);
|
|
88
89
|
__exportStar(require("./enums/cron-jobs-status.enum"), exports);
|
|
@@ -11,6 +11,9 @@ import { BillingEntityModel } from "../model/billing.entity.model";
|
|
|
11
11
|
import { ClientAffiliateEntityModel } from "../model/client-affiliate.entity.model";
|
|
12
12
|
import { ClientEntityModel } from "../model/client.entity.model";
|
|
13
13
|
import { ConfigurationEntityModel } from "../model/configuration.model";
|
|
14
|
+
import { HolidayEntityModel } from "../model/holiday.entity.model";
|
|
15
|
+
import { LeaveEntityModel } from "../model/leave.entity.model";
|
|
16
|
+
import { LeaveCountVirtualEntityModel } from "../model/leave_count.entity.model";
|
|
14
17
|
import { ProjectUserMappingEntityModel } from "../model/project-user-mapping.entity.model";
|
|
15
18
|
import { ProjectEntityModel } from "../model/project.entity.model";
|
|
16
19
|
import { ReimbursementExpenseEntityModel } from "../model/reimbursement-expense.entity.model";
|
|
@@ -284,12 +287,12 @@ export declare enum VirtualEntityEnum {
|
|
|
284
287
|
}
|
|
285
288
|
export type IHistoryConstraintSearchResponse<T> = IBaseResponse<IHistoryEntitySearchByConstraintResponse<T>[]>;
|
|
286
289
|
export type IHistoryConstraintSearchServiceResponse<T> = IHistoryEntitySearchByConstraintResponse<T>[];
|
|
287
|
-
export type EnumToModel<T extends EntityEnum | VirtualEntityEnum> = T extends EntityEnum.BILLING ? BillingEntityModel : T extends EntityEnum.CLIENT ? ClientEntityModel : T extends EntityEnum.PROJECT ? ProjectEntityModel : T extends EntityEnum.PROJECT_USER_MAPPING ? ProjectUserMappingEntityModel : T extends EntityEnum.REIMBURSEMENT ? ReimbursementEntityModel : T extends EntityEnum.REIMBURSEMENT_EXPENSE ? ReimbursementExpenseEntityModel : T extends EntityEnum.BILLING_REIMBURSEMENT_EXPENSE ? BillingReimbursementExpneseEntityModel : T extends EntityEnum.CLIENT_AFFILIATE ? ClientAffiliateEntityModel : T extends EntityEnum.BANK ? BankEntityModel : T extends EntityEnum.CONFIGURATION ? ConfigurationEntityModel : T extends EntityEnum.TASK ? TaskEntityModel : T extends EntityEnum.BILLING_TIMESHEET ? BillingTimesheetEntityModel : T extends EntityEnum.TIMESHEET ? TimesheetEntityModel : T extends EntityEnum.BILLING_TRANSACTION ? BillingTransactionEntityModel : UserEntityModel;
|
|
290
|
+
export type EnumToModel<T extends EntityEnum | VirtualEntityEnum> = T extends EntityEnum.BILLING ? BillingEntityModel : T extends EntityEnum.CLIENT ? ClientEntityModel : T extends EntityEnum.PROJECT ? ProjectEntityModel : T extends EntityEnum.PROJECT_USER_MAPPING ? ProjectUserMappingEntityModel : T extends EntityEnum.REIMBURSEMENT ? ReimbursementEntityModel : T extends EntityEnum.REIMBURSEMENT_EXPENSE ? ReimbursementExpenseEntityModel : T extends EntityEnum.BILLING_REIMBURSEMENT_EXPENSE ? BillingReimbursementExpneseEntityModel : T extends EntityEnum.LEAVE ? LeaveEntityModel : T extends EntityEnum.HOLIDAY ? HolidayEntityModel : T extends VirtualEntityEnum.LEAVE_COUNT ? LeaveCountVirtualEntityModel : T extends EntityEnum.CLIENT_AFFILIATE ? ClientAffiliateEntityModel : T extends EntityEnum.BANK ? BankEntityModel : T extends EntityEnum.CONFIGURATION ? ConfigurationEntityModel : T extends EntityEnum.TASK ? TaskEntityModel : T extends EntityEnum.BILLING_TIMESHEET ? BillingTimesheetEntityModel : T extends EntityEnum.TIMESHEET ? TimesheetEntityModel : T extends EntityEnum.BILLING_TRANSACTION ? BillingTransactionEntityModel : UserEntityModel;
|
|
288
291
|
export type EntityMap = {
|
|
289
|
-
[key in EntityEnum]: EnumToModel<key>[];
|
|
292
|
+
[key in EntityEnum | VirtualEntityEnum]: EnumToModel<key>[];
|
|
290
293
|
};
|
|
291
294
|
export type EntityIndexMap = {
|
|
292
|
-
[key in EntityEnum]: {
|
|
295
|
+
[key in EntityEnum | VirtualEntityEnum]: {
|
|
293
296
|
[id: number]: EnumToModel<key>;
|
|
294
297
|
};
|
|
295
298
|
};
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { EntityEnum, EntityIndexMap } from "../interface/entity.utils.interface";
|
|
2
|
-
export declare
|
|
1
|
+
import { EntityEnum, EntityIndexMap, VirtualEntityEnum } from "../interface/entity.utils.interface";
|
|
2
|
+
export declare enum RelationType {
|
|
3
|
+
ONE = "one",
|
|
4
|
+
MANY = "many"
|
|
5
|
+
}
|
|
6
|
+
export declare abstract class BaseEntityModel<T extends EntityEnum | VirtualEntityEnum> {
|
|
3
7
|
protected entityName: T;
|
|
4
8
|
constructor(entityName: T);
|
|
5
9
|
abstract getRelationConfigs(): any[];
|
|
6
10
|
populateRelationsByIndex(entityIndexMap: EntityIndexMap): void;
|
|
7
11
|
static populateRelationsForEntities(entityIndexMap: EntityIndexMap, entityType: EntityEnum): void;
|
|
12
|
+
populateRelations(entityIndexMap: EntityIndexMap): void;
|
|
13
|
+
overwrite(entityIndexMap: EntityIndexMap, indexKey?: string): this;
|
|
8
14
|
}
|
|
@@ -1,58 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseEntityModel = void 0;
|
|
4
|
-
|
|
3
|
+
exports.BaseEntityModel = exports.RelationType = void 0;
|
|
4
|
+
var RelationType;
|
|
5
|
+
(function (RelationType) {
|
|
6
|
+
RelationType["ONE"] = "one";
|
|
7
|
+
RelationType["MANY"] = "many";
|
|
8
|
+
})(RelationType || (exports.RelationType = RelationType = {}));
|
|
5
9
|
class BaseEntityModel {
|
|
6
10
|
constructor(entityName) {
|
|
7
11
|
this.entityName = entityName;
|
|
8
12
|
}
|
|
9
13
|
populateRelationsByIndex(entityIndexMap) {
|
|
10
14
|
for (const relationConfig of this.getRelationConfigs() || []) {
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
const thisMappingKey = relationConfig.mapKeyConfig.key;
|
|
16
|
+
const relatedMappingKey = relationConfig.mapKeyConfig.relationKey;
|
|
17
|
+
const thisKey = relationConfig.key;
|
|
18
|
+
// console.log('Populating relation for', relationConfig.name, 'on', this.entityName, relationConfig);
|
|
19
|
+
// debugger;
|
|
20
|
+
if (relationConfig.relation === RelationType.ONE) {
|
|
13
21
|
const relatedEntities = entityIndexMap[relationConfig.name] || {};
|
|
14
|
-
// @ts-ignore
|
|
15
22
|
let foundRelatedEntities = [];
|
|
16
|
-
if (
|
|
17
|
-
const [parentKey, childKey] =
|
|
18
|
-
|
|
19
|
-
if (this[parentKey] && this[parentKey][childKey]) {
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
foundRelatedEntities = [relatedEntities[this[parentKey][childKey]]];
|
|
22
|
-
}
|
|
23
|
+
if (thisMappingKey.includes(".")) {
|
|
24
|
+
const [parentKey, childKey] = thisMappingKey.split(".");
|
|
25
|
+
foundRelatedEntities = [relatedEntities[this[parentKey][childKey]]];
|
|
23
26
|
}
|
|
24
27
|
else {
|
|
25
|
-
foundRelatedEntities = relatedEntities[
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
// foundRelatedEntities = relatedEntities[this[thisKey]] ? [relatedEntities[this[thisKey]]] : [];
|
|
29
|
+
const relatedEntity = relatedEntities[this[thisMappingKey]];
|
|
30
|
+
if (relatedEntity) {
|
|
31
|
+
foundRelatedEntities = [relatedEntity];
|
|
32
|
+
}
|
|
33
|
+
else if (relatedMappingKey !== "id") {
|
|
34
|
+
foundRelatedEntities = Object.values(relatedEntities).filter((entity) => entity[relatedMappingKey] === this[thisMappingKey]);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
foundRelatedEntities = [];
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
40
|
if (foundRelatedEntities.length > 1) {
|
|
33
41
|
throw new Error(`Expected one related entity for ${relationConfig.name} but found ${foundRelatedEntities.length}`);
|
|
34
42
|
}
|
|
35
43
|
if (foundRelatedEntities.length === 0) {
|
|
36
|
-
console.warn(`No related entity found for ${relationConfig.name} with ${relationConfig.mapKeyConfig.
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
}=${this[relationConfig.mapKeyConfig.foreignKey]}`);
|
|
44
|
+
console.warn(`No related entity found for ${relationConfig.name} with ${thisMappingKey}=${this[relationConfig.mapKeyConfig.foreignKey]}`);
|
|
39
45
|
}
|
|
40
|
-
|
|
41
|
-
this[relationConfig.key] = foundRelatedEntities[0];
|
|
46
|
+
this[thisKey] = foundRelatedEntities[0];
|
|
42
47
|
}
|
|
43
|
-
else if (relationConfig.relation ===
|
|
44
|
-
|
|
45
|
-
this[relationConfig.key] = [];
|
|
46
|
-
// @ts-ignore
|
|
48
|
+
else if (relationConfig.relation === RelationType.MANY) {
|
|
49
|
+
this[thisKey] = [];
|
|
47
50
|
const relatedEntities = entityIndexMap[relationConfig.name] || {};
|
|
48
51
|
for (const relatedEntity of Object.values(relatedEntities)) {
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
relatedEntity[relationConfig.mapKeyConfig.relationKey] ===
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
this[relationConfig.mapKeyConfig.key]) {
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
this[relationConfig.key].push(relatedEntity);
|
|
52
|
+
if (relatedEntity[relatedMappingKey] === this[thisMappingKey]) {
|
|
53
|
+
this[thisKey].push(relatedEntity);
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
56
|
}
|
|
@@ -60,10 +58,20 @@ class BaseEntityModel {
|
|
|
60
58
|
}
|
|
61
59
|
static populateRelationsForEntities(entityIndexMap, entityType) {
|
|
62
60
|
for (const key of Object.keys(entityIndexMap[entityType] || {})) {
|
|
63
|
-
// @ts-ignore
|
|
64
61
|
const entity = entityIndexMap[entityType][key];
|
|
65
62
|
entity.populateRelationsByIndex(entityIndexMap);
|
|
66
63
|
}
|
|
67
64
|
}
|
|
65
|
+
populateRelations(entityIndexMap) {
|
|
66
|
+
this.populateRelationsByIndex(entityIndexMap);
|
|
67
|
+
}
|
|
68
|
+
overwrite(entityIndexMap, indexKey = "id") {
|
|
69
|
+
if (this[indexKey] === undefined) {
|
|
70
|
+
console.warn(`Entity of type ${this.entityName} does not have ${indexKey}, cannot merge`);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
entityIndexMap[this.entityName][this[indexKey]] = this;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
68
76
|
}
|
|
69
77
|
exports.BaseEntityModel = BaseEntityModel;
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
import { EntityEnum, EntityIndexMap, EntityMap, EnumEntityType, IBaseEntityApiResponse } from "../interface/entity.utils.interface";
|
|
1
|
+
import { EntityEnum, EntityIndexMap, EntityMap, EnumEntityType, EnumToModel, IApiEntity, IBaseEntityApiResponse, VirtualEntityEnum } from "../interface/entity.utils.interface";
|
|
2
2
|
export declare function mapToIndex(entityMap: EntityMap): EntityIndexMap;
|
|
3
3
|
export declare function getEntityIndexMap<T extends EntityEnum>(data: IBaseEntityApiResponse<EnumEntityType<T>>, baseEntity: T, reusedConfig?: {
|
|
4
4
|
existingEntityIndexMap: EntityIndexMap;
|
|
5
5
|
enumEntities: EntityEnum[];
|
|
6
6
|
}): EntityIndexMap;
|
|
7
7
|
export declare function populateRelationsFor(entityIndexMap: EntityIndexMap, enumEntities: EntityEnum[]): void;
|
|
8
|
-
export declare
|
|
8
|
+
export declare const entityEnumToEntityModel: {
|
|
9
|
+
[E in EntityEnum | VirtualEntityEnum]?: (json: IApiEntity<EnumEntityType<E>>) => EnumToModel<E>;
|
|
10
|
+
};
|
|
11
|
+
export declare function entityMapToModels(entityMap: EntityMap): void;
|
|
12
|
+
export declare function parseEntities<T extends EnumEntityType<EntityEnum | VirtualEntityEnum>>(json: IBaseEntityApiResponse<T>, baseEntity: EntityEnum | VirtualEntityEnum, entityMap: EntityMap): EntityMap;
|
|
13
|
+
export declare function entityMapToEntityIndexMap(entityMap: EntityMap, entityRelationsFor: EntityEnum[]): EntityIndexMap;
|
|
14
|
+
export declare function parseEntitiesWithoutModels<T extends EnumEntityType<EntityEnum | VirtualEntityEnum>>(json: IBaseEntityApiResponse<T>, baseEntity: EntityEnum | VirtualEntityEnum, entityMap?: {
|
|
15
|
+
[E in EntityEnum | VirtualEntityEnum]?: IApiEntity<EnumEntityType<E>>[];
|
|
16
|
+
}): {
|
|
17
|
+
[E in EntityEnum | VirtualEntityEnum]?: IApiEntity<EnumEntityType<E>>[];
|
|
18
|
+
};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entityEnumToEntityModel = void 0;
|
|
3
4
|
exports.mapToIndex = mapToIndex;
|
|
4
5
|
exports.getEntityIndexMap = getEntityIndexMap;
|
|
5
6
|
exports.populateRelationsFor = populateRelationsFor;
|
|
7
|
+
exports.entityMapToModels = entityMapToModels;
|
|
6
8
|
exports.parseEntities = parseEntities;
|
|
9
|
+
exports.entityMapToEntityIndexMap = entityMapToEntityIndexMap;
|
|
10
|
+
exports.parseEntitiesWithoutModels = parseEntitiesWithoutModels;
|
|
7
11
|
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
8
12
|
const bank_entity_model_1 = require("./bank.entity.model");
|
|
9
13
|
const base_entity_model_1 = require("./base.entity.model");
|
|
@@ -13,6 +17,9 @@ const billing_transaction_model_1 = require("./billing-transaction.model");
|
|
|
13
17
|
const billing_entity_model_1 = require("./billing.entity.model");
|
|
14
18
|
const client_affiliate_entity_model_1 = require("./client-affiliate.entity.model");
|
|
15
19
|
const client_entity_model_1 = require("./client.entity.model");
|
|
20
|
+
const holiday_entity_model_1 = require("./holiday.entity.model");
|
|
21
|
+
const leave_entity_model_1 = require("./leave.entity.model");
|
|
22
|
+
const leave_count_entity_model_1 = require("./leave_count.entity.model");
|
|
16
23
|
const configuration_model_1 = require("./configuration.model");
|
|
17
24
|
const project_user_mapping_entity_model_1 = require("./project-user-mapping.entity.model");
|
|
18
25
|
const project_entity_model_1 = require("./project.entity.model");
|
|
@@ -48,29 +55,41 @@ function populateRelationsFor(entityIndexMap, enumEntities) {
|
|
|
48
55
|
base_entity_model_1.BaseEntityModel.populateRelationsForEntities(entityIndexMap, entity);
|
|
49
56
|
});
|
|
50
57
|
}
|
|
58
|
+
exports.entityEnumToEntityModel = {
|
|
59
|
+
[entity_utils_interface_1.EntityEnum.PROJECT]: project_entity_model_1.ProjectEntityModel.fromApiEntity,
|
|
60
|
+
[entity_utils_interface_1.EntityEnum.CLIENT]: client_entity_model_1.ClientEntityModel.fromApiEntity,
|
|
61
|
+
[entity_utils_interface_1.EntityEnum.BILLING]: billing_entity_model_1.BillingEntityModel.fromApiEntity,
|
|
62
|
+
[entity_utils_interface_1.EntityEnum.USER]: user_entity_model_1.UserEntityModel.fromApiEntity,
|
|
63
|
+
[entity_utils_interface_1.EntityEnum.PROJECT_USER_MAPPING]: project_user_mapping_entity_model_1.ProjectUserMappingEntityModel.fromApiEntity,
|
|
64
|
+
[entity_utils_interface_1.EntityEnum.REIMBURSEMENT]: reimbursement_entity_model_1.ReimbursementEntityModel.fromApiEntity,
|
|
65
|
+
[entity_utils_interface_1.EntityEnum.REIMBURSEMENT_EXPENSE]: reimbursement_expense_entity_model_1.ReimbursementExpenseEntityModel.fromApiEntity,
|
|
66
|
+
[entity_utils_interface_1.EntityEnum.BILLING_REIMBURSEMENT_EXPENSE]: billing_reimbursement_expense_entity_model_1.BillingReimbursementExpneseEntityModel.fromApiEntity,
|
|
67
|
+
[entity_utils_interface_1.EntityEnum.HOLIDAY]: holiday_entity_model_1.HolidayEntityModel.fromApiEntity,
|
|
68
|
+
[entity_utils_interface_1.EntityEnum.LEAVE]: leave_entity_model_1.LeaveEntityModel.fromApiEntity,
|
|
69
|
+
[entity_utils_interface_1.VirtualEntityEnum.LEAVE_COUNT]: leave_count_entity_model_1.LeaveCountVirtualEntityModel.fromApiEntity,
|
|
70
|
+
// Add other entities here as needed
|
|
71
|
+
[entity_utils_interface_1.EntityEnum.CLIENT_AFFILIATE]: client_affiliate_entity_model_1.ClientAffiliateEntityModel.fromApiEntity,
|
|
72
|
+
[entity_utils_interface_1.EntityEnum.BANK]: bank_entity_model_1.BankEntityModel.fromApiEntity,
|
|
73
|
+
[entity_utils_interface_1.EntityEnum.CONFIGURATION]: configuration_model_1.ConfigurationEntityModel.fromApiEntity,
|
|
74
|
+
[entity_utils_interface_1.EntityEnum.TASK]: task_entity_model_1.TaskEntityModel.fromApiEntity,
|
|
75
|
+
[entity_utils_interface_1.EntityEnum.BILLING_TIMESHEET]: billing_timesheet_entity_model_1.BillingTimesheetEntityModel.fromApiEntity,
|
|
76
|
+
[entity_utils_interface_1.EntityEnum.TIMESHEET]: timesheet_entity_model_1.TimesheetEntityModel.fromApiEntity,
|
|
77
|
+
[entity_utils_interface_1.EntityEnum.BILLING_TRANSACTION]: billing_transaction_model_1.BillingTransactionEntityModel.fromApiEntity,
|
|
78
|
+
};
|
|
79
|
+
function entityMapToModels(entityMap) {
|
|
80
|
+
for (const entityName in entityMap) {
|
|
81
|
+
if (!(entityName in exports.entityEnumToEntityModel)) {
|
|
82
|
+
throw new Error(`Unknown entity: ${entityName}`);
|
|
83
|
+
}
|
|
84
|
+
entityMap[entityName] = entityMap[entityName].map((entity) => exports.entityEnumToEntityModel[entityName](entity));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
51
87
|
function parseEntities(json, baseEntity, entityMap) {
|
|
52
88
|
var _a;
|
|
53
|
-
|
|
54
|
-
[entity_utils_interface_1.EntityEnum.PROJECT]: project_entity_model_1.ProjectEntityModel.fromApiEntity,
|
|
55
|
-
[entity_utils_interface_1.EntityEnum.CLIENT]: client_entity_model_1.ClientEntityModel.fromApiEntity,
|
|
56
|
-
[entity_utils_interface_1.EntityEnum.BILLING]: billing_entity_model_1.BillingEntityModel.fromApiEntity,
|
|
57
|
-
[entity_utils_interface_1.EntityEnum.USER]: user_entity_model_1.UserEntityModel.fromApiEntity,
|
|
58
|
-
[entity_utils_interface_1.EntityEnum.PROJECT_USER_MAPPING]: project_user_mapping_entity_model_1.ProjectUserMappingEntityModel.fromApiEntity,
|
|
59
|
-
[entity_utils_interface_1.EntityEnum.REIMBURSEMENT]: reimbursement_entity_model_1.ReimbursementEntityModel.fromApiEntity,
|
|
60
|
-
[entity_utils_interface_1.EntityEnum.REIMBURSEMENT_EXPENSE]: reimbursement_expense_entity_model_1.ReimbursementExpenseEntityModel.fromApiEntity,
|
|
61
|
-
[entity_utils_interface_1.EntityEnum.BILLING_REIMBURSEMENT_EXPENSE]: billing_reimbursement_expense_entity_model_1.BillingReimbursementExpneseEntityModel.fromApiEntity,
|
|
62
|
-
[entity_utils_interface_1.EntityEnum.CLIENT_AFFILIATE]: client_affiliate_entity_model_1.ClientAffiliateEntityModel.fromApiEntity,
|
|
63
|
-
[entity_utils_interface_1.EntityEnum.BANK]: bank_entity_model_1.BankEntityModel.fromApiEntity,
|
|
64
|
-
[entity_utils_interface_1.EntityEnum.CONFIGURATION]: configuration_model_1.ConfigurationEntityModel.fromApiEntity,
|
|
65
|
-
[entity_utils_interface_1.EntityEnum.TASK]: task_entity_model_1.TaskEntityModel.fromApiEntity,
|
|
66
|
-
[entity_utils_interface_1.EntityEnum.BILLING_TIMESHEET]: billing_timesheet_entity_model_1.BillingTimesheetEntityModel.fromApiEntity,
|
|
67
|
-
[entity_utils_interface_1.EntityEnum.TIMESHEET]: timesheet_entity_model_1.TimesheetEntityModel.fromApiEntity,
|
|
68
|
-
[entity_utils_interface_1.EntityEnum.BILLING_TRANSACTION]: billing_transaction_model_1.BillingTransactionEntityModel.fromApiEntity,
|
|
69
|
-
};
|
|
70
|
-
if (!(baseEntity in entityFromJsonMappings)) {
|
|
89
|
+
if (!(baseEntity in exports.entityEnumToEntityModel)) {
|
|
71
90
|
throw new Error(`Unknown entity: ${baseEntity}`);
|
|
72
91
|
}
|
|
73
|
-
entityMap[baseEntity] = ((_a = json["baseEntities"]) !== null && _a !== void 0 ? _a : []).map((e) =>
|
|
92
|
+
entityMap[baseEntity] = ((_a = json["baseEntities"]) !== null && _a !== void 0 ? _a : []).map((e) => exports.entityEnumToEntityModel[baseEntity](e));
|
|
74
93
|
if (json["relatedEntities"]) {
|
|
75
94
|
const relatedEntities = json["relatedEntities"];
|
|
76
95
|
for (const entityName in relatedEntities) {
|
|
@@ -81,3 +100,25 @@ function parseEntities(json, baseEntity, entityMap) {
|
|
|
81
100
|
}
|
|
82
101
|
return entityMap;
|
|
83
102
|
}
|
|
103
|
+
function entityMapToEntityIndexMap(entityMap, entityRelationsFor) {
|
|
104
|
+
entityMapToModels(entityMap);
|
|
105
|
+
const entityIndexMap = mapToIndex(entityMap);
|
|
106
|
+
populateRelationsFor(entityIndexMap, entityRelationsFor);
|
|
107
|
+
return entityIndexMap;
|
|
108
|
+
}
|
|
109
|
+
function parseEntitiesWithoutModels(json, baseEntity, entityMap = {}) {
|
|
110
|
+
var _a;
|
|
111
|
+
if (!(baseEntity in exports.entityEnumToEntityModel)) {
|
|
112
|
+
throw new Error(`Unknown entity: ${baseEntity}`);
|
|
113
|
+
}
|
|
114
|
+
entityMap[baseEntity] = ((_a = json["baseEntities"]) !== null && _a !== void 0 ? _a : []);
|
|
115
|
+
if (json["relatedEntities"]) {
|
|
116
|
+
const relatedEntities = json["relatedEntities"];
|
|
117
|
+
for (const entityName in relatedEntities) {
|
|
118
|
+
parseEntitiesWithoutModels(
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
relatedEntities[entityName], entityName, entityMap);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return entityMap;
|
|
124
|
+
}
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { IHolidayApiEntity } from "../../api";
|
|
2
|
+
import { EntityEnum } from "../interface/entity.utils.interface";
|
|
3
|
+
import { BaseEntityModel } from "./base.entity.model";
|
|
4
|
+
export declare class HolidayEntityModel extends BaseEntityModel<EntityEnum.HOLIDAY> implements IHolidayApiEntity {
|
|
5
|
+
id: number;
|
|
6
|
+
holidayListId: number;
|
|
7
|
+
dateCode: string;
|
|
8
|
+
createdBy: number;
|
|
9
|
+
updatedBy: number;
|
|
10
|
+
createdOn: string;
|
|
11
|
+
updatedOn: string;
|
|
12
|
+
getRelationConfigs(): never[];
|
|
13
|
+
static fromApiEntity(apiEntity: IHolidayApiEntity): HolidayEntityModel;
|
|
14
|
+
}
|
|
@@ -1,44 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// import { DateCodeModel } from "../../utils";
|
|
3
|
-
// import { IAuditColumnEntity } from "../interface/audit-column.entity.interface";
|
|
4
|
-
// import { IHolidayEntity } from "../interface/holiday.entity.interface";
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// }
|
|
32
|
-
// getDateCodeModel(): DateCodeModel {
|
|
33
|
-
// return new DateCodeModel(this.dateCode);
|
|
34
|
-
// }
|
|
35
|
-
// static fromEntity(data: IHolidayEntity): HolidayEntityModel {
|
|
36
|
-
// return new HolidayEntityModel(data);
|
|
37
|
-
// }
|
|
38
|
-
// static getDateCodeModelFromDate(
|
|
39
|
-
// models: HolidayEntityModel[]
|
|
40
|
-
// ): DateCodeModel[] {
|
|
41
|
-
// return models.map((model) => model.getDateCodeModel());
|
|
42
|
-
// }
|
|
43
|
-
// }
|
|
44
|
-
exports.toBeDeleted = "holiday";
|
|
3
|
+
exports.HolidayEntityModel = void 0;
|
|
4
|
+
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
5
|
+
const base_entity_model_1 = require("./base.entity.model");
|
|
6
|
+
// import { IHolidayApiEntity } from "law-common/dist/src/api";
|
|
7
|
+
class HolidayEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.id = 0;
|
|
11
|
+
this.holidayListId = 0;
|
|
12
|
+
this.dateCode = "";
|
|
13
|
+
this.createdBy = 0;
|
|
14
|
+
this.updatedBy = 0;
|
|
15
|
+
this.createdOn = "";
|
|
16
|
+
this.updatedOn = "";
|
|
17
|
+
}
|
|
18
|
+
getRelationConfigs() {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
static fromApiEntity(apiEntity) {
|
|
22
|
+
const entity = new HolidayEntityModel(entity_utils_interface_1.EntityEnum.HOLIDAY);
|
|
23
|
+
Object.assign(entity, apiEntity);
|
|
24
|
+
return entity;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.HolidayEntityModel = HolidayEntityModel;
|
|
@@ -3,7 +3,12 @@ import { DateCodeModel, Weekday } from "../../utils";
|
|
|
3
3
|
import { DurationTypeEnum } from "../enums/duration-type.enum";
|
|
4
4
|
import { LeaveTypeEnum } from "../enums/leave-type.enum";
|
|
5
5
|
import { LeaveStatusEnum } from "../enums/leave.status.enum";
|
|
6
|
-
|
|
6
|
+
import { RelationType } from "../enums/relation-type.enum";
|
|
7
|
+
import { EntityEnum, VirtualEntityEnum } from "../interface/entity.utils.interface";
|
|
8
|
+
import { BaseEntityModel } from "./base.entity.model";
|
|
9
|
+
import { LeaveCountVirtualEntityModel } from "./leave_count.entity.model";
|
|
10
|
+
import { UserEntityModel } from "./user.entity.model";
|
|
11
|
+
export declare class LeaveEntityModel extends BaseEntityModel<EntityEnum.LEAVE> implements ILeaveApiEntity {
|
|
7
12
|
id: number;
|
|
8
13
|
employeeId: number;
|
|
9
14
|
fromDate: string;
|
|
@@ -17,13 +22,55 @@ export declare class LeaveEntityModel implements ILeaveApiEntity {
|
|
|
17
22
|
updatedOn: string;
|
|
18
23
|
createdBy: number;
|
|
19
24
|
updatedBy: number;
|
|
20
|
-
|
|
25
|
+
leaveCount?: LeaveCountVirtualEntityModel;
|
|
26
|
+
createdByUser?: UserEntityModel;
|
|
27
|
+
updatedByUser?: UserEntityModel;
|
|
28
|
+
user?: UserEntityModel;
|
|
21
29
|
static fromEntity(data: ILeaveApiEntity): LeaveEntityModel;
|
|
22
|
-
isMoreThanOneDayLeave(): boolean;
|
|
23
30
|
getLeaveDuration(excludeWeekdays?: Weekday[], excludeDates?: DateCodeModel[]): number;
|
|
24
31
|
static getLeaveDuration(leaves: LeaveEntityModel[], excludeWeekdays?: Weekday[], excludeDates?: DateCodeModel[], leaveStatusEnum?: LeaveStatusEnum[]): number;
|
|
25
32
|
getDateCodeModels(dateCodeIncludePredicates?: ((dateModel: DateCodeModel) => boolean)[], dateCodeExcludePredicates?: ((dateModel: DateCodeModel) => boolean)[]): DateCodeModel[];
|
|
26
33
|
static getLeaveApprovePredicate(): (leave: LeaveEntityModel) => boolean;
|
|
27
34
|
static getLeavePendingPredicate(): (leave: LeaveEntityModel) => boolean;
|
|
28
35
|
static getLeavesByPredicates(leaves: LeaveEntityModel[], includePredicates?: ((leave: LeaveEntityModel) => boolean)[], excludePredicates?: ((leave: LeaveEntityModel) => boolean)[]): LeaveEntityModel[];
|
|
36
|
+
static orderByFromDateAsc(leaves: LeaveEntityModel[]): LeaveEntityModel[];
|
|
37
|
+
isWeekendSucceeds(): boolean;
|
|
38
|
+
isWeekendPrecedes(): boolean;
|
|
39
|
+
isHolidaySucceeds(holidays: DateCodeModel[]): boolean;
|
|
40
|
+
isHolidayPrecedes(holidays: DateCodeModel[]): boolean;
|
|
41
|
+
getRelationConfigs(): any[];
|
|
42
|
+
static relationConfigs: ({
|
|
43
|
+
name: VirtualEntityEnum;
|
|
44
|
+
relation: RelationType;
|
|
45
|
+
key: string;
|
|
46
|
+
mapKeyConfig: {
|
|
47
|
+
relationKey: string;
|
|
48
|
+
key: string;
|
|
49
|
+
};
|
|
50
|
+
} | {
|
|
51
|
+
name: EntityEnum;
|
|
52
|
+
relation: RelationType;
|
|
53
|
+
key: string;
|
|
54
|
+
mapKeyConfig: {
|
|
55
|
+
relationKey: string;
|
|
56
|
+
key: string;
|
|
57
|
+
};
|
|
58
|
+
})[];
|
|
59
|
+
static fromApiEntity(apiEntity: ILeaveApiEntity): LeaveEntityModel;
|
|
60
|
+
static getPendingApprovalStatuses(): LeaveStatusEnum[];
|
|
61
|
+
getStatusLabel(): string;
|
|
62
|
+
getTypeLabel(): string;
|
|
63
|
+
getLeaveCount(): number;
|
|
64
|
+
static getLeaveCount(leaveEntities: LeaveEntityModel[]): number;
|
|
65
|
+
isMoreThanOneDayLeave(): boolean;
|
|
66
|
+
getFromDateLabel(): string;
|
|
67
|
+
getToDateLabel(): string;
|
|
68
|
+
getDateDurationLabel(): string;
|
|
69
|
+
static getLeaveStatusPriority(): {
|
|
70
|
+
pending_approval: number;
|
|
71
|
+
edit_approval: number;
|
|
72
|
+
delete_approval: number;
|
|
73
|
+
approved: number;
|
|
74
|
+
rejected: number;
|
|
75
|
+
};
|
|
29
76
|
}
|
|
@@ -2,33 +2,33 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LeaveEntityModel = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
|
+
const string_util_1 = require("../../utils/string.util");
|
|
5
6
|
const duration_type_enum_1 = require("../enums/duration-type.enum");
|
|
7
|
+
const leave_type_enum_1 = require("../enums/leave-type.enum");
|
|
6
8
|
const leave_status_enum_1 = require("../enums/leave.status.enum");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
const relation_type_enum_1 = require("../enums/relation-type.enum");
|
|
10
|
+
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
11
|
+
const base_entity_model_1 = require("./base.entity.model");
|
|
12
|
+
class LeaveEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.id = 0;
|
|
16
|
+
this.employeeId = 0;
|
|
17
|
+
this.fromDate = "";
|
|
18
|
+
this.toDate = "";
|
|
19
|
+
this.reason = "";
|
|
20
|
+
this.durationType = duration_type_enum_1.DurationTypeEnum.FULL;
|
|
21
|
+
this.status = leave_status_enum_1.LeaveStatusEnum.DELETED;
|
|
22
|
+
this.type = leave_type_enum_1.LeaveTypeEnum.SICK;
|
|
9
23
|
this.createdOn = "";
|
|
10
24
|
this.updatedOn = "";
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
this.fromDate = data.fromDate;
|
|
14
|
-
this.toDate = data.toDate;
|
|
15
|
-
this.reason = data.reason;
|
|
16
|
-
this.durationType = data.durationType;
|
|
17
|
-
this.status = data.status;
|
|
18
|
-
this.remark = data.remark;
|
|
19
|
-
this.type = data.type;
|
|
20
|
-
this.createdOn = data.createdOn;
|
|
21
|
-
this.updatedOn = data.updatedOn;
|
|
22
|
-
this.createdBy = data.createdBy;
|
|
23
|
-
this.updatedBy = data.updatedBy;
|
|
25
|
+
this.createdBy = 0;
|
|
26
|
+
this.updatedBy = 0;
|
|
24
27
|
}
|
|
25
28
|
static fromEntity(data) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const fromDate = new utils_1.DateCodeModel(this.fromDate);
|
|
30
|
-
const toDate = new utils_1.DateCodeModel(this.toDate);
|
|
31
|
-
return fromDate.diffInDays(toDate) > 1;
|
|
29
|
+
const entity = new LeaveEntityModel(entity_utils_interface_1.EntityEnum.LEAVE);
|
|
30
|
+
Object.assign(entity, data);
|
|
31
|
+
return entity;
|
|
32
32
|
}
|
|
33
33
|
getLeaveDuration(excludeWeekdays = [], excludeDates = []) {
|
|
34
34
|
if (!this.isMoreThanOneDayLeave()) {
|
|
@@ -80,5 +80,138 @@ class LeaveEntityModel {
|
|
|
80
80
|
return leaves.filter((leave) => includePredicates.every((predicate) => predicate(leave)) &&
|
|
81
81
|
excludePredicates.every((predicate) => !predicate(leave)));
|
|
82
82
|
}
|
|
83
|
+
static orderByFromDateAsc(leaves) {
|
|
84
|
+
return leaves.sort((a, b) => {
|
|
85
|
+
const dateA = new Date(a.fromDate);
|
|
86
|
+
const dateB = new Date(b.fromDate);
|
|
87
|
+
return dateA.getTime() - dateB.getTime();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
isWeekendSucceeds() {
|
|
91
|
+
const toDate = new utils_1.DateCodeModel(this.toDate);
|
|
92
|
+
const nextDate = toDate.getByOffset(1);
|
|
93
|
+
return nextDate.isDayPresent([utils_1.Weekday.Saturday, utils_1.Weekday.Sunday]);
|
|
94
|
+
}
|
|
95
|
+
isWeekendPrecedes() {
|
|
96
|
+
const fromDate = new utils_1.DateCodeModel(this.fromDate);
|
|
97
|
+
const prevDate = fromDate.getByOffset(-1);
|
|
98
|
+
return prevDate.isDayPresent([utils_1.Weekday.Saturday, utils_1.Weekday.Sunday]);
|
|
99
|
+
}
|
|
100
|
+
isHolidaySucceeds(holidays) {
|
|
101
|
+
const toDate = new utils_1.DateCodeModel(this.toDate);
|
|
102
|
+
const nextDate = toDate.getByOffset(1);
|
|
103
|
+
return holidays.some((holiday) => holiday.isSame(nextDate));
|
|
104
|
+
}
|
|
105
|
+
isHolidayPrecedes(holidays) {
|
|
106
|
+
const fromDate = new utils_1.DateCodeModel(this.fromDate);
|
|
107
|
+
const prevDate = fromDate.getByOffset(-1);
|
|
108
|
+
return holidays.some((holiday) => holiday.isSame(prevDate));
|
|
109
|
+
}
|
|
110
|
+
getRelationConfigs() {
|
|
111
|
+
return this.constructor.prototype.constructor.relationConfigs;
|
|
112
|
+
}
|
|
113
|
+
static fromApiEntity(apiEntity) {
|
|
114
|
+
return LeaveEntityModel.fromEntity(apiEntity);
|
|
115
|
+
}
|
|
116
|
+
static getPendingApprovalStatuses() {
|
|
117
|
+
return [
|
|
118
|
+
leave_status_enum_1.LeaveStatusEnum.PENDING_APPROVAL,
|
|
119
|
+
leave_status_enum_1.LeaveStatusEnum.DELETE_APPROVAL,
|
|
120
|
+
leave_status_enum_1.LeaveStatusEnum.EDIT_APPROVAL,
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
getStatusLabel() {
|
|
124
|
+
const pendingStatuses = LeaveEntityModel.getPendingApprovalStatuses();
|
|
125
|
+
let statusLabel = '';
|
|
126
|
+
if (pendingStatuses.includes(this.status)) {
|
|
127
|
+
statusLabel = 'PENDING_APPROVAL';
|
|
128
|
+
}
|
|
129
|
+
else if (this.status === leave_status_enum_1.LeaveStatusEnum.RESOLVE_REJECTED) {
|
|
130
|
+
statusLabel = 'CHANGES_REJECTED';
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
statusLabel = this.status.toString();
|
|
134
|
+
}
|
|
135
|
+
return (0, string_util_1.formatString)(statusLabel);
|
|
136
|
+
}
|
|
137
|
+
getTypeLabel() {
|
|
138
|
+
return (0, string_util_1.formatString)(this.type.toString());
|
|
139
|
+
}
|
|
140
|
+
getLeaveCount() {
|
|
141
|
+
var _a;
|
|
142
|
+
return ((_a = this.leaveCount) === null || _a === void 0 ? void 0 : _a.count) || 0;
|
|
143
|
+
}
|
|
144
|
+
static getLeaveCount(leaveEntities) {
|
|
145
|
+
return leaveEntities.reduce((acc, leave) => acc + leave.getLeaveCount(), 0);
|
|
146
|
+
}
|
|
147
|
+
isMoreThanOneDayLeave() {
|
|
148
|
+
const fromDate = new utils_1.DateCodeModel(this.fromDate);
|
|
149
|
+
const toDate = new utils_1.DateCodeModel(this.toDate);
|
|
150
|
+
return fromDate.diffInDays(toDate) > 1;
|
|
151
|
+
}
|
|
152
|
+
getFromDateLabel() {
|
|
153
|
+
const statues = [duration_type_enum_1.DurationTypeEnum.SECOND, duration_type_enum_1.DurationTypeEnum.SECOND_FULL, duration_type_enum_1.DurationTypeEnum.SECOND_FIRST];
|
|
154
|
+
if (statues.includes(this.durationType)) {
|
|
155
|
+
return 'Second Half';
|
|
156
|
+
}
|
|
157
|
+
return 'Full Day';
|
|
158
|
+
}
|
|
159
|
+
getToDateLabel() {
|
|
160
|
+
const statues = [duration_type_enum_1.DurationTypeEnum.FIRST, duration_type_enum_1.DurationTypeEnum.FULL_FIRST, duration_type_enum_1.DurationTypeEnum.SECOND_FIRST];
|
|
161
|
+
if (statues.includes(this.durationType)) {
|
|
162
|
+
return 'First Half';
|
|
163
|
+
}
|
|
164
|
+
return 'Full Day';
|
|
165
|
+
}
|
|
166
|
+
getDateDurationLabel() {
|
|
167
|
+
if (!this.isMoreThanOneDayLeave()) {
|
|
168
|
+
return `${new utils_1.DateCodeModel(this.fromDate).getFormattedDateWithMonthName()} ${this.durationType === duration_type_enum_1.DurationTypeEnum.FULL ? '(Full Day)' : this.durationType === duration_type_enum_1.DurationTypeEnum.FIRST ? '(First Half)' : '(Second Half)'}`;
|
|
169
|
+
}
|
|
170
|
+
return `${new utils_1.DateCodeModel(this.fromDate).getFormattedDateWithMonthName()} (${this.getFromDateLabel()}) - ${new utils_1.DateCodeModel(this.toDate).getFormattedDateWithMonthName()} (${this.getToDateLabel()})`;
|
|
171
|
+
}
|
|
172
|
+
static getLeaveStatusPriority() {
|
|
173
|
+
return {
|
|
174
|
+
[leave_status_enum_1.LeaveStatusEnum.PENDING_APPROVAL]: 1,
|
|
175
|
+
[leave_status_enum_1.LeaveStatusEnum.EDIT_APPROVAL]: 2,
|
|
176
|
+
[leave_status_enum_1.LeaveStatusEnum.DELETE_APPROVAL]: 3,
|
|
177
|
+
[leave_status_enum_1.LeaveStatusEnum.APPROVED]: 4,
|
|
178
|
+
[leave_status_enum_1.LeaveStatusEnum.REJECTED]: 5,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
83
181
|
}
|
|
84
182
|
exports.LeaveEntityModel = LeaveEntityModel;
|
|
183
|
+
LeaveEntityModel.relationConfigs = [
|
|
184
|
+
{
|
|
185
|
+
name: entity_utils_interface_1.VirtualEntityEnum.LEAVE_COUNT,
|
|
186
|
+
relation: relation_type_enum_1.RelationType.ONE,
|
|
187
|
+
key: 'leaveCount',
|
|
188
|
+
mapKeyConfig: {
|
|
189
|
+
relationKey: 'leaveId',
|
|
190
|
+
key: 'id',
|
|
191
|
+
},
|
|
192
|
+
}, {
|
|
193
|
+
name: entity_utils_interface_1.EntityEnum.USER,
|
|
194
|
+
relation: relation_type_enum_1.RelationType.ONE,
|
|
195
|
+
key: 'createdByUser',
|
|
196
|
+
mapKeyConfig: {
|
|
197
|
+
relationKey: 'id',
|
|
198
|
+
key: 'createdBy',
|
|
199
|
+
},
|
|
200
|
+
}, {
|
|
201
|
+
name: entity_utils_interface_1.EntityEnum.USER,
|
|
202
|
+
relation: relation_type_enum_1.RelationType.ONE,
|
|
203
|
+
key: 'updatedByUser',
|
|
204
|
+
mapKeyConfig: {
|
|
205
|
+
relationKey: 'id',
|
|
206
|
+
key: 'updatedBy',
|
|
207
|
+
},
|
|
208
|
+
}, {
|
|
209
|
+
name: entity_utils_interface_1.EntityEnum.USER,
|
|
210
|
+
relation: relation_type_enum_1.RelationType.ONE,
|
|
211
|
+
key: 'user',
|
|
212
|
+
mapKeyConfig: {
|
|
213
|
+
relationKey: 'id',
|
|
214
|
+
key: 'employeeId',
|
|
215
|
+
},
|
|
216
|
+
}
|
|
217
|
+
];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DateCodeModel } from "../../utils";
|
|
2
|
+
import { IApiEntity, VirtualEntityEnum } from "../interface/entity.utils.interface";
|
|
3
|
+
import { ILeaveCountVirtualEntity } from "../interface/leave.entity.interface";
|
|
4
|
+
import { BaseEntityModel } from "./base.entity.model";
|
|
5
|
+
import { LeaveEntityModel } from "./leave.entity.model";
|
|
6
|
+
export declare class LeaveCountVirtualEntityModel extends BaseEntityModel<VirtualEntityEnum.LEAVE_COUNT> implements IApiEntity<ILeaveCountVirtualEntity> {
|
|
7
|
+
id: number;
|
|
8
|
+
period: string;
|
|
9
|
+
leaveId?: number;
|
|
10
|
+
count: number;
|
|
11
|
+
createdBy: number;
|
|
12
|
+
updatedBy: number;
|
|
13
|
+
createdOn: string;
|
|
14
|
+
updatedOn: string;
|
|
15
|
+
static fromApiEntity(apiEntity: IApiEntity<ILeaveCountVirtualEntity>): LeaveCountVirtualEntityModel;
|
|
16
|
+
getRelationConfigs(): any[];
|
|
17
|
+
static relationConfigs: never[];
|
|
18
|
+
static fromLeaveHoliday(leaveModel: LeaveEntityModel, holidayDateCodes: DateCodeModel[]): LeaveCountVirtualEntityModel;
|
|
19
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LeaveCountVirtualEntityModel = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const leave_type_enum_1 = require("../enums/leave-type.enum");
|
|
6
|
+
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
7
|
+
const base_entity_model_1 = require("./base.entity.model");
|
|
8
|
+
class LeaveCountVirtualEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.id = 0;
|
|
12
|
+
this.period = "";
|
|
13
|
+
this.count = 0;
|
|
14
|
+
this.createdBy = 0;
|
|
15
|
+
this.updatedBy = 0;
|
|
16
|
+
this.createdOn = "";
|
|
17
|
+
this.updatedOn = "";
|
|
18
|
+
}
|
|
19
|
+
static fromApiEntity(apiEntity) {
|
|
20
|
+
const entity = new LeaveCountVirtualEntityModel(entity_utils_interface_1.VirtualEntityEnum.LEAVE_COUNT);
|
|
21
|
+
Object.assign(entity, apiEntity);
|
|
22
|
+
return entity;
|
|
23
|
+
}
|
|
24
|
+
getRelationConfigs() {
|
|
25
|
+
return this.constructor.prototype.constructor.relationConfigs;
|
|
26
|
+
}
|
|
27
|
+
static fromLeaveHoliday(leaveModel, holidayDateCodes) {
|
|
28
|
+
const leaveCountVirtualEntity = {
|
|
29
|
+
leaveId: leaveModel.id,
|
|
30
|
+
count: leaveModel.getLeaveDuration([utils_1.Weekday.Sunday, utils_1.Weekday.Saturday], holidayDateCodes) +
|
|
31
|
+
(leaveModel.type === leave_type_enum_1.LeaveTypeEnum.SICK &&
|
|
32
|
+
(leaveModel.isWeekendPrecedes() ||
|
|
33
|
+
leaveModel.isWeekendSucceeds() ||
|
|
34
|
+
leaveModel.isHolidayPrecedes(holidayDateCodes) ||
|
|
35
|
+
leaveModel.isHolidaySucceeds(holidayDateCodes))
|
|
36
|
+
? 2
|
|
37
|
+
: 0),
|
|
38
|
+
createdBy: leaveModel.createdBy,
|
|
39
|
+
updatedBy: leaveModel.updatedBy,
|
|
40
|
+
createdOn: leaveModel.createdOn,
|
|
41
|
+
updatedOn: leaveModel.updatedOn,
|
|
42
|
+
id: leaveModel.id,
|
|
43
|
+
period: leaveModel.fromDate + leaveModel.toDate + leaveModel.durationType,
|
|
44
|
+
};
|
|
45
|
+
return LeaveCountVirtualEntityModel.fromApiEntity(leaveCountVirtualEntity);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.LeaveCountVirtualEntityModel = LeaveCountVirtualEntityModel;
|
|
49
|
+
// static relationConfigs = [
|
|
50
|
+
// {
|
|
51
|
+
// name: EntityEnum.LEAVE,
|
|
52
|
+
// relation: RelationType.ONE,
|
|
53
|
+
// key: 'leaveCount',
|
|
54
|
+
// mapKeyConfig: {
|
|
55
|
+
// relationKey: 'id',
|
|
56
|
+
// key: 'leaveId',
|
|
57
|
+
// },
|
|
58
|
+
// },
|
|
59
|
+
// ];
|
|
60
|
+
LeaveCountVirtualEntityModel.relationConfigs = [];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { LeaveActionEnum, LeaveStatusEnum } from "../entities";
|
|
2
|
+
export type LeaveStatusActionPair = {
|
|
3
|
+
status: LeaveStatusEnum;
|
|
4
|
+
action: LeaveActionEnum;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Gets available actions for a leave based on current status and user permissions
|
|
8
|
+
* @param entityFlowConfig - The flow configuration for the entity
|
|
9
|
+
* @param currentStatus - The current status of the leave
|
|
10
|
+
* @param userPermissions - Array of permissions the user has
|
|
11
|
+
* @param combineActions - Array of action values to combine into a single action
|
|
12
|
+
* @param actionLabels - Object mapping actions to custom labels
|
|
13
|
+
* @param data - Optional function to provide additional visibility conditions
|
|
14
|
+
* @returns Array of available actions with labels and values
|
|
15
|
+
*/
|
|
16
|
+
export declare function getPermittedActions<T extends LeaveStatusActionPair, E>(entityFlowConfig: {
|
|
17
|
+
[key in T["status"]]?: {
|
|
18
|
+
actions: {
|
|
19
|
+
[key in T["action"]]?: {
|
|
20
|
+
permissions: string[];
|
|
21
|
+
next: () => T["status"];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}, currentStatus: T["status"] | null, userPermissions: string[], combineActions?: T["action"][], actionLabels?: {
|
|
26
|
+
[key in T["action"]]?: string;
|
|
27
|
+
}, data?: (a: E) => {
|
|
28
|
+
[key: string]: () => boolean;
|
|
29
|
+
}): {
|
|
30
|
+
label: string;
|
|
31
|
+
value: T["action"] | string;
|
|
32
|
+
}[];
|
|
@@ -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;
|
|
@@ -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
|
*
|
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
|
+
}
|