law-common 10.20.0 → 10.21.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/api/interface/billing.create.dto.interface.d.ts +2 -2
- package/dist/src/entities/index.d.ts +1 -0
- package/dist/src/entities/index.js +1 -0
- package/dist/src/entities/interface/billing_timesheet.entity.interface.d.ts +2 -2
- 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 +2 -2
- package/dist/src/entities/model/entity.model.interface.js +7 -0
- 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 +30 -0
- package/dist/src/utils/entity.flow.util.js +54 -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 +35 -35
|
@@ -16,7 +16,7 @@ export interface IBillingCreateDtoExtra {
|
|
|
16
16
|
}
|
|
17
17
|
export interface IBillingTimesheetUnchangedDto {
|
|
18
18
|
id: number;
|
|
19
|
-
amount
|
|
19
|
+
amount?: number;
|
|
20
20
|
}
|
|
21
21
|
export interface IBillingTimesheetUpdateDeleteDetailDto {
|
|
22
22
|
id: number;
|
|
@@ -24,7 +24,7 @@ export interface IBillingTimesheetUpdateDeleteDetailDto {
|
|
|
24
24
|
description: string;
|
|
25
25
|
date: string;
|
|
26
26
|
duration: number;
|
|
27
|
-
amount
|
|
27
|
+
amount?: number;
|
|
28
28
|
impact: BillingImpactEnum;
|
|
29
29
|
amendmentPurpose: string;
|
|
30
30
|
}
|
|
@@ -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);
|
|
@@ -13,7 +13,7 @@ export interface IBillingTimesheetEntity extends IAuditColumnEntity {
|
|
|
13
13
|
task: string;
|
|
14
14
|
description?: string;
|
|
15
15
|
totalDuration: number;
|
|
16
|
-
totalAmount
|
|
16
|
+
totalAmount?: number;
|
|
17
17
|
impact: BillingImpactEnum;
|
|
18
18
|
amendmentPurpose?: string;
|
|
19
19
|
changedStatus: BillingTimesheetStatusEnum;
|
|
@@ -23,7 +23,7 @@ export interface IBillingTimesheetEntityCreateDto extends IEntityCreateDto<IBill
|
|
|
23
23
|
export interface IBillingTimesheetDetail extends IAuditColumnEntity {
|
|
24
24
|
timesheetId: number;
|
|
25
25
|
billingId: number;
|
|
26
|
-
totalAmount
|
|
26
|
+
totalAmount?: number;
|
|
27
27
|
changedStatus: BillingTimesheetStatusEnum;
|
|
28
28
|
impact: BillingImpactEnum;
|
|
29
29
|
amendmentPurpose?: string;
|
|
@@ -10,6 +10,9 @@ import { BillingEntityModel } from "../model/billing.entity.model";
|
|
|
10
10
|
import { ClientAffiliateEntityModel } from "../model/client-affiliate.entity.model";
|
|
11
11
|
import { ClientEntityModel } from "../model/client.entity.model";
|
|
12
12
|
import { ConfigurationEntityModel } from "../model/configuration.model";
|
|
13
|
+
import { HolidayEntityModel } from "../model/holiday.entity.model";
|
|
14
|
+
import { LeaveEntityModel } from "../model/leave.entity.model";
|
|
15
|
+
import { LeaveCountVirtualEntityModel } from "../model/leave_count.entity.model";
|
|
13
16
|
import { ProjectUserMappingEntityModel } from "../model/project-user-mapping.entity.model";
|
|
14
17
|
import { ProjectEntityModel } from "../model/project.entity.model";
|
|
15
18
|
import { ReimbursementExpenseEntityModel } from "../model/reimbursement-expense.entity.model";
|
|
@@ -281,12 +284,12 @@ export declare enum VirtualEntityEnum {
|
|
|
281
284
|
}
|
|
282
285
|
export type IHistoryConstraintSearchResponse<T> = IBaseResponse<IHistoryEntitySearchByConstraintResponse<T>[]>;
|
|
283
286
|
export type IHistoryConstraintSearchServiceResponse<T> = IHistoryEntitySearchByConstraintResponse<T>[];
|
|
284
|
-
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;
|
|
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.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 : UserEntityModel;
|
|
285
288
|
export type EntityMap = {
|
|
286
|
-
[key in EntityEnum]: EnumToModel<key>[];
|
|
289
|
+
[key in EntityEnum | VirtualEntityEnum]: EnumToModel<key>[];
|
|
287
290
|
};
|
|
288
291
|
export type EntityIndexMap = {
|
|
289
|
-
[key in EntityEnum]: {
|
|
292
|
+
[key in EntityEnum | VirtualEntityEnum]: {
|
|
290
293
|
[id: number]: EnumToModel<key>;
|
|
291
294
|
};
|
|
292
295
|
};
|
|
@@ -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,8 @@
|
|
|
1
|
-
import { EntityEnum, EntityIndexMap, EntityMap, EnumEntityType, IBaseEntityApiResponse } from "../interface/entity.utils.interface";
|
|
1
|
+
import { EntityEnum, EntityIndexMap, EntityMap, EnumEntityType, 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 function parseEntities<T extends EnumEntityType<EntityEnum>>(json: IBaseEntityApiResponse<T>, baseEntity: EntityEnum, entityMap: EntityMap): EntityMap;
|
|
8
|
+
export declare function parseEntities<T extends EnumEntityType<EntityEnum | VirtualEntityEnum>>(json: IBaseEntityApiResponse<T>, baseEntity: EntityEnum | VirtualEntityEnum, entityMap: EntityMap): EntityMap;
|
|
@@ -12,6 +12,9 @@ const billing_timesheet_entity_model_1 = require("./billing-timesheet.entity.mod
|
|
|
12
12
|
const billing_entity_model_1 = require("./billing.entity.model");
|
|
13
13
|
const client_affiliate_entity_model_1 = require("./client-affiliate.entity.model");
|
|
14
14
|
const client_entity_model_1 = require("./client.entity.model");
|
|
15
|
+
const holiday_entity_model_1 = require("./holiday.entity.model");
|
|
16
|
+
const leave_entity_model_1 = require("./leave.entity.model");
|
|
17
|
+
const leave_count_entity_model_1 = require("./leave_count.entity.model");
|
|
15
18
|
const configuration_model_1 = require("./configuration.model");
|
|
16
19
|
const project_user_mapping_entity_model_1 = require("./project-user-mapping.entity.model");
|
|
17
20
|
const project_entity_model_1 = require("./project.entity.model");
|
|
@@ -58,6 +61,10 @@ function parseEntities(json, baseEntity, entityMap) {
|
|
|
58
61
|
[entity_utils_interface_1.EntityEnum.REIMBURSEMENT]: reimbursement_entity_model_1.ReimbursementEntityModel.fromApiEntity,
|
|
59
62
|
[entity_utils_interface_1.EntityEnum.REIMBURSEMENT_EXPENSE]: reimbursement_expense_entity_model_1.ReimbursementExpenseEntityModel.fromApiEntity,
|
|
60
63
|
[entity_utils_interface_1.EntityEnum.BILLING_REIMBURSEMENT_EXPENSE]: billing_reimbursement_expense_entity_model_1.BillingReimbursementExpneseEntityModel.fromApiEntity,
|
|
64
|
+
[entity_utils_interface_1.EntityEnum.HOLIDAY]: holiday_entity_model_1.HolidayEntityModel.fromApiEntity,
|
|
65
|
+
[entity_utils_interface_1.EntityEnum.LEAVE]: leave_entity_model_1.LeaveEntityModel.fromApiEntity,
|
|
66
|
+
[entity_utils_interface_1.VirtualEntityEnum.LEAVE_COUNT]: leave_count_entity_model_1.LeaveCountVirtualEntityModel.fromApiEntity,
|
|
67
|
+
// Add other entities here as needed
|
|
61
68
|
[entity_utils_interface_1.EntityEnum.CLIENT_AFFILIATE]: client_affiliate_entity_model_1.ClientAffiliateEntityModel.fromApiEntity,
|
|
62
69
|
[entity_utils_interface_1.EntityEnum.BANK]: bank_entity_model_1.BankEntityModel.fromApiEntity,
|
|
63
70
|
[entity_utils_interface_1.EntityEnum.CONFIGURATION]: configuration_model_1.ConfigurationEntityModel.fromApiEntity,
|
|
@@ -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,30 @@
|
|
|
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 data - Optional function to provide additional visibility conditions based on the entity data
|
|
13
|
+
* @returns Array of available actions with labels and values
|
|
14
|
+
* @throws Error if user has multiple permissions for a single action
|
|
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'][], data?: (a: E) => {
|
|
26
|
+
[key: string]: () => boolean;
|
|
27
|
+
}): {
|
|
28
|
+
label: string;
|
|
29
|
+
value: T['action'] | string;
|
|
30
|
+
}[];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPermittedActions = getPermittedActions;
|
|
4
|
+
const entities_1 = require("../entities");
|
|
5
|
+
/**
|
|
6
|
+
* Gets available actions for a leave based on current status and user permissions
|
|
7
|
+
* @param entityFlowConfig - The flow configuration for the entity
|
|
8
|
+
* @param currentStatus - The current status of the leave
|
|
9
|
+
* @param userPermissions - Array of permissions the user has
|
|
10
|
+
* @param combineActions - Array of action values to combine into a single action
|
|
11
|
+
* @param data - Optional function to provide additional visibility conditions based on the entity data
|
|
12
|
+
* @returns Array of available actions with labels and values
|
|
13
|
+
* @throws Error if user has multiple permissions for a single action
|
|
14
|
+
*/
|
|
15
|
+
function getPermittedActions(entityFlowConfig, currentStatus, userPermissions, combineActions = [], data = (_) => ({})) {
|
|
16
|
+
var _a;
|
|
17
|
+
// Handle invalid inputs
|
|
18
|
+
if (!currentStatus || !entityFlowConfig[currentStatus]) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const actionConfig = ((_a = entityFlowConfig[currentStatus]) === null || _a === void 0 ? void 0 : _a.actions) || {};
|
|
22
|
+
// Filter actions based on user permissions
|
|
23
|
+
const permittedActions = Object.entries(actionConfig)
|
|
24
|
+
.filter(([actionKey, config]) => {
|
|
25
|
+
var _a;
|
|
26
|
+
const actionRequiredPermissions = (_a = config.permissions) !== null && _a !== void 0 ? _a : [];
|
|
27
|
+
const matchingPermissions = actionRequiredPermissions.filter((permission) => userPermissions.includes(permission));
|
|
28
|
+
// Check for multiple permissions
|
|
29
|
+
if (matchingPermissions.length > 1) {
|
|
30
|
+
throw new Error(`Multiple permissions found for action ${actionKey}: ${matchingPermissions.join(', ')}`);
|
|
31
|
+
}
|
|
32
|
+
return matchingPermissions.length > 0 && (!data || !data({})[matchingPermissions[0]] || data({})[matchingPermissions[0]]());
|
|
33
|
+
})
|
|
34
|
+
.map(([actionKey, _]) => ({
|
|
35
|
+
label: entities_1.LeaveActionEnum.getLabel(actionKey) || '',
|
|
36
|
+
value: actionKey,
|
|
37
|
+
}));
|
|
38
|
+
// // Combine specified actions if all are present and combineActions is not empty
|
|
39
|
+
if (combineActions.length > 0) {
|
|
40
|
+
const isCombinedActionPresent = combineActions.every((action) => permittedActions.some((a) => a.value === action));
|
|
41
|
+
if (isCombinedActionPresent) {
|
|
42
|
+
return [
|
|
43
|
+
...permittedActions.filter((action) => !combineActions.includes(action.value)),
|
|
44
|
+
{
|
|
45
|
+
label: combineActions
|
|
46
|
+
.map((a) => entities_1.LeaveActionEnum.getLabel(a) || '')
|
|
47
|
+
.join('/'),
|
|
48
|
+
value: combineActions.join('_'),
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return permittedActions;
|
|
54
|
+
}
|
package/dist/src/utils/index.js
CHANGED
|
@@ -17,3 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./date.util"), exports);
|
|
18
18
|
__exportStar(require("./helper.fn.util"), exports);
|
|
19
19
|
__exportStar(require("./models/date-code.model.util"), exports);
|
|
20
|
+
__exportStar(require("./string.util"), exports);
|
|
21
|
+
__exportStar(require("./entity.flow.util"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatString(input: string): string;
|
|
@@ -1 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatString = formatString;
|
|
4
|
+
function formatString(input) {
|
|
5
|
+
if (input.includes('_')) {
|
|
6
|
+
return input
|
|
7
|
+
.split('_')
|
|
8
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
9
|
+
.join(' ');
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
// For single-word strings, capitalize the first letter
|
|
13
|
+
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "law-common",
|
|
3
|
-
"version": "10.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"files": [
|
|
7
|
-
"dist/**/*"
|
|
8
|
-
],
|
|
9
|
-
"scripts": {
|
|
10
|
-
"clean": "rm -rf dist",
|
|
11
|
-
"build": "npm run clean && tsc",
|
|
12
|
-
"publish:beta": "npm version prerelease --preid beta && git push && npm run build && npm publish --tag beta",
|
|
13
|
-
"publish:patch": "npm version patch && git push && npm run build && npm publish",
|
|
14
|
-
"publish:minor": "npm version minor && git push && npm run build && npm publish",
|
|
15
|
-
"publish:major": "npm version major && git push && npm run build && npm publish",
|
|
16
|
-
"link": "npm run build && npm link",
|
|
17
|
-
"test": "jest"
|
|
18
|
-
},
|
|
19
|
-
"keywords": [],
|
|
20
|
-
"author": "",
|
|
21
|
-
"license": "ISC",
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@types/jest": "^29.5.13",
|
|
24
|
-
"@types/node": "^22.6.1",
|
|
25
|
-
"jest": "^29.7.0",
|
|
26
|
-
"ts-jest": "^29.2.5",
|
|
27
|
-
"ts-node": "^10.9.2",
|
|
28
|
-
"typescript": "^5.6.2"
|
|
29
|
-
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"@types/express": "^5.0.0",
|
|
32
|
-
"@types/multer": "^1.4.12",
|
|
33
|
-
"date-fns": "^4.1.0"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "law-common",
|
|
3
|
+
"version": "10.21.1-beta.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist/**/*"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"clean": "rm -rf dist",
|
|
11
|
+
"build": "npm run clean && tsc",
|
|
12
|
+
"publish:beta": "npm version prerelease --preid beta && git push && npm run build && npm publish --tag beta",
|
|
13
|
+
"publish:patch": "npm version patch && git push && npm run build && npm publish",
|
|
14
|
+
"publish:minor": "npm version minor && git push && npm run build && npm publish",
|
|
15
|
+
"publish:major": "npm version major && git push && npm run build && npm publish",
|
|
16
|
+
"link": "npm run build && npm link",
|
|
17
|
+
"test": "jest"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [],
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/jest": "^29.5.13",
|
|
24
|
+
"@types/node": "^22.6.1",
|
|
25
|
+
"jest": "^29.7.0",
|
|
26
|
+
"ts-jest": "^29.2.5",
|
|
27
|
+
"ts-node": "^10.9.2",
|
|
28
|
+
"typescript": "^5.6.2"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@types/express": "^5.0.0",
|
|
32
|
+
"@types/multer": "^1.4.12",
|
|
33
|
+
"date-fns": "^4.1.0"
|
|
34
|
+
}
|
|
35
|
+
}
|