diff --git a/src/modules/settings/api/settings.js b/src/modules/settings/api/settings.js index 46295abb9..a9c2100d6 100644 --- a/src/modules/settings/api/settings.js +++ b/src/modules/settings/api/settings.js @@ -1,39 +1,71 @@ -import { EndpointPatcherApiConsumer } from 'webitel-sdk/esm2015/api-consumers'; -import instance, { config } from '../../../app/api/old/instance'; +import instance from '../../../app/api/instance'; +import applyTransform, { + camelToSnake, + notify, + snakeToCamel +} from '@webitel/ui-sdk/src/api/transformers'; const baseUrl = 'users'; -const itemPatcher = new EndpointPatcherApiConsumer({ baseUrl, instance }); -export const changePassword = ({ id, changes }) => itemPatcher.patchItem({ - id, - changes, -}); +export const getWebPhone = async () => { -export const changeWebPhone = async (changes) => { const url = 'user/settings/phone'; try { - config.errors.silent = true; - return await instance.put(url, changes); + const response = await instance.get(url); + return applyTransform(response.data, [ + snakeToCamel(), + ]); } catch (err) { - throw err; - } finally { - config.errors.silent = false; + throw applyTransform(err, [ + notify, + ]); } }; -export const getWebPhone = async () => { +export const changeWebPhone = async (changes) => { + + const item = applyTransform(changes, [ + camelToSnake(), + ]); + const url = 'user/settings/phone'; + try { - config.errors.silent = true; - return await instance.get(url); + const response = await instance.put(url, item); + return applyTransform(response.data, [ + snakeToCamel(), + ]); } catch (err) { - throw err; - } finally { - config.errors.silent = false; + throw applyTransform(err, [ + notify, + ]); } }; +const patchItem = async ({ changes, id }) => { + const body = applyTransform(changes, [ + camelToSnake(), + ]); + const url = `${baseUrl}/${id}`; + try { + const response = await instance.patch(url, body); + return applyTransform(response.data, [ + snakeToCamel(), + ]); + } catch (err) { + throw applyTransform(err, [ + notify, + ]); + } +}; + +export const changePassword = ({ id, changes }) => patchItem({ + id, + changes, +}); + + export default { changePassword, changeWebPhone,