mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-03 10:53:40 +00:00
28 lines
1.0 KiB
TypeScript
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),
|
|
}),
|
|
});
|
|
}
|