-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotowire-api-client.module.ts
59 lines (55 loc) · 1.97 KB
/
rotowire-api-client.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Module, DynamicModule, Global } from '@nestjs/common';
import * as RotowireMlbApi from './rotowire_mlb';
import * as RotowireNbaApi from './rotowire_nba';
import * as RotowireNflApi from './rotowire_nfl';
import { Configuration } from './rotowire_mlb';
interface SportConfig {
basePath: string;
apiKey: string;
}
interface ModuleConfig {
mlb: SportConfig;
nba: SportConfig;
nfl: SportConfig;
}
@Global()
@Module({})
export class RotowireApiClientModule {
static forRootAsync(options: {
imports?: any[];
useFactory: (...args: any[]) => Promise<ModuleConfig> | ModuleConfig;
inject?: any[];
}): DynamicModule {
return {
module: RotowireApiClientModule,
imports: [
RotowireMlbApi.ApiModule.forRootAsync({
imports: options.imports,
useFactory: async (...args: any[]) => rotowireApiConfigFactory((await options.useFactory(...args)).mlb),
inject: options.inject,
}),
RotowireNbaApi.ApiModule.forRootAsync({
imports: options.imports,
useFactory: async (...args: any[]) => rotowireApiConfigFactory((await options.useFactory(...args)).nba),
inject: options.inject,
}),
RotowireNflApi.ApiModule.forRootAsync({
imports: options.imports,
useFactory: async (...args: any[]) => rotowireApiConfigFactory((await options.useFactory(...args)).nfl),
inject: options.inject,
}),
],
exports: [
RotowireMlbApi.ApiModule,
RotowireNbaApi.ApiModule,
RotowireNflApi.ApiModule,
],
};
}
}
function rotowireApiConfigFactory(config: SportConfig): Configuration {
return new Configuration({
basePath: config.basePath,
apiKeys: { "key": config.apiKey },
});
}