organizationProfile.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. * @returns {boolean}
  20. */
  21. hasModule(modules:Array<string>) {
  22. let hasModule = false;
  23. modules.map((module) => {
  24. if (this.organizationProfile.modules.indexOf(module) > -1)
  25. hasModule = true;
  26. });
  27. return hasModule;
  28. }
  29. /**
  30. * L'organization possède t'elle un produit school ou school premium
  31. * @returns {boolean}
  32. */
  33. isSchool():boolean {
  34. return this.isSchoolProduct() || this.isSchoolPremiumProduct();
  35. }
  36. /**
  37. * L'organization possède t'elle un produit artiste ou artiste premium
  38. * @returns {boolean}
  39. */
  40. isArtist():boolean {
  41. return this.isArtistProduct() || this.isArtistPremiumProduct();
  42. }
  43. /**
  44. * L'organization possède t'elle un produit school
  45. * @returns {boolean}
  46. */
  47. isSchoolProduct() {
  48. return this.organizationProfile.product === process.env.school_product
  49. }
  50. /**
  51. * L'organization possède t'elle un produit school premium
  52. * @returns {boolean}
  53. */
  54. isSchoolPremiumProduct() {
  55. return this.organizationProfile.product === process.env.school_premium_product
  56. }
  57. /**
  58. * L'organization possède t'elle un produit premium
  59. * @returns {boolean}
  60. */
  61. isArtistProduct() {
  62. return this.organizationProfile.product === process.env.artist_product
  63. }
  64. /**
  65. * L'organization possède t'elle un produit artiste premium
  66. * @returns {boolean}
  67. */
  68. isArtistPremiumProduct() {
  69. return this.organizationProfile.product === process.env.artist_premium_product
  70. }
  71. /**
  72. * L'organization possède t'elle un produit manager
  73. * @returns {boolean}
  74. */
  75. isManagerProduct() {
  76. return this.organizationProfile.product === process.env.manager_product
  77. }
  78. /**
  79. * L'organization possède t'elledes enfants
  80. * @returns {boolean}
  81. */
  82. isOrganizationWithChildren(){
  83. return this.organizationProfile.hasChildren;
  84. }
  85. /**
  86. * Factory
  87. * @returns {AnyJson} retourne les fonction rendues publiques
  88. */
  89. handler():AnyJson{
  90. return {
  91. hasModule: this.hasModule.bind(this),
  92. isSchool: this.isSchool.bind(this),
  93. isArtist: this.isArtist.bind(this),
  94. isManagerProduct: this.isManagerProduct.bind(this),
  95. isOrganizationWithChildren: this.isOrganizationWithChildren.bind(this)
  96. }
  97. }
  98. }
  99. export const organizationProfile = (store:OrganizationStore) => new OrganizationProfile(store);