mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-12 09:19:08 +00:00
implementation of rest comunication on gateway
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
import axios from 'axios';
|
||||
require("dotenv").config();
|
||||
import { RestInputsService } from './rest-inputs.service';
|
||||
import { CreateInputGrpcClientDto } from 'src/inputs/dto/create-input-grpc-client.dto';
|
||||
import { UpdateInputGrpcClientDto } from 'src/inputs/dto/update-input-grpc-client.dto';
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, Put, Headers } from '@nestjs/common';
|
||||
import { AuthenticateController } from 'src/utils/Authenticate';
|
||||
|
||||
|
||||
|
||||
@Controller('input')
|
||||
export class RestInputsController {
|
||||
constructor(private readonly restInputsService: RestInputsService) {}
|
||||
|
||||
@Post('/test-connection/')
|
||||
async testConnection(@Body() body){
|
||||
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
|
||||
const connectionResponse = await axios.post(
|
||||
`${process.env.DEV_URL}/input/test-connection`,
|
||||
body,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
return connectionResponse.data
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Body() body: CreateInputGrpcClientDto){
|
||||
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
|
||||
const connectionResponse = await axios.post(
|
||||
`${process.env.DEV_URL}/input`,
|
||||
body,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`,
|
||||
"Content-Type":"application/json"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
return connectionResponse.data
|
||||
}
|
||||
|
||||
@Get()
|
||||
async list(){
|
||||
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
|
||||
const connectionResponse = await axios.get(
|
||||
`${process.env.DEV_URL}/input`,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
return connectionResponse.data
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
async show(@Param() id: string){
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
|
||||
const connectionResponse = await axios.get(
|
||||
`${process.env.DEV_URL}/input/:${id}`,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
return connectionResponse.data
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
async update(
|
||||
@Body() body: UpdateInputGrpcClientDto,
|
||||
@Param() id: string,
|
||||
){
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
|
||||
const connectionResponse = await axios.put(
|
||||
`${process.env.DEV_URL}/input/:${id}`,
|
||||
body,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`,
|
||||
"Content-Type":"application/json"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
return connectionResponse.data
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Param() id: string){
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
|
||||
const connectionResponse = await axios.delete(
|
||||
`${process.env.DEV_URL}/input/:${id}`,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
return connectionResponse.data
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user