Skip to content

Commit

Permalink
Merge pull request #298 from webitel/feature/fix-name-and-search-in-c…
Browse files Browse the repository at this point in the history
…ontacts-api

fix: search for destination and add prerequesthandler for commonName[…
  • Loading branch information
Lera24 authored Sep 16, 2024
2 parents 212e654 + 05475f2 commit 4991574
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webitel/ui-sdk",
"version": "24.10.7",
"version": "24.10.8",
"private": false,
"scripts": {
"dev": "vite",
Expand Down
14 changes: 13 additions & 1 deletion src/api/crm/contacts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContactsApiFactory } from 'webitel-sdk';
import deepCopy from 'deep-copy';
import {
getDefaultGetListResponse,
getDefaultGetParams,
Expand Down Expand Up @@ -82,7 +83,7 @@ const getList = async (params) => {
searchKey = ContactsSearchMode.VARIABLES;
} else if (params[ContactsSearchMode.DESTINATION]) {
searchValue = params[ContactsSearchMode.DESTINATION];
searchKey = 'emails,phones';
searchKey = 'emails,phones,imclients{user{name}}';
}

// This code needed for adding starToSearch method to applyTransform while searchKey !== SearchMode.VARIABLES because '*' in variables search mode brokes backend logic.
Expand Down Expand Up @@ -143,6 +144,7 @@ const get = async ({ itemId: id }) => {
const itemResponseHandler = (item) => {
return {
...item,
name: item.name.commonName,
labels: item.labels ? [...item.labels.data] : [],
managers: item.managers ? [...item.managers.data] : [],
timezones: item.timezones ? [...item.timezones.data] : [],
Expand Down Expand Up @@ -178,8 +180,17 @@ const sanitizeTimezones = (itemInstance) => {
return { ...itemInstance, timezones };
};

const preRequestHandler = (item) => {
const copy = deepCopy(item);
copy.name = {
commonName: copy.name,
};
return copy;
};

const add = async ({ itemInstance }) => {
const item = applyTransform(itemInstance, [
preRequestHandler,
sanitizeManagers,
sanitizeTimezones,
sanitize(fieldsToSend),
Expand All @@ -196,6 +207,7 @@ const add = async ({ itemInstance }) => {
const update = async ({ itemInstance }) => {
const { etag } = itemInstance;
const item = applyTransform(itemInstance, [
preRequestHandler,
sanitizeManagers,
sanitizeTimezones,
sanitize(fieldsToSend),
Expand Down

0 comments on commit 4991574

Please sign in to comment.