import { Controller , Get , Post , Body , UseGuards , Param , Put , Query } from "@nestjs/common" ; import { AuthGuard } from "@nestjs/passport" ; import { plainToClass } from "class-transformer" ; import { AppearancesService } from "./appearances.service" ; import { Appearance } from "./../interfaces/appearance.interface" ; import { CreateAppearanceReq , EditAppearanceReq , KeyValueDto } from "./../dto" ; import { Tags } from "nest-swagger" ; import { NullableParseIntPipe , ResultList } from "nestx-common" ; @ Tags ( "core" ) @ Controller ( "appearance" ) @ UseGuards ( AuthGuard ( "jwt" ) ) export class AppearancesController { constructor ( private readonly appearanceService ) { } @ Post ( ) async create ( @ Body ( ) entry ) { return this . appearanceService . create ( plainToClass ( CreateAppearanceReq , entry ) ) ; } @ Put ( ) async update ( @ Body ( ) entry ) { return this . appearanceService . update ( plainToClass ( EditAppearanceReq , entry ) ) ; } @ Get ( "search" ) async search ( @ Query ( "keyword" ) keyword ? , @ Query ( "value" ) value ? ) { return this . appearanceService . 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 . appearanceService . querySearch ( keyword , page , size , sort ) ; } @ Get ( "name/:name" ) async getAppearanceByName ( @ Param ( "name" ) name ) { const result = await this . appearanceService . findOne ( { name } ) ; result . options = JSON . parse ( result . options || "{}" ) ; result . data = JSON . parse ( result . data || "{}" ) ; return result ; } @ Get ( ":id" ) async findOne ( @ Param ( "id" ) id ) { return this . appearanceService . findById ( id ) ; } }