import { Get , Post , Put , Delete , Body , Param } from '@nestjs/common' ; import { InMemoryDBService } from '../services' ; import { InMemoryDBEntity } from '../interfaces' ; example Controller export abstract class InMemoryDBEntityController < T extends InMemoryDBEntity > { constructor ( protected readonly dbService ) { } @ Post ( ) public create ( @ Body ( ) record ) { if ( Array . isArray ( record ) ) { return this . dbService . createMany ( record ) ; } return this . dbService . create ( record ) ; } @ Put ( ':id' ) public update ( @ Param ( 'id' ) id , @ Body ( ) record ) { return this . dbService . update ( { id , ... record } as T ) ; } @ Put ( ) public updateMany ( @ Body ( ) records ) { return this . dbService . updateMany ( records ) ; } @ Delete ( ':id' ) public delete ( @ Param ( 'id' ) id ) { return this . dbService . delete ( id ) ; } @ Delete ( ) public deleteMany ( @ Body ( ) ids ) { return this . dbService . deleteMany ( ids ) ; } @ Get ( ':id' ) public get ( @ Param ( 'id' ) id ) { return this . dbService . get ( id ) ; } @ Get ( ) public getMany ( @ Body ( ) ids ? ) { if ( ids && Array . isArray ( ids ) ) { return this . dbService . getMany ( ids ) ; } return this . dbService . getAll ( ) ; } }