law-common 10.19.1-beta.10 → 10.19.1-beta.3

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.
Files changed (29) hide show
  1. package/dist/src/api/interface/billing.transaction.create.dto.interface.d.ts +1 -4
  2. package/dist/src/api/interface/billing.transaction.update.dto.interface.d.ts +1 -7
  3. package/dist/src/entities/func/convert-to-common-entity.func.js +2 -8
  4. package/dist/src/entities/index.d.ts +0 -2
  5. package/dist/src/entities/index.js +0 -2
  6. package/dist/src/entities/interface/entity.utils.interface.d.ts +3 -10
  7. package/dist/src/entities/model/base.entity.model.d.ts +2 -8
  8. package/dist/src/entities/model/base.entity.model.js +35 -43
  9. package/dist/src/entities/model/billing.entity.model.d.ts +1 -4
  10. package/dist/src/entities/model/billing.entity.model.js +0 -9
  11. package/dist/src/entities/model/entity.model.interface.d.ts +2 -12
  12. package/dist/src/entities/model/entity.model.interface.js +18 -61
  13. package/dist/src/entities/model/holiday.entity.model.d.ts +1 -14
  14. package/dist/src/entities/model/holiday.entity.model.js +42 -25
  15. package/dist/src/entities/model/leave.entity.model.d.ts +3 -50
  16. package/dist/src/entities/model/leave.entity.model.js +21 -154
  17. package/dist/src/utils/helper.fn.util.d.ts +1 -37
  18. package/dist/src/utils/helper.fn.util.js +0 -53
  19. package/dist/src/utils/index.d.ts +0 -2
  20. package/dist/src/utils/index.js +0 -2
  21. package/dist/src/utils/string.util.d.ts +0 -1
  22. package/dist/src/utils/string.util.js +0 -14
  23. package/package.json +1 -1
  24. package/dist/src/entities/model/billing-transaction.model.d.ts +0 -35
  25. package/dist/src/entities/model/billing-transaction.model.js +0 -62
  26. package/dist/src/entities/model/leave_count.entity.model.d.ts +0 -19
  27. package/dist/src/entities/model/leave_count.entity.model.js +0 -60
  28. package/dist/src/utils/entity.flow.util.d.ts +0 -32
  29. package/dist/src/utils/entity.flow.util.js +0 -83
@@ -1,8 +1,5 @@
1
- import { BillingTransactionStatusEnum, IBillingEntity, IBillingTransactionEntity, IEntityCreateDto } from "../../entities";
1
+ import { BillingTransactionStatusEnum, 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
- }
@@ -1,13 +1,7 @@
1
1
  import { BillingTransactionActionEnum, IBillingTransactionEntity, IEntityUpdateDto } from "../../entities";
2
- export interface IBillingTransactionSupportingDocsDetails {
3
- supportingDocsDetails?: string[];
4
- }
5
2
  export interface IBillingTransactionActionDataDto {
6
3
  action: BillingTransactionActionEnum;
7
4
  }
8
- export interface IBillingTransactionUpdateDto extends IEntityUpdateDto<IBillingTransactionEntity>, IBillingTransactionSupportingDocsDetails {
5
+ export interface IBillingTransactionUpdateDto extends IEntityUpdateDto<IBillingTransactionEntity> {
9
6
  actionData?: IBillingTransactionActionDataDto;
10
7
  }
11
- export interface IBillingTransactionUpdateDtoValidationResult {
12
- billingTransactionEntity: IBillingTransactionEntity;
13
- }
@@ -14,15 +14,9 @@ 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;
17
18
  const { createdOn: _, updatedOn: __ } = obj, objectToAssign = __rest(obj, ["createdOn", "updatedOn"]);
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);
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);
26
20
  }
