Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c838bb9

Browse files
Merge pull request #3222 from KhoDis/fix/service-naming-consistency
docs: use plural names instead of singular
2 parents 78cba69 + 37b1145 commit c838bb9

File tree

5 files changed

+50
-50
lines changed

5 files changed

+50
-50
lines changed

‎content/openapi/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export interface SwaggerDocumentOptions {
148148
}
149149
```
150150
151-
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:
151+
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:
152152
153153
```TypeScript
154154
const options: SwaggerDocumentOptions = {

‎content/recipes/async-local-storage.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export class AlsModule {}
3636
```ts
3737
@@filename(app.module)
3838
@Module({
39-
imports: [AlsModule]
40-
providers: [CatService],
41-
controllers: [CatController],
39+
imports: [AlsModule],
40+
providers: [CatsService],
41+
controllers: [CatsController],
4242
})
4343
export class AppModule implements NestModule {
4444
constructor(
@@ -64,9 +64,9 @@ export class AppModule implements NestModule {
6464
}
6565
@@switch
6666
@Module({
67-
imports: [AlsModule]
68-
providers: [CatService],
69-
controllers: [CatController],
67+
imports: [AlsModule],
68+
providers: [CatsService],
69+
controllers: [CatsController],
7070
})
7171
@Dependencies(AsyncLocalStorage)
7272
export class AppModule {
@@ -96,37 +96,37 @@ export class AppModule {
9696
3. Now, anywhere within the lifecycle of a request, we can access the local store instance.
9797

9898
```ts
99-
@@filename(cat.service)
99+
@@filename(cats.service)
100100
@Injectable()
101-
export class CatService {
101+
export class CatsService {
102102
constructor(
103103
// We can inject the provided ALS instance.
104104
private readonly als: AsyncLocalStorage,
105-
private readonly catRepository:CatRepository,
105+
private readonly catsRepository:CatsRepository,
106106
) {}
107107

108108
getCatForUser() {
109109
// The "getStore" method will always return the
110110
// store instance associated with the given request.
111111
const userId = this.als.getStore()["userId"] as number;
112-
return this.catRepository.getForUser(userId);
112+
return this.catsRepository.getForUser(userId);
113113
}
114114
}
115115
@@switch
116116
@Injectable()
117-
@Dependencies(AsyncLocalStorage, CatRepository)
118-
export class CatService {
119-
constructor(als, catRepository) {
117+
@Dependencies(AsyncLocalStorage, CatsRepository)
118+
export class CatsService {
119+
constructor(als, catsRepository) {
120120
// We can inject the provided ALS instance.
121121
this.als = als
122-
this.catRepository = catRepository
122+
this.catsRepository = catsRepository
123123
}
124124

125125
getCatForUser() {
126126
// The "getStore" method will always return the
127127
// store instance associated with the given request.
128128
const userId = this.als.getStore()["userId"] as number;
129-
return this.catRepository.getForUser(userId);
129+
return this.catsRepository.getForUser(userId);
130130
}
131131
}
132132
```
@@ -175,44 +175,44 @@ A similar functionality as described [above](recipes/async-local-storage#custom-
175175
},
176176
}),
177177
],
178-
providers: [CatService],
179-
controllers: [CatController],
178+
providers: [CatsService],
179+
controllers: [CatsController],
180180
})
181181
export class AppModule {}
182182
```
183183

184184
2. And then can use the `ClsService` to access the store values.
185185

186186
```ts
187-
@@filename(cat.service)
187+
@@filename(cats.service)
188188
@Injectable()
189-
export class CatService {
189+
export class CatsService {
190190
constructor(
191191
// We can inject the provided ClsService instance,
192192
private readonly cls: ClsService,
193-
private readonly catRepository:CatRepository,
193+
private readonly catsRepository:CatsRepository,
194194
) {}
195195

196196
getCatForUser() {
197197
// and use the "get" method to retrieve any stored value.
198198
const userId = this.cls.get('userId');
199-
return this.catRepository.getForUser(userId);
199+
return this.catsRepository.getForUser(userId);
200200
}
201201
}
202202
@@switch
203203
@Injectable()
204-
@Dependencies(AsyncLocalStorage, CatRepository)
205-
export class CatService {
206-
constructor(cls, catRepository) {
204+
@Dependencies(AsyncLocalStorage, CatsRepository)
205+
export class CatsService {
206+
constructor(cls, catsRepository) {
207207
// We can inject the provided ClsService instance,
208208
this.cls = cls
209-
this.catRepository = catRepository
209+
this.catsRepository = catsRepository
210210
}
211211

212212
getCatForUser() {
213213
// and use the "get" method to retrieve any stored value.
214214
const userId = this.cls.get('userId');
215-
return this.catRepository.getForUser(userId);
215+
return this.catsRepository.getForUser(userId);
216216
}
217217
}
218218
```
@@ -233,19 +233,19 @@ Since the `ClsService` is just another injectable provider, it can be entirely m
233233
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`.
234234

235235
```ts
236-
describe('CatService', () => {
237-
let service: CatService
236+
describe('CatsService', () => {
237+
let service: CatsService
238238
let cls: ClsService
239-
const mockCatRepository = createMock<CatRepository>()
239+
const mockCatsRepository = createMock<CatsRepository>()
240240

241241
beforeEach(async () => {
242242
const module = await Test.createTestingModule({
243243
// Set up most of the testing module as we normally would.
244244
providers: [
245-
CatService,
245+
CatsService,
246246
{
247-
provide: CatRepository
248-
useValue: mockCatRepository
247+
provide: CatsRepository
248+
useValue: mockCatsRepository
249249
}
250250
],
251251
imports: [
@@ -255,7 +255,7 @@ describe('CatService', () => {
255255
],
256256
}).compile()
257257

258-
service = module.get(CatService)
258+
service = module.get(CatsService)
259259

260260
// Also retrieve the ClsService for later use.
261261
cls = module.get(ClsService)
@@ -264,7 +264,7 @@ describe('CatService', () => {
264264
describe('getCatForUser', () => {
265265
it('retrieves cat based on user id', async () => {
266266
const expectedUserId = 42
267-
mockCatRepository.getForUser.mockImplementationOnce(
267+
mocksCatsRepository.getForUser.mockImplementationOnce(
268268
(id) => ({ userId: id })
269269
)
270270

‎content/recipes/cqrs.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Let's create a handler for the `KillDragonCommand` command.
112112
@@filename(kill-dragon.handler)
113113
@CommandHandler(KillDragonCommand)
114114
export class KillDragonHandler implements ICommandHandler<KillDragonCommand> {
115-
constructor(private repository: HeroRepository) {}
115+
constructor(private repository: HeroesRepository) {}
116116

117117
async execute(command: KillDragonCommand) {
118118
const { heroId, dragonId } = command;
@@ -129,7 +129,7 @@ export class KillDragonHandler implements ICommandHandler<KillDragonCommand> {
129129
}
130130
@@switch
131131
@CommandHandler(KillDragonCommand)
132-
@Dependencies(HeroRepository)
132+
@Dependencies(HeroesRepository)
133133
export class KillDragonHandler {
134134
constructor(repository) {
135135
this.repository = repository;
@@ -180,15 +180,15 @@ To retrieve the hero, we need to create a query handler:
180180
@@filename(get-hero.handler)
181181
@QueryHandler(GetHeroQuery)
182182
export class GetHeroHandler implements IQueryHandler<GetHeroQuery> {
183-
constructor(private repository: HeroRepository) {}
183+
constructor(private repository: HeroesRepository) {}
184184

185185
async execute(query: GetHeroQuery) {
186186
return this.repository.findOneById(query.hero);
187187
}
188188
}
189189
@@switch
190190
@QueryHandler(GetHeroQuery)
191-
@Dependencies(HeroRepository)
191+
@Dependencies(HeroesRepository)
192192
export class GetHeroHandler {
193193
constructor(repository) {
194194
this.repository = repository;
@@ -272,7 +272,7 @@ The `apply()` method is used to dispatch events. It accepts an event object as a
272272
@CommandHandler(KillDragonCommand)
273273
export class KillDragonHandler implements ICommandHandler<KillDragonCommand> {
274274
constructor(
275-
private repository: HeroRepository,
275+
private repository: HeroesRepository,
276276
private publisher: EventPublisher,
277277
) {}
278278

@@ -287,7 +287,7 @@ export class KillDragonHandler implements ICommandHandler<KillDragonCommand> {
287287
}
288288
@@switch
289289
@CommandHandler(KillDragonCommand)
290-
@Dependencies(HeroRepository, EventPublisher)
290+
@Dependencies(HeroesRepository, EventPublisher)
291291
export class KillDragonHandler {
292292
constructor(repository, publisher) {
293293
this.repository = repository;
@@ -341,7 +341,7 @@ Each event can have multiple **Event Handlers**.
341341
@@filename(hero-killed-dragon.handler)
342342
@EventsHandler(HeroKilledDragonEvent)
343343
export class HeroKilledDragonHandler implements IEventHandler<HeroKilledDragonEvent> {
344-
constructor(private repository: HeroRepository) {}
344+
constructor(private repository: HeroesRepository) {}
345345

346346
handle(event: HeroKilledDragonEvent) {
347347
// Business logic

‎content/recipes/prisma.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ import { PrismaService } from './prisma.service';
296296
import { User, Prisma } from '@prisma/client';
297297

298298
@Injectable()
299-
export class UserService {
299+
export class UsersService {
300300
constructor(private prisma: PrismaService) {}
301301

302302
async user(
@@ -361,7 +361,7 @@ import { PrismaService } from './prisma.service';
361361
import { Post, Prisma } from '@prisma/client';
362362

363363
@Injectable()
364-
export class PostService {
364+
export class PostsService {
365365
constructor(private prisma: PrismaService) {}
366366

367367
async post(
@@ -414,7 +414,7 @@ export class PostService {
414414
}
415415
```
416416

417-
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.
417+
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.
418418

419419
Remember to register the new services in the app module.
420420

@@ -434,15 +434,15 @@ import {
434434
Put,
435435
Delete,
436436
} from '@nestjs/common';
437-
import { UserService } from './user.service';
438-
import { PostService } from './post.service';
437+
import { UsersService } from './users.service';
438+
import { PostsService } from './posts.service';
439439
import { User as UserModel, Post as PostModel } from '@prisma/client';
440440

441441
@Controller()
442442
export class AppController {
443443
constructor(
444-
private readonly userService: UserService,
445-
private readonly postService: PostService,
444+
private readonly userService: UsersService,
445+
private readonly postService: PostsService,
446446
) {}
447447

448448
@Get('post/:id')

‎content/recipes/swc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ For all [circular dependency injections](/fundamentals/circular-dependency) in y
198198

199199
```typescript
200200
@Injectable()
201-
export class UserService {
201+
export class UsersService {
202202
constructor(
203203
@Inject(forwardRef(() => ProfileService))
204204
private readonly profileService: WrapperType<ProfileService>,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /