返回 AiToEarn
wechat.module.ts
1 import type { DynamicModule } from '@nestjs/common'
2 import { Module } from '@nestjs/common'
3 import { WeChatChannelsModule } from './wechat-channels/wechat-channels.module'
4 import { WeChatOfficialModule } from './wechat-official/wechat-official.module'
5 import { WechatConfig } from './wechat.config'
6 import { WeChatService } from './wechat.service'
7
8 /**
9 * Root WeChat module.
10 *
11 * Accepts the full WeChat config (official + channels) via `forRoot()`,
12 * imports sub-modules with their respective sub-configs, and provides
13 * shared services (WeChatService).
14 *
15 * Registers two platform integrations:
16 * - AccountType.WeChatOfficial (auth + publish)
17 * - AccountType.WeChatChannels (work)
18 */
19 @Module({})
20 export class WechatModule {
21 static forRoot(config: WechatConfig | undefined): DynamicModule {
22 if (!config) {
23 return { module: WechatModule }
24 }
25
26 return {
27 module: WechatModule,
28 imports: [
29 WeChatOfficialModule.forRoot(config.official, config),
30 WeChatChannelsModule.forRoot(config.channels, config),
31 ],
32 providers: [
33 { provide: WechatConfig, useValue: config },
34 WeChatService,
35 ],
36 exports: [
37 WeChatService,
38 WeChatOfficialModule,
39 WeChatChannelsModule,
40 ],
41 }
42 }
43 }
44
44 lines TYPESCRIPT