1- import { Body , Controller , Delete , Get , HttpStatus , Param , Patch , Post , Req , Res } from '@nestjs/common'
2- import { CrontabsCreateDto , CrontabsUpdateDto } from './_dto/crontabs.dto'
1+ import { Body , Controller , Delete , Get , HttpStatus , Param , Patch , Post , Res } from '@nestjs/common'
2+ import { CrontabsCreateDto , CrontabsDto , CrontabsUpdateDto } from './_dto/crontabs.dto'
33import { CrontabsService } from './crontabs.service'
44import { AbstractController } from '~/_common/abstracts/abstract.controller'
55import { ApiParam } from '@nestjs/swagger'
6- import { SearchFilterSchema , FilterSchema , SearchFilterOptions , FilterOptions , ObjectIdValidationPipe } from '@streamkits/nestjs_module_scrud'
6+ import {
7+ FilterOptions ,
8+ FilterSchema ,
9+ ObjectIdValidationPipe ,
10+ SearchFilterOptions ,
11+ SearchFilterSchema ,
12+ } from '@streamkits/nestjs_module_scrud'
713import { Types } from 'mongoose'
8- import { Request , Response } from 'express'
14+ import { Response } from 'express'
15+ import { PartialProjectionType } from '~/_common/types/partial-projection.type'
16+ import { ApiCreateDecorator } from '~/_common/decorators/api-create.decorator'
17+ import { ApiPaginatedDecorator } from '~/_common/decorators/api-paginated.decorator'
18+ import { PickProjectionHelper } from '~/_common/helpers/pick-projection.helper'
19+ import { ApiReadResponseDecorator } from '~/_common/decorators/api-read-response.decorator'
20+ import { ApiUpdateDecorator } from '~/_common/decorators/api-update.decorator'
21+ import { ApiDeletedResponseDecorator } from '~/_common/decorators/api-deleted-response.decorator'
922
1023@Controller ( 'crontabs' )
1124export class CrontabsController extends AbstractController {
12- protected readonly projection = {
25+ protected static readonly projection : PartialProjectionType < CrontabsDto > = {
1326 name : 1 ,
14- description : 1 ,
27+ interval : 1 ,
1528 }
1629
17- constructor ( private readonly _service : CrontabsService ) {
30+ public constructor ( private readonly _service : CrontabsService ) {
1831 super ( )
1932 }
2033
2134 @Post ( )
22- public async create ( @Req ( ) req : Request , @Res ( ) res : Response , @Body ( ) body : CrontabsCreateDto ) {
35+ @ApiCreateDecorator ( CrontabsCreateDto , CrontabsDto )
36+ public async create ( @Res ( ) res : Response , @Body ( ) body : CrontabsCreateDto ) : Promise < Response > {
2337 const data = await this . _service . create ( body )
2438 return res . status ( HttpStatus . CREATED ) . json ( {
2539 statusCode : HttpStatus . CREATED ,
@@ -28,8 +42,9 @@ export class CrontabsController extends AbstractController {
2842 }
2943
3044 @Get ( )
31- public async search ( @Res ( ) res : Response , @SearchFilterSchema ( ) searchFilterSchema : FilterSchema , @SearchFilterOptions ( ) searchFilterOptions : FilterOptions ) {
32- const [ data , total ] = await this . _service . findAndCount ( searchFilterSchema , this . projection , searchFilterOptions )
45+ @ApiPaginatedDecorator ( PickProjectionHelper ( CrontabsDto , CrontabsController . projection ) )
46+ public async search ( @Res ( ) res : Response , @SearchFilterSchema ( ) searchFilterSchema : FilterSchema , @SearchFilterOptions ( ) searchFilterOptions : FilterOptions ) : Promise < Response > {
47+ const [ data , total ] = await this . _service . findAndCount ( searchFilterSchema , CrontabsController . projection , searchFilterOptions )
3348 return res . status ( HttpStatus . OK ) . json ( {
3449 statusCode : HttpStatus . OK ,
3550 total,
@@ -39,7 +54,8 @@ export class CrontabsController extends AbstractController {
3954
4055 @Get ( ':_id([0-9a-fA-F]{24})' )
4156 @ApiParam ( { name : '_id' , type : String } )
42- public async read ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) {
57+ @ApiReadResponseDecorator ( CrontabsDto )
58+ public async read ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) : Promise < Response > {
4359 const data = await this . _service . findById ( _id )
4460 return res . status ( HttpStatus . OK ) . json ( {
4561 statusCode : HttpStatus . OK ,
@@ -49,7 +65,8 @@ export class CrontabsController extends AbstractController {
4965
5066 @Patch ( ':_id([0-9a-fA-F]{24})' )
5167 @ApiParam ( { name : '_id' , type : String } )
52- public async update ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Body ( ) body : CrontabsUpdateDto , @Res ( ) res : Response ) {
68+ @ApiUpdateDecorator ( CrontabsUpdateDto , CrontabsDto )
69+ public async update ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Body ( ) body : CrontabsUpdateDto , @Res ( ) res : Response ) : Promise < Response > {
5370 const data = await this . _service . update ( _id , body )
5471 return res . status ( HttpStatus . OK ) . json ( {
5572 statusCode : HttpStatus . OK ,
@@ -59,7 +76,8 @@ export class CrontabsController extends AbstractController {
5976
6077 @Delete ( ':_id([0-9a-fA-F]{24})' )
6178 @ApiParam ( { name : '_id' , type : String } )
62- public async remove ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) {
79+ @ApiDeletedResponseDecorator ( CrontabsDto )
80+ public async remove ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) : Promise < Response > {
6381 const data = await this . _service . delete ( _id )
6482 return res . status ( HttpStatus . OK ) . json ( {
6583 statusCode : HttpStatus . OK ,
0 commit comments