import { Injectable } from '@nestjs/common' import { compact } from 'lodash' import { PlanRepository } from '../../../repositories' import { LanguageCountryCode } from '../../../utils/countries' import { PAYMENT_PROVIDER_DEFAULT } from './consts' import { planToPlanResult } from './converters' import { PlanResult } from './types' @Injectable() export class Plans { constructor(private readonly planRepository: PlanRepository) {} async getAvailable( countryCode: LanguageCountryCode, unitAcronym?: string, complete?: boolean, ): Promise> { const plans = await this.planRepository.findEnabledAndVisible({ language: countryCode, complete }) return compact(plans.map(plan => planToPlanResult(plan, PAYMENT_PROVIDER_DEFAULT, unitAcronym))) } }