law-common 10.18.2-beta.3 → 10.18.2-beta.5
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.
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { EntityEnum, EntityIndexMap,
|
|
1
|
+
import { EntityEnum, EntityIndexMap, VirtualEntityEnum } from "../interface/entity.utils.interface";
|
|
2
|
+
export declare enum RelationType {
|
|
3
|
+
ONE = "one",
|
|
4
|
+
MANY = "many"
|
|
5
|
+
}
|
|
2
6
|
export declare abstract class BaseEntityModel<T extends EntityEnum | VirtualEntityEnum> {
|
|
3
7
|
protected entityName: T;
|
|
4
8
|
constructor(entityName: T);
|
|
@@ -6,5 +10,5 @@ export declare abstract class BaseEntityModel<T extends EntityEnum | VirtualEnti
|
|
|
6
10
|
populateRelationsByIndex(entityIndexMap: EntityIndexMap): void;
|
|
7
11
|
static populateRelationsForEntities(entityIndexMap: EntityIndexMap, entityType: EntityEnum): void;
|
|
8
12
|
populateRelations(entityIndexMap: EntityIndexMap): void;
|
|
9
|
-
overwrite(entityIndexMap: EntityIndexMap, indexKey?:
|
|
13
|
+
overwrite(entityIndexMap: EntityIndexMap, indexKey?: string): this;
|
|
10
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,7 +58,6 @@ 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
|
}
|
|
@@ -73,7 +70,6 @@ class BaseEntityModel {
|
|
|
73
70
|
console.warn(`Entity of type ${this.entityName} does not have ${indexKey}, cannot merge`);
|
|
74
71
|
return this;
|
|
75
72
|
}
|
|
76
|
-
// @ts-ignore
|
|
77
73
|
entityIndexMap[this.entityName][this[indexKey]] = this;
|
|
78
74
|
return this;
|
|
79
75
|
}
|
|
@@ -26,7 +26,6 @@ export declare class LeaveEntityModel extends BaseEntityModel<EntityEnum.LEAVE>
|
|
|
26
26
|
createdByUser?: UserEntityModel;
|
|
27
27
|
updatedByUser?: UserEntityModel;
|
|
28
28
|
user?: UserEntityModel;
|
|
29
|
-
private constructor();
|
|
30
29
|
static fromEntity(data: ILeaveApiEntity): LeaveEntityModel;
|
|
31
30
|
getLeaveDuration(excludeWeekdays?: Weekday[], excludeDates?: DateCodeModel[]): number;
|
|
32
31
|
static getLeaveDuration(leaves: LeaveEntityModel[], excludeWeekdays?: Weekday[], excludeDates?: DateCodeModel[], leaveStatusEnum?: LeaveStatusEnum[]): number;
|
|
@@ -4,31 +4,31 @@ exports.LeaveEntityModel = void 0;
|
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
5
|
const string_util_1 = require("../../utils/string.util");
|
|
6
6
|
const duration_type_enum_1 = require("../enums/duration-type.enum");
|
|
7
|
+
const leave_type_enum_1 = require("../enums/leave-type.enum");
|
|
7
8
|
const leave_status_enum_1 = require("../enums/leave.status.enum");
|
|
8
9
|
const relation_type_enum_1 = require("../enums/relation-type.enum");
|
|
9
10
|
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
10
11
|
const base_entity_model_1 = require("./base.entity.model");
|
|
11
12
|
class LeaveEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
12
|
-
constructor(
|
|
13
|
-
super(
|
|
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;
|
|
14
23
|
this.createdOn = "";
|
|
15
24
|
this.updatedOn = "";
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.fromDate = data.fromDate;
|
|
19
|
-
this.toDate = data.toDate;
|
|
20
|
-
this.reason = data.reason;
|
|
21
|
-
this.durationType = data.durationType;
|
|
22
|
-
this.status = data.status;
|
|
23
|
-
this.remark = data.remark;
|
|
24
|
-
this.type = data.type;
|
|
25
|
-
this.createdOn = data.createdOn;
|
|
26
|
-
this.updatedOn = data.updatedOn;
|
|
27
|
-
this.createdBy = data.createdBy;
|
|
28
|
-
this.updatedBy = data.updatedBy;
|
|
25
|
+
this.createdBy = 0;
|
|
26
|
+
this.updatedBy = 0;
|
|
29
27
|
}
|
|
30
28
|
static fromEntity(data) {
|
|
31
|
-
|
|
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()) {
|
|
@@ -111,7 +111,7 @@ class LeaveEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
|
111
111
|
return this.constructor.prototype.constructor.relationConfigs;
|
|
112
112
|
}
|
|
113
113
|
static fromApiEntity(apiEntity) {
|
|
114
|
-
return
|
|
114
|
+
return LeaveEntityModel.fromEntity(apiEntity);
|
|
115
115
|
}
|
|
116
116
|
static getPendingApprovalStatuses() {
|
|
117
117
|
return [
|