import { Controller , Get , Post , Body , UseGuards , Param , Put , Query , UseInterceptors , } from '@nestjs/common' ; import { AuthGuard } from '@nestjs/passport' ; import { plainToClass } from 'class-transformer' ; import { GroupsService } from './groups.service' ; import { Group } from './../interfaces' ; import { KeyValueDto , CreateGroupReq , EditGroupReq , GroupedUsersRes , } from './../dto' ; import { Tags } from 'nest-swagger' ; import { ResultList , NullableParseIntPipe , TreeNode , RolesGuard , LoggingInterceptor , } from 'nestx-common' ; @ Tags ( 'core' ) @ Controller ( 'group' ) @ UseGuards ( AuthGuard ( 'jwt' ) , RolesGuard ) @ UseInterceptors ( LoggingInterceptor ) export class GroupsController { constructor ( private readonly groupService ) { } @ Post ( ) async create ( @ Body ( ) entry ) { return this . groupService . create ( plainToClass ( CreateGroupReq , entry ) ) ; } @ Put ( ) async update ( @ Body ( ) entry ) { return this . groupService . editGroup ( plainToClass ( EditGroupReq , entry ) ) ; } @ Get ( 'search' ) async search ( @ Query ( 'keyword' ) keyword ? , @ Query ( 'value' ) value ? ) { return this . groupService . search ( keyword , value ) ; } @ Get ( 'users' ) async getGroupedUsers ( @ Query ( 'parent' ) parent ? ) { return this . groupService . getGroupedUsers ( parent ) ; } @ Get ( 'query' ) async query ( @ Query ( 'keyword' ) keyword ? , @ Query ( 'page' , new NullableParseIntPipe ( ) ) page = 1 , @ Query ( 'size' , new NullableParseIntPipe ( ) ) size = 10 , @ Query ( 'sort' ) sort ? ) { return this . groupService . querySearch ( keyword , page , size , sort ) ; } @ Get ( 'tree' ) async searchTree ( @ Query ( 'keyword' ) keyword ? , @ Query ( 'value' ) value ? ) { return this . groupService . searchGroupTree ( keyword , value ) ; } @ Get ( ':id' ) async findOne ( @ Param ( 'id' ) id ) { return this . groupService . findById ( id ) ; } }