implementation of rest comunication on gateway

This commit is contained in:
rodrigo.zamboni
2022-01-25 14:46:23 -03:00
parent 9dbe3ec33b
commit 332e0f0d80
66 changed files with 5450 additions and 4039 deletions
@@ -0,0 +1,22 @@
import { ApiProperty } from "@nestjs/swagger";
export class CreateRestInputDto {
@ApiProperty()
cron:string;
@ApiProperty({
description:"Name of the input",
example:"Test Name"
})
name:string;
@ApiProperty()
plugin:string;
@ApiProperty()
values:string;
@ApiProperty()
operation:string;
}
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/swagger';
import { CreateRestInputDto } from './create-rest-input.dto';
export class UpdateRestInputDto extends PartialType(CreateRestInputDto) {}
@@ -0,0 +1,14 @@
export class RestInput {
id:string;
cron:string;
name:string;
plugin:string;
values:string;
operation:string;
}
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { RestInputsController } from './rest-inputs.controller';
import { RestInputsService } from './rest-inputs.service';
describe('RestInputsController', () => {
let controller: RestInputsController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [RestInputsController],
providers: [RestInputsService],
}).compile();
controller = module.get<RestInputsController>(RestInputsController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
@@ -0,0 +1,134 @@
import axios from 'axios';
require("dotenv").config();
import { RestInputsService } from './rest-inputs.service';
import { CreateInputGrpcClientDto } from 'src/inputs/dto/create-input-grpc-client.dto';
import { UpdateInputGrpcClientDto } from 'src/inputs/dto/update-input-grpc-client.dto';
import { Controller, Get, Post, Body, Patch, Param, Delete, Put, Headers } from '@nestjs/common';
import { AuthenticateController } from 'src/utils/Authenticate';
@Controller('input')
export class RestInputsController {
constructor(private readonly restInputsService: RestInputsService) {}
@Post('/test-connection/')
async testConnection(@Body() body){
const authController = new AuthenticateController()
const accessToken = await authController.authenticate()
const connectionResponse = await axios.post(
`${process.env.DEV_URL}/input/test-connection`,
body,
{
headers:{
"Authorization":`Token ${accessToken}`
}
}
)
return connectionResponse.data
}
@Post()
async create(@Body() body: CreateInputGrpcClientDto){
const authController = new AuthenticateController()
const accessToken = await authController.authenticate()
const connectionResponse = await axios.post(
`${process.env.DEV_URL}/input`,
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}/input`,
{
headers:{
"Authorization":`Token ${accessToken}`
}
}
)
return connectionResponse.data
}
@Get('/:id')
async show(@Param() id: string){
const authController = new AuthenticateController()
const accessToken = await authController.authenticate()
const connectionResponse = await axios.get(
`${process.env.DEV_URL}/input/:${id}`,
{
headers:{
"Authorization":`Token ${accessToken}`
}
}
)
return connectionResponse.data
}
@Put(':id')
async update(
@Body() body: UpdateInputGrpcClientDto,
@Param() id: string,
){
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}`,
"Content-Type":"application/json"
}
}
)
return connectionResponse.data
}
@Delete(':id')
async delete(@Param() id: string){
const authController = new AuthenticateController()
const accessToken = await authController.authenticate()
const connectionResponse = await axios.delete(
`${process.env.DEV_URL}/input/:${id}`,
{
headers:{
"Authorization":`Token ${accessToken}`
}
}
)
return connectionResponse.data
}
}
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { RestInputsService } from './rest-inputs.service';
import { RestInputsController } from './rest-inputs.controller';
@Module({
controllers: [RestInputsController],
providers: [RestInputsService]
})
export class RestInputsModule {}
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { RestInputsService } from './rest-inputs.service';
describe('RestInputsService', () => {
let service: RestInputsService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [RestInputsService],
}).compile();
service = module.get<RestInputsService>(RestInputsService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { CreateRestInputDto } from './dto/create-rest-input.dto';
import { UpdateRestInputDto } from './dto/update-rest-input.dto';
@Injectable()
export class RestInputsService {
create(createRestInputDto: CreateRestInputDto) {
return 'This action adds a new restInput';
}
findAll() {
return `This action returns all restInputs`;
}
findOne(id: number) {
return `This action returns a #${id} restInput`;
}
update(id: number, updateRestInputDto: UpdateRestInputDto) {
return `This action updates a #${id} restInput`;
}
remove(id: number) {
return `This action removes a #${id} restInput`;
}
}