@webitel/api-services 0.0.72 → 0.0.73
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/package.json
CHANGED
package/src/api/clients/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * from './pdfServices/pdfServices';
|
|
|
30
30
|
export * from './phones/phones';
|
|
31
31
|
export * from './queues/queues';
|
|
32
32
|
export * from './quickReplies/quickReplies';
|
|
33
|
+
export * from './regions/regions';
|
|
33
34
|
// export * from './roles/roles'; fixme: ApplicationAccess import
|
|
34
35
|
export * from './skills/skills';
|
|
35
36
|
export * from './slas/slas';
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { RegionServiceApiFactory } from 'webitel-sdk';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getDefaultGetListResponse,
|
|
5
|
+
getDefaultGetParams,
|
|
6
|
+
getDefaultInstance,
|
|
7
|
+
getDefaultOpenAPIConfig,
|
|
8
|
+
} from '../../defaults';
|
|
9
|
+
import {
|
|
10
|
+
applyTransform,
|
|
11
|
+
camelToSnake,
|
|
12
|
+
merge,
|
|
13
|
+
notify,
|
|
14
|
+
sanitize,
|
|
15
|
+
snakeToCamel,
|
|
16
|
+
starToSearch,
|
|
17
|
+
} from '../../transformers';
|
|
18
|
+
|
|
19
|
+
const instance = getDefaultInstance();
|
|
20
|
+
const configuration = getDefaultOpenAPIConfig();
|
|
21
|
+
|
|
22
|
+
const regionService = RegionServiceApiFactory(configuration, '', instance);
|
|
23
|
+
|
|
24
|
+
const getRegionsList = async (params) => {
|
|
25
|
+
const { page, size, search, sort, fields, id } = applyTransform(params, [
|
|
26
|
+
merge(getDefaultGetParams()),
|
|
27
|
+
starToSearch('search'),
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const response = await regionService.searchRegion(
|
|
32
|
+
page,
|
|
33
|
+
size,
|
|
34
|
+
search,
|
|
35
|
+
sort,
|
|
36
|
+
fields,
|
|
37
|
+
id,
|
|
38
|
+
);
|
|
39
|
+
const { items, next } = applyTransform(response.data, [
|
|
40
|
+
snakeToCamel(),
|
|
41
|
+
merge(getDefaultGetListResponse()),
|
|
42
|
+
]);
|
|
43
|
+
return {
|
|
44
|
+
items,
|
|
45
|
+
next,
|
|
46
|
+
};
|
|
47
|
+
} catch (err) {
|
|
48
|
+
throw applyTransform(err, [notify]);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const getRegion = async ({ itemId: id }) => {
|
|
53
|
+
try {
|
|
54
|
+
const response = await regionService.readRegion(id);
|
|
55
|
+
return applyTransform(response.data, [snakeToCamel()]);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
throw applyTransform(err, [notify]);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const fieldsToSend = ['name', 'timezone', 'description'];
|
|
62
|
+
|
|
63
|
+
const addRegion = async ({ itemInstance }) => {
|
|
64
|
+
const item = applyTransform(itemInstance, [
|
|
65
|
+
sanitize(fieldsToSend),
|
|
66
|
+
camelToSnake(),
|
|
67
|
+
]);
|
|
68
|
+
try {
|
|
69
|
+
const response = await regionService.createRegion(item);
|
|
70
|
+
return applyTransform(response.data, [snakeToCamel()]);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
throw applyTransform(err, [notify]);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const updateRegion = async ({ itemInstance, itemId: id }) => {
|
|
77
|
+
const item = applyTransform(itemInstance, [
|
|
78
|
+
sanitize(fieldsToSend),
|
|
79
|
+
camelToSnake(),
|
|
80
|
+
]);
|
|
81
|
+
try {
|
|
82
|
+
const response = await regionService.updateRegion(id, item);
|
|
83
|
+
return applyTransform(response.data, [snakeToCamel()]);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
throw applyTransform(err, [notify]);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const deleteRegion = async ({ id }) => {
|
|
90
|
+
try {
|
|
91
|
+
const response = await regionService.deleteRegion(id);
|
|
92
|
+
return applyTransform(response.data, []);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
throw applyTransform(err, [notify]);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const getRegionsLookup = (params) =>
|
|
99
|
+
getRegionsList({
|
|
100
|
+
...params,
|
|
101
|
+
fields: params.fields || ['id', 'name'],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const RegionsAPI = {
|
|
105
|
+
getList: getRegionsList,
|
|
106
|
+
get: getRegion,
|
|
107
|
+
add: addRegion,
|
|
108
|
+
update: updateRegion,
|
|
109
|
+
delete: deleteRegion,
|
|
110
|
+
getLookup: getRegionsLookup,
|
|
111
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const RegionsAPI: {
|
|
2
|
+
getList: (params: any) => Promise<{
|
|
3
|
+
items: any;
|
|
4
|
+
next: any;
|
|
5
|
+
}>;
|
|
6
|
+
get: ({ itemId: id }: {
|
|
7
|
+
itemId: any;
|
|
8
|
+
}) => Promise<any>;
|
|
9
|
+
add: ({ itemInstance }: {
|
|
10
|
+
itemInstance: any;
|
|
11
|
+
}) => Promise<any>;
|
|
12
|
+
update: ({ itemInstance, itemId: id }: {
|
|
13
|
+
itemInstance: any;
|
|
14
|
+
itemId: any;
|
|
15
|
+
}) => Promise<any>;
|
|
16
|
+
delete: ({ id }: {
|
|
17
|
+
id: any;
|
|
18
|
+
}) => Promise<any>;
|
|
19
|
+
getLookup: (params: any) => Promise<{
|
|
20
|
+
items: any;
|
|
21
|
+
next: any;
|
|
22
|
+
}>;
|
|
23
|
+
};
|