@webitel/api-services 26.8.15 → 26.8.17
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/users/users.ts +21 -2
- package/src/validations/queueMember/__tests__/queueMember.validations.spec.ts +54 -0
- package/src/validations/queueMember/queueMember.validations.ts +4 -2
- package/types/.tsbuildinfo +1 -1
- package/types/validations/queueMember/queueMember.validations.d.ts +2 -2
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
getDefaultInstance,
|
|
6
6
|
} from '../../defaults';
|
|
7
7
|
import {
|
|
8
|
+
addQueryParamsToUrl,
|
|
8
9
|
applyTransform,
|
|
9
10
|
camelToSnake,
|
|
10
11
|
generateUrl,
|
|
@@ -101,6 +102,7 @@ const getUser = async ({ itemId: id }: GetItemParams) => {
|
|
|
101
102
|
license: [],
|
|
102
103
|
devices: [],
|
|
103
104
|
device: {},
|
|
105
|
+
generateDevice: false,
|
|
104
106
|
variables: [
|
|
105
107
|
{
|
|
106
108
|
key: '',
|
|
@@ -185,8 +187,17 @@ const addUser = async ({ itemInstance }: AddItemParams) => {
|
|
|
185
187
|
'profile',
|
|
186
188
|
]),
|
|
187
189
|
]);
|
|
190
|
+
const url = applyTransform(baseUrl, [
|
|
191
|
+
addQueryParamsToUrl(
|
|
192
|
+
itemInstance.generateDevice
|
|
193
|
+
? [
|
|
194
|
+
'generate_device=true',
|
|
195
|
+
]
|
|
196
|
+
: [],
|
|
197
|
+
),
|
|
198
|
+
]);
|
|
188
199
|
try {
|
|
189
|
-
const response = await instance.post(
|
|
200
|
+
const response = await instance.post(url, item);
|
|
190
201
|
return applyTransform(response.data, [
|
|
191
202
|
snakeToCamel([
|
|
192
203
|
'profile',
|
|
@@ -208,7 +219,15 @@ const updateUser = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
|
|
|
208
219
|
]),
|
|
209
220
|
]);
|
|
210
221
|
|
|
211
|
-
const url = `${baseUrl}/${id}
|
|
222
|
+
const url = applyTransform(`${baseUrl}/${id}`, [
|
|
223
|
+
addQueryParamsToUrl(
|
|
224
|
+
itemInstance.generateDevice
|
|
225
|
+
? [
|
|
226
|
+
'generate_device=true',
|
|
227
|
+
]
|
|
228
|
+
: [],
|
|
229
|
+
),
|
|
230
|
+
]);
|
|
212
231
|
try {
|
|
213
232
|
const response = await instance.put(url, item);
|
|
214
233
|
return applyTransform(response.data, [
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getDefaultsFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import { addDays } from 'date-fns';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import { queueMemberSchema } from '../queueMember.validations';
|
|
6
|
+
|
|
7
|
+
const filledCommunication = {
|
|
8
|
+
destination: '380000000000',
|
|
9
|
+
type: {
|
|
10
|
+
id: '1',
|
|
11
|
+
name: 'phone',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('queueMemberSchema', () => {
|
|
16
|
+
/** the card store seeds a new item from the schema defaults */
|
|
17
|
+
it('seeds a new member with the defaults the form expects', () => {
|
|
18
|
+
const defaults = getDefaultsFromZodSchema(queueMemberSchema, {}) as {
|
|
19
|
+
priority?: number;
|
|
20
|
+
expireAt?: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
expect(defaults.priority).toBe(0);
|
|
24
|
+
expect(defaults.expireAt).toBeCloseTo(addDays(Date.now(), 7).getTime(), -4);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('keeps values already on the draft', () => {
|
|
28
|
+
expect(
|
|
29
|
+
getDefaultsFromZodSchema(queueMemberSchema, {
|
|
30
|
+
name: 'member',
|
|
31
|
+
priority: 5,
|
|
32
|
+
expireAt: 1_700_000_000_000,
|
|
33
|
+
communications: [
|
|
34
|
+
filledCommunication,
|
|
35
|
+
],
|
|
36
|
+
}),
|
|
37
|
+
).toMatchObject({
|
|
38
|
+
priority: 5,
|
|
39
|
+
expireAt: 1_700_000_000_000,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('still requires a name and a communication', () => {
|
|
44
|
+
const result = queueMemberSchema.safeParse({});
|
|
45
|
+
|
|
46
|
+
expect(result.success).toBe(false);
|
|
47
|
+
expect(result.error?.issues.map((issue) => issue.path.join('.'))).toEqual(
|
|
48
|
+
expect.arrayContaining([
|
|
49
|
+
'name',
|
|
50
|
+
'communications',
|
|
51
|
+
]),
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { addDays } from 'date-fns';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
|
|
3
4
|
import { flexibleLookupSchema } from '../_shared/lookup.validations';
|
|
@@ -17,7 +18,7 @@ export const queueMemberSchema = z.object({
|
|
|
17
18
|
name: z.string().min(1),
|
|
18
19
|
/** legacy `requiredArrayValue` — a member with no way to reach it is useless */
|
|
19
20
|
communications: z.array(memberCommunicationSchema).min(1),
|
|
20
|
-
priority: z.number().optional(),
|
|
21
|
+
priority: z.number().optional().default(0),
|
|
21
22
|
bucket: flexibleLookupSchema.optional(),
|
|
22
23
|
timezone: flexibleLookupSchema.optional(),
|
|
23
24
|
agent: flexibleLookupSchema.optional(),
|
|
@@ -26,7 +27,8 @@ export const queueMemberSchema = z.object({
|
|
|
26
27
|
z.string(),
|
|
27
28
|
z.number(),
|
|
28
29
|
])
|
|
29
|
-
.optional()
|
|
30
|
+
.optional()
|
|
31
|
+
.default(() => addDays(Date.now(), 7).getTime()),
|
|
30
32
|
minOfferingAt: z
|
|
31
33
|
.union([
|
|
32
34
|
z.string(),
|