27
21
  function ConvertApiToEntity(obj) {
28
22
  const { createdOn: _, updatedOn: __ } = obj, objectToAssign = __rest(obj, ["createdOn", "updatedOn"]);
@@ -66,7 +66,6 @@ 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";
70
69
  export * from "./model/holiday.entity.model";
71
70
  export * from "./enums/cron-jobs-name.enum";
72
71
  export * from "./enums/cron-jobs-status.enum";
@@ -101,4 +100,3 @@ export * from "./model/billing-timesheet.entity.model";
101
100
  export * from "./enums/billing-transaction-action.enum";
102
101
  export * from "./enums/billing-transaction-status.enum";
103
102
  export * from "./interface/billing-transaction-history.entity";
104
- export * from "./model/billing-transaction.model";
@@ -83,7 +83,6 @@ __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);
87
86
  __exportStar(require("./model/holiday.entity.model"), exports);
88
87
  __exportStar(require("./enums/cron-jobs-name.enum"), exports);
89
88
  __exportStar(require("./enums/cron-jobs-status.enum"), exports);
@@ -118,4 +117,3 @@ __exportStar(require("./model/billing-timesheet.entity.model"), exports);
118
117
  __exportStar(require("./enums/billing-transaction-action.enum"), exports);
119
118
  __exportStar(require("./enums/billing-transaction-status.enum"), exports);
120
119
  __exportStar(require("./interface/billing-transaction-history.entity"), exports);
121
- __exportStar(require("./model/billing-transaction.model"), exports);
@@ -6,14 +6,10 @@ import { HistoryOperationEnum } from "../enums/history_operation.enum";
6
6
  import { BankEntityModel } from "../model/bank.entity.model";
7
7
  import { BillingReimbursementExpneseEntityModel } from "../model/billing-reimbursement-expense.entity.model";
8
8
  import { BillingTimesheetEntityModel } from "../model/billing-timesheet.entity.model";
9
- import { BillingTransactionEntityModel } from "../model/billing-transaction.model";
10
9
  import { BillingEntityModel } from "../model/billing.entity.model";
11
10
  import { ClientAffiliateEntityModel } from "../model/client-affiliate.entity.model";
12
11
  import { ClientEntityModel } from "../model/client.entity.model";
13
12
  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";
17
13
  import { ProjectUserMappingEntityModel } from "../model/project-user-mapping.entity.model";
18
14
  import { ProjectEntityModel } from "../model/project.entity.model";
19
15
  import { ReimbursementExpenseEntityModel } from "../model/reimbursement-expense.entity.model";
@@ -287,15 +283,12 @@ export declare enum VirtualEntityEnum {
287
283
  }
288
284
  export type IHistoryConstraintSearchResponse<T> = IBaseResponse<IHistoryEntitySearchByConstraintResponse<T>[]>;
289
285
  export type IHistoryConstraintSearchServiceResponse<T> = IHistoryEntitySearchByConstraintResponse<T>[];
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;
286
+ 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 : UserEntityModel;
291
287
  export type EntityMap = {
292
- [key in EntityEnum | VirtualEntityEnum]: EnumToModel<key>[];
288
+ [key in EntityEnum]: EnumToModel<key>[];
293
289
  };
