From c78df757e1268a9932e1cab3a65d677169463969 Mon Sep 17 00:00:00 2001 From: Debora Crescenzo Date: Fri, 7 Jun 2024 15:11:17 +0100 Subject: [PATCH] MT#60187 bugfixes on call forwarding When testing the bugfix mentioned in the ticket I found the below bugs and proceeded with the fixes: - cscCfGroupConditionDate: added try/catch to handle better errors. Before the fix the component was gettign stuck on loading when the backend was returning an error - refactored post() in common.js to reflect sipwise js policy - actions.js: fixed bug to pass correct timeSetId in the cfmapping PATCH requests. Before the fix we were passing an object with all the data of the new timeset rather than the id only and the backend was complaining. Change-Id: I7bfabaf7a1a2aea8c6034de0d8f76e2f90633cdb --- src/api/common.js | 14 +++--- .../CscCfGroupConditionDate.vue | 47 ++++++++++--------- src/store/call-forwarding/actions.js | 16 +++---- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/api/common.js b/src/api/common.js index b09c3d40..473c1f32 100644 --- a/src/api/common.js +++ b/src/api/common.js @@ -272,17 +272,17 @@ export function patchRemoveFull (options) { } export async function post (options) { - options = options || {} - options = _.merge({ + let requestOptions = options || {} + requestOptions = _.merge({ headers: POST_HEADERS }, options) - let path = options.path - if (options.resource !== undefined) { - path = 'api/' + options.resource + '/' + let path = requestOptions.path + if (requestOptions.resource !== undefined) { + path = 'api/' + requestOptions.resource + '/' } try { - const res = await httpApi.post(path, options.body, { - headers: options.headers + const res = await httpApi.post(path, requestOptions.body, { + headers: requestOptions.headers }) const hasBody = res.data !== undefined && res.data !== null && res.data !== '' if (hasBody) { diff --git a/src/components/call-forwarding/CscCfGroupConditionDate.vue b/src/components/call-forwarding/CscCfGroupConditionDate.vue index 73796168..45ed10ad 100644 --- a/src/components/call-forwarding/CscCfGroupConditionDate.vue +++ b/src/components/call-forwarding/CscCfGroupConditionDate.vue @@ -41,6 +41,7 @@ import CscCfGroupCondition from 'components/call-forwarding/CscCfGroupCondition' import { mapActions, mapGetters } from 'vuex' import { timeSetDateExact } from 'src/filters/time-set' +import { showGlobalError } from 'src/helpers/ui' export default { name: 'CscCfGroupConditionDate', components: { @@ -101,27 +102,31 @@ export default { ]), async createTimeSetEvent () { const dateParts = this.selectedDate.split('/') - if (this.timeSet) { - await this.updateTimeSetDate({ - mapping: this.mapping, - id: this.timeSet.id, - subscriberId: this.subscriberId, - date: { - date: dateParts[2], - month: dateParts[1], - year: dateParts[0] - } - }) - } else { - await this.createTimeSetDate({ - mapping: this.mapping, - subscriberId: this.subscriberId, - date: { - date: dateParts[2], - month: dateParts[1], - year: dateParts[0] - } - }) + try { + if (this.timeSet) { + await this.updateTimeSetDate({ + mapping: this.mapping, + id: this.timeSet.id, + subscriberId: this.subscriberId, + date: { + date: dateParts[2], + month: dateParts[1], + year: dateParts[0] + } + }) + } else { + await this.createTimeSetDate({ + mapping: this.mapping, + subscriberId: this.subscriberId, + date: { + date: dateParts[2], + month: dateParts[1], + year: dateParts[0] + } + }) + } + } catch (err) { + showGlobalError(err?.message || this.$t('Unknown error')) } this.$emit('close') }, diff --git a/src/store/call-forwarding/actions.js b/src/store/call-forwarding/actions.js index 65bbd84d..f14ed0f0 100644 --- a/src/store/call-forwarding/actions.js +++ b/src/store/call-forwarding/actions.js @@ -16,18 +16,14 @@ import { cfUpdateTimeSetDateRange, cfUpdateTimeSetWeekdays } from 'src/api/call-forwarding' -import { - v4 -} from 'uuid' +import { v4 } from 'uuid' import { patchReplace, patchReplaceFull, post, put, get, getList } from 'src/api/common' import _ from 'lodash' -import { - showGlobalError -} from 'src/helpers/ui' +import { showGlobalError } from 'src/helpers/ui' const DEFAULT_RING_TIMEOUT = 60 const DEFAULT_PRIORITY = 0 @@ -341,7 +337,7 @@ export async function createTimeSetDate ({ dispatch, commit, rootGetters, state dispatch('wait/start', 'csc-cf-time-set-create', { root: true }) const timeSetId = await cfCreateTimeSetDate(rootGetters['user/getSubscriberId'], payload.date) const updatedMapping = _.cloneDeep(state.mappings[payload.mapping.type]) - updatedMapping[payload.mapping.index].timeset_id = timeSetId + updatedMapping[payload.mapping.index].timeset_id = timeSetId.id const updatedMappings = await patchReplaceFull({ resource: 'cfmappings', resourceId: (payload.subscriberId) ? payload.subscriberId : rootGetters['user/getSubscriberId'], @@ -432,7 +428,7 @@ export async function createTimeSetDateRange ({ dispatch, commit, rootGetters, s dispatch('wait/start', 'csc-cf-time-set-create', { root: true }) const timeSetId = await cfCreateTimeSetDateRange(rootGetters['user/getSubscriberId'], payload.date) const updatedMapping = _.cloneDeep(state.mappings[payload.mapping.type]) - updatedMapping[payload.mapping.index].timeset_id = timeSetId + updatedMapping[payload.mapping.index].timeset_id = timeSetId.id const updatedMappings = await patchReplaceFull({ resource: 'cfmappings', resourceId: (payload.subscriberId) ? payload.subscriberId : rootGetters['user/getSubscriberId'], @@ -461,7 +457,7 @@ export async function createTimeSetWeekdays ({ dispatch, commit, rootGetters, st dispatch('wait/start', 'csc-cf-time-set-create', { root: true }) const timeSetId = await cfCreateTimeSetWeekdays(rootGetters['user/getSubscriberId'], payload.weekdays) const updatedMapping = _.cloneDeep(state.mappings[payload.mapping.type]) - updatedMapping[payload.mapping.index].timeset_id = timeSetId + updatedMapping[payload.mapping.index].timeset_id = timeSetId.id const updatedMappings = await patchReplaceFull({ resource: 'cfmappings', resourceId: (payload.subscriberId) ? payload.subscriberId : rootGetters['user/getSubscriberId'], @@ -490,7 +486,7 @@ export async function createOfficeHours ({ dispatch, commit, rootGetters, state dispatch('wait/start', 'csc-cf-time-set-create', { root: true }) const timeSetId = await cfCreateOfficeHours(rootGetters['user/getSubscriberId'], payload.times) const updatedMapping = _.cloneDeep(state.mappings[payload.mapping.type]) - updatedMapping[payload.mapping.index].timeset_id = timeSetId + updatedMapping[payload.mapping.index].timeset_id = timeSetId.id const updatedMappings = await patchReplaceFull({ resource: 'cfmappings', resourceId: (payload.subscriberId) ? payload.subscriberId : rootGetters['user/getSubscriberId'],