All files / app/assets/javascripts/admin/statistics_panel/store actions.js

100% Statements 12/12
100% Branches 0/0
100% Functions 6/6
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28            11x   2x 11x   11x   10x   1x     2x 18x   2x 1x 1x        
import Api from '~/api';
import { createAlert } from '~/alert';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { s__ } from '~/locale';
import * as types from './mutation_types';
 
export const requestStatistics = ({ commit }) => commit(types.REQUEST_STATISTICS);
 
export const fetchStatistics = ({ dispatch }) => {
  dispatch('requestStatistics');
 
  Api.adminStatistics()
    .then(({ data }) => {
      dispatch('receiveStatisticsSuccess', convertObjectPropsToCamelCase(data, { deep: true }));
    })
    .catch((error) => dispatch('receiveStatisticsError', error));
};
 
export const receiveStatisticsSuccess = ({ commit }, statistics) =>
  commit(types.RECEIVE_STATISTICS_SUCCESS, statistics);
 
export const receiveStatisticsError = ({ commit }, error) => {
  commit(types.RECEIVE_STATISTICS_ERROR, error);
  createAlert({
    message: s__('AdminDashboard|Error loading the statistics. Please try again'),
  });
};