organizationProfile.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import type { BaseOrganizationProfile } from '~/types/interfaces'
  2. import { defineStore } from "pinia";
  3. import {computed} from "@vue/reactivity";
  4. import type {Ref} from "@vue/reactivity";
  5. import * as _ from 'lodash-es'
  6. import {LEGAL_STATUS, NETWORK, ORGANIZATION_ID, PRODUCT} from '~/types/enum/enums';
  7. export const useOrganizationProfileStore = defineStore('organizationProfile', () => {
  8. // State
  9. const id: Ref<number | null> = ref(null)
  10. const parametersId: Ref<number | null> = ref(null)
  11. const name: Ref<string | null> = ref(null)
  12. const product: Ref<string | null> = ref(null)
  13. const currentActivityYear: Ref<number | null> = ref(null)
  14. const modules: Ref<Array<string>> = ref([])
  15. const hasChildren: Ref<boolean | null> = ref(false)
  16. const legalStatus: Ref<string | null> = ref(null)
  17. const showAdherentList: Ref<boolean | null> = ref(false)
  18. const networks: Ref<Array<string>> = ref([])
  19. const website: Ref<string | null> = ref(null)
  20. const parents: Ref<Array<BaseOrganizationProfile>> = ref([])
  21. // Getters
  22. /**
  23. * L'organization fait-elle partie du réseau CMF ?
  24. *
  25. * @return {boolean}
  26. */
  27. const isCmf = computed( (): boolean => {
  28. return networks.value && networks.value.filter((network: string) => {
  29. return network === NETWORK.CMF
  30. }).length > 0
  31. })
  32. /**
  33. * L'organization fait-elle partie du réseau FFEC ?
  34. *
  35. * @return {boolean}
  36. */
  37. const isFfec = computed( (): boolean => {
  38. return networks.value && networks.value.filter((network: string) => {
  39. return network === NETWORK.FFEC
  40. }).length > 0
  41. })
  42. /**
  43. * L'organization fait-elle partie d'un réseau ?
  44. *
  45. * @return {boolean}
  46. */
  47. const isInsideNetwork = computed( (): boolean => {
  48. return isCmf.value || isFfec.value
  49. })
  50. /**
  51. * L'organization possède t'elle un produit premium
  52. * @return {boolean}
  53. */
  54. const isArtistProduct = computed( (): boolean => {
  55. return product.value === PRODUCT.ARTIST
  56. })
  57. /**
  58. * L'organization possède t'elle un produit artiste premium
  59. * @return {boolean}
  60. */
  61. const isArtistPremiumProduct = computed( (): boolean => {
  62. return product.value === PRODUCT.ARTIST_PREMIUM
  63. })
  64. /**
  65. * L'organization possède-t-elle un produit artiste ou artiste premium
  66. * @return {boolean}
  67. */
  68. const isArtist = computed( (): boolean => {
  69. return isArtistProduct.value || isArtistPremiumProduct.value
  70. })
  71. /**
  72. * L'organization possède-t-elle un produit school?
  73. *
  74. * @return {boolean}
  75. */
  76. const isSchoolProduct = computed( (): boolean => {
  77. return product.value === PRODUCT.SCHOOL
  78. })
  79. /**
  80. * L'organization possède-t-elle un produit school-premium?
  81. *
  82. * @return {boolean}
  83. */
  84. const isSchoolPremiumProduct = computed( (): boolean => {
  85. return product.value === PRODUCT.SCHOOL_PREMIUM
  86. })
  87. /**
  88. * L'organization possède-t-elle un produit school ou school-premium
  89. * @return {boolean}
  90. */
  91. const isSchool = computed( (): boolean => {
  92. return isSchoolProduct.value || isSchoolPremiumProduct.value
  93. })
  94. /**
  95. * L'organization possède-t-elle un produit manager
  96. * @return {boolean}
  97. */
  98. const isManagerProduct = computed( (): boolean => {
  99. return product.value === PRODUCT.MANAGER
  100. })
  101. /**
  102. * L'organization peut-elle afficher la lister des adhérents avec leurs coordonnées
  103. * @return {boolean|null}
  104. */
  105. const isShowAdherentList = computed(():any => {
  106. return showAdherentList.value;
  107. })
  108. /**
  109. * L'organization est elle une association ?
  110. * @return {boolean|null}
  111. */
  112. const isAssociation = computed(():any => {
  113. return legalStatus.value === LEGAL_STATUS.ASSOCIATION_LAW_1901;
  114. })
  115. /**
  116. * L'organization est-elle la CMF ?
  117. *
  118. * @return {boolean}
  119. */
  120. const isCMFCentralService = computed((): boolean => {
  121. return id.value === ORGANIZATION_ID.CMF
  122. })
  123. const getWebsite = computed((): string | null => {
  124. return website.value ?? null
  125. })
  126. const hasModule = (module: string): boolean => {
  127. return modules.value && modules.value.includes(module)
  128. }
  129. /**
  130. * /!\ Server side only
  131. * @param profile
  132. */
  133. const initiateProfile = (profile: any) => {
  134. setProfile(profile)
  135. // >>> Triggers a listener in plugins/ability
  136. }
  137. // Actions
  138. const setProfile = (profile: any) => {
  139. id.value = profile.id
  140. parametersId.value = profile.parametersId
  141. name.value = profile.name
  142. product.value = profile.product
  143. currentActivityYear.value = profile.currentYear
  144. website.value = profile.website
  145. modules.value = Array.from(profile.modules)
  146. hasChildren.value = profile.hasChildren
  147. legalStatus.value = profile.legalStatus
  148. showAdherentList.value = profile.showAdherentList
  149. networks.value = Array.from(profile.networks)
  150. _.each(profile.parents, (parent) => {
  151. parents.value.push({
  152. id: parent.id,
  153. name: parent.name,
  154. website: parent.website
  155. })
  156. })
  157. }
  158. const refreshProfile = (profile: any) => {
  159. name.value = profile.name
  160. currentActivityYear.value = profile.currentYear
  161. website.value = profile.website
  162. legalStatus.value = profile.legalStatus
  163. }
  164. return {
  165. id,
  166. parametersId,
  167. name,
  168. product,
  169. currentActivityYear,
  170. modules,
  171. hasChildren,
  172. legalStatus,
  173. showAdherentList,
  174. networks,
  175. website,
  176. parents,
  177. isCmf,
  178. isCMFCentralService,
  179. isFfec,
  180. isInsideNetwork,
  181. isArtistProduct,
  182. isArtistPremiumProduct,
  183. isArtist,
  184. isSchoolPremiumProduct,
  185. isSchoolProduct,
  186. isSchool,
  187. isManagerProduct,
  188. isShowAdherentList,
  189. isAssociation,
  190. getWebsite,
  191. hasModule,
  192. setProfile,
  193. refreshProfile,
  194. initiateProfile
  195. }
  196. })