{"size": 1811, "ext": "js", "max_stars_repo_path": "src/store/modules/organizaciones.js", "max_stars_repo_name": "ferjmc/Expedientes-Web", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/store/modules/organizaciones.js", "max_issues_repo_name": "ferjmc/Expedientes-Web", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/store/modules/organizaciones.js", "max_forks_repo_name": "ferjmc/Expedientes-Web", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.1222222222, "max_line_length": 70, "alphanum_fraction": 0.5488680287}
import { fetchList, getOrg, setOrg, getOpt } from '@/api/organizacion'

const state = {
  organizaciones: [{
    id: 1,
    codigo: 1,
    nombre: '',
    children: [],
    createdAt: '',
    createdBy: 1,
    updatedAt: '',
    updatedBy: 1
  }],
  organizacion: {
    id: undefined,
    nombre: '',
    codigo: '',
    parentid: undefined,
    parentcodigo: '',
    parentnombre: ''
  },
  options: {
    id: undefined,
    codigo: undefined,
    nombre: ''
  }
}

const mutations = {
  SET_ORGANIZACIONES: (state, organizaciones) => {
    state.organizaciones = organizaciones
  },
  SET_ORG: (state, org) => {
    state.organizacion = org
  },
  SET_OPTIONS: (state, payload) => {
    state.options = payload
  }
}

const actions = {
  getOrganizaciones({ commit }) {
    return new Promise((resolve, reject) => {
      fetchList().then(response => {
        commit('SET_ORGANIZACIONES', response.data)
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  },
  getOrganizacion({ commit }, id) {
    return new Promise((resolve, reject) => {
      getOrg(id).then(response => {
        commit('SET_ORG', response.data)
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  },
  updateOrganizacion({ commit }, payload) {
    return new Promise((resolve, reject) => {
      setOrg(payload).then(response => {
        commit('SET_ORG', response.data)
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  },
  getOptions({ commit }) {
    return new Promise((resolve, reject) => {
      getOpt().then(response => {
        commit('SET_OPTIONS', response.data)
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
