mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-20 23:59:09 +00:00
changing auth middleware approach
This commit is contained in:
@@ -2,7 +2,6 @@ import axios from 'axios';
|
||||
require("dotenv").config();
|
||||
import { RestInputsService } from './rest-inputs.service';
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, Put, Headers } from '@nestjs/common';
|
||||
import { AuthenticateController } from 'src/utils/Authenticate';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { CreateRestInputDto } from './dto/create-rest-input.dto';
|
||||
import { UpdateRestInputDto } from './dto/update-rest-input.dto';
|
||||
@@ -15,24 +14,16 @@ import { testConnectionDTO } from './dto/testConnection.dto';
|
||||
export class RestInputsController {
|
||||
constructor(private readonly restInputsService: RestInputsService) {}
|
||||
|
||||
@Get('/test-auth/')
|
||||
async testauth(){
|
||||
return "Auth Success"
|
||||
}
|
||||
|
||||
|
||||
@Post('/test-connection/')
|
||||
async testConnection(@Body() body:testConnectionDTO){
|
||||
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
async testConnection(@Body() body:testConnectionDTO,@Headers() headers){
|
||||
|
||||
const connectionResponse = await axios.post(
|
||||
`${process.env.DEV_URL}/input/test-connection`,
|
||||
body,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`
|
||||
"Authorization":headers.authorization
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -42,17 +33,14 @@ export class RestInputsController {
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(@Body() body: CreateRestInputDto){
|
||||
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
async create(@Body() body: CreateRestInputDto,@Headers() headers){
|
||||
|
||||
const connectionResponse = await axios.post(
|
||||
`${process.env.DEV_URL}/input`,
|
||||
body,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`,
|
||||
"Authorization":headers.authorization,
|
||||
"Content-Type":"application/json"
|
||||
}
|
||||
}
|
||||
@@ -63,16 +51,13 @@ export class RestInputsController {
|
||||
}
|
||||
|
||||
@Get()
|
||||
async list(){
|
||||
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
async list(@Headers() headers){
|
||||
|
||||
const connectionResponse = await axios.get(
|
||||
`${process.env.DEV_URL}/input`,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`
|
||||
"Authorization":headers.authorization
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -82,15 +67,13 @@ export class RestInputsController {
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
async show(@Param() id: string){
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
async show(@Param() id: string,@Headers() headers){
|
||||
|
||||
const connectionResponse = await axios.get(
|
||||
`${process.env.DEV_URL}/input/:${id}`,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`
|
||||
"Authorization":headers.authorization
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -103,16 +86,15 @@ export class RestInputsController {
|
||||
async update(
|
||||
@Body() body: UpdateRestInputDto,
|
||||
@Param() id: string,
|
||||
@Headers() headers
|
||||
){
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
|
||||
const connectionResponse = await axios.put(
|
||||
`${process.env.DEV_URL}/input/:${id}`,
|
||||
body,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`,
|
||||
"Authorization":headers.authorization,
|
||||
"Content-Type":"application/json"
|
||||
}
|
||||
}
|
||||
@@ -123,15 +105,13 @@ export class RestInputsController {
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Param() id: string){
|
||||
const authController = new AuthenticateController()
|
||||
const accessToken = await authController.authenticate()
|
||||
async delete(@Param() id: string,@Headers() headers){
|
||||
|
||||
const connectionResponse = await axios.delete(
|
||||
`${process.env.DEV_URL}/input/:${id}`,
|
||||
{
|
||||
headers:{
|
||||
"Authorization":`Token ${accessToken}`
|
||||
"Authorization":headers.authorization
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user