import { Body, Controller, Delete, Get, Param, Patch, Post, } from '@nestjs/common'; import { InputsService } from './inputs.service'; import { InputsClientService } from 'src/clients/inputs/client.service'; import { UpdateInputRequest } from 'src/clients/inputs/interfaces'; import { ApiOkResponse, ApiTags } from '@nestjs/swagger'; import { CreateInputReq, GetAvailableEntitiesReq, GetAvailableEntitiesRes, Input, TestConnectionGetColumnsReq, TestConnectionGetColumnsRes, TestConnectionReq, TestConnectionRes, } from './dtos/input.model'; @ApiTags('inputs') @Controller('inputs') export class InputsController { inputService: InputsService; constructor(private inputsClientService: InputsClientService) { this.inputService = new InputsService(this.inputsClientService); } @Get('available-entities/:plugin') @ApiOkResponse({ type: GetAvailableEntitiesRes }) async getAvailableEntities( @Body() body, @Param() params: GetAvailableEntitiesReq, ) { const { info } = body; const { plugin } = params; return await this.inputService.getAvailableEntities({ info, plugin }); } @Post('/test-connection') @ApiOkResponse({ type: TestConnectionRes }) async testConnection(@Body() data: TestConnectionReq) { console.log(`/test-connection`, 'ON TEST CONNECTION ROUTE'); const inputService = new InputsService(this.inputsClientService); const response = await inputService.testConnection(data); return response; } @Post('/test-connection/get-columns') @ApiOkResponse({ type: TestConnectionGetColumnsRes }) async getColumns(@Body() data: TestConnectionGetColumnsReq) { console.log( `/test-connection/get-columns`, 'ON TEST CONNECTION GET COLUMNS ROUTE', ); const inputService = new InputsService(this.inputsClientService); const response = await inputService.getColumns(data); return response; } @Post() @ApiOkResponse({ type: Input }) async create(@Body() createInputDto: CreateInputReq) { console.log(`/input`, 'ON CREATE ROUTE'); const inputService = new InputsService(this.inputsClientService); const response = await inputService.create(createInputDto); return response; } @Get() async findAll(@Body() body) { console.log(`/input`, 'ON FIND ALL ROUTE'); const inputService = new InputsService(this.inputsClientService); const response = await inputService.findAll(body); return response; } @Get('/:id') async findOne(@Body() body, @Param() params) { const { id } = params; console.log(`/input/${id}`, 'ON FIND ONE ROUTE'); const inputService = new InputsService(this.inputsClientService); const response = await inputService.findOne({ id, ...body }); return response; } @Patch(':id') async update(@Body() updateInputDto: UpdateInputRequest, @Param() params) { const { id } = params; const { info } = updateInputDto; delete updateInputDto.info; console.log(`/input/${id}`, 'ON UPDATE ROUTE'); const inputService = new InputsService(this.inputsClientService); const response = await inputService.update(id, updateInputDto, info); return response; } @Delete(':id') async delete(@Body() data, @Param() params) { const { id } = params; console.log(`/input/${id}`, 'ON DELETE ROUTE'); const inputService = new InputsService(this.inputsClientService); const response = await inputService.remove({ id, ...data }); return response; } }