294
290
  export type EntityIndexMap = {
295
- [key in EntityEnum | VirtualEntityEnum]: {
291
+ [key in EntityEnum]: {
296
292
  [id: number]: EnumToModel<key>;
297
293
  };
298
294
  };
299
- export type IPremissionFilterConfig<T extends EntityEnum | VirtualEntityEnum> = {
300
- [key: string]: () => Promise<IEntityFilterData<EnumEntityType<T>>>;
301
- };
@@ -1,14 +1,8 @@
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> {
1
+ import { EntityEnum, EntityIndexMap } from "../interface/entity.utils.interface";
2
+ export declare abstract class BaseEntityModel<T extends EntityEnum> {
7
3
  protected entityName: T;
8
4
  constructor(entityName: T);
9
5
  abstract getRelationConfigs(): any[];
10
6
  populateRelationsByIndex(entityIndexMap: EntityIndexMap): void;
11
7
  static populateRelationsForEntities(entityIndexMap: EntityIndexMap, entityType: EntityEnum): void;
12
- populateRelations(entityIndexMap: EntityIndexMap): void;
13
- overwrite(entityIndexMap: EntityIndexMap, indexKey?: string): this;
14
8
  }
@@ -1,56 +1,58 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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 = {}));
3
+ exports.BaseEntityModel = void 0;
4
+ const relation_type_enum_1 = require("../enums/relation-type.enum");
9
5
  class BaseEntityModel {
10
6
  constructor(entityName) {
11
7
  this.entityName = entityName;
12
8
  }
13
9
  populateRelationsByIndex(entityIndexMap) {
14
10
  for (const relationConfig of this.getRelationConfigs() || []) {
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) {
11
+ if (relationConfig.relation === relation_type_enum_1.RelationType.ONE) {
12
+ // @ts-ignore
21
13
  const relatedEntities = entityIndexMap[relationConfig.name] || {};
14
+ // @ts-ignore
22
15
  let foundRelatedEntities = [];
23
- if (thisMappingKey.includes(".")) {
24
- const [parentKey, childKey] = thisMappingKey.split(".");
25
- foundRelatedEntities = [relatedEntities[this[parentKey][childKey]]];
16
+ if (relationConfig.mapKeyConfig.key.includes(".")) {
17
+ const [parentKey, childKey] = relationConfig.mapKeyConfig.key.split(".");
18
+ // @ts-ignore
19
+ if (this[parentKey] && this[parentKey][childKey]) {
20
+ // @ts-ignore
21
+ foundRelatedEntities = [relatedEntities[this[parentKey][childKey]]];
22
+ }
26
23
  }
27
24
  else {
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
- }
25
+ foundRelatedEntities = relatedEntities[
26
+ // @ts-ignore
27
+ this[relationConfig.mapKeyConfig.key]]
28
+ ? // @ts-ignore
29
+ [relatedEntities[this[relationConfig.mapKeyConfig.key]]]
30
+ : [];
39
31
  }
40
32
  if (foundRelatedEntities.length > 1) {
41
33
  throw new Error(`Expected one related entity for ${relationConfig.name} but found ${foundRelatedEntities.length}`);
42
34
  }
43
35
  if (foundRelatedEntities.length === 0) {
44
- console.warn(`No related entity found for ${relationConfig.name} with ${thisMappingKey}=${this[relationConfig.mapKeyConfig.foreignKey]}`);
36
+ console.warn(`No related entity found for ${relationConfig.name} with ${relationConfig.mapKeyConfig.key
37
+ // @ts-ignore
38
+ }=${this[relationConfig.mapKeyConfig.foreignKey]}`);
45
39
  }
46
- this[thisKey] = foundRelatedEntities[0];
40
+ // @ts-ignore
41
+ this[relationConfig.key] = foundRelatedEntities[0];
47
42
  }
48
- else if (relationConfig.relation === RelationType.MANY) {
49
- this[thisKey] = [];
43
+ else if (relationConfig.relation === relation_type_enum_1.RelationType.MANY) {
44
+ // @ts-ignore
45
+ this[relationConfig.key] = [];
46
+ // @ts-ignore
50
47
  const relatedEntities = entityIndexMap[relationConfig.name] || {};
51
48
  for (const relatedEntity of Object.values(relatedEntities)) {
52
- if (relatedEntity[relatedMappingKey] === this[thisMappingKey]) {
53
- this[thisKey].push(relatedEntity);
49
+ if (
50
+ // @ts-ignore
51
+ relatedEntity[relationConfig.mapKeyConfig.relationKey] ===
52
+ // @ts-ignore
53
+ this[relationConfig.mapKeyConfig.key]) {
54
+ // @ts-ignore
55
+ this[relationConfig.key].push(relatedEntity);
54
56
  }
55
57
  }
56
58
  }
@@ -58,20 +60,10 @@ class BaseEntityModel {
58
60
  }
59
61
  static populateRelationsForEntities(entityIndexMap, entityType) {
60
62
  for (const key of Object.keys(entityIndexMap[entityType] || {})) {
63
+ // @ts-ignore
61
64
  const entity = entityIndexMap[entityType][key];
62
65
  entity.populateRelationsByIndex(entityIndexMap);
63
66
  }
64
67
  }
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
- }
76
68
  }
77
69
  exports.BaseEntityModel = BaseEntityModel;
@@ -11,7 +11,6 @@ import { BankEntityModel } from "./bank.entity.model";
11
11
  import { BaseEntityModel } from "./base.entity.model";
12
12
  import { BillingReimbursementExpneseEntityModel } from "./billing-reimbursement-expense.entity.model";
13
13
  import { BillingTimesheetEntityModel } from "./billing-timesheet.entity.model";
14
- import { BillingTransactionEntityModel } from "./billing-transaction.model";
15
14
  import { ClientEntityModel } from "./client.entity.model";
16
15
  import { ProjectEntityModel } from "./project.entity.model";
17
16
  import { ReimbursementExpenseEntityModel } from "./reimbursement-expense.entity.model";
@@ -60,7 +59,6 @@ export declare class BillingEntityModel extends BaseEntityModel<EntityEnum.BILLI
60
59
  reimbursementExpense?: ReimbursementExpenseEntityModel[];
61
60
  bank?: BankEntityModel[];
62
61
  billingTimesheets?: BillingTimesheetEntityModel[];
63
- billingTransactions?: BillingTransactionEntityModel[];
64
62
  static relationConfigs: RelationConfigs<[
65
63
  EntityEnum.PROJECT,
66
64
  EntityEnum.CLIENT,
@@ -68,8 +66,7 @@ export declare class BillingEntityModel extends BaseEntityModel<EntityEnum.BILLI
68
66
  EntityEnum.REIMBURSEMENT_EXPENSE,
69
67
  EntityEnum.BILLING_REIMBURSEMENT_EXPENSE,
70
68
  EntityEnum.BILLING_TIMESHEET,
71
- EntityEnum.BANK,
72
- EntityEnum.BILLING_TRANSACTION
69
+ EntityEnum.BANK
73
70
  ], EnumEntityType<EntityEnum.BILLING>>;
74
71
  static fromApiEntity(apiEntity: IBillingApiEntity): BillingEntityModel;
75
72
  getStatusCategory(): BillingStatusCategoryEnumForUI;
@@ -243,13 +243,4 @@ BillingEntityModel.relationConfigs = [
243
243
  key: "bankId",
244
244
  },
245
245
  },
246
- {
247
- name: entity_utils_interface_1.EntityEnum.BILLING_TRANSACTION,
248
- relation: relation_type_enum_1.RelationType.MANY,
249
- key: "billingTransactions",
250
- mapKeyConfig: {
251
- relationKey: "billingId",
252
- key: "id",
253
- },
254
- },
255
246
  ];
@@ -1,18 +1,8 @@
1
- import { EntityEnum, EntityIndexMap, EntityMap, EnumEntityType, EnumToModel, IApiEntity, IBaseEntityApiResponse, VirtualEntityEnum } from "../interface/entity.utils.interface";
1
+ import { EntityEnum, EntityIndexMap, EntityMap, EnumEntityType, IBaseEntityApiResponse } 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 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
- };
8
+ export declare function parseEntities<T extends EnumEntityType<EntityEnum>>(json: IBaseEntityApiResponse<T>, baseEntity: EntityEnum, entityMap: EntityMap): EntityMap;
@@ -1,25 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.entityEnumToEntityModel = void 0;
4
3
  exports.mapToIndex = mapToIndex;
