ggez-banking-sdk 0.1.116 → 0.1.118
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.
@@ -1,18 +1,9 @@
|
|
1
|
-
import {
|
2
|
-
declare const OldUserHelper: (userInfo: any) => {
|
3
|
-
checkResponse: () => {
|
4
|
-
checkUserResponseAuth: (response: any, showMessageSuccess: boolean, funcName: string) => any;
|
5
|
-
checkGlobalResponse: (key: string, response: any, funcName: string, keyAction?: string) => {
|
6
|
-
newUserInfo: any;
|
7
|
-
};
|
8
|
-
errorHandler: (error: any, funcName: string, response?: string) => never;
|
9
|
-
};
|
10
|
-
};
|
11
|
-
export declare function sortUserInfo(list?: any[] | null): any;
|
12
|
-
export default OldUserHelper;
|
1
|
+
import { TModifyListByEntity, TModifyByDocumentData, TSortByID, TSortByIsPrimary, TSortByVerificationStatus, TSortEntity, TModifyOrganizationByDocumentData, TModifyProfilePicture } from "..";
|
13
2
|
declare class UserHelper {
|
14
|
-
static
|
3
|
+
static ModifyListByEntity: TModifyListByEntity;
|
15
4
|
static ModifyByDocumentData: TModifyByDocumentData;
|
5
|
+
static ModifyOrganizationByDocumentData: TModifyOrganizationByDocumentData;
|
6
|
+
static ModifyProfilePicture: TModifyProfilePicture;
|
16
7
|
static SortEntity: TSortEntity;
|
17
8
|
static SortByIsPrimary: TSortByIsPrimary;
|
18
9
|
static SortByVerificationStatus: TSortByVerificationStatus;
|
@@ -1,342 +1,7 @@
|
|
1
|
-
import { EntityVerificationStatus } from "../constants
|
2
|
-
import { SystemResponses } from "../constants";
|
3
|
-
const OldUserHelper = (userInfo) => {
|
4
|
-
// error Handler
|
5
|
-
// action type
|
6
|
-
const newUserInfo = () => {
|
7
|
-
const error = null;
|
8
|
-
const addInfo = (key, data) => {
|
9
|
-
if (Array.isArray(userInfo[`${key}`])) {
|
10
|
-
const newData = [...userInfo[`${key}`], data[0]];
|
11
|
-
const newUserInfo = { ...userInfo, [key]: sortUserInfo(newData) };
|
12
|
-
return { newUserInfo: newUserInfo };
|
13
|
-
}
|
14
|
-
else {
|
15
|
-
const newUserInfo = { ...userInfo, [key]: data };
|
16
|
-
return { newUserInfo: newUserInfo };
|
17
|
-
}
|
18
|
-
};
|
19
|
-
const updateInfo = (key, data) => {
|
20
|
-
const updatedData = Array.isArray(userInfo[`${key}`]) &&
|
21
|
-
userInfo[`${key}`].map((el, i) => {
|
22
|
-
if (el.id == data[0].id) {
|
23
|
-
return data[0];
|
24
|
-
}
|
25
|
-
else {
|
26
|
-
return el;
|
27
|
-
}
|
28
|
-
});
|
29
|
-
const newUserInfo = { ...userInfo, [key]: sortUserInfo(updatedData) };
|
30
|
-
return { newUserInfo: newUserInfo };
|
31
|
-
};
|
32
|
-
const removeInfo = (key, data) => {
|
33
|
-
let newUserInfo;
|
34
|
-
if (Array.isArray(userInfo[`${key}`]) && data != null) {
|
35
|
-
const removeData = Array.isArray(userInfo[`${key}`]) &&
|
36
|
-
userInfo[`${key}`].filter((el, i) => {
|
37
|
-
return el.id !== data[0].id;
|
38
|
-
});
|
39
|
-
newUserInfo = { ...userInfo, [key]: sortUserInfo(removeData) };
|
40
|
-
}
|
41
|
-
else if (data == null) {
|
42
|
-
const userInfoObj = { ...userInfo };
|
43
|
-
userInfoObj[key] = data;
|
44
|
-
newUserInfo = userInfoObj;
|
45
|
-
}
|
46
|
-
return { newUserInfo: newUserInfo };
|
47
|
-
};
|
48
|
-
const updatePrimaryInfo = (key, data) => {
|
49
|
-
const updateData = Array.isArray(userInfo[`${key}`]) &&
|
50
|
-
userInfo[`${key}`].map((el, i) => {
|
51
|
-
if (el.id == data[0].id) {
|
52
|
-
return { ...el, is_primary: 1 };
|
53
|
-
}
|
54
|
-
else if (el.is_primary == 1) {
|
55
|
-
return { ...el, is_primary: 0 };
|
56
|
-
}
|
57
|
-
else {
|
58
|
-
return el;
|
59
|
-
}
|
60
|
-
});
|
61
|
-
const newUserInfo = { ...userInfo, [key]: sortUserInfo(updateData) };
|
62
|
-
return { newUserInfo: newUserInfo };
|
63
|
-
};
|
64
|
-
const updateDocumentInfo = (key, data) => {
|
65
|
-
const updateData = Array.isArray(userInfo[`${key}`]) &&
|
66
|
-
userInfo[`${key}`].map((el, i) => {
|
67
|
-
if (el.id == data?.info?.entity_id) {
|
68
|
-
return {
|
69
|
-
...el,
|
70
|
-
verification_status: EntityVerificationStatus.Pending,
|
71
|
-
};
|
72
|
-
}
|
73
|
-
else {
|
74
|
-
return el;
|
75
|
-
}
|
76
|
-
});
|
77
|
-
const newUserInfo = { ...userInfo, [key]: sortUserInfo(updateData) };
|
78
|
-
return { newUserInfo: newUserInfo, error: error };
|
79
|
-
};
|
80
|
-
const updateObjectInfo = (key, data) => {
|
81
|
-
const updateData = { ...userInfo[`${key}`], ...data };
|
82
|
-
const newUserInfo = { ...userInfo, [key]: updateData };
|
83
|
-
return { newUserInfo: newUserInfo };
|
84
|
-
};
|
85
|
-
const updateProfilePicture = (key, res) => {
|
86
|
-
const data = res.data.attachment[0].file_url;
|
87
|
-
const updateData = { ...userInfo[`${key}`], ["picture"]: data };
|
88
|
-
const newUserInfo = { ...userInfo, [`${key}`]: updateData };
|
89
|
-
return { newUserInfo: newUserInfo };
|
90
|
-
};
|
91
|
-
const getUserInfo = (data) => {
|
92
|
-
const newUserInfo = { ...userInfo, data };
|
93
|
-
return { newUserInfo: newUserInfo };
|
94
|
-
};
|
95
|
-
const resetSecurity = (key, keyAction) => {
|
96
|
-
let security = null;
|
97
|
-
if (keyAction == "resetQuestions") {
|
98
|
-
security = {
|
99
|
-
...userInfo[`${key}`],
|
100
|
-
["secret_answer_1"]: "____",
|
101
|
-
["secret_answer_2"]: "____",
|
102
|
-
};
|
103
|
-
}
|
104
|
-
else if (keyAction == "resetSecurityCode") {
|
105
|
-
security = {
|
106
|
-
...userInfo[`${key}`],
|
107
|
-
["security_code"]: "____",
|
108
|
-
};
|
109
|
-
}
|
110
|
-
const newUserInfo = { ...userInfo, [`${key}`]: security };
|
111
|
-
return { newUserInfo: newUserInfo };
|
112
|
-
};
|
113
|
-
const addOrganizationInfo = (key, data) => {
|
114
|
-
if (Array.isArray(userInfo[`${key}`])) {
|
115
|
-
const newData = [...userInfo[`${key}`], data];
|
116
|
-
const newUserInfo = { ...userInfo, [key]: sortUserInfo(newData) };
|
117
|
-
return { newUserInfo: newUserInfo };
|
118
|
-
}
|
119
|
-
else {
|
120
|
-
const newUserInfo = { ...userInfo, [key]: [data] };
|
121
|
-
return { newUserInfo: newUserInfo };
|
122
|
-
}
|
123
|
-
};
|
124
|
-
const updateOrganizationInfo = (key, data) => {
|
125
|
-
const updatedData = Array.isArray(userInfo[`${key}`]) &&
|
126
|
-
userInfo[`${key}`].map((el, i) => {
|
127
|
-
if (el.info.id == data.info.id) {
|
128
|
-
return data;
|
129
|
-
}
|
130
|
-
else {
|
131
|
-
return el;
|
132
|
-
}
|
133
|
-
});
|
134
|
-
const newUserInfo = { ...userInfo, [key]: sortUserInfo(updatedData) };
|
135
|
-
return { newUserInfo: newUserInfo };
|
136
|
-
};
|
137
|
-
const removeOrganizationInfo = (key, data) => {
|
138
|
-
let newUserInfo;
|
139
|
-
if (Array.isArray(userInfo[`${key}`]) && data != null) {
|
140
|
-
let removeData = Array.isArray(userInfo[`${key}`]) &&
|
141
|
-
userInfo[`${key}`].filter((el, i) => {
|
142
|
-
return el.info.id !== data.info.id;
|
143
|
-
});
|
144
|
-
if (removeData.length <= 0) {
|
145
|
-
removeData = null;
|
146
|
-
}
|
147
|
-
newUserInfo = { ...userInfo, [key]: sortUserInfo(removeData) };
|
148
|
-
}
|
149
|
-
else if (data == null) {
|
150
|
-
const userInfoObj = { ...userInfo };
|
151
|
-
userInfoObj[key] = data;
|
152
|
-
newUserInfo = userInfoObj;
|
153
|
-
}
|
154
|
-
return { newUserInfo: newUserInfo };
|
155
|
-
};
|
156
|
-
const createDocumentOrganization = (key, data) => {
|
157
|
-
const updateData = Array.isArray(userInfo[`${key}`]) &&
|
158
|
-
userInfo[`${key}`].map((el, i) => {
|
159
|
-
if (el.info.id == data?.info?.entity_id) {
|
160
|
-
const newInfo = {
|
161
|
-
...el.info,
|
162
|
-
verification_status: EntityVerificationStatus.Pending,
|
163
|
-
};
|
164
|
-
return { ...el, ["info"]: newInfo };
|
165
|
-
}
|
166
|
-
else {
|
167
|
-
return el;
|
168
|
-
}
|
169
|
-
});
|
170
|
-
const newUserInfo = { ...userInfo, [key]: updateData };
|
171
|
-
return { newUserInfo: newUserInfo };
|
172
|
-
};
|
173
|
-
return {
|
174
|
-
addInfo,
|
175
|
-
removeInfo,
|
176
|
-
updateInfo,
|
177
|
-
updatePrimaryInfo,
|
178
|
-
updateDocumentInfo,
|
179
|
-
updateObjectInfo,
|
180
|
-
updateProfilePicture,
|
181
|
-
getUserInfo,
|
182
|
-
resetSecurity,
|
183
|
-
addOrganizationInfo,
|
184
|
-
updateOrganizationInfo,
|
185
|
-
removeOrganizationInfo,
|
186
|
-
createDocumentOrganization,
|
187
|
-
};
|
188
|
-
};
|
189
|
-
const { addInfo, removeInfo, updateInfo, updatePrimaryInfo, updateDocumentInfo, updateObjectInfo, updateProfilePicture, getUserInfo, resetSecurity, addOrganizationInfo, updateOrganizationInfo, removeOrganizationInfo, createDocumentOrganization, } = newUserInfo();
|
190
|
-
// check response
|
191
|
-
const checkResponse = () => {
|
192
|
-
const errorHandler = (error, funcName, response) => {
|
193
|
-
const errorObj = {
|
194
|
-
status: "failed",
|
195
|
-
message: error,
|
196
|
-
funcName: funcName,
|
197
|
-
response: response,
|
198
|
-
};
|
199
|
-
throw errorObj;
|
200
|
-
};
|
201
|
-
const actionTypeHandler = (key, response, keyAction) => {
|
202
|
-
const data = response?.data[`${key}`];
|
203
|
-
if (keyAction == "create") {
|
204
|
-
return addInfo(`${key}`, data);
|
205
|
-
}
|
206
|
-
else if (keyAction == "update") {
|
207
|
-
return updateInfo(`${key}`, data);
|
208
|
-
}
|
209
|
-
else if (keyAction == "delete") {
|
210
|
-
return removeInfo(`${key}`, data);
|
211
|
-
}
|
212
|
-
else if (keyAction == "updatePrimary") {
|
213
|
-
return updatePrimaryInfo(`${key}`, data);
|
214
|
-
}
|
215
|
-
else if (keyAction == "confirm") {
|
216
|
-
const data = response?.data?.verify_data[`${key}`];
|
217
|
-
return updateInfo(`${key}`, [data]);
|
218
|
-
}
|
219
|
-
else if (keyAction == "createDocument") {
|
220
|
-
return updateDocumentInfo(`${key}`, response?.data);
|
221
|
-
}
|
222
|
-
else if (keyAction == "updateObjectInfo") {
|
223
|
-
return updateObjectInfo(`${key}`, data);
|
224
|
-
}
|
225
|
-
else if (keyAction == "updateProfilePicture") {
|
226
|
-
return updateProfilePicture(`${key}`, response);
|
227
|
-
}
|
228
|
-
else if (keyAction == "userInfo") {
|
229
|
-
return getUserInfo(response?.data);
|
230
|
-
}
|
231
|
-
else if (keyAction == "resetQuestions" ||
|
232
|
-
keyAction == "resetSecurityCode") {
|
233
|
-
return resetSecurity(`${key}`, keyAction);
|
234
|
-
}
|
235
|
-
else if (keyAction == "createOrganization") {
|
236
|
-
return addOrganizationInfo(`${key}`, response?.data);
|
237
|
-
}
|
238
|
-
else if (keyAction == "updateOrganization") {
|
239
|
-
return updateOrganizationInfo(`${key}`, response?.data);
|
240
|
-
}
|
241
|
-
else if (keyAction == "deleteOrganization") {
|
242
|
-
return removeOrganizationInfo(`${key}`, response?.data);
|
243
|
-
}
|
244
|
-
else if (keyAction == "createDocumentOrganization") {
|
245
|
-
return createDocumentOrganization(`${key}`, response?.data);
|
246
|
-
}
|
247
|
-
else {
|
248
|
-
return { newUserInfo: null };
|
249
|
-
}
|
250
|
-
};
|
251
|
-
const checkUserResponseAuth = (response, showMessageSuccess, funcName) => {
|
252
|
-
const check = response?.data?.result?.code;
|
253
|
-
if (check != SystemResponses.Approved &&
|
254
|
-
check != SystemResponses.Create_User_Completed_Partially) {
|
255
|
-
errorHandler(response?.data?.result?.message, funcName, response);
|
256
|
-
}
|
257
|
-
else if (!showMessageSuccess) {
|
258
|
-
const value = response.data;
|
259
|
-
value.email = sortUserInfo(value.email);
|
260
|
-
value.phone = sortUserInfo(value.phone);
|
261
|
-
value.identification = sortUserInfo(value.identification);
|
262
|
-
value.addresses = sortUserInfo(value.addresses);
|
263
|
-
value.bank_account = sortUserInfo(value.bank_account);
|
264
|
-
return value;
|
265
|
-
}
|
266
|
-
else {
|
267
|
-
return {
|
268
|
-
action: "Success",
|
269
|
-
message: "User Created Successfully",
|
270
|
-
};
|
271
|
-
}
|
272
|
-
};
|
273
|
-
const checkGlobalResponse = (key, response, funcName, keyAction) => {
|
274
|
-
const check = response?.data?.result?.code;
|
275
|
-
if (!check && funcName.includes("login")) {
|
276
|
-
return { newUserInfo: null };
|
277
|
-
}
|
278
|
-
else if (check &&
|
279
|
-
(check == SystemResponses.Approved ||
|
280
|
-
check == SystemResponses.Create_User_Completed_Partially)) {
|
281
|
-
return actionTypeHandler(key, response, keyAction);
|
282
|
-
}
|
283
|
-
else {
|
284
|
-
return errorHandler(response?.data?.result?.message, funcName, response);
|
285
|
-
}
|
286
|
-
};
|
287
|
-
return {
|
288
|
-
checkUserResponseAuth,
|
289
|
-
checkGlobalResponse,
|
290
|
-
errorHandler,
|
291
|
-
};
|
292
|
-
};
|
293
|
-
return {
|
294
|
-
checkResponse,
|
295
|
-
};
|
296
|
-
};
|
297
|
-
export function sortUserInfo(list) {
|
298
|
-
try {
|
299
|
-
const verificationStatusOrder = {
|
300
|
-
"1": 0, // Verified
|
301
|
-
"2": 1, // Pending
|
302
|
-
"3": 2, // Failed
|
303
|
-
"0": 3, // Not Verified
|
304
|
-
"-1": 4, // Undefined
|
305
|
-
};
|
306
|
-
return list
|
307
|
-
? list?.sort((a, b) => {
|
308
|
-
// First, compare by 'is_primary'
|
309
|
-
const isPrimaryComparison = a?.is_primary != undefined && b?.is_primary != undefined
|
310
|
-
? b?.is_primary - a?.is_primary
|
311
|
-
: 0;
|
312
|
-
// If 'is_primary' values are equal, compare by 'verification_status'
|
313
|
-
if (isPrimaryComparison === 0) {
|
314
|
-
const verificationStatusComparison = verificationStatusOrder[a?.verification_status] -
|
315
|
-
verificationStatusOrder[b?.verification_status];
|
316
|
-
// If 'is_primary' values are equal, and 'verification_status' values are equal, compare by id
|
317
|
-
if (verificationStatusComparison == 0) {
|
318
|
-
return b?.id - a?.id;
|
319
|
-
}
|
320
|
-
return verificationStatusComparison;
|
321
|
-
}
|
322
|
-
return isPrimaryComparison;
|
323
|
-
})
|
324
|
-
: list;
|
325
|
-
}
|
326
|
-
catch (error) {
|
327
|
-
const errorObj = {
|
328
|
-
status: "failed",
|
329
|
-
message: error,
|
330
|
-
funcName: "sortUserInfo",
|
331
|
-
response: null,
|
332
|
-
};
|
333
|
-
return errorObj;
|
334
|
-
}
|
335
|
-
}
|
336
|
-
export default OldUserHelper;
|
1
|
+
import { EntityVerificationStatus } from "../constants";
|
337
2
|
class UserHelper {
|
338
3
|
// #region "Modify"
|
339
|
-
static
|
4
|
+
static ModifyListByEntity = (entityList, entity) => {
|
340
5
|
const modifiedList = entityList.map((e) => {
|
341
6
|
if (e.id == entity.id) {
|
342
7
|
return { ...e, ...entity };
|
@@ -359,6 +24,22 @@ class UserHelper {
|
|
359
24
|
const sortedList = this.SortEntity(modifiedList);
|
360
25
|
return sortedList;
|
361
26
|
};
|
27
|
+
static ModifyOrganizationByDocumentData = (organizationList, organization) => {
|
28
|
+
const modifiedList = organizationList.map((e) => {
|
29
|
+
if (e.info.id == organization.info.entity_id) {
|
30
|
+
return { ...e, verification_status: EntityVerificationStatus.Pending };
|
31
|
+
}
|
32
|
+
return e;
|
33
|
+
});
|
34
|
+
return modifiedList;
|
35
|
+
};
|
36
|
+
static ModifyProfilePicture = (personal_info, documentData) => {
|
37
|
+
const picture = documentData.attachment[0].file_url;
|
38
|
+
return {
|
39
|
+
...personal_info,
|
40
|
+
picture: picture,
|
41
|
+
};
|
42
|
+
};
|
362
43
|
// #endregion
|
363
44
|
// #region "Sort"
|
364
45
|
static SortEntity = (entityList) => {
|
@@ -1,9 +1,10 @@
|
|
1
|
-
import { DocumentData, OrganizationData, UserData } from "..";
|
2
|
-
type TEntity = UserData[keyof Pick<UserData, "addresses" | "bank_account" | "email" | "phone">][0];
|
3
|
-
type
|
1
|
+
import { DocumentData, OrganizationData, PersonalInfo, UserData } from "..";
|
2
|
+
type TEntity = UserData[keyof Pick<UserData, "addresses" | "bank_account" | "email" | "phone" | "identification">][0];
|
3
|
+
type TModifyListByEntity = <K extends TEntity>(entityList: K[], entity: K) => K[];
|
4
4
|
type TModifyByDocumentData = <K extends TEntity>(entityList: K[], entity: DocumentData) => K[];
|
5
|
-
type TModifyOrganizationByDocumentData = <K extends OrganizationData>(
|
6
|
-
|
5
|
+
type TModifyOrganizationByDocumentData = <K extends OrganizationData>(organizationList: K[], organization: DocumentData) => K[];
|
6
|
+
type TModifyProfilePicture = (personal_info: PersonalInfo, documentData: DocumentData) => PersonalInfo;
|
7
|
+
export { TEntity, TModifyListByEntity, TModifyByDocumentData, TModifyOrganizationByDocumentData, TModifyProfilePicture, };
|
7
8
|
type BaseEntity = {
|
8
9
|
id: number;
|
9
10
|
is_primary: number;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ggez-banking-sdk",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.118",
|
4
4
|
"description": "A Node.js package to handle GGEZ Banking API endpoints, Simplify the process of managing CRUD operations with this efficient and easy-to-use package.",
|
5
5
|
"types": "dist/index.d.ts",
|
6
6
|
"main": "dist/index.js",
|