organizationProfile.ts 4.8 KB

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