law-common 10.74.1-beta.7 → 10.74.1-beta.8

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.
@@ -22,6 +22,7 @@ export * from "./interface/office.location.entity.response";
22
22
  export * from "./interface/office.Location.update.dto.interface";
23
23
  export * from "./interface/billing.update.dto.interface";
24
24
  export * from "./interface/moving_timesheet.create.dto.interface";
25
+ export * from "./interface/moving_timesheet.entity.response";
25
26
  export * from "./interface/moving_timesheet.filter.dto.interface";
26
27
  export * from "./interface/moving_timesheet.update.dto.interface";
27
28
  export * from "./interface/bank.create.dto.interface";
@@ -38,6 +38,7 @@ __exportStar(require("./interface/office.location.entity.response"), exports);
38
38
  __exportStar(require("./interface/office.Location.update.dto.interface"), exports);
39
39
  __exportStar(require("./interface/billing.update.dto.interface"), exports);
40
40
  __exportStar(require("./interface/moving_timesheet.create.dto.interface"), exports);
41
+ __exportStar(require("./interface/moving_timesheet.entity.response"), exports);
41
42
  __exportStar(require("./interface/moving_timesheet.filter.dto.interface"), exports);
42
43
  __exportStar(require("./interface/moving_timesheet.update.dto.interface"), exports);
43
44
  __exportStar(require("./interface/bank.create.dto.interface"), exports);
@@ -0,0 +1,4 @@
1
+ import { FlowConfig, MovingTimesheetActionEnum, MovingTimesheetStatusEnum } from "../../entities";
2
+ export interface IMovingTimesheetFlowConfigContextData {
3
+ }
4
+ export type IIMovingTimesheetFlowConfig = FlowConfig<MovingTimesheetStatusEnum, MovingTimesheetActionEnum, IMovingTimesheetFlowConfigContextData>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { IIMovingTimesheetFlowConfig } from "../../api";
2
+ export declare const movingTimesheetFlowConfig: IIMovingTimesheetFlowConfig;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.movingTimesheetFlowConfig = void 0;
4
+ const moving_timesheet_action_enum_1 = require("../enums/moving_timesheet_action_enum");
5
+ const moving_timesheet_status_enum_1 = require("../enums/moving_timesheet_status_enum");
6
+ exports.movingTimesheetFlowConfig = {
7
+ [moving_timesheet_status_enum_1.MovingTimesheetStatusEnum.PENDING_APPROVAL]: {
8
+ actions: {
9
+ [moving_timesheet_action_enum_1.MovingTimesheetActionEnum.APPROVE]: {
10
+ permissions: ["MOVING_TIMESHEET_APPROVE"],
11
+ next: () => moving_timesheet_status_enum_1.MovingTimesheetStatusEnum.APPROVED,
12
+ },
13
+ [moving_timesheet_action_enum_1.MovingTimesheetActionEnum.REJECT]: {
14
+ permissions: ["MOVING_TIMESHEET_APPROVE"],
15
+ next: () => moving_timesheet_status_enum_1.MovingTimesheetStatusEnum.REJECTED,
16
+ },
17
+ },
18
+ },
19
+ [moving_timesheet_status_enum_1.MovingTimesheetStatusEnum.APPROVED]: {
20
+ actions: {},
21
+ },
22
+ [moving_timesheet_status_enum_1.MovingTimesheetStatusEnum.REJECTED]: {
23
+ actions: {},
24
+ },
25
+ };
@@ -11,5 +11,4 @@ export interface IMovingTimesheetEntity extends IEntityAuditColumn {
11
11
  }
12
12
  export interface IMovingTimesheetActionDataDto {
13
13
  action: MovingTimesheetActionEnum;
14
- remark?: string;
15
14
  }
@@ -1,10 +1,14 @@
1
+ import { IMovingTimesheetUpdateDto } from "../../api";
2
+ import { MovingTimesheetActionEnum } from "../enums/moving_timesheet_action_enum";
1
3
  import { MovingTimesheetStatusEnum } from "../enums/moving_timesheet_status_enum";
2
4
  import { EntityEnum } from "../interface/entity.utils.interface";
