mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-07 10:19:09 +00:00
implementation of rest comunication on gateway
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user