Files
edr-platform/apps/edr-freight-api/src/modules/exchange-settings/exchange-module-options.ts

28 lines
1.0 KiB
TypeScript

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<ExchangeOptions>("app.cbeExchange") ?? {}),
loadFallbackRate: () => settings.loadFallbackRate(),
saveFallbackRate: (rate: number) => settings.saveFallbackRate(rate),
}),
});
}