organizationProfile.ts 3.4 KB

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