mirror of
https://github.com/dadosfera/maestro.git
synced 2026-08-31 19:58:21 +00:00
124 lines
2.8 KiB
TypeScript
124 lines
2.8 KiB
TypeScript
import axios from 'axios';
|
|
require("dotenv").config();
|
|
import { RestInputsService } from './rest-inputs.service';
|
|
import { Controller, Get, Post, Body, Patch, Param, Delete, Put, Headers } from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
import { CreateRestInputDto } from './dto/create-rest-input.dto';
|
|
import { UpdateRestInputDto } from './dto/update-rest-input.dto';
|
|
import { testConnectionDTO } from './dto/testConnection.dto';
|
|
|
|
|
|
@ApiTags('Inputs')
|
|
@ApiBearerAuth()
|
|
@Controller('input')
|
|
export class RestInputsController {
|
|
constructor(private readonly restInputsService: RestInputsService) {}
|
|
|
|
|
|
@Post('/test-connection/')
|
|
async testConnection(@Body() body:testConnectionDTO,@Headers() headers){
|
|
|
|
const connectionResponse = await axios.post(
|
|
`${process.env.DEV_URL}/input/test-connection`,
|
|
body,
|
|
{
|
|
headers:{
|
|
"Authorization":headers.authorization
|
|
}
|
|
}
|
|
)
|
|
|
|
|
|
return connectionResponse.data
|
|
}
|
|
|
|
@Post()
|
|
async create(@Body() body: CreateRestInputDto,@Headers() headers){
|
|
|
|
const connectionResponse = await axios.post(
|
|
`${process.env.DEV_URL}/input`,
|
|
body,
|
|
{
|
|
headers:{
|
|
"Authorization":headers.authorization,
|
|
"Content-Type":"application/json"
|
|
}
|
|
}
|
|
)
|
|
|
|
|
|
return connectionResponse.data
|
|
}
|
|
|
|
@Get()
|
|
async list(@Headers() headers){
|
|
|
|
const connectionResponse = await axios.get(
|
|
`${process.env.DEV_URL}/input`,
|
|
{
|
|
headers:{
|
|
"Authorization":headers.authorization
|
|
}
|
|
}
|
|
)
|
|
|
|
|
|
return connectionResponse.data
|
|
}
|
|
|
|
@Get('/:id')
|
|
async show(@Param() id: string,@Headers() headers){
|
|
|
|
const connectionResponse = await axios.get(
|
|
`${process.env.DEV_URL}/input/:${id}`,
|
|
{
|
|
headers:{
|
|
"Authorization":headers.authorization
|
|
}
|
|
}
|
|
)
|
|
|
|
|
|
return connectionResponse.data
|
|
}
|
|
|
|
@Put(':id')
|
|
async update(
|
|
@Body() body: UpdateRestInputDto,
|
|
@Param() id: string,
|
|
@Headers() headers
|
|
){
|
|
|
|
const connectionResponse = await axios.put(
|
|
`${process.env.DEV_URL}/input/:${id}`,
|
|
body,
|
|
{
|
|
headers:{
|
|
"Authorization":headers.authorization,
|
|
"Content-Type":"application/json"
|
|
}
|
|
}
|
|
)
|
|
|
|
|
|
return connectionResponse.data
|
|
}
|
|
|
|
@Delete(':id')
|
|
async delete(@Param() id: string,@Headers() headers){
|
|
|
|
const connectionResponse = await axios.delete(
|
|
`${process.env.DEV_URL}/input/:${id}`,
|
|
{
|
|
headers:{
|
|
"Authorization":headers.authorization
|
|
}
|
|
}
|
|
)
|
|
|
|
|
|
return connectionResponse.data
|
|
}
|
|
|
|
}
|