import { Body , Controller , Get , HttpCode , HttpStatus , Logger , Param , ParseUUIDPipe , Post , Put , Query , } from '@nestjs/common' ; import { ApiOAuth2 , ApiOperation , ApiTags } from '@nestjs/swagger' ; import { User } from '@ngx-starter-kit/models' ; import { CurrentUser , Roles , RolesEnum , Token } from '../auth' ; import { CrudController } from '../core' ; import { CreateProjectDto } from './dto/create-project.dto' ; import { FindOwnProjectsDto } from './dto/find-own-projects.dto' ; import { FindProjectsDto } from './dto/find-projects.dto' ; import { ProjectList } from './dto/project-list.model' ; import { UpdateProjectDto } from './dto/update-project.dto' ; import { KubeContext } from './interfaces/kube-context' ; import { KubernetesService } from './kubernetes/kubernetes.service' ; import { Project } from './project.entity' ; import { ProjectService } from './project.service' ; @ ApiOAuth2 ( [ 'read' ] ) @ ApiTags ( 'Project' ) @ Controller ( 'project' ) export class ProjectController extends CrudController < Project > { private readonly logger = new Logger ( ProjectController . name ) ; constructor ( private readonly projectService , private readonly kservice ) { super ( projectService ) ; } @ ApiOperation ( { summary : 'Find all Projects. Admins only' } ) @ ApiTags ( 'Admin' ) @ Roles ( RolesEnum . ADMIN ) @ Get ( ) async findAll ( @ Query ( ) filter ) { return this . projectService . findAll ( filter ) ; } @ ApiOperation ( { summary : 'Search all Projects. Admins only' , description : 'Ref: https://github.com/rjlopezdev/typeorm-express-query-builder' , } ) @ ApiTags ( 'Admin' ) @ Roles ( RolesEnum . ADMIN ) @ Get ( '/search' ) async searchAll ( query ) { return this . projectService . searchAll ( query ) ; } @ ApiOperation ( { summary : 'find all user Projects' } ) @ Get ( '/own' ) async findOwn ( @ Query ( ) filter , @ CurrentUser ( ) user , @ Token ( ) token ) { return this . projectService . findOwn ( filter , user ) ; } @ ApiOperation ( { summary : 'Create new record, Self use only' } ) @ HttpCode ( HttpStatus . CREATED ) @ Post ( ) async create ( @ Body ( ) entity , @ CurrentUser ( ) user , @ Token ( ) token ) { const context = { cluster : entity . clusterName , namespace : entity . namespace , labels : entity . labels } ; return this . projectService . create ( entity , user ) ; } @ ApiOperation ( { summary : 'Update an existing record' } ) @ Put ( ':id' ) async update ( @ Param ( 'id' , new ParseUUIDPipe ( { version : '4' } ) ) id , @ Body ( ) entity ) { return super . update ( id , entity ) ; } }