import { Controller , Get , Post , Body , UseGuards , Param , Put , Query , UseInterceptors , } from '@nestjs/common' ; import { AuthGuard } from '@nestjs/passport' ; import { plainToClass } from 'class-transformer' ; import { ResultList , NullableParseIntPipe , RolesGuard , LoggingInterceptor } from 'nestx-common' ; import { DictsService } from './dicts.service' ; import { Dict } from './../interfaces/dict.interface' ; import { CreateDictReq , EditDictReq , KeyValueDto } from './../dto' ; import { Tags } from 'nest-swagger' ; @ Tags ( 'core' ) @ Controller ( 'dict' ) @ UseGuards ( AuthGuard ( 'jwt' ) , RolesGuard ) @ UseInterceptors ( LoggingInterceptor ) export class DictsController { constructor ( private readonly dictService ) { } @ Post ( ) async create ( @ Body ( ) entry ) { return this . dictService . create ( plainToClass ( CreateDictReq , entry ) ) ; } @ Put ( ) async update ( @ Body ( ) entry ) { return this . dictService . update ( plainToClass ( EditDictReq , entry ) ) ; } @ Get ( 'search' ) async search ( @ Query ( 'keyword' ) keyword ? , @ Query ( 'value' ) value ? , @ Query ( 'category' ) category ? ) { return this . dictService . search ( keyword , value , category , 10 , 'name' , 'category' ) ; } @ Get ( 'query' ) async query ( @ Query ( 'keyword' ) keyword ? , @ Query ( 'category' ) category ? , @ Query ( 'page' , new NullableParseIntPipe ( ) ) page = 1 , @ Query ( 'size' , new NullableParseIntPipe ( ) ) size = 10 , @ Query ( 'sort' ) sort ? ) { return this . dictService . querySearch ( keyword , category , page , size , sort ) ; } @ Get ( ':id' ) async findOne ( @ Param ( 'id' ) id ) { return this . dictService . findById ( id ) ; } }