@webitel/api-services 26.12.37 → 26.12.39
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/workingConditions/__tests__/workingConditions.spec.ts +40 -0
- package/src/api/clients/workingConditions/workingConditions.ts +11 -0
- package/src/validations/_shared/__tests__/timeRange.validations.spec.ts +21 -3
- package/src/validations/_shared/timeRange.validations.ts +25 -5
- package/src/validations/shiftTemplate/__tests__/shiftTemplate.validations.spec.ts +19 -17
- package/src/validations/shiftTemplate/shiftTemplate.validations.ts +12 -3
- package/types/.tsbuildinfo +1 -1
- package/types/validations/_shared/timeRange.validations.d.ts +5 -2
package/package.json
CHANGED
|
@@ -146,6 +146,46 @@ describe('WorkingConditionsAPI', () => {
|
|
|
146
146
|
});
|
|
147
147
|
});
|
|
148
148
|
|
|
149
|
+
it.each([
|
|
150
|
+
'add',
|
|
151
|
+
'update',
|
|
152
|
+
] as const)('%s sends a cleared shift template (`{}`) as null', async (method) => {
|
|
153
|
+
await WorkingConditionsAPI[method]({
|
|
154
|
+
itemId: '1',
|
|
155
|
+
itemInstance: {
|
|
156
|
+
...formItem,
|
|
157
|
+
shiftTemplate: {},
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const serviceMethod =
|
|
162
|
+
method === 'add'
|
|
163
|
+
? service.workingConditionServiceCreateWorkingCondition
|
|
164
|
+
: service.workingConditionServiceUpdateWorkingCondition;
|
|
165
|
+
const body = serviceMethod.mock.calls[0].at(-1);
|
|
166
|
+
expect(body.item.shift_template).toBeNull();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('keeps a selected shift template', async () => {
|
|
170
|
+
await WorkingConditionsAPI.update({
|
|
171
|
+
itemId: '1',
|
|
172
|
+
itemInstance: {
|
|
173
|
+
...formItem,
|
|
174
|
+
shiftTemplate: {
|
|
175
|
+
id: '3',
|
|
176
|
+
name: 'Full time',
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const [, body] =
|
|
182
|
+
service.workingConditionServiceUpdateWorkingCondition.mock.calls[0];
|
|
183
|
+
expect(body.item.shift_template).toEqual({
|
|
184
|
+
id: '3',
|
|
185
|
+
name: 'Full time',
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
149
189
|
it('update sends the id separately and drops it from the item', async () => {
|
|
150
190
|
await WorkingConditionsAPI.update({
|
|
151
191
|
itemId: '1',
|
|
@@ -33,6 +33,15 @@ const itemResponseHandler = (response: ApiParams) => ({
|
|
|
33
33
|
...response.item,
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
+
const clearEmptyShiftTemplate = (item: ApiParams) => ({
|
|
37
|
+
...item,
|
|
38
|
+
...(item.shiftTemplate && !item.shiftTemplate.id
|
|
39
|
+
? {
|
|
40
|
+
shiftTemplate: null,
|
|
41
|
+
}
|
|
42
|
+
: {}),
|
|
43
|
+
});
|
|
44
|
+
|
|
36
45
|
const getWorkingConditionsList = async (params: ApiParams) => {
|
|
37
46
|
const requestParams = applyTransform(params, [
|
|
38
47
|
merge(getDefaultGetParams()),
|
|
@@ -89,6 +98,7 @@ const getWorkingCondition = async ({ itemId: id }: GetItemParams) => {
|
|
|
89
98
|
const addWorkingCondition = async ({ itemInstance }: AddItemParams) => {
|
|
90
99
|
const item = applyTransform(itemInstance, [
|
|
91
100
|
sanitizeToWire(fieldsToSend),
|
|
101
|
+
clearEmptyShiftTemplate,
|
|
92
102
|
camelToSnake(),
|
|
93
103
|
]);
|
|
94
104
|
try {
|
|
@@ -115,6 +125,7 @@ const updateWorkingCondition = async ({
|
|
|
115
125
|
}: UpdateItemParams) => {
|
|
116
126
|
const item = applyTransform(itemInstance, [
|
|
117
127
|
sanitizeToWire(fieldsToSend),
|
|
128
|
+
clearEmptyShiftTemplate,
|
|
118
129
|
camelToSnake(),
|
|
119
130
|
]);
|
|
120
131
|
try {
|
|
@@ -24,10 +24,17 @@ describe('getTimeRangeDuration', () => {
|
|
|
24
24
|
],
|
|
25
25
|
[
|
|
26
26
|
{
|
|
27
|
-
start:
|
|
28
|
-
end:
|
|
27
|
+
start: 1320,
|
|
28
|
+
end: 360,
|
|
29
29
|
},
|
|
30
|
-
|
|
30
|
+
480,
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
{
|
|
34
|
+
start: 1320,
|
|
35
|
+
end: 0,
|
|
36
|
+
},
|
|
37
|
+
120,
|
|
31
38
|
],
|
|
32
39
|
[
|
|
33
40
|
{
|
|
@@ -59,6 +66,17 @@ describe('setTimeRangeDuration', () => {
|
|
|
59
66
|
});
|
|
60
67
|
});
|
|
61
68
|
|
|
69
|
+
it('wraps end past midnight', () => {
|
|
70
|
+
const range = {
|
|
71
|
+
start: 1320,
|
|
72
|
+
end: 1380,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
setTimeRangeDuration(range, 480);
|
|
76
|
+
|
|
77
|
+
expect(range.end).toBe(360);
|
|
78
|
+
});
|
|
79
|
+
|
|
62
80
|
it('counts from 0 when start is unset', () => {
|
|
63
81
|
const range: Partial<TimeRange> = {};
|
|
64
82
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { minutesInDay } from 'date-fns/constants';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
|
|
3
4
|
import { i18nIssue } from './i18nIssue';
|
|
@@ -5,7 +6,10 @@ import { i18nIssue } from './i18nIssue';
|
|
|
5
6
|
export const dayMinuteSchema = z
|
|
6
7
|
.number()
|
|
7
8
|
.int()
|
|
8
|
-
.refine(
|
|
9
|
+
.refine(
|
|
10
|
+
(value) => value >= 0 && value < minutesInDay,
|
|
11
|
+
i18nIssue('hourRange'),
|
|
12
|
+
);
|
|
9
13
|
|
|
10
14
|
export type TimeRange = {
|
|
11
15
|
start: number;
|
|
@@ -47,6 +51,21 @@ export const refineTimeRangeStartLessThanEnd = (
|
|
|
47
51
|
if (item.start >= item.end) addRangeIssue(ctx, 'timerangeStartLessThanEnd');
|
|
48
52
|
};
|
|
49
53
|
|
|
54
|
+
/** [Claude] an empty range (start = end) is reported once, on `end` */
|
|
55
|
+
export const refineTimeRangeEndNotEqualStart = (
|
|
56
|
+
item: TimeRange,
|
|
57
|
+
ctx: z.RefinementCtx,
|
|
58
|
+
) => {
|
|
59
|
+
if (item.start !== item.end) return;
|
|
60
|
+
ctx.addIssue({
|
|
61
|
+
code: 'custom',
|
|
62
|
+
path: [
|
|
63
|
+
'end',
|
|
64
|
+
],
|
|
65
|
+
...i18nIssue('timerangeEndNotEqualStart'),
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
50
69
|
export const timeRangeSchema = z
|
|
51
70
|
.object({
|
|
52
71
|
start: dayMinuteSchema,
|
|
@@ -55,19 +74,20 @@ export const timeRangeSchema = z
|
|
|
55
74
|
.superRefine(refineTimeRangeStartLessThanEnd);
|
|
56
75
|
|
|
57
76
|
/**
|
|
58
|
-
* [Claude] range length in minutes
|
|
77
|
+
* [Claude] range length in minutes, crossing midnight when `end` is before `start`
|
|
78
|
+
* (22:00–06:00 → 8h); an unset bound counts as 0
|
|
59
79
|
*/
|
|
60
80
|
export const getTimeRangeDuration = (range: Partial<TimeRange>) =>
|
|
61
|
-
|
|
81
|
+
((range.end ?? 0) - (range.start ?? 0) + minutesInDay) % minutesInDay;
|
|
62
82
|
|
|
63
83
|
/**
|
|
64
|
-
* [Claude] sets the length by moving `end
|
|
84
|
+
* [Claude] sets the length by moving `end`, wrapping past midnight; `start` stays
|
|
65
85
|
*/
|
|
66
86
|
export const setTimeRangeDuration = (
|
|
67
87
|
range: Partial<TimeRange>,
|
|
68
88
|
minutes: number,
|
|
69
89
|
) => {
|
|
70
|
-
range.end = (range.start ?? 0) + minutes;
|
|
90
|
+
range.end = ((range.start ?? 0) + minutes) % minutesInDay;
|
|
71
91
|
};
|
|
72
92
|
|
|
73
93
|
const isIntersecting = (a: TimeRange, b: TimeRange) =>
|
|
@@ -77,14 +77,21 @@ describe('shiftTemplateSchema', () => {
|
|
|
77
77
|
).toBe(false);
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
it('accepts an overnight row (end before start)', () => {
|
|
81
|
+
expect(
|
|
82
|
+
shiftTemplateSchema.safeParse({
|
|
83
|
+
...valid,
|
|
84
|
+
times: [
|
|
85
|
+
{
|
|
86
|
+
start: 1320,
|
|
87
|
+
end: 360,
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
}).success,
|
|
91
|
+
).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
|
|
80
94
|
it.each([
|
|
81
|
-
[
|
|
82
|
-
'end before start',
|
|
83
|
-
{
|
|
84
|
-
start: 600,
|
|
85
|
-
end: 540,
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
95
|
[
|
|
89
96
|
'zero duration',
|
|
90
97
|
{
|
|
@@ -118,28 +125,23 @@ describe('shiftTemplateSchema', () => {
|
|
|
118
125
|
});
|
|
119
126
|
|
|
120
127
|
describe('getShiftTemplateTimeRangeErrors', () => {
|
|
121
|
-
it('marks
|
|
128
|
+
it('marks only the end of a row whose start equals its end', () => {
|
|
122
129
|
expect(
|
|
123
130
|
getShiftTemplateTimeRangeErrors([
|
|
124
131
|
{
|
|
125
|
-
start:
|
|
126
|
-
end:
|
|
132
|
+
start: 1320,
|
|
133
|
+
end: 360,
|
|
127
134
|
},
|
|
128
135
|
{
|
|
129
136
|
start: 600,
|
|
130
|
-
end:
|
|
137
|
+
end: 600,
|
|
131
138
|
},
|
|
132
139
|
]),
|
|
133
140
|
).toEqual([
|
|
134
|
-
{
|
|
135
|
-
index: 1,
|
|
136
|
-
prop: 'start',
|
|
137
|
-
key: 'timerangeStartLessThanEnd',
|
|
138
|
-
},
|
|
139
141
|
{
|
|
140
142
|
index: 1,
|
|
141
143
|
prop: 'end',
|
|
142
|
-
key: '
|
|
144
|
+
key: 'timerangeEndNotEqualStart',
|
|
143
145
|
},
|
|
144
146
|
]);
|
|
145
147
|
});
|
|
@@ -2,16 +2,25 @@ import type { WfmShiftTemplate } from '@webitel/api-services/gen/models';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
+
dayMinuteSchema,
|
|
5
6
|
getTimeRangeErrors,
|
|
7
|
+
refineTimeRangeEndNotEqualStart,
|
|
6
8
|
type TimeRange,
|
|
7
|
-
timeRangeSchema,
|
|
8
9
|
} from '../_shared/timeRange.validations';
|
|
9
10
|
import type { ZodShape } from '../types';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* [Claude] each row is a part of the shift
|
|
13
|
+
* [Claude] each row is a part of the shift, in minutes of the day; it may cross
|
|
14
|
+
* midnight (22:00–06:00), so only start = end is rejected, under `end`
|
|
13
15
|
*/
|
|
14
|
-
const
|
|
16
|
+
const shiftTemplateTimeSchema = z
|
|
17
|
+
.object({
|
|
18
|
+
start: dayMinuteSchema,
|
|
19
|
+
end: dayMinuteSchema,
|
|
20
|
+
})
|
|
21
|
+
.superRefine(refineTimeRangeEndNotEqualStart);
|
|
22
|
+
|
|
23
|
+
const shiftTemplateTimesSchema = z.array(shiftTemplateTimeSchema).min(1);
|
|
15
24
|
|
|
16
25
|
/**
|
|
17
26
|
* [Claude] row errors for `useTimeRangesValidation`: regle marks a row as a plain field,
|