@webitel/api-services 1.0.6 → 1.0.7
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/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.7",
|
|
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"
|
|
@@ -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
|
+
};
|
|
@@ -19,13 +19,29 @@ import {
|
|
|
19
19
|
starToSearch,
|
|
20
20
|
} from '../../transformers';
|
|
21
21
|
import type {
|
|
22
|
+
AddItemParams,
|
|
22
23
|
ApiId,
|
|
23
24
|
ApiParams,
|
|
24
25
|
DeleteItemParams,
|
|
25
26
|
GetItemParams,
|
|
26
27
|
PatchItemParams,
|
|
28
|
+
UpdateItemParams,
|
|
27
29
|
} from '../_shared/types';
|
|
28
30
|
|
|
31
|
+
const preRequestHandler = (item: ApiParams) => {
|
|
32
|
+
return {
|
|
33
|
+
...item,
|
|
34
|
+
state: item.state ?? true,
|
|
35
|
+
sla_id: item.sla?.id,
|
|
36
|
+
status_id: item.status?.id,
|
|
37
|
+
close_reason_id: item.closeReason?.id,
|
|
38
|
+
team_ids: item.teams?.map((team: ApiParams) => team.id),
|
|
39
|
+
skill_ids: item.skills?.map((skill: ApiParams) => skill.id),
|
|
40
|
+
assignee:
|
|
41
|
+
item.group?.type === ContactsGroupType.Dynamic ? {} : item.assignee,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
29
45
|
const getServicesList = async ({
|
|
30
46
|
parentId,
|
|
31
47
|
rootId,
|
|
@@ -34,7 +50,7 @@ const getServicesList = async ({
|
|
|
34
50
|
parentId?: ApiId;
|
|
35
51
|
rootId: ApiId;
|
|
36
52
|
} & ApiParams) => {
|
|
37
|
-
const
|
|
53
|
+
const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
38
54
|
ListServicesQueryParams,
|
|
39
55
|
);
|
|
40
56
|
|
|
@@ -45,7 +61,7 @@ const getServicesList = async ({
|
|
|
45
61
|
...params,
|
|
46
62
|
q: params.search,
|
|
47
63
|
}),
|
|
48
|
-
sanitizeToWire(
|
|
64
|
+
sanitizeToWire(listFieldsToSend),
|
|
49
65
|
camelToSnake(),
|
|
50
66
|
]);
|
|
51
67
|
|
|
@@ -53,11 +69,11 @@ const getServicesList = async ({
|
|
|
53
69
|
const response = await getServices().listServices({
|
|
54
70
|
page,
|
|
55
71
|
size,
|
|
56
|
-
fields,
|
|
57
72
|
sort,
|
|
58
73
|
id,
|
|
59
74
|
q,
|
|
60
75
|
root_id: String(rootId ?? parentId),
|
|
76
|
+
fields,
|
|
61
77
|
});
|
|
62
78
|
const { items, next } = applyTransform(response.data, [
|
|
63
79
|
merge(getDefaultGetListResponse()),
|
|
@@ -75,26 +91,15 @@ const getServicesList = async ({
|
|
|
75
91
|
}
|
|
76
92
|
};
|
|
77
93
|
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
'name',
|
|
81
|
-
'code',
|
|
82
|
-
'sla',
|
|
83
|
-
'state',
|
|
84
|
-
'prefix',
|
|
85
|
-
'group',
|
|
86
|
-
'assignee',
|
|
87
|
-
'description',
|
|
88
|
-
'default_priority',
|
|
89
|
-
'catalog_id',
|
|
90
|
-
'root_id',
|
|
91
|
-
];
|
|
94
|
+
const serviceFieldsToSend =
|
|
95
|
+
getShallowFieldsToSendFromZodSchema(CreateServiceBody);
|
|
92
96
|
|
|
97
|
+
const getService = async ({ itemId: id }: GetItemParams) => {
|
|
93
98
|
const itemResponseHandler = (item: ApiParams) => item.service;
|
|
94
99
|
|
|
95
100
|
try {
|
|
96
101
|
const response = await getServices().locateService(String(id), {
|
|
97
|
-
fields:
|
|
102
|
+
fields: serviceFieldsToSend,
|
|
98
103
|
});
|
|
99
104
|
return applyTransform(response.data, [
|
|
100
105
|
snakeToCamel(),
|
|
@@ -107,42 +112,14 @@ const getService = async ({ itemId: id }: GetItemParams) => {
|
|
|
107
112
|
}
|
|
108
113
|
};
|
|
109
114
|
|
|
110
|
-
const
|
|
111
|
-
rootId,
|
|
112
|
-
catalogId,
|
|
113
|
-
}: {
|
|
114
|
-
rootId: ApiId;
|
|
115
|
-
catalogId: ApiId;
|
|
116
|
-
}) => {
|
|
117
|
-
return (item: ApiParams) => ({
|
|
118
|
-
...item,
|
|
119
|
-
assignee:
|
|
120
|
-
item.group?.type === ContactsGroupType.Dynamic ? {} : item.assignee,
|
|
121
|
-
rootId: rootId ?? item.rootId,
|
|
122
|
-
catalogId: catalogId ?? item.catalogId,
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const addService = async ({
|
|
127
|
-
itemInstance,
|
|
128
|
-
rootId,
|
|
129
|
-
catalogId,
|
|
130
|
-
}: {
|
|
131
|
-
itemInstance: ApiParams;
|
|
132
|
-
rootId: ApiId;
|
|
133
|
-
catalogId: ApiId;
|
|
134
|
-
}) => {
|
|
135
|
-
const fieldsToSend = getShallowFieldsToSendFromZodSchema(CreateServiceBody);
|
|
115
|
+
const addFieldsToSend = getShallowFieldsToSendFromZodSchema(CreateServiceBody);
|
|
136
116
|
|
|
117
|
+
const addService = async ({ itemInstance }: AddItemParams) => {
|
|
137
118
|
const item = applyTransform(itemInstance, [
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
catalogId,
|
|
141
|
-
}),
|
|
142
|
-
sanitizeToWire(fieldsToSend),
|
|
119
|
+
sanitizeToWire(addFieldsToSend),
|
|
120
|
+
preRequestHandler,
|
|
143
121
|
camelToSnake(),
|
|
144
122
|
]);
|
|
145
|
-
|
|
146
123
|
try {
|
|
147
124
|
const response = await getServices().createService(item);
|
|
148
125
|
return applyTransform(response.data, [
|
|
@@ -155,28 +132,18 @@ const addService = async ({
|
|
|
155
132
|
}
|
|
156
133
|
};
|
|
157
134
|
|
|
135
|
+
const updateFieldsToSend =
|
|
136
|
+
getShallowFieldsToSendFromZodSchema(UpdateServiceBody);
|
|
137
|
+
|
|
158
138
|
const updateService = async ({
|
|
159
139
|
itemInstance,
|
|
160
140
|
itemId: id,
|
|
161
|
-
|
|
162
|
-
catalogId,
|
|
163
|
-
}: {
|
|
164
|
-
itemInstance: ApiParams;
|
|
165
|
-
itemId: ApiId;
|
|
166
|
-
rootId: ApiId;
|
|
167
|
-
catalogId: ApiId;
|
|
168
|
-
}) => {
|
|
169
|
-
const fieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateServiceBody);
|
|
170
|
-
|
|
141
|
+
}: UpdateItemParams) => {
|
|
171
142
|
const item = applyTransform(itemInstance, [
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
catalogId,
|
|
175
|
-
}),
|
|
176
|
-
sanitizeToWire(fieldsToSend),
|
|
143
|
+
sanitizeToWire(updateFieldsToSend),
|
|
144
|
+
preRequestHandler,
|
|
177
145
|
camelToSnake(),
|
|
178
146
|
]);
|
|
179
|
-
|
|
180
147
|
try {
|
|
181
148
|
const response = await getServices().updateService(String(id), item);
|
|
182
149
|
return applyTransform(response.data, [
|
|
@@ -189,11 +156,12 @@ const updateService = async ({
|
|
|
189
156
|
}
|
|
190
157
|
};
|
|
191
158
|
|
|
192
|
-
const
|
|
193
|
-
|
|
159
|
+
const patchFieldsToSend =
|
|
160
|
+
getShallowFieldsToSendFromZodSchema(UpdateService2Body);
|
|
194
161
|
|
|
162
|
+
const patchService = async ({ changes, id }: PatchItemParams) => {
|
|
195
163
|
const body = applyTransform(changes, [
|
|
196
|
-
sanitizeToWire(
|
|
164
|
+
sanitizeToWire(patchFieldsToSend),
|
|
197
165
|
camelToSnake(),
|
|
198
166
|
]);
|
|
199
167
|
try {
|
|
@@ -221,9 +189,7 @@ const deleteService = async ({ id }: DeleteItemParams) => {
|
|
|
221
189
|
}
|
|
222
190
|
};
|
|
223
191
|
|
|
224
|
-
const getServicesLookup =
|
|
225
|
-
params: Parameters<typeof getServicesList>[0],
|
|
226
|
-
) =>
|
|
192
|
+
const getServicesLookup = (params: Parameters<typeof getServicesList>[0]) =>
|
|
227
193
|
getServicesList({
|
|
228
194
|
...params,
|
|
229
195
|
fields: params.fields || [
|