import {AnyJson, organizationState, OrganizationStore} from "~/types/interfaces"; /** * @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 * @return {boolean} */ hasModule(modules:Array):boolean { let hasModule = false; modules.map((module) => { if (this.organizationProfile.modules && this.organizationProfile.modules.indexOf(module) > -1) hasModule = true }); return hasModule } /** * L'organization fait-elle partie d'un réseau ? * @return {boolean} */ isInsideNetwork(): boolean{ return this.isCmf() || this.isFfec() } /** * L'organization fait-elle partie du réseau CMF ? * @return {boolean} */ isCmf():boolean { const networks = this.organizationProfile.networks.filter( (network:string) => { return network == process.env.cmf_network }); return networks.length > 0; } /** * L'organization fait-elle partie du réseau FFEC ? * @return {boolean} */ isFfec():boolean { const networks = this.organizationProfile.networks.filter( (network:string) => { return network == process.env.ffec_network }); return networks.length > 0; } /** * L'organization possède t'elle un produit school ou school premium * @return {boolean} */ isSchool():boolean { return this.isSchoolProduct() || this.isSchoolPremiumProduct() } /** * L'organization possède t'elle un produit artiste ou artiste premium * @return {boolean} */ isArtist():boolean { return this.isArtistProduct() || this.isArtistPremiumProduct() } /** * L'organization possède t'elle un produit school * @return {boolean} */ isSchoolProduct():boolean { return this.organizationProfile.product === process.env.school_product } /** * L'organization possède t'elle un produit school premium * @return {boolean} */ isSchoolPremiumProduct():boolean { return this.organizationProfile.product === process.env.school_premium_product } /** * L'organization possède t'elle un produit premium * @return {boolean} */ isArtistProduct():boolean { return this.organizationProfile.product === process.env.artist_product } /** * L'organization possède t'elle un produit artiste premium * @return {boolean} */ isArtistPremiumProduct():boolean { return this.organizationProfile.product === process.env.artist_premium_product } /** * L'organization possède t'elle un produit manager * @return {boolean} */ isManagerProduct():boolean { return this.organizationProfile.product === process.env.manager_product } /** * L'organization possède t'elledes enfants * @return {boolean|null} */ isOrganizationWithChildren():any{ return this.organizationProfile.hasChildren; } /** * Factory * @return {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), isCmf: this.isCmf.bind(this) } } } export const $organizationProfile = (store:OrganizationStore) => new OrganizationProfile(store);