Answer the question
In order to leave comments, you need to log in
Is this correct and how will it be correct?
Right now I have 3 controllers, 3 entities, 3 services and 3 modules.
The situation now is that in one of the services I need to refer to the other one, respectively, but nest said something like: you forgot to connect the entity as well, because it is not in the second one.
In the final form, it all looks like services and entities are connected one by one in modules, where almost all services are already connected in the final module, due to some reuse.
Here is the example itself:
PurchaseModule.ts
import { Module } from '@nestjs/common';
import { PurchaseController } from './PurchaseController';
import { PurchaseService } from './PurchaseService';
import { TypeOrmModule } from '@nestjs/typeorm';
import { paymentsEntity } from './purchasedEntity';
import { userEntity } from '../userAuthorization/userEntity';
import { userService } from '../userAuthorization/user.service';
import { ConfigModule } from '@nestjs/config';
import { ForgotEntity } from '../userAuthorization/forgotEntity';
@Module({
imports: [
ConfigModule.forRoot(),
TypeOrmModule.forFeature([paymentsEntity, userEntity, ForgotEntity]),
],
exports: [TypeOrmModule],
controllers:[PurchaseController],
providers: [PurchaseService, userService]
})
export class PurchaseModule{}
import {Module} from '@nestjs/common';
import { userController } from './user.controller';
import { userService } from './user.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { userEntity } from './userEntity';
import { ForgotEntity } from './forgotEntity';
@Module({
imports: [
TypeOrmModule.forFeature([userEntity, ForgotEntity]),
],
exports: [TypeOrmModule],
controllers: [userController],
providers: [userService]
})
export class userModule{}
Answer the question
In order to leave comments, you need to log in
If you want to use providers from one module in another, use an arrayexports: []
@Module({
imports: [
TypeOrmModule.forFeature([UserEntity, ForgotEntity]),
],
controllers: [UserController],
providers: [UserService],
exports: [UserService] // Экспортируем зависимости данного модуля.
})
export class UserModule{}
@Module({
imports: [
TypeOrmModule.forFeature([PaymentsEntity]),
UserModule // Импортируем его сдесь. Теперь в пределах данного модуля нам доступен UserService.
],
controllers: [PurchaseController],
providers: [PurchaseService]
})
export class PurchaseModule {}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question