1- import { Body , Controller , Delete , Get , HttpStatus , Param , Patch , Post , Req , Res } from '@nestjs/common'
2- import { ProjectCreateDto , ProjectUpdateDto } from './_dto/project.dto'
1+ import { Body , Controller , Delete , Get , HttpStatus , Param , Patch , Post , Res } from '@nestjs/common'
2+ import { ProjectCreateDto , ProjectDto , ProjectUpdateDto } from './_dto/project.dto'
33import { ProjectService } from './project.service'
44import { AbstractController } from '~/_common/abstracts/abstract.controller'
55import { ApiParam , ApiTags } from '@nestjs/swagger'
66import { SearchFilterSchema , FilterSchema , SearchFilterOptions , FilterOptions , ObjectIdValidationPipe } from '@streamkits/nestjs_module_scrud'
77import { Types } from 'mongoose'
8- import { Request , Response } from 'express'
8+ import { Response } from 'express'
9+ import { ApiCreateDecorator } from '~/_common/decorators/api-create.decorator'
10+ import { ApiDeletedResponseDecorator } from '~/_common/decorators/api-deleted-response.decorator'
11+ import { ApiPaginatedDecorator } from '~/_common/decorators/api-paginated.decorator'
12+ import { ApiReadResponseDecorator } from '~/_common/decorators/api-read-response.decorator'
13+ import { ApiUpdateDecorator } from '~/_common/decorators/api-update.decorator'
14+ import { PickProjectionHelper } from '~/_common/helpers/pick-projection.helper'
15+ import { PartialProjectionType } from '~/_common/types/partial-projection.type'
916
1017@ApiTags ( 'core' )
1118@Controller ( 'project' )
1219export class ProjectController extends AbstractController {
13- protected readonly projection = {
20+ protected static readonly projection : PartialProjectionType < ProjectDto > = {
1421 name : 1 ,
1522 startDate : 1 ,
1623 endDate : 1 ,
@@ -22,7 +29,8 @@ export class ProjectController extends AbstractController {
2229 }
2330
2431 @Post ( )
25- public async create ( @Req ( ) req : Request , @Res ( ) res : Response , @Body ( ) body : ProjectCreateDto ) {
32+ @ApiCreateDecorator ( ProjectCreateDto , ProjectDto )
33+ public async create ( @Res ( ) res : Response , @Body ( ) body : ProjectCreateDto ) : Promise < Response > {
2634 const data = await this . _service . create ( body )
2735 return res . status ( HttpStatus . CREATED ) . json ( {
2836 statusCode : HttpStatus . CREATED ,
@@ -31,8 +39,9 @@ export class ProjectController extends AbstractController {
3139 }
3240
3341 @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 )
42+ @ApiPaginatedDecorator ( PickProjectionHelper ( ProjectDto , ProjectController . projection ) )
43+ public async search ( @Res ( ) res : Response , @SearchFilterSchema ( ) searchFilterSchema : FilterSchema , @SearchFilterOptions ( ) searchFilterOptions : FilterOptions ) : Promise < Response > {
44+ const [ data , total ] = await this . _service . findAndCount ( searchFilterSchema , ProjectController . projection , searchFilterOptions )
3645 return res . status ( HttpStatus . OK ) . json ( {
3746 statusCode : HttpStatus . OK ,
3847 total,
@@ -42,7 +51,8 @@ export class ProjectController extends AbstractController {
4251
4352 @Get ( ':_id([0-9a-fA-F]{24})' )
4453 @ApiParam ( { name : '_id' , type : String } )
45- public async read ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) {
54+ @ApiReadResponseDecorator ( ProjectDto )
55+ public async read ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) : Promise < Response > {
4656 const data = await this . _service . findById ( _id )
4757 return res . status ( HttpStatus . OK ) . json ( {
4858 statusCode : HttpStatus . OK ,
@@ -52,7 +62,8 @@ export class ProjectController extends AbstractController {
5262
5363 @Patch ( ':_id([0-9a-fA-F]{24})' )
5464 @ApiParam ( { name : '_id' , type : String } )
55- public async update ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Body ( ) body : ProjectUpdateDto , @Res ( ) res : Response ) {
65+ @ApiUpdateDecorator ( ProjectUpdateDto , ProjectDto )
66+ public async update ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Body ( ) body : ProjectUpdateDto , @Res ( ) res : Response ) : Promise < Response > {
5667 const data = await this . _service . update ( _id , body )
5768 return res . status ( HttpStatus . OK ) . json ( {
5869 statusCode : HttpStatus . OK ,
@@ -62,7 +73,8 @@ export class ProjectController extends AbstractController {
6273
6374 @Delete ( ':_id([0-9a-fA-F]{24})' )
6475 @ApiParam ( { name : '_id' , type : String } )
65- public async remove ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) {
76+ @ApiDeletedResponseDecorator ( ProjectDto )
77+ public async remove ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) : Promise < Response > {
6678 const data = await this . _service . delete ( _id )
6779 return res . status ( HttpStatus . OK ) . json ( {
6880 statusCode : HttpStatus . OK ,
0 commit comments