@webitel/api-services 26.8.76 → 26.8.78

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/api-services",
3
- "version": "26.8.76",
3
+ "version": "26.8.78",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,144 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ const wireItem = {
4
+ id: '1',
5
+ name: 'lunch',
6
+ description: 'desc',
7
+ causes: [
8
+ {
9
+ cause: {
10
+ id: '7',
11
+ name: 'Coffee',
12
+ },
13
+ duration: '15',
14
+ },
15
+ ],
16
+ domain_id: '1',
17
+ };
18
+
19
+ const service = {
20
+ pauseTemplateServiceSearchPauseTemplate: vi.fn(() =>
21
+ Promise.resolve({
22
+ data: {
23
+ items: [
24
+ wireItem,
25
+ ],
26
+ next: true,
27
+ },
28
+ }),
29
+ ),
30
+ pauseTemplateServiceReadPauseTemplate: vi.fn(() =>
31
+ Promise.resolve({
32
+ data: {
33
+ item: wireItem,
34
+ },
35
+ }),
36
+ ),
37
+ pauseTemplateServiceCreatePauseTemplate: vi.fn(() =>
38
+ Promise.resolve({
39
+ data: {
40
+ item: wireItem,
41
+ },
42
+ }),
43
+ ),
44
+ pauseTemplateServiceUpdatePauseTemplate: vi.fn(() =>
45
+ Promise.resolve({
46
+ data: {
47
+ item: wireItem,
48
+ },
49
+ }),
50
+ ),
51
+ };
52
+
53
+ vi.mock('../../../../gen-wire', async (importOriginal) => ({
54
+ ...(await importOriginal<Record<string, unknown>>()),
55
+ getPauseTemplateService: () => service,
56
+ }));
57
+
58
+ const { PauseTemplatesAPI } = await import('../pauseTemplates');
59
+
60
+ const formItem = {
61
+ id: '1',
62
+ name: 'lunch',
63
+ description: 'desc',
64
+ causes: [
65
+ {
66
+ cause: {
67
+ id: '7',
68
+ name: 'Coffee',
69
+ },
70
+ duration: 15,
71
+ },
72
+ {
73
+ duration: 30,
74
+ },
75
+ ],
76
+ domainId: '1',
77
+ _dirty: true,
78
+ };
79
+
80
+ describe('PauseTemplatesAPI', () => {
81
+ beforeEach(() => {
82
+ vi.clearAllMocks();
83
+ });
84
+
85
+ it('getList sends the search as `q`', async () => {
86
+ const { items, next } = await PauseTemplatesAPI.getList({
87
+ search: 'lun',
88
+ page: 2,
89
+ size: 10,
90
+ });
91
+
92
+ expect(
93
+ service.pauseTemplateServiceSearchPauseTemplate,
94
+ ).toHaveBeenCalledWith(
95
+ expect.objectContaining({
96
+ q: 'lun*',
97
+ page: 2,
98
+ size: 10,
99
+ }),
100
+ );
101
+ expect(items[0].domainId).toBe('1');
102
+ expect(next).toBe(true);
103
+ });
104
+
105
+ it('get unwraps the `item` envelope and keeps causes nested', async () => {
106
+ const item = await PauseTemplatesAPI.get({
107
+ itemId: '1',
108
+ });
109
+
110
+ expect(item.name).toBe('lunch');
111
+ expect(item.causes).toEqual(wireItem.causes);
112
+ });
113
+
114
+ it('add wraps the item and sends only the form fields', async () => {
115
+ await PauseTemplatesAPI.add({
116
+ itemInstance: formItem,
117
+ });
118
+
119
+ const [body] =
120
+ service.pauseTemplateServiceCreatePauseTemplate.mock.calls[0];
121
+ expect(body).toEqual({
122
+ item: {
123
+ name: 'lunch',
124
+ description: 'desc',
125
+ causes: formItem.causes,
126
+ },
127
+ });
128
+ });
129
+
130
+ it('update sends the id separately and drops it from the item', async () => {
131
+ await PauseTemplatesAPI.update({
132
+ itemId: '1',
133
+ itemInstance: formItem,
134
+ });
135
+
136
+ const [id, body] =
137
+ service.pauseTemplateServiceUpdatePauseTemplate.mock.calls[0];
138
+ expect(id).toBe('1');
139
+ expect(body.item).not.toHaveProperty('id');
140
+ expect(body.item).not.toHaveProperty('domain_id');
141
+ expect(body.item).not.toHaveProperty('_dirty');
142
+ expect(body.item.causes).toEqual(formItem.causes);
143
+ });
144
+ });
@@ -1,13 +1,18 @@
1
- import deepCopy from 'deep-copy';
2
- import { getPauseTemplateService } from '../../../gen-wire';
1
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
2
+ import { pauseTemplateSchema } from '@webitel/api-services/validations';
3
+ import {
4
+ getPauseTemplateService,
5
+ PauseTemplateServiceSearchPauseTemplateQueryParams,
6
+ } from '../../../gen-wire';
3
7
  import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
