Skip to content

Commit 18c6d32

Browse files
feat: change stub of controller and service
1 parent 9f02ae9 commit 18c6d32

File tree

6 files changed

+35
-26
lines changed

6 files changed

+35
-26
lines changed

libs/commands/base-make.command.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mkdirSync, readFileSync, writeFileSync } from 'fs';
2-
import { camelCase, escapeRegExp, kebabCase, upperFirst } from 'lodash';
2+
import { camelCase, escapeRegExp, kebabCase, startCase, upperFirst } from 'lodash';
33
import path from 'path';
44
import { BaseCommand } from './base.command';
55

@@ -52,15 +52,19 @@ export abstract class BaseMakeCommand extends BaseCommand {
5252
return this.handle();
5353
}
5454

55-
public getClassName(name) {
55+
public getClassName(name: string): string {
5656
return upperFirst(camelCase(name));
5757
}
5858

59-
public getPropertyName(name) {
59+
public getPropertyName(name: string): string {
6060
return camelCase(name);
6161
}
6262

63-
public getFileName(name) {
63+
public getFileName(name: string): string {
6464
return kebabCase(name);
6565
}
66+
67+
public getTitleName(name: string): string {
68+
return startCase(camelCase(name));
69+
}
6670
}

libs/commands/make-controller.command.ts

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export class MakeControllerCommand extends BaseMakeCommand {
3434
{
3535
search: '$$FILENAME$$',
3636
value: this.getFileName(name)
37+
},
38+
{
39+
search: '$$TITLE$$',
40+
value: this.getTitleName(name)
3741
}
3842
]);
3943
this.writeFileToModule('http/controllers', `${name}.controller.ts`);

libs/stubs/modules/http/controllers/controller.stub

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,39 @@ import { $$CLASS$$Service } from '../../services/$$FILENAME$$.service';
66
import { Create$$CLASS$$Dto } from '../dto/create-$$FILENAME$$.dto';
77

88
@Controller('$$CONTROLLER_NAME$$')
9-
@ApiTags('$$CLASS$$')
9+
@ApiTags('$$TITLE$$')
1010
export class $$CLASS$$Controller extends BaseController {
1111
constructor(private $$PROPERTY$$Service: $$CLASS$$Service) {
1212
super();
1313
}
1414

1515
@Get()
1616
@ApiOperation({
17-
description: 'Get list $$PROPERTY$$'
17+
description: 'Get list $$TITLE$$'
1818
})
19-
async index(@Pagination() page: PaginationParams) {
19+
async index(@Pagination() page: PaginationParams): Promise<PaginationCollection<$$CLASS$$Entity>> {
2020
return this.$$PROPERTY$$Service.list(page);
2121
}
2222

2323
@Get(':id')
2424
@ApiParam({
2525
name: 'id',
26-
description: '$$CLASS$$ id',
26+
description: '$$TITLE$$ id',
2727
type: 'string'
2828
})
2929
@ApiOperation({
30-
description: 'Get detail of $$PROPERTY$$'
30+
description: 'Get detail of $$TITLE$$'
3131
})
32-
async show(@Id() id: string) {
32+
async show(@Id() id: string): Promise<$$CLASS$$Entity> {
3333
return this.$$PROPERTY$$Service.findById(id);
3434
}
3535

3636
@Post()
3737
@ApiOperation({
38-
description: 'Create an $$PROPERTY$$'
38+
description: 'Create a $$TITLE$$'
3939
})
4040
@HttpCode(HttpStatus.CREATED)
41-
async create(@Body() dto: Create$$CLASS$$Dto) {
41+
async create(@Body() dto: Create$$CLASS$$Dto): Promise<$$CLASS$$Entity> {
4242
return this.$$PROPERTY$$Service.create(dto);
4343
}
4444

@@ -49,11 +49,11 @@ export class $$CLASS$$Controller extends BaseController {
4949
type: 'string'
5050
})
5151
@ApiOperation({
52-
description: 'Update an $$PROPERTY$$'
52+
description: 'Update a $$TITLE$$'
5353
})
5454
@HttpCode(HttpStatus.NO_CONTENT)
55-
async update(@Body() dto: Create$$CLASS$$Dto, @Id() id: string) {
56-
return this.$$PROPERTY$$Service.update(id, dto);
55+
async update(@Body() dto: Create$$CLASS$$Dto, @Id() id: string): Promise<void> {
56+
await this.$$PROPERTY$$Service.update(id, dto);
5757
}
5858

5959
@Delete(':id')
@@ -63,10 +63,10 @@ export class $$CLASS$$Controller extends BaseController {
6363
type: 'string'
6464
})
6565
@ApiOperation({
66-
description: 'Destroy an $$PROPERTY$$'
66+
description: 'Destroy a $$TITLE$$'
6767
})
6868
@HttpCode(HttpStatus.NO_CONTENT)
69-
async destroy(@Id() id: string) {
70-
return this.$$PROPERTY$$Service.destroy(id);
69+
async destroy(@Id() id: string): Promise<void> {
70+
await this.$$PROPERTY$$Service.destroy(id);
7171
}
7272
}
+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Injectable } from '@nestjs/common';
2-
import { InjectRepository } from '@nestjs/typeorm';
32
import { $$CLASS$$Repository } from '../repositories/$$FILENAME$$.repository';
3+
import { $$CLASS$$Entity } from '../entities/$$FILENAME$$.entity';
4+
import { PaginationCollection } from '@hodfords/typeorm-helper';
45

56
@Injectable()
67
export class $$CLASS$$Service {
@@ -10,19 +11,19 @@ export class $$CLASS$$Service {
1011
return this.$$PROPERTY$$Repo.findById(id);
1112
}
1213

13-
async list(page): Promise<$$CLASS$$Entity[]> {
14+
async list(page: PaginationParams): Promise<PaginationCollection<$$CLASS$$Entity>> {
1415
return this.$$PROPERTY$$Repo.pagination({}, page);
1516
}
1617

17-
async create(data): Promise<$$CLASS$$Entity> {
18+
async create(data: Create$$CLASS$$Dto): Promise<$$CLASS$$Entity> {
1819
return this.$$PROPERTY$$Repo.createOne(data);
1920
}
2021

21-
async update(id, data): Promise<void> {
22+
async update(id: string, data: Create$$CLASS$$Dto): Promise<void> {
2223
await this.$$PROPERTY$$Repo.update(id, data);
2324
}
2425

25-
async destroy(id): Promise<void> {
26+
async destroy(id: string): Promise<void> {
2627
await this.$$PROPERTY$$Repo.delete(id);
2728
}
2829
}

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hodfords/nestjs-command",
3-
"version": "10.0.1",
3+
"version": "10.0.2",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)