@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
|
@@ -62,6 +62,13 @@ const getList = async ({
|
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
+
const emailFieldsToSend = [
|
|
66
|
+
'email',
|
|
67
|
+
'primary',
|
|
68
|
+
'etag',
|
|
69
|
+
'type',
|
|
70
|
+
];
|
|
71
|
+
|
|
65
72
|
const get = async ({
|
|
66
73
|
itemId,
|
|
67
74
|
parentId,
|
|
@@ -69,18 +76,12 @@ const get = async ({
|
|
|
69
76
|
itemId: ApiId;
|
|
70
77
|
parentId: ApiId;
|
|
71
78
|
}) => {
|
|
72
|
-
const fields = [
|
|
73
|
-
'email',
|
|
74
|
-
'primary',
|
|
75
|
-
'etag',
|
|
76
|
-
'type',
|
|
77
|
-
];
|
|
78
79
|
try {
|
|
79
80
|
const response = await getEmails().locateEmail(
|
|
80
81
|
String(parentId),
|
|
81
82
|
String(itemId),
|
|
82
83
|
{
|
|
83
|
-
fields,
|
|
84
|
+
fields: emailFieldsToSend,
|
|
84
85
|
},
|
|
85
86
|
);
|
|
86
87
|
return applyTransform(response.data, [
|
|
@@ -142,6 +143,9 @@ const update = async ({
|
|
|
142
143
|
String(parentId),
|
|
143
144
|
itemInstance.etag,
|
|
144
145
|
item,
|
|
146
|
+
{
|
|
147
|
+
fields: emailFieldsToSend,
|
|
148
|
+
},
|
|
145
149
|
);
|
|
146
150
|
const { data } = applyTransform(response.data, [
|
|
147
151
|
snakeToCamel(),
|
package/src/api/clients/index.ts
CHANGED
|
@@ -8,18 +8,25 @@ export * from './calendars/calendars';
|
|
|
8
8
|
export * from './callHistory/callHistory';
|
|
9
9
|
export * from './caseCloseReasonGroups/caseCloseReasonGroups';
|
|
10
10
|
export * from './caseCloseReasons/caseCloseReasons';
|
|
11
|
+
export * from './caseComments/caseComments';
|
|
12
|
+
export * from './caseFiles/caseFiles';
|
|
13
|
+
export * from './caseLinks/caseLinks';
|
|
11
14
|
export * from './casePriorities/casePriorities';
|
|
15
|
+
export * from './caseRelatedCases/caseRelatedCases';
|
|
12
16
|
export * from './caseServiceCatalogs/serviceCatalogs';
|
|
13
17
|
export * from './caseServices/services';
|
|
14
18
|
export * from './caseSources/caseSources';
|
|
15
19
|
export * from './caseStatusConditions/caseStatusConditions';
|
|
16
20
|
export * from './caseStatuses/caseStatuses';
|
|
21
|
+
export * from './cases/cases';
|
|
17
22
|
export * from './catalog/catalog';
|
|
18
23
|
export * from './changelogs/changelogs';
|
|
19
24
|
export * from './chatDialogs/chatDialogs';
|
|
20
25
|
export * from './chatGateways/chatGateways';
|
|
26
|
+
export * from './chatMessagesHistory/chatMessagesHistory';
|
|
21
27
|
export * from './communications/communications';
|
|
22
28
|
export * from './configurations/configurations';
|
|
29
|
+
export * from './contactCases/contactCases';
|
|
23
30
|
export * from './contactGroups/contactGroups';
|
|
24
31
|
export * from './dynamicConditions/dynamicConditions';
|
|
25
32
|
export * from './dynamicGroups/dynamicGroups';
|
|
@@ -51,8 +58,10 @@ export * from './quickReplies/quickReplies';
|
|
|
51
58
|
export * from './regions/regions';
|
|
52
59
|
// export * from './roles/roles'; fixme: ApplicationAccess import
|
|
53
60
|
export * from './skills/skills';
|
|
61
|
+
export * from './slaConditions/slaConditions';
|
|
54
62
|
export * from './slas/slas';
|
|
55
63
|
export * from './teams/teams';
|
|
64
|
+
export * from './timeline/timeline';
|
|
56
65
|
export * from './userSettings/userSettings';
|
|
57
66
|
export * from './users/users';
|
|
58
67
|
export * from './variables/variables';
|
|
@@ -1,42 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
getDefaultInstance,
|
|
5
|
-
getDefaultOpenAPIConfig,
|
|
6
|
-
} from '../../defaults';
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import { GetLabelsQueryParams, getLabels } from '../../../gen-wire';
|
|
3
|
+
import { getDefaultGetParams } from '../../defaults';
|
|
7
4
|
import {
|
|
8
5
|
applyTransform,
|
|
9
6
|
camelToSnake,
|
|
10
7
|
merge,
|
|
11
8
|
notify,
|
|
12
|
-
|
|
9
|
+
sanitizeToWire,
|
|
13
10
|
snakeToCamel,
|
|
14
11
|
starToSearch,
|
|
15
12
|
} from '../../transformers';
|
|
16
13
|
import type { ApiParams } from '../_shared/types';
|
|
17
14
|
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const service = LabelsApiFactory(configuration, '', instance);
|
|
15
|
+
const getLabelsList = async (params: ApiParams) => {
|
|
16
|
+
const listFieldsToSend =
|
|
17
|
+
getShallowFieldsToSendFromZodSchema(GetLabelsQueryParams);
|
|
22
18
|
|
|
23
|
-
const
|
|
24
|
-
const fieldsToSend = [
|
|
25
|
-
'page',
|
|
26
|
-
'size',
|
|
27
|
-
'search',
|
|
28
|
-
'sort',
|
|
29
|
-
'fields',
|
|
30
|
-
'id',
|
|
31
|
-
];
|
|
32
|
-
const { page, size, search } = applyTransform(params, [
|
|
33
|
-
sanitize(fieldsToSend),
|
|
19
|
+
const { page, size, q, fields } = applyTransform(params, [
|
|
34
20
|
merge(getDefaultGetParams()),
|
|
35
|
-
|
|
21
|
+
merge({
|
|
22
|
+
q: params.search,
|
|
23
|
+
}),
|
|
24
|
+
sanitizeToWire(listFieldsToSend),
|
|
25
|
+
starToSearch('q'),
|
|
36
26
|
camelToSnake(),
|
|
37
27
|
]);
|
|
28
|
+
|
|
38
29
|
try {
|
|
39
|
-
const response = await
|
|
30
|
+
const response = await getLabels().getLabels({
|
|
31
|
+
page,
|
|
32
|
+
size,
|
|
33
|
+
q,
|
|
34
|
+
fields,
|
|
35
|
+
});
|
|
40
36
|
const { labels, next } = applyTransform(response.data, [
|
|
41
37
|
snakeToCamel(),
|
|
42
38
|
merge({
|
|
@@ -55,16 +51,15 @@ const getList = async (params: ApiParams) => {
|
|
|
55
51
|
}
|
|
56
52
|
};
|
|
57
53
|
|
|
58
|
-
const getLabelsLookup = (params: Parameters<typeof
|
|
59
|
-
|
|
54
|
+
const getLabelsLookup = (params: Parameters<typeof getLabelsList>[0]) =>
|
|
55
|
+
getLabelsList({
|
|
60
56
|
...params,
|
|
61
57
|
fields: params.fields || [
|
|
62
|
-
'
|
|
63
|
-
'name',
|
|
58
|
+
'label',
|
|
64
59
|
],
|
|
65
60
|
});
|
|
66
61
|
|
|
67
62
|
export const LabelsAPI = {
|
|
68
|
-
getList,
|
|
63
|
+
getList: getLabelsList,
|
|
69
64
|
getLookup: getLabelsLookup,
|
|
70
65
|
};
|
|
@@ -63,6 +63,13 @@ const getPhonesList = async ({
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
+
const phoneFieldsToSend = [
|
|
67
|
+
'number',
|
|
68
|
+
'primary',
|
|
69
|
+
'etag',
|
|
70
|
+
'type',
|
|
71
|
+
];
|
|
72
|
+
|
|
66
73
|
const getPhone = async ({
|
|
67
74
|
itemId,
|
|
68
75
|
parentId,
|
|
@@ -70,18 +77,12 @@ const getPhone = async ({
|
|
|
70
77
|
itemId: ApiId;
|
|
71
78
|
parentId: ApiId;
|
|
72
79
|
}) => {
|
|
73
|
-
const fields = [
|
|
74
|
-
'number',
|
|
75
|
-
'primary',
|
|
76
|
-
'etag',
|
|
77
|
-
'type',
|
|
78
|
-
];
|
|
79
80
|
try {
|
|
80
81
|
const response = await getPhones().locatePhone(
|
|
81
82
|
String(parentId),
|
|
82
83
|
String(itemId),
|
|
83
84
|
{
|
|
84
|
-
fields,
|
|
85
|
+
fields: phoneFieldsToSend,
|
|
85
86
|
},
|
|
86
87
|
);
|
|
87
88
|
return applyTransform(response.data, [
|
|
@@ -143,6 +144,9 @@ const updatePhone = async ({
|
|
|
143
144
|
String(parentId),
|
|
144
145
|
itemInstance.etag,
|
|
145
146
|
item,
|
|
147
|
+
{
|
|
148
|
+
fields: phoneFieldsToSend,
|
|
149
|
+
},
|
|
146
150
|
);
|
|
147
151
|
const { data } = applyTransform(response.data, [
|
|
148
152
|
snakeToCamel(),
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import {
|
|
3
|
+
GetTimelineQueryParams,
|
|
4
|
+
GetTimelineTimelineQueryParams,
|
|
5
|
+
getCaseTimeline,
|
|
6
|
+
getTimeline,
|
|
7
|
+
} from '../../../gen-wire';
|
|
8
|
+
|
|
9
|
+
import { getDefaultGetParams } from '../../defaults';
|
|
10
|
+
import {
|
|
11
|
+
applyTransform,
|
|
12
|
+
merge,
|
|
13
|
+
notify,
|
|
14
|
+
sanitizeToWire,
|
|
15
|
+
snakeToCamel,
|
|
16
|
+
} from '../../transformers';
|
|
17
|
+
import type { ApiId, ApiParams } from '../_shared/types';
|
|
18
|
+
|
|
19
|
+
type TimelineEntity = 'case' | 'contact';
|
|
20
|
+
|
|
21
|
+
const clients = {
|
|
22
|
+
case: {
|
|
23
|
+
getTimeline: (parentId, params) =>
|
|
24
|
+
getCaseTimeline().getTimeline(parentId, params),
|
|
25
|
+
getTimelineCounter: (parentId) =>
|
|
26
|
+
getCaseTimeline().getTimelineCounter(parentId),
|
|
27
|
+
queryParamsSchema: GetTimelineQueryParams,
|
|
28
|
+
},
|
|
29
|
+
contact: {
|
|
30
|
+
getTimeline: (parentId, params) =>
|
|
31
|
+
getTimeline().getTimelineTimeline(parentId, params),
|
|
32
|
+
getTimelineCounter: (parentId) =>
|
|
33
|
+
getTimeline().getTimelineCounterTimeline(parentId),
|
|
34
|
+
queryParamsSchema: GetTimelineTimelineQueryParams,
|
|
35
|
+
},
|
|
36
|
+
} satisfies Record<
|
|
37
|
+
TimelineEntity,
|
|
38
|
+
{
|
|
39
|
+
getTimeline: (
|
|
40
|
+
parentId: string,
|
|
41
|
+
params: ApiParams,
|
|
42
|
+
) => Promise<{
|
|
43
|
+
data: unknown;
|
|
44
|
+
}>;
|
|
45
|
+
getTimelineCounter: (parentId: string) => Promise<{
|
|
46
|
+
data: unknown;
|
|
47
|
+
}>;
|
|
48
|
+
queryParamsSchema: unknown;
|
|
49
|
+
}
|
|
50
|
+
>;
|
|
51
|
+
|
|
52
|
+
const getList = async ({
|
|
53
|
+
entity,
|
|
54
|
+
parentId,
|
|
55
|
+
...rest
|
|
56
|
+
}: {
|
|
57
|
+
entity: TimelineEntity;
|
|
58
|
+
parentId: ApiId;
|
|
59
|
+
} & ApiParams) => {
|
|
60
|
+
const { getTimeline, queryParamsSchema } = clients[entity];
|
|
61
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(queryParamsSchema);
|
|
62
|
+
|
|
63
|
+
const { dateFrom, dateTo, type, page, size } = applyTransform(rest, [
|
|
64
|
+
merge(getDefaultGetParams()),
|
|
65
|
+
sanitizeToWire(fieldsToSend),
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const response = await getTimeline(String(parentId), {
|
|
70
|
+
page,
|
|
71
|
+
size,
|
|
72
|
+
dateFrom,
|
|
73
|
+
dateTo,
|
|
74
|
+
type,
|
|
75
|
+
});
|
|
76
|
+
// `days` can be a large, deeply-nested tree — merge() would recursively
|
|
77
|
+
// clone the whole thing via deepmerge just to add unused `items`/`next`
|
|
78
|
+
// defaults, which risks a stack overflow on large histories.
|
|
79
|
+
const data = applyTransform(response.data, [
|
|
80
|
+
snakeToCamel(),
|
|
81
|
+
]);
|
|
82
|
+
return {
|
|
83
|
+
days: data?.days ?? [],
|
|
84
|
+
next: data?.next ?? false,
|
|
85
|
+
};
|
|
86
|
+
} catch (err) {
|
|
87
|
+
throw applyTransform(err, [
|
|
88
|
+
notify,
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const getCounters = async ({
|
|
94
|
+
entity,
|
|
95
|
+
parentId,
|
|
96
|
+
}: {
|
|
97
|
+
entity: TimelineEntity;
|
|
98
|
+
parentId: ApiId;
|
|
99
|
+
}) => {
|
|
100
|
+
const { getTimelineCounter } = clients[entity];
|
|
101
|
+
const defaultObject = {
|
|
102
|
+
callsCount: 0,
|
|
103
|
+
chatsCount: 0,
|
|
104
|
+
emailsCount: 0,
|
|
105
|
+
dateFrom: Date.now(),
|
|
106
|
+
dateTo: Date.now(),
|
|
107
|
+
};
|
|
108
|
+
try {
|
|
109
|
+
const response = await getTimelineCounter(String(parentId));
|
|
110
|
+
return applyTransform(response.data, [
|
|
111
|
+
snakeToCamel(),
|
|
112
|
+
merge(defaultObject),
|
|
113
|
+
]);
|
|
114
|
+
} catch (err) {
|
|
115
|
+
throw applyTransform(err, [
|
|
116
|
+
notify,
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const TimelineAPI = {
|
|
122
|
+
getList,
|
|
123
|
+
getCounters,
|
|
124
|
+
};
|
|
@@ -61,6 +61,12 @@ const getVariablesList = async ({
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
+
const variableFieldsToSend = [
|
|
65
|
+
'key',
|
|
66
|
+
'value',
|
|
67
|
+
'etag',
|
|
68
|
+
];
|
|
69
|
+
|
|
64
70
|
// no dedicated "locate one" endpoint exists for variables — reuse the list
|
|
65
71
|
// endpoint filtered to a single id, matching what the crm-local adapter did
|
|
66
72
|
const getVariable = async ({
|
|
@@ -74,11 +80,7 @@ const getVariable = async ({
|
|
|
74
80
|
const response = await getVariables().listVariables(parentId, {
|
|
75
81
|
page: 1,
|
|
76
82
|
size: 1,
|
|
77
|
-
fields:
|
|
78
|
-
'key',
|
|
79
|
-
'value',
|
|
80
|
-
'etag',
|
|
81
|
-
],
|
|
83
|
+
fields: variableFieldsToSend,
|
|
82
84
|
id: [
|
|
83
85
|
itemId,
|
|
84
86
|
],
|
|
@@ -145,6 +147,9 @@ const updateVariable = async ({
|
|
|
145
147
|
parentId,
|
|
146
148
|
itemInstance.etag,
|
|
147
149
|
item,
|
|
150
|
+
{
|
|
151
|
+
fields: variableFieldsToSend,
|
|
152
|
+
},
|
|
148
153
|
);
|
|
149
154
|
const { data } = applyTransform(response.data, [
|
|
150
155
|
snakeToCamel(),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DataField,
|
|
3
|
+
ProtoDataStruct,
|
|
4
|
+
} from '@webitel/api-services/gen/models';
|
|
5
|
+
|
|
6
|
+
type PositionableDataField = DataField & {
|
|
7
|
+
position?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// readonly (system) fields never get a position; every other field is
|
|
11
|
+
// numbered in the order the backend returns it, 1-based.
|
|
12
|
+
export const assignFieldPositions = (
|
|
13
|
+
item: ProtoDataStruct,
|
|
14
|
+
): ProtoDataStruct => {
|
|
15
|
+
let position = 1;
|
|
16
|
+
|
|
17
|
+
const fields = ((item.fields ?? []) as PositionableDataField[]).map(
|
|
18
|
+
(field) => ({
|
|
19
|
+
...field,
|
|
20
|
+
position: field.readonly ? undefined : position++,
|
|
21
|
+
}),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
...item,
|
|
26
|
+
fields,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import deepCopy from 'deep-copy';
|
|
2
1
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from 'webitel-
|
|
2
|
+
DataField,
|
|
3
|
+
ProtoDataStruct,
|
|
4
|
+
} from '@webitel/api-services/gen/models';
|
|
5
|
+
import deepCopy from 'deep-copy';
|
|
6
6
|
|
|
7
|
-
// The generated
|
|
7
|
+
// The generated type omits `position`, but the backend returns it
|
|
8
8
|
// and it drives ordering of dynamic fields.
|
|
9
|
-
type SortableDataField =
|
|
9
|
+
type SortableDataField = DataField & {
|
|
10
10
|
position?: number;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const sortDynamicFields = (
|
|
14
|
-
item: WebitelProtoDataStruct,
|
|
15
|
-
): WebitelProtoDataStruct => {
|
|
13
|
+
export const sortDynamicFields = (item: ProtoDataStruct): ProtoDataStruct => {
|
|
16
14
|
const allFields = (item.fields ?? []) as SortableDataField[];
|
|
17
15
|
|
|
18
16
|
const unSortableFields = allFields.filter((field) => !field.position);
|
|
@@ -20,10 +20,10 @@ import type { ApiId, ApiParams } from '../../_shared/types';
|
|
|
20
20
|
const instance = getDefaultInstance();
|
|
21
21
|
|
|
22
22
|
const getAdjunctTypeRecordsList = async ({
|
|
23
|
-
|
|
23
|
+
parentId,
|
|
24
24
|
...params
|
|
25
25
|
}: {
|
|
26
|
-
|
|
26
|
+
parentId: string;
|
|
27
27
|
} & ApiParams) => {
|
|
28
28
|
const fieldsToSend = [
|
|
29
29
|
'page',
|
|
@@ -45,7 +45,7 @@ const getAdjunctTypeRecordsList = async ({
|
|
|
45
45
|
camelToSnake(),
|
|
46
46
|
]);
|
|
47
47
|
try {
|
|
48
|
-
const response = await getDictionaries().searchData(
|
|
48
|
+
const response = await getDictionaries().searchData(parentId, {
|
|
49
49
|
size,
|
|
50
50
|
page,
|
|
51
51
|
sort,
|
|
@@ -69,13 +69,13 @@ const getAdjunctTypeRecordsList = async ({
|
|
|
69
69
|
|
|
70
70
|
const getAdjunctTypeRecord = async ({
|
|
71
71
|
itemId: id,
|
|
72
|
-
|
|
72
|
+
parentId,
|
|
73
73
|
}: {
|
|
74
74
|
itemId: ApiId;
|
|
75
|
-
|
|
75
|
+
parentId: string;
|
|
76
76
|
}) => {
|
|
77
77
|
try {
|
|
78
|
-
const response = await getDictionaries().locateData(
|
|
78
|
+
const response = await getDictionaries().locateData(parentId, String(id));
|
|
79
79
|
return response.data;
|
|
80
80
|
} catch (err) {
|
|
81
81
|
throw applyTransform(err, [
|
|
@@ -87,18 +87,18 @@ const getAdjunctTypeRecord = async ({
|
|
|
87
87
|
const addAdjunctTypeRecord = async ({
|
|
88
88
|
itemInstance,
|
|
89
89
|
fieldsToSend,
|
|
90
|
-
|
|
90
|
+
parentId,
|
|
91
91
|
}: {
|
|
92
92
|
itemInstance: ApiParams;
|
|
93
93
|
fieldsToSend: string[];
|
|
94
|
-
|
|
94
|
+
parentId: string;
|
|
95
95
|
}) => {
|
|
96
96
|
const item = applyTransform(itemInstance, [
|
|
97
97
|
camelToSnake(),
|
|
98
98
|
sanitize(fieldsToSend),
|
|
99
99
|
]);
|
|
100
100
|
try {
|
|
101
|
-
const response = await getDictionaries().createData(
|
|
101
|
+
const response = await getDictionaries().createData(parentId, item);
|
|
102
102
|
return applyTransform(response.data, [
|
|
103
103
|
snakeToCamel(),
|
|
104
104
|
]);
|
|
@@ -113,19 +113,23 @@ const updateAdjunctTypeRecord = async ({
|
|
|
113
113
|
itemInstance,
|
|
114
114
|
fieldsToSend,
|
|
115
115
|
itemId: id,
|
|
116
|
-
|
|
116
|
+
parentId,
|
|
117
117
|
}: {
|
|
118
118
|
itemInstance: ApiParams;
|
|
119
119
|
fieldsToSend: string[];
|
|
120
120
|
itemId: ApiId;
|
|
121
|
-
|
|
121
|
+
parentId: string;
|
|
122
122
|
}) => {
|
|
123
123
|
const item = applyTransform(itemInstance, [
|
|
124
124
|
camelToSnake(),
|
|
125
125
|
sanitize(fieldsToSend),
|
|
126
126
|
]);
|
|
127
127
|
try {
|
|
128
|
-
const response = await getDictionaries().updateData(
|
|
128
|
+
const response = await getDictionaries().updateData(
|
|
129
|
+
parentId,
|
|
130
|
+
String(id),
|
|
131
|
+
item,
|
|
132
|
+
);
|
|
129
133
|
return applyTransform(response.data, [
|
|
130
134
|
snakeToCamel(),
|
|
131
135
|
]);
|
|
@@ -137,10 +141,10 @@ const updateAdjunctTypeRecord = async ({
|
|
|
137
141
|
};
|
|
138
142
|
|
|
139
143
|
const deleteAdjunctTypeRecord = async ({
|
|
140
|
-
|
|
144
|
+
parentId,
|
|
141
145
|
id,
|
|
142
146
|
}: {
|
|
143
|
-
|
|
147
|
+
parentId: string;
|
|
144
148
|
id: ApiId | ApiId[];
|
|
145
149
|
}) => {
|
|
146
150
|
const ids = (
|
|
@@ -151,8 +155,7 @@ const deleteAdjunctTypeRecord = async ({
|
|
|
151
155
|
]
|
|
152
156
|
).map(String);
|
|
153
157
|
try {
|
|
154
|
-
|
|
155
|
-
return response.data;
|
|
158
|
+
await getDictionaries().deleteData2(parentId, ids);
|
|
156
159
|
} catch (err) {
|
|
157
160
|
throw applyTransform(err, [
|
|
158
161
|
notify,
|
|
@@ -18,6 +18,8 @@ import type {
|
|
|
18
18
|
ApiParams,
|
|
19
19
|
UpdateItemParams,
|
|
20
20
|
} from '../../_shared/types';
|
|
21
|
+
import { assignFieldPositions } from '../_shared/utils/assignFieldPositions';
|
|
22
|
+
import { sortDynamicFields } from '../_shared/utils/sortDynamicFields';
|
|
21
23
|
|
|
22
24
|
const fieldsToSend = [
|
|
23
25
|
'name',
|
|
@@ -102,6 +104,7 @@ const getAdjunctType = async ({ itemId: itemRepo }: { itemId: string }) => {
|
|
|
102
104
|
return applyTransform(response.data, [
|
|
103
105
|
snakeToCamel(),
|
|
104
106
|
itemResponseHandler,
|
|
107
|
+
assignFieldPositions,
|
|
105
108
|
]);
|
|
106
109
|
} catch (err) {
|
|
107
110
|
throw applyTransform(err, [
|
|
@@ -134,6 +137,7 @@ const updateAdjunctType = async ({
|
|
|
134
137
|
itemId: id,
|
|
135
138
|
}: UpdateItemParams) => {
|
|
136
139
|
const item = applyTransform(itemInstance, [
|
|
140
|
+
sortDynamicFields,
|
|
137
141
|
camelToSnake(),
|
|
138
142
|
sanitize(fieldsToSend),
|
|
139
143
|
]);
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ProtoDataStruct } from '@webitel/api-services/gen/models';
|
|
2
|
+
import { getExtensions } from '../../../../gen-wire';
|
|
3
3
|
import {
|
|
4
4
|
applyTransform,
|
|
5
5
|
camelToSnake,
|
|
6
6
|
notify,
|
|
7
|
-
|
|
7
|
+
sanitizeToWire,
|
|
8
8
|
snakeToCamel,
|
|
9
9
|
} from '../../../transformers';
|
|
10
10
|
import type { ApiId, ApiParams } from '../../_shared/types';
|
|
11
|
+
import { assignFieldPositions } from '../_shared/utils/assignFieldPositions';
|
|
11
12
|
import { sortDynamicFields } from '../_shared/utils/sortDynamicFields';
|
|
12
13
|
|
|
13
|
-
const
|
|
14
|
-
const configuration = getDefaultOpenAPIConfig();
|
|
15
|
-
|
|
16
|
-
const typeExtensionsService = ExtensionsApiFactory(configuration, '', instance);
|
|
14
|
+
const typeExtensionsService = getExtensions();
|
|
17
15
|
|
|
18
16
|
const fieldsToSend = [
|
|
19
17
|
'fields',
|
|
@@ -21,33 +19,19 @@ const fieldsToSend = [
|
|
|
21
19
|
'path',
|
|
22
20
|
];
|
|
23
21
|
|
|
24
|
-
const generateIdsFromRepos = (item:
|
|
22
|
+
const generateIdsFromRepos = (item: ProtoDataStruct) => ({
|
|
25
23
|
...item,
|
|
26
24
|
id: item.repo,
|
|
27
25
|
});
|
|
28
26
|
|
|
29
27
|
const getTypeExtension = async ({ itemId: typeRepo }: { itemId: string }) => {
|
|
30
|
-
const createPositionGenerator = () => {
|
|
31
|
-
let position = 1;
|
|
32
|
-
return (item: ApiParams) => (item.readonly ? null : position++);
|
|
33
|
-
};
|
|
34
|
-
const getPosition = createPositionGenerator();
|
|
35
|
-
|
|
36
|
-
const itemResponseHandler = (item: ApiParams) => ({
|
|
37
|
-
...item,
|
|
38
|
-
fields: item.fields.map((field: ApiParams) => ({
|
|
39
|
-
...field,
|
|
40
|
-
position: getPosition(field),
|
|
41
|
-
})),
|
|
42
|
-
});
|
|
43
|
-
|
|
44
28
|
try {
|
|
45
|
-
const response = await typeExtensionsService.
|
|
29
|
+
const response = await typeExtensionsService.locateTypeExtensions(typeRepo);
|
|
46
30
|
|
|
47
31
|
return applyTransform(response.data, [
|
|
48
32
|
snakeToCamel(),
|
|
49
33
|
generateIdsFromRepos,
|
|
50
|
-
|
|
34
|
+
assignFieldPositions,
|
|
51
35
|
]);
|
|
52
36
|
} catch {
|
|
53
37
|
return {
|
|
@@ -67,11 +51,11 @@ const addTypeExtension = async ({
|
|
|
67
51
|
}) => {
|
|
68
52
|
const item = applyTransform(itemInstance, [
|
|
69
53
|
sortDynamicFields,
|
|
54
|
+
sanitizeToWire(fieldsToSend),
|
|
70
55
|
camelToSnake(),
|
|
71
|
-
sanitize(fieldsToSend),
|
|
72
56
|
]);
|
|
73
57
|
try {
|
|
74
|
-
const response = await typeExtensionsService.
|
|
58
|
+
const response = await typeExtensionsService.createTypeExtensions(
|
|
75
59
|
String(typeRepo),
|
|
76
60
|
item,
|
|
77
61
|
);
|
|
@@ -88,7 +72,7 @@ const addTypeExtension = async ({
|
|
|
88
72
|
|
|
89
73
|
const deleteTypeExtension = async ({ itemId: typeRepo }: { itemId: ApiId }) => {
|
|
90
74
|
try {
|
|
91
|
-
await typeExtensionsService.
|
|
75
|
+
await typeExtensionsService.deleteTypeExtensions([
|
|
92
76
|
String(typeRepo),
|
|
93
77
|
]);
|
|
94
78
|
} catch (err) {
|
|
@@ -116,18 +100,24 @@ const updateTypeExtension = async ({
|
|
|
116
100
|
}
|
|
117
101
|
|
|
118
102
|
if (!itemInstance.fields.length && !itemInstance.isNew) {
|
|
119
|
-
|
|
103
|
+
await deleteTypeExtension({
|
|
120
104
|
itemId: typeRepo,
|
|
121
105
|
});
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
id: typeRepo,
|
|
109
|
+
fields: [],
|
|
110
|
+
isNew: true,
|
|
111
|
+
};
|
|
122
112
|
}
|
|
123
113
|
|
|
124
114
|
const item = applyTransform(itemInstance, [
|
|
125
115
|
sortDynamicFields,
|
|
116
|
+
sanitizeToWire(fieldsToSend),
|
|
126
117
|
camelToSnake(),
|
|
127
|
-
sanitize(fieldsToSend),
|
|
128
118
|
]);
|
|
129
119
|
try {
|
|
130
|
-
const response = await typeExtensionsService.
|
|
120
|
+
const response = await typeExtensionsService.updateTypeExtensions(
|
|
131
121
|
String(typeRepo),
|
|
132
122
|
item,
|
|
133
123
|
);
|
|
@@ -143,7 +133,7 @@ const updateTypeExtension = async ({
|
|
|
143
133
|
};
|
|
144
134
|
|
|
145
135
|
export const WtTypeExtensionAPI = {
|
|
146
|
-
|
|
136
|
+
get: getTypeExtension,
|
|
147
137
|
add: addTypeExtension,
|
|
148
138
|
update: updateTypeExtension,
|
|
149
139
|
delete: deleteTypeExtension,
|