From 2f95f2a86d841813a3b5f531bc976ce2f7ce8574 Mon Sep 17 00:00:00 2001 From: Lera24 Date: Fri, 6 Dec 2024 14:16:05 +0200 Subject: [PATCH] fix: change api instance on factory[WTEL-4883](https://webitel.atlassian.net/browse/WTEL-4883) --- package-lock.json | 8 ++-- package.json | 2 +- .../modules/lookups/modules/slas/api/slas.js | 39 ++++++++++++------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index d3469da5..944aecd6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "vue-i18n": "^9.13.1", "vue-router": "^4.3.2", "vuex": "^4.1.0", - "webitel-sdk": "^24.8.8" + "webitel-sdk": "^24.10.1" }, "devDependencies": { "@vitejs/plugin-vue": "5.1.3", @@ -10451,9 +10451,9 @@ } }, "node_modules/webitel-sdk": { - "version": "24.8.8", - "resolved": "https://registry.npmjs.org/webitel-sdk/-/webitel-sdk-24.8.8.tgz", - "integrity": "sha512-YwivCEjnnsH/8VedFUcMjCX9Kdhy+KSp2MkKtladyKxMKjttGysM7D3jEyqAAH5jSL1XYL/sr8D3ntmr2FOg/A==", + "version": "24.10.1", + "resolved": "https://registry.npmjs.org/webitel-sdk/-/webitel-sdk-24.10.1.tgz", + "integrity": "sha512-zG49gPGMHKlakjrmPOXS24N7IOudtkVq0UKQwWr4x2a1vgKw9Jerz2BhAxwCkdIswFWFAIbymICOG/tNvb2UHg==", "license": "MIT", "dependencies": { "@types/webrtc": "~0.0.41", diff --git a/package.json b/package.json index e2962730..3645b2f2 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "vue-i18n": "^9.13.1", "vue-router": "^4.3.2", "vuex": "^4.1.0", - "webitel-sdk": "^24.8.8" + "webitel-sdk": "^24.10.1" }, "devDependencies": { "@vitejs/plugin-vue": "5.1.3", diff --git a/src/modules/configuration/modules/lookups/modules/slas/api/slas.js b/src/modules/configuration/modules/lookups/modules/slas/api/slas.js index 7848252b..c1a12057 100644 --- a/src/modules/configuration/modules/lookups/modules/slas/api/slas.js +++ b/src/modules/configuration/modules/lookups/modules/slas/api/slas.js @@ -2,36 +2,51 @@ import { getDefaultGetListResponse, getDefaultGetParams, getDefaultInstance, + getDefaultOpenAPIConfig, } from '@webitel/ui-sdk/src/api/defaults/index.js'; import applyTransform, { camelToSnake, - generateUrl, merge, notify, sanitize, snakeToCamel, starToSearch, } from '@webitel/ui-sdk/src/api/transformers/index.js'; +import { SLAsApiFactory } from 'webitel-sdk'; const instance = getDefaultInstance(); +const configuration = getDefaultOpenAPIConfig(); -const baseUrl = '/cases/slas'; +const slaService = new SLAsApiFactory(configuration, '', instance); const fieldsToSend = ['name', 'description', 'valid_from', 'valid_to', 'calendar', 'reaction_time', 'resolution_time']; const getSlasList = async (params) => { const fieldsToSend = ['page', 'size', 'q', 'sort', 'fields', 'id']; - const url = applyTransform(params, [ + const { + page, + size, + fields, + sort, + id, + q, + } = applyTransform(params, [ merge(getDefaultGetParams()), starToSearch('search'), (params) => ({ ...params, q: params.search }), sanitize(fieldsToSend), camelToSnake(), - generateUrl(baseUrl), ]); try { - const response = await instance.get(url); + const response = await slaService.listSLAs( + page, + size, + fields, + sort, + id, + q, + ); const { items, next } = applyTransform(response.data, [ merge(getDefaultGetListResponse()), ]); @@ -49,12 +64,8 @@ const getSla = async ({ itemId: id }) => { return item.sla; }; - const url = applyTransform({ fields: fieldsToSend }, [ - generateUrl(`${baseUrl}/${id}`), - ]); - try { - const response = await instance.get(url); + const response = await slaService.locateSLA(id); return applyTransform(response.data, [ snakeToCamel(), itemResponseHandler, @@ -79,7 +90,7 @@ const addSla = async ({ itemInstance }) => { camelToSnake(), ]); try { - const response = await instance.post(baseUrl, item); + const response = await slaService.createSLA(item); return applyTransform(response.data, [ snakeToCamel() ]); @@ -91,9 +102,8 @@ const addSla = async ({ itemInstance }) => { const updateSla = async ({ itemInstance, itemId: id }) => { const item = applyTransform(itemInstance, [camelToSnake(), sanitize(fieldsToSend)]); - const url = `${baseUrl}/${id}`; try { - const response = await instance.put(url, item); + const response = await slaService.updateSLA(id, item); return applyTransform(response.data, [snakeToCamel()]); } catch (err) { throw applyTransform(err, [notify]); @@ -101,9 +111,8 @@ const updateSla = async ({ itemInstance, itemId: id }) => { }; const deleteSla = async ({ id }) => { - const url = `${baseUrl}/${id}`; try { - const response = await instance.delete(url); + const response = await slaService.deleteSLA(id); return applyTransform(response.data, []); } catch (err) { throw applyTransform(err, [notify]);