mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-21 16:29:08 +00:00
107 lines
2.8 KiB
TypeScript
107 lines
2.8 KiB
TypeScript
import { Controller, Get, Post, Body, Patch, Param, Delete, Put } from '@nestjs/common';
|
|
import { RestOutputsService } from './rest-outputs.service';
|
|
import { CreateRestOutputDto } from './dto/create-rest-output.dto';
|
|
import { UpdateRestOutputDto } from './dto/update-rest-output.dto';
|
|
import { AuthenticateController } from 'src/utils/Authenticate';
|
|
import axios from 'axios';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
|
|
@ApiTags('Outputs')
|
|
@ApiBearerAuth()
|
|
@Controller('output')
|
|
export class RestOutputsController {
|
|
constructor(private readonly restOutputsService: RestOutputsService) {}
|
|
|
|
@Post()
|
|
async create(@Body() body: CreateRestOutputDto) {
|
|
|
|
const authController = new AuthenticateController()
|
|
const accessToken = await authController.authenticate()
|
|
|
|
const connectionResponse = await axios.post(
|
|
`${process.env.DEV_URL}/output`,
|
|
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}/output`,
|
|
{
|
|
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}/output/${id}`,
|
|
{
|
|
headers:{
|
|
"Authorization":`Token ${accessToken}`
|
|
}
|
|
}
|
|
)
|
|
|
|
return connectionResponse.data
|
|
}
|
|
|
|
@Put(':id')
|
|
async update(@Param('id') id: string, @Body() body: UpdateRestOutputDto) {
|
|
|
|
const authController = new AuthenticateController()
|
|
const accessToken = await authController.authenticate()
|
|
|
|
const connectionResponse = await axios.put(
|
|
`${process.env.DEV_URL}/output/${id}`,
|
|
body,
|
|
{
|
|
headers:{
|
|
"Authorization":`Token ${accessToken}`
|
|
}
|
|
}
|
|
)
|
|
|
|
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}/output/${id}`,
|
|
{
|
|
headers:{
|
|
"Authorization":`Token ${accessToken}`
|
|
}
|
|
}
|
|
)
|
|
|
|
return connectionResponse.data
|
|
}
|
|
}
|