import { ExchangeModule, ExchangeOptions } from "@edr/api-common"; import { ConfigService } from "@nestjs/config"; import { DynamicModule } from "@nestjs/common"; import { ExchangeSettingsService } from "./exchange-settings.service"; /** * The app's single `ExchangeModule` registration shape: CBE endpoint config * from `app.cbeExchange`, with the DB-backed fallback wired in. * * `ExchangeModule` is registered per-feature-module (bookings, contracts, * warehouses), so this keeps the three call sites identical rather than * letting their options drift apart. */ export function registerExchangeModule(): DynamicModule { return ExchangeModule.forRootAsync({ inject: [ConfigService, ExchangeSettingsService], useFactory: ( config: ConfigService, settings: ExchangeSettingsService, ): ExchangeOptions => ({ ...(config.get("app.cbeExchange") ?? {}), loadFallbackRate: () => settings.loadFallbackRate(), saveFallbackRate: (rate: number) => settings.saveFallbackRate(rate), }), }); }