mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-15 17:09:08 +00:00
111 lines
2.9 KiB
TypeScript
111 lines
2.9 KiB
TypeScript
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
|
|
}
|
|
}
|