import { AnyJson, organizationState } from '~/types/interfaces' import {useProfileOrganizationStore} from "~/store/profile/organization"; /** * L'OrganizationProfile permet de manipuler l'OrganizationState auquel * l'access courant est connecté et qui peuvent être nécessaires pour l'affichage * de chacune des pages de l'application * (ex: modules, produit, ...etc) */ class OrganizationProfile { private organizationProfile: organizationState /** * @constructor */ constructor () { this.organizationProfile = useProfileOrganizationStore() } /** * Est-ce que l'organisation possède le module donné * * @param {Array} modules Modules à tester * @return {boolean} */ hasModule (modules: Array): boolean { let hasModule = false modules.map((module) => { if (this.organizationProfile.modules && this.organizationProfile.modules.includes(module)) { 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 { return this.organizationProfile.networks.filter((network: string) => { return network === process.env.cmf_network }).length > 0 } /** * L'organization fait-elle partie du réseau FFEC? * * @return {boolean} */ isFfec (): boolean { return this.organizationProfile.networks.filter((network: string) => { return network === process.env.ffec_network }).length > 0 } /** * 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 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 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 manager * @return {boolean} */ isManagerProduct (): boolean { return this.organizationProfile.product === process.env.manager_product } /** * L'organization possède t-elle des enfants * @return {boolean|null} */ hasChildren (): any { return this.organizationProfile.hasChildren } /** * L'organization peut elle afficher la lister des adhérents avec leurs coordonnées * @return {boolean|null} */ isShowAdherentList():any{ return this.organizationProfile.showAdherentList; } /** * L'organization est elle une association ? * @return {boolean|null} */ isAssociation():any{ return this.organizationProfile.legalStatus === 'ASSOCIATION_LAW_1901'; } /** * L'organization est-elle la CMF ? * * @return {boolean} */ isCMFCentralService(): boolean { if(process.env.CMF_ID) return this.organizationProfile.id == parseInt(process.env.CMF_ID) return false } getWebsite(): string | null { return this.organizationProfile.website ?? null } /** * 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.hasChildren.bind(this), isAssociation: this.isAssociation.bind(this), isShowAdherentList: this.isShowAdherentList.bind(this), isCmf: this.isCmf.bind(this), getWebsite: this.getWebsite.bind(this), } } } export const $organizationProfile = () => new OrganizationProfile()