1- import { Body , Controller , Delete , Get , HttpStatus , Param , Patch , Post , Req , Res } from '@nestjs/common'
2- import { TriggersCreateDto , TriggersUpdateDto } from './_dto/triggers.dto'
3- import { TriggersService } from './triggers.service'
4- import { AbstractController } from '~/_common/abstracts/abstract.controller'
5- import { ApiParam , ApiTags } from '@nestjs/swagger'
6- import { SearchFilterSchema , FilterSchema , SearchFilterOptions , FilterOptions , ObjectIdValidationPipe } from '@streamkits/nestjs_module_scrud'
1+ import { Controller , Post , Res , Body , HttpStatus , Get , Param , Patch , Delete } from '@nestjs/common'
2+ import { ApiTags , ApiParam } from '@nestjs/swagger'
3+ import { AbstractController , SearchFilterSchema , FilterSchema , SearchFilterOptions , FilterOptions , ObjectIdValidationPipe } from '@streamkits/nestjs_module_scrud'
74import { Types } from 'mongoose'
8- import { Request , Response } from 'express'
5+ import { ApiCreateDecorator } from '~/_common/decorators/api-create.decorator'
6+ import { ApiDeletedResponseDecorator } from '~/_common/decorators/api-deleted-response.decorator'
7+ import { ApiPaginatedDecorator } from '~/_common/decorators/api-paginated.decorator'
8+ import { ApiReadResponseDecorator } from '~/_common/decorators/api-read-response.decorator'
9+ import { ApiUpdateDecorator } from '~/_common/decorators/api-update.decorator'
10+ import { PickProjectionHelper } from '~/_common/helpers/pick-projection.helper'
11+ import { PartialProjectionType } from '~/_common/types/partial-projection.type'
12+ import { TriggersDto , TriggersCreateDto , TriggersUpdateDto } from './_dto/triggers.dto'
13+ import { TriggersService } from './triggers.service'
14+ import { Response } from 'express'
915
1016@ApiTags ( 'core' )
1117@Controller ( 'triggers' )
1218export class TriggersController extends AbstractController {
13- protected readonly projection = {
19+ protected static readonly projection : PartialProjectionType < TriggersDto > = {
1420 name : 1 ,
1521 description : 1 ,
1622 }
@@ -20,7 +26,8 @@ export class TriggersController extends AbstractController {
2026 }
2127
2228 @Post ( )
23- public async create ( @Req ( ) req : Request , @Res ( ) res : Response , @Body ( ) body : TriggersCreateDto ) {
29+ @ApiCreateDecorator ( TriggersCreateDto , TriggersDto )
30+ public async create ( @Res ( ) res : Response , @Body ( ) body : TriggersCreateDto ) : Promise < Response > {
2431 const data = await this . _service . create ( body )
2532 return res . status ( HttpStatus . CREATED ) . json ( {
2633 statusCode : HttpStatus . CREATED ,
@@ -29,8 +36,9 @@ export class TriggersController extends AbstractController {
2936 }
3037
3138 @Get ( )
32- public async search ( @Res ( ) res : Response , @SearchFilterSchema ( ) searchFilterSchema : FilterSchema , @SearchFilterOptions ( ) searchFilterOptions : FilterOptions ) {
33- const [ data , total ] = await this . _service . findAndCount ( searchFilterSchema , this . projection , searchFilterOptions )
39+ @ApiPaginatedDecorator ( PickProjectionHelper ( TriggersDto , TriggersController . projection ) )
40+ public async search ( @Res ( ) res : Response , @SearchFilterSchema ( ) searchFilterSchema : FilterSchema , @SearchFilterOptions ( ) searchFilterOptions : FilterOptions ) : Promise < Response > {
41+ const [ data , total ] = await this . _service . findAndCount ( searchFilterSchema , TriggersController . projection , searchFilterOptions )
3442 return res . status ( HttpStatus . OK ) . json ( {
3543 statusCode : HttpStatus . OK ,
3644 total,
@@ -40,7 +48,8 @@ export class TriggersController extends AbstractController {
4048
4149 @Get ( ':_id([0-9a-fA-F]{24})' )
4250 @ApiParam ( { name : '_id' , type : String } )
43- public async read ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) {
51+ @ApiReadResponseDecorator ( TriggersDto )
52+ public async read ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) : Promise < Response > {
4453 const data = await this . _service . findById ( _id )
4554 return res . status ( HttpStatus . OK ) . json ( {
4655 statusCode : HttpStatus . OK ,
@@ -50,7 +59,8 @@ export class TriggersController extends AbstractController {
5059
5160 @Patch ( ':_id([0-9a-fA-F]{24})' )
5261 @ApiParam ( { name : '_id' , type : String } )
53- public async update ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Body ( ) body : TriggersUpdateDto , @Res ( ) res : Response ) {
62+ @ApiUpdateDecorator ( TriggersUpdateDto , TriggersDto )
63+ public async update ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Body ( ) body : TriggersUpdateDto , @Res ( ) res : Response ) : Promise < Response > {
5464 const data = await this . _service . update ( _id , body )
5565 return res . status ( HttpStatus . OK ) . json ( {
5666 statusCode : HttpStatus . OK ,
@@ -60,7 +70,8 @@ export class TriggersController extends AbstractController {
6070
6171 @Delete ( ':_id([0-9a-fA-F]{24})' )
6272 @ApiParam ( { name : '_id' , type : String } )
63- public async remove ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) {
73+ @ApiDeletedResponseDecorator ( TriggersDto )
74+ public async remove ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) : Promise < Response > {
6475 const data = await this . _service . delete ( _id )
6576 return res . status ( HttpStatus . OK ) . json ( {
6677 statusCode : HttpStatus . OK ,
0 commit comments