storemw-core-client 1.0.1
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/.env +1 -0
- package/.vscode/launch.json +24 -0
- package/dist/config/config.d.ts +6 -0
- package/dist/config/config.js +13 -0
- package/dist/config/env.d.ts +7 -0
- package/dist/config/env.js +16 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -0
- package/dist/lib/ApiService.d.ts +41 -0
- package/dist/lib/ApiService.js +143 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.js +9 -0
- package/dist/lib/queryParams.d.ts +43 -0
- package/dist/lib/queryParams.js +99 -0
- package/dist/services/account/AccountService.d.ts +52 -0
- package/dist/services/account/AccountService.js +119 -0
- package/dist/services/auth/AuthService.d.ts +44 -0
- package/dist/services/auth/AuthService.js +76 -0
- package/dist/services/branch/BranchService.d.ts +124 -0
- package/dist/services/branch/BranchService.js +162 -0
- package/dist/services/business/BusinessService.d.ts +91 -0
- package/dist/services/business/BusinessService.js +153 -0
- package/dist/services/document/DocumentService.d.ts +578 -0
- package/dist/services/document/DocumentService.js +615 -0
- package/dist/services/index.d.ts +36 -0
- package/dist/services/index.js +97 -0
- package/dist/services/injection_field/InjectionFieldService.d.ts +113 -0
- package/dist/services/injection_field/InjectionFieldService.js +220 -0
- package/dist/services/inventory/InventoryService.d.ts +27 -0
- package/dist/services/inventory/InventoryService.js +231 -0
- package/dist/services/item/ItemService.d.ts +227 -0
- package/dist/services/item/ItemService.js +411 -0
- package/dist/services/location/LocationService.d.ts +154 -0
- package/dist/services/location/LocationService.js +256 -0
- package/dist/services/logistic/LogisticService.d.ts +104 -0
- package/dist/services/logistic/LogisticService.js +150 -0
- package/dist/services/permission/PermissionService.d.ts +296 -0
- package/dist/services/permission/PermissionService.js +576 -0
- package/dist/services/permission/config/custom/adminPermission.d.ts +4 -0
- package/dist/services/permission/config/custom/adminPermission.js +18 -0
- package/dist/services/permission/config/custom/config.d.ts +40 -0
- package/dist/services/permission/config/custom/config.js +23 -0
- package/dist/services/permission/config/default/adminPermission.d.ts +2 -0
- package/dist/services/permission/config/default/adminPermission.js +129 -0
- package/dist/services/permission/config/default/agentPermission.d.ts +2 -0
- package/dist/services/permission/config/default/agentPermission.js +43 -0
- package/dist/services/permission/config/default/customerPermission.d.ts +2 -0
- package/dist/services/permission/config/default/customerPermission.js +10 -0
- package/dist/services/permission/config/default/driverPermission.d.ts +2 -0
- package/dist/services/permission/config/default/driverPermission.js +4 -0
- package/dist/services/permission/config/default/workerPermission.d.ts +2 -0
- package/dist/services/permission/config/default/workerPermission.js +25 -0
- package/dist/services/rate/RateService.d.ts +201 -0
- package/dist/services/rate/RateService.js +303 -0
- package/dist/services/region/RegionService.d.ts +111 -0
- package/dist/services/region/RegionService.js +193 -0
- package/dist/services/repository/RepositoryService.d.ts +153 -0
- package/dist/services/repository/RepositoryService.js +243 -0
- package/dist/services/transaction/TransactionService.d.ts +153 -0
- package/dist/services/transaction/TransactionService.js +173 -0
- package/dist/services/user/BranchUserService.d.ts +129 -0
- package/dist/services/user/BranchUserService.js +193 -0
- package/dist/services/user/UserRoleService.d.ts +105 -0
- package/dist/services/user/UserRoleService.js +193 -0
- package/dist/services/user/UserService.d.ts +269 -0
- package/dist/services/user/UserService.js +477 -0
- package/dist/services/wallet/WalletService.d.ts +104 -0
- package/dist/services/wallet/WalletService.js +163 -0
- package/dist/utils/dateUtils.d.ts +6 -0
- package/dist/utils/dateUtils.js +28 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +13 -0
- package/package.json +27 -0
- package/src/config/config.ts +15 -0
- package/src/config/env.ts +18 -0
- package/src/config/index.ts +2 -0
- package/src/index.ts +41 -0
- package/src/lib/ApiService.ts +170 -0
- package/src/lib/index.ts +5 -0
- package/src/lib/queryParams.ts +162 -0
- package/src/services/account/AccountService.ts +232 -0
- package/src/services/auth/AuthService.ts +125 -0
- package/src/services/branch/BranchService.ts +330 -0
- package/src/services/business/BusinessService.ts +277 -0
- package/src/services/document/DocumentService.ts +1471 -0
- package/src/services/index.ts +73 -0
- package/src/services/injection_field/InjectionFieldService.ts +483 -0
- package/src/services/inventory/InventoryService.ts +314 -0
- package/src/services/item/ItemService.ts +707 -0
- package/src/services/location/LocationService.ts +505 -0
- package/src/services/logistic/LogisticService.ts +285 -0
- package/src/services/permission/PermissionService.ts +1069 -0
- package/src/services/permission/config/custom/adminPermission.ts +19 -0
- package/src/services/permission/config/custom/config.ts +39 -0
- package/src/services/permission/config/default/adminPermission.ts +129 -0
- package/src/services/permission/config/default/agentPermission.ts +42 -0
- package/src/services/permission/config/default/customerPermission.ts +9 -0
- package/src/services/permission/config/default/driverPermission.ts +4 -0
- package/src/services/permission/config/default/workerPermission.ts +25 -0
- package/src/services/rate/RateService.ts +570 -0
- package/src/services/region/RegionService.ts +353 -0
- package/src/services/repository/RepositoryService.ts +437 -0
- package/src/services/transaction/TransactionService.ts +404 -0
- package/src/services/user/BranchUserService.ts +381 -0
- package/src/services/user/UserRoleService.ts +342 -0
- package/src/services/user/UserService.ts +807 -0
- package/src/services/wallet/WalletService.ts +300 -0
- package/src/utils/dateUtils.ts +26 -0
- package/src/utils/index.ts +2 -0
- package/tsconfig.json +119 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionService = exports.transactionTargetTypes = exports.transactionActionTypes = exports.transactionTypes = void 0;
|
|
4
|
+
const lib_1 = require("@/lib");
|
|
5
|
+
const lib_2 = require("@/lib");
|
|
6
|
+
exports.transactionTypes = {
|
|
7
|
+
request: "request",
|
|
8
|
+
wallet: "wallet"
|
|
9
|
+
};
|
|
10
|
+
exports.transactionActionTypes = {
|
|
11
|
+
requestTransfer: "wallet_transfer",
|
|
12
|
+
requestTopup: "wallet_topup",
|
|
13
|
+
requestWithdraw: "wallet_withdraw",
|
|
14
|
+
walletTransfer: "transfer",
|
|
15
|
+
walletTopup: "topup",
|
|
16
|
+
walletWithdraw: "withdraw",
|
|
17
|
+
walletPayment: "payment"
|
|
18
|
+
};
|
|
19
|
+
exports.transactionTargetTypes = {
|
|
20
|
+
request: "request",
|
|
21
|
+
wallet: "wallet"
|
|
22
|
+
};
|
|
23
|
+
const getCreatePayload = (transactionActionType, data) => {
|
|
24
|
+
if (transactionActionType === "wallet_transfer" && "requestTransfer" in data) {
|
|
25
|
+
return {
|
|
26
|
+
source: {
|
|
27
|
+
target: data.requestTransfer.source.sourceTarget,
|
|
28
|
+
module: data.requestTransfer.source.sourceModule,
|
|
29
|
+
transaction_ref: data.requestTransfer.source.transactionRef,
|
|
30
|
+
ref_id: {
|
|
31
|
+
[data.requestTransfer.source.sourceRefFieldName]: data.requestTransfer.source.refId
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
destination: {
|
|
35
|
+
target: data.requestTransfer.destination.sourceTarget,
|
|
36
|
+
module: data.requestTransfer.destination.sourceModule,
|
|
37
|
+
transaction_ref: data.requestTransfer.destination.transactionRef,
|
|
38
|
+
ref_id: {
|
|
39
|
+
[data.requestTransfer.destination.sourceRefFieldName]: data.requestTransfer.destination.refId
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (transactionActionType === "wallet_withdraw" && "requestWithdraw" in data) {
|
|
45
|
+
return {
|
|
46
|
+
source: {
|
|
47
|
+
target: data.requestWithdraw.source.sourceTarget,
|
|
48
|
+
module: data.requestWithdraw.source.sourceModule,
|
|
49
|
+
transaction_ref: data.requestWithdraw.source.transactionRef,
|
|
50
|
+
ref_id: {
|
|
51
|
+
[data.requestWithdraw.source.sourceRefFieldName]: data.requestWithdraw.source.refId
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
// destination: {
|
|
55
|
+
// target: data.requestWithdraw.destination.sourceTarget,
|
|
56
|
+
// module: data.requestWithdraw.destination.sourceModule,
|
|
57
|
+
// transaction_ref: data.requestWithdraw.destination.transactionRef,
|
|
58
|
+
// ref_id: {
|
|
59
|
+
// [data.requestWithdraw.destination.sourceRefFieldName]: data.requestWithdraw.destination.refId
|
|
60
|
+
// }
|
|
61
|
+
// }
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (transactionActionType === "wallet_topup" && "requestTopup" in data) {
|
|
65
|
+
return {
|
|
66
|
+
source: {
|
|
67
|
+
target: data.requestTopup.source.sourceTarget,
|
|
68
|
+
module: data.requestTopup.source.sourceModule,
|
|
69
|
+
transaction_ref: data.requestTopup.source.transactionRef,
|
|
70
|
+
ref_id: {
|
|
71
|
+
[data.requestTopup.source.sourceRefFieldName]: data.requestTopup.source.refId
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
// destination: {
|
|
75
|
+
// target: data.requestWithdraw.destination.sourceTarget,
|
|
76
|
+
// module: data.requestWithdraw.destination.sourceModule,
|
|
77
|
+
// transaction_ref: data.requestWithdraw.destination.transactionRef,
|
|
78
|
+
// ref_id: {
|
|
79
|
+
// [data.requestWithdraw.destination.sourceRefFieldName]: data.requestWithdraw.destination.refId
|
|
80
|
+
// }
|
|
81
|
+
// }
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const getUpdatePayload = (data) => {
|
|
86
|
+
return {
|
|
87
|
+
transaction: {
|
|
88
|
+
status: data.status,
|
|
89
|
+
transaction_date: data.transactionDate,
|
|
90
|
+
internal_reference_no: data.internalReferenceNo,
|
|
91
|
+
internal_remark: data.internalRemark
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
const TransactionService = (props) => {
|
|
96
|
+
const { transactionType = "wallet", transactionTargetType, ...rest } = props ?? {};
|
|
97
|
+
const { makeCall } = (0, lib_1.ApiService)(rest?.customToken ? { customToken: rest.customToken } : {});
|
|
98
|
+
const endpoint1 = "transaction";
|
|
99
|
+
const endpoint2 = "transactions";
|
|
100
|
+
const list = async (props) => {
|
|
101
|
+
const { transactionType: overrideTransactionType } = props;
|
|
102
|
+
const url = (0, lib_2.buildApiListUrl)(`${endpoint2}/${overrideTransactionType || transactionType}`, props);
|
|
103
|
+
const response = await makeCall({
|
|
104
|
+
url,
|
|
105
|
+
method: "get",
|
|
106
|
+
payload: {},
|
|
107
|
+
// configuration
|
|
108
|
+
});
|
|
109
|
+
return response;
|
|
110
|
+
};
|
|
111
|
+
const get = async (props) => {
|
|
112
|
+
const { id, transactionType: overrideTransactionType } = props;
|
|
113
|
+
const url = (0, lib_2.buildApiGetUrl)(`${endpoint1}/${overrideTransactionType || transactionType}/${id}`, props);
|
|
114
|
+
const response = await makeCall({
|
|
115
|
+
url,
|
|
116
|
+
method: "get",
|
|
117
|
+
payload: {},
|
|
118
|
+
// configuration
|
|
119
|
+
});
|
|
120
|
+
return response;
|
|
121
|
+
};
|
|
122
|
+
const create = async ({ data, transactionActionType = "wallet_topup", transactionTargetType: overrideTransactionTargetType }) => {
|
|
123
|
+
let _transactionType = transactionActionType;
|
|
124
|
+
let payload = getCreatePayload(_transactionType, data);
|
|
125
|
+
let url = `${endpoint1}`;
|
|
126
|
+
let postData = {
|
|
127
|
+
scope: {
|
|
128
|
+
target: overrideTransactionTargetType || transactionTargetType,
|
|
129
|
+
action: "",
|
|
130
|
+
},
|
|
131
|
+
payload
|
|
132
|
+
};
|
|
133
|
+
const response = await makeCall({
|
|
134
|
+
url,
|
|
135
|
+
method: "post",
|
|
136
|
+
payload: postData
|
|
137
|
+
});
|
|
138
|
+
return response;
|
|
139
|
+
};
|
|
140
|
+
const updateStatus = async ({ id, data, transactionTargetType: overrideTransactionTargetType }) => {
|
|
141
|
+
let url = `${endpoint1}/status/${id}`;
|
|
142
|
+
let payload = getUpdatePayload(data);
|
|
143
|
+
const postData = {
|
|
144
|
+
scope: {
|
|
145
|
+
target: overrideTransactionTargetType || transactionTargetType,
|
|
146
|
+
action: "",
|
|
147
|
+
},
|
|
148
|
+
payload
|
|
149
|
+
};
|
|
150
|
+
const response = await makeCall({
|
|
151
|
+
url,
|
|
152
|
+
method: "put",
|
|
153
|
+
payload: postData
|
|
154
|
+
});
|
|
155
|
+
return response;
|
|
156
|
+
};
|
|
157
|
+
const getDataTypes = async ({ transactionType: overrideTransactionType }) => {
|
|
158
|
+
let url = `${endpoint1}/data_types/${overrideTransactionType || transactionType}`;
|
|
159
|
+
const response = await makeCall({
|
|
160
|
+
url,
|
|
161
|
+
method: "get",
|
|
162
|
+
});
|
|
163
|
+
return response;
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
list,
|
|
167
|
+
get,
|
|
168
|
+
create,
|
|
169
|
+
updateStatus,
|
|
170
|
+
getDataTypes,
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
exports.TransactionService = TransactionService;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { ApiServiceType } from '@/lib';
|
|
2
|
+
import { BuildApiListParamsProps, BuildApiGetParamsProps } from '@/lib';
|
|
3
|
+
export declare const branchUserTypes: {
|
|
4
|
+
readonly customer: "customer";
|
|
5
|
+
readonly retailer: "retailer";
|
|
6
|
+
};
|
|
7
|
+
export declare const branchUserTargetTypes: {
|
|
8
|
+
readonly customer: "customer";
|
|
9
|
+
readonly retailer: "retailer";
|
|
10
|
+
};
|
|
11
|
+
export type BranchUserType = typeof branchUserTypes[keyof typeof branchUserTypes];
|
|
12
|
+
export type BranchUserTargetType = typeof branchUserTargetTypes[keyof typeof branchUserTargetTypes];
|
|
13
|
+
export type BranchUserTargetKey = keyof typeof branchUserTargetTypes;
|
|
14
|
+
export type BranchUserServiceProps = ApiServiceType & {
|
|
15
|
+
branchUserTargetType?: BranchUserTargetType;
|
|
16
|
+
branchUserType?: BranchUserType;
|
|
17
|
+
};
|
|
18
|
+
export type ListBranchUserProps = BuildApiListParamsProps & {
|
|
19
|
+
branchUserType?: BranchUserType;
|
|
20
|
+
};
|
|
21
|
+
export type GetBranchUserProps = BuildApiGetParamsProps & {
|
|
22
|
+
id: number | string;
|
|
23
|
+
branchUserType: BranchUserType;
|
|
24
|
+
};
|
|
25
|
+
type BranchUserCredential = {
|
|
26
|
+
username: string;
|
|
27
|
+
password: string;
|
|
28
|
+
firstname: string;
|
|
29
|
+
lastname: string;
|
|
30
|
+
contact: string;
|
|
31
|
+
email: string;
|
|
32
|
+
status: boolean;
|
|
33
|
+
address: string;
|
|
34
|
+
};
|
|
35
|
+
export type CreateBranchUserProps = {
|
|
36
|
+
branchUserTargetType?: BranchUserTargetType;
|
|
37
|
+
branchUserType?: BranchUserType;
|
|
38
|
+
data: {
|
|
39
|
+
customer: {
|
|
40
|
+
credential: BranchUserCredential;
|
|
41
|
+
branchUser: {
|
|
42
|
+
parentUserId: string | number;
|
|
43
|
+
};
|
|
44
|
+
props?: {
|
|
45
|
+
branchId: number[];
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
} | {
|
|
49
|
+
retailer: {
|
|
50
|
+
credential: BranchUserCredential;
|
|
51
|
+
branchUser: {
|
|
52
|
+
parentUserId: string | number;
|
|
53
|
+
};
|
|
54
|
+
props?: {
|
|
55
|
+
branchId: number[];
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export type UpdateBranchUserProps = {
|
|
61
|
+
id: number;
|
|
62
|
+
branchUserTargetType?: BranchUserTargetType;
|
|
63
|
+
branchUserType?: BranchUserType;
|
|
64
|
+
data: {
|
|
65
|
+
customer: {
|
|
66
|
+
credential: Omit<BranchUserCredential, "username" | "password"> & {
|
|
67
|
+
password?: string;
|
|
68
|
+
};
|
|
69
|
+
branchUser: {
|
|
70
|
+
parentUserId: string | number;
|
|
71
|
+
};
|
|
72
|
+
props?: {
|
|
73
|
+
branchId: number[];
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
} | {
|
|
77
|
+
retailer: {
|
|
78
|
+
credential: Omit<BranchUserCredential, "username" | "password"> & {
|
|
79
|
+
password?: string;
|
|
80
|
+
};
|
|
81
|
+
branchUser: {
|
|
82
|
+
parentUserId: string | number;
|
|
83
|
+
};
|
|
84
|
+
props?: {
|
|
85
|
+
branchId: number[];
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export type RemoveBranchUserProps = {
|
|
91
|
+
branchUserTargetType?: BranchUserTargetType;
|
|
92
|
+
ids: number[];
|
|
93
|
+
};
|
|
94
|
+
export type GetDataTypeBranchUserProps = {
|
|
95
|
+
branchUserType?: BranchUserType;
|
|
96
|
+
};
|
|
97
|
+
export declare const BranchUserService: (props?: BranchUserServiceProps) => {
|
|
98
|
+
list: (props: ListBranchUserProps) => Promise<{
|
|
99
|
+
status: boolean;
|
|
100
|
+
message: string;
|
|
101
|
+
data?: any;
|
|
102
|
+
}>;
|
|
103
|
+
get: (props: GetBranchUserProps) => Promise<{
|
|
104
|
+
status: boolean;
|
|
105
|
+
message: string;
|
|
106
|
+
data?: any;
|
|
107
|
+
}>;
|
|
108
|
+
create: ({ data, branchUserType: overrideBranchUserType, branchUserTargetType: overrideBranchUserTargetType }: CreateBranchUserProps) => Promise<{
|
|
109
|
+
status: boolean;
|
|
110
|
+
message: string;
|
|
111
|
+
data?: any;
|
|
112
|
+
}>;
|
|
113
|
+
update: ({ id, data, branchUserType: overrideBranchUserType, branchUserTargetType: overrideBranchUserTargetType }: UpdateBranchUserProps) => Promise<{
|
|
114
|
+
status: boolean;
|
|
115
|
+
message: string;
|
|
116
|
+
data?: any;
|
|
117
|
+
}>;
|
|
118
|
+
remove: ({ ids, branchUserTargetType: overrideBranchUserTargetType }: RemoveBranchUserProps) => Promise<{
|
|
119
|
+
status: boolean;
|
|
120
|
+
message: string;
|
|
121
|
+
data?: any;
|
|
122
|
+
}>;
|
|
123
|
+
getDataTypes: ({ branchUserType: overrideBranchUserType }: GetDataTypeBranchUserProps) => Promise<{
|
|
124
|
+
status: boolean;
|
|
125
|
+
message: string;
|
|
126
|
+
data?: any;
|
|
127
|
+
}>;
|
|
128
|
+
};
|
|
129
|
+
export {};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BranchUserService = exports.branchUserTargetTypes = exports.branchUserTypes = void 0;
|
|
4
|
+
const lib_1 = require("@/lib");
|
|
5
|
+
const lib_2 = require("@/lib");
|
|
6
|
+
exports.branchUserTypes = {
|
|
7
|
+
customer: "customer",
|
|
8
|
+
retailer: "retailer",
|
|
9
|
+
};
|
|
10
|
+
exports.branchUserTargetTypes = {
|
|
11
|
+
customer: "customer",
|
|
12
|
+
retailer: "retailer",
|
|
13
|
+
};
|
|
14
|
+
const getCreatePayload = (branchUserType, data) => {
|
|
15
|
+
if (branchUserType === "customer" && "customer" in data) {
|
|
16
|
+
return {
|
|
17
|
+
credential: {
|
|
18
|
+
username: data.customer.credential.username,
|
|
19
|
+
password: data.customer.credential.password,
|
|
20
|
+
firstname: data.customer.credential.firstname,
|
|
21
|
+
lastname: data.customer.credential.lastname,
|
|
22
|
+
contact: data.customer.credential.contact,
|
|
23
|
+
email: data.customer.credential.email,
|
|
24
|
+
status: (data.customer.credential.status === true) ? 1 : 0,
|
|
25
|
+
address: data.customer.credential.address
|
|
26
|
+
},
|
|
27
|
+
branchUser: {
|
|
28
|
+
parent_user_id: data.customer.branchUser.parentUserId
|
|
29
|
+
},
|
|
30
|
+
props: {
|
|
31
|
+
branch_id: data.customer.props?.branchId ? data.customer.props?.branchId : []
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (branchUserType === "retailer" && "retailer" in data) {
|
|
36
|
+
return {
|
|
37
|
+
credential: {
|
|
38
|
+
username: data.retailer.credential.username,
|
|
39
|
+
password: data.retailer.credential.password,
|
|
40
|
+
firstname: data.retailer.credential.firstname,
|
|
41
|
+
lastname: data.retailer.credential.lastname,
|
|
42
|
+
contact: data.retailer.credential.contact,
|
|
43
|
+
email: data.retailer.credential.email,
|
|
44
|
+
status: (data.retailer.credential.status === true) ? 1 : 0,
|
|
45
|
+
address: data.retailer.credential.address
|
|
46
|
+
},
|
|
47
|
+
branch_user: {
|
|
48
|
+
parent_user_id: data.retailer.branchUser.parentUserId
|
|
49
|
+
},
|
|
50
|
+
props: {
|
|
51
|
+
branch_id: data.retailer.props?.branchId ? data.retailer.props?.branchId : []
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const getUpdatePayload = (branchUserType, data) => {
|
|
57
|
+
if (branchUserType === "customer" && "customer" in data) {
|
|
58
|
+
return {
|
|
59
|
+
credential: {
|
|
60
|
+
...(data.customer.credential.password ? { password: data.customer.credential.password } : {}),
|
|
61
|
+
firstname: data.customer.credential.firstname,
|
|
62
|
+
lastname: data.customer.credential.lastname,
|
|
63
|
+
contact: data.customer.credential.contact,
|
|
64
|
+
email: data.customer.credential.email,
|
|
65
|
+
status: (data.customer.credential.status === true) ? 1 : 0,
|
|
66
|
+
address: data.customer.credential.address
|
|
67
|
+
},
|
|
68
|
+
branch_user: {
|
|
69
|
+
parent_user_id: data.customer.branchUser.parentUserId
|
|
70
|
+
},
|
|
71
|
+
props: {
|
|
72
|
+
branch_id: data.customer.props?.branchId ? data.customer.props?.branchId : []
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (branchUserType === "retailer" && "retailer" in data) {
|
|
77
|
+
return {
|
|
78
|
+
credential: {
|
|
79
|
+
...(data.retailer.credential.password ? { password: data.retailer.credential.password } : {}),
|
|
80
|
+
firstname: data.retailer.credential.firstname,
|
|
81
|
+
lastname: data.retailer.credential.lastname,
|
|
82
|
+
contact: data.retailer.credential.contact,
|
|
83
|
+
email: data.retailer.credential.email,
|
|
84
|
+
status: (data.retailer.credential.status === true) ? 1 : 0,
|
|
85
|
+
address: data.retailer.credential.address
|
|
86
|
+
},
|
|
87
|
+
branchUser: {
|
|
88
|
+
parent_user_id: data.retailer.branchUser.parentUserId
|
|
89
|
+
},
|
|
90
|
+
props: {
|
|
91
|
+
branch_id: data.retailer.props?.branchId ? data.retailer.props?.branchId : []
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const BranchUserService = (props) => {
|
|
97
|
+
const { branchUserType = "customer", branchUserTargetType, ...rest } = props ?? {};
|
|
98
|
+
const { makeCall } = (0, lib_1.ApiService)(rest?.customToken ? { customToken: rest.customToken } : {});
|
|
99
|
+
const endpoint1 = "user/branch_user";
|
|
100
|
+
const endpoint2 = "user/branch_users";
|
|
101
|
+
const list = async (props) => {
|
|
102
|
+
const { branchUserType: overrideBranchUserType } = props;
|
|
103
|
+
const url = (0, lib_2.buildApiListUrl)(`${endpoint2}/${overrideBranchUserType || branchUserType}`, props);
|
|
104
|
+
const response = await makeCall({
|
|
105
|
+
url,
|
|
106
|
+
method: "get",
|
|
107
|
+
payload: {},
|
|
108
|
+
// configuration
|
|
109
|
+
});
|
|
110
|
+
return response;
|
|
111
|
+
};
|
|
112
|
+
const get = async (props) => {
|
|
113
|
+
const { id, branchUserType: overrideBranchUserType } = props;
|
|
114
|
+
const url = (0, lib_2.buildApiGetUrl)(`${endpoint1}/${overrideBranchUserType || branchUserType}/${id}`, props);
|
|
115
|
+
const response = await makeCall({
|
|
116
|
+
url,
|
|
117
|
+
method: "get",
|
|
118
|
+
payload: {},
|
|
119
|
+
// configuration
|
|
120
|
+
});
|
|
121
|
+
return response;
|
|
122
|
+
};
|
|
123
|
+
const create = async ({ data, branchUserType: overrideBranchUserType, branchUserTargetType: overrideBranchUserTargetType }) => {
|
|
124
|
+
let _branchUserType = overrideBranchUserType || branchUserType;
|
|
125
|
+
let payload = getCreatePayload(_branchUserType, data);
|
|
126
|
+
let url = `${endpoint1}`;
|
|
127
|
+
let postData = {
|
|
128
|
+
scope: {
|
|
129
|
+
target: overrideBranchUserTargetType || branchUserTargetType,
|
|
130
|
+
action: "",
|
|
131
|
+
},
|
|
132
|
+
payload
|
|
133
|
+
};
|
|
134
|
+
const response = await makeCall({
|
|
135
|
+
url,
|
|
136
|
+
method: "post",
|
|
137
|
+
payload: postData
|
|
138
|
+
});
|
|
139
|
+
return response;
|
|
140
|
+
};
|
|
141
|
+
const update = async ({ id, data, branchUserType: overrideBranchUserType, branchUserTargetType: overrideBranchUserTargetType }) => {
|
|
142
|
+
let url = `${endpoint1}/${id}`;
|
|
143
|
+
let _branchUserType = overrideBranchUserType || branchUserType;
|
|
144
|
+
let payload = getUpdatePayload(_branchUserType, data);
|
|
145
|
+
const postData = {
|
|
146
|
+
scope: {
|
|
147
|
+
target: overrideBranchUserTargetType || branchUserTargetType,
|
|
148
|
+
action: "",
|
|
149
|
+
},
|
|
150
|
+
payload
|
|
151
|
+
};
|
|
152
|
+
const response = await makeCall({
|
|
153
|
+
url,
|
|
154
|
+
method: "put",
|
|
155
|
+
payload: postData
|
|
156
|
+
});
|
|
157
|
+
return response;
|
|
158
|
+
};
|
|
159
|
+
const remove = async ({ ids, branchUserTargetType: overrideBranchUserTargetType }) => {
|
|
160
|
+
let url = `${endpoint2}/delete`;
|
|
161
|
+
const postData = {
|
|
162
|
+
scope: {
|
|
163
|
+
target: overrideBranchUserTargetType || branchUserTargetType,
|
|
164
|
+
},
|
|
165
|
+
payload: {
|
|
166
|
+
ids
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const response = await makeCall({
|
|
170
|
+
url,
|
|
171
|
+
method: "post",
|
|
172
|
+
payload: postData
|
|
173
|
+
});
|
|
174
|
+
return response;
|
|
175
|
+
};
|
|
176
|
+
const getDataTypes = async ({ branchUserType: overrideBranchUserType }) => {
|
|
177
|
+
let url = `${endpoint2}/data_types/${overrideBranchUserType || branchUserType}`;
|
|
178
|
+
const response = await makeCall({
|
|
179
|
+
url,
|
|
180
|
+
method: "get",
|
|
181
|
+
});
|
|
182
|
+
return response;
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
list,
|
|
186
|
+
get,
|
|
187
|
+
create,
|
|
188
|
+
update,
|
|
189
|
+
remove,
|
|
190
|
+
getDataTypes
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
exports.BranchUserService = BranchUserService;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ApiServiceType } from '@/lib';
|
|
2
|
+
import { BuildApiListParamsProps, BuildApiGetParamsProps } from '@/lib';
|
|
3
|
+
export declare const roleTypes: {
|
|
4
|
+
readonly role: "role";
|
|
5
|
+
};
|
|
6
|
+
export declare const roleTargetTypes: {
|
|
7
|
+
readonly role: "role";
|
|
8
|
+
};
|
|
9
|
+
export type RoleType = typeof roleTypes[keyof typeof roleTypes];
|
|
10
|
+
export type RoleTargetType = typeof roleTargetTypes[keyof typeof roleTargetTypes];
|
|
11
|
+
export type RoleTargetKey = keyof typeof roleTargetTypes;
|
|
12
|
+
export type UserRoleServiceProps = ApiServiceType & {
|
|
13
|
+
roleTargetType?: RoleTargetType;
|
|
14
|
+
roleType?: RoleType;
|
|
15
|
+
};
|
|
16
|
+
export type ListRoleProps = BuildApiListParamsProps & {
|
|
17
|
+
roleType?: RoleType;
|
|
18
|
+
};
|
|
19
|
+
export type GetRoleProps = BuildApiGetParamsProps & {
|
|
20
|
+
id: number | string;
|
|
21
|
+
roleType?: RoleType;
|
|
22
|
+
};
|
|
23
|
+
type AssignRoleType = "admin" | "retail" | "workstation";
|
|
24
|
+
type Role = {
|
|
25
|
+
roleName: string;
|
|
26
|
+
assignRoleType: AssignRoleType;
|
|
27
|
+
description: string;
|
|
28
|
+
status: boolean;
|
|
29
|
+
userIds: number[];
|
|
30
|
+
};
|
|
31
|
+
type Permission = {
|
|
32
|
+
scopeType: string;
|
|
33
|
+
scopeName: string;
|
|
34
|
+
permissionType: string;
|
|
35
|
+
status: boolean;
|
|
36
|
+
isCustom: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type CreateRoleProps = {
|
|
39
|
+
roleTargetType?: RoleTargetType;
|
|
40
|
+
roleType?: RoleType;
|
|
41
|
+
data: {
|
|
42
|
+
userRole: Role;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export type UpdateRoleProps = {
|
|
46
|
+
id: number;
|
|
47
|
+
roleTargetType?: RoleTargetType;
|
|
48
|
+
roleType?: RoleType;
|
|
49
|
+
data: {
|
|
50
|
+
userRole: Omit<Role, "assignRoleType">;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export type UpdateRolePermissionProps = {
|
|
54
|
+
id: number;
|
|
55
|
+
roleTargetType?: RoleTargetType;
|
|
56
|
+
roleType?: RoleType;
|
|
57
|
+
data: {
|
|
58
|
+
permissions: Permission[];
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export type RemoveRoleProps = {
|
|
62
|
+
roleTargetType?: RoleTargetType;
|
|
63
|
+
ids: number[];
|
|
64
|
+
};
|
|
65
|
+
export type GetDataTypeRoleProps = {
|
|
66
|
+
roleType?: RoleType;
|
|
67
|
+
};
|
|
68
|
+
export declare const UserRoleService: (props?: UserRoleServiceProps) => {
|
|
69
|
+
list: (props: ListRoleProps) => Promise<{
|
|
70
|
+
status: boolean;
|
|
71
|
+
message: string;
|
|
72
|
+
data?: any;
|
|
73
|
+
}>;
|
|
74
|
+
get: (props: GetRoleProps) => Promise<{
|
|
75
|
+
status: boolean;
|
|
76
|
+
message: string;
|
|
77
|
+
data?: any;
|
|
78
|
+
}>;
|
|
79
|
+
create: ({ data, roleType: overrideRoleType, roleTargetType: overrideRoleTargetType }: CreateRoleProps) => Promise<{
|
|
80
|
+
status: boolean;
|
|
81
|
+
message: string;
|
|
82
|
+
data?: any;
|
|
83
|
+
}>;
|
|
84
|
+
update: ({ id, data, roleType: overrideRoleType, roleTargetType: overrideRoleTargetType }: UpdateRoleProps) => Promise<{
|
|
85
|
+
status: boolean;
|
|
86
|
+
message: string;
|
|
87
|
+
data?: any;
|
|
88
|
+
}>;
|
|
89
|
+
remove: ({ ids, roleTargetType: overrideRoleTargetType }: RemoveRoleProps) => Promise<{
|
|
90
|
+
status: boolean;
|
|
91
|
+
message: string;
|
|
92
|
+
data?: any;
|
|
93
|
+
}>;
|
|
94
|
+
getDataTypes: ({ roleType: overrideRoleType }: GetDataTypeRoleProps) => Promise<{
|
|
95
|
+
status: boolean;
|
|
96
|
+
message: string;
|
|
97
|
+
data?: any;
|
|
98
|
+
}>;
|
|
99
|
+
updateRolePermission: ({ id, data, roleType: overrideRoleType, roleTargetType: overrideRoleTargetType }: UpdateRolePermissionProps) => Promise<{
|
|
100
|
+
status: boolean;
|
|
101
|
+
message: string;
|
|
102
|
+
data?: any;
|
|
103
|
+
}>;
|
|
104
|
+
};
|
|
105
|
+
export {};
|