diff --git a/content/openapi/introduction.md b/content/openapi/introduction.md index 8c5e469d0f..9f901779fe 100644 --- a/content/openapi/introduction.md +++ b/content/openapi/introduction.md @@ -148,7 +148,7 @@ export interface SwaggerDocumentOptions { } ``` -For example, if you want to make sure that the library generates operation names like `createUser` instead of `UserController_createUser`, you can set the following: +For example, if you want to make sure that the library generates operation names like `createUser` instead of `UsersController_createUser`, you can set the following: ```TypeScript const options: SwaggerDocumentOptions = { diff --git a/content/recipes/async-local-storage.md b/content/recipes/async-local-storage.md index 74e6ed20ca..ea7422b163 100644 --- a/content/recipes/async-local-storage.md +++ b/content/recipes/async-local-storage.md @@ -36,9 +36,9 @@ export class AlsModule {} ```ts @@filename(app.module) @Module({ - imports: [AlsModule] - providers: [CatService], - controllers: [CatController], + imports: [AlsModule], + providers: [CatsService], + controllers: [CatsController], }) export class AppModule implements NestModule { constructor( @@ -64,9 +64,9 @@ export class AppModule implements NestModule { } @@switch @Module({ - imports: [AlsModule] - providers: [CatService], - controllers: [CatController], + imports: [AlsModule], + providers: [CatsService], + controllers: [CatsController], }) @Dependencies(AsyncLocalStorage) export class AppModule { @@ -96,37 +96,37 @@ export class AppModule { 3. Now, anywhere within the lifecycle of a request, we can access the local store instance. ```ts -@@filename(cat.service) +@@filename(cats.service) @Injectable() -export class CatService { +export class CatsService { constructor( // We can inject the provided ALS instance. private readonly als: AsyncLocalStorage, - private readonly catRepository: CatRepository, + private readonly catsRepository: CatsRepository, ) {} getCatForUser() { // The "getStore" method will always return the // store instance associated with the given request. const userId = this.als.getStore()["userId"] as number; - return this.catRepository.getForUser(userId); + return this.catsRepository.getForUser(userId); } } @@switch @Injectable() -@Dependencies(AsyncLocalStorage, CatRepository) -export class CatService { - constructor(als, catRepository) { +@Dependencies(AsyncLocalStorage, CatsRepository) +export class CatsService { + constructor(als, catsRepository) { // We can inject the provided ALS instance. this.als = als - this.catRepository = catRepository + this.catsRepository = catsRepository } getCatForUser() { // The "getStore" method will always return the // store instance associated with the given request. const userId = this.als.getStore()["userId"] as number; - return this.catRepository.getForUser(userId); + return this.catsRepository.getForUser(userId); } } ``` @@ -175,8 +175,8 @@ A similar functionality as described [above](recipes/async-local-storage#custom- }, }), ], - providers: [CatService], - controllers: [CatController], + providers: [CatsService], + controllers: [CatsController], }) export class AppModule {} ``` @@ -184,35 +184,35 @@ export class AppModule {} 2. And then can use the `ClsService` to access the store values. ```ts -@@filename(cat.service) +@@filename(cats.service) @Injectable() -export class CatService { +export class CatsService { constructor( // We can inject the provided ClsService instance, private readonly cls: ClsService, - private readonly catRepository: CatRepository, + private readonly catsRepository: CatsRepository, ) {} getCatForUser() { // and use the "get" method to retrieve any stored value. const userId = this.cls.get('userId'); - return this.catRepository.getForUser(userId); + return this.catsRepository.getForUser(userId); } } @@switch @Injectable() -@Dependencies(AsyncLocalStorage, CatRepository) -export class CatService { - constructor(cls, catRepository) { +@Dependencies(AsyncLocalStorage, CatsRepository) +export class CatsService { + constructor(cls, catsRepository) { // We can inject the provided ClsService instance, this.cls = cls - this.catRepository = catRepository + this.catsRepository = catsRepository } getCatForUser() { // and use the "get" method to retrieve any stored value. const userId = this.cls.get('userId'); - return this.catRepository.getForUser(userId); + return this.catsRepository.getForUser(userId); } } ``` @@ -233,19 +233,19 @@ Since the `ClsService` is just another injectable provider, it can be entirely m However, in certain integration tests, we might still want to use the real `ClsService` implementation. In that case, we will need to wrap the context-aware piece of code with a call to `ClsService#run` or `ClsService#runWith`. ```ts -describe('CatService', () => { - let service: CatService +describe('CatsService', () => { + let service: CatsService let cls: ClsService - const mockCatRepository = createMock() + const mockCatsRepository = createMock() beforeEach(async () => { const module = await Test.createTestingModule({ // Set up most of the testing module as we normally would. providers: [ - CatService, + CatsService, { - provide: CatRepository - useValue: mockCatRepository + provide: CatsRepository + useValue: mockCatsRepository } ], imports: [ @@ -255,7 +255,7 @@ describe('CatService', () => { ], }).compile() - service = module.get(CatService) + service = module.get(CatsService) // Also retrieve the ClsService for later use. cls = module.get(ClsService) @@ -264,7 +264,7 @@ describe('CatService', () => { describe('getCatForUser', () => { it('retrieves cat based on user id', async () => { const expectedUserId = 42 - mockCatRepository.getForUser.mockImplementationOnce( + mocksCatsRepository.getForUser.mockImplementationOnce( (id) => ({ userId: id }) ) diff --git a/content/recipes/cqrs.md b/content/recipes/cqrs.md index ba8ce32912..0b3df8079a 100644 --- a/content/recipes/cqrs.md +++ b/content/recipes/cqrs.md @@ -112,7 +112,7 @@ Let's create a handler for the `KillDragonCommand` command. @@filename(kill-dragon.handler) @CommandHandler(KillDragonCommand) export class KillDragonHandler implements ICommandHandler { - constructor(private repository: HeroRepository) {} + constructor(private repository: HeroesRepository) {} async execute(command: KillDragonCommand) { const { heroId, dragonId } = command; @@ -129,7 +129,7 @@ export class KillDragonHandler implements ICommandHandler { } @@switch @CommandHandler(KillDragonCommand) -@Dependencies(HeroRepository) +@Dependencies(HeroesRepository) export class KillDragonHandler { constructor(repository) { this.repository = repository; @@ -180,7 +180,7 @@ To retrieve the hero, we need to create a query handler: @@filename(get-hero.handler) @QueryHandler(GetHeroQuery) export class GetHeroHandler implements IQueryHandler { - constructor(private repository: HeroRepository) {} + constructor(private repository: HeroesRepository) {} async execute(query: GetHeroQuery) { return this.repository.findOneById(query.hero); @@ -188,7 +188,7 @@ export class GetHeroHandler implements IQueryHandler { } @@switch @QueryHandler(GetHeroQuery) -@Dependencies(HeroRepository) +@Dependencies(HeroesRepository) export class GetHeroHandler { constructor(repository) { this.repository = repository; @@ -272,7 +272,7 @@ The `apply()` method is used to dispatch events. It accepts an event object as a @CommandHandler(KillDragonCommand) export class KillDragonHandler implements ICommandHandler { constructor( - private repository: HeroRepository, + private repository: HeroesRepository, private publisher: EventPublisher, ) {} @@ -287,7 +287,7 @@ export class KillDragonHandler implements ICommandHandler { } @@switch @CommandHandler(KillDragonCommand) -@Dependencies(HeroRepository, EventPublisher) +@Dependencies(HeroesRepository, EventPublisher) export class KillDragonHandler { constructor(repository, publisher) { this.repository = repository; @@ -341,7 +341,7 @@ Each event can have multiple **Event Handlers**. @@filename(hero-killed-dragon.handler) @EventsHandler(HeroKilledDragonEvent) export class HeroKilledDragonHandler implements IEventHandler { - constructor(private repository: HeroRepository) {} + constructor(private repository: HeroesRepository) {} handle(event: HeroKilledDragonEvent) { // Business logic diff --git a/content/recipes/prisma.md b/content/recipes/prisma.md index cb7994fabc..427f03b092 100644 --- a/content/recipes/prisma.md +++ b/content/recipes/prisma.md @@ -296,7 +296,7 @@ import { PrismaService } from './prisma.service'; import { User, Prisma } from '@prisma/client'; @Injectable() -export class UserService { +export class UsersService { constructor(private prisma: PrismaService) {} async user( @@ -361,7 +361,7 @@ import { PrismaService } from './prisma.service'; import { Post, Prisma } from '@prisma/client'; @Injectable() -export class PostService { +export class PostsService { constructor(private prisma: PrismaService) {} async post( @@ -414,7 +414,7 @@ export class PostService { } ``` -Your `UserService` and `PostService` currently wrap the CRUD queries that are available in Prisma Client. In a real world application, the service would also be the place to add business logic to your application. For example, you could have a method called `updatePassword` inside the `UserService` that would be responsible for updating the password of a user. +Your `UsersService` and `PostsService` currently wrap the CRUD queries that are available in Prisma Client. In a real world application, the service would also be the place to add business logic to your application. For example, you could have a method called `updatePassword` inside the `UsersService` that would be responsible for updating the password of a user. Remember to register the new services in the app module. @@ -434,15 +434,15 @@ import { Put, Delete, } from '@nestjs/common'; -import { UserService } from './user.service'; -import { PostService } from './post.service'; +import { UsersService } from './users.service'; +import { PostsService } from './posts.service'; import { User as UserModel, Post as PostModel } from '@prisma/client'; @Controller() export class AppController { constructor( - private readonly userService: UserService, - private readonly postService: PostService, + private readonly userService: UsersService, + private readonly postService: PostsService, ) {} @Get('post/:id') diff --git a/content/recipes/swc.md b/content/recipes/swc.md index f37bc77e24..8fe8c3e9d4 100644 --- a/content/recipes/swc.md +++ b/content/recipes/swc.md @@ -198,7 +198,7 @@ For all [circular dependency injections](/fundamentals/circular-dependency) in y ```typescript @Injectable() -export class UserService { +export class UsersService { constructor( @Inject(forwardRef(() => ProfileService)) private readonly profileService: WrapperType,