import { Controller , Get , Post , Body , UseGuards , Param , Put , Query , Req , UseInterceptors } from "@nestjs/common" ; import { AuthGuard } from "@nestjs/passport" ; import { plainToClass } from "class-transformer" ; import { ResultList , NullableParseIntPipe , RolesGuard , LoggingInterceptor , TreeNode } from "nestx-common" ; import { MenusService } from "./menus.service" ; import { Menu } from "./../interfaces" ; import { CreateMenuReq , EditMenuReq , KeyValueDto , MenuRes } from "./../dto" ; import { Tags } from "nest-swagger" ; @ Tags ( "core" ) @ Controller ( "menu" ) @ UseGuards ( AuthGuard ( "jwt" ) , RolesGuard ) @ UseInterceptors ( LoggingInterceptor ) export class MenusController { constructor ( private readonly menuService ) { } @ Post ( ) async create ( @ Body ( ) entry ) { return this . menuService . create ( plainToClass ( CreateMenuReq , entry ) ) ; } @ Put ( ) async update ( @ Body ( ) entry ) { return this . menuService . update ( plainToClass ( EditMenuReq , entry ) ) ; } @ Get ( "tree" ) async searchTree ( @ Query ( "keyword" ) keyword ? , @ Query ( "value" ) value ? ) { return this . menuService . searchMenuTree ( keyword , value ) ; } @ Get ( "search" ) async search ( @ Query ( "keyword" ) keyword ? , @ Query ( "value" ) value ? ) { return this . menuService . search ( keyword , value ) ; } @ Get ( "query" ) async query ( @ Query ( "isMenu" ) isMenu , @ Query ( "keyword" ) keyword ? , @ Query ( "page" , new NullableParseIntPipe ( ) ) page = 1 , @ Query ( "size" , new NullableParseIntPipe ( ) ) size = 10 , @ Query ( "sort" ) sort ? ) { return this . menuService . querySearch ( isMenu , keyword , page , size , sort ) ; } @ Get ( "permissions" ) async getPermissionTags ( ) { return this . menuService . getAllPermissionTags ( ) ; } @ Get ( "auth" ) async getUserMenus ( @ Req ( ) request ) { return this . menuService . getAuthenticatedMenus ( request . user ) ; } @ Get ( ":id" ) async findOne ( @ Param ( "id" ) id ) { return this . menuService . getMenuById ( id ) ; } }