3
5
  import { IMovingTimesheetEntity } from "../interface/moving_timesheet.entity.interface";
4
6
  import { RelationConfigs } from "../interface/relation-config.interface";
5
7
  import { BaseEntityModel } from "./base.entity.model";
8
+ import { IRowActions } from "./interface/row-actions.interface";
6
9
  import { ProjectEntityModel } from "./project.entity.model";
7
10
  import { TimesheetEntityModel } from "./timesheet.entity.model";
11
+ import { UserEntityModel } from "./user.entity.model";
8
12
  export declare class MovingTimesheetEntityModel extends BaseEntityModel<EntityEnum.MOVING_TIMESHEET> implements IMovingTimesheetEntity {
9
13
  id: number;
10
14
  timesheetId: number;
@@ -19,6 +23,20 @@ export declare class MovingTimesheetEntityModel extends BaseEntityModel<EntityEn
19
23
  reason: string;
20
24
  remark?: string;
21
25
  static fromEntity(entity: IMovingTimesheetEntity): MovingTimesheetEntityModel;
26
+ getAvailableActions(currentUser: UserEntityModel, config?: {
27
+ combinedActions?: Record<string, {
28
+ combineActions: MovingTimesheetActionEnum[];
29
+ label: string;
30
+ }>;
31
+ customLabels?: Partial<Record<MovingTimesheetActionEnum, string>>;
32
+ }): IRowActions<EntityEnum.MOVING_TIMESHEET>[];
33
+ getUpdateActionVisibility(currentUser: UserEntityModel): {
34
+ [key: string]: () => boolean;
35
+ };
36
+ getNextStatus(currentUser: UserEntityModel, dto: IMovingTimesheetUpdateDto): MovingTimesheetStatusEnum;
37
+ mapStatusLabel(status: MovingTimesheetStatusEnum): string;
38
+ static getPendingApprovalStatuses(): MovingTimesheetStatusEnum[];
39
+ static getFormattedStatus(status: MovingTimesheetStatusEnum): string;
22
40
  static relationConfigs: RelationConfigs<[EntityEnum.TIMESHEET, EntityEnum.PROJECT], EntityEnum.MOVING_TIMESHEET>;
23
41
  getRelationConfigs(): [import("../interface/relation-config.interface").IRelationConfig<EntityEnum.TIMESHEET, EntityEnum.MOVING_TIMESHEET>, import("../interface/relation-config.interface").IRelationConfig<EntityEnum.PROJECT, EntityEnum.MOVING_TIMESHEET>];
24
42
  }
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MovingTimesheetEntityModel = void 0;
4
+ const error_key_enum_1 = require("../../enums/error.key.enum");
5
+ const exceptions_1 = require("../../exceptions");
6
+ const utils_1 = require("../../utils");
7
+ const string_util_1 = require("../../utils/string.util");
4
8
  const moving_timesheet_status_enum_1 = require("../enums/moving_timesheet_status_enum");
5
9
  const relation_type_enum_1 = require("../enums/relation-type.enum");
10
+ const moving_timesheet_flow_config_1 = require("../flow-configs/moving_timesheet_flow.config");
6
11
  const entity_utils_interface_1 = require("../interface/entity.utils.interface");
7
12
  const base_entity_model_1 = require("./base.entity.model");
