import { Body , Delete , Get , HttpCode , HttpStatus , Param , Post , Put } from '@nestjs/common' ; import { ApiOperation } from '@nestjs/swagger' ; import { DeepPartial } from 'typeorm' ; import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity' ; import { Base } from '../entities/base' ; import { ICrudService } from './icrud.service' ; import { IPagination } from './pagination' ; import { PaginationParams } from './pagination-params' ; export abstract class CrudController < T extends Base > { protected constructor ( private readonly crudService ) { } @ ApiOperation ( { summary : 'find all' } ) @ Get ( ) async findAll ( filter ? ) { return this . crudService . findAll ( filter ) ; } @ ApiOperation ( { summary : 'Find by id' } ) @ Get ( ':id' ) async findById ( @ Param ( 'id' ) id ) { return this . crudService . findOne ( id ) ; } @ ApiOperation ( { summary : 'Create new record' } ) @ HttpCode ( HttpStatus . CREATED ) @ Post ( ) async create ( @ Body ( ) entity , ... options ) { return this . crudService . create ( entity ) ; } @ ApiOperation ( { summary : 'Update an existing record' } ) @ HttpCode ( HttpStatus . ACCEPTED ) @ Put ( ':id' ) async update ( @ Param ( 'id' ) id , @ Body ( ) entity , ... options ) { return this . crudService . update ( id , entity ) ; } @ ApiOperation ( { summary : 'Delete record' } ) @ HttpCode ( HttpStatus . ACCEPTED ) @ Delete ( ':id' ) async delete ( @ Param ( 'id' ) id , ... options ) { return this . crudService . delete ( id ) ; } }