import { Controller , Get , Post , Body , UseGuards , Param , Put , Query , UseInterceptors } from "@nestjs/common" ; import { AuthGuard } from "@nestjs/passport" ; import { plainToClass } from "class-transformer" ; import { SettingsService } from "./settings.service" ; import { Setting } from "./../interfaces" ; import { KeyValueDto , CreateSettingReq , EditSettingReq , SettingsGroup , SettingRes } from "./../dto" ; import { Tags } from "nest-swagger" ; import { ResultList , NullableParseIntPipe , RolesGuard , LoggingInterceptor } from "nestx-common" ; @ Tags ( "core" ) @ Controller ( "setting" ) @ UseGuards ( AuthGuard ( "jwt" ) , RolesGuard ) @ UseInterceptors ( LoggingInterceptor ) export class SettingsController { constructor ( private readonly settingService ) { } @ Post ( ) async create ( @ Body ( ) entry ) { return this . settingService . create ( plainToClass ( CreateSettingReq , entry ) ) ; } @ Put ( ) async update ( @ Body ( ) entry ) { return this . settingService . update ( plainToClass ( EditSettingReq , entry ) ) ; } @ Put ( "name/:name" ) async updateSettingsByName ( @ Query ( "name" ) name , @ Body ( ) entry ) { return this . settingService . updateSettingsByName ( name , entry ) ; } @ Get ( "search" ) async search ( @ Query ( "keyword" ) keyword ? , @ Query ( "value" ) value ? ) { return this . settingService . search ( keyword , value ) ; } @ Get ( "query" ) async query ( @ Query ( "keyword" ) keyword ? , @ Query ( "page" , new NullableParseIntPipe ( ) ) page = 1 , @ Query ( "size" , new NullableParseIntPipe ( ) ) size = 10 , @ Query ( "sort" ) sort ? ) { return this . settingService . querySearch ( keyword , page , size , sort ) ; } @ Get ( "name/:name" ) async getSettingsByName ( @ Query ( "name" ) name ? ) { return this . settingService . getSettingsByName ( name ) ; } @ Get ( "key/:key" ) async getSettingsByKey ( @ Query ( "key" ) key ) { return this . settingService . getSettingsByKey ( key ) ; } @ Get ( ":id" ) async findOne ( @ Param ( "id" ) id ) { return this . settingService . findById ( id ) ; } }