4
8
  import {
5
9
  applyTransform,
6
10
  camelToSnake,
7
11
  merge,
8
12
  notify,
9
- sanitize,
13
+ sanitizeToWire,
10
14
  snakeToCamel,
15
+ starToSearch,
11
16
  } from '../../transformers';
12
17
  import type {
13
18
  AddItemParams,
@@ -17,71 +22,36 @@ import type {
17
22
  UpdateItemParams,
18
23
  } from '../_shared/types';
19
24
 
20
- const fieldsToSend = [
21
- 'name',
22
- 'description',
23
- 'causes',
24
- 'domainId',
25
- 'createdAt',
26
- 'createdBy',
27
- 'updatedAt',
28
- 'updatedBy',
29
- ];
25
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(pauseTemplateSchema);
30
26
 
31
27
  /**
32
- * WFM services wrap both request and response payloads in an `item` envelope,
33
- * and nest each pause cause under a `cause` key. The form binds a flat
34
- * `{ id, name, duration }`.
28
+ * [Claude] WFM services wrap both request and response payloads in an `item` envelope.
35
29
  */
36
- const itemResponseHandler = (response: ApiParams) => {
37
- const item = {
38
- ...response.item,
39
- };
40
-
41
- item.causes = item.causes?.map((cause: ApiParams) => ({
42
- id: cause.cause?.id,
43
- name: cause.cause?.name,
44
- duration: cause?.duration,
45
- }));
46
-
47
- return item;
48
- };
49
-
50
- const preRequestHandler = (item: ApiParams) => {
51
- const copy = deepCopy(item);
52
- copy.causes = copy.causes.map((cause: ApiParams) => {
53
- if (!cause.name && !cause.id) return cause;
54
- return {
55
- cause: {
56
- id: cause?.id,
57
- name: cause?.name,
58
- },
59
- duration: cause.duration,
60
- };
61
- });
62
- return copy;
63
- };
30
+ const itemResponseHandler = (response: ApiParams) => ({
31
+ ...response.item,
32
+ });
64
33
 
65
34
  const getPauseTemplatesList = async (params: ApiParams) => {
66
- const {
67
- search: q,
68
- page,
69
- size,
70
- sort,
71
- fields,
72
- } = applyTransform(params, [
35
+ const requestParams = applyTransform(params, [
73
36
  merge(getDefaultGetParams()),
37
+ starToSearch('search'),
38
+ (params: ApiParams) => ({
39
+ ...params,
40
+ q: params.q ?? params.search,
41
+ }),
42
+ sanitizeToWire(
43
+ getShallowFieldsToSendFromZodSchema(
44
+ PauseTemplateServiceSearchPauseTemplateQueryParams,
45
+ ),
46
+ ),
47
+ camelToSnake(),
74
48
  ]);
75
49
 
76
50
  try {
77
51
  const response =
78
- await getPauseTemplateService().pauseTemplateServiceSearchPauseTemplate({
79
- q,
80
- page,
81
- size,
82
- sort,
83
- fields,
84
- });
52
+ await getPauseTemplateService().pauseTemplateServiceSearchPauseTemplate(
53
+ requestParams,
54
+ );
85
55
  const { items, next } = applyTransform(response.data, [
86
56
  snakeToCamel(),
87
57
  merge(getDefaultGetListResponse()),
@@ -116,16 +86,13 @@ const getPauseTemplate = async ({ itemId: id }: GetItemParams) => {
116
86
 
117
87
  const addPauseTemplate = async ({ itemInstance }: AddItemParams) => {
118
88
  const item = applyTransform(itemInstance, [
119
- sanitize(fieldsToSend),
89
+ sanitizeToWire(fieldsToSend),
120
90
  camelToSnake(),
121
- preRequestHandler,
122
91
  ]);
123
92
  try {
124
93
  const response =
125
94
  await getPauseTemplateService().pauseTemplateServiceCreatePauseTemplate({
126
- item: {
127
- ...item,
128
- },
95
+ item,
129
96
  });
130
97
  return applyTransform(response.data, [
131
98
  snakeToCamel(),
@@ -143,18 +110,15 @@ const updatePauseTemplate = async ({
143
110
  itemId: id,
144
111
  }: UpdateItemParams) => {
145
112
  const item = applyTransform(itemInstance, [
146
- sanitize(fieldsToSend),
113
+ sanitizeToWire(fieldsToSend),
147
114
  camelToSnake(),
148
- preRequestHandler,
149
115
  ]);
150
116
  try {
151
117
  const response =
152
118
  await getPauseTemplateService().pauseTemplateServiceUpdatePauseTemplate(
153
119
  String(id),
154
120
  {
155
- item: {
156
- ...item,
157
- },
121
+ item,
158
122
  },
159
123
  );
160
124
  return applyTransform(response.data, [
@@ -182,9 +146,7 @@ const deletePauseTemplate = async ({ id }: DeleteItemParams) => {
182
146
  }
183
147
  };
184
148
 
185
- const getPauseTemplatesLookup = (
186
- params: Parameters<typeof getPauseTemplatesList>[0],
187
- ) =>
149
+ const getPauseTemplatesLookup = (params: ApiParams) =>
188
150
  getPauseTemplatesList({
189
151
  ...params,
190
152
  fields: params.fields || [
@@ -0,0 +1,162 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ const wireItem = {
4
+ id: '1',
5
+ name: 'FTE 1',
6
+ description: 'desc',
7
+ workday_hours: 9,
8
+ workdays_per_month: 20,
9
+ vacation: 24,
10
+ sick_leaves: 10,
11
+ days_off: 5,
12
+ pause_duration: 60,
13
+ pause_template: {
14
+ id: '7',
15
+ name: '30-15-15',
16
+ },
17
+ shift_template: {
18
+ id: '3',
19
+ name: 'Full time',
20
+ },
21
+ domain_id: '1',
22
+ };
23
+
24
+ const service = {
25
+ workingConditionServiceSearchWorkingCondition: vi.fn(() =>
26
+ Promise.resolve({
27
+ data: {
28
+ items: [
29
+ wireItem,
30
+ ],
31
+ next: true,
32
+ },
33
+ }),
34
+ ),
35
+ workingConditionServiceReadWorkingCondition: vi.fn(() =>
36
+ Promise.resolve({
37
+ data: {
38
+ item: wireItem,
39
+ },
40
+ }),
41
+ ),
42
+ workingConditionServiceCreateWorkingCondition: vi.fn(() =>
43
+ Promise.resolve({
44
+ data: {
45
+ item: wireItem,
46
+ },
47
+ }),
48
+ ),
49
+ workingConditionServiceUpdateWorkingCondition: vi.fn(() =>
50
+ Promise.resolve({
51
+ data: {
52
+ item: wireItem,
53
+ },
54
+ }),
55
+ ),
56
+ };
57
+
58
+ vi.mock('../../../../gen-wire', async (importOriginal) => ({
59
+ ...(await importOriginal<Record<string, unknown>>()),
60
+ getWorkingConditionService: () => service,
61
+ }));
62
+
63
+ const { WorkingConditionsAPI } = await import('../workingConditions');
64
+
65
+ const formItem = {
66
+ id: '1',
67
+ name: 'FTE 1',
68
+ description: 'desc',
69
+ workdayHours: 9,
70
+ workdaysPerMonth: 20,
71
+ vacation: 24,
72
+ sickLeaves: 10,
73
+ daysOff: 5,
74
+ pauseDuration: 60,
75
+ pauseTemplate: {
76
+ id: '7',
77
+ name: '30-15-15',
78
+ },
79
+ shiftTemplate: null,
80
+ domainId: '1',
81
+ createdAt: '1',
82
+ _dirty: true,
83
+ };
84
+
85
+ describe('WorkingConditionsAPI', () => {
86
+ beforeEach(() => {
87
+ vi.clearAllMocks();
88
+ });
89
+
90
+ it('getList sends the search as `q`', async () => {
91
+ const { items, next } = await WorkingConditionsAPI.getList({
92
+ search: 'fte',
93
+ page: 2,
94
+ size: 10,
95
+ });
96
+
97
+ expect(
98
+ service.workingConditionServiceSearchWorkingCondition,
99
+ ).toHaveBeenCalledWith(
100
+ expect.objectContaining({
101
+ q: 'fte*',
102
+ page: 2,
103
+ size: 10,
104
+ }),
105
+ );
106
+ expect(items[0].workdaysPerMonth).toBe(20);
107
+ expect(next).toBe(true);
108
+ });
109
+
110
+ it('get and update unwrap the `item` envelope', async () => {
111
+ const item = await WorkingConditionsAPI.get({
112
+ itemId: '1',
113
+ });
114
+ expect(item.pauseTemplate).toEqual(wireItem.pause_template);
115
+
116
+ const updated = await WorkingConditionsAPI.update({
117
+ itemId: '1',
118
+ itemInstance: formItem,
119
+ });
120
+ expect(updated.name).toBe('FTE 1');
121
+ });
122
+
123
+ it('add wraps the item and sends only the form fields', async () => {
124
+ await WorkingConditionsAPI.add({
125
+ itemInstance: formItem,
126
+ });
127
+
128
+ const [body] =
129
+ service.workingConditionServiceCreateWorkingCondition.mock.calls[0];
130
+ expect(body).toEqual({
131
+ item: {
132
+ name: 'FTE 1',
133
+ description: 'desc',
134
+ workday_hours: 9,
135
+ workdays_per_month: 20,
136
+ vacation: 24,
137
+ sick_leaves: 10,
138
+ days_off: 5,
139
+ pause_duration: 60,
140
+ pause_template: {
141
+ id: '7',
142
+ name: '30-15-15',
143
+ },
144
+ shift_template: null,
145
+ },
146
+ });
147
+ });
148
+
149
+ it('update sends the id separately and drops it from the item', async () => {
150
+ await WorkingConditionsAPI.update({
151
+ itemId: '1',
152
+ itemInstance: formItem,
153
+ });
154
+
155
+ const [id, body] =
156
+ service.workingConditionServiceUpdateWorkingCondition.mock.calls[0];
157
+ expect(id).toBe('1');
158
+ expect(body.item).not.toHaveProperty('id');
159
+ expect(body.item).not.toHaveProperty('domain_id');
160
+ expect(body.item).not.toHaveProperty('_dirty');
161
+ });
162
+ });
@@ -1,12 +1,18 @@
1
- import { getWorkingConditionService } from '../../../gen-wire';
1
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
2
+ import { workingConditionSchema } from '@webitel/api-services/validations';
3
+ import {
4
+ getWorkingConditionService,
5
+ WorkingConditionServiceSearchWorkingConditionQueryParams,
6
+ } from '../../../gen-wire';
2
7
  import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
3
8
  import {
4
9
  applyTransform,
5
10
  camelToSnake,
6
11
  merge,
7
12
  notify,
8
- sanitize,
13
+ sanitizeToWire,
9
14
  snakeToCamel,
15
+ starToSearch,
10
16
  } from '../../transformers';
11
17
  import type {
12
18
  AddItemParams,
@@ -16,53 +22,37 @@ import type {
16
22
  UpdateItemParams,
17
23
  } from '../_shared/types';
18
24
 
19
- const fieldsToSend = [
20
- 'name',
21
- 'description',
22
- 'workdayHours',
23
- 'workdayPerMonth',
24
- 'pauseDuration',
25
- 'vacation',
26
- 'pauseTemplate',
27
- 'sickLeaves',
28
- 'shiftTemplate',
29
- 'daysOff',
30
- 'createdAt',
31
- 'createdBy',
32
- 'domainId',
33
- 'id',
34
- 'updatedAt',
35
- 'updatedBy',
36
- ];
25
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
26
+ workingConditionSchema,
27
+ );
37
28
 
38
29
  /**
39
- * WFM services wrap both request and response payloads in an `item` envelope.
30
+ * [Claude] WFM services wrap both request and response payloads in an `item` envelope.
40
31
  */
41
32
  const itemResponseHandler = (response: ApiParams) => ({
42
33
  ...response.item,
43
34
  });
44
35
 
45
36
  const getWorkingConditionsList = async (params: ApiParams) => {
46
- const {
47
- search: q,
48
- page,
49
- size,
50
- sort,
51
- fields,
52
- } = applyTransform(params, [
37
+ const requestParams = applyTransform(params, [
53
38
  merge(getDefaultGetParams()),
39
+ starToSearch('search'),
40
+ (params: ApiParams) => ({
41
+ ...params,
42
+ q: params.q ?? params.search,
43
+ }),
44
+ sanitizeToWire(
45
+ getShallowFieldsToSendFromZodSchema(
46
+ WorkingConditionServiceSearchWorkingConditionQueryParams,
47
+ ),
48
+ ),
49
+ camelToSnake(),
54
50
  ]);
55
51
 
56
52
  try {
57
53
  const response =
58
54
  await getWorkingConditionService().workingConditionServiceSearchWorkingCondition(
59
- {
60
- page,
61
- size,
62
- q,
63
- sort,
64
- fields,
65
- },
55
+ requestParams,
66
56
  );
67
57
  const { items, next } = applyTransform(response.data, [
68
58
  snakeToCamel(),
@@ -98,16 +88,14 @@ const getWorkingCondition = async ({ itemId: id }: GetItemParams) => {
98
88
 
99
89
  const addWorkingCondition = async ({ itemInstance }: AddItemParams) => {
100
90
  const item = applyTransform(itemInstance, [
101
- sanitize(fieldsToSend),
91
+ sanitizeToWire(fieldsToSend),
102
92
  camelToSnake(),
103
93
  ]);
104
94
  try {
105
95
  const response =
106
96
  await getWorkingConditionService().workingConditionServiceCreateWorkingCondition(
107
97
  {
108
- item: {
109
- ...item,
110
- },
98
+ item,
111
99
  },
112
100
  );
113
101
  return applyTransform(response.data, [
@@ -126,7 +114,7 @@ const updateWorkingCondition = async ({
126
114
  itemId: id,
127
115
  }: UpdateItemParams) => {
128
116
  const item = applyTransform(itemInstance, [
129
- sanitize(fieldsToSend),
117
+ sanitizeToWire(fieldsToSend),
130
118
  camelToSnake(),
131
119
  ]);
132
120
  try {
@@ -134,13 +122,12 @@ const updateWorkingCondition = async ({
134
122
  await getWorkingConditionService().workingConditionServiceUpdateWorkingCondition(
135
123
  String(id),
136
124
  {
137
- item: {
138
- ...item,
139
- },
125
+ item,
140
126
  },
141
127
  );
142
128
  return applyTransform(response.data, [
143
129
  snakeToCamel(),
130
+ itemResponseHandler,
144
131
  ]);
145
132
  } catch (err) {
146
133
  throw applyTransform(err, [
@@ -163,9 +150,7 @@ const deleteWorkingCondition = async ({ id }: DeleteItemParams) => {
163
150
  }
164
151
  };
165
152
 
166
- const getWorkingConditionsLookup = (
167
- params: Parameters<typeof getWorkingConditionsList>[0],
168
- ) =>
153
+ const getWorkingConditionsLookup = (params: ApiParams) =>
169
154
  getWorkingConditionsList({
170
155
  ...params,
171
156
  fields: params.fields || [
@@ -34,6 +34,7 @@ export * from './device/device.validations';
34
34
  export * from './license/licenseImport.validations';
35
35
  export * from './OAuth/OAuth.validations';
36
36
  export * from './onlineSkill/onlineSkill.validations';
37
+ export * from './pauseTemplate/pauseTemplate.validations';
37
38
  export * from './queue/queue.rules';
38
39
  export * from './queue/queue.validations';
39
40
  export * from './queue/queueAmd.validations';
@@ -61,3 +62,4 @@ export * from './types';
61
62
  export * from './user/user.validations';
62
63
  export * from './userToken/userToken.validations';
63
64
  export * from './variable/variable.validations';
65
+ export * from './workingCondition/workingCondition.validations';