From 42d41b09d9bb1e1ed33ee9ce15748f152ccec7ca Mon Sep 17 00:00:00 2001 From: liza-pohranichna Date: Thu, 13 Jul 2023 18:03:09 +0300 Subject: [PATCH 1/8] refactoring: queue-members api [WTEL-3669] --- .../modules/members/api/queueMembers.js | 360 +++++++++++++----- 1 file changed, 256 insertions(+), 104 deletions(-) diff --git a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js index f49cd5bd8..0e20bac0d 100644 --- a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js +++ b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js @@ -1,17 +1,27 @@ import eventBus from '@webitel/ui-sdk/src/scripts/eventBus'; import deepCopy from 'deep-copy'; -import { MemberServiceApiFactory } from 'webitel-sdk'; import { - SdkCreatorApiConsumer, - SdkDeleterApiConsumer, - SdkGetterApiConsumer, - SdkListGetterApiConsumer, - SdkPatcherApiConsumer, - SdkUpdaterApiConsumer, -} from 'webitel-sdk/esm2015/api-consumers'; -import instance from '../../../../../../../app/api/old/instance'; + getDefaultGetListResponse, + getDefaultGetParams, +} from '@webitel/ui-sdk/src/api/defaults'; +import applyTransform, { + camelToSnake, + handleUnauthorized, + merge, mergeEach, notify, sanitize, snakeToCamel, + starToSearch, +} from '@webitel/ui-sdk/src/api/transformers'; +import { MemberServiceApiFactory } from 'webitel-sdk'; +// import { +// SdkCreatorApiConsumer, +// SdkDeleterApiConsumer, +// SdkGetterApiConsumer, +// SdkListGetterApiConsumer, +// SdkPatcherApiConsumer, +// SdkUpdaterApiConsumer, +// } from 'webitel-sdk/esm2015/api-consumers'; +import instance from '../../../../../../../app/api/instance'; import configuration from '../../../../../../../app/api/openAPIConfig'; -import sanitizer from '../../../../../../../app/api/old/utils/sanitizer'; +// import sanitizer from '../../../../../../../app/api/old/utils/sanitizer'; const memberService = new MemberServiceApiFactory(configuration, '', instance); @@ -30,23 +40,6 @@ const communicationsFieldsToSend = [ 'dtmf', ]; -const defaultListObject = { - createdAt: 'unknown', - priority: 0, -}; - -const defaultSingleObject = { - createdAt: 'unknown', - priority: '0', - name: 'member', - expireAt: 0, - bucket: {}, - timezone: {}, - agent: {}, - communications: [], - variables: [], -}; - const defaultSingleObjectCommunication = { destination: '', display: '', @@ -63,22 +56,22 @@ const mapDefaultCommunications = (item) => ( ); const _getMembersList = (getList) => function({ - page, - size, - search, - sort, - fields, - id, - parentId, - from, - to, - bucket, - priorityFrom, - priorityTo, - priority, - cause, - agent, - }) { + page, + size, + search, + sort, + fields, + id, + parentId, + from, + to, + bucket, + priorityFrom, + priorityTo, + priority, + cause, + agent, + }) { const params = [ parentId, page, size, search, sort, fields, id, bucket, undefined, from, to, undefined, undefined, cause, @@ -89,29 +82,9 @@ const _getMembersList = (getList) => function({ return getList(params); }; -const listResponseHandler = (response) => { - const items = response.items.map((item) => ({ - ...item, - communications: mapDefaultCommunications(item), - })); - return { items, next: response.next }; -}; - -const itemResponseHandler = (response) => { - let variables = []; - if (response.variables) { - variables = Object.keys(response.variables).map((key) => ({ - key, - value: response.variables[key], - })); - } - const communications = mapDefaultCommunications(response); - return { ...response, variables, communications }; -}; - const preRequestHandler = (item) => { item.communications - .forEach((item) => sanitizer(item, communicationsFieldsToSend)); + .forEach((item) => sanitizer(item, communicationsFieldsToSend)); //переробити на аплій трансформ? подивитись, як працює новий санітайс const variables = item.variables.reduce((variables, variable) => ({ ...variables, [variable.key]: variable.value, @@ -119,35 +92,228 @@ const preRequestHandler = (item) => { return { ...item, variables }; }; -const listGetter = new SdkListGetterApiConsumer( - memberService.searchMemberInQueue, - { defaultListObject, listResponseHandler }, -) -.setGetListMethod(_getMembersList); -const itemGetter = new SdkGetterApiConsumer( - memberService.readMember, - { defaultSingleObject, itemResponseHandler }, -); -const itemCreator = new SdkCreatorApiConsumer( - memberService.createMember, - { fieldsToSend, preRequestHandler }, -); -const itemUpdater = new SdkUpdaterApiConsumer( - memberService.updateMember, - { fieldsToSend, preRequestHandler }, -); -const itemDeleter = new SdkDeleterApiConsumer(memberService.deleteMember); +// const listGetter = new SdkListGetterApiConsumer( +// memberService.searchMemberInQueue, +// { defaultListObject, listResponseHandler }, +// ) +// .setGetListMethod(_getMembersList); +const getMembersList = async (params) => { + const fieldsToSend = ['page', 'size', 'search', 'sort', 'fields', 'id', 'parentId']; + + const defaultObject = { + createdAt: 'unknown', + priority: 0, + }; + + const responseHandler = (response) => { + const items = response.items.map((item) => ({ + ...item, + communications: mapDefaultCommunications(item), + })); + return { items, next: response.next }; + }; // переробити, це треба робити в return items: + + const { + page, + size, + search, + sort, + fields, + id, + parentId, + from, + to, + bucket, + priorityFrom, + priorityTo, + priority, + cause, + agent, + } = applyTransform(params, [ + merge(getDefaultGetParams()), + starToSearch('search'), + sanitize(fieldsToSend), + ]); -const resetMembersApiConsumer = new SdkPatcherApiConsumer(memberService.resetMembers); + try { + const response = await memberService.searchMemberInQueue( + parentId, + page, + size, + search, + sort, + fields, + id, + bucket, + undefined, + from, + to, + undefined, + undefined, + cause, + priorityFrom || priority?.from, + priorityTo || priority?.to, + undefined, + undefined, + undefined, + agent, + ); + const { items, next } = applyTransform(response.data, [ + snakeToCamel(), + merge(getDefaultGetListResponse()), + ]); + return { + items: applyTransform(items, [ + mergeEach(defaultObject), + ]), + next, + }; + } catch (err) { + throw applyTransform(err, [ + handleUnauthorized, + notify, + ]); + } +}; + +// const itemGetter = new SdkGetterApiConsumer( +// memberService.readMember, +// { defaultSingleObject, itemResponseHandler }, +// ); +const getMember = async ({ parentId, itemId: id }) => { + const defaultObject = { + createdAt: 'unknown', + priority: '0', + name: 'member', + expireAt: 0, + bucket: {}, + timezone: {}, + agent: {}, + communications: [], + variables: [], + }; + + const responseHandler = (response) => { + let variables = []; + if (response.variables) { + variables = Object.keys(response.variables).map((key) => ({ + key, + value: response.variables[key], + })); + } + const communications = mapDefaultCommunications(response); + return { ...response, variables, communications }; + }; + + try { + const response = await memberService.readMember(parentId, id); + return applyTransform(response.data, [ + snakeToCamel(), + merge(defaultObject), + responseHandler, + ]); + } catch (err) { + throw applyTransform(err, [ + handleUnauthorized, + notify, + ]); + } +}; -const getMembersList = (params) => listGetter.getList(params); -const getMember = (params) => itemGetter.getNestedItem(params); -const addMember = (params) => itemCreator.createNestedItem(params); -const updateMember = (params) => itemUpdater.updateNestedItem(params); -const deleteMember = (params) => itemDeleter.deleteNestedItem(params); +// const itemCreator = new SdkCreatorApiConsumer( +// memberService.createMember, +// { fieldsToSend, preRequestHandler }, +// ); +const addMember = async ({ parentId, itemInstance }) => { + const item = applyTransform(itemInstance, [ + preRequestHandler, + sanitize(fieldsToSend), + camelToSnake(), + ]); + try { + const response = await memberService.createMember(parentId, item); + return applyTransform(response.data, [ + snakeToCamel(), + ]); + } catch (err) { + throw applyTransform(err, [ + handleUnauthorized, + notify, + ]); + } +}; -const resetMembers = ({ parentId }) => resetMembersApiConsumer -.patchItem({ id: parentId, changes: {} }); +// const itemUpdater = new SdkUpdaterApiConsumer( +// memberService.updateMember, +// { fieldsToSend, preRequestHandler }, +// ); +const updateMember = async ({ itemInstance, itemId: id, parentId }) => { + const item = applyTransform(itemInstance, [ + preRequestHandler(parentId), + sanitize(fieldsToSend), + camelToSnake(), + ]); + try { + const response = await memberService.updateMember(parentId, id, item); + return applyTransform(response.data, [ + snakeToCamel(), + ]); + } catch (err) { + throw applyTransform(err, [ + handleUnauthorized, + notify, + ]); + } +}; + +// const itemDeleter = new SdkDeleterApiConsumer(memberService.deleteMember); +const deleteMember = async ({ parentId, id }) => { + try { + const response = await memberService.deleteMember(parentId, id); + return applyTransform(response.data, []); + } catch (err) { + throw applyTransform(err, [ + handleUnauthorized, + notify, + ]); + } +}; + +// const resetMembersApiConsumer = new SdkPatcherApiConsumer(memberService.resetMembers); + +// const resetMembers = ({ parentId }) => resetMembersApiConsumer +// .patchItem({ id: parentId, changes: {} }); + +const resetMembers = async ({ parentId }) => { + // const body = applyTransform(changes, [ + // sanitize(fieldsToSend), + // camelToSnake(), + // ]); + try { + const response = await memberService.resetMembers(parentId, {}); + return applyTransform(response.data, [ + snakeToCamel(), + ]); + } catch (err) { + throw applyTransform(err, [ + handleUnauthorized, + notify, + ]); + } +}; +const addMembersBulk = async (queueId, fileName, items) => { + const itemsCopy = deepCopy(items); + const body = { queueId, fileName, items: itemsCopy }; + try { + await memberService.createMemberBulk(queueId, body); + eventBus.$emit('notification', { + type: 'info', + text: 'Successfully added', + }); + } catch (err) { + throw err; + } +}; export const deleteMembersBulk = async (queueId, { search, @@ -172,20 +338,6 @@ export const deleteMembersBulk = async (queueId, { } }; -const addMembersBulk = async (queueId, fileName, items) => { - const itemsCopy = deepCopy(items); - const body = { queueId, fileName, items: itemsCopy }; - try { - await memberService.createMemberBulk(queueId, body); - eventBus.$emit('notification', { - type: 'info', - text: 'Successfully added', - }); - } catch (err) { - throw err; - } -}; - const QueueMembersAPI = { getList: getMembersList, get: getMember, From 77db9d66f2a7525fd3f4965073d4c5d135f671c8 Mon Sep 17 00:00:00 2001 From: lizacoma Date: Fri, 14 Jul 2023 23:51:36 +0300 Subject: [PATCH 2/8] refactoring: queue members api [WTEL-3619] --- package-lock.json | 14 +- .../modules/members/api/queueMembers.js | 150 +++++++----------- 2 files changed, 61 insertions(+), 103 deletions(-) diff --git a/package-lock.json b/package-lock.json index ea804018d..a0d1b1115 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@vuelidate/core": "^2.0.0", "@vuelidate/validators": "^2.0.0", "@webitel/flow-ui-sdk": "^0.1.14", - "@webitel/ui-sdk": "^3.2.59". + "@webitel/ui-sdk": "^3.2.59", "axios": "^0.27.1", "clipboard-copy": "^4.0.1", "core-js": "^3.6.4", @@ -4247,9 +4247,9 @@ "license": "MIT" }, "node_modules/@webitel/ui-sdk": { - "version": "3.2.59", - "resolved": "https://registry.npmjs.org/@webitel/ui-sdk/-/ui-sdk-3.2.59.tgz", - "integrity": "sha512-GCvI6sL8rEjIy0rrWlRBCOLxEewTZXu1RyeVxc5fjSgxLAdpC8qqUHh0Rr+5gpQGI45FYMBxjiCCBztNBYheHQ==", + "version": "3.2.61", + "resolved": "https://registry.npmjs.org/@webitel/ui-sdk/-/ui-sdk-3.2.61.tgz", + "integrity": "sha512-RwwHt2A/lN3SEGXUjzL370s0xb5qcL7olwQgA4C8YkWEBPpsYgHJnwxY0I+Fd7PN98cM/zzD20uSnm731eLR6A==", "dependencies": { "@floating-ui/vue": "^1.0.1", "@vue/compat": "^3.2.47", @@ -22371,9 +22371,9 @@ } }, "@webitel/ui-sdk": { - "version": "3.2.59", - "resolved": "https://registry.npmjs.org/@webitel/ui-sdk/-/ui-sdk-3.2.59.tgz", - "integrity": "sha512-GCvI6sL8rEjIy0rrWlRBCOLxEewTZXu1RyeVxc5fjSgxLAdpC8qqUHh0Rr+5gpQGI45FYMBxjiCCBztNBYheHQ==", + "version": "3.2.61", + "resolved": "https://registry.npmjs.org/@webitel/ui-sdk/-/ui-sdk-3.2.61.tgz", + "integrity": "sha512-RwwHt2A/lN3SEGXUjzL370s0xb5qcL7olwQgA4C8YkWEBPpsYgHJnwxY0I+Fd7PN98cM/zzD20uSnm731eLR6A==", "requires": { "@floating-ui/vue": "^1.0.1", "@vue/compat": "^3.2.47", diff --git a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js index 0e20bac0d..ce0d7339e 100644 --- a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js +++ b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js @@ -1,4 +1,3 @@ -import eventBus from '@webitel/ui-sdk/src/scripts/eventBus'; import deepCopy from 'deep-copy'; import { getDefaultGetListResponse, @@ -11,14 +10,6 @@ import applyTransform, { starToSearch, } from '@webitel/ui-sdk/src/api/transformers'; import { MemberServiceApiFactory } from 'webitel-sdk'; -// import { -// SdkCreatorApiConsumer, -// SdkDeleterApiConsumer, -// SdkGetterApiConsumer, -// SdkListGetterApiConsumer, -// SdkPatcherApiConsumer, -// SdkUpdaterApiConsumer, -// } from 'webitel-sdk/esm2015/api-consumers'; import instance from '../../../../../../../app/api/instance'; import configuration from '../../../../../../../app/api/openAPIConfig'; // import sanitizer from '../../../../../../../app/api/old/utils/sanitizer'; @@ -50,41 +41,17 @@ const defaultSingleObjectCommunication = { dtmf: '', }; -const mapDefaultCommunications = (item) => ( - item.communications ? item.communications - .map((comm) => ({ ...defaultSingleObjectCommunication, ...comm })) : [] -); - -const _getMembersList = (getList) => function({ - page, - size, - search, - sort, - fields, - id, - parentId, - from, - to, - bucket, - priorityFrom, - priorityTo, - priority, - cause, - agent, - }) { - const params = [ - parentId, page, size, search, sort, fields, id, bucket, - undefined, from, to, undefined, undefined, cause, - priorityFrom || priority?.from, priorityTo || priority?.to, - undefined, undefined, undefined, agent, - ]; - - return getList(params); +const mapDefaultCommunications = (item) => { + console.log('mapDefaultCommunications item:', item); + const copy = item.communications ? item.communications + .map((comm) => ({ ...defaultSingleObjectCommunication, ...comm })) : []; + console.log('copy:', copy) + return copy; }; const preRequestHandler = (item) => { item.communications - .forEach((item) => sanitizer(item, communicationsFieldsToSend)); //переробити на аплій трансформ? подивитись, як працює новий санітайс + .forEach((item) => sanitize(item, communicationsFieldsToSend)); //переробити на аплій трансформ? подивитись, як працює новий санітайс const variables = item.variables.reduce((variables, variable) => ({ ...variables, [variable.key]: variable.value, @@ -92,26 +59,18 @@ const preRequestHandler = (item) => { return { ...item, variables }; }; -// const listGetter = new SdkListGetterApiConsumer( -// memberService.searchMemberInQueue, -// { defaultListObject, listResponseHandler }, -// ) -// .setGetListMethod(_getMembersList); const getMembersList = async (params) => { const fieldsToSend = ['page', 'size', 'search', 'sort', 'fields', 'id', 'parentId']; - const defaultObject = { createdAt: 'unknown', priority: 0, - }; - - const responseHandler = (response) => { - const items = response.items.map((item) => ({ + } + const listHandler = (items) => { + return items.map((item) => ({ ...item, communications: mapDefaultCommunications(item), })); - return { items, next: response.next }; - }; // переробити, це треба робити в return items: + }; const { page, @@ -165,6 +124,7 @@ const getMembersList = async (params) => { return { items: applyTransform(items, [ mergeEach(defaultObject), + listHandler, ]), next, }; @@ -176,10 +136,6 @@ const getMembersList = async (params) => { } }; -// const itemGetter = new SdkGetterApiConsumer( -// memberService.readMember, -// { defaultSingleObject, itemResponseHandler }, -// ); const getMember = async ({ parentId, itemId: id }) => { const defaultObject = { createdAt: 'unknown', @@ -220,10 +176,6 @@ const getMember = async ({ parentId, itemId: id }) => { } }; -// const itemCreator = new SdkCreatorApiConsumer( -// memberService.createMember, -// { fieldsToSend, preRequestHandler }, -// ); const addMember = async ({ parentId, itemInstance }) => { const item = applyTransform(itemInstance, [ preRequestHandler, @@ -243,18 +195,14 @@ const addMember = async ({ parentId, itemInstance }) => { } }; -// const itemUpdater = new SdkUpdaterApiConsumer( -// memberService.updateMember, -// { fieldsToSend, preRequestHandler }, -// ); const updateMember = async ({ itemInstance, itemId: id, parentId }) => { - const item = applyTransform(itemInstance, [ - preRequestHandler(parentId), + const body = applyTransform(itemInstance, [ + preRequestHandler, sanitize(fieldsToSend), camelToSnake(), ]); try { - const response = await memberService.updateMember(parentId, id, item); + const response = await memberService.updateMember(parentId, id, body); return applyTransform(response.data, [ snakeToCamel(), ]); @@ -266,7 +214,6 @@ const updateMember = async ({ itemInstance, itemId: id, parentId }) => { } }; -// const itemDeleter = new SdkDeleterApiConsumer(memberService.deleteMember); const deleteMember = async ({ parentId, id }) => { try { const response = await memberService.deleteMember(parentId, id); @@ -279,16 +226,7 @@ const deleteMember = async ({ parentId, id }) => { } }; -// const resetMembersApiConsumer = new SdkPatcherApiConsumer(memberService.resetMembers); - -// const resetMembers = ({ parentId }) => resetMembersApiConsumer -// .patchItem({ id: parentId, changes: {} }); - const resetMembers = async ({ parentId }) => { - // const body = applyTransform(changes, [ - // sanitize(fieldsToSend), - // camelToSnake(), - // ]); try { const response = await memberService.resetMembers(parentId, {}); return applyTransform(response.data, [ @@ -301,21 +239,36 @@ const resetMembers = async ({ parentId }) => { ]); } }; -const addMembersBulk = async (queueId, fileName, items) => { - const itemsCopy = deepCopy(items); - const body = { queueId, fileName, items: itemsCopy }; + +const addMembersBulk = async (parentId, fileName, items) => { + const body = { parentId, fileName, items }; + // try { + // await memberService.createMemberBulk(queueId, body); + // eventBus.$emit('notification', { + // type: 'info', + // text: 'Successfully added', + // }); + // } catch (err) { + // throw err; + // } try { - await memberService.createMemberBulk(queueId, body); - eventBus.$emit('notification', { - type: 'info', - text: 'Successfully added', - }); + const response = await memberService.createMemberBulk(parentId, body); + return applyTransform(response.data, [ + snakeToCamel(), + notify(({ callback }) => callback({ + type: 'info', + text: 'Successfully added', + })), + ]); } catch (err) { - throw err; + throw applyTransform(err, [ + handleUnauthorized, + notify, + ]); } }; -export const deleteMembersBulk = async (queueId, { +export const deleteMembersBulk = async (parentId, { search, id, from, @@ -324,17 +277,22 @@ export const deleteMembersBulk = async (queueId, { priority, cause, }) => { + const body = { + id, + q: search, + createdAt: (from || to) ? { from, to } : undefined, + priority, + stopCause: cause, + bucketId: bucket, + }; try { - await memberService.deleteMembers(queueId, { - id, - q: search, - createdAt: (from || to) ? { from, to } : undefined, - priority, - stopCause: cause, - bucketId: bucket, - }); + const response = await memberService.deleteMembers(parentId, body); + return applyTransform(response.data, []); } catch (err) { - throw err; + throw applyTransform(err, [ + handleUnauthorized, + notify, + ]); } }; From 0dd1913c5fc523c951a9bba7b4833a7b9424acce Mon Sep 17 00:00:00 2001 From: lizacoma Date: Wed, 19 Jul 2023 19:06:11 +0300 Subject: [PATCH 3/8] refactoring: queue members api [WTEL-3619] --- .../queues/modules/members/api/queueMembers.js | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js index ce0d7339e..0e5577f84 100644 --- a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js +++ b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js @@ -1,4 +1,3 @@ -import deepCopy from 'deep-copy'; import { getDefaultGetListResponse, getDefaultGetParams, @@ -12,7 +11,6 @@ import applyTransform, { import { MemberServiceApiFactory } from 'webitel-sdk'; import instance from '../../../../../../../app/api/instance'; import configuration from '../../../../../../../app/api/openAPIConfig'; -// import sanitizer from '../../../../../../../app/api/old/utils/sanitizer'; const memberService = new MemberServiceApiFactory(configuration, '', instance); @@ -42,11 +40,8 @@ const defaultSingleObjectCommunication = { }; const mapDefaultCommunications = (item) => { - console.log('mapDefaultCommunications item:', item); - const copy = item.communications ? item.communications + return item.communications ? item.communications .map((comm) => ({ ...defaultSingleObjectCommunication, ...comm })) : []; - console.log('copy:', copy) - return copy; }; const preRequestHandler = (item) => { @@ -242,15 +237,6 @@ const resetMembers = async ({ parentId }) => { const addMembersBulk = async (parentId, fileName, items) => { const body = { parentId, fileName, items }; - // try { - // await memberService.createMemberBulk(queueId, body); - // eventBus.$emit('notification', { - // type: 'info', - // text: 'Successfully added', - // }); - // } catch (err) { - // throw err; - // } try { const response = await memberService.createMemberBulk(parentId, body); return applyTransform(response.data, [ From f29aadc5f6f7198c48e2e3ad7cd13b7254d3bf1f Mon Sep 17 00:00:00 2001 From: lizacoma Date: Thu, 20 Jul 2023 23:05:36 +0300 Subject: [PATCH 4/8] refactoring: queue members api [WTEL-3619] --- .../modules/members/api/queueMembers.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js index 0e5577f84..a9262a771 100644 --- a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js +++ b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js @@ -46,7 +46,7 @@ const mapDefaultCommunications = (item) => { const preRequestHandler = (item) => { item.communications - .forEach((item) => sanitize(item, communicationsFieldsToSend)); //переробити на аплій трансформ? подивитись, як працює новий санітайс + .forEach((item) => sanitize(item, communicationsFieldsToSend)); const variables = item.variables.reduce((variables, variable) => ({ ...variables, [variable.key]: variable.value, @@ -55,7 +55,23 @@ const preRequestHandler = (item) => { }; const getMembersList = async (params) => { - const fieldsToSend = ['page', 'size', 'search', 'sort', 'fields', 'id', 'parentId']; + const fieldsToSend = [ + 'page', + 'size', + 'search', + 'sort', + 'fields', + 'id', + 'parentId', + 'from', + 'to', + 'bucket', + 'priorityFrom', + 'priorityTo', + 'priority', + 'cause', + 'agent', + ]; const defaultObject = { createdAt: 'unknown', priority: 0, From da85cfc498fe7f82a87ee98cd63341465e0efc05 Mon Sep 17 00:00:00 2001 From: lizacoma Date: Fri, 21 Jul 2023 15:41:58 +0300 Subject: [PATCH 5/8] refactor: queue mambers api --- .../modules/members/api/queueMembers.js | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js index a9262a771..94165e821 100644 --- a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js +++ b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js @@ -4,7 +4,7 @@ import { } from '@webitel/ui-sdk/src/api/defaults'; import applyTransform, { camelToSnake, - handleUnauthorized, + handleUnauthorized, log, merge, mergeEach, notify, sanitize, snakeToCamel, starToSearch, } from '@webitel/ui-sdk/src/api/transformers'; @@ -55,23 +55,6 @@ const preRequestHandler = (item) => { }; const getMembersList = async (params) => { - const fieldsToSend = [ - 'page', - 'size', - 'search', - 'sort', - 'fields', - 'id', - 'parentId', - 'from', - 'to', - 'bucket', - 'priorityFrom', - 'priorityTo', - 'priority', - 'cause', - 'agent', - ]; const defaultObject = { createdAt: 'unknown', priority: 0, @@ -102,7 +85,6 @@ const getMembersList = async (params) => { } = applyTransform(params, [ merge(getDefaultGetParams()), starToSearch('search'), - sanitize(fieldsToSend), ]); try { From 968e47f3467247407a54b92784adc89ab628e27b Mon Sep 17 00:00:00 2001 From: lizacoma Date: Fri, 21 Jul 2023 16:10:57 +0300 Subject: [PATCH 6/8] refactor: queue mambers api --- .../modules/queues/modules/members/api/queueMembers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js index 94165e821..296bff532 100644 --- a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js +++ b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js @@ -4,7 +4,7 @@ import { } from '@webitel/ui-sdk/src/api/defaults'; import applyTransform, { camelToSnake, - handleUnauthorized, log, + handleUnauthorized, merge, mergeEach, notify, sanitize, snakeToCamel, starToSearch, } from '@webitel/ui-sdk/src/api/transformers'; From 04d2f49b63d06de23bfbc8f305efcfe8b772ed7f Mon Sep 17 00:00:00 2001 From: liza-pohranichna Date: Tue, 8 Aug 2023 13:39:28 +0300 Subject: [PATCH 7/8] refactor: removed handleUnauthorized --- .../modules/queues/modules/members/api/queueMembers.js | 9 --------- .../modules/queues/modules/skills/api/queueSkills.js | 7 ------- 2 files changed, 16 deletions(-) diff --git a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js index 296bff532..fe51b78bd 100644 --- a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js +++ b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js @@ -4,7 +4,6 @@ import { } from '@webitel/ui-sdk/src/api/defaults'; import applyTransform, { camelToSnake, - handleUnauthorized, merge, mergeEach, notify, sanitize, snakeToCamel, starToSearch, } from '@webitel/ui-sdk/src/api/transformers'; @@ -123,7 +122,6 @@ const getMembersList = async (params) => { }; } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -163,7 +161,6 @@ const getMember = async ({ parentId, itemId: id }) => { ]); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -182,7 +179,6 @@ const addMember = async ({ parentId, itemInstance }) => { ]); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -201,7 +197,6 @@ const updateMember = async ({ itemInstance, itemId: id, parentId }) => { ]); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -213,7 +208,6 @@ const deleteMember = async ({ parentId, id }) => { return applyTransform(response.data, []); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -227,7 +221,6 @@ const resetMembers = async ({ parentId }) => { ]); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -246,7 +239,6 @@ const addMembersBulk = async (parentId, fileName, items) => { ]); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -274,7 +266,6 @@ export const deleteMembersBulk = async (parentId, { return applyTransform(response.data, []); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } diff --git a/src/modules/contact-center/modules/queues/modules/skills/api/queueSkills.js b/src/modules/contact-center/modules/queues/modules/skills/api/queueSkills.js index 3086fb348..d0fe06a46 100644 --- a/src/modules/contact-center/modules/queues/modules/skills/api/queueSkills.js +++ b/src/modules/contact-center/modules/queues/modules/skills/api/queueSkills.js @@ -5,7 +5,6 @@ import { } from '@webitel/ui-sdk/src/api/defaults'; import applyTransform, { camelToSnake, - merge, mergeEach, notify, sanitize, snakeToCamel, starToSearch, } from '@webitel/ui-sdk/src/api/transformers'; @@ -69,7 +68,6 @@ export const getQueueSkillsList = async (params) => { }; } catch (err) { throw applyTransform(err, [ - notify, ]); } @@ -93,7 +91,6 @@ export const getQueueSkill = async ({ parentId, itemId: id }) => { ]); } catch (err) { throw applyTransform(err, [ - notify, ]); } @@ -112,7 +109,6 @@ export const addQueueSkill = async ({ parentId, itemInstance }) => { ]); } catch (err) { throw applyTransform(err, [ - notify, ]); } @@ -130,7 +126,6 @@ export const patchQueueSkill = async ({ changes, id, parentId }) => { ]); } catch (err) { throw applyTransform(err, [ - notify, ]); } @@ -149,7 +144,6 @@ export const updateQueueSkill = async ({ itemInstance, itemId: id, parentId }) = ]); } catch (err) { throw applyTransform(err, [ - notify, ]); } @@ -161,7 +155,6 @@ export const deleteQueueSkill = async ({ parentId, id }) => { return applyTransform(response.data, []); } catch (err) { throw applyTransform(err, [ - notify, ]); } From ad489ca7c8e049b1e9b431a0503a59ca65106acd Mon Sep 17 00:00:00 2001 From: lizacoma Date: Mon, 6 Nov 2023 22:37:53 +0200 Subject: [PATCH 8/8] refactor: refactor after review [WTEL-3619] --- .../modules/members/api/queueMembers.js | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js index 296bff532..0cbe4531c 100644 --- a/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js +++ b/src/modules/contact-center/modules/queues/modules/members/api/queueMembers.js @@ -4,14 +4,15 @@ import { } from '@webitel/ui-sdk/src/api/defaults'; import applyTransform, { camelToSnake, - handleUnauthorized, merge, mergeEach, notify, sanitize, snakeToCamel, starToSearch, } from '@webitel/ui-sdk/src/api/transformers'; +import deepCopy from 'deep-copy'; import { MemberServiceApiFactory } from 'webitel-sdk'; import instance from '../../../../../../../app/api/instance'; import configuration from '../../../../../../../app/api/openAPIConfig'; + const memberService = new MemberServiceApiFactory(configuration, '', instance); const fieldsToSend = [ @@ -40,18 +41,20 @@ const defaultSingleObjectCommunication = { }; const mapDefaultCommunications = (item) => { - return item.communications ? item.communications + const copy = deepCopy(item); + return copy.communications ? copy.communications .map((comm) => ({ ...defaultSingleObjectCommunication, ...comm })) : []; }; const preRequestHandler = (item) => { - item.communications - .forEach((item) => sanitize(item, communicationsFieldsToSend)); - const variables = item.variables.reduce((variables, variable) => ({ + const copy = deepCopy(item); + copy.communications + .forEach((copy) => sanitize(copy, communicationsFieldsToSend)); + const variables = copy.variables.reduce((variables, variable) => ({ ...variables, [variable.key]: variable.value, }), {}); - return { ...item, variables }; + return { ...copy, variables }; }; const getMembersList = async (params) => { @@ -59,10 +62,14 @@ const getMembersList = async (params) => { createdAt: 'unknown', priority: 0, } + const listHandler = (items) => { - return items.map((item) => ({ + const copy = deepCopy(items); + return copy.map((item) => ({ ...item, - communications: mapDefaultCommunications(item), + communications: applyTransform(item, [ + mapDefaultCommunications, + ]), })); }; @@ -123,7 +130,6 @@ const getMembersList = async (params) => { }; } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -143,14 +149,15 @@ const getMember = async ({ parentId, itemId: id }) => { }; const responseHandler = (response) => { + const copy = deepCopy(response); let variables = []; - if (response.variables) { - variables = Object.keys(response.variables).map((key) => ({ + if (copy.variables) { + variables = Object.keys(copy.variables).map((key) => ({ key, - value: response.variables[key], + value: copy.variables[key], })); } - const communications = mapDefaultCommunications(response); + const communications = mapDefaultCommunications(copy); return { ...response, variables, communications }; }; @@ -163,7 +170,6 @@ const getMember = async ({ parentId, itemId: id }) => { ]); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -182,7 +188,6 @@ const addMember = async ({ parentId, itemInstance }) => { ]); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -201,7 +206,6 @@ const updateMember = async ({ itemInstance, itemId: id, parentId }) => { ]); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -213,7 +217,6 @@ const deleteMember = async ({ parentId, id }) => { return applyTransform(response.data, []); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -227,7 +230,6 @@ const resetMembers = async ({ parentId }) => { ]); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -246,7 +248,6 @@ const addMembersBulk = async (parentId, fileName, items) => { ]); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); } @@ -274,7 +275,6 @@ export const deleteMembersBulk = async (parentId, { return applyTransform(response.data, []); } catch (err) { throw applyTransform(err, [ - handleUnauthorized, notify, ]); }