Skip to content

Commit

Permalink
fix: change api instance on factory[WTEL-4883](https://webitel.atlass…
Browse files Browse the repository at this point in the history
  • Loading branch information
Lera24 committed Dec 6, 2024
1 parent 0a090b0 commit 2f95f2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
8 changes: 4 additions & 4 deletions 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
Expand Up @@ -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",
Expand Down
39 changes: 24 additions & 15 deletions src/modules/configuration/modules/lookups/modules/slas/api/slas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
]);
Expand All @@ -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,
Expand All @@ -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()
]);
Expand All @@ -91,19 +102,17 @@ 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]);
}
};

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]);
Expand Down

0 comments on commit 2f95f2a

Please sign in to comment.