law-common 10.21.1-beta.2 → 10.21.1-beta.4
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/index.d.ts +1 -0
- package/dist/src/api/index.js +1 -0
- package/dist/src/api/interface/address-book.create.dto.interface.d.ts +19 -0
- package/dist/src/api/interface/address-book.create.dto.interface.js +2 -0
- package/dist/src/entities/index.d.ts +2 -0
- package/dist/src/entities/index.js +2 -0
- package/dist/src/entities/interface/address-book.entity.interface.d.ts +10 -0
- package/dist/src/entities/interface/address-book.entity.interface.js +2 -0
- package/dist/src/entities/interface/entity.utils.interface.d.ts +6 -3
- package/dist/src/entities/interface/entity.utils.interface.js +1 -0
- package/dist/src/entities/model/country.entity.model.d.ts +11 -0
- package/dist/src/entities/model/country.entity.model.js +20 -0
- package/dist/src/entities/model/entity.model.interface.js +2 -3
- package/dist/src/utils/entity.flow.util.d.ts +8 -8
- package/dist/src/utils/entity.flow.util.js +64 -32
- package/package.json +1 -1
package/dist/src/api/index.d.ts
CHANGED
|
@@ -83,3 +83,4 @@ export * from "./interface/to-do.entity.api";
|
|
|
83
83
|
export * from "./interface/billing-reimbursement-expense.api";
|
|
84
84
|
export * from "./interface/billing-reimbursement-expense-history.api";
|
|
85
85
|
export * from "./interface/project-user-mapping.entity.api";
|
|
86
|
+
export * from "./interface/address-book.create.dto.interface";
|
package/dist/src/api/index.js
CHANGED
|
@@ -99,3 +99,4 @@ __exportStar(require("./interface/to-do.entity.api"), exports);
|
|
|
99
99
|
__exportStar(require("./interface/billing-reimbursement-expense.api"), exports);
|
|
100
100
|
__exportStar(require("./interface/billing-reimbursement-expense-history.api"), exports);
|
|
101
101
|
__exportStar(require("./interface/project-user-mapping.entity.api"), exports);
|
|
102
|
+
__exportStar(require("./interface/address-book.create.dto.interface"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IAddressBookEntity, IEntityCreateDto } from "../../entities";
|
|
2
|
+
export type IAddressBookCreateExclude = "contactDetails" | "address" | "organizationId";
|
|
3
|
+
export interface IAddressBookContactDetail {
|
|
4
|
+
id?: number;
|
|
5
|
+
name: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
phone?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IAddressBookAddress {
|
|
10
|
+
addressLine1?: string;
|
|
11
|
+
addressLine2?: string;
|
|
12
|
+
city?: string;
|
|
13
|
+
state?: string;
|
|
14
|
+
zipCode?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface IAddressBookCreateDto extends Omit<IEntityCreateDto<IAddressBookEntity>, IAddressBookCreateExclude> {
|
|
17
|
+
contactDetails: IAddressBookContactDetail[];
|
|
18
|
+
address?: IAddressBookAddress;
|
|
19
|
+
}
|
|
@@ -65,6 +65,7 @@ export * from "./interface/billing_timesheet.entity.interface";
|
|
|
65
65
|
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
|
+
export * from "./interface/address-book.entity.interface";
|
|
68
69
|
export * from "./model/leave.entity.model";
|
|
69
70
|
export * from "./model/leave_count.entity.model";
|
|
70
71
|
export * from "./model/holiday.entity.model";
|
|
@@ -98,3 +99,4 @@ export * from "./model/timesheet.entity.model";
|
|
|
98
99
|
export * from "./model/user.entity.model";
|
|
99
100
|
export * from "./model/client-affiliate.entity.model";
|
|
100
101
|
export * from "./model/billing-timesheet.entity.model";
|
|
102
|
+
export * from "./model/country.entity.model";
|
|
@@ -82,6 +82,7 @@ __exportStar(require("./interface/billing_timesheet.entity.interface"), exports)
|
|
|
82
82
|
__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
|
+
__exportStar(require("./interface/address-book.entity.interface"), exports);
|
|
85
86
|
__exportStar(require("./model/leave.entity.model"), exports);
|
|
86
87
|
__exportStar(require("./model/leave_count.entity.model"), exports);
|
|
87
88
|
__exportStar(require("./model/holiday.entity.model"), exports);
|
|
@@ -115,3 +116,4 @@ __exportStar(require("./model/timesheet.entity.model"), exports);
|
|
|
115
116
|
__exportStar(require("./model/user.entity.model"), exports);
|
|
116
117
|
__exportStar(require("./model/client-affiliate.entity.model"), exports);
|
|
117
118
|
__exportStar(require("./model/billing-timesheet.entity.model"), exports);
|
|
119
|
+
__exportStar(require("./model/country.entity.model"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IAuditColumnEntity } from "./audit-column.entity.interface";
|
|
2
|
+
export interface IAddressBookEntity extends IAuditColumnEntity {
|
|
3
|
+
id: number;
|
|
4
|
+
contactDetails: string;
|
|
5
|
+
address?: string;
|
|
6
|
+
country: string;
|
|
7
|
+
notes?: string;
|
|
8
|
+
organizationId: number;
|
|
9
|
+
introducedBy?: number;
|
|
10
|
+
}
|
|
@@ -10,6 +10,7 @@ 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 { CountryEntityModel } from "../model/country.entity.model";
|
|
13
14
|
import { HolidayEntityModel } from "../model/holiday.entity.model";
|
|
14
15
|
import { LeaveEntityModel } from "../model/leave.entity.model";
|
|
15
16
|
import { LeaveCountVirtualEntityModel } from "../model/leave_count.entity.model";
|
|
@@ -20,6 +21,7 @@ import { ReimbursementEntityModel } from "../model/reimbursement.entity.model";
|
|
|
20
21
|
import { TaskEntityModel } from "../model/task.entity.model";
|
|
21
22
|
import { TimesheetEntityModel } from "../model/timesheet.entity.model";
|
|
22
23
|
import { UserEntityModel } from "../model/user.entity.model";
|
|
24
|
+
import { IAddressBookEntity } from "./address-book.entity.interface";
|
|
23
25
|
import { IAuditColumnEntity } from "./audit-column.entity.interface";
|
|
24
26
|
import { IBankEntity } from "./bank.entity.interface";
|
|
25
27
|
import { IBankHistoryEntity } from "./bank_history.entity.interface";
|
|
@@ -139,7 +141,8 @@ export declare enum EntityEnum {
|
|
|
139
141
|
HOLIDAY = "holiday",
|
|
140
142
|
HOLIDAY_LIST = "holiday_list",
|
|
141
143
|
CRON_JOBS = "cron_jobs",
|
|
142
|
-
TO_DO_LIST = "to_do_list"
|
|
144
|
+
TO_DO_LIST = "to_do_list",
|
|
145
|
+
ADDRESS_BOOK = "address_book"
|
|
143
146
|
}
|
|
144
147
|
export type EntityRelations = {
|
|
145
148
|
[K in EntityEnum | VirtualEntityEnum]: K;
|
|
@@ -161,7 +164,7 @@ export type IBaseEntityApiResponse<T extends {
|
|
|
161
164
|
[K in EntityEnum | VirtualEntityEnum]?: IBaseEntityApiResponse<EnumEntityType<K>>;
|
|
162
165
|
};
|
|
163
166
|
};
|
|
164
|
-
export type EnumEntityType<T extends EntityEnum | VirtualEntityEnum> = (T extends EntityEnum.BILLING ? IBillingEntity : T extends EntityEnum.BILLING_TIMESHEET ? IBillingTimesheetEntity : T extends EntityEnum.BILLING_REIMBURSEMENT_EXPENSE ? IBillingReimbursementExpenseEntity : T extends EntityEnum.TIMESHEET ? ITimesheetEntity : T extends EntityEnum.USER ? IUserEntity : T extends EntityEnum.PROJECT ? IProjectEntity : T extends EntityEnum.CLIENT ? IClientEntity : T extends EntityEnum.LEAVE ? ILeaveEntity : T extends EntityEnum.BANK ? IBankEntity : T extends EntityEnum.BILLING_PAYMENT ? IBillingPaymentEntity : T extends EntityEnum.BILLING_TRANSACTION ? IBillingTransactionEntity : T extends EntityEnum.CLIENT_AFFILIATE ? IClientAffiliateEntity : T extends EntityEnum.CONFIGURATION ? IConfigurationEntity : T extends EntityEnum.HOLIDAY ? IHolidayEntity : T extends EntityEnum.HOLIDAY_LIST ? IHolidayListEntity : T extends EntityEnum.COUNTRY ? ICountryEntity : T extends EntityEnum.EXPENSE_TYPE ? IExpenseTypeEntity : T extends EntityEnum.INDUSTRY ? IIndustryEntity : T extends EntityEnum.INTERMEDIARY_BANK ? IIntermediaryBankEntity : T extends EntityEnum.OFFICE_LOCATION ? IOfficeLocationEntity : T extends EntityEnum.PERMISSION ? IPermissionEntity : T extends EntityEnum.ROLE ? IRoleEntity : T extends EntityEnum.TASK ? ITaskEntity : T extends EntityEnum.DESIGNATION ? IDesignationEntity : T extends EntityEnum.RATE ? IRateEntity : T extends EntityEnum.REIMBURSEMENT ? IReimbursementEntity : T extends EntityEnum.REIMBURSEMENT_EXPENSE ? IReimbursementExpenseEntity : T extends EntityEnum.WORK_FROM_HOME ? IWorkFromHomeEntity : T extends EntityEnum.ORGANIZATION ? IOrganizationEntity : T extends EntityEnum.PROJECT_USER_MAPPING ? IProjectUserMappingEntity : T extends EntityEnum.CLIENT_USER_MAPPING ? IClientUserMappingEntity : T extends EntityEnum.TO_DO_LIST ? IToDoListEntity : T extends EntityEnum.CRON_JOBS ? ICronJobsEntity : T extends EntityEnum.ROLE_PERMISSION_MAPPING ? IRolePermissionMappingEntity : T extends VirtualEntityEnum.USER_LEAVE ? IUserLeaveVirtualEntity : T extends VirtualEntityEnum.LEAVE_COUNT ? ILeaveCountVirtualEntity : T extends EntityEnum.BANK_HISTORY ? IBankHistoryEntity : T extends EntityEnum.LEAVE_HISTORY ? ILeaveHistoryEntity : T extends EntityEnum.WORK_FROM_HOME_HISTORY ? IWorkFromHomeHistoryEntity : T extends EntityEnum.TIMESHEET_HISTORY ? ITimesheetHistoryEntity : never) & {
|
|
167
|
+
export type EnumEntityType<T extends EntityEnum | VirtualEntityEnum> = (T extends EntityEnum.BILLING ? IBillingEntity : T extends EntityEnum.BILLING_TIMESHEET ? IBillingTimesheetEntity : T extends EntityEnum.BILLING_REIMBURSEMENT_EXPENSE ? IBillingReimbursementExpenseEntity : T extends EntityEnum.TIMESHEET ? ITimesheetEntity : T extends EntityEnum.USER ? IUserEntity : T extends EntityEnum.PROJECT ? IProjectEntity : T extends EntityEnum.CLIENT ? IClientEntity : T extends EntityEnum.LEAVE ? ILeaveEntity : T extends EntityEnum.BANK ? IBankEntity : T extends EntityEnum.BILLING_PAYMENT ? IBillingPaymentEntity : T extends EntityEnum.BILLING_TRANSACTION ? IBillingTransactionEntity : T extends EntityEnum.CLIENT_AFFILIATE ? IClientAffiliateEntity : T extends EntityEnum.CONFIGURATION ? IConfigurationEntity : T extends EntityEnum.HOLIDAY ? IHolidayEntity : T extends EntityEnum.HOLIDAY_LIST ? IHolidayListEntity : T extends EntityEnum.COUNTRY ? ICountryEntity : T extends EntityEnum.EXPENSE_TYPE ? IExpenseTypeEntity : T extends EntityEnum.INDUSTRY ? IIndustryEntity : T extends EntityEnum.INTERMEDIARY_BANK ? IIntermediaryBankEntity : T extends EntityEnum.OFFICE_LOCATION ? IOfficeLocationEntity : T extends EntityEnum.PERMISSION ? IPermissionEntity : T extends EntityEnum.ROLE ? IRoleEntity : T extends EntityEnum.TASK ? ITaskEntity : T extends EntityEnum.DESIGNATION ? IDesignationEntity : T extends EntityEnum.RATE ? IRateEntity : T extends EntityEnum.REIMBURSEMENT ? IReimbursementEntity : T extends EntityEnum.REIMBURSEMENT_EXPENSE ? IReimbursementExpenseEntity : T extends EntityEnum.WORK_FROM_HOME ? IWorkFromHomeEntity : T extends EntityEnum.ORGANIZATION ? IOrganizationEntity : T extends EntityEnum.PROJECT_USER_MAPPING ? IProjectUserMappingEntity : T extends EntityEnum.CLIENT_USER_MAPPING ? IClientUserMappingEntity : T extends EntityEnum.TO_DO_LIST ? IToDoListEntity : T extends EntityEnum.CRON_JOBS ? ICronJobsEntity : T extends EntityEnum.ROLE_PERMISSION_MAPPING ? IRolePermissionMappingEntity : T extends VirtualEntityEnum.USER_LEAVE ? IUserLeaveVirtualEntity : T extends VirtualEntityEnum.LEAVE_COUNT ? ILeaveCountVirtualEntity : T extends EntityEnum.BANK_HISTORY ? IBankHistoryEntity : T extends EntityEnum.LEAVE_HISTORY ? ILeaveHistoryEntity : T extends EntityEnum.WORK_FROM_HOME_HISTORY ? IWorkFromHomeHistoryEntity : T extends EntityEnum.TIMESHEET_HISTORY ? ITimesheetHistoryEntity : T extends EntityEnum.ADDRESS_BOOK ? IAddressBookEntity : never) & {
|
|
165
168
|
id: number;
|
|
166
169
|
};
|
|
167
170
|
export type EntityRelationConfig<T extends EntityEnum | VirtualEntityEnum> = {
|
|
@@ -284,7 +287,7 @@ export declare enum VirtualEntityEnum {
|
|
|
284
287
|
}
|
|
285
288
|
export type IHistoryConstraintSearchResponse<T> = IBaseResponse<IHistoryEntitySearchByConstraintResponse<T>[]>;
|
|
286
289
|
export type IHistoryConstraintSearchServiceResponse<T> = IHistoryEntitySearchByConstraintResponse<T>[];
|
|
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;
|
|
290
|
+
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 : T extends EntityEnum.COUNTRY ? CountryEntityModel : UserEntityModel;
|
|
288
291
|
export type EntityMap = {
|
|
289
292
|
[key in EntityEnum | VirtualEntityEnum]: EnumToModel<key>[];
|
|
290
293
|
};
|
|
@@ -76,6 +76,7 @@ var EntityEnum;
|
|
|
76
76
|
EntityEnum["HOLIDAY_LIST"] = "holiday_list";
|
|
77
77
|
EntityEnum["CRON_JOBS"] = "cron_jobs";
|
|
78
78
|
EntityEnum["TO_DO_LIST"] = "to_do_list";
|
|
79
|
+
EntityEnum["ADDRESS_BOOK"] = "address_book";
|
|
79
80
|
})(EntityEnum || (exports.EntityEnum = EntityEnum = {}));
|
|
80
81
|
var VirtualEntityEnum;
|
|
81
82
|
(function (VirtualEntityEnum) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ICountryApiEntity } from "../../api";
|
|
2
|
+
export declare class CountryEntityModel implements ICountryApiEntity {
|
|
3
|
+
id: number;
|
|
4
|
+
name: string;
|
|
5
|
+
createdBy: number;
|
|
6
|
+
updatedBy: number;
|
|
7
|
+
createdOn: string;
|
|
8
|
+
updatedOn: string;
|
|
9
|
+
constructor(data?: ICountryApiEntity);
|
|
10
|
+
static fromApiEntity(apiEntity: ICountryApiEntity): CountryEntityModel;
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CountryEntityModel = void 0;
|
|
4
|
+
class CountryEntityModel {
|
|
5
|
+
constructor(data) {
|
|
6
|
+
this.id = 0;
|
|
7
|
+
this.name = "";
|
|
8
|
+
this.createdBy = 0;
|
|
9
|
+
this.updatedBy = 0;
|
|
10
|
+
this.createdOn = "";
|
|
11
|
+
this.updatedOn = "";
|
|
12
|
+
Object.assign(this, data);
|
|
13
|
+
}
|
|
14
|
+
static fromApiEntity(apiEntity) {
|
|
15
|
+
const entity = new CountryEntityModel(apiEntity);
|
|
16
|
+
Object.assign(entity, apiEntity);
|
|
17
|
+
return entity;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.CountryEntityModel = CountryEntityModel;
|
|
@@ -27,6 +27,7 @@ const reimbursement_entity_model_1 = require("./reimbursement.entity.model");
|
|
|
27
27
|
const task_entity_model_1 = require("./task.entity.model");
|
|
28
28
|
const timesheet_entity_model_1 = require("./timesheet.entity.model");
|
|
29
29
|
const user_entity_model_1 = require("./user.entity.model");
|
|
30
|
+
const country_entity_model_1 = require("./country.entity.model");
|
|
30
31
|
function mapToIndex(entityMap) {
|
|
31
32
|
return Object.keys(entityMap).reduce((acc, key) => {
|
|
32
33
|
// @ts-ignore
|
|
@@ -73,6 +74,7 @@ exports.entityEnumToEntityModel = {
|
|
|
73
74
|
[entity_utils_interface_1.EntityEnum.TASK]: task_entity_model_1.TaskEntityModel.fromApiEntity,
|
|
74
75
|
[entity_utils_interface_1.EntityEnum.BILLING_TIMESHEET]: billing_timesheet_entity_model_1.BillingTimesheetEntityModel.fromApiEntity,
|
|
75
76
|
[entity_utils_interface_1.EntityEnum.TIMESHEET]: timesheet_entity_model_1.TimesheetEntityModel.fromApiEntity,
|
|
77
|
+
[entity_utils_interface_1.EntityEnum.COUNTRY]: country_entity_model_1.CountryEntityModel.fromApiEntity,
|
|
76
78
|
};
|
|
77
79
|
function entityMapToModels(entityMap) {
|
|
78
80
|
for (const entityName in entityMap) {
|
|
@@ -106,9 +108,6 @@ function entityMapToEntityIndexMap(entityMap, entityRelationsFor) {
|
|
|
106
108
|
}
|
|
107
109
|
function parseEntitiesWithoutModels(json, baseEntity, entityMap = {}) {
|
|
108
110
|
var _a;
|
|
109
|
-
if (!(baseEntity in exports.entityEnumToEntityModel)) {
|
|
110
|
-
throw new Error(`Unknown entity: ${baseEntity}`);
|
|
111
|
-
}
|
|
112
111
|
entityMap[baseEntity] = ((_a = json["baseEntities"]) !== null && _a !== void 0 ? _a : []);
|
|
113
112
|
if (json["relatedEntities"]) {
|
|
114
113
|
const relatedEntities = json["relatedEntities"];
|
|
@@ -9,24 +9,24 @@ export type LeaveStatusActionPair = {
|
|
|
9
9
|
* @param currentStatus - The current status of the leave
|
|
10
10
|
* @param userPermissions - Array of permissions the user has
|
|
11
11
|
* @param combineActions - Array of action values to combine into a single action
|
|
12
|
-
* @param
|
|
12
|
+
* @param actionLabels - Object mapping actions to custom labels
|
|
13
|
+
* @param data - Optional function to provide additional visibility conditions
|
|
13
14
|
* @returns Array of available actions with labels and values
|
|
14
|
-
* @throws Error if user has multiple permissions for a single action
|
|
15
15
|
*/
|
|
16
16
|
export declare function getPermittedActions<T extends LeaveStatusActionPair, E>(entityFlowConfig: {
|
|
17
|
-
[key in T[
|
|
17
|
+
[key in T["status"]]?: {
|
|
18
18
|
actions: {
|
|
19
|
-
[key in T[
|
|
19
|
+
[key in T["action"]]?: {
|
|
20
20
|
permissions: string[];
|
|
21
|
-
next: () => T[
|
|
21
|
+
next: () => T["status"];
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
-
}, currentStatus: T[
|
|
26
|
-
[key in T[
|
|
25
|
+
}, currentStatus: T["status"] | null, userPermissions: string[], combineActions?: T["action"][], actionLabels?: {
|
|
26
|
+
[key in T["action"]]?: string;
|
|
27
27
|
}, data?: (a: E) => {
|
|
28
28
|
[key: string]: () => boolean;
|
|
29
29
|
}): {
|
|
30
30
|
label: string;
|
|
31
|
-
value: T[
|
|
31
|
+
value: T["action"] | string;
|
|
32
32
|
}[];
|
|
@@ -1,15 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPermittedActions = getPermittedActions;
|
|
4
|
+
/**
|
|
5
|
+
* Converts an action or combined action to a value-label pair
|
|
6
|
+
* @param action - The action or combined action key
|
|
7
|
+
* @param actionLabels - Object mapping actions to custom labels
|
|
8
|
+
* @returns Object with label and value
|
|
9
|
+
*/
|
|
10
|
+
function convertToValueLabel(action, actionLabels) {
|
|
11
|
+
return {
|
|
12
|
+
label: actionLabels[action] || action,
|
|
13
|
+
value: action,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Filters actions based on user permissions and visibility conditions
|
|
18
|
+
* @param actionConfig - The actions configuration for the current status
|
|
19
|
+
* @param userPermissions - Array of permissions the user has
|
|
20
|
+
* @param data - Optional function to provide additional visibility conditions
|
|
21
|
+
* @returns Array of permitted action keys
|
|
22
|
+
* @throws Error if multiple permissions are found for a single action
|
|
23
|
+
*/
|
|
24
|
+
function _getPermittedActions(actionConfig, userPermissions, data) {
|
|
25
|
+
return Object.entries(actionConfig)
|
|
26
|
+
.filter(([actionKey, config]) => {
|
|
27
|
+
var _a;
|
|
28
|
+
const actionRequiredPermissions = (_a = config === null || config === void 0 ? void 0 : config.permissions) !== null && _a !== void 0 ? _a : [];
|
|
29
|
+
const matchingPermissions = actionRequiredPermissions.filter((permission) => userPermissions.includes(permission));
|
|
30
|
+
if (matchingPermissions.length > 1) {
|
|
31
|
+
throw new Error(`Multiple permissions found for action ${actionKey}: ${matchingPermissions.join(", ")}`);
|
|
32
|
+
}
|
|
33
|
+
return (matchingPermissions.length > 0 &&
|
|
34
|
+
(!data ||
|
|
35
|
+
!data({})[matchingPermissions[0]] ||
|
|
36
|
+
data({})[matchingPermissions[0]]()));
|
|
37
|
+
})
|
|
38
|
+
.map(([actionKey, _]) => actionKey);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Combines specified actions into a single action if all are present
|
|
42
|
+
* @param permittedActions - Array of permitted action keys
|
|
43
|
+
* @param combineActions - Array of actions to combine
|
|
44
|
+
* @returns Array of action keys, with combined action if applicable
|
|
45
|
+
*/
|
|
46
|
+
function combinePermittedActions(permittedActions, combineActions) {
|
|
47
|
+
if (combineActions.length === 0) {
|
|
48
|
+
return permittedActions;
|
|
49
|
+
}
|
|
50
|
+
const isCombinedActionPresent = combineActions.every((action) => permittedActions.includes(action));
|
|
51
|
+
if (isCombinedActionPresent) {
|
|
52
|
+
const combinedValue = combineActions.join("_");
|
|
53
|
+
return [
|
|
54
|
+
...permittedActions.filter((action) => !combineActions.includes(action)),
|
|
55
|
+
combinedValue,
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
return permittedActions;
|
|
59
|
+
}
|
|
4
60
|
/**
|
|
5
61
|
* Gets available actions for a leave based on current status and user permissions
|
|
6
62
|
* @param entityFlowConfig - The flow configuration for the entity
|
|
7
63
|
* @param currentStatus - The current status of the leave
|
|
8
64
|
* @param userPermissions - Array of permissions the user has
|
|
9
65
|
* @param combineActions - Array of action values to combine into a single action
|
|
10
|
-
* @param
|
|
66
|
+
* @param actionLabels - Object mapping actions to custom labels
|
|
67
|
+
* @param data - Optional function to provide additional visibility conditions
|
|
11
68
|
* @returns Array of available actions with labels and values
|
|
12
|
-
* @throws Error if user has multiple permissions for a single action
|
|
13
69
|
*/
|
|
14
70
|
function getPermittedActions(entityFlowConfig, currentStatus, userPermissions, combineActions = [], actionLabels = {}, data = (_) => ({})) {
|
|
15
71
|
var _a;
|
|
@@ -18,34 +74,10 @@ function getPermittedActions(entityFlowConfig, currentStatus, userPermissions, c
|
|
|
18
74
|
return [];
|
|
19
75
|
}
|
|
20
76
|
const actionConfig = ((_a = entityFlowConfig[currentStatus]) === null || _a === void 0 ? void 0 : _a.actions) || {};
|
|
21
|
-
//
|
|
22
|
-
const permittedActions =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// Check for multiple permissions
|
|
28
|
-
if (matchingPermissions.length > 1) {
|
|
29
|
-
throw new Error(`Multiple permissions found for action ${actionKey}: ${matchingPermissions.join(', ')}`);
|
|
30
|
-
}
|
|
31
|
-
return matchingPermissions.length > 0 && (!data || !data({})[matchingPermissions[0]] || data({})[matchingPermissions[0]]());
|
|
32
|
-
})
|
|
33
|
-
.map(([actionKey, _]) => ({
|
|
34
|
-
label: actionLabels[actionKey] || actionKey,
|
|
35
|
-
value: actionKey,
|
|
36
|
-
}));
|
|
37
|
-
// // Combine specified actions if all are present and combineActions is not empty
|
|
38
|
-
if (combineActions.length > 0) {
|
|
39
|
-
const isCombinedActionPresent = combineActions.every((action) => permittedActions.some((a) => a.value === action));
|
|
40
|
-
if (isCombinedActionPresent) {
|
|
41
|
-
return [
|
|
42
|
-
...permittedActions.filter((action) => !combineActions.includes(action.value)),
|
|
43
|
-
{
|
|
44
|
-
label: actionLabels[combineActions.join('_')] || combineActions.join('_'),
|
|
45
|
-
value: combineActions.join('_'),
|
|
46
|
-
},
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return permittedActions;
|
|
77
|
+
// Get permitted actions
|
|
78
|
+
const permittedActions = _getPermittedActions(actionConfig, userPermissions, data);
|
|
79
|
+
// Combine actions if specified
|
|
80
|
+
const finalActions = combinePermittedActions(permittedActions, combineActions);
|
|
81
|
+
// Convert to value-label pairs
|
|
82
|
+
return finalActions.map((action) => convertToValueLabel(action, actionLabels));
|
|
51
83
|
}
|