Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ contact-groups - api, router store [WTEL-4740] #130

Open
wants to merge 1 commit into
base: feat/lookups-pr
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import {
getDefaultGetListResponse,
getDefaultGetParams,
} from '@webitel/ui-sdk/src/api/defaults/index.js';
import applyTransform, {
camelToSnake,
merge,
mergeEach,
log,
notify,
sanitize,
snakeToCamel,
starToSearch,
generateUrl,
} from '@webitel/ui-sdk/src/api/transformers/index.js';

import instance from '../../../../../../../app/api/instance';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

імпорти краще робити з розширенням файлу, по можливості, щоб потім не було проблем з білдами
імпорти без розширення -- це фішка commonjs модулів, що в esm модулях, більш нових, вже не канає


const contactGroupsUrl = '/contacts/groups';

const getContactGroupsList = async (params) => {
const fieldsToSend = ['page', 'size', 'fields', 'sort', 'id', 'q', 'name'];

const defaultObject = {
};

const url = applyTransform(params, [
starToSearch('search'),
(params) => ({ ...params, q: params.search }),
sanitize(fieldsToSend),
camelToSnake(),
generateUrl(contactGroupsUrl),
]);

try {
const response = await instance.get(url);

const { items, next } = applyTransform(response.data, [
snakeToCamel(),
merge(getDefaultGetListResponse()),
]);
return {
items: applyTransform(items, [mergeEach(defaultObject), log]),
next,
};

} catch (err) {
throw applyTransform(err, [notify]);
}
};

const getAgent = async ({ itemId: id }) => {
const url = `${contactGroupsUrl}/${id}`;
const defaultObject = {
};

try {
const response = await instance.get(url);

return applyTransform(response.data.group, [
snakeToCamel(),
merge(defaultObject),
]);
} catch (err) {
throw applyTransform(err, [notify]);
}
};

const fieldsToSend = [
'name',
'description',
];

const addAgent = async ({ itemInstance }) => {
const item = applyTransform(itemInstance, [
sanitize(fieldsToSend),
camelToSnake(),
]);

try {
const response = await instance.post(contactGroupsUrl, item);
return applyTransform(response.data, []);
} catch (err) {
throw applyTransform(err, [notify]);
}
};

const patchAgent = async ({ itemInstance, id }) => {
const url = `${contactGroupsUrl}/${id}`;

const item = applyTransform(itemInstance, [
sanitize(fieldsToSend),
camelToSnake(),
]);

try {
const response = await instance.patch(url, item);
return applyTransform(response.data, []);
} catch (err) {
throw applyTransform(err, [notify]);
}
};

const updateAgent = async ({ itemInstance, itemId: id }) => {
const url = `${contactGroupsUrl}/${id}`;

const item = applyTransform(itemInstance, [
sanitize(fieldsToSend),
camelToSnake(),
]);

try {
const response = await instance.put(url, item);
return applyTransform(response.data, []);
} catch (err) {
throw applyTransform(err, [notify]);
}
};

const deleteAgent = async ({ id }) => {
const url = `${contactGroupsUrl}/${id}`

try {
const response = await instance.delete(url);
return applyTransform(response.data, []);
} catch (err) {
throw applyTransform(err, [notify]);
}
};

const ContactGroupsAPI = {
getList: getContactGroupsList,
getListGroups: getContactGroupsList,
get: getAgent,
add: addAgent,
patch: patchAgent,
update: updateAgent,
delete: deleteAgent,
};

export default ContactGroupsAPI;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import RouteNames from "../../../../../../../../app/router/_internals/RouteNames.enum.js";

export default Object.freeze({
GENERAL: `${RouteNames.CONTACT_GROUPS}-general`,
PERMISSIONS: `${RouteNames.CONTACT_GROUPS}-permissions`,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import RouteNames from "../../../../../../../app/router/_internals/RouteNames.enum.js";
import ContactGroupsRouteNames from "./_internals/ContactGroupsRouteNames.enum.js";

const ContactGroups = () => import( '../components/the-contact-groups.vue');
const Agent = () => import('../components/opened-contact-groups.vue');
const General = () => import("../components/opened-contact-groups-general.vue");
const Permissions = () => import("../../../../../../_shared/permissions-tab/components/permissions-tab.vue");

import {checkRouteAccess} from "../../../../../../../app/router/_internals/guards.js";


const ContactGroupsRoutes = [
{
path: '/lookups/contact-groups',
name: RouteNames.CONTACT_GROUPS,
component: ContactGroups,
beforeEnter: checkRouteAccess,
},
{
path: '/lookups/contact-groups/:id',
name: `${RouteNames.CONTACT_GROUPS}-card`,
redirect: { name: ContactGroupsRouteNames.GENERAL },
component: Agent,
beforeEnter: checkRouteAccess,
children: [
{
path: 'general',
name: ContactGroupsRouteNames.GENERAL,
component: General,
},{
path: 'permissions/:permissionId?',
name: ContactGroupsRouteNames.PERMISSIONS,
component: Permissions,
}
],
},
]

export default ContactGroupsRoutes;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { SortSymbols } from '@webitel/ui-sdk/src/scripts/sortQueryAdapters';

export default [
{
value: 'name',
locale: 'objects.name',
field: 'name',
sort: SortSymbols.NONE,
},
{
value: 'description',
locale: 'objects.description',
field: 'description',
sort: SortSymbols.NONE,
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import HistoryStoreModule from '../../../../../../../app/store/BaseStoreModules/StoreModules/HistoryStoreModule/HistoryStoreModule';
import ObjectStoreModule from '../../../../../../../app/store/BaseStoreModules/StoreModules/ObjectStoreModule';
import PermissionsStoreModule from '../../../../../../../app/store/BaseStoreModules/StoreModules/PermissionsStoreModule/PermissionsStoreModule';
import ContactGroupsAPI from '../api/contact-groups';
import headers from './_internals/headers';

const resettableState = {
itemInstance: {
user: {},
team: {},
supervisor: [],
auditor: [],
region: {},
progressiveCount: 1,
chatCount: 1,
taskCount: 1,
isSupervisor: false,
greetingMedia: {},
},
};

const actions = {
RESET_ITEM_STATE: async (context) => {
context.commit('RESET_ITEM_STATE');
},
};

const PERMISSIONS_API_URL = '/contacts/groups';
const permissions = new PermissionsStoreModule()
.generateAPIActions(PERMISSIONS_API_URL)
.getModule();

const history = new HistoryStoreModule()
.generateGetListAction(ContactGroupsAPI.getAgentHistory)
.getModule();

const contactGroups = new ObjectStoreModule({ resettableState, headers })
Comment on lines +29 to +37
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пермішени модуль точно з адмінки
а інші 2?

то не комільфо, треба переробити з новими модулями
я мінімум там, де нові модулі вже є
якщо що, напиши мені, розберемось)

.attachAPIModule(ContactGroupsAPI)
.generateAPIActions()
.setChildModules({
history,
permissions,
})
.getModule({ actions });

export default contactGroups;
10 changes: 10 additions & 0 deletions src/modules/lookups/modules/contact-groups/store/cgroups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import contactGroups from '../modules/cgroups/store/contact-groups';

const modules = {
groups: contactGroups,
};

export default {
namespaced: true,
modules,
};
Loading