You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.5 KiB
89 lines
2.5 KiB
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
NotFoundException,
|
|
Param,
|
|
ParseIntPipe,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { {{ properCase name }} } from './{{ kebabCase name }}.entity';
|
|
import { {{ properCase name }}Service } from './{{ kebabCase name }}.service';
|
|
import {
|
|
ApiBearerAuth,
|
|
ApiImplicitParam,
|
|
ApiResponse,
|
|
ApiUseTags,
|
|
} from '@nestjs/swagger';
|
|
import { {{ properCase name }}Dto } from './{{ kebabCase name }}.dto';
|
|
|
|
|
|
@ApiUseTags('{{ sentenceCase name }}')
|
|
@Controller()
|
|
// @ApiBearerAuth()
|
|
export class {{ properCase name }}Controller {
|
|
constructor(private readonly {{ camelCase name }}Service: {{ properCase name }}Service) {}
|
|
|
|
@Get()
|
|
@ApiResponse({
|
|
status: 200,
|
|
description: 'Get a list of all {{ sentenceCase name }}.',
|
|
type: {{ properCase name }},
|
|
isArray: true,
|
|
})
|
|
getAll(): Promise<{{ properCase name }}[]> {
|
|
return this.{{ camelCase name }}Service.getAll();
|
|
}
|
|
|
|
@Post()
|
|
@ApiResponse({
|
|
status: 201,
|
|
description: 'The {{ sentenceCase name }} has been created.',
|
|
type: {{ properCase name }},
|
|
})
|
|
saveNew(@Body() {{ camelCase name }}Dto: {{ properCase name }}Dto): Promise<{{ properCase name }}> {
|
|
return this.{{ camelCase name }}Service.saveNew({{ camelCase name }}Dto);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiResponse({
|
|
status: 200,
|
|
description: 'The {{ sentenceCase name }} with the matching id',
|
|
type: {{ properCase name }},
|
|
})
|
|
@ApiResponse({ status: 404, description: 'Not found.' })
|
|
async findOne(
|
|
@Param('id', new ParseIntPipe()) id: number,
|
|
): Promise<{{ properCase name }}> {
|
|
return (await this.{{ camelCase name }}Service.getOneById(id)).orElseThrow(
|
|
() => new NotFoundException(),
|
|
);
|
|
}
|
|
|
|
@Put(':id')
|
|
@ApiResponse({
|
|
status: 200,
|
|
description: 'The updated {{ sentenceCase name }} with the matching id',
|
|
type: {{ properCase name }},
|
|
})
|
|
@ApiResponse({ status: 404, description: 'Not found.' })
|
|
async updateOne(
|
|
@Param('id', new ParseIntPipe()) id: number,
|
|
@Body() {{ camelCase name }}Dto: {{ properCase name }}Dto,
|
|
): Promise<{{ properCase name }}> {
|
|
return this.{{ camelCase name }}Service.update(id, {{ camelCase name }}Dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiResponse({
|
|
status: 200,
|
|
description: 'The {{ sentenceCase name }} with the matching id was deleted',
|
|
})
|
|
@ApiResponse({ status: 404, description: 'Not found.' })
|
|
async deleteOne(@Param('id', new ParseIntPipe()) id: number): Promise<void> {
|
|
await this.{{ camelCase name }}Service.deleteById(id);
|
|
}
|
|
}
|