Skip to content

Commit

Permalink
feature: add default communication type[WTEl-4074]
Browse files Browse the repository at this point in the history
  • Loading branch information
Lera24 committed Dec 13, 2023
1 parent ed1987e commit 1aca99f
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 11 deletions.
14 changes: 7 additions & 7 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 @@ -36,7 +36,7 @@
"vue-router": "^4.2.5",
"vue2-dropzone": "^3.6.0",
"vuex": "^4.1.0",
"webitel-sdk": "^23.12.8"
"webitel-sdk": "^23.12.9"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.4.0",
Expand Down
30 changes: 27 additions & 3 deletions src/modules/lookups/modules/communications/api/communications.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from '@webitel/ui-sdk/src/api/defaults';
import applyTransform, {
camelToSnake,
merge,
merge, mergeEach,
notify,
sanitize,
snakeToCamel,
Expand All @@ -17,6 +17,10 @@ import configuration from '../../../../../app/api/openAPIConfig';
const communicationService = new CommunicationTypeServiceApiFactory(configuration, '', instance);

const getCommunicationsList = async (params) => {
const defaultObject = {
default: false,
};

const {
page,
size,
Expand All @@ -43,7 +47,9 @@ const getCommunicationsList = async (params) => {
merge(getDefaultGetListResponse()),
]);
return {
items,
items: applyTransform(items, [
mergeEach(defaultObject),
]),
next,
};
} catch (err) {
Expand All @@ -68,7 +74,7 @@ const getCommunication = async ({ itemId: id }) => {
}
};

const fieldsToSend = ['code', 'name', 'description', 'channel'];
const fieldsToSend = ['code', 'name', 'description', 'channel', 'default'];

const addCommunication = async ({ itemInstance }) => {
const item = applyTransform(itemInstance, [
Expand All @@ -88,6 +94,23 @@ const addCommunication = async ({ itemInstance }) => {
}
};

const patchCommunication = async ({ changes, id }) => {
const body = applyTransform(changes, [
sanitize(fieldsToSend),
camelToSnake(),
]);
try {
const response = await communicationService.patchCommunicationType(id, body);
return applyTransform(response.data, [
snakeToCamel(),
]);
} catch (err) {
throw applyTransform(err, [
notify,
]);
}
};

const updateCommunication = async ({ itemInstance, itemId: id }) => {
const item = applyTransform(itemInstance, [
sanitize(fieldsToSend),
Expand Down Expand Up @@ -127,6 +150,7 @@ const CommunicationsAPI = {
getList: getCommunicationsList,
get: getCommunication,
add: addCommunication,
patch: patchCommunication,
update: updateCommunication,
delete: deleteCommunication,
getLookup: getCommunicationsLookup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@
<template #code="{ item }">
{{ item.code }}
</template>
<template #default="{ item, index }">
<wt-radio
:selected="item.default"
:value="true"
@input="changeDefaultType({ item, index, value: $event })"
/>
</template>
<template #description="{ item }">
{{ item.description }}
</template>
Expand Down Expand Up @@ -168,6 +175,18 @@ export default {
];
},
},
methods: {
async changeDefaultType({ index, item, value }) {
try {
await this.patchItem({
index, item, prop: 'default', value,
});
if (value) this.loadList();
} catch {
this.loadList();
}
}
}
};
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export default [
field: 'code',
sort: SortSymbols.NONE,
},
{
value: 'default',
locale: 'objects.default',
field: 'default',
sort: SortSymbols.NONE,
},
{
value: 'description',
locale: 'objects.description',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const resettableState = {
code: '',
description: '',
channel: '',
default: false,
},
};

Expand Down

0 comments on commit 1aca99f

Please sign in to comment.