organization.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import * as _ from 'lodash'
  2. import { baseOrganizationState, organizationState } from '~/types/interfaces'
  3. export const state = () => ({
  4. id: null,
  5. name: '',
  6. product: '',
  7. modules: [],
  8. hasChildren: false,
  9. networks: [],
  10. website: '',
  11. subDomain: '',
  12. parents: []
  13. })
  14. export const mutations = {
  15. setId (state: organizationState, id: number) {
  16. state.id = id
  17. },
  18. setName (state: organizationState, name: string) {
  19. state.name = name
  20. },
  21. setProduct (state: organizationState, product: string) {
  22. state.product = product
  23. },
  24. setModules (state: organizationState, modules: Array<string>) {
  25. state.modules = modules
  26. },
  27. setHasChildren (state: organizationState, hasChildren: boolean) {
  28. state.hasChildren = hasChildren
  29. },
  30. setNetworks (state: organizationState, networks: Array<string>) {
  31. state.networks = networks
  32. },
  33. setParents (state: organizationState, parents: Array<organizationState>) {
  34. state.parents = parents
  35. },
  36. setWebsite (state: organizationState, website: string) {
  37. state.website = website
  38. },
  39. setSubDomain (state: organizationState, subDomain: string) {
  40. state.subDomain = subDomain
  41. },
  42. addParent (state: organizationState, parent: organizationState) {
  43. state.parents.push(parent)
  44. }
  45. }
  46. export const actions = {
  47. setProfile (context: any, profile: any) {
  48. context.commit('setId', profile.id)
  49. context.commit('setName', profile.name)
  50. context.commit('setProduct', profile.product)
  51. context.commit('setWebsite', profile.website)
  52. context.commit('setSubDomain', profile.subDomain)
  53. context.commit('setModules', profile.modules)
  54. context.commit('setHasChildren', profile.hasChildren)
  55. context.commit('setNetworks', profile.networks)
  56. _.each(profile.parents, (parent) => {
  57. const p: baseOrganizationState = {
  58. id: parent.id,
  59. name: parent.name,
  60. website: parent.website,
  61. subDomain: parent.subDomain
  62. }
  63. context.commit('addParent', p)
  64. })
  65. }
  66. }