5
4
  exports.getEntityIndexMap = getEntityIndexMap;
6
5
  exports.populateRelationsFor = populateRelationsFor;
7
- exports.entityMapToModels = entityMapToModels;
8
6
  exports.parseEntities = parseEntities;
9
- exports.entityMapToEntityIndexMap = entityMapToEntityIndexMap;
10
- exports.parseEntitiesWithoutModels = parseEntitiesWithoutModels;
11
7
  const entity_utils_interface_1 = require("../interface/entity.utils.interface");
12
8
  const bank_entity_model_1 = require("./bank.entity.model");
13
9
  const base_entity_model_1 = require("./base.entity.model");
14
10
  const billing_reimbursement_expense_entity_model_1 = require("./billing-reimbursement-expense.entity.model");
15
11
  const billing_timesheet_entity_model_1 = require("./billing-timesheet.entity.model");
16
- const billing_transaction_model_1 = require("./billing-transaction.model");
17
12
  const billing_entity_model_1 = require("./billing.entity.model");
18
13
  const client_affiliate_entity_model_1 = require("./client-affiliate.entity.model");
19
14
  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");
23
15
  const configuration_model_1 = require("./configuration.model");
24
16
  const project_user_mapping_entity_model_1 = require("./project-user-mapping.entity.model");
