Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
@ApiForbiddenResponse({ description: 'Forbidden.' })
export abstract class CrudController {
constructor(private readonly crudService: CrudRepositoryService) { }
@ApiOperation({ title: 'find all' })
@ApiOkResponse({ description: 'Found records' })
@Get()
public async findAll(@Query() filter: PaginationParams>): Promise>> {
return this.crudService.paginator(filter);
}
@ApiOperation({ title: 'Find by id' })
@ApiOkResponse({ description: 'Found one record' })
@ApiNotFoundResponse({ description: 'Record not found' })
@Get(':id')
public async findById(@Param('id') id: string): Promise> {
return this.crudService.findOne(id);
}
@ApiOperation({ title: 'Create new record' })
@ApiCreatedResponse({ description: 'The record has been successfully created.' })
@ApiBadRequestResponse({ description: 'Invalid input, The response body may contain clues as to what went wrong' })
@HttpCode(HttpStatus.CREATED)
@Post()
public async create(@Body() entity: Partial): Promise> {
return this.crudService.create(entity);
}
@ApiOperation({ title: 'Update an existing record' })
@ApiCreatedResponse({ description: 'The record has been successfully edited.' })
public async findById(@Param('id') id: string): Promise> {
return this.crudService.findOne(id);
}
@ApiOperation({ title: 'Create new record' })
@ApiCreatedResponse({ description: 'The record has been successfully created.' })
@ApiBadRequestResponse({ description: 'Invalid input, The response body may contain clues as to what went wrong' })
@HttpCode(HttpStatus.CREATED)
@Post()
public async create(@Body() entity: Partial): Promise> {
return this.crudService.create(entity);
}
@ApiOperation({ title: 'Update an existing record' })
@ApiCreatedResponse({ description: 'The record has been successfully edited.' })
@ApiNotFoundResponse({ description: 'Record not found' })
@ApiBadRequestResponse({ description: 'Invalid input, The response body may contain clues as to what went wrong' })
@HttpCode(HttpStatus.CREATED)
@Put(':id')
public async update(@Param('id') id: string, @Body() entity: Partial>): Promise> {
return this.crudService.update(id, entity);
}
@ApiOperation({ title: 'Delete record' })
@ApiResponse({ status: HttpStatus.NO_CONTENT, description: 'The record has been successfully deleted' })
@ApiNotFoundResponse({ description: 'Record not found' })
@HttpCode(HttpStatus.NO_CONTENT)
@Delete(':id')
public async delete(@Param('id') id: string): Promise>> {
return this.crudService.delete(id);
}
}
return this.crudService.create(entity);
}
@ApiOperation({ title: 'Update an existing record' })
@ApiCreatedResponse({ description: 'The record has been successfully edited.' })
@ApiNotFoundResponse({ description: 'Record not found' })
@ApiBadRequestResponse({ description: 'Invalid input, The response body may contain clues as to what went wrong' })
@HttpCode(HttpStatus.CREATED)
@Put(':id')
public async update(@Param('id') id: string, @Body() entity: Partial>): Promise> {
return this.crudService.update(id, entity);
}
@ApiOperation({ title: 'Delete record' })
@ApiResponse({ status: HttpStatus.NO_CONTENT, description: 'The record has been successfully deleted' })
@ApiNotFoundResponse({ description: 'Record not found' })
@HttpCode(HttpStatus.NO_CONTENT)
@Delete(':id')
public async delete(@Param('id') id: string): Promise>> {
return this.crudService.delete(id);
}
}