@webitel/api-services 0.1.60 → 0.1.62
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 +1 -1
- package/src/api/clients/calendars/__tests__/calendars.spec.ts +795 -0
- package/src/api/clients/calendars/calendars.ts +89 -62
- package/src/validations/bucket/bucket.validations.ts +8 -0
- package/src/validations/calendar/__tests__/calendar.validations.spec.ts +526 -0
- package/src/validations/calendar/calendar.validations.ts +181 -0
- package/src/validations/index.ts +2 -0
- package/types/.tsbuildinfo +1 -1
- package/types/api/clients/calendars/calendars.d.ts +7 -0
- package/types/validations/bucket/bucket.validations.d.ts +6 -0
- package/types/validations/calendar/calendar.validations.d.ts +26 -0
- package/types/validations/index.d.ts +2 -0
|
@@ -1,11 +1,6 @@
|
|
|
1
|
+
import { getCalendarService } from '@webitel/api-services/gen';
|
|
1
2
|
import deepCopy from 'deep-copy';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
getDefaultGetListResponse,
|
|
5
|
-
getDefaultGetParams,
|
|
6
|
-
getDefaultInstance,
|
|
7
|
-
getDefaultOpenAPIConfig,
|
|
8
|
-
} from '../../defaults';
|
|
3
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
9
4
|
import {
|
|
10
5
|
applyTransform,
|
|
11
6
|
camelToSnake,
|
|
@@ -15,6 +10,7 @@ import {
|
|
|
15
10
|
snakeToCamel,
|
|
16
11
|
starToSearch,
|
|
17
12
|
} from '../../transformers';
|
|
13
|
+
import { generatePermissionsApi } from '../_shared/generatePermissionsApi';
|
|
18
14
|
import type {
|
|
19
15
|
AddItemParams,
|
|
20
16
|
ApiParams,
|
|
@@ -23,26 +19,71 @@ import type {
|
|
|
23
19
|
UpdateItemParams,
|
|
24
20
|
} from '../_shared/types';
|
|
25
21
|
|
|
26
|
-
const
|
|
27
|
-
const configuration = getDefaultOpenAPIConfig();
|
|
22
|
+
const baseUrl = '/calendars';
|
|
28
23
|
|
|
29
|
-
const
|
|
24
|
+
const mapCalendarToUi = (item: ApiParams) => {
|
|
25
|
+
const copy = deepCopy(item);
|
|
26
|
+
const defaultSingleObject = {
|
|
27
|
+
name: '',
|
|
28
|
+
timezone: {},
|
|
29
|
+
description: '',
|
|
30
|
+
startAt: Date.now(),
|
|
31
|
+
endAt: Date.now(),
|
|
32
|
+
expires: !!(copy.startAt || copy.endAt),
|
|
33
|
+
accepts: [],
|
|
34
|
+
excepts: [],
|
|
35
|
+
specials: [],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
copy.accepts = (copy.accepts || []).map((accept: ApiParams) => ({
|
|
39
|
+
day: accept.day || 0,
|
|
40
|
+
disabled: accept.disabled || false,
|
|
41
|
+
start: accept.startTimeOfDay || 0,
|
|
42
|
+
end: accept.endTimeOfDay || 0,
|
|
43
|
+
}));
|
|
44
|
+
if (copy.specials) {
|
|
45
|
+
copy.specials = copy.specials.map((special: ApiParams) => ({
|
|
46
|
+
day: special.day || 0,
|
|
47
|
+
disabled: special.disabled || false,
|
|
48
|
+
start: special.startTimeOfDay || 0,
|
|
49
|
+
end: special.endTimeOfDay || 0,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
if (copy.excepts) {
|
|
53
|
+
copy.excepts = copy.excepts.map((except: ApiParams) => ({
|
|
54
|
+
name: except.name || '',
|
|
55
|
+
date: except.date || 0,
|
|
56
|
+
repeat: except.repeat || false,
|
|
57
|
+
working: except.working || false,
|
|
58
|
+
workStart: except.workStart || null,
|
|
59
|
+
workStop: except.workStop || null,
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
...defaultSingleObject,
|
|
64
|
+
...copy,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
30
67
|
|
|
31
68
|
const getCalendarList = async (params: ApiParams) => {
|
|
32
|
-
const { page, size,
|
|
69
|
+
const { page, size, q, sort, fields, id } = applyTransform(params, [
|
|
33
70
|
merge(getDefaultGetParams()),
|
|
34
|
-
|
|
71
|
+
(params) => ({
|
|
72
|
+
...params,
|
|
73
|
+
q: params?.q || params?.search,
|
|
74
|
+
}),
|
|
75
|
+
starToSearch('q'),
|
|
35
76
|
]);
|
|
36
77
|
|
|
37
78
|
try {
|
|
38
|
-
const response = await
|
|
79
|
+
const response = await getCalendarService().searchCalendar({
|
|
39
80
|
page,
|
|
40
81
|
size,
|
|
41
|
-
|
|
82
|
+
q,
|
|
42
83
|
sort,
|
|
43
84
|
fields,
|
|
44
85
|
id,
|
|
45
|
-
);
|
|
86
|
+
});
|
|
46
87
|
const { items, next } = applyTransform(response.data, [
|
|
47
88
|
snakeToCamel(),
|
|
48
89
|
merge(getDefaultGetListResponse()),
|
|
@@ -59,46 +100,11 @@ const getCalendarList = async (params: ApiParams) => {
|
|
|
59
100
|
};
|
|
60
101
|
|
|
61
102
|
const getCalendar = async ({ itemId: id }: GetItemParams) => {
|
|
62
|
-
const itemResponseHandler = (item: ApiParams) => {
|
|
63
|
-
const copy = deepCopy(item);
|
|
64
|
-
const defaultSingleObject = {
|
|
65
|
-
name: '',
|
|
66
|
-
timezone: {},
|
|
67
|
-
description: '',
|
|
68
|
-
startAt: Date.now(),
|
|
69
|
-
endAt: Date.now(),
|
|
70
|
-
expires: !!(copy.startAt || copy.endAt),
|
|
71
|
-
accepts: [],
|
|
72
|
-
excepts: [],
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
copy.accepts = copy.accepts.map((accept: ApiParams) => ({
|
|
76
|
-
day: accept.day || 0,
|
|
77
|
-
disabled: accept.disabled || false,
|
|
78
|
-
start: accept.startTimeOfDay || 0,
|
|
79
|
-
end: accept.endTimeOfDay || 0,
|
|
80
|
-
}));
|
|
81
|
-
if (copy.excepts) {
|
|
82
|
-
copy.excepts = copy.excepts.map((except: ApiParams) => ({
|
|
83
|
-
name: except.name || '',
|
|
84
|
-
date: except.date || 0,
|
|
85
|
-
repeat: except.repeat || false,
|
|
86
|
-
working: except.working || false,
|
|
87
|
-
workStart: except.workStart || null,
|
|
88
|
-
workStop: except.workStop || null,
|
|
89
|
-
}));
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
...defaultSingleObject,
|
|
93
|
-
...copy,
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
|
|
97
103
|
try {
|
|
98
|
-
const response = await
|
|
104
|
+
const response = await getCalendarService().readCalendar(String(id));
|
|
99
105
|
return applyTransform(response.data, [
|
|
100
106
|
snakeToCamel(),
|
|
101
|
-
|
|
107
|
+
mapCalendarToUi,
|
|
102
108
|
]);
|
|
103
109
|
} catch (err) {
|
|
104
110
|
throw applyTransform(err, [
|
|
@@ -116,6 +122,7 @@ const fieldsToSend = [
|
|
|
116
122
|
'day',
|
|
117
123
|
'accepts',
|
|
118
124
|
'excepts',
|
|
125
|
+
'specials',
|
|
119
126
|
'startTimeOfDay',
|
|
120
127
|
'endTimeOfDay',
|
|
121
128
|
'disabled',
|
|
@@ -128,18 +135,27 @@ const fieldsToSend = [
|
|
|
128
135
|
|
|
129
136
|
const preRequestHandler = (item: ApiParams) => {
|
|
130
137
|
const copy = deepCopy(item);
|
|
131
|
-
copy.timezone
|
|
138
|
+
if (copy.timezone) {
|
|
139
|
+
copy.timezone.offset = undefined;
|
|
140
|
+
}
|
|
132
141
|
if (!copy.expires) {
|
|
133
142
|
copy.startAt = undefined;
|
|
134
143
|
copy.endAt = undefined;
|
|
135
144
|
}
|
|
136
145
|
|
|
137
|
-
copy.accepts = copy.accepts.map((accept: ApiParams) => ({
|
|
146
|
+
copy.accepts = (copy.accepts || []).map((accept: ApiParams) => ({
|
|
138
147
|
day: accept.day,
|
|
139
148
|
disabled: accept.disabled,
|
|
140
149
|
startTimeOfDay: accept.start,
|
|
141
150
|
endTimeOfDay: accept.end,
|
|
142
151
|
}));
|
|
152
|
+
|
|
153
|
+
copy.specials = (copy.specials || []).map((special: ApiParams) => ({
|
|
154
|
+
day: special.day,
|
|
155
|
+
disabled: special.disabled,
|
|
156
|
+
startTimeOfDay: special.start,
|
|
157
|
+
endTimeOfDay: special.end,
|
|
158
|
+
}));
|
|
143
159
|
return copy;
|
|
144
160
|
};
|
|
145
161
|
|
|
@@ -150,9 +166,10 @@ const addCalendar = async ({ itemInstance }: AddItemParams) => {
|
|
|
150
166
|
camelToSnake(),
|
|
151
167
|
]);
|
|
152
168
|
try {
|
|
153
|
-
const response = await
|
|
169
|
+
const response = await getCalendarService().createCalendar(item);
|
|
154
170
|
return applyTransform(response.data, [
|
|
155
171
|
snakeToCamel(),
|
|
172
|
+
mapCalendarToUi,
|
|
156
173
|
]);
|
|
157
174
|
} catch (err) {
|
|
158
175
|
throw applyTransform(err, [
|
|
@@ -171,9 +188,13 @@ const updateCalendar = async ({
|
|
|
171
188
|
camelToSnake(),
|
|
172
189
|
]);
|
|
173
190
|
try {
|
|
174
|
-
const response = await
|
|
191
|
+
const response = await getCalendarService().updateCalendar(
|
|
192
|
+
String(id),
|
|
193
|
+
item,
|
|
194
|
+
);
|
|
175
195
|
return applyTransform(response.data, [
|
|
176
196
|
snakeToCamel(),
|
|
197
|
+
mapCalendarToUi,
|
|
177
198
|
]);
|
|
178
199
|
} catch (err) {
|
|
179
200
|
throw applyTransform(err, [
|
|
@@ -184,7 +205,7 @@ const updateCalendar = async ({
|
|
|
184
205
|
|
|
185
206
|
const deleteCalendar = async ({ id }: DeleteItemParams) => {
|
|
186
207
|
try {
|
|
187
|
-
const response = await
|
|
208
|
+
const response = await getCalendarService().deleteCalendar(String(id));
|
|
188
209
|
return applyTransform(response.data, []);
|
|
189
210
|
} catch (err) {
|
|
190
211
|
throw applyTransform(err, [
|
|
@@ -203,20 +224,24 @@ const getCalendarsLookup = (params: Parameters<typeof getCalendarList>[0]) =>
|
|
|
203
224
|
});
|
|
204
225
|
|
|
205
226
|
const getTimezonesLookup = async (params: ApiParams) => {
|
|
206
|
-
const { page, size,
|
|
227
|
+
const { page, size, q, sort, fields, id } = applyTransform(params, [
|
|
207
228
|
merge(getDefaultGetParams()),
|
|
208
|
-
|
|
229
|
+
(params) => ({
|
|
230
|
+
...params,
|
|
231
|
+
q: params?.q || params?.search,
|
|
232
|
+
}),
|
|
233
|
+
starToSearch('q'),
|
|
209
234
|
]);
|
|
210
235
|
|
|
211
236
|
try {
|
|
212
|
-
const response = await
|
|
237
|
+
const response = await getCalendarService().searchTimezones({
|
|
213
238
|
page,
|
|
214
239
|
size,
|
|
215
|
-
|
|
240
|
+
q,
|
|
216
241
|
sort,
|
|
217
242
|
fields,
|
|
218
243
|
id,
|
|
219
|
-
);
|
|
244
|
+
});
|
|
220
245
|
const { items, next } = applyTransform(response.data, [
|
|
221
246
|
snakeToCamel(),
|
|
222
247
|
merge(getDefaultGetListResponse()),
|
|
@@ -240,4 +265,6 @@ export const CalendarsAPI = {
|
|
|
240
265
|
delete: deleteCalendar,
|
|
241
266
|
getLookup: getCalendarsLookup,
|
|
242
267
|
getTimezonesLookup,
|
|
268
|
+
|
|
269
|
+
...generatePermissionsApi(baseUrl),
|
|
243
270
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { EngineBucket } from '@webitel/api-services/gen/models';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { ZodShape } from '../types';
|
|
4
|
+
|
|
5
|
+
export const bucketSchema = z.object<ZodShape<EngineBucket>>({
|
|
6
|
+
name: z.string().min(1),
|
|
7
|
+
description: z.string().optional(),
|
|
8
|
+
});
|