@webitel/api-services 0.1.65 → 0.1.67
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 +1 -1
- package/src/api/clients/contactGroups/contactGroups.ts +57 -58
- package/src/api/clients/dynamicConditions/dynamicConditions.ts +179 -0
- package/src/api/clients/dynamicGroups/dynamicGroups.ts +191 -0
- package/src/api/clients/index.ts +2 -0
- package/src/api/clients/slaConditions/slaConditions.ts +50 -66
- package/src/api/clients/slas/slas.ts +30 -43
- package/src/validations/_shared/duration.validations.ts +7 -0
- package/src/validations/contactGroup/contactGroup.validations.ts +34 -0
- package/src/validations/contactGroupCondition/contactGroupCondition.validations.ts +15 -0
- package/src/validations/index.ts +6 -0
- package/src/validations/sla/sla.validations.ts +49 -0
- package/src/validations/slaCondition/slaCondition.validations.ts +12 -0
- package/types/.tsbuildinfo +1 -1
- package/types/api/clients/contactGroups/contactGroups.d.ts +3 -3
- package/types/api/clients/dynamicConditions/dynamicConditions.d.ts +27 -0
- package/types/api/clients/dynamicGroups/dynamicGroups.d.ts +27 -0
- package/types/api/clients/index.d.ts +2 -0
- package/types/api/clients/slaConditions/slaConditions.d.ts +5 -2
- package/types/validations/_shared/duration.validations.d.ts +2 -0
- package/types/validations/contactGroup/contactGroup.validations.d.ts +28 -0
- package/types/validations/contactGroupCondition/contactGroupCondition.validations.d.ts +7 -0
- package/types/validations/index.d.ts +6 -0
- package/types/validations/sla/sla.validations.d.ts +15 -0
- package/types/validations/slaCondition/slaCondition.validations.d.ts +13 -0
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { GroupsApiFactory } from 'webitel-sdk';
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
AddContactsToGroupsBody,
|
|
3
|
+
CreateGroupBody,
|
|
4
|
+
getGroups,
|
|
5
|
+
ListGroupsQueryParams,
|
|
6
|
+
UpdateGroupBody,
|
|
7
|
+
} from '@webitel/api-services/gen';
|
|
8
|
+
import { ContactsGroupType } from '@webitel/api-services/gen/models';
|
|
9
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
10
|
+
|
|
11
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
8
12
|
import {
|
|
9
13
|
applyTransform,
|
|
10
14
|
camelToSnake,
|
|
@@ -25,32 +29,19 @@ import type {
|
|
|
25
29
|
UpdateItemParams,
|
|
26
30
|
} from '../_shared/types';
|
|
27
31
|
|
|
28
|
-
const instance = getDefaultInstance();
|
|
29
|
-
const configuration = getDefaultOpenAPIConfig();
|
|
30
|
-
|
|
31
|
-
const contactGroupsService = GroupsApiFactory(configuration, '', instance);
|
|
32
|
-
|
|
33
32
|
const baseUrl = '/contacts/groups';
|
|
34
33
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
];
|
|
34
|
+
const groupFieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateGroupBody);
|
|
35
|
+
|
|
36
|
+
const appendStaticType = (item: ApiParams) => ({
|
|
37
|
+
...item,
|
|
38
|
+
type: item.type ?? ContactsGroupType.Static,
|
|
39
|
+
});
|
|
42
40
|
|
|
43
41
|
const getContactGroupsList = async (params: ApiParams) => {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
'q',
|
|
48
|
-
'sort',
|
|
49
|
-
'fields',
|
|
50
|
-
'type',
|
|
51
|
-
'enabled',
|
|
52
|
-
'id',
|
|
53
|
-
];
|
|
42
|
+
const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
43
|
+
ListGroupsQueryParams,
|
|
44
|
+
);
|
|
54
45
|
const defaultObject = {
|
|
55
46
|
enabled: false,
|
|
56
47
|
};
|
|
@@ -58,26 +49,22 @@ const getContactGroupsList = async (params: ApiParams) => {
|
|
|
58
49
|
const { page, size, fields, sort, id, q, name, type, enabled } =
|
|
59
50
|
applyTransform(params, [
|
|
60
51
|
merge(getDefaultGetParams()),
|
|
61
|
-
(
|
|
62
|
-
...params,
|
|
63
|
-
q: params.search,
|
|
64
|
-
}),
|
|
65
|
-
sanitize(fieldsToSend),
|
|
52
|
+
sanitize(listFieldsToSend),
|
|
66
53
|
camelToSnake(),
|
|
67
54
|
]);
|
|
68
55
|
|
|
69
56
|
try {
|
|
70
|
-
const response = await
|
|
57
|
+
const response = await getGroups().listGroups({
|
|
71
58
|
page,
|
|
72
59
|
size,
|
|
73
60
|
fields,
|
|
74
61
|
sort,
|
|
75
62
|
id,
|
|
76
|
-
q,
|
|
63
|
+
q: q || params.search,
|
|
77
64
|
name,
|
|
78
65
|
type,
|
|
79
66
|
enabled,
|
|
80
|
-
);
|
|
67
|
+
});
|
|
81
68
|
const { items, next } = applyTransform(response.data, [
|
|
82
69
|
merge(getDefaultGetListResponse()),
|
|
83
70
|
]);
|
|
@@ -96,13 +83,10 @@ const getContactGroupsList = async (params: ApiParams) => {
|
|
|
96
83
|
};
|
|
97
84
|
|
|
98
85
|
const getContactGroup = async ({ itemId: id }: GetItemParams) => {
|
|
99
|
-
const itemResponseHandler = (item:
|
|
86
|
+
const itemResponseHandler = (item: { group: unknown }) => item.group;
|
|
100
87
|
|
|
101
88
|
try {
|
|
102
|
-
const response = await
|
|
103
|
-
String(id),
|
|
104
|
-
fieldsToSend,
|
|
105
|
-
);
|
|
89
|
+
const response = await getGroups().locateGroup(String(id));
|
|
106
90
|
return applyTransform(response.data, [
|
|
107
91
|
snakeToCamel(),
|
|
108
92
|
itemResponseHandler,
|
|
@@ -115,14 +99,17 @@ const getContactGroup = async ({ itemId: id }: GetItemParams) => {
|
|
|
115
99
|
};
|
|
116
100
|
|
|
117
101
|
const addStaticContactGroup = async ({ itemInstance }: AddItemParams) => {
|
|
102
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(CreateGroupBody);
|
|
103
|
+
|
|
118
104
|
const item = applyTransform(itemInstance, [
|
|
119
|
-
camelToSnake(),
|
|
120
105
|
sanitize(fieldsToSend),
|
|
106
|
+
camelToSnake(),
|
|
121
107
|
]);
|
|
122
108
|
try {
|
|
123
|
-
const response = await
|
|
109
|
+
const response = await getGroups().createGroup(item);
|
|
124
110
|
return applyTransform(response.data, [
|
|
125
111
|
snakeToCamel(),
|
|
112
|
+
appendStaticType,
|
|
126
113
|
]);
|
|
127
114
|
} catch (err) {
|
|
128
115
|
throw applyTransform(err, [
|
|
@@ -135,14 +122,25 @@ const addContactsToGroups = async ({
|
|
|
135
122
|
contactIds,
|
|
136
123
|
groupIds,
|
|
137
124
|
}: {
|
|
138
|
-
contactIds:
|
|
139
|
-
groupIds:
|
|
125
|
+
contactIds: ApiId[];
|
|
126
|
+
groupIds: ApiId[];
|
|
140
127
|
}) => {
|
|
141
|
-
|
|
142
|
-
|
|
128
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
129
|
+
AddContactsToGroupsBody,
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const item = applyTransform(
|
|
133
|
+
{
|
|
143
134
|
groupIds,
|
|
144
135
|
contactIds,
|
|
145
|
-
}
|
|
136
|
+
},
|
|
137
|
+
[
|
|
138
|
+
sanitize(fieldsToSend),
|
|
139
|
+
],
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
const response = await getGroups().addContactsToGroups(item);
|
|
146
144
|
return applyTransform(response.data, [
|
|
147
145
|
snakeToCamel(),
|
|
148
146
|
]);
|
|
@@ -158,13 +156,12 @@ const removeContactsFromGroup = async ({
|
|
|
158
156
|
contactIds,
|
|
159
157
|
}: {
|
|
160
158
|
id: ApiId;
|
|
161
|
-
contactIds:
|
|
159
|
+
contactIds: ApiId[];
|
|
162
160
|
}) => {
|
|
163
161
|
try {
|
|
164
|
-
const response = await
|
|
165
|
-
String
|
|
166
|
-
|
|
167
|
-
);
|
|
162
|
+
const response = await getGroups().removeContactsFromGroup(String(id), {
|
|
163
|
+
contactIds: contactIds.map(String),
|
|
164
|
+
});
|
|
168
165
|
return applyTransform(response.data, []);
|
|
169
166
|
} catch (err) {
|
|
170
167
|
throw applyTransform(err, [
|
|
@@ -178,14 +175,15 @@ const updateStaticContactGroup = async ({
|
|
|
178
175
|
itemId: id,
|
|
179
176
|
}: UpdateItemParams) => {
|
|
180
177
|
const item = applyTransform(itemInstance, [
|
|
178
|
+
sanitize(groupFieldsToSend),
|
|
181
179
|
camelToSnake(),
|
|
182
|
-
sanitize(fieldsToSend),
|
|
183
180
|
]);
|
|
184
181
|
|
|
185
182
|
try {
|
|
186
|
-
const response = await
|
|
183
|
+
const response = await getGroups().updateGroup(String(id), item);
|
|
187
184
|
return applyTransform(response.data, [
|
|
188
185
|
snakeToCamel(),
|
|
186
|
+
appendStaticType,
|
|
189
187
|
]);
|
|
190
188
|
} catch (err) {
|
|
191
189
|
throw applyTransform(err, [
|
|
@@ -196,14 +194,15 @@ const updateStaticContactGroup = async ({
|
|
|
196
194
|
|
|
197
195
|
const patchStaticContactGroup = async ({ id, changes }: PatchItemParams) => {
|
|
198
196
|
const item = applyTransform(changes, [
|
|
197
|
+
sanitize(groupFieldsToSend),
|
|
199
198
|
camelToSnake(),
|
|
200
|
-
sanitize(fieldsToSend),
|
|
201
199
|
]);
|
|
202
200
|
|
|
203
201
|
try {
|
|
204
|
-
const response = await
|
|
202
|
+
const response = await getGroups().updateGroup2(String(id), item);
|
|
205
203
|
return applyTransform(response.data, [
|
|
206
204
|
snakeToCamel(),
|
|
205
|
+
appendStaticType,
|
|
207
206
|
]);
|
|
208
207
|
} catch (err) {
|
|
209
208
|
throw applyTransform(err, [
|
|
@@ -214,7 +213,7 @@ const patchStaticContactGroup = async ({ id, changes }: PatchItemParams) => {
|
|
|
214
213
|
|
|
215
214
|
const deleteStaticContactGroup = async ({ id }: DeleteItemParams) => {
|
|
216
215
|
try {
|
|
217
|
-
const response = await
|
|
216
|
+
const response = await getGroups().deleteGroup(String(id));
|
|
218
217
|
return applyTransform(response.data, []);
|
|
219
218
|
} catch (err) {
|
|
220
219
|
throw applyTransform(err, [
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CreateConditionBody,
|
|
3
|
+
getDynamicConditions,
|
|
4
|
+
ListConditionsQueryParams,
|
|
5
|
+
UpdateCondition2Body,
|
|
6
|
+
UpdateConditionBody,
|
|
7
|
+
} from '@webitel/api-services/gen';
|
|
8
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
9
|
+
|
|
10
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
11
|
+
import {
|
|
12
|
+
applyTransform,
|
|
13
|
+
camelToSnake,
|
|
14
|
+
merge,
|
|
15
|
+
notify,
|
|
16
|
+
sanitize,
|
|
17
|
+
snakeToCamel,
|
|
18
|
+
} from '../../transformers';
|
|
19
|
+
|
|
20
|
+
const conditionFieldsToSend =
|
|
21
|
+
getShallowFieldsToSendFromZodSchema(CreateConditionBody);
|
|
22
|
+
|
|
23
|
+
const getConditionsList = async ({
|
|
24
|
+
parentId,
|
|
25
|
+
...params
|
|
26
|
+
}: {
|
|
27
|
+
parentId: string;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}) => {
|
|
30
|
+
const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
31
|
+
ListConditionsQueryParams,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const { page, size, fields, sort, id, q } = applyTransform(params, [
|
|
35
|
+
merge(getDefaultGetParams()),
|
|
36
|
+
sanitize(listFieldsToSend),
|
|
37
|
+
camelToSnake(),
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const response = await getDynamicConditions().listConditions(parentId, {
|
|
42
|
+
page,
|
|
43
|
+
size,
|
|
44
|
+
fields,
|
|
45
|
+
sort,
|
|
46
|
+
id,
|
|
47
|
+
q: q || params.search,
|
|
48
|
+
});
|
|
49
|
+
const { items, next } = applyTransform(response.data, [
|
|
50
|
+
merge(getDefaultGetListResponse()),
|
|
51
|
+
]);
|
|
52
|
+
return {
|
|
53
|
+
items: applyTransform(items, []),
|
|
54
|
+
next,
|
|
55
|
+
};
|
|
56
|
+
} catch (err) {
|
|
57
|
+
throw applyTransform(err, [
|
|
58
|
+
notify,
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getCondition = async ({ itemId: id }: { itemId: string }) => {
|
|
64
|
+
const itemResponseHandler = (item: { condition: unknown }) => item.condition;
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const response = await getDynamicConditions().locateCondition(id, {
|
|
68
|
+
fields: conditionFieldsToSend,
|
|
69
|
+
});
|
|
70
|
+
return applyTransform(response.data, [
|
|
71
|
+
snakeToCamel(),
|
|
72
|
+
itemResponseHandler,
|
|
73
|
+
]);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
throw applyTransform(err, [
|
|
76
|
+
notify,
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const addCondition = async ({
|
|
82
|
+
itemInstance,
|
|
83
|
+
parentId,
|
|
84
|
+
}: {
|
|
85
|
+
itemInstance: Record<string, unknown>;
|
|
86
|
+
parentId: string;
|
|
87
|
+
}) => {
|
|
88
|
+
const item = applyTransform(itemInstance, [
|
|
89
|
+
sanitize(conditionFieldsToSend),
|
|
90
|
+
camelToSnake(),
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const response = await getDynamicConditions().createCondition(
|
|
95
|
+
parentId,
|
|
96
|
+
item,
|
|
97
|
+
);
|
|
98
|
+
return applyTransform(response.data, [
|
|
99
|
+
snakeToCamel(),
|
|
100
|
+
]);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
throw applyTransform(err, [
|
|
103
|
+
notify,
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const updateCondition = async ({
|
|
109
|
+
itemInstance,
|
|
110
|
+
itemId: id,
|
|
111
|
+
}: {
|
|
112
|
+
itemInstance: Record<string, unknown>;
|
|
113
|
+
itemId: string;
|
|
114
|
+
}) => {
|
|
115
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateConditionBody);
|
|
116
|
+
|
|
117
|
+
const item = applyTransform(itemInstance, [
|
|
118
|
+
sanitize(fieldsToSend),
|
|
119
|
+
camelToSnake(),
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
const response = await getDynamicConditions().updateCondition(id, item);
|
|
124
|
+
return applyTransform(response.data, [
|
|
125
|
+
snakeToCamel(),
|
|
126
|
+
]);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
throw applyTransform(err, [
|
|
129
|
+
notify,
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const patchCondition = async ({
|
|
135
|
+
changes,
|
|
136
|
+
itemId: id,
|
|
137
|
+
}: {
|
|
138
|
+
changes: Record<string, unknown>;
|
|
139
|
+
itemId: string;
|
|
140
|
+
}) => {
|
|
141
|
+
const fieldsToSend =
|
|
142
|
+
getShallowFieldsToSendFromZodSchema(UpdateCondition2Body);
|
|
143
|
+
|
|
144
|
+
const item = applyTransform(changes, [
|
|
145
|
+
sanitize(fieldsToSend),
|
|
146
|
+
camelToSnake(),
|
|
147
|
+
]);
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const response = await getDynamicConditions().updateCondition2(id, item);
|
|
151
|
+
return applyTransform(response.data, [
|
|
152
|
+
snakeToCamel(),
|
|
153
|
+
]);
|
|
154
|
+
} catch (err) {
|
|
155
|
+
throw applyTransform(err, [
|
|
156
|
+
notify,
|
|
157
|
+
]);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const deleteCondition = async ({ id }: { id: string }) => {
|
|
162
|
+
try {
|
|
163
|
+
const response = await getDynamicConditions().deleteCondition(id);
|
|
164
|
+
return applyTransform(response.data, []);
|
|
165
|
+
} catch (err) {
|
|
166
|
+
throw applyTransform(err, [
|
|
167
|
+
notify,
|
|
168
|
+
]);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export const DynamicConditionsAPI = {
|
|
173
|
+
getList: getConditionsList,
|
|
174
|
+
get: getCondition,
|
|
175
|
+
add: addCondition,
|
|
176
|
+
update: updateCondition,
|
|
177
|
+
patch: patchCondition,
|
|
178
|
+
delete: deleteCondition,
|
|
179
|
+
};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CreateDynamicGroupBody,
|
|
3
|
+
getDynamicGroups,
|
|
4
|
+
ListDynamicGroupsQueryParams,
|
|
5
|
+
UpdateDynamicGroup2Body,
|
|
6
|
+
UpdateDynamicGroupBody,
|
|
7
|
+
} from '@webitel/api-services/gen';
|
|
8
|
+
import { ContactsGroupType } from '@webitel/api-services/gen/models';
|
|
9
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
10
|
+
|
|
11
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
12
|
+
import {
|
|
13
|
+
applyTransform,
|
|
14
|
+
camelToSnake,
|
|
15
|
+
merge,
|
|
16
|
+
notify,
|
|
17
|
+
sanitize,
|
|
18
|
+
snakeToCamel,
|
|
19
|
+
} from '../../transformers';
|
|
20
|
+
|
|
21
|
+
const dynamicGroupFieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
22
|
+
UpdateDynamicGroupBody,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const appendDynamicType = (item: Record<string, unknown>) => ({
|
|
26
|
+
...item,
|
|
27
|
+
type: item.type ?? ContactsGroupType.Dynamic,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const getDynamicGroupsList = async (params: Record<string, unknown>) => {
|
|
31
|
+
const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
32
|
+
ListDynamicGroupsQueryParams,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const { page, size, fields, sort, id, q, name } = applyTransform(params, [
|
|
36
|
+
merge(getDefaultGetParams()),
|
|
37
|
+
sanitize(listFieldsToSend),
|
|
38
|
+
camelToSnake(),
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const response = await getDynamicGroups().listDynamicGroups({
|
|
43
|
+
page,
|
|
44
|
+
size,
|
|
45
|
+
fields,
|
|
46
|
+
sort,
|
|
47
|
+
id,
|
|
48
|
+
q,
|
|
49
|
+
name,
|
|
50
|
+
});
|
|
51
|
+
const { items, next } = applyTransform(response.data, [
|
|
52
|
+
merge(getDefaultGetListResponse()),
|
|
53
|
+
]);
|
|
54
|
+
return {
|
|
55
|
+
items: applyTransform(items, []),
|
|
56
|
+
next,
|
|
57
|
+
};
|
|
58
|
+
} catch (err) {
|
|
59
|
+
throw applyTransform(err, [
|
|
60
|
+
notify,
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getDynamicGroup = async ({ itemId: id }: { itemId: string }) => {
|
|
66
|
+
const itemResponseHandler = (item: { group: unknown }) => item.group;
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const response = await getDynamicGroups().locateDynamicGroup(id);
|
|
70
|
+
return applyTransform(response.data, [
|
|
71
|
+
snakeToCamel(),
|
|
72
|
+
itemResponseHandler,
|
|
73
|
+
appendDynamicType,
|
|
74
|
+
]);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
throw applyTransform(err, [
|
|
77
|
+
notify,
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const addDynamicGroup = async ({
|
|
83
|
+
itemInstance,
|
|
84
|
+
}: {
|
|
85
|
+
itemInstance: Record<string, unknown>;
|
|
86
|
+
}) => {
|
|
87
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
88
|
+
CreateDynamicGroupBody,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const item = applyTransform(itemInstance, [
|
|
92
|
+
sanitize(fieldsToSend),
|
|
93
|
+
camelToSnake(),
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
const response = await getDynamicGroups().createDynamicGroup(item);
|
|
98
|
+
return applyTransform(response.data, [
|
|
99
|
+
snakeToCamel(),
|
|
100
|
+
appendDynamicType,
|
|
101
|
+
]);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
throw applyTransform(err, [
|
|
104
|
+
notify,
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const updateDynamicGroup = async ({
|
|
110
|
+
itemInstance,
|
|
111
|
+
itemId: id,
|
|
112
|
+
}: {
|
|
113
|
+
itemInstance: Record<string, unknown>;
|
|
114
|
+
itemId: string;
|
|
115
|
+
}) => {
|
|
116
|
+
const item = applyTransform(itemInstance, [
|
|
117
|
+
sanitize(dynamicGroupFieldsToSend),
|
|
118
|
+
camelToSnake(),
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
const response = await getDynamicGroups().updateDynamicGroup(id, item);
|
|
123
|
+
return applyTransform(response.data, [
|
|
124
|
+
snakeToCamel(),
|
|
125
|
+
appendDynamicType,
|
|
126
|
+
]);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
throw applyTransform(err, [
|
|
129
|
+
notify,
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const patchDynamicGroup = async ({
|
|
135
|
+
changes,
|
|
136
|
+
itemId: id,
|
|
137
|
+
}: {
|
|
138
|
+
changes: Record<string, unknown>;
|
|
139
|
+
itemId: string;
|
|
140
|
+
}) => {
|
|
141
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
142
|
+
UpdateDynamicGroup2Body,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const item = applyTransform(changes, [
|
|
146
|
+
sanitize(fieldsToSend),
|
|
147
|
+
camelToSnake(),
|
|
148
|
+
]);
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
const response = await getDynamicGroups().updateDynamicGroup2(id, item);
|
|
152
|
+
return applyTransform(response.data, [
|
|
153
|
+
snakeToCamel(),
|
|
154
|
+
appendDynamicType,
|
|
155
|
+
]);
|
|
156
|
+
} catch (err) {
|
|
157
|
+
throw applyTransform(err, [
|
|
158
|
+
notify,
|
|
159
|
+
]);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const deleteDynamicGroup = async ({ id }: { id: string }) => {
|
|
164
|
+
try {
|
|
165
|
+
const response = await getDynamicGroups().deleteDynamicGroup(id);
|
|
166
|
+
return applyTransform(response.data, []);
|
|
167
|
+
} catch (err) {
|
|
168
|
+
throw applyTransform(err, [
|
|
169
|
+
notify,
|
|
170
|
+
]);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const getLookup = (params: Record<string, unknown>) =>
|
|
175
|
+
getDynamicGroupsList({
|
|
176
|
+
...params,
|
|
177
|
+
fields: params.fields || [
|
|
178
|
+
'id',
|
|
179
|
+
'name',
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
export const DynamicGroupsAPI = {
|
|
184
|
+
getList: getDynamicGroupsList,
|
|
185
|
+
get: getDynamicGroup,
|
|
186
|
+
add: addDynamicGroup,
|
|
187
|
+
update: updateDynamicGroup,
|
|
188
|
+
patch: patchDynamicGroup,
|
|
189
|
+
delete: deleteDynamicGroup,
|
|
190
|
+
getLookup,
|
|
191
|
+
};
|
package/src/api/clients/index.ts
CHANGED
|
@@ -20,6 +20,8 @@ export * from './chatGateways/chatGateways';
|
|
|
20
20
|
export * from './communications/communications';
|
|
21
21
|
export * from './configurations/configurations';
|
|
22
22
|
export * from './contactGroups/contactGroups';
|
|
23
|
+
export * from './dynamicConditions/dynamicConditions';
|
|
24
|
+
export * from './dynamicGroups/dynamicGroups';
|
|
23
25
|
export * from './emails/emails';
|
|
24
26
|
export * from './fileServices/fileServices';
|
|
25
27
|
export * from './flows/flow';
|