import { ProductModule, ProductTier } from '../../interfaces' export class OrganizationInactiveError extends Error { constructor(message: string) { super(message) this.name = 'OrganizationInactiveError' } } export const filterModulesByTierAndType = ( type?: ProductModule['type'], modules?: ProductModule[], tier?: ProductTier, ) => { return ( modules?.filter( (m) => (type !== undefined ? m.type === type : true) && (tier !== undefined ? isModuleInTier(m, tier) : true), ) || [] ) } export const TIER_ORDER = ['basic', 'standard', 'pro'] export const isModuleInTier = (module: ProductModule, tier: ProductTier) => { return TIER_ORDER.indexOf(tier) >= TIER_ORDER.indexOf(module.lowestTier) }