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,110 @@
import { Controller, Get, Post, Body, Patch, Param, Delete, Put } from '@nestjs/common';
import { RestTransformationsService } from './rest-transformations.service';
import { CreateRestTransformationDto } from './dto/create-rest-transformation.dto';
import { UpdateRestTransformationDto } from './dto/update-rest-transformation.dto';
import { AuthenticateController } from 'src/utils/Authenticate';
import axios from 'axios';
@Controller('transformation')
export class RestTransformationsController {
constructor(private readonly restTransformationsService: RestTransformationsService) {}
@Post()
async create(@Body() body: CreateRestTransformationDto) {
const authController = new AuthenticateController()
const accessToken = await authController.authenticate()
const connectionResponse = await axios.post(
`${process.env.DEV_URL}/transformation`,
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}/transformation`,
{
headers:{
"Authorization":`Token ${accessToken}`
}
}
)
return connectionResponse.data
}
@Get(':id')
async show(@Param('id') id: string) {
const authController = new AuthenticateController()
const accessToken = await authController.authenticate()
const connectionResponse = await axios.get(
`${process.env.DEV_URL}/transformation/${id}`,
{
headers:{
"Authorization":`Token ${accessToken}`
}
}
)
return connectionResponse.data
}
@Put(':id')
async update(@Param('id') id: string, @Body() body: UpdateRestTransformationDto) {
const authController = new AuthenticateController()
const accessToken = await authController.authenticate()
const connectionResponse = await axios.put(
`${process.env.DEV_URL}/transformation/${id}`,
body,
{
headers:{
"Authorization":`Token ${accessToken}`,
"Content-Type":"application/json"
}
}
)
return connectionResponse.data
}
@Delete(':id')
async remove(@Param('id') id: string) {
const authController = new AuthenticateController()
const accessToken = await authController.authenticate()
const connectionResponse = await axios.delete(
`${process.env.DEV_URL}/transformation/${id}`,
{
headers:{
"Authorization":`Token ${accessToken}`
}
}
)
return connectionResponse.data
}
}