service.module.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Module, OnModuleInit } from '@nestjs/common';
  2. import { TypeOrmModule } from '@nestjs/typeorm';
  3. import { ConfigModule } from '../config/config.module';
  4. import { getConfig } from '../config/vendure-config';
  5. import { AdministratorService } from './administrator.service';
  6. import { AuthService } from './auth.service';
  7. import { ChannelService } from './channel.service';
  8. import { CustomerService } from './customer.service';
  9. import { FacetValueService } from './facet-value.service';
  10. import { FacetService } from './facet.service';
  11. import { TranslationUpdaterService } from './helpers/translation-updater.service';
  12. import { PasswordService } from './password.service';
  13. import { ProductOptionGroupService } from './product-option-group.service';
  14. import { ProductOptionService } from './product-option.service';
  15. import { ProductVariantService } from './product-variant.service';
  16. import { ProductService } from './product.service';
  17. import { RoleService } from './role.service';
  18. const exportedProviders = [
  19. AdministratorService,
  20. AuthService,
  21. ChannelService,
  22. CustomerService,
  23. FacetService,
  24. FacetValueService,
  25. ProductOptionService,
  26. ProductOptionGroupService,
  27. ProductService,
  28. ProductVariantService,
  29. RoleService,
  30. ];
  31. /**
  32. * The ServiceModule is responsible for the service layer, i.e. accessing the database
  33. * and implementing the main business logic of the application.
  34. *
  35. * The exported providers are used in the ApiModule, which is responsible for parsing requests
  36. * into a format suitable for the service layer logic.
  37. */
  38. @Module({
  39. imports: [ConfigModule, TypeOrmModule.forRoot(getConfig().dbConnectionOptions)],
  40. providers: [...exportedProviders, PasswordService, TranslationUpdaterService],
  41. exports: exportedProviders,
  42. })
  43. export class ServiceModule implements OnModuleInit {
  44. constructor(
  45. private channelService: ChannelService,
  46. private roleService: RoleService,
  47. private administratorService: AdministratorService,
  48. ) {}
  49. async onModuleInit() {
  50. await this.channelService.initChannels();
  51. await this.roleService.initRoles();
  52. await this.administratorService.initAdministrators();
  53. }
  54. }