diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index 6d7e7613..ceb152c0 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -103,28 +103,31 @@ const actions: ActionTree = { ...payload } - const facilities = JSON.parse(JSON.stringify(state.facilities.list)); - let total = 0, facilityList = []; + let facilities = JSON.parse(JSON.stringify(state.facilities.list)); + let total = 0; try { const resp = await FacilityService.fetchFacilities(params) - - if(!hasError(resp) && resp.data.count) { + + if(!hasError(resp) && resp.data.count > 0) { if(payload.viewIndex && payload.viewIndex > 0) { - facilityList = facilities.concat(resp.data.docs) + facilities = facilities.concat(resp.data.docs) } else { - facilityList = resp.data.docs + facilities = resp.data.docs } total = resp.data.count } else { throw resp.data } } catch(error) { - logger.error(error) + if (payload.viewIndex === 0) { + facilities = []; + total = 0; + } } + commit(types.FACILITY_LIST_UPDATED , { facilities, total }); emitter.emit("dismissLoader"); - commit(types.FACILITY_LIST_UPDATED , { facilities: facilityList, total }); if(facilities.length) { await dispatch('fetchFacilitiesAdditionalInformation', payload)