1- import { Body , Controller , Delete , Get , HttpStatus , Param , Patch , Post , Req , Res } from '@nestjs/common'
1+ import { Body , Controller , Delete , Get , HttpStatus , Param , Patch , Post , Res } from '@nestjs/common'
22import { AbstractController } from '~/_common/abstracts/abstract.controller'
3- import { Request , Response } from 'express'
3+ import { Response } from 'express'
44import { FilterOptions , FilterSchema , SearchFilterOptions , SearchFilterSchema } from '@streamkits/nestjs_module_scrud'
55import { ApiParam , ApiTags } from '@nestjs/swagger'
66import { ObjectIdValidationPipe } from '~/_common/pipes/object-id-validation.pipe'
77import { Types } from 'mongoose'
8- import { SourceRequestCreateDto , SourceRequestUpdateDto } from '~/tickets/source-request/_dto/source-request.dto'
8+ import {
9+ SourceRequestCreateDto ,
10+ SourceRequestDto ,
11+ SourceRequestUpdateDto ,
12+ } from '~/tickets/source-request/_dto/source-request.dto'
913import { SourceRequestService } from '~/tickets/source-request/source-request.service'
14+ import { PartialProjectionType } from '~/_common/types/partial-projection.type'
15+ import { ApiCreateDecorator } from '~/_common/decorators/api-create.decorator'
16+ import { ApiPaginatedDecorator } from '~/_common/decorators/api-paginated.decorator'
17+ import { PickProjectionHelper } from '~/_common/helpers/pick-projection.helper'
18+ import { ApiReadResponseDecorator } from '~/_common/decorators/api-read-response.decorator'
19+ import { ApiUpdateDecorator } from '~/_common/decorators/api-update.decorator'
20+ import { ApiDeletedResponseDecorator } from '~/_common/decorators/api-deleted-response.decorator'
1021
1122@ApiTags ( 'tickets' )
1223@Controller ( 'source-request' )
1324export class SourceRequestController extends AbstractController {
14- protected readonly projection = {
25+ protected static readonly projection : PartialProjectionType < SourceRequestDto > = {
1526 name : 1 ,
1627 color : 1 ,
1728 icon : 1 ,
@@ -22,7 +33,8 @@ export class SourceRequestController extends AbstractController {
2233 }
2334
2435 @Post ( )
25- public async create ( @Req ( ) req : Request , @Res ( ) res : Response , @Body ( ) body : SourceRequestCreateDto ) {
36+ @ApiCreateDecorator ( SourceRequestCreateDto , SourceRequestDto )
37+ public async create ( @Res ( ) res : Response , @Body ( ) body : SourceRequestCreateDto ) : Promise < Response > {
2638 const data = await this . _service . create ( body )
2739 return res . status ( HttpStatus . CREATED ) . json ( {
2840 statusCode : HttpStatus . CREATED ,
@@ -31,8 +43,9 @@ export class SourceRequestController extends AbstractController {
3143 }
3244
3345 @Get ( )
34- public async search ( @Res ( ) res : Response , @SearchFilterSchema ( ) searchFilterSchema : FilterSchema , @SearchFilterOptions ( ) searchFilterOptions : FilterOptions ) {
35- const [ data , total ] = await this . _service . findAndCount ( searchFilterSchema , this . projection , searchFilterOptions )
46+ @ApiPaginatedDecorator ( PickProjectionHelper ( SourceRequestDto , SourceRequestController . projection ) )
47+ public async search ( @Res ( ) res : Response , @SearchFilterSchema ( ) searchFilterSchema : FilterSchema , @SearchFilterOptions ( ) searchFilterOptions : FilterOptions ) : Promise < Response > {
48+ const [ data , total ] = await this . _service . findAndCount ( searchFilterSchema , SourceRequestController . projection , searchFilterOptions )
3649 return res . status ( HttpStatus . OK ) . json ( {
3750 statusCode : HttpStatus . OK ,
3851 total,
@@ -42,7 +55,8 @@ export class SourceRequestController extends AbstractController {
4255
4356 @Get ( ':_id([0-9a-fA-F]{24})' )
4457 @ApiParam ( { name : '_id' , type : String } )
45- public async read ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) {
58+ @ApiReadResponseDecorator ( SourceRequestDto )
59+ public async read ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) : Promise < Response > {
4660 const data = await this . _service . findById ( _id )
4761 return res . status ( HttpStatus . OK ) . json ( {
4862 statusCode : HttpStatus . OK ,
@@ -52,7 +66,8 @@ export class SourceRequestController extends AbstractController {
5266
5367 @Patch ( ':_id([0-9a-fA-F]{24})' )
5468 @ApiParam ( { name : '_id' , type : String } )
55- public async update ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Body ( ) body : SourceRequestUpdateDto , @Res ( ) res : Response ) {
69+ @ApiUpdateDecorator ( SourceRequestUpdateDto , SourceRequestDto )
70+ public async update ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Body ( ) body : SourceRequestUpdateDto , @Res ( ) res : Response ) : Promise < Response > {
5671 const data = await this . _service . update ( _id , body )
5772 return res . status ( HttpStatus . OK ) . json ( {
5873 statusCode : HttpStatus . OK ,
@@ -62,7 +77,8 @@ export class SourceRequestController extends AbstractController {
6277
6378 @Delete ( ':_id([0-9a-fA-F]{24})' )
6479 @ApiParam ( { name : '_id' , type : String } )
65- public async remove ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) {
80+ @ApiDeletedResponseDecorator ( SourceRequestDto )
81+ public async remove ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) : Promise < Response > {
6682 const data = await this . _service . delete ( _id )
6783 return res . status ( HttpStatus . OK ) . json ( {
6884 statusCode : HttpStatus . OK ,
0 commit comments