organizationProfile.ts 3.8 KB

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