@webitel/api-services 0.1.67 → 0.1.69

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.
@@ -1,10 +1,14 @@
1
- import { ServicesApiFactory, WebitelContactsGroupType } from 'webitel-sdk';
2
1
  import {
3
- getDefaultGetListResponse,
4
- getDefaultGetParams,
5
- getDefaultInstance,
6
- getDefaultOpenAPIConfig,
7
- } from '../../defaults';
2
+ CreateServiceBody,
3
+ getServices,
4
+ ListServicesQueryParams,
5
+ UpdateService2Body,
6
+ UpdateServiceBody,
7
+ } from '@webitel/api-services/gen';
8
+ import { ContactsGroupType } from '@webitel/api-services/gen/models';
9
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
10
+
11
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
8
12
  import {
9
13
  applyTransform,
10
14
  camelToSnake,
@@ -22,39 +26,17 @@ import type {
22
26
  PatchItemParams,
23
27
  } from '../_shared/types';
24
28
 
25
- const instance = getDefaultInstance();
26
- const configuration = getDefaultOpenAPIConfig();
27
-
28
- const servicesService = ServicesApiFactory(configuration, '', instance);
29
-
30
- const fieldsToSend = [
31
- 'name',
32
- 'code',
33
- 'sla',
34
- 'status',
35
- 'state',
36
- 'description',
37
- 'group',
38
- 'assignee',
39
- 'services',
40
- 'root_id',
41
- 'catalog_id',
42
- ];
43
-
44
29
  const getServicesList = async ({
30
+ parentId,
45
31
  rootId,
46
32
  ...rest
47
33
  }: {
34
+ parentId?: ApiId;
48
35
  rootId: ApiId;
49
36
  } & ApiParams) => {
50
- const fieldsToSend = [
51
- 'page',
52
- 'size',
53
- 'q',
54
- 'sort',
55
- 'fields',
56
- 'id',
57
- ];
37
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
38
+ ListServicesQueryParams,
39
+ );
58
40
 
59
41
  const { page, size, fields, sort, id, q } = applyTransform(rest, [
60
42
  merge(getDefaultGetParams()),
@@ -66,22 +48,24 @@ const getServicesList = async ({
66
48
  sanitize(fieldsToSend),
67
49
  camelToSnake(),
68
50
  ]);
51
+
69
52
  try {
70
- const response = await servicesService.listServices(
53
+ const response = await getServices().listServices({
71
54
  page,
72
55
  size,
56
+ fields,
73
57
  sort,
74
58
  id,
75
59
  q,
76
- String(rootId),
77
- undefined,
78
- fields,
79
- );
60
+ rootId: String(rootId ?? parentId),
61
+ });
80
62
  const { items, next } = applyTransform(response.data, [
81
63
  merge(getDefaultGetListResponse()),
82
64
  ]);
83
65
  return {
84
- items: applyTransform(items, []),
66
+ items: applyTransform(items, [
67
+ snakeToCamel(),
68
+ ]),
85
69
  next,
86
70
  };
87
71
  } catch (err) {
@@ -101,19 +85,17 @@ const getService = async ({ itemId: id }: GetItemParams) => {
101
85
  'group',
102
86
  'assignee',
103
87
  'description',
88
+ 'default_priority',
104
89
  'catalog_id',
105
90
  'root_id',
106
91
  ];
107
92
 
108
- const itemResponseHandler = (item: ApiParams) => {
109
- return item.service;
110
- };
93
+ const itemResponseHandler = (item: ApiParams) => item.service;
111
94
 
112
95
  try {
113
- const response = await servicesService.locateService(
114
- String(id),
115
- fieldsToSend,
116
- );
96
+ const response = await getServices().locateService(String(id), {
97
+ fields: fieldsToSend,
98
+ });
117
99
  return applyTransform(response.data, [
118
100
  snakeToCamel(),
119
101
  itemResponseHandler,
@@ -135,11 +117,9 @@ const preRequestHandler = ({
135
117
  return (item: ApiParams) => ({
136
118
  ...item,
137
119
  assignee:
138
- item.group?.type === WebitelContactsGroupType.DYNAMIC
139
- ? {}
140
- : item.assignee,
141
- rootId,
142
- catalogId,
120
+ item.group?.type === ContactsGroupType.Dynamic ? {} : item.assignee,
121
+ rootId: rootId ?? item.rootId,
122
+ catalogId: catalogId ?? item.catalogId,
143
123
  });
144
124
  };
145
125
 
@@ -152,17 +132,19 @@ const addService = async ({
152
132
  rootId: ApiId;
153
133
  catalogId: ApiId;
154
134
  }) => {
135
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(CreateServiceBody);
136
+
155
137
  const item = applyTransform(itemInstance, [
156
138
  preRequestHandler({
157
139
  rootId,
158
140
  catalogId,
159
141
  }),
160
- camelToSnake(),
161
142
  sanitize(fieldsToSend),
143
+ camelToSnake(),
162
144
  ]);
163
145
 
164
146
  try {
165
- const response = await servicesService.createService(item);
147
+ const response = await getServices().createService(item);
166
148
  return applyTransform(response.data, [
167
149
  snakeToCamel(),
168
150
  ]);
@@ -184,17 +166,19 @@ const updateService = async ({
184
166
  rootId: ApiId;
185
167
  catalogId: ApiId;
186
168
  }) => {
169
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateServiceBody);
170
+
187
171
  const item = applyTransform(itemInstance, [
188
172
  preRequestHandler({
189
173
  rootId,
190
174
  catalogId,
191
175
  }),
192
- camelToSnake(),
193
176
  sanitize(fieldsToSend),
177
+ camelToSnake(),
194
178
  ]);
195
179
 
196
180
  try {
197
- const response = await servicesService.updateService(String(id), item);
181
+ const response = await getServices().updateService(String(id), item);
198
182
  return applyTransform(response.data, [
199
183
  snakeToCamel(),
200
184
  ]);
@@ -206,12 +190,14 @@ const updateService = async ({
206
190
  };
207
191
 
208
192
  const patchService = async ({ changes, id }: PatchItemParams) => {
193
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateService2Body);
194
+
209
195
  const body = applyTransform(changes, [
210
196
  sanitize(fieldsToSend),
211
197
  camelToSnake(),
212
198
  ]);
213
199
  try {
214
- const response = await servicesService.updateService2(String(id), body);
200
+ const response = await getServices().updateService2(String(id), body);
215
201
  return applyTransform(response.data, [
216
202
  snakeToCamel(),
217
203
  ]);
@@ -224,7 +210,7 @@ const patchService = async ({ changes, id }: PatchItemParams) => {
224
210
 
225
211
  const deleteService = async ({ id }: DeleteItemParams) => {
226
212
  try {
227
- const response = await servicesService.deleteService([
213
+ const response = await getServices().deleteService([
228
214
  String(id),
229
215
  ]);
230
216
  return applyTransform(response.data, []);
@@ -10,6 +10,7 @@ export * from './caseCloseReasonGroups/caseCloseReasonGroups';
10
10
  export * from './caseCloseReasons/caseCloseReasons';
11
11
  export * from './casePriorities/casePriorities';
12
12
  export * from './caseServiceCatalogs/serviceCatalogs';
13
+ export * from './caseServices/services';
13
14
  export * from './caseSources/caseSources';
14
15
  export * from './caseStatusConditions/caseStatusConditions';
15
16
  export * from './caseStatuses/caseStatuses';
@@ -0,0 +1,10 @@
1
+ import type { WebitelCasesCloseReason } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+ import type { ZodShape } from '../types';
4
+
5
+ export const caseCloseReasonSchema = z.object<
6
+ ZodShape<WebitelCasesCloseReason>
7
+ >({
8
+ name: z.string().min(1),
9
+ description: z.string().optional(),
10
+ });
@@ -0,0 +1,10 @@
1
+ import type { WebitelCasesCloseReasonGroup } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+ import type { ZodShape } from '../types';
4
+
5
+ export const caseCloseReasonGroupSchema = z.object<
6
+ ZodShape<WebitelCasesCloseReasonGroup>
7
+ >({
8
+ name: z.string().min(1),
9
+ description: z.string().optional(),
10
+ });
@@ -0,0 +1,15 @@
1
+ import type { WebitelCasesService } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+ import { lookupSchema } from '../_shared/lookup.validations';
4
+ import type { ZodShape } from '../types';
5
+
6
+ export const caseServiceSchema = z.object<ZodShape<WebitelCasesService>>({
7
+ name: z.string().min(1),
8
+ assignee: lookupSchema.optional(),
9
+ group: lookupSchema.optional(),
10
+ sla: lookupSchema.optional(),
11
+ defaultPriority: lookupSchema.optional(),
12
+ code: z.string().optional(),
13
+ description: z.string().optional(),
14
+ state: z.boolean().default(true),
15
+ });
@@ -0,0 +1,23 @@
1
+ import type { WebitelCasesCatalog } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+ import {
4
+ lookupSchema,
5
+ requiredLookupSchema,
6
+ } from '../_shared/lookup.validations';
7
+ import type { ZodShape } from '../types';
8
+
9
+ export const caseServiceCatalogSchema = z.object<ZodShape<WebitelCasesCatalog>>(
10
+ {
11
+ name: z.string().min(1),
12
+ prefix: z.string().min(1),
13
+ status: requiredLookupSchema,
14
+ closeReasonGroup: requiredLookupSchema,
15
+ sla: requiredLookupSchema,
16
+ defaultPriority: requiredLookupSchema,
17
+ teams: z.array(lookupSchema).optional(),
18
+ skills: z.array(lookupSchema).optional(),
19
+ code: z.string().optional(),
20
+ description: z.string().optional(),
21
+ state: z.boolean().default(true),
22
+ },
23
+ );
@@ -3,7 +3,11 @@ export * from './_shared/lookup.validations';
3
3
  export * from './auditForm/auditForm.validations';
4
4
  export * from './bucket/bucket.validations';
5
5
  export * from './calendar/calendar.validations';
6
+ export * from './caseCloseReason/caseCloseReason.validations';
7
+ export * from './caseCloseReasonGroup/caseCloseReasonGroup.validations';
6
8
  export * from './casePriority/casePriority.validations';
9
+ export * from './caseService/caseService.validations';
10
+ export * from './caseServiceCatalog/caseServiceCatalog.validations';
7
11
  export * from './caseSource/caseSource.validations';
8
12
  export * from './caseStatus/caseStatus.validations';
9
13
  export * from './caseStatusCondition/caseStatusCondition.validations';