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
mr13.0
Debora Crescenzo 1 year ago committed by Nouhaila Idrissi-Zouggari
parent 668e23dfab
commit c78df757e1

@ -272,17 +272,17 @@ export function patchRemoveFull (options) {
} }
export async function post (options) { export async function post (options) {
options = options || {} let requestOptions = options || {}
options = _.merge({ requestOptions = _.merge({
headers: POST_HEADERS headers: POST_HEADERS
}, options) }, options)
let path = options.path let path = requestOptions.path
if (options.resource !== undefined) { if (requestOptions.resource !== undefined) {
path = 'api/' + options.resource + '/' path = 'api/' + requestOptions.resource + '/'
} }
try { try {
const res = await httpApi.post(path, options.body, { const res = await httpApi.post(path, requestOptions.body, {
headers: options.headers headers: requestOptions.headers
}) })
const hasBody = res.data !== undefined && res.data !== null && res.data !== '' const hasBody = res.data !== undefined && res.data !== null && res.data !== ''
if (hasBody) { if (hasBody) {

@ -41,6 +41,7 @@
import CscCfGroupCondition from 'components/call-forwarding/CscCfGroupCondition' import CscCfGroupCondition from 'components/call-forwarding/CscCfGroupCondition'
import { mapActions, mapGetters } from 'vuex' import { mapActions, mapGetters } from 'vuex'
import { timeSetDateExact } from 'src/filters/time-set' import { timeSetDateExact } from 'src/filters/time-set'
import { showGlobalError } from 'src/helpers/ui'
export default { export default {
name: 'CscCfGroupConditionDate', name: 'CscCfGroupConditionDate',
components: { components: {
@ -101,27 +102,31 @@ export default {
]), ]),
async createTimeSetEvent () { async createTimeSetEvent () {
const dateParts = this.selectedDate.split('/') const dateParts = this.selectedDate.split('/')
if (this.timeSet) { try {
await this.updateTimeSetDate({ if (this.timeSet) {
mapping: this.mapping, await this.updateTimeSetDate({
id: this.timeSet.id, mapping: this.mapping,
subscriberId: this.subscriberId, id: this.timeSet.id,
date: { subscriberId: this.subscriberId,
date: dateParts[2], date: {
month: dateParts[1], date: dateParts[2],
year: dateParts[0] month: dateParts[1],
} year: dateParts[0]
}) }
} else { })
await this.createTimeSetDate({ } else {
mapping: this.mapping, await this.createTimeSetDate({
subscriberId: this.subscriberId, mapping: this.mapping,
date: { subscriberId: this.subscriberId,
date: dateParts[2], date: {
month: dateParts[1], date: dateParts[2],
year: dateParts[0] month: dateParts[1],
} year: dateParts[0]
}) }
})
}
} catch (err) {
showGlobalError(err?.message || this.$t('Unknown error'))
} }
this.$emit('close') this.$emit('close')
}, },

@ -16,18 +16,14 @@ import {
cfUpdateTimeSetDateRange, cfUpdateTimeSetDateRange,
cfUpdateTimeSetWeekdays cfUpdateTimeSetWeekdays
} from 'src/api/call-forwarding' } from 'src/api/call-forwarding'
import { import { v4 } from 'uuid'
v4
} from 'uuid'
import { import {
patchReplace, patchReplace,
patchReplaceFull, patchReplaceFull,
post, put, get, getList post, put, get, getList
} from 'src/api/common' } from 'src/api/common'
import _ from 'lodash' import _ from 'lodash'
import { import { showGlobalError } from 'src/helpers/ui'
showGlobalError
} from 'src/helpers/ui'
const DEFAULT_RING_TIMEOUT = 60 const DEFAULT_RING_TIMEOUT = 60
const DEFAULT_PRIORITY = 0 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 }) dispatch('wait/start', 'csc-cf-time-set-create', { root: true })
const timeSetId = await cfCreateTimeSetDate(rootGetters['user/getSubscriberId'], payload.date) const timeSetId = await cfCreateTimeSetDate(rootGetters['user/getSubscriberId'], payload.date)
const updatedMapping = _.cloneDeep(state.mappings[payload.mapping.type]) 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({ const updatedMappings = await patchReplaceFull({
resource: 'cfmappings', resource: 'cfmappings',
resourceId: (payload.subscriberId) ? payload.subscriberId : rootGetters['user/getSubscriberId'], 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 }) dispatch('wait/start', 'csc-cf-time-set-create', { root: true })
const timeSetId = await cfCreateTimeSetDateRange(rootGetters['user/getSubscriberId'], payload.date) const timeSetId = await cfCreateTimeSetDateRange(rootGetters['user/getSubscriberId'], payload.date)
const updatedMapping = _.cloneDeep(state.mappings[payload.mapping.type]) 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({ const updatedMappings = await patchReplaceFull({
resource: 'cfmappings', resource: 'cfmappings',
resourceId: (payload.subscriberId) ? payload.subscriberId : rootGetters['user/getSubscriberId'], 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 }) dispatch('wait/start', 'csc-cf-time-set-create', { root: true })
const timeSetId = await cfCreateTimeSetWeekdays(rootGetters['user/getSubscriberId'], payload.weekdays) const timeSetId = await cfCreateTimeSetWeekdays(rootGetters['user/getSubscriberId'], payload.weekdays)
const updatedMapping = _.cloneDeep(state.mappings[payload.mapping.type]) 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({ const updatedMappings = await patchReplaceFull({
resource: 'cfmappings', resource: 'cfmappings',
resourceId: (payload.subscriberId) ? payload.subscriberId : rootGetters['user/getSubscriberId'], 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 }) dispatch('wait/start', 'csc-cf-time-set-create', { root: true })
const timeSetId = await cfCreateOfficeHours(rootGetters['user/getSubscriberId'], payload.times) const timeSetId = await cfCreateOfficeHours(rootGetters['user/getSubscriberId'], payload.times)
const updatedMapping = _.cloneDeep(state.mappings[payload.mapping.type]) 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({ const updatedMappings = await patchReplaceFull({
resource: 'cfmappings', resource: 'cfmappings',
resourceId: (payload.subscriberId) ? payload.subscriberId : rootGetters['user/getSubscriberId'], resourceId: (payload.subscriberId) ? payload.subscriberId : rootGetters['user/getSubscriberId'],

Loading…
Cancel
Save