8
13
  class MovingTimesheetEntityModel extends base_entity_model_1.BaseEntityModel {
@@ -23,6 +28,88 @@ class MovingTimesheetEntityModel extends base_entity_model_1.BaseEntityModel {
23
28
  Object.assign(result, entity);
24
29
  return result;
25
30
  }
31
+ getAvailableActions(currentUser, config) {
32
+ var _a;
33
+ const params = {
34
+ flowConfig: moving_timesheet_flow_config_1.movingTimesheetFlowConfig,
35
+ currentStatus: this.status,
36
+ userPermissions: (_a = currentUser.permissions) !== null && _a !== void 0 ? _a : [],
37
+ visibilityData: this.getUpdateActionVisibility.bind(this, currentUser),
38
+ combinedActions: config === null || config === void 0 ? void 0 : config.combinedActions,
39
+ customLabels: config === null || config === void 0 ? void 0 : config.customLabels,
40
+ };
41
+ return utils_1.EntityActionFlowResolverV2.getAvailableActionsData(params);
42
+ }
43
+ getUpdateActionVisibility(currentUser) {
44
+ return {
45
+ MOVING_TIMESHEET_UPDATE_SELF: () => currentUser.id === this.createdBy,
46
+ MOVING_TIMESHEET_DELETE_SELF: () => currentUser.id === this.createdBy,
47
+ };
48
+ }
49
+ getNextStatus(currentUser, dto) {
50
+ if (!this.status) {
51
+ throw new exceptions_1.AppBadRequestException({
52
+ key: error_key_enum_1.ErrorKeyEnum.STATUS,
53
+ message: [`Status not found: ${this.status}`],
54
+ });
55
+ }
56
+ const flowForStatus = moving_timesheet_flow_config_1.movingTimesheetFlowConfig[this.status];
57
+ if (!flowForStatus) {
58
+ throw new exceptions_1.AppBadRequestException({
59
+ key: error_key_enum_1.ErrorKeyEnum.STATUS,
60
+ message: [`No flow configuration found for status: ${this.status}`],
61
+ });
62
+ }
63
+ if (!(dto === null || dto === void 0 ? void 0 : dto.actionData)) {
64
+ throw new exceptions_1.AppBadRequestException({
65
+ key: error_key_enum_1.ErrorKeyEnum.ACTION_DATA,
66
+ message: ["dto.actionData is required"],
67
+ });
68
+ }
69
+ const matchingPermissionConfig = flowForStatus.actions[dto.actionData.action];
70
+ if (!matchingPermissionConfig) {
71
+ throw new exceptions_1.AppBadRequestException({
72
+ key: error_key_enum_1.ErrorKeyEnum.ACTION,
73
+ message: [`Action '${dto.actionData.action}' is not valid for the current status.`],
74
+ });
75
+ }
76
+ if (!currentUser.permissions || currentUser.permissions.length === 0) {
77
+ throw new exceptions_1.AppBadRequestException({
78
+ key: error_key_enum_1.ErrorKeyEnum.PERMISSIONS,
79
+ message: ["Permission not available for currentUser"],
80
+ });
81
+ }
82
+ const hasPermission = matchingPermissionConfig.permissions.some((permission) => { var _a; return (_a = currentUser.permissions) === null || _a === void 0 ? void 0 : _a.includes(permission); });
83
+ if (!hasPermission) {
84
+ throw new exceptions_1.AppBadRequestException({
85
+ key: error_key_enum_1.ErrorKeyEnum.PERMISSION,
86
+ message: [`Current user does not have permission to ${dto.actionData.action} moving timesheet`],
87
+ });
88
+ }
89
+ return matchingPermissionConfig.next({});
90
+ }
91
+ mapStatusLabel(status) {
92
+ var _a;
93
+ const labelMap = {
94
+ [moving_timesheet_status_enum_1.MovingTimesheetStatusEnum.PENDING_APPROVAL]: "Pending Approval",
95
+ [moving_timesheet_status_enum_1.MovingTimesheetStatusEnum.APPROVED]: "Approved",
96
+ [moving_timesheet_status_enum_1.MovingTimesheetStatusEnum.REJECTED]: "Rejected",
97
+ };
98
+ return (_a = labelMap[status]) !== null && _a !== void 0 ? _a : status;
99
+ }
100
+ static getPendingApprovalStatuses() {
101
+ return [moving_timesheet_status_enum_1.MovingTimesheetStatusEnum.PENDING_APPROVAL];
102
+ }
103
+ static getFormattedStatus(status) {
104
+ let statusToReturn = "";
105
+ if (MovingTimesheetEntityModel.getPendingApprovalStatuses().includes(status)) {
106
+ statusToReturn = "PENDING_APPROVAL";
107
+ }
108
+ else {
109
+ statusToReturn = status.toString();
110
+ }
111
+ return (0, string_util_1.formatString)(statusToReturn);
112
+ }
26
113
  getRelationConfigs() {
27
114
  return MovingTimesheetEntityModel.relationConfigs;
28
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "law-common",
3
- "version": "10.74.1-beta.7",
3
+ "version": "10.74.1-beta.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [