organizationProfile.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import { organizationState } from '~/types/interfaces'
  2. import {useProfileOrganizationStore} from "~/store/profile/organization";
  3. import {AnyJson} from "~/types/data";
  4. /**
  5. * L'OrganizationProfile permet de manipuler l'OrganizationState auquel
  6. * l'access courant est connecté et qui peuvent être nécessaires pour l'affichage
  7. * de chacune des pages de l'application
  8. * (ex: modules, produit, ...etc)
  9. */
  10. class OrganizationProfile {
  11. private organizationProfile: organizationState
  12. /**
  13. * @constructor
  14. */
  15. constructor () {
  16. this.organizationProfile = useProfileOrganizationStore()
  17. }
  18. /**
  19. * Est-ce que l'organisation possède le module donné
  20. *
  21. * @param {Array<string>} modules Modules à tester
  22. * @return {boolean}
  23. */
  24. hasModule (modules: Array<string>): boolean {
  25. let hasModule = false
  26. modules.map((module) => {
  27. if (this.organizationProfile.modules && this.organizationProfile.modules.includes(module)) { hasModule = true }
  28. })
  29. return hasModule
  30. }
  31. /**
  32. * L'organization fait-elle partie d'un réseau ?
  33. *
  34. * @return {boolean}
  35. */
  36. isInsideNetwork (): boolean {
  37. return this.isCmf() || this.isFfec()
  38. }
  39. /**
  40. * L'organization fait-elle partie du réseau CMF?
  41. *
  42. * @return {boolean}
  43. */
  44. isCmf (): boolean {
  45. return this.organizationProfile.networks.filter((network: string) => {
  46. return network === process.env.cmf_network
  47. }).length > 0
  48. }
  49. /**
  50. * L'organization fait-elle partie du réseau FFEC?
  51. *
  52. * @return {boolean}
  53. */
  54. isFfec (): boolean {
  55. return this.organizationProfile.networks.filter((network: string) => {
  56. return network === process.env.ffec_network
  57. }).length > 0
  58. }
  59. /**
  60. * L'organization possède t'elle un produit premium
  61. * @return {boolean}
  62. */
  63. isArtistProduct (): boolean {
  64. return this.organizationProfile.product === process.env.artist_product
  65. }
  66. /**
  67. * L'organization possède t'elle un produit artiste premium
  68. * @return {boolean}
  69. */
  70. isArtistPremiumProduct (): boolean {
  71. return this.organizationProfile.product === process.env.artist_premium_product
  72. }
  73. /**
  74. * L'organization possède-t-elle un produit school?
  75. *
  76. * @return {boolean}
  77. */
  78. isSchoolProduct (): boolean {
  79. return this.organizationProfile.product === process.env.school_product
  80. }
  81. /**
  82. * L'organization possède-t-elle un produit school-premium?
  83. *
  84. * @return {boolean}
  85. */
  86. isSchoolPremiumProduct (): boolean {
  87. return this.organizationProfile.product === process.env.school_premium_product
  88. }
  89. /**
  90. * L'organization possède-t-elle un produit school ou school-premium
  91. * @return {boolean}
  92. */
  93. isSchool (): boolean {
  94. return this.isSchoolProduct() || this.isSchoolPremiumProduct()
  95. }
  96. /**
  97. * L'organization possède t'elle un produit artiste ou artiste premium
  98. * @return {boolean}
  99. */
  100. isArtist (): boolean {
  101. return this.isArtistProduct() || this.isArtistPremiumProduct()
  102. }
  103. /**
  104. * L'organization possède t'elle un produit manager
  105. * @return {boolean}
  106. */
  107. isManagerProduct (): boolean {
  108. return this.organizationProfile.product === process.env.manager_product
  109. }
  110. /**
  111. * L'organization possède t-elle des enfants
  112. * @return {boolean|null}
  113. */
  114. hasChildren (): any {
  115. return this.organizationProfile.hasChildren
  116. }
  117. /**
  118. * L'organization peut elle afficher la lister des adhérents avec leurs coordonnées
  119. * @return {boolean|null}
  120. */
  121. isShowAdherentList():any{
  122. return this.organizationProfile.showAdherentList;
  123. }
  124. /**
  125. * L'organization est elle une association ?
  126. * @return {boolean|null}
  127. */
  128. isAssociation():any{
  129. return this.organizationProfile.legalStatus === 'ASSOCIATION_LAW_1901';
  130. }
  131. /**
  132. * L'organization est-elle la CMF ?
  133. *
  134. * @return {boolean}
  135. */
  136. isCMFCentralService(): boolean {
  137. if(process.env.CMF_ID)
  138. return this.organizationProfile.id == parseInt(process.env.CMF_ID)
  139. return false
  140. }
  141. getWebsite(): string | null {
  142. return this.organizationProfile.website ?? null
  143. }
  144. /**
  145. * Factory
  146. *
  147. * @return {AnyJson} retourne les fonction rendues publiques
  148. */
  149. handler (): AnyJson {
  150. return {
  151. hasModule: this.hasModule.bind(this),
  152. isSchool: this.isSchool.bind(this),
  153. isArtist: this.isArtist.bind(this),
  154. isManagerProduct: this.isManagerProduct.bind(this),
  155. isOrganizationWithChildren: this.hasChildren.bind(this),
  156. isAssociation: this.isAssociation.bind(this),
  157. isShowAdherentList: this.isShowAdherentList.bind(this),
  158. isCmf: this.isCmf.bind(this),
  159. getWebsite: this.getWebsite.bind(this),
  160. }
  161. }
  162. }
  163. export const $organizationProfile = () => new OrganizationProfile()