@webitel/api-services 26.8.40 → 26.8.42

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.40",
3
+ "version": "26.8.42",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,9 +1,11 @@
1
+ import { FormatDateMode } from '../../../enums';
1
2
  import { getAgentService } from '../../../gen-wire';
2
3
  // @author @Lera
3
4
  // fixme: change on library
4
5
  // https://webitel.atlassian.net/browse/WTEL-7842?focusedCommentId=702198
5
6
  //
6
- import { convertDuration } from '../../../scripts';
7
+ import { convertDuration, normalizeDatetimeRange } from '../../../scripts';
8
+ import { formatDate } from '../../../utils';
7
9
  import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
8
10
  import {
9
11
  applyTransform,
@@ -382,18 +384,32 @@ const getAgentsLookup = (params: Parameters<typeof getAgentsList>[0]) =>
382
384
  });
383
385
 
384
386
  const getAgentHistory = async (params: ApiParams) => {
385
- const {
386
- parentId,
387
- from,
388
- to,
389
- page,
390
- size,
391
- sort = '-joined_at',
392
- } = applyTransform(params, [
387
+ const defaultParams = {
388
+ sort: '-joined_at',
389
+ };
390
+
391
+ const { parentId, joinedAt, page, size, sort } = applyTransform(params, [
393
392
  merge(getDefaultGetParams()),
393
+ merge(defaultParams),
394
394
  starToSearch('search'),
395
395
  ]);
396
396
 
397
+ const normalizedJoinedAt = normalizeDatetimeRange(joinedAt);
398
+
399
+ const listResponseHandler = (items: ApiParams[]) => {
400
+ return items.map((item) => ({
401
+ ...item,
402
+ from: formatDate(+item.joinedAt, FormatDateMode.DATETIME),
403
+ to: item.duration
404
+ ? formatDate(
405
+ +item.joinedAt + item.duration * 1000,
406
+ FormatDateMode.DATETIME,
407
+ )
408
+ : null,
409
+ duration: convertDuration(item.duration),
410
+ }));
411
+ };
412
+
397
413
  try {
398
414
  const response = await getAgentService().searchAgentStateHistory({
399
415
  page,
@@ -404,15 +420,23 @@ const getAgentHistory = async (params: ApiParams) => {
404
420
  ]
405
421
  : undefined,
406
422
  sort,
407
- 'joined_at.from': from,
408
- 'joined_at.to': to,
423
+ 'joined_at.from':
424
+ normalizedJoinedAt?.from == null
425
+ ? undefined
426
+ : String(normalizedJoinedAt.from),
427
+ 'joined_at.to':
428
+ normalizedJoinedAt?.to == null
429
+ ? undefined
430
+ : String(normalizedJoinedAt.to),
409
431
  });
410
432
  const { items, next } = applyTransform(response.data, [
411
433
  snakeToCamel(),
412
434
  merge(getDefaultGetListResponse()),
413
435
  ]);
414
436
  return {
415
- items,
437
+ items: applyTransform(items, [
438
+ listResponseHandler,
439
+ ]),
416
440
  next,
417
441
  };
418
442
  } catch (err) {