organizationProfile.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.indexOf(module) > -1)
  25. hasModule = true
  26. });
  27. return hasModule
  28. }
  29. /**
  30. * L'organization fait-elle partie d'un réseau ?
  31. * @return {boolean}
  32. */
  33. isInsideNetwork(): boolean{
  34. return this.isCmf() || this.isFfec()
  35. }
  36. /**
  37. * L'organization fait-elle partie du réseau CMF ?
  38. * @return {boolean}
  39. */
  40. isCmf():boolean {
  41. const networks = this.organizationProfile.networks.filter( (network:string) => {
  42. return network == process.env.cmf_network
  43. });
  44. return networks.length > 0;
  45. }
  46. /**
  47. * L'organization fait-elle partie du réseau FFEC ?
  48. * @return {boolean}
  49. */
  50. isFfec():boolean {
  51. const networks = this.organizationProfile.networks.filter( (network:string) => {
  52. return network == process.env.ffec_network
  53. });
  54. return networks.length > 0;
  55. }
  56. /**
  57. * L'organization possède t'elle un produit school ou school premium
  58. * @return {boolean}
  59. */
  60. isSchool():boolean {
  61. return this.isSchoolProduct() || this.isSchoolPremiumProduct()
  62. }
  63. /**
  64. * L'organization possède t'elle un produit artiste ou artiste premium
  65. * @return {boolean}
  66. */
  67. isArtist():boolean {
  68. return this.isArtistProduct() || this.isArtistPremiumProduct()
  69. }
  70. /**
  71. * L'organization possède t'elle un produit school
  72. * @return {boolean}
  73. */
  74. isSchoolProduct():boolean {
  75. return this.organizationProfile.product === process.env.school_product
  76. }
  77. /**
  78. * L'organization possède t'elle un produit school premium
  79. * @return {boolean}
  80. */
  81. isSchoolPremiumProduct():boolean {
  82. return this.organizationProfile.product === process.env.school_premium_product
  83. }
  84. /**
  85. * L'organization possède t'elle un produit premium
  86. * @return {boolean}
  87. */
  88. isArtistProduct():boolean {
  89. return this.organizationProfile.product === process.env.artist_product
  90. }
  91. /**
  92. * L'organization possède t'elle un produit artiste premium
  93. * @return {boolean}
  94. */
  95. isArtistPremiumProduct():boolean {
  96. return this.organizationProfile.product === process.env.artist_premium_product
  97. }
  98. /**
  99. * L'organization possède t'elle un produit manager
  100. * @return {boolean}
  101. */
  102. isManagerProduct():boolean {
  103. return this.organizationProfile.product === process.env.manager_product
  104. }
  105. /**
  106. * L'organization possède t'elledes enfants
  107. * @return {boolean|null}
  108. */
  109. isOrganizationWithChildren():any{
  110. return this.organizationProfile.hasChildren;
  111. }
  112. /**
  113. * Factory
  114. * @return {AnyJson} retourne les fonction rendues publiques
  115. */
  116. handler():AnyJson{
  117. return {
  118. hasModule: this.hasModule.bind(this),
  119. isSchool: this.isSchool.bind(this),
  120. isArtist: this.isArtist.bind(this),
  121. isManagerProduct: this.isManagerProduct.bind(this),
  122. isOrganizationWithChildren: this.isOrganizationWithChildren.bind(this),
  123. isCmf: this.isCmf.bind(this)
  124. }
  125. }
  126. }
  127. export const $organizationProfile = (store:OrganizationStore) => new OrganizationProfile(store);