law-common 10.18.2-beta.4 → 10.18.2-beta.6

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.
@@ -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(data) {
13
- super(entity_utils_interface_1.EntityEnum.LEAVE);
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.id = data.id;
17
- this.employeeId = data.employeeId;
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
- return new LeaveEntityModel(data);
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 new LeaveEntityModel(apiEntity);
114
+ return LeaveEntityModel.fromEntity(apiEntity);
115
115
  }
116
116
  static getPendingApprovalStatuses() {
117
117
  return [
@@ -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
+ }
@@ -2,3 +2,4 @@ export * from "./date.util";
2
2
  export * from "./helper.fn.util";
3
3
  export * from "./models/date-code.model.util";
4
4
  export * from "./string.util";
5
+ export * from "./entity.flow.util";
@@ -18,3 +18,4 @@ __exportStar(require("./date.util"), exports);
18
18
  __exportStar(require("./helper.fn.util"), exports);
19
19
  __exportStar(require("./models/date-code.model.util"), exports);
20
20
  __exportStar(require("./string.util"), exports);
21
+ __exportStar(require("./entity.flow.util"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "law-common",
3
- "version": "10.18.2-beta.4",
3
+ "version": "10.18.2-beta.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [