law-common 10.61.2-beta.0 → 10.61.2-beta.2
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/vendor-invoice.entity.response.d.ts +2 -2
- package/dist/src/entities/model/vendor.entity.model.d.ts +6 -1
- package/dist/src/entities/model/vendor.entity.model.js +46 -0
- package/dist/src/entities/model/vendor_invoice.entity.model.d.ts +3 -0
- package/dist/src/entities/model/vendor_invoice.entity.model.js +51 -0
- package/dist/src/entities/model/vendor_invoice_item.entity.model.d.ts +3 -0
- package/dist/src/entities/model/vendor_invoice_item.entity.model.js +43 -0
- package/dist/src/enums/error.key.enum.d.ts +2 -1
- package/dist/src/enums/error.key.enum.js +1 -0
- package/dist/src/utils/entity.flow.util.d.ts +44 -0
- package/dist/src/utils/entity.flow.util.js +69 -1
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { IVendorInvoiceEntity,
|
|
1
|
+
import { IVendorInvoiceEntity, VendorInvoiceActionStatusEnum, VendorInvoiceItemEntityModel } from "../../entities";
|
|
2
2
|
import { VendorInvoiceActionEnum } from "../../entities/enums/vendor_invoice_action.enum";
|
|
3
3
|
import { VendorInvoiceItemActionEnum } from "../../entities/enums/vendor_invoice_item_action.enum";
|
|
4
4
|
import { VendorInvoiceItemStatus } from "../../entities/enums/vendor_invoice_item_status.enum";
|
|
5
5
|
export interface IVendorInvoiceFlowContextData {
|
|
6
6
|
invoice: IVendorInvoiceEntity;
|
|
7
|
-
items:
|
|
7
|
+
items: VendorInvoiceItemEntityModel[];
|
|
8
8
|
}
|
|
9
9
|
export type IVendorInvoiceFlowConfig = {
|
|
10
10
|
parent: {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { EntityEnum, Nullable } from "../interface/entity.utils.interface";
|
|
1
|
+
import { EntityEnum, IEntityUpdateDto, Nullable } from "../interface/entity.utils.interface";
|
|
2
2
|
import { RelationConfigs } from "../interface/relation-config.interface";
|
|
3
3
|
import { BaseEntityModel } from "./base.entity.model";
|
|
4
|
+
import { IVendorActionDataDto } from "../../api";
|
|
4
5
|
import { VendorStatusEnum } from "../enums/vendor-status.enum";
|
|
5
6
|
import { VendorContractApplicabilityEnum } from "../enums/vendor_contract_applicability_enum";
|
|
6
7
|
import { VendorGstTypeEnum } from "../enums/vendor_gst_type_enum";
|
|
7
8
|
import { VendorLocationTypeEnum } from "../enums/vendor_location_type_enum";
|
|
8
9
|
import { VendorPanTypeEnum } from "../enums/vendor_pan_type_enum";
|
|
10
|
+
import { IUserEntity } from "../interface/user.entity.interface";
|
|
9
11
|
import { IVendorEntity } from "../interface/vendor.entity.interface";
|
|
10
12
|
import { OrganizationTypeEntityModel } from "./organization_type.entity.model";
|
|
11
13
|
export declare class VendorEntityModel extends BaseEntityModel<EntityEnum.VENDOR> implements IVendorEntity {
|
|
@@ -42,4 +44,7 @@ export declare class VendorEntityModel extends BaseEntityModel<EntityEnum.VENDOR
|
|
|
42
44
|
static relationConfigs: RelationConfigs<[], EntityEnum.VENDOR>;
|
|
43
45
|
static fromEntity(entity: IVendorEntity): VendorEntityModel;
|
|
44
46
|
getRelationConfigs(): any[];
|
|
47
|
+
getNextStatus(currentUser: IUserEntity, dto: IEntityUpdateDto<IVendorEntity> & {
|
|
48
|
+
actionData: IVendorActionDataDto;
|
|
49
|
+
}): VendorStatusEnum;
|
|
45
50
|
}
|
|
@@ -3,11 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VendorEntityModel = void 0;
|
|
4
4
|
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
5
5
|
const base_entity_model_1 = require("./base.entity.model");
|
|
6
|
+
const error_key_enum_1 = require("../../enums/error.key.enum");
|
|
7
|
+
const exceptions_1 = require("../../exceptions");
|
|
6
8
|
const vendor_status_enum_1 = require("../enums/vendor-status.enum");
|
|
7
9
|
const vendor_contract_applicability_enum_1 = require("../enums/vendor_contract_applicability_enum");
|
|
8
10
|
const vendor_gst_type_enum_1 = require("../enums/vendor_gst_type_enum");
|
|
9
11
|
const vendor_location_type_enum_1 = require("../enums/vendor_location_type_enum");
|
|
10
12
|
const vendor_pan_type_enum_1 = require("../enums/vendor_pan_type_enum");
|
|
13
|
+
const vendor_flow_config_1 = require("../flow-configs/vendor-flow.config");
|
|
11
14
|
class VendorEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
12
15
|
constructor() {
|
|
13
16
|
super(...arguments);
|
|
@@ -52,6 +55,49 @@ class VendorEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
|
52
55
|
getRelationConfigs() {
|
|
53
56
|
return this.constructor.prototype.constructor.relationConfigs || [];
|
|
54
57
|
}
|
|
58
|
+
getNextStatus(currentUser, dto) {
|
|
59
|
+
if (!this.status) {
|
|
60
|
+
throw new exceptions_1.AppBadRequestException({
|
|
61
|
+
key: error_key_enum_1.ErrorKeyEnum.STATUS,
|
|
62
|
+
message: [`Status not found: ${this.status}`],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const flowForStatus = vendor_flow_config_1.vendorFlowConfig[this.status];
|
|
66
|
+
if (!flowForStatus) {
|
|
67
|
+
throw new exceptions_1.AppBadRequestException({
|
|
68
|
+
key: error_key_enum_1.ErrorKeyEnum.STATUS,
|
|
69
|
+
message: [`No flow configuration found for status: ${this.status}`],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (!(dto === null || dto === void 0 ? void 0 : dto.actionData)) {
|
|
73
|
+
throw new exceptions_1.AppBadRequestException({
|
|
74
|
+
key: error_key_enum_1.ErrorKeyEnum.ACTION_DATA,
|
|
75
|
+
message: ["dto.actionData is required"],
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const matchingPermissionConfig = flowForStatus.actions[dto.actionData.action];
|
|
79
|
+
if (!matchingPermissionConfig) {
|
|
80
|
+
throw new exceptions_1.AppBadRequestException({
|
|
81
|
+
key: error_key_enum_1.ErrorKeyEnum.ACTION,
|
|
82
|
+
message: [`Action '${dto.actionData.action}' is not valid for the current status.`],
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (!currentUser.permissions || currentUser.permissions.length === 0) {
|
|
86
|
+
throw new exceptions_1.AppBadRequestException({
|
|
87
|
+
key: error_key_enum_1.ErrorKeyEnum.PERMISSIONS,
|
|
88
|
+
message: ["Permission not available for currentUser"],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const hasPermission = matchingPermissionConfig.permissions.some((permission) => currentUser.permissions.includes(permission));
|
|
92
|
+
if (!hasPermission) {
|
|
93
|
+
throw new exceptions_1.AppBadRequestException({
|
|
94
|
+
key: error_key_enum_1.ErrorKeyEnum.PERMISSION,
|
|
95
|
+
message: [`Current user does not have permission to ${dto.actionData.action} vendor`],
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const nextStatus = matchingPermissionConfig.next();
|
|
99
|
+
return nextStatus;
|
|
100
|
+
}
|
|
55
101
|
}
|
|
56
102
|
exports.VendorEntityModel = VendorEntityModel;
|
|
57
103
|
VendorEntityModel.relationConfigs = [];
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { EntityEnum, Nullable } from "../interface/entity.utils.interface";
|
|
2
2
|
import { RelationConfigs } from "../interface/relation-config.interface";
|
|
3
3
|
import { BaseEntityModel } from "./base.entity.model";
|
|
4
|
+
import { IVendorInvoiceUpdateDto } from "../../api";
|
|
4
5
|
import { VendorInvoiceActionStatusEnum } from "../enums/vendor_invoice_action_status_enum";
|
|
5
6
|
import { VendorInvoiceStatusEnum } from "../enums/vendor_invoice_status_enum";
|
|
7
|
+
import { IUserEntity } from "../interface/user.entity.interface";
|
|
6
8
|
import { IVendorInvoiceEntity } from "../interface/vendor_invoice.entity.interface";
|
|
7
9
|
import { OfficeLocationEntityModel } from "./office_location.entity.model";
|
|
8
10
|
import { VendorEntityModel } from "./vendor.entity.model";
|
|
@@ -30,4 +32,5 @@ export declare class VendorInvoiceEntityModel extends BaseEntityModel<EntityEnum
|
|
|
30
32
|
static relationConfigs: RelationConfigs<[EntityEnum.VENDOR, EntityEnum.OFFICE_LOCATION, EntityEnum.VENDOR_INVOICE_ITEM], EntityEnum.VENDOR_INVOICE>;
|
|
31
33
|
static fromEntity(entity: IVendorInvoiceEntity): VendorInvoiceEntityModel;
|
|
32
34
|
getRelationConfigs(): any[];
|
|
35
|
+
getNextStatusForParent(currentUser: IUserEntity, dto: IVendorInvoiceUpdateDto): VendorInvoiceActionStatusEnum;
|
|
33
36
|
}
|
|
@@ -3,9 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VendorInvoiceEntityModel = void 0;
|
|
4
4
|
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
5
5
|
const base_entity_model_1 = require("./base.entity.model");
|
|
6
|
+
const error_key_enum_1 = require("../../enums/error.key.enum");
|
|
7
|
+
const exceptions_1 = require("../../exceptions");
|
|
6
8
|
const relation_type_enum_1 = require("../enums/relation-type.enum");
|
|
9
|
+
const vendor_invoice_action_enum_1 = require("../enums/vendor_invoice_action.enum");
|
|
7
10
|
const vendor_invoice_action_status_enum_1 = require("../enums/vendor_invoice_action_status_enum");
|
|
8
11
|
const vendor_invoice_status_enum_1 = require("../enums/vendor_invoice_status_enum");
|
|
12
|
+
const vendor_invoice_flow_config_1 = require("../flow-configs/vendor-invoice-flow.config");
|
|
9
13
|
class VendorInvoiceEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
10
14
|
constructor() {
|
|
11
15
|
super(...arguments);
|
|
@@ -31,6 +35,53 @@ class VendorInvoiceEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
|
31
35
|
getRelationConfigs() {
|
|
32
36
|
return this.constructor.prototype.constructor.relationConfigs || [];
|
|
33
37
|
}
|
|
38
|
+
getNextStatusForParent(currentUser, dto) {
|
|
39
|
+
const flowForStatus = vendor_invoice_flow_config_1.vendorInvoiceConfigFlow.parent[this.actionStatus];
|
|
40
|
+
if (!flowForStatus) {
|
|
41
|
+
throw new exceptions_1.AppBadRequestException({
|
|
42
|
+
key: error_key_enum_1.ErrorKeyEnum.STATUS,
|
|
43
|
+
message: [`Status not found: ${this.status}`],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (!dto.actionData) {
|
|
47
|
+
dto.actionData = { action: vendor_invoice_action_enum_1.VendorInvoiceActionEnum.EDIT };
|
|
48
|
+
}
|
|
49
|
+
const matchingPermissionConfig = flowForStatus.actions[dto.actionData.action];
|
|
50
|
+
if (!matchingPermissionConfig) {
|
|
51
|
+
throw new exceptions_1.AppBadRequestException({
|
|
52
|
+
key: error_key_enum_1.ErrorKeyEnum.ACTION,
|
|
53
|
+
message: [`Action '${dto.actionData.action}' is not valid for the current status.`],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (!currentUser.permissions || currentUser.permissions.length === 0) {
|
|
57
|
+
throw new exceptions_1.AppBadRequestException({
|
|
58
|
+
key: error_key_enum_1.ErrorKeyEnum.PERMISSIONS,
|
|
59
|
+
message: ["Permission not available for currentUser"],
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const hasPermission = matchingPermissionConfig.permissions.some((permission) => { var _a; return (_a = currentUser.permissions) === null || _a === void 0 ? void 0 : _a.includes(permission); });
|
|
63
|
+
if (!hasPermission) {
|
|
64
|
+
throw new exceptions_1.AppBadRequestException({
|
|
65
|
+
key: error_key_enum_1.ErrorKeyEnum.PERMISSION,
|
|
66
|
+
message: [`Current user does not have permission to ${dto.actionData.action} vendor`],
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (!this.vendorInvoiceItems) {
|
|
70
|
+
throw new exceptions_1.AppBadRequestException({
|
|
71
|
+
key: error_key_enum_1.ErrorKeyEnum.VENDOR_INVOICE_ITEMS,
|
|
72
|
+
message: [`Vendor invoice items are required for getting next status of Vendor Invoice.`],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const contextFlowData = {
|
|
76
|
+
invoice: this,
|
|
77
|
+
items: this.vendorInvoiceItems,
|
|
78
|
+
};
|
|
79
|
+
let nextStatus = vendor_invoice_action_status_enum_1.VendorInvoiceActionStatusEnum.PENDING_APPROVAL;
|
|
80
|
+
if (matchingPermissionConfig.next) {
|
|
81
|
+
nextStatus = matchingPermissionConfig.next(contextFlowData);
|
|
82
|
+
}
|
|
83
|
+
return nextStatus;
|
|
84
|
+
}
|
|
34
85
|
}
|
|
35
86
|
exports.VendorInvoiceEntityModel = VendorInvoiceEntityModel;
|
|
36
87
|
VendorInvoiceEntityModel.relationConfigs = [
|
|
@@ -2,7 +2,9 @@ import { EntityEnum, Nullable } from "../interface/entity.utils.interface";
|
|
|
2
2
|
import { RelationConfigs } from "../interface/relation-config.interface";
|
|
3
3
|
import { BaseEntityModel } from "./base.entity.model";
|
|
4
4
|
import { IVendorInvoiceItemEntity } from "../interface/vendor_invoice_item.entity.interface";
|
|
5
|
+
import { IVendorInvoiceItemUpdateDto } from "../../api";
|
|
5
6
|
import { VendorInvoiceItemStatus } from "../enums/vendor_invoice_item_status.enum";
|
|
7
|
+
import { IUserEntity } from "../interface/user.entity.interface";
|
|
6
8
|
import { ExpenseHeadEntityModel } from "./expense_head.entity.model";
|
|
7
9
|
import { GstRateEntityModel } from "./gst_rate.entity.model";
|
|
8
10
|
import { TdsRateEntityModel } from "./tds_rate.entity.model";
|
|
@@ -41,4 +43,5 @@ export declare class VendorInvoiceItemEntityModel extends BaseEntityModel<Entity
|
|
|
41
43
|
], EntityEnum.VENDOR_INVOICE_ITEM>;
|
|
42
44
|
static fromEntity(entity: IVendorInvoiceItemEntity): VendorInvoiceItemEntityModel;
|
|
43
45
|
getRelationConfigs(): any[];
|
|
46
|
+
getNextStatus(dto: IVendorInvoiceItemUpdateDto, currentUser: IUserEntity): VendorInvoiceItemStatus;
|
|
44
47
|
}
|
|
@@ -4,7 +4,10 @@ exports.VendorInvoiceItemEntityModel = void 0;
|
|
|
4
4
|
const relation_type_enum_1 = require("../enums/relation-type.enum");
|
|
5
5
|
const entity_utils_interface_1 = require("../interface/entity.utils.interface");
|
|
6
6
|
const base_entity_model_1 = require("./base.entity.model");
|
|
7
|
+
const error_key_enum_1 = require("../../enums/error.key.enum");
|
|
8
|
+
const exceptions_1 = require("../../exceptions");
|
|
7
9
|
const vendor_invoice_item_status_enum_1 = require("../enums/vendor_invoice_item_status.enum");
|
|
10
|
+
const vendor_invoice_flow_config_1 = require("../flow-configs/vendor-invoice-flow.config");
|
|
8
11
|
class VendorInvoiceItemEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
9
12
|
constructor() {
|
|
10
13
|
super(...arguments);
|
|
@@ -35,6 +38,46 @@ class VendorInvoiceItemEntityModel extends base_entity_model_1.BaseEntityModel {
|
|
|
35
38
|
getRelationConfigs() {
|
|
36
39
|
return this.constructor.prototype.constructor.relationConfigs || [];
|
|
37
40
|
}
|
|
41
|
+
getNextStatus(dto, currentUser) {
|
|
42
|
+
const flowForStatus = vendor_invoice_flow_config_1.vendorInvoiceConfigFlow.child[this.status];
|
|
43
|
+
if (!flowForStatus) {
|
|
44
|
+
throw new exceptions_1.AppBadRequestException({
|
|
45
|
+
key: error_key_enum_1.ErrorKeyEnum.STATUS,
|
|
46
|
+
message: [`Status not found: ${this.status}`],
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (!(dto === null || dto === void 0 ? void 0 : dto.action)) {
|
|
50
|
+
throw new exceptions_1.AppBadRequestException({
|
|
51
|
+
key: error_key_enum_1.ErrorKeyEnum.ACTION_DATA,
|
|
52
|
+
message: ["dto.actionData is required"],
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const matchingPermissionConfig = flowForStatus.actions[dto.action];
|
|
56
|
+
if (!matchingPermissionConfig) {
|
|
57
|
+
throw new exceptions_1.AppBadRequestException({
|
|
58
|
+
key: error_key_enum_1.ErrorKeyEnum.ACTION,
|
|
59
|
+
message: [`Action '${dto.action}' is not valid for the current status.`],
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (!currentUser.permissions || currentUser.permissions.length === 0) {
|
|
63
|
+
throw new exceptions_1.AppBadRequestException({
|
|
64
|
+
key: error_key_enum_1.ErrorKeyEnum.PERMISSIONS,
|
|
65
|
+
message: ["Permission not available for currentUser"],
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const hasPermission = matchingPermissionConfig.permissions.some((permission) => { var _a; return (_a = currentUser.permissions) === null || _a === void 0 ? void 0 : _a.includes(permission); });
|
|
69
|
+
if (!hasPermission) {
|
|
70
|
+
throw new exceptions_1.AppBadRequestException({
|
|
71
|
+
key: error_key_enum_1.ErrorKeyEnum.PERMISSION,
|
|
72
|
+
message: [`Current user does not have permission to ${dto.action} vendor`],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
let nextStatus = vendor_invoice_item_status_enum_1.VendorInvoiceItemStatus.PENDING;
|
|
76
|
+
if (matchingPermissionConfig.next) {
|
|
77
|
+
nextStatus = matchingPermissionConfig.next();
|
|
78
|
+
}
|
|
79
|
+
return nextStatus;
|
|
80
|
+
}
|
|
38
81
|
}
|
|
39
82
|
exports.VendorInvoiceItemEntityModel = VendorInvoiceItemEntityModel;
|
|
40
83
|
VendorInvoiceItemEntityModel.relationConfigs = [
|
|
@@ -31,5 +31,6 @@ export declare enum ErrorKeyEnum {
|
|
|
31
31
|
PERMISSION = "PERMISSION",
|
|
32
32
|
BILLING = "BILLING",
|
|
33
33
|
DEFAULT_SIZE = "DEFAULT_SIZE",
|
|
34
|
-
BILLING_EXPORT_TYPE = "BILLING_EXPORT_TYPE"
|
|
34
|
+
BILLING_EXPORT_TYPE = "BILLING_EXPORT_TYPE",
|
|
35
|
+
VENDOR_INVOICE_ITEMS = "VENDOR_INVOICE_ITEMS"
|
|
35
36
|
}
|
|
@@ -36,4 +36,5 @@ var ErrorKeyEnum;
|
|
|
36
36
|
ErrorKeyEnum["BILLING"] = "BILLING";
|
|
37
37
|
ErrorKeyEnum["DEFAULT_SIZE"] = "DEFAULT_SIZE";
|
|
38
38
|
ErrorKeyEnum["BILLING_EXPORT_TYPE"] = "BILLING_EXPORT_TYPE";
|
|
39
|
+
ErrorKeyEnum["VENDOR_INVOICE_ITEMS"] = "VENDOR_INVOICE_ITEMS";
|
|
39
40
|
})(ErrorKeyEnum || (exports.ErrorKeyEnum = ErrorKeyEnum = {}));
|
|
@@ -117,3 +117,47 @@ export declare class EntityActionFlowResolver<E extends EntityEnum, S extends st
|
|
|
117
117
|
customLabels?: Partial<Record<A, string>>;
|
|
118
118
|
}): IRowActions<E>[];
|
|
119
119
|
}
|
|
120
|
+
export declare class EntityActionFlowResolverV2 {
|
|
121
|
+
static getPermittedActions<E extends EntityEnum, S extends string, A extends string>(entityFlowConfig: {
|
|
122
|
+
[key in S]?: {
|
|
123
|
+
actions: {
|
|
124
|
+
[key in A]?: {
|
|
125
|
+
permissions: string[];
|
|
126
|
+
next: () => S;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
}, currentStatus: S | null, userPermissions: string[], data?: (a: E) => {
|
|
131
|
+
[key: string]: () => boolean;
|
|
132
|
+
}): A[];
|
|
133
|
+
static _getPermittedActions<E extends EntityEnum, S extends string, A extends string>(actionConfig: {
|
|
134
|
+
[key in A]?: {
|
|
135
|
+
permissions: string[];
|
|
136
|
+
next: () => S;
|
|
137
|
+
};
|
|
138
|
+
}, userPermissions: string[], data: (a: E) => {
|
|
139
|
+
[key: string]: () => boolean;
|
|
140
|
+
}): (A | string)[];
|
|
141
|
+
static combinePermittedActions<A extends string>(permittedActions: readonly A[], combinedActions?: Record<string, {
|
|
142
|
+
combineActions: readonly A[];
|
|
143
|
+
label: string;
|
|
144
|
+
}>): Map<A | string, string>;
|
|
145
|
+
static applyActionLabels<A extends string>(result: Map<A | string, string>, customLabels?: Partial<Record<A, string>>): Map<A | string, string>;
|
|
146
|
+
static getAvailableActionsLabelValue<A extends string>(availableActionsFromModel: Map<A | string, string>): {
|
|
147
|
+
label: string;
|
|
148
|
+
value: string;
|
|
149
|
+
}[];
|
|
150
|
+
static getAvailableActionsData<E extends EntityEnum, S extends string, A extends string>(params: {
|
|
151
|
+
flowConfig: FlowConfig<S, A>;
|
|
152
|
+
currentStatus: S | null;
|
|
153
|
+
userPermissions: string[];
|
|
154
|
+
visibilityData?: (e: E) => {
|
|
155
|
+
[key: string]: () => boolean;
|
|
156
|
+
};
|
|
157
|
+
combinedActions?: Record<string, {
|
|
158
|
+
combineActions: readonly A[];
|
|
159
|
+
label: string;
|
|
160
|
+
}>;
|
|
161
|
+
customLabels?: Partial<Record<A, string>>;
|
|
162
|
+
}): IRowActions<E>[];
|
|
163
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EntityActionFlowResolver = void 0;
|
|
3
|
+
exports.EntityActionFlowResolverV2 = exports.EntityActionFlowResolver = void 0;
|
|
4
4
|
exports.getPermittedActionsOld = getPermittedActionsOld;
|
|
5
5
|
exports.combinePermittedActions = combinePermittedActions;
|
|
6
6
|
exports.applyActionLabels = applyActionLabels;
|
|
@@ -242,3 +242,71 @@ class EntityActionFlowResolver {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
exports.EntityActionFlowResolver = EntityActionFlowResolver;
|
|
245
|
+
class EntityActionFlowResolverV2 {
|
|
246
|
+
static getPermittedActions(entityFlowConfig, currentStatus, userPermissions, data = (_) => ({})) {
|
|
247
|
+
var _a, _b;
|
|
248
|
+
if (!currentStatus || !entityFlowConfig[currentStatus]) {
|
|
249
|
+
return [];
|
|
250
|
+
}
|
|
251
|
+
const actionConfig = (_b = (_a = entityFlowConfig[currentStatus]) === null || _a === void 0 ? void 0 : _a.actions) !== null && _b !== void 0 ? _b : {};
|
|
252
|
+
return EntityActionFlowResolverV2._getPermittedActions(actionConfig, userPermissions, data);
|
|
253
|
+
}
|
|
254
|
+
static _getPermittedActions(actionConfig, userPermissions, data) {
|
|
255
|
+
return Object.entries(actionConfig)
|
|
256
|
+
.filter(([actionKey, config]) => {
|
|
257
|
+
var _a;
|
|
258
|
+
const actionRequiredPermissions = (_a = config === null || config === void 0 ? void 0 : config.permissions) !== null && _a !== void 0 ? _a : [];
|
|
259
|
+
const matchingPermissions = actionRequiredPermissions.filter((permission) => userPermissions.includes(permission));
|
|
260
|
+
if (matchingPermissions.length > 1) {
|
|
261
|
+
throw new Error(`Multiple permissions found for action ${actionKey}: ${matchingPermissions.join(", ")}`);
|
|
262
|
+
}
|
|
263
|
+
return matchingPermissions.length > 0 && (!data || !data({})[matchingPermissions[0]] || data({})[matchingPermissions[0]]());
|
|
264
|
+
})
|
|
265
|
+
.map(([actionKey, _]) => actionKey);
|
|
266
|
+
}
|
|
267
|
+
static combinePermittedActions(permittedActions, combinedActions) {
|
|
268
|
+
let remainingActions = [...permittedActions];
|
|
269
|
+
const result = new Map();
|
|
270
|
+
if (combinedActions && !(0, helper_fn_util_1.checkEmptyObj)(combinedActions)) {
|
|
271
|
+
for (const [combinedKey, config] of Object.entries(combinedActions)) {
|
|
272
|
+
if (config.combineActions.every((a) => remainingActions.includes(a))) {
|
|
273
|
+
remainingActions = remainingActions.filter((a) => !config.combineActions.includes(a));
|
|
274
|
+
result.set(combinedKey, config.label);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
for (const action of remainingActions) {
|
|
279
|
+
result.set(action, (0, string_util_1.toTitleCase)(action));
|
|
280
|
+
}
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
static applyActionLabels(result, customLabels) {
|
|
284
|
+
if (!customLabels || (0, helper_fn_util_1.checkEmptyObj)(customLabels)) {
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
for (const [key] of result.entries()) {
|
|
288
|
+
if (customLabels[key]) {
|
|
289
|
+
result.set(key, customLabels[key]);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
static getAvailableActionsLabelValue(availableActionsFromModel) {
|
|
295
|
+
const availableActionsForRes = [];
|
|
296
|
+
for (const [value, label] of availableActionsFromModel.entries()) {
|
|
297
|
+
availableActionsForRes.push({ label, value: value.toString() });
|
|
298
|
+
}
|
|
299
|
+
return availableActionsForRes;
|
|
300
|
+
}
|
|
301
|
+
static getAvailableActionsData(params) {
|
|
302
|
+
const { flowConfig, currentStatus, userPermissions, visibilityData = (_) => ({}), combinedActions, customLabels } = params;
|
|
303
|
+
if (!currentStatus || !(userPermissions === null || userPermissions === void 0 ? void 0 : userPermissions.length)) {
|
|
304
|
+
return [];
|
|
305
|
+
}
|
|
306
|
+
const permittedActions = EntityActionFlowResolverV2.getPermittedActions(flowConfig, currentStatus, userPermissions, visibilityData);
|
|
307
|
+
let result = EntityActionFlowResolverV2.combinePermittedActions(permittedActions, combinedActions);
|
|
308
|
+
result = EntityActionFlowResolverV2.applyActionLabels(result, customLabels);
|
|
309
|
+
return EntityActionFlowResolverV2.getAvailableActionsLabelValue(result);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
exports.EntityActionFlowResolverV2 = EntityActionFlowResolverV2;
|