English 中文(简体)
NestJS: organizing providers to be shared among several controllers
原标题:
  • 时间:2023-06-27 02:07:48
  •  标签:
  • nestjs

I have seen the following project structure so far:

src
- cats
  - dto
    - create-cat.dto.ts
  - interfaces
    - cat.interface.ts
  - cats.controller.ts
  - cats.module.ts
  - cats.service.ts
- app.module.ts
- main.ts

The cats module units related functionalities (service and controller) and it makes sense.

Let s now imagine we have 2 parts of our application:

  • Customer portal for users to manage their cats.
  • Admin panel for admins to manage all cats.

Each part needs its own controller, but I feel like both controllers should use the same service. What would be a proper way to achieve this functionality?

Is it a good idea to make a module for service and 2 modules for controllers importing it? Or maybe 1 module for both controllers? The best option, which comes to my mind just make a controllers directory and make each controller (admin and portal) part of the same cats module.

问题回答

暂无回答




相关问题
how to have http response with pipe throwing error?

I have a nestjs application in which I created a pipe to check if value is a valid URL. If the URL is invalid, throw error. This is used in a controller to save an item into the database. I just ...

Can t set cookie in response NestJs

I Have a nestjs graphQL auth microservice and trying to set a http only cookie containing the token, and for some reason setting the cookie doesn t work, i get this error: { "errors": [ ...

store data in memory with nestjs

I am trying to persist some data in my nestjs server so I can then use that data in my client app through http requests. I have created a products.service.ts file with the function getAllData() that ...

NestJS ConfigModule not loading the correct .env file

I have 2 different file with environment variables: .env.development and .env.production. I am trying to load the correct file through the ConfigModule like so: app.module.ts @Module({ imports: [ ...

热门标签