import {AnyJson, organizationState, OrganizationStore} from "~/types/types"; /** * @category Services/profiles * @class OrganizationProfile * Classe répondant aux différentes questions que l'on peut se poser sur l'organization de l'access connecté */ class OrganizationProfile{ private organizationProfile:organizationState /** * @constructor * @param {OrganizationStore} store State organization du store contenant les informations de l'organisation */ constructor(store:OrganizationStore) { this.organizationProfile = store.state.profile.organization } /** * Est-ce que l'organisation possède le module * @param {Array} modules Modules à tester * @returns {boolean} */ hasModule(modules:Array) { let hasModule = false; modules.map((module) => { if (this.organizationProfile.modules.indexOf(module) > -1) hasModule = true; }); return hasModule; } /** * L'organization possède t'elle un produit school ou school premium * @returns {boolean} */ isSchool():boolean { return this.isSchoolProduct() || this.isSchoolPremiumProduct(); } /** * L'organization possède t'elle un produit artiste ou artiste premium * @returns {boolean} */ isArtist():boolean { return this.isArtistProduct() || this.isArtistPremiumProduct(); } /** * L'organization possède t'elle un produit school * @returns {boolean} */ isSchoolProduct() { return this.organizationProfile.product === process.env.school_product } /** * L'organization possède t'elle un produit school premium * @returns {boolean} */ isSchoolPremiumProduct() { return this.organizationProfile.product === process.env.school_premium_product } /** * L'organization possède t'elle un produit premium * @returns {boolean} */ isArtistProduct() { return this.organizationProfile.product === process.env.artist_product } /** * L'organization possède t'elle un produit artiste premium * @returns {boolean} */ isArtistPremiumProduct() { return this.organizationProfile.product === process.env.artist_premium_product } /** * L'organization possède t'elle un produit manager * @returns {boolean} */ isManagerProduct() { return this.organizationProfile.product === process.env.manager_product } /** * L'organization possède t'elledes enfants * @returns {boolean} */ isOrganizationWithChildren(){ return this.organizationProfile.hasChildren; } /** * Factory * @returns {AnyJson} retourne les fonction rendues publiques */ handler():AnyJson{ return { hasModule: this.hasModule.bind(this), isSchool: this.isSchool.bind(this), isArtist: this.isArtist.bind(this), isManagerProduct: this.isManagerProduct.bind(this), isOrganizationWithChildren: this.isOrganizationWithChildren.bind(this) } } } export const organizationProfile = (store:OrganizationStore) => new OrganizationProfile(store);