@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
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import { getFtsservice, SearchQueryParams } from '../../../../gen-wire';
|
|
3
|
+
import {
|
|
4
|
+
getDefaultGetListResponse,
|
|
5
|
+
getDefaultGetParams,
|
|
6
|
+
} from '../../../defaults';
|
|
7
|
+
import {
|
|
8
|
+
applyTransform,
|
|
9
|
+
merge,
|
|
10
|
+
notify,
|
|
11
|
+
sanitizeToWire,
|
|
12
|
+
snakeToCamel,
|
|
13
|
+
} from '../../../transformers';
|
|
14
|
+
import type { ApiParams } from '../../_shared/types';
|
|
15
|
+
|
|
16
|
+
const getSearchList = async (params: ApiParams) => {
|
|
17
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(SearchQueryParams);
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
page,
|
|
21
|
+
size,
|
|
22
|
+
q,
|
|
23
|
+
sort,
|
|
24
|
+
fields,
|
|
25
|
+
options,
|
|
26
|
+
object_name: objectName,
|
|
27
|
+
} = applyTransform(params, [
|
|
28
|
+
merge(getDefaultGetParams()),
|
|
29
|
+
(params) => ({
|
|
30
|
+
...params,
|
|
31
|
+
q: params.fts,
|
|
32
|
+
}),
|
|
33
|
+
sanitizeToWire(fieldsToSend),
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const response = await getFtsservice().search(
|
|
38
|
+
{
|
|
39
|
+
page,
|
|
40
|
+
size,
|
|
41
|
+
q,
|
|
42
|
+
sort,
|
|
43
|
+
fields,
|
|
44
|
+
object_name: objectName,
|
|
45
|
+
},
|
|
46
|
+
options,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const { items, next } = applyTransform(response.data, [
|
|
50
|
+
merge(getDefaultGetListResponse()),
|
|
51
|
+
]);
|
|
52
|
+
return {
|
|
53
|
+
items: applyTransform(items, [
|
|
54
|
+
snakeToCamel(),
|
|
55
|
+
]),
|
|
56
|
+
next,
|
|
57
|
+
};
|
|
58
|
+
} catch (err) {
|
|
59
|
+
throw applyTransform(err, [
|
|
60
|
+
notify,
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const FTSServiceAPI = {
|
|
66
|
+
getList: getSearchList,
|
|
67
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { isObject } from 'lodash-es';
|
|
2
|
+
import { RelativeDatetimeValue } from '../../../../enums';
|
|
3
|
+
import {
|
|
4
|
+
isRelativeDatetimeValue,
|
|
5
|
+
normalizeToTimestamp,
|
|
6
|
+
} from '../../../../scripts';
|
|
7
|
+
import type { ApiParams } from '../../_shared/types';
|
|
8
|
+
|
|
9
|
+
// filter values are heterogeneous (string, number, object, array) — not worth
|
|
10
|
+
// modeling per filter key
|
|
11
|
+
type FilterTransformer = (
|
|
12
|
+
// biome-ignore lint/suspicious/noExplicitAny: see comment above
|
|
13
|
+
value: any,
|
|
14
|
+
key: string,
|
|
15
|
+
) => string | string[] | undefined;
|
|
16
|
+
|
|
17
|
+
const filterTransformersMap: Record<string, FilterTransformer> = {
|
|
18
|
+
createdAt: (createdAt) => {
|
|
19
|
+
const arr = [];
|
|
20
|
+
if (!createdAt) {
|
|
21
|
+
arr.push(
|
|
22
|
+
`created_at.from=${normalizeToTimestamp(RelativeDatetimeValue.Today, {
|
|
23
|
+
round: 'start',
|
|
24
|
+
})}`,
|
|
25
|
+
);
|
|
26
|
+
} else {
|
|
27
|
+
if (typeof createdAt === 'string') {
|
|
28
|
+
arr.push(
|
|
29
|
+
`created_at.from=${normalizeToTimestamp(createdAt, {
|
|
30
|
+
round: 'start',
|
|
31
|
+
})}`,
|
|
32
|
+
`created_at.to=${normalizeToTimestamp(createdAt, {
|
|
33
|
+
round: 'end',
|
|
34
|
+
})}`,
|
|
35
|
+
);
|
|
36
|
+
} else {
|
|
37
|
+
if (createdAt.from) arr.push(`created_at.from=${createdAt.from}`);
|
|
38
|
+
if (createdAt.to) arr.push(`created_at.to=${createdAt.to}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return arr;
|
|
42
|
+
},
|
|
43
|
+
status: (value) => `status_condition=${value.conditions}`,
|
|
44
|
+
source: (value) => `source=${value}`,
|
|
45
|
+
author: (value) => `created_by=${value}`,
|
|
46
|
+
reporter: (value) => `reporter=${value}`,
|
|
47
|
+
impacted: (value) => `impacted=${value}`,
|
|
48
|
+
assignee: (value) =>
|
|
49
|
+
value.unassigned
|
|
50
|
+
? `assignee=${value.list},${null}`
|
|
51
|
+
: `assignee=${value.list}`,
|
|
52
|
+
contactGroup: (value) =>
|
|
53
|
+
value.unassigned ? `group=${value.list},${null}` : `group=${value.list}`,
|
|
54
|
+
priority: (value) => `priority=${value}`,
|
|
55
|
+
closeReasonGroups: (value) => `close_reason=${value.conditions}`,
|
|
56
|
+
rating: (value) => {
|
|
57
|
+
const arr = [];
|
|
58
|
+
if (value.from) arr.push(`rating.from=${value.from}`);
|
|
59
|
+
if (value.to) arr.push(`rating.to=${value.to}`);
|
|
60
|
+
return arr;
|
|
61
|
+
},
|
|
62
|
+
service: (value) => `service=${value}`,
|
|
63
|
+
sla: (value) => `sla=${value}`,
|
|
64
|
+
slaCondition: (value) => `sla_condition=${value.conditions}`,
|
|
65
|
+
reactionTime: (value) => {
|
|
66
|
+
const arr = [];
|
|
67
|
+
if (value.from) arr.push(`planned_reaction_at.from=${value.from}`);
|
|
68
|
+
if (value.to) arr.push(`planned_reaction_at.to=${value.to}`);
|
|
69
|
+
return arr;
|
|
70
|
+
},
|
|
71
|
+
resolutionTime: (value) => {
|
|
72
|
+
const arr = [];
|
|
73
|
+
if (value.from) arr.push(`planned_resolve_at.from=${value.from}`);
|
|
74
|
+
if (value.to) arr.push(`planned_resolve_at.to=${value.to}`);
|
|
75
|
+
return arr;
|
|
76
|
+
},
|
|
77
|
+
actualReactionTime: (value) => {
|
|
78
|
+
const arr = [];
|
|
79
|
+
if (value.from) arr.push(`reacted_at.from=${value.from}`);
|
|
80
|
+
if (value.to) arr.push(`reacted_at.to=${value.to}`);
|
|
81
|
+
return arr;
|
|
82
|
+
},
|
|
83
|
+
actualResolutionTime: (value) => {
|
|
84
|
+
const arr = [];
|
|
85
|
+
if (value.from) arr.push(`resolved_at.from=${value.from}`);
|
|
86
|
+
if (value.to) arr.push(`resolved_at.to=${value.to}`);
|
|
87
|
+
return arr;
|
|
88
|
+
},
|
|
89
|
+
hasAttachment: (value) => `attachments=${value}`,
|
|
90
|
+
others: (value, key) => {
|
|
91
|
+
const makeArrWithStringValuesFromObjectValue = (
|
|
92
|
+
value: ApiParams,
|
|
93
|
+
key: string,
|
|
94
|
+
) => {
|
|
95
|
+
return Object.entries(value).map(
|
|
96
|
+
([propKey, propValue]) => `${key}.${propKey}=${propValue}`,
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/* then value is magic datetime string */
|
|
101
|
+
if (isRelativeDatetimeValue(value)) {
|
|
102
|
+
const normalizedValue = {
|
|
103
|
+
from: normalizeToTimestamp(value, {
|
|
104
|
+
round: 'start',
|
|
105
|
+
}),
|
|
106
|
+
to: normalizeToTimestamp(value, {
|
|
107
|
+
round: 'end',
|
|
108
|
+
}),
|
|
109
|
+
};
|
|
110
|
+
return makeArrWithStringValuesFromObjectValue(normalizedValue, key);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @author @dlohvinov
|
|
115
|
+
* if..., then assume its a datetime
|
|
116
|
+
*/
|
|
117
|
+
if (value?.from || value?.to) {
|
|
118
|
+
const normalizedValue: {
|
|
119
|
+
from?: number;
|
|
120
|
+
to?: number;
|
|
121
|
+
} = {};
|
|
122
|
+
|
|
123
|
+
if (value.from) {
|
|
124
|
+
normalizedValue.from = normalizeToTimestamp(value.from);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (value.to) {
|
|
128
|
+
normalizedValue.to = normalizeToTimestamp(value.to);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return makeArrWithStringValuesFromObjectValue(normalizedValue, key);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!isObject(value) || Array.isArray(value)) return `${key}=${value}`;
|
|
135
|
+
|
|
136
|
+
return makeArrWithStringValuesFromObjectValue(value, key);
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const stringifyCaseFilters = (filters: ApiParams) => {
|
|
141
|
+
const result: string[] = [];
|
|
142
|
+
|
|
143
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
144
|
+
const transformer =
|
|
145
|
+
filterTransformersMap[key] || filterTransformersMap.others;
|
|
146
|
+
|
|
147
|
+
const strValue = transformer(value, key);
|
|
148
|
+
|
|
149
|
+
if (value != null && strValue) {
|
|
150
|
+
if (Array.isArray(strValue)) {
|
|
151
|
+
result.push(...strValue);
|
|
152
|
+
} else result.push(strValue);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
};
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import { snakeToKebab } from '@webitel/api-services/utils';
|
|
3
|
+
import {
|
|
4
|
+
CreateCaseBody,
|
|
5
|
+
getCases,
|
|
6
|
+
UpdateCase2Body,
|
|
7
|
+
UpdateCaseBody,
|
|
8
|
+
} from '../../../gen-wire';
|
|
9
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
10
|
+
import {
|
|
11
|
+
applyTransform,
|
|
12
|
+
camelToSnake,
|
|
13
|
+
merge,
|
|
14
|
+
notify,
|
|
15
|
+
sanitizeToWire,
|
|
16
|
+
snakeToCamel,
|
|
17
|
+
} from '../../transformers';
|
|
18
|
+
import { generatePermissionsApi } from '../_shared/generatePermissionsApi';
|
|
19
|
+
import type {
|
|
20
|
+
AddItemParams,
|
|
21
|
+
ApiId,
|
|
22
|
+
ApiParams,
|
|
23
|
+
DeleteItemParams,
|
|
24
|
+
GetItemParams,
|
|
25
|
+
} from '../_shared/types';
|
|
26
|
+
import { FTSServiceAPI } from './_internals/ftsService';
|
|
27
|
+
import { stringifyCaseFilters } from './_internals/stringifyCaseFilters';
|
|
28
|
+
|
|
29
|
+
const casesService = getCases();
|
|
30
|
+
|
|
31
|
+
const baseUrl = '/cases';
|
|
32
|
+
|
|
33
|
+
function transformSourceType(data: ApiParams | ApiParams[]) {
|
|
34
|
+
if (Array.isArray(data)) {
|
|
35
|
+
return data.map((item) => {
|
|
36
|
+
if (item.source?.type) {
|
|
37
|
+
item.source.type = snakeToKebab(item.source.type.toLowerCase());
|
|
38
|
+
}
|
|
39
|
+
return item;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (data.source?.type) {
|
|
44
|
+
data.source.type = snakeToKebab(data.source.type.toLowerCase());
|
|
45
|
+
}
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const transformCustomFields = (data: ApiParams) => {
|
|
50
|
+
if (!data.custom) {
|
|
51
|
+
data.custom = {};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return data;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const checkCustomFields = (data: ApiParams) => {
|
|
58
|
+
if (!Object.keys(data.custom).length) {
|
|
59
|
+
delete data.custom;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return data;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getCasesList = async (params: ApiParams) => {
|
|
66
|
+
let ftsIds: string[] | undefined;
|
|
67
|
+
const { fts } = params;
|
|
68
|
+
if (fts) {
|
|
69
|
+
try {
|
|
70
|
+
const { items } = await FTSServiceAPI.getList({
|
|
71
|
+
page: params.page,
|
|
72
|
+
size: params.size,
|
|
73
|
+
fts: params.fts,
|
|
74
|
+
sort: params.sort,
|
|
75
|
+
objectName: [
|
|
76
|
+
'cases',
|
|
77
|
+
'case_comments',
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
ftsIds = items.map(({ id }: ApiParams) => id);
|
|
81
|
+
} catch {
|
|
82
|
+
// skip error, load cases without fts
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const { page, size, q, ids, sort, fields, options, ...filters } =
|
|
87
|
+
applyTransform(
|
|
88
|
+
{
|
|
89
|
+
...params,
|
|
90
|
+
ids: params.ids || ftsIds,
|
|
91
|
+
},
|
|
92
|
+
[
|
|
93
|
+
merge(getDefaultGetParams()),
|
|
94
|
+
(params) => ({
|
|
95
|
+
...params,
|
|
96
|
+
q: params.search,
|
|
97
|
+
}),
|
|
98
|
+
],
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const response = await casesService.searchCases(
|
|
103
|
+
{
|
|
104
|
+
page,
|
|
105
|
+
size,
|
|
106
|
+
q,
|
|
107
|
+
ids,
|
|
108
|
+
sort,
|
|
109
|
+
fields: [
|
|
110
|
+
'custom',
|
|
111
|
+
'priority',
|
|
112
|
+
'description',
|
|
113
|
+
'comments',
|
|
114
|
+
...fields,
|
|
115
|
+
],
|
|
116
|
+
filters: stringifyCaseFilters(filters),
|
|
117
|
+
},
|
|
118
|
+
options,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const { items, next } = applyTransform(response.data, [
|
|
122
|
+
merge(getDefaultGetListResponse()),
|
|
123
|
+
]);
|
|
124
|
+
return {
|
|
125
|
+
items: applyTransform(items, [
|
|
126
|
+
snakeToCamel(),
|
|
127
|
+
transformSourceType,
|
|
128
|
+
]),
|
|
129
|
+
next,
|
|
130
|
+
};
|
|
131
|
+
} catch (err) {
|
|
132
|
+
throw applyTransform(err, [
|
|
133
|
+
notify,
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const caseFieldsToSend = [
|
|
139
|
+
'etag',
|
|
140
|
+
'id',
|
|
141
|
+
'name',
|
|
142
|
+
'subject',
|
|
143
|
+
'description',
|
|
144
|
+
'contact_info',
|
|
145
|
+
'created_at',
|
|
146
|
+
'planned_reaction_at',
|
|
147
|
+
'planned_resolve_at',
|
|
148
|
+
'status_lookup',
|
|
149
|
+
'close_reason_lookup',
|
|
150
|
+
'author',
|
|
151
|
+
'assignee',
|
|
152
|
+
'reporter',
|
|
153
|
+
'impacted',
|
|
154
|
+
'group',
|
|
155
|
+
'priority',
|
|
156
|
+
'source',
|
|
157
|
+
'status',
|
|
158
|
+
'close_reason',
|
|
159
|
+
'close_result',
|
|
160
|
+
'rating',
|
|
161
|
+
'rating_comment',
|
|
162
|
+
'reacted_at',
|
|
163
|
+
'resolved_at',
|
|
164
|
+
'sla_condition',
|
|
165
|
+
'difference_in_reaction',
|
|
166
|
+
'difference_in_resolve',
|
|
167
|
+
'sla',
|
|
168
|
+
'service',
|
|
169
|
+
'comments',
|
|
170
|
+
'related_cases',
|
|
171
|
+
'links',
|
|
172
|
+
'status_condition',
|
|
173
|
+
'created_by',
|
|
174
|
+
'custom',
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
const getCase = async ({ itemId: id }: GetItemParams) => {
|
|
178
|
+
try {
|
|
179
|
+
const response = await casesService.locateCase(String(id), {
|
|
180
|
+
fields: caseFieldsToSend,
|
|
181
|
+
});
|
|
182
|
+
return applyTransform(response.data, [
|
|
183
|
+
snakeToCamel([
|
|
184
|
+
'custom',
|
|
185
|
+
]),
|
|
186
|
+
transformCustomFields,
|
|
187
|
+
transformSourceType,
|
|
188
|
+
]);
|
|
189
|
+
} catch (err) {
|
|
190
|
+
throw applyTransform(err, [
|
|
191
|
+
notify,
|
|
192
|
+
]);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const deleteCase = async ({ id }: DeleteItemParams) => {
|
|
197
|
+
try {
|
|
198
|
+
const response = await casesService.deleteCase(String(id));
|
|
199
|
+
return applyTransform(response.data, []);
|
|
200
|
+
} catch (err) {
|
|
201
|
+
throw applyTransform(err, [
|
|
202
|
+
notify,
|
|
203
|
+
]);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const updateFieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateCaseBody);
|
|
208
|
+
|
|
209
|
+
const updateCase = async ({ itemInstance }: AddItemParams) => {
|
|
210
|
+
const { etag } = itemInstance;
|
|
211
|
+
|
|
212
|
+
const item = applyTransform(itemInstance, [
|
|
213
|
+
sanitizeToWire(updateFieldsToSend),
|
|
214
|
+
camelToSnake([
|
|
215
|
+
'custom',
|
|
216
|
+
]),
|
|
217
|
+
checkCustomFields,
|
|
218
|
+
]);
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
const response = await casesService.updateCase(etag, item, {
|
|
222
|
+
fields: caseFieldsToSend,
|
|
223
|
+
});
|
|
224
|
+
return applyTransform(response.data.case, [
|
|
225
|
+
snakeToCamel([
|
|
226
|
+
'custom',
|
|
227
|
+
]),
|
|
228
|
+
transformCustomFields,
|
|
229
|
+
transformSourceType,
|
|
230
|
+
]);
|
|
231
|
+
} catch (err) {
|
|
232
|
+
throw applyTransform(err, [
|
|
233
|
+
notify,
|
|
234
|
+
]);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const addFieldsToSend = getShallowFieldsToSendFromZodSchema(CreateCaseBody);
|
|
239
|
+
|
|
240
|
+
const addCase = async ({ itemInstance }: AddItemParams) => {
|
|
241
|
+
const item = applyTransform(itemInstance, [
|
|
242
|
+
sanitizeToWire(addFieldsToSend),
|
|
243
|
+
camelToSnake([
|
|
244
|
+
'custom',
|
|
245
|
+
]),
|
|
246
|
+
]);
|
|
247
|
+
try {
|
|
248
|
+
const response = await casesService.createCase(item);
|
|
249
|
+
return applyTransform(response.data, [
|
|
250
|
+
snakeToCamel(),
|
|
251
|
+
]);
|
|
252
|
+
} catch (err) {
|
|
253
|
+
throw applyTransform(err, [
|
|
254
|
+
notify,
|
|
255
|
+
]);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const patchCase = async ({
|
|
260
|
+
changes,
|
|
261
|
+
etag,
|
|
262
|
+
}: {
|
|
263
|
+
changes: ApiParams;
|
|
264
|
+
etag: ApiId;
|
|
265
|
+
}) => {
|
|
266
|
+
const body = applyTransform(changes, [
|
|
267
|
+
sanitizeToWire(getShallowFieldsToSendFromZodSchema(UpdateCase2Body)),
|
|
268
|
+
camelToSnake(),
|
|
269
|
+
]);
|
|
270
|
+
try {
|
|
271
|
+
const response = await casesService.updateCase2(String(etag), body, {
|
|
272
|
+
fields: caseFieldsToSend,
|
|
273
|
+
});
|
|
274
|
+
return applyTransform(response.data.case, [
|
|
275
|
+
snakeToCamel([
|
|
276
|
+
'custom',
|
|
277
|
+
]),
|
|
278
|
+
transformCustomFields,
|
|
279
|
+
transformSourceType,
|
|
280
|
+
]);
|
|
281
|
+
} catch (err) {
|
|
282
|
+
throw applyTransform(err, [
|
|
283
|
+
notify,
|
|
284
|
+
]);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const exportCase = async (params: ApiParams) => {
|
|
289
|
+
const { q, sort, fields, options, format, separator, ids, ...filters } =
|
|
290
|
+
applyTransform(
|
|
291
|
+
{
|
|
292
|
+
...params,
|
|
293
|
+
},
|
|
294
|
+
[
|
|
295
|
+
merge(getDefaultGetParams()),
|
|
296
|
+
(params) => ({
|
|
297
|
+
...params,
|
|
298
|
+
q: params.search,
|
|
299
|
+
}),
|
|
300
|
+
],
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
delete filters.page;
|
|
304
|
+
delete filters.size;
|
|
305
|
+
|
|
306
|
+
const exportParams: Record<string, unknown> = {
|
|
307
|
+
q,
|
|
308
|
+
sort,
|
|
309
|
+
fields,
|
|
310
|
+
format,
|
|
311
|
+
separator,
|
|
312
|
+
filters: stringifyCaseFilters(filters),
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
if (ids?.length) {
|
|
316
|
+
exportParams.ids = ids;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
try {
|
|
320
|
+
const response = await casesService.exportCases(exportParams, {
|
|
321
|
+
...options,
|
|
322
|
+
responseType: 'blob',
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
return {
|
|
326
|
+
response,
|
|
327
|
+
};
|
|
328
|
+
} catch (err) {
|
|
329
|
+
throw applyTransform(err, [
|
|
330
|
+
notify,
|
|
331
|
+
]);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
const getCasesLookup = (params: Parameters<typeof getCasesList>[0]) =>
|
|
336
|
+
getCasesList({
|
|
337
|
+
...params,
|
|
338
|
+
fields: params.fields || [
|
|
339
|
+
'id',
|
|
340
|
+
'name',
|
|
341
|
+
'subject',
|
|
342
|
+
'priority',
|
|
343
|
+
],
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
export const CasesAPI = {
|
|
347
|
+
getList: getCasesList,
|
|
348
|
+
getLookup: getCasesLookup,
|
|
349
|
+
get: getCase,
|
|
350
|
+
delete: deleteCase,
|
|
351
|
+
update: updateCase,
|
|
352
|
+
add: addCase,
|
|
353
|
+
patch: patchCase,
|
|
354
|
+
exportData: exportCase,
|
|
355
|
+
|
|
356
|
+
...generatePermissionsApi(baseUrl),
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
export { FTSServiceAPI } from './_internals/ftsService';
|
|
360
|
+
export { stringifyCaseFilters } from './_internals/stringifyCaseFilters';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getCasesChatCatalog, getContactsChatCatalog } from '../../../gen-wire';
|
|
2
|
+
import { applyTransform, notify, snakeToCamel } from '../../transformers';
|
|
3
|
+
import type { ApiId, ApiParams } from '../_shared/types';
|
|
4
|
+
|
|
5
|
+
const mergeChatMessagesData = ({
|
|
6
|
+
messages,
|
|
7
|
+
peers,
|
|
8
|
+
}: {
|
|
9
|
+
messages: ApiParams[];
|
|
10
|
+
peers: ApiParams[];
|
|
11
|
+
}) => {
|
|
12
|
+
if (!messages) return [];
|
|
13
|
+
return messages.map(({ from, ...message }) => {
|
|
14
|
+
return {
|
|
15
|
+
...message,
|
|
16
|
+
peer: from && peers ? peers[from.id - 1] : undefined,
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const buildGetChatHistory =
|
|
22
|
+
(
|
|
23
|
+
getChatHistory: (
|
|
24
|
+
parentId: string,
|
|
25
|
+
taskId: string,
|
|
26
|
+
) => Promise<{
|
|
27
|
+
data: ApiParams;
|
|
28
|
+
}>,
|
|
29
|
+
) =>
|
|
30
|
+
async ({ parentId, taskId }: { parentId: ApiId; taskId: ApiId }) => {
|
|
31
|
+
try {
|
|
32
|
+
const response = await getChatHistory(String(parentId), String(taskId));
|
|
33
|
+
const { messages, peers } = applyTransform(response.data, [
|
|
34
|
+
snakeToCamel(),
|
|
35
|
+
]);
|
|
36
|
+
return {
|
|
37
|
+
items: applyTransform(
|
|
38
|
+
{
|
|
39
|
+
messages,
|
|
40
|
+
peers,
|
|
41
|
+
},
|
|
42
|
+
[
|
|
43
|
+
mergeChatMessagesData,
|
|
44
|
+
],
|
|
45
|
+
),
|
|
46
|
+
};
|
|
47
|
+
} catch (err) {
|
|
48
|
+
throw applyTransform(err, [
|
|
49
|
+
notify,
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const ChatMessagesHistoryAPI = {
|
|
55
|
+
getContactChatHistory: buildGetChatHistory((contactId, chatId) =>
|
|
56
|
+
getContactsChatCatalog().contactsChatCatalogGetContactChatHistory(
|
|
57
|
+
contactId,
|
|
58
|
+
chatId,
|
|
59
|
+
),
|
|
60
|
+
),
|
|
61
|
+
getCaseChatHistory: buildGetChatHistory((caseId, chatId) =>
|
|
62
|
+
getCasesChatCatalog().casesChatCatalogGetCaseChatHistory(caseId, chatId),
|
|
63
|
+
),
|
|
64
|
+
};
|