25
17
  const project_entity_model_1 = require("./project.entity.model");
@@ -55,41 +47,28 @@ function populateRelationsFor(entityIndexMap, enumEntities) {
55
47
  base_entity_model_1.BaseEntityModel.populateRelationsForEntities(entityIndexMap, entity);
56
48
  });
57
49
  }
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
- }
87
50
  function parseEntities(json, baseEntity, entityMap) {
88
51
  var _a;
89
- if (!(baseEntity in exports.entityEnumToEntityModel)) {
52
+ const entityFromJsonMappings = {
53
+ [entity_utils_interface_1.EntityEnum.PROJECT]: project_entity_model_1.ProjectEntityModel.fromApiEntity,
54
+ [entity_utils_interface_1.EntityEnum.CLIENT]: client_entity_model_1.ClientEntityModel.fromApiEntity,
55
+ [entity_utils_interface_1.EntityEnum.BILLING]: billing_entity_model_1.BillingEntityModel.fromApiEntity,
56
+ [entity_utils_interface_1.EntityEnum.USER]: user_entity_model_1.UserEntityModel.fromApiEntity,
57
+ [entity_utils_interface_1.EntityEnum.PROJECT_USER_MAPPING]: project_user_mapping_entity_model_1.ProjectUserMappingEntityModel.fromApiEntity,
58
+ [entity_utils_interface_1.EntityEnum.REIMBURSEMENT]: reimbursement_entity_model_1.ReimbursementEntityModel.fromApiEntity,
59
+ [entity_utils_interface_1.EntityEnum.REIMBURSEMENT_EXPENSE]: reimbursement_expense_entity_model_1.ReimbursementExpenseEntityModel.fromApiEntity,
60
+ [entity_utils_interface_1.EntityEnum.BILLING_REIMBURSEMENT_EXPENSE]: billing_reimbursement_expense_entity_model_1.BillingReimbursementExpneseEntityModel.fromApiEntity,
61
+ [entity_utils_interface_1.EntityEnum.CLIENT_AFFILIATE]: client_affiliate_entity_model_1.ClientAffiliateEntityModel.fromApiEntity,
62
+ [entity_utils_interface_1.EntityEnum.BANK]: bank_entity_model_1.BankEntityModel.fromApiEntity,
63
+ [entity_utils_interface_1.EntityEnum.CONFIGURATION]: configuration_model_1.ConfigurationEntityModel.fromApiEntity,
64
+ [entity_utils_interface_1.EntityEnum.TASK]: task_entity_model_1.TaskEntityModel.fromApiEntity,
65
+ [entity_utils_interface_1.EntityEnum.BILLING_TIMESHEET]: billing_timesheet_entity_model_1.BillingTimesheetEntityModel.fromApiEntity,
66
+ [entity_utils_interface_1.EntityEnum.TIMESHEET]: timesheet_entity_model_1.TimesheetEntityModel.fromApiEntity,
67
+ };
68
+ if (!(baseEntity in entityFromJsonMappings)) {
90
69
  throw new Error(`Unknown entity: ${baseEntity}`);
91
70
  }
92
- entityMap[baseEntity] = ((_a = json["baseEntities"]) !== null && _a !== void 0 ? _a : []).map((e) => exports.entityEnumToEntityModel[baseEntity](e));
71
+ entityMap[baseEntity] = ((_a = json["baseEntities"]) !== null && _a !== void 0 ? _a : []).map((e) => entityFromJsonMappings[baseEntity](e));
93
72
  if (json["relatedEntities"]) {
94
73
  const relatedEntities = json["relatedEntities"];
95
74
  for (const entityName in relatedEntities) {
@@ -100,25 +79,3 @@ function parseEntities(json, baseEntity, entityMap) {
100
79
  }
101
80
  return entityMap;
102
81
  }
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,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
+ export declare const toBeDeleted = "holiday";
@@ -1,27 +1,44 @@
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";
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
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;
6
+ exports.toBeDeleted = void 0;
7
+ // export class BaseEntityModelV1<T extends IAuditColumnEntity> {
8
+ // createdOn: Date;
9
+ // updatedOn: Date;
10
+ // createdBy: number;
11
+ // updatedBy: number;
12
+ // constructor(data: T) {
13
+ // this.createdOn = data.createdOn;
14
+ // this.updatedOn = data.updatedOn;
15
+ // this.createdBy = data.createdBy;
16
+ // this.updatedBy = data.updatedBy;
17
+ // }
18
+ // }
19
+ // export class HolidayEntityModel
20
+ // extends BaseEntityModelV1<IHolidayEntity>
21
+ // implements IHolidayEntity
22
+ // {
23
+ // id: number;
24
+ // holidayListId: number;
25
+ // dateCode: string;
26
+ // private constructor(data: IHolidayEntity) {
27
+ // super(data);
28
+ // this.id = data.id;
29
+ // this.holidayListId = data.holidayListId;
30
+ // this.dateCode = data.dateCode;
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,12 +3,7 @@ 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
- 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 {
6
+ export declare class LeaveEntityModel implements ILeaveApiEntity {
12
7
  id: number;
13
8
  employeeId: number;
14
9
  fromDate: string;
@@ -22,55 +17,13 @@ export declare class LeaveEntityModel extends BaseEntityModel<EntityEnum.LEAVE>
22
17
  updatedOn: string;
23
18
  createdBy: number;
24
19
  updatedBy: number;
25
- leaveCount?: LeaveCountVirtualEntityModel;
26
- createdByUser?: UserEntityModel;
27
- updatedByUser?: UserEntityModel;
28
- user?: UserEntityModel;
20
+ private constructor();
29
21
  static fromEntity(data: ILeaveApiEntity): LeaveEntityModel;
22
+ isMoreThanOneDayLeave(): boolean;
30
23
  getLeaveDuration(excludeWeekdays?: Weekday[], excludeDates?: DateCodeModel[]): number;
31
24
  static getLeaveDuration(leaves: LeaveEntityModel[], excludeWeekdays?: Weekday[], excludeDates?: DateCodeModel[], leaveStatusEnum?: LeaveStatusEnum[]): number;
32
25
  getDateCodeModels(dateCodeIncludePredicates?: ((dateModel: DateCodeModel) => boolean)[], dateCodeExcludePredicates?: ((dateModel: DateCodeModel) => boolean)[]): DateCodeModel[];
33
26
  static getLeaveApprovePredicate(): (leave: LeaveEntityModel) => boolean;
34
27
  static getLeavePendingPredicate(): (leave: LeaveEntityModel) => boolean;
35
28
  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
- };
76
29
  }
@@ -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");
6
5
  const duration_type_enum_1 = require("../enums/duration-type.enum");
7
- const leave_type_enum_1 = require("../enums/leave-type.enum");
8
6
  const leave_status_enum_1 = require("../enums/leave.status.enum");
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;
7
+ class LeaveEntityModel {
8
+ constructor(data) {
23
9
  this.createdOn = "";
24
10
  this.updatedOn = "";
25
- this.createdBy = 0;
26
- this.updatedBy = 0;
11
+ this.id = data.id;
12
+ this.employeeId = data.employeeId;
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;
27
24
  }
28
25
  static fromEntity(data) {
29
- const entity = new LeaveEntityModel(entity_utils_interface_1.EntityEnum.LEAVE);
30
- Object.assign(entity, data);
31
- return entity;
26
+ return new LeaveEntityModel(data);
27
+ }
28
+ isMoreThanOneDayLeave() {
29
+ const fromDate = new utils_1.DateCodeModel(this.fromDate);
30
+ const toDate = new utils_1.DateCodeModel(this.toDate);
31
+ return fromDate.diffInDays(toDate) > 1;
32
32
  }
33
33
  getLeaveDuration(excludeWeekdays = [], excludeDates = []) {
34
34
  if (!this.isMoreThanOneDayLeave()) {
@@ -80,138 +80,5 @@ class LeaveEntityModel extends base_entity_model_1.BaseEntityModel {
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
- }
181
83
  }
182
84
  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
- ];
@@ -1,4 +1,4 @@
1
- import { EntityEnum, EnumEntityType, IBaseEntityServiceResponse, IEntityFilterData, IEntityServiceResponse } from "../entities";
1
+ import { EntityEnum, EnumEntityType, IBaseEntityServiceResponse, IEntityFilterData } 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,42 +176,6 @@ 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[];
215
179
  /**
216
180
  * Checks if two decimal numbers are approximately equal within a given tolerance.
217
181
  *
@@ -33,7 +33,6 @@ exports.createKeyLabelMap = createKeyLabelMap;
33
33
  exports.transformDate = transformDate;
34
34
  exports.capitalizeFirstWord = capitalizeFirstWord;
35
35
  exports.getEntitiesFromSearchV2Response = getEntitiesFromSearchV2Response;
36
- exports.findEntitiesFromSearchV2RelatedEntities = findEntitiesFromSearchV2RelatedEntities;
37
36
  exports.areDecimalNumbersEqual = areDecimalNumbersEqual;
38
37
  exports.formatIndianNumber = formatIndianNumber;
39
38
  exports.findDuplicateIds = findDuplicateIds;
@@ -400,58 +399,6 @@ function getEntitiesFromSearchV2Response(searchResponseV2, entityEnumKey, Entity
400
399
  }
401
400
  return (((_a = searchResponseV2.relatedEntities[entityEnumKey]) === null || _a === void 0 ? void 0 : _a.baseEntities) || []).map((entity) => Object.assign(new EntityClass(), entity));
402
401
  }
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
- }
455
402
  /**
456
403
  * Checks if two decimal numbers are approximately equal within a given tolerance.
457
404
  *
@@ -1,5 +1,3 @@
1
1
  export * from "./date.util";
2
2
  export * from "./helper.fn.util";
3
3
  export * from "./models/date-code.model.util";
4
- export * from "./string.util";
5
- export * from "./entity.flow.util";
@@ -17,5 +17,3 @@ 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);
@@ -1 +0,0 @@
1
- export declare function formatString(input: string): string;
@@ -1,15 +1 @@
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,6 +1,6 @@
1
1
  {
2
2
  "name": "law-common",
3
- "version": "10.19.1-beta.10",
3
+ "version": "10.19.1-beta.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -1,35 +0,0 @@
1
- import { IBillingTransactionApiEntity } from "../../api";
2
- import { BillingTransactionStatusEnum } from "../enums/billing-transaction-status.enum";
3
- import { BillingTransactionType } from "../enums/billing.transaction.enum";
4
- import { EntityEnum, EnumEntityType } from "../interface/entity.utils.interface";
5
- import { RelationConfigs } from "../interface/relation-config.interface";
6
- import { BankEntityModel } from "./bank.entity.model";
7
- import { BaseEntityModel } from "./base.entity.model";
8
- import { UserEntityModel } from "./user.entity.model";
9
- export declare class BillingTransactionEntityModel extends BaseEntityModel<EntityEnum.BILLING_TRANSACTION> implements IBillingTransactionApiEntity {
10
- id: number;
11
- billingId: number;
12
- type: BillingTransactionType;
13
- amount: number;
14
- details: string;
15
- bankCharges?: number;
16
- bankId?: number;
17
- paymentDate?: string;
18
- referenceNo?: string;
19
- supportingDocsUrls?: string;
20
- status: BillingTransactionStatusEnum;
21
- createdOn: string;
22
- updatedOn: string;
23
- createdBy: number;
24
- updatedBy: number;
25
- createdByUserName?: UserEntityModel;
26
- updatedByUserName?: UserEntityModel;
27
- bank?: BankEntityModel;
28
- getRelationConfigs(): any;
29
- static relationConfigs: RelationConfigs<[
30
- EntityEnum.USER,
31
- EntityEnum.USER,
32
- EntityEnum.BANK
33
- ], EnumEntityType<EntityEnum.BILLING_TRANSACTION>>;
34
- static fromApiEntity(apiEntity: IBillingTransactionApiEntity): BillingTransactionEntityModel;
35
- }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BillingTransactionEntityModel = void 0;
4
- const billing_transaction_status_enum_1 = require("../enums/billing-transaction-status.enum");
5
- const billing_transaction_enum_1 = require("../enums/billing.transaction.enum");
6
- const entity_utils_interface_1 = require("../interface/entity.utils.interface");
7
- const base_entity_model_1 = require("./base.entity.model");
8
- class BillingTransactionEntityModel extends base_entity_model_1.BaseEntityModel {
9
- constructor() {
10
- super(...arguments);
11
- this.id = 0;
12
- this.billingId = 0;
13
- this.type = billing_transaction_enum_1.BillingTransactionType.PAYMENT;
14
- this.amount = 0;
15
- this.details = "";
16
- this.status = billing_transaction_status_enum_1.BillingTransactionStatusEnum.APPROVED;
17
- this.createdOn = "";
18
- this.updatedOn = "";
19
- this.createdBy = 0;
20
- this.updatedBy = 0;
21
- }
22
- // billing?: BillingEntityModel;
23
- // bank?: BankEntityModel;
24
- getRelationConfigs() {
25
- return this.constructor.prototype.constructor.relationConfigs;
26
- }
27
- static fromApiEntity(apiEntity) {
28
- const entity = new BillingTransactionEntityModel(entity_utils_interface_1.EntityEnum.BILLING_TRANSACTION);
29
- Object.assign(entity, apiEntity);
30
- return entity;
31
- }
32
- }
33
- exports.BillingTransactionEntityModel = BillingTransactionEntityModel;
34
- BillingTransactionEntityModel.relationConfigs = [
35
- {
36
- name: entity_utils_interface_1.EntityEnum.USER,
37
- relation: base_entity_model_1.RelationType.ONE,
38
- key: "createdByUserName",
39
- mapKeyConfig: {
40
- relationKey: "id",
41
- key: "createdBy",
42
- },
43
- },
44
- {
45
- name: entity_utils_interface_1.EntityEnum.USER,
46
- relation: base_entity_model_1.RelationType.ONE,
47
- key: "updatedByUserName",
48
- mapKeyConfig: {
49
- relationKey: "id",
50
- key: "updatedBy",
51
- },
52
- },
53
- {
54
- name: entity_utils_interface_1.EntityEnum.BANK,
55
- relation: base_entity_model_1.RelationType.ONE,
56
- key: "bank",
57
- mapKeyConfig: {
58
- relationKey: "id",
59
- key: "bankId",
60
- },
61
- },
62
- ];
@@ -1,19 +0,0 @@
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
- }
@@ -1,60 +0,0 @@
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 = [];
@@ -1,32 +0,0 @@
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
- }[];
@@ -1,83 +0,0 @@
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
- }