import { AnyJson, organizationState, OrganizationStore } from '~/types/interfaces' /** * 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 * @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 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 } /** * 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), isCmf: this.isCmf.bind(this) } } } export const $organizationProfile = (store:OrganizationStore) => new OrganizationProfile(store)