implementation of rest comunication on gateway

This commit is contained in:
rodrigo.zamboni
2022-01-25 14:46:23 -03:00
parent 9dbe3ec33b
commit 332e0f0d80
66 changed files with 5450 additions and 4039 deletions
@@ -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
}
}