HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/assets/vue/widgets/Worklist/store/tasks/actions.js
import {
  TASK_ACTION_GET_TASK_LIST,
  TASK_MUTATION_SET_TASK_LIST_LOADING,
  TASK_MUTATION_SET_ERROR,
  TASK_MUTATION_SET_PAGE_META,
  TASK_MUTATION_SET_TASK_LIST,
  TASK_GETTER_LATEST_TASK_CREATED_DATE,
  TASK_ACTION_RESET_ERROR,
  TASK_MUTATION_SET_CURRENT_PAGE_TASK_LIST,
  TASK_ACTION_SET_CURRENT_PAGE_TASK_LIST,
  TASK_ACTION_SET_STATUS_FILTER_TASK_LIST,
  TASK_MUTATION_SET_STATUS_FILTER_TASK_LIST,
  TASK_ACTION_GET_TASKS_META,
  TASK_MUTATION_SET_TASKS_META,
  TASK_ACTION_RELOAD_TASK_LIST,
  TASK_MUTATION_RELOAD_TASK_LIST,
  TASK_MUTATION_SET_TASK_AGGREGATIONS,
  TASK_ACTION_SET_TYPE_FILTER_TASK_LIST,
  TASK_MUTATION_SET_TYPE_FILTER_TASK_LIST,
  TASK_ACTION_GET_NEW_TASK_LIST,
  TASK_MUTATION_SET_NEW_TASK_LIST_LOADING,
  TASK_MUTATION_SET_PAGE_META_RECORD_COUNT,
  ROOT_ACTION_GET_LEAD_INTERACTIONS,
} from '../../constants';

import WorklistService from '../../../../service/worklistService';
export default {
  async [TASK_ACTION_GET_TASK_LIST]({ commit, state, getters }) {
    commit(TASK_MUTATION_SET_TASK_LIST_LOADING, true);
    const {
      data: { data, message, success },
    } = await WorklistService.getAllTasks({
      limit: state.taskfetchLimit,
      currentpage: state.currentpage,
      taskType: state.taskTypeFilter === 'ALL' ? '' : state.taskTypeFilter,
      taskStatus:
        state.taskStatusFilter === 'ALL' ? '' : state.taskStatusFilter,
      dateRangeStart: getters[TASK_GETTER_LATEST_TASK_CREATED_DATE]
        ? getters[TASK_GETTER_LATEST_TASK_CREATED_DATE]
        : '',
    });
    if (!success) {
      commit(TASK_MUTATION_SET_ERROR, message);
    } else {
      commit(TASK_MUTATION_SET_PAGE_META, data.pagination);
      commit(TASK_MUTATION_SET_TASK_LIST, [...state.tasks, ...data.records]);
      commit(TASK_MUTATION_SET_TASK_AGGREGATIONS, data.aggregations);
    }
    commit(TASK_MUTATION_SET_TASK_LIST_LOADING, false);
  },
  async [TASK_ACTION_GET_NEW_TASK_LIST]({ commit, state, getters }) {
    commit(TASK_MUTATION_SET_NEW_TASK_LIST_LOADING, true);
    const {
      data: { data, message, success },
    } = await WorklistService.getAllTasks({
      limit: state.taskfetchLimit,
      currentpage: 1,
      taskType: state.taskTypeFilter === 'ALL' ? '' : state.taskTypeFilter,
      taskStatus:
        state.taskStatusFilter === 'ALL' ? '' : state.taskStatusFilter,
      dateRangeEnd: getters[TASK_GETTER_LATEST_TASK_CREATED_DATE]
        ? getters[TASK_GETTER_LATEST_TASK_CREATED_DATE]
        : '',
    });
    if (!success) {
      commit(TASK_MUTATION_SET_ERROR, message);
    } else {
      commit(TASK_MUTATION_SET_PAGE_META_RECORD_COUNT, data.pagination);
      commit(TASK_MUTATION_SET_TASK_LIST, [...data.records, ...state.tasks]);
      commit(TASK_MUTATION_SET_TASK_AGGREGATIONS, data.aggregations);
    }
    commit(TASK_MUTATION_SET_NEW_TASK_LIST_LOADING, false);
  },
  [TASK_ACTION_RESET_ERROR]({ commit }) {
    commit(TASK_MUTATION_SET_ERROR, null);
  },
  [TASK_ACTION_SET_CURRENT_PAGE_TASK_LIST]({ commit }, payload) {
    commit(TASK_MUTATION_SET_CURRENT_PAGE_TASK_LIST, payload);
  },
  [TASK_ACTION_SET_STATUS_FILTER_TASK_LIST]({ commit }, payload) {
    commit(TASK_MUTATION_SET_STATUS_FILTER_TASK_LIST, payload);
  },
  [TASK_ACTION_SET_TYPE_FILTER_TASK_LIST]({ commit }, payload) {
    commit(TASK_MUTATION_SET_TYPE_FILTER_TASK_LIST, payload);
  },
  async [TASK_ACTION_GET_TASKS_META]({ commit, getters, dispatch }) {
    const {
      data: { data },
    } = await WorklistService.getTaskMeta();
    commit(TASK_MUTATION_SET_TASKS_META, data);
    if (
      new Date(data.latestTaskCreatedAt) >
      new Date(getters[TASK_GETTER_LATEST_TASK_CREATED_DATE])
    ) {
      dispatch(TASK_ACTION_GET_NEW_TASK_LIST);
    }
  },
  [TASK_ACTION_RELOAD_TASK_LIST]({ commit }) {
    commit(TASK_MUTATION_RELOAD_TASK_LIST);
  },
};