11import { Body , Controller , Delete , Get , HttpStatus , Param , Patch , Post , Req , Res } from '@nestjs/common'
2- import { PreferencesCreateDto , PreferencesUpdateDto } from './_dto/preferences.dto'
2+ import { PreferencesCreateDto , PreferencesDto , PreferencesUpdateDto } from './_dto/preferences.dto'
33import { PreferencesService } from './preferences.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'
88import { Request , Response } from 'express'
9+ import { PartialProjectionType } from '~/_common/types/partial-projection.type'
10+ import { ApiCreateDecorator } from '~/_common/decorators/api-create.decorator'
11+ import { ApiPaginatedDecorator } from '~/_common/decorators/api-paginated.decorator'
12+ import { PickProjectionHelper } from '~/_common/helpers/pick-projection.helper'
13+ import { ApiReadResponseDecorator } from '~/_common/decorators/api-read-response.decorator'
14+ import { ApiUpdateDecorator } from '~/_common/decorators/api-update.decorator'
15+ import { ApiDeletedResponseDecorator } from '~/_common/decorators/api-deleted-response.decorator'
916
1017@ApiTags ( 'core' )
1118@Controller ( 'preferences' )
1219export class PreferencesController extends AbstractController {
13- public readonly projection = {
20+ public static readonly projection : PartialProjectionType < PreferencesDto > = {
1421 name : 1 ,
1522 data : 1 ,
16- personId : 1 ,
23+ entityId : 1 ,
1724 }
1825
1926 constructor ( private readonly _service : PreferencesService ) {
2027 super ( )
2128 }
2229
2330 @Post ( )
24- public async create ( @Req ( ) req : Request , @Res ( ) res : Response , @Body ( ) body : PreferencesCreateDto ) {
31+ @ApiCreateDecorator ( PreferencesCreateDto , PreferencesDto )
32+ public async create ( @Req ( ) req : Request , @Res ( ) res : Response , @Body ( ) body : PreferencesCreateDto ) : Promise < Response > {
2533 const data = await this . _service . create ( body )
2634 return res . status ( HttpStatus . CREATED ) . json ( {
2735 statusCode : HttpStatus . CREATED ,
@@ -30,8 +38,9 @@ export class PreferencesController extends AbstractController {
3038 }
3139
3240 @Get ( )
33- public async search ( @Res ( ) res : Response , @SearchFilterSchema ( ) searchFilterSchema : FilterSchema , @SearchFilterOptions ( ) searchFilterOptions : FilterOptions ) {
34- const [ data , total ] = await this . _service . findAndCount ( searchFilterSchema , this . projection , searchFilterOptions )
41+ @ApiPaginatedDecorator ( PickProjectionHelper ( PreferencesDto , PreferencesController . projection ) )
42+ public async search ( @Res ( ) res : Response , @SearchFilterSchema ( ) searchFilterSchema : FilterSchema , @SearchFilterOptions ( ) searchFilterOptions : FilterOptions ) : Promise < Response > {
43+ const [ data , total ] = await this . _service . findAndCount ( searchFilterSchema , PreferencesController . projection , searchFilterOptions )
3544 return res . status ( HttpStatus . OK ) . json ( {
3645 statusCode : HttpStatus . OK ,
3746 total,
@@ -41,7 +50,8 @@ export class PreferencesController extends AbstractController {
4150
4251 @Get ( ':_id([0-9a-fA-F]{24})' )
4352 @ApiParam ( { name : '_id' , type : String } )
44- public async read ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) {
53+ @ApiReadResponseDecorator ( PreferencesDto )
54+ public async read ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) : Promise < Response > {
4555 const data = await this . _service . findById ( _id )
4656 return res . status ( HttpStatus . OK ) . json ( {
4757 statusCode : HttpStatus . OK ,
@@ -51,7 +61,8 @@ export class PreferencesController extends AbstractController {
5161
5262 @Patch ( ':_id([0-9a-fA-F]{24})' )
5363 @ApiParam ( { name : '_id' , type : String } )
54- public async update ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Body ( ) body : PreferencesUpdateDto , @Res ( ) res : Response ) {
64+ @ApiUpdateDecorator ( PreferencesUpdateDto , PreferencesDto )
65+ public async update ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Body ( ) body : PreferencesUpdateDto , @Res ( ) res : Response ) : Promise < Response > {
5566 const data = await this . _service . update ( _id , body )
5667 return res . status ( HttpStatus . OK ) . json ( {
5768 statusCode : HttpStatus . OK ,
@@ -61,7 +72,8 @@ export class PreferencesController extends AbstractController {
6172
6273 @Delete ( ':_id([0-9a-fA-F]{24})' )
6374 @ApiParam ( { name : '_id' , type : String } )
64- public async remove ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) {
75+ @ApiDeletedResponseDecorator ( PreferencesDto )
76+ public async remove ( @Param ( '_id' , ObjectIdValidationPipe ) _id : Types . ObjectId , @Res ( ) res : Response ) : Promise < Response > {
6577 const data = await this . _service . delete ( _id )
6678 return res . status ( HttpStatus . OK ) . json ( {
6779 statusCode : HttpStatus . OK ,
0 commit comments