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 } }