-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat / merge conflicts (package-lock.json,package.json, /ContactsAPI.…
…js) [WTEL-4740]
- Loading branch information
Showing
45 changed files
with
2,298 additions
and
1,562 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const generateMediaURL = (id, download) => { | ||
const token = localStorage.getItem('access-token'); | ||
const BASE_URL = import.meta.env.VITE_API_URL; | ||
return `${BASE_URL}/storage/recordings/${id}/${download ? 'download' : 'stream'}?access_token=${token}`; | ||
}; | ||
|
||
export default generateMediaURL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,202 +1,3 @@ | ||
import { getDefaultGetParams } from '@webitel/ui-sdk/src/api/defaults/index.js'; | ||
import applyTransform, { | ||
camelToSnake, | ||
merge, | ||
notify, | ||
sanitize, | ||
snakeToCamel, | ||
} from '@webitel/ui-sdk/src/api/transformers/index.js'; | ||
import { ContactsApiFactory } from 'webitel-sdk'; | ||
import getDefaultGetListResponse | ||
from '../../../app/api/defaults/getDefaultGetListResponse'; | ||
import instance from '../../../app/api/instance'; | ||
import configuration from '../../../app/api/openAPIConfig'; | ||
import SearchMode from '../modules/filters/enums/SearchMode.enum'; | ||
import { contacts } from '@webitel/ui-sdk/src/api/crm/index.js'; | ||
|
||
const service = new ContactsApiFactory(configuration, '', instance); | ||
|
||
const formatAccessMode = (item) => ({ | ||
...item, | ||
access: { | ||
edit: item.mode.includes('w'), | ||
delete: item.mode.includes('d'), | ||
}, | ||
}); | ||
|
||
const getList = async (params) => { | ||
const fieldsToSend = ['page', 'size', 'q', 'sort', 'fields', 'id', 'qin']; | ||
let searchValue = ''; | ||
let searchKey = ''; | ||
|
||
if (params[SearchMode.NAME]) { | ||
searchValue = params[SearchMode.NAME]; | ||
searchKey = SearchMode.NAME; | ||
} else if (params[SearchMode.LABELS]) { | ||
searchValue = params[SearchMode.LABELS]; | ||
searchKey = SearchMode.LABELS; | ||
} else if (params[SearchMode.ABOUT]) { | ||
searchValue = params[SearchMode.ABOUT]; | ||
searchKey = SearchMode.ABOUT; | ||
} else if (params[SearchMode.VARIABLES]) { | ||
searchValue = params[SearchMode.VARIABLES]; | ||
searchKey = SearchMode.VARIABLES; | ||
} else if (params[SearchMode.DESTINATION]) { | ||
searchValue = params[SearchMode.DESTINATION]; | ||
searchKey = 'emails,phones'; | ||
} | ||
|
||
const changedParams = { | ||
...params, | ||
q: searchValue, | ||
qin: searchKey, | ||
}; | ||
|
||
const transformations = [ | ||
sanitize(fieldsToSend), | ||
merge(getDefaultGetParams()), | ||
camelToSnake(), | ||
]; | ||
|
||
// This code needed for adding starToSearch method to applyTransform while searchKey !== SearchMode.VARIABLES because '*' in variables search mode brokes backend logic. | ||
if (searchKey !== SearchMode.VARIABLES) { | ||
// transformations.push(starToSearch('q')); WTEL-4265 | ||
} | ||
|
||
const { | ||
page, | ||
size, | ||
q, | ||
sort, | ||
fields, | ||
id, | ||
qin, | ||
} = applyTransform(changedParams, transformations); | ||
|
||
try { | ||
const response = await service.searchContacts( | ||
page, | ||
size, | ||
q, | ||
sort || '+name', | ||
['mode', ...fields], | ||
id, | ||
qin, | ||
); | ||
const { data, next } = applyTransform(response.data, [ | ||
snakeToCamel(), | ||
merge(getDefaultGetListResponse()), | ||
]); | ||
return { | ||
items: applyTransform(data, [ | ||
(items) => items.map((item) => formatAccessMode(item)), | ||
]), | ||
next, | ||
}; | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
const get = async ({ itemId: id }) => { | ||
const fields = ['name', 'about', 'labels', 'etag', 'mode', 'managers', 'timezones']; | ||
|
||
const defaultObject = {}; | ||
const itemResponseHandler = (item) => { | ||
return { | ||
...item, | ||
labels: item.labels?.data || [], | ||
managers: item.managers?.data || [], | ||
timezones: item.timezones?.data || [], | ||
}; | ||
}; | ||
try { | ||
const response = await service.locateContact(id, fields); | ||
return applyTransform(response.data, [ | ||
snakeToCamel(), | ||
merge(defaultObject), | ||
itemResponseHandler, | ||
formatAccessMode, | ||
]); | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
const fieldsToSend = ['name', 'labels', 'about', 'managers', 'timezones']; | ||
|
||
const sanitizeManagers = (itemInstance) => { | ||
// handle many managers and even no managers field cases | ||
const managers = (itemInstance.managers || | ||
[]).filter(({ user } = {}) => user.id); | ||
return { ...itemInstance, managers }; | ||
}; | ||
|
||
const sanitizeTimezones = (itemInstance) => { | ||
// handle many timezones and even no timezones field cases | ||
const timezones = (itemInstance.timezones || | ||
[]).filter(({ timezone } = {}) => timezone.id); | ||
return { ...itemInstance, timezones }; | ||
}; | ||
|
||
const add = async ({ itemInstance }) => { | ||
const item = applyTransform(itemInstance, [ | ||
sanitizeManagers, | ||
sanitizeTimezones, | ||
sanitize(fieldsToSend), | ||
camelToSnake(), | ||
|
||
]); | ||
try { | ||
const response = await service.createContact(item); | ||
return applyTransform(response.data, [ | ||
snakeToCamel(), | ||
]); | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
const update = async ({ itemInstance }) => { | ||
const { etag } = itemInstance; | ||
const item = applyTransform(itemInstance, [ | ||
sanitizeManagers, | ||
sanitizeTimezones, | ||
sanitize(fieldsToSend), | ||
camelToSnake(), | ||
]); | ||
try { | ||
const response = await service.updateContact(etag, item); | ||
return applyTransform(response.data, [ | ||
snakeToCamel(), | ||
]); | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
const deleteContact = async ({ id }) => { | ||
try { | ||
const response = await service.deleteContact(id); | ||
return applyTransform(response.data, []); | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
export default { | ||
getList, | ||
get, | ||
add, | ||
update, | ||
delete: deleteContact, | ||
}; | ||
export default contacts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.