@webitel/api-services 1.0.6 → 1.0.8
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 +2 -1
- package/src/api/clients/calendars/__tests__/calendars.spec.ts +71 -0
- package/src/api/clients/calendars/calendars.ts +2 -2
- package/src/api/clients/caseComments/caseComments.ts +141 -0
- package/src/api/clients/caseFiles/caseFiles.ts +79 -0
- package/src/api/clients/caseLinks/caseLinks.ts +150 -0
- package/src/api/clients/caseRelatedCases/caseRelatedCases.ts +125 -0
- package/src/api/clients/caseServices/services.ts +38 -72
- package/src/api/clients/cases/_internals/ftsService.ts +67 -0
- package/src/api/clients/cases/_internals/stringifyCaseFilters.ts +156 -0
- package/src/api/clients/cases/cases.ts +360 -0
- package/src/api/clients/chatMessagesHistory/chatMessagesHistory.ts +64 -0
- package/src/api/clients/configurations/configurations.ts +56 -39
- package/src/api/clients/contactCases/contactCases.ts +109 -0
- package/src/api/clients/emails/emails.ts +11 -7
- package/src/api/clients/index.ts +9 -0
- package/src/api/clients/labels/labels.ts +24 -29
- package/src/api/clients/phones/phones.ts +11 -7
- package/src/api/clients/timeline/timeline.ts +124 -0
- package/src/api/clients/variables/variables.ts +10 -5
- package/src/api/clients/wtTypes/_shared/utils/assignFieldPositions.ts +28 -0
- package/src/api/clients/wtTypes/_shared/utils/sortDynamicFields.ts +7 -9
- package/src/api/clients/wtTypes/adjunctTypeRecords/adjunctTypeRecords.ts +19 -16
- package/src/api/clients/wtTypes/adjunctTypes/adjunctTypes.ts +4 -0
- package/src/api/clients/wtTypes/typeExtensions/typeExtensions.ts +21 -31
- package/src/api/clients//321/201ontacts/contacts.ts +103 -234
- package/src/api/clients//321/201ontacts/getContactAccessFromMode.ts +9 -0
- package/src/api/clients//321/201ontacts/index.ts +1 -1
- package/src/validations/adjunctType/adjunctType.validations.ts +18 -0
- package/src/validations/case/case.validations.ts +33 -0
- package/src/validations/caseClose/caseClose.validations.ts +30 -0
- package/src/validations/caseExportOptions/caseExportOptions.validations.ts +27 -0
- package/src/validations/contact/contact.validations.ts +12 -7
- package/src/validations/index.ts +5 -0
- package/src/validations/typeExtension/typeExtension.validations.ts +8 -0
- package/types/.tsbuildinfo +1 -1
- package/types/api/clients/caseComments/caseComments.d.ts +20 -0
- package/types/api/clients/caseFiles/caseFiles.d.ts +10 -0
- package/types/api/clients/caseLinks/caseLinks.d.ts +22 -0
- package/types/api/clients/caseRelatedCases/caseRelatedCases.d.ts +14 -0
- package/types/api/clients/caseServices/services.d.ts +3 -12
- package/types/api/clients/cases/_internals/ftsService.d.ts +7 -0
- package/types/api/clients/cases/_internals/stringifyCaseFilters.d.ts +2 -0
- package/types/api/clients/cases/cases.d.ts +35 -0
- package/types/api/clients/chatMessagesHistory/chatMessagesHistory.d.ts +15 -0
- package/types/api/clients/contactCases/contactCases.d.ts +9 -0
- package/types/api/clients/index.d.ts +9 -0
- package/types/api/clients/labels/labels.d.ts +2 -2
- package/types/api/clients/timeline/timeline.d.ts +16 -0
- package/types/api/clients/wtTypes/_shared/utils/assignFieldPositions.d.ts +2 -0
- package/types/api/clients/wtTypes/_shared/utils/sortDynamicFields.d.ts +2 -2
- package/types/api/clients/wtTypes/adjunctTypeRecords/adjunctTypeRecords.d.ts +11 -11
- package/types/api/clients/wtTypes/typeExtensions/typeExtensions.d.ts +1 -1
- package/types/api/clients//321/201ontacts/getContactAccessFromMode.d.ts +5 -0
- package/types/api/clients//321/201ontacts/index.d.ts +1 -1
- package/types/validations/adjunctType/adjunctType.validations.d.ts +11 -0
- package/types/validations/case/case.validations.d.ts +31 -0
- package/types/validations/caseClose/caseClose.validations.d.ts +8 -0
- package/types/validations/caseExportOptions/caseExportOptions.validations.d.ts +9 -0
- package/types/validations/contact/contact.validations.d.ts +15 -15
- package/types/validations/index.d.ts +5 -0
- package/types/validations/typeExtension/typeExtension.validations.d.ts +20 -0
- package/src/api/clients//321/201ontacts/types/ContactEntity.types.ts +0 -25
- package/types/api/clients//321/201ontacts/types/ContactEntity.types.d.ts +0 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webitel/api-services",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"@faker-js/faker": "^9.7.0",
|
|
74
|
+
"date-fns": "^4.1.0",
|
|
74
75
|
"lodash-es": "^4.17.21",
|
|
75
76
|
"msw": "^2.8.2",
|
|
76
77
|
"qs-esm": "^7.0.2"
|
|
@@ -262,6 +262,77 @@ describe('CalendarsAPI', () => {
|
|
|
262
262
|
});
|
|
263
263
|
});
|
|
264
264
|
|
|
265
|
+
it('treats omitted work_start on a working except as midnight (protobuf omits 0)', async () => {
|
|
266
|
+
mockCalendarService.readCalendar.mockResolvedValueOnce({
|
|
267
|
+
data: {
|
|
268
|
+
name: 'Cal',
|
|
269
|
+
timezone: {
|
|
270
|
+
id: 'tz-1',
|
|
271
|
+
},
|
|
272
|
+
excepts: [
|
|
273
|
+
{
|
|
274
|
+
name: 'ff',
|
|
275
|
+
date: 123,
|
|
276
|
+
repeat: true,
|
|
277
|
+
working: true,
|
|
278
|
+
work_stop: 1200,
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
const result = await CalendarsAPI.get({
|
|
285
|
+
itemId: 1,
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
expect(result.excepts).toEqual([
|
|
289
|
+
{
|
|
290
|
+
name: 'ff',
|
|
291
|
+
date: 123,
|
|
292
|
+
repeat: true,
|
|
293
|
+
working: true,
|
|
294
|
+
workStart: 0,
|
|
295
|
+
workStop: 1200,
|
|
296
|
+
},
|
|
297
|
+
]);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('keeps midnight (0) holiday workStart/workStop instead of coercing to null', async () => {
|
|
301
|
+
mockCalendarService.readCalendar.mockResolvedValueOnce({
|
|
302
|
+
data: {
|
|
303
|
+
name: 'Cal',
|
|
304
|
+
timezone: {
|
|
305
|
+
id: 'tz-1',
|
|
306
|
+
},
|
|
307
|
+
excepts: [
|
|
308
|
+
{
|
|
309
|
+
name: 'holiday',
|
|
310
|
+
date: 123,
|
|
311
|
+
repeat: true,
|
|
312
|
+
working: true,
|
|
313
|
+
work_start: 0,
|
|
314
|
+
work_stop: 60,
|
|
315
|
+
},
|
|
316
|
+
],
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
const result = await CalendarsAPI.get({
|
|
321
|
+
itemId: 1,
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
expect(result.excepts).toEqual([
|
|
325
|
+
{
|
|
326
|
+
name: 'holiday',
|
|
327
|
+
date: 123,
|
|
328
|
+
repeat: true,
|
|
329
|
+
working: true,
|
|
330
|
+
workStart: 0,
|
|
331
|
+
workStop: 60,
|
|
332
|
+
},
|
|
333
|
+
]);
|
|
334
|
+
});
|
|
335
|
+
|
|
265
336
|
it('defaults accepts to an empty array instead of throwing when missing', async () => {
|
|
266
337
|
mockCalendarService.readCalendar.mockResolvedValueOnce({
|
|
267
338
|
data: {
|
|
@@ -55,8 +55,8 @@ const mapCalendarToUi = (item: ApiParams) => {
|
|
|
55
55
|
date: except.date || 0,
|
|
56
56
|
repeat: except.repeat || false,
|
|
57
57
|
working: except.working || false,
|
|
58
|
-
workStart: except.workStart
|
|
59
|
-
workStop: except.workStop
|
|
58
|
+
workStart: except.workStart ?? (except.working ? 0 : null),
|
|
59
|
+
workStop: except.workStop ?? (except.working ? 0 : null),
|
|
60
60
|
}));
|
|
61
61
|
}
|
|
62
62
|
return {
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import {
|
|
3
|
+
getCaseComments,
|
|
4
|
+
ListCommentsQueryParams,
|
|
5
|
+
UpdateComment2Body,
|
|
6
|
+
} from '../../../gen-wire';
|
|
7
|
+
|
|
8
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
9
|
+
import {
|
|
10
|
+
applyTransform,
|
|
11
|
+
camelToSnake,
|
|
12
|
+
merge,
|
|
13
|
+
notify,
|
|
14
|
+
sanitizeToWire,
|
|
15
|
+
snakeToCamel,
|
|
16
|
+
starToSearch,
|
|
17
|
+
} from '../../transformers';
|
|
18
|
+
import type { ApiId, ApiParams } from '../_shared/types';
|
|
19
|
+
|
|
20
|
+
const getCommentsList = async ({
|
|
21
|
+
parentId,
|
|
22
|
+
...rest
|
|
23
|
+
}: {
|
|
24
|
+
parentId: ApiId;
|
|
25
|
+
} & ApiParams) => {
|
|
26
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
27
|
+
ListCommentsQueryParams,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const { page, size, q, ids, sort } = applyTransform(rest, [
|
|
31
|
+
merge(getDefaultGetParams()),
|
|
32
|
+
starToSearch('search'),
|
|
33
|
+
(params) => ({
|
|
34
|
+
...params,
|
|
35
|
+
q: params.search,
|
|
36
|
+
}),
|
|
37
|
+
sanitizeToWire(fieldsToSend),
|
|
38
|
+
camelToSnake(),
|
|
39
|
+
]);
|
|
40
|
+
try {
|
|
41
|
+
const response = await getCaseComments().listComments(String(parentId), {
|
|
42
|
+
page,
|
|
43
|
+
size,
|
|
44
|
+
q,
|
|
45
|
+
ids,
|
|
46
|
+
sort,
|
|
47
|
+
fields: [
|
|
48
|
+
'id',
|
|
49
|
+
'etag',
|
|
50
|
+
'text',
|
|
51
|
+
'created_at',
|
|
52
|
+
'updated_at',
|
|
53
|
+
'created_by',
|
|
54
|
+
'author',
|
|
55
|
+
'can_edit',
|
|
56
|
+
'edited',
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const { items, next } = applyTransform(response.data, [
|
|
61
|
+
merge(getDefaultGetListResponse()),
|
|
62
|
+
]);
|
|
63
|
+
return {
|
|
64
|
+
items: applyTransform(items, [
|
|
65
|
+
snakeToCamel(),
|
|
66
|
+
]),
|
|
67
|
+
next,
|
|
68
|
+
};
|
|
69
|
+
} catch (err) {
|
|
70
|
+
throw applyTransform(err, [
|
|
71
|
+
notify,
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const addComment = async ({
|
|
77
|
+
parentId,
|
|
78
|
+
input,
|
|
79
|
+
}: {
|
|
80
|
+
parentId: ApiId;
|
|
81
|
+
input: ApiParams;
|
|
82
|
+
}) => {
|
|
83
|
+
try {
|
|
84
|
+
const response = await getCaseComments().publishComment(
|
|
85
|
+
String(parentId),
|
|
86
|
+
input,
|
|
87
|
+
);
|
|
88
|
+
return applyTransform(response.data, [
|
|
89
|
+
snakeToCamel(),
|
|
90
|
+
]);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
throw applyTransform(err, [
|
|
93
|
+
notify,
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const patchComment = async ({
|
|
99
|
+
commentId,
|
|
100
|
+
changes,
|
|
101
|
+
}: {
|
|
102
|
+
commentId: ApiId;
|
|
103
|
+
changes: ApiParams;
|
|
104
|
+
}) => {
|
|
105
|
+
const body = applyTransform(changes, [
|
|
106
|
+
sanitizeToWire(getShallowFieldsToSendFromZodSchema(UpdateComment2Body)),
|
|
107
|
+
camelToSnake(),
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const response = await getCaseComments().updateComment2(
|
|
112
|
+
String(commentId),
|
|
113
|
+
body,
|
|
114
|
+
);
|
|
115
|
+
return applyTransform(response.data, [
|
|
116
|
+
snakeToCamel(),
|
|
117
|
+
]);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
throw applyTransform(err, [
|
|
120
|
+
notify,
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const deleteComment = async ({ etag }: { etag: ApiId }) => {
|
|
126
|
+
try {
|
|
127
|
+
const response = await getCaseComments().deleteComment(String(etag));
|
|
128
|
+
return applyTransform(response.data, []);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
throw applyTransform(err, [
|
|
131
|
+
notify,
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const CommentsAPI = {
|
|
137
|
+
getList: getCommentsList,
|
|
138
|
+
delete: deleteComment,
|
|
139
|
+
add: addComment,
|
|
140
|
+
patch: patchComment,
|
|
141
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import { getCaseFiles, ListFilesQueryParams } from '../../../gen-wire';
|
|
3
|
+
|
|
4
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
5
|
+
import {
|
|
6
|
+
applyTransform,
|
|
7
|
+
camelToSnake,
|
|
8
|
+
merge,
|
|
9
|
+
notify,
|
|
10
|
+
sanitizeToWire,
|
|
11
|
+
snakeToCamel,
|
|
12
|
+
starToSearch,
|
|
13
|
+
} from '../../transformers';
|
|
14
|
+
import type {
|
|
15
|
+
ApiId,
|
|
16
|
+
ApiParams,
|
|
17
|
+
NestedDeleteItemParams,
|
|
18
|
+
} from '../_shared/types';
|
|
19
|
+
|
|
20
|
+
const getFilesList = async ({
|
|
21
|
+
parentId,
|
|
22
|
+
...rest
|
|
23
|
+
}: {
|
|
24
|
+
parentId: ApiId;
|
|
25
|
+
} & ApiParams) => {
|
|
26
|
+
const fieldsToSend =
|
|
27
|
+
getShallowFieldsToSendFromZodSchema(ListFilesQueryParams);
|
|
28
|
+
|
|
29
|
+
const { page, size, q } = applyTransform(rest, [
|
|
30
|
+
merge(getDefaultGetParams()),
|
|
31
|
+
starToSearch('search'),
|
|
32
|
+
(params) => ({
|
|
33
|
+
...params,
|
|
34
|
+
q: params.search,
|
|
35
|
+
}),
|
|
36
|
+
sanitizeToWire(fieldsToSend),
|
|
37
|
+
camelToSnake(),
|
|
38
|
+
]);
|
|
39
|
+
try {
|
|
40
|
+
const response = await getCaseFiles().listFiles(String(parentId), {
|
|
41
|
+
page,
|
|
42
|
+
size,
|
|
43
|
+
q,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const { items, next } = applyTransform(response.data, [
|
|
47
|
+
merge(getDefaultGetListResponse()),
|
|
48
|
+
]);
|
|
49
|
+
return {
|
|
50
|
+
items: applyTransform(items, [
|
|
51
|
+
snakeToCamel(),
|
|
52
|
+
]),
|
|
53
|
+
next,
|
|
54
|
+
};
|
|
55
|
+
} catch (err) {
|
|
56
|
+
throw applyTransform(err, [
|
|
57
|
+
notify,
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const deleteFile = async ({ parentId, id }: NestedDeleteItemParams) => {
|
|
63
|
+
try {
|
|
64
|
+
const response = await getCaseFiles().deleteFile(
|
|
65
|
+
String(parentId),
|
|
66
|
+
String(id),
|
|
67
|
+
);
|
|
68
|
+
return applyTransform(response.data, []);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
throw applyTransform(err, [
|
|
71
|
+
notify,
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const CaseFilesAPI = {
|
|
77
|
+
getList: getFilesList,
|
|
78
|
+
delete: deleteFile,
|
|
79
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import {
|
|
3
|
+
CreateLinkParams,
|
|
4
|
+
getCaseLinks,
|
|
5
|
+
ListLinksQueryParams,
|
|
6
|
+
UpdateLink2Body,
|
|
7
|
+
} from '../../../gen-wire';
|
|
8
|
+
|
|
9
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
10
|
+
import {
|
|
11
|
+
applyTransform,
|
|
12
|
+
camelToSnake,
|
|
13
|
+
merge,
|
|
14
|
+
notify,
|
|
15
|
+
sanitizeToWire,
|
|
16
|
+
snakeToCamel,
|
|
17
|
+
starToSearch,
|
|
18
|
+
} from '../../transformers';
|
|
19
|
+
import type { ApiId, ApiParams } from '../_shared/types';
|
|
20
|
+
|
|
21
|
+
const getLinksList = async ({
|
|
22
|
+
parentId,
|
|
23
|
+
...rest
|
|
24
|
+
}: {
|
|
25
|
+
parentId: ApiId;
|
|
26
|
+
} & ApiParams) => {
|
|
27
|
+
const fieldsToSend =
|
|
28
|
+
getShallowFieldsToSendFromZodSchema(ListLinksQueryParams);
|
|
29
|
+
|
|
30
|
+
const { page, size, q } = applyTransform(rest, [
|
|
31
|
+
merge(getDefaultGetParams()),
|
|
32
|
+
starToSearch('search'),
|
|
33
|
+
(params) => ({
|
|
34
|
+
...params,
|
|
35
|
+
q: params.search,
|
|
36
|
+
}),
|
|
37
|
+
sanitizeToWire(fieldsToSend),
|
|
38
|
+
camelToSnake(),
|
|
39
|
+
]);
|
|
40
|
+
try {
|
|
41
|
+
const response = await getCaseLinks().listLinks(String(parentId), {
|
|
42
|
+
page,
|
|
43
|
+
size,
|
|
44
|
+
q,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const { items, next } = applyTransform(response.data, [
|
|
48
|
+
merge(getDefaultGetListResponse()),
|
|
49
|
+
]);
|
|
50
|
+
return {
|
|
51
|
+
items: applyTransform(items, [
|
|
52
|
+
snakeToCamel(),
|
|
53
|
+
]),
|
|
54
|
+
next,
|
|
55
|
+
};
|
|
56
|
+
} catch (err) {
|
|
57
|
+
throw applyTransform(err, [
|
|
58
|
+
notify,
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const createLinkFieldsToSend =
|
|
64
|
+
getShallowFieldsToSendFromZodSchema(CreateLinkParams);
|
|
65
|
+
|
|
66
|
+
const addLink = async ({
|
|
67
|
+
parentId,
|
|
68
|
+
input,
|
|
69
|
+
}: {
|
|
70
|
+
parentId: ApiId;
|
|
71
|
+
input: ApiParams;
|
|
72
|
+
}) => {
|
|
73
|
+
const params = applyTransform(
|
|
74
|
+
{
|
|
75
|
+
inputUrl: input.url,
|
|
76
|
+
inputName: input.name,
|
|
77
|
+
},
|
|
78
|
+
[
|
|
79
|
+
sanitizeToWire(createLinkFieldsToSend),
|
|
80
|
+
],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const response = await getCaseLinks().createLink(String(parentId), params);
|
|
85
|
+
return applyTransform(response.data, [
|
|
86
|
+
snakeToCamel(),
|
|
87
|
+
]);
|
|
88
|
+
} catch (err) {
|
|
89
|
+
throw applyTransform(err, [
|
|
90
|
+
notify,
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const patchLink = async ({
|
|
96
|
+
parentId,
|
|
97
|
+
linkId,
|
|
98
|
+
changes,
|
|
99
|
+
}: {
|
|
100
|
+
parentId: ApiId;
|
|
101
|
+
linkId: ApiId;
|
|
102
|
+
changes: ApiParams;
|
|
103
|
+
}) => {
|
|
104
|
+
const body = applyTransform(changes, [
|
|
105
|
+
sanitizeToWire(getShallowFieldsToSendFromZodSchema(UpdateLink2Body)),
|
|
106
|
+
camelToSnake(),
|
|
107
|
+
]);
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const response = await getCaseLinks().updateLink2(
|
|
111
|
+
String(parentId),
|
|
112
|
+
String(linkId),
|
|
113
|
+
body,
|
|
114
|
+
);
|
|
115
|
+
return applyTransform(response.data, [
|
|
116
|
+
snakeToCamel(),
|
|
117
|
+
]);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
throw applyTransform(err, [
|
|
120
|
+
notify,
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const deleteLink = async ({
|
|
126
|
+
parentId,
|
|
127
|
+
etag,
|
|
128
|
+
}: {
|
|
129
|
+
parentId: ApiId;
|
|
130
|
+
etag: ApiId;
|
|
131
|
+
}) => {
|
|
132
|
+
try {
|
|
133
|
+
const response = await getCaseLinks().deleteLink(
|
|
134
|
+
String(parentId),
|
|
135
|
+
String(etag),
|
|
136
|
+
);
|
|
137
|
+
return applyTransform(response.data, []);
|
|
138
|
+
} catch (err) {
|
|
139
|
+
throw applyTransform(err, [
|
|
140
|
+
notify,
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export const CaseLinksAPI = {
|
|
146
|
+
getList: getLinksList,
|
|
147
|
+
delete: deleteLink,
|
|
148
|
+
add: addLink,
|
|
149
|
+
patch: patchLink,
|
|
150
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import {
|
|
3
|
+
getRelatedCases,
|
|
4
|
+
ListRelatedCasesQueryParams,
|
|
5
|
+
} from '../../../gen-wire';
|
|
6
|
+
|
|
7
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
8
|
+
import {
|
|
9
|
+
applyTransform,
|
|
10
|
+
camelToSnake,
|
|
11
|
+
merge,
|
|
12
|
+
notify,
|
|
13
|
+
sanitizeToWire,
|
|
14
|
+
snakeToCamel,
|
|
15
|
+
starToSearch,
|
|
16
|
+
} from '../../transformers';
|
|
17
|
+
import type {
|
|
18
|
+
ApiId,
|
|
19
|
+
ApiParams,
|
|
20
|
+
NestedDeleteItemParams,
|
|
21
|
+
} from '../_shared/types';
|
|
22
|
+
|
|
23
|
+
const getRelatedCasesList = async ({
|
|
24
|
+
parentId,
|
|
25
|
+
...rest
|
|
26
|
+
}: {
|
|
27
|
+
parentId: ApiId;
|
|
28
|
+
} & ApiParams) => {
|
|
29
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
30
|
+
ListRelatedCasesQueryParams,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const { page, size, q, ids, sort, fields } = applyTransform(rest, [
|
|
34
|
+
merge(getDefaultGetParams()),
|
|
35
|
+
starToSearch('search'),
|
|
36
|
+
(params) => ({
|
|
37
|
+
...params,
|
|
38
|
+
q: params.search,
|
|
39
|
+
fields: [
|
|
40
|
+
...(params.fields || []),
|
|
41
|
+
'primary_case',
|
|
42
|
+
'id',
|
|
43
|
+
],
|
|
44
|
+
}),
|
|
45
|
+
sanitizeToWire(fieldsToSend),
|
|
46
|
+
camelToSnake(),
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const response = await getRelatedCases().listRelatedCases(
|
|
51
|
+
String(parentId),
|
|
52
|
+
{
|
|
53
|
+
page,
|
|
54
|
+
size,
|
|
55
|
+
q,
|
|
56
|
+
sort,
|
|
57
|
+
fields,
|
|
58
|
+
ids,
|
|
59
|
+
},
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const { items, next } = applyTransform(
|
|
63
|
+
{
|
|
64
|
+
...response.data,
|
|
65
|
+
items: response.data?.data || [],
|
|
66
|
+
},
|
|
67
|
+
[
|
|
68
|
+
merge(getDefaultGetListResponse()),
|
|
69
|
+
],
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
items: applyTransform(items, [
|
|
74
|
+
snakeToCamel(),
|
|
75
|
+
]),
|
|
76
|
+
next,
|
|
77
|
+
};
|
|
78
|
+
} catch (err) {
|
|
79
|
+
throw applyTransform(err, [
|
|
80
|
+
notify,
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const addRelatedCase = async ({
|
|
86
|
+
parentId,
|
|
87
|
+
input,
|
|
88
|
+
}: {
|
|
89
|
+
parentId: ApiId;
|
|
90
|
+
input: ApiParams;
|
|
91
|
+
}) => {
|
|
92
|
+
try {
|
|
93
|
+
const response = await getRelatedCases().createRelatedCase(
|
|
94
|
+
String(parentId),
|
|
95
|
+
input,
|
|
96
|
+
);
|
|
97
|
+
return applyTransform(response.data, [
|
|
98
|
+
snakeToCamel(),
|
|
99
|
+
]);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
throw applyTransform(err, [
|
|
102
|
+
notify,
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const deleteRelatedCase = async ({ parentId, id }: NestedDeleteItemParams) => {
|
|
108
|
+
try {
|
|
109
|
+
const response = await getRelatedCases().deleteRelatedCase(
|
|
110
|
+
String(parentId),
|
|
111
|
+
String(id),
|
|
112
|
+
);
|
|
113
|
+
return applyTransform(response.data, []);
|
|
114
|
+
} catch (err) {
|
|
115
|
+
throw applyTransform(err, [
|
|
116
|
+
notify,
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const RelatedCasesAPI = {
|
|
122
|
+
getList: getRelatedCasesList,
|
|
123
|
+
delete: deleteRelatedCase,
|
|
124
|
+
add: addRelatedCase,
|
|
125
|
+
};
|