organizationProfile.ts 3